Package io.aether.syncmap
Class SyncMap<K,V>
- java.lang.Object
-
- io.aether.syncmap.SyncMap<K,V>
-
- Type Parameters:
V- The type of mapped values, serialized viaFastMetaType* @see AutoFlushContext
public abstract class SyncMap<K,V> extends java.lang.ObjectA high-performance, decentralized distributed map providing strongly eventual consistency across the Aether cluster topology without relying on a central database bottleneck. *Instead of holding state data directly,
SyncMapacts as a network orchestrator and conflict resolver layer over any local storage implementation (e.g., in-memory caches, RocksDB, or relational store) provided via functional hooks. *Core Architectural Pillars
- Decentralized Ownership (Consistent Hashing): Leverages a
ConsistentHashRingto deterministically map keys to specific authoritative cluster nodes ("owners"). Every node acts simultaneously as a master for a subset of keys and a replica for others.
* - Optimized Network Batching (Auto-Flush): By extending
AutoFlushContext, outgoing RPC commands (such asSyncPutandSyncPropose) are not transmitted immediately as thousands of expensive network micro-packets. Instead, they are accumulated in a thread-safe buffer and flushed as a single packed binary chunk usingremoteDataToArray(), minimizing system calls and bandwidth overhead.
* - Authoritative Ordering ("Owner-Wins"):
- When a mutation happens on the owner node, it increments the data version globally,
commits it locally, and broadcasts a
SyncPutpayload to all replica peers. - When a mutation happens on a replica (non-owner) node, it applies the update
optimistically and dispatches a
SyncProposepacket to the designated owner node. The owner evaluates the base version, linearizes the event, and either broadcasts a definitiveSyncPutor issues aSyncRejectif a race condition occurred.
- When a mutation happens on the owner node, it increments the data version globally,
commits it locally, and broadcasts a
Lifecycle & Usage Guidelines
To integrate
*SyncMapinto your cluster runtime, follow these setup steps:
* @param// 1. Initialize local cache maps/hooks Map<String, VersionedValue<String>> cache = new ConcurrentHashMap<>(); * // 2. Create the SyncMap instance SyncMap<String, String> syncMap = new SyncMap<>( serverId, scopeId, hashRing, FastMeta.META_STRING, FastMeta.META_STRING, cache::get, cache::put, dbLoader ); * // 3. Cluster Discovery: Bind transport layers by passing nodes as MetaContexts syncMap.addPeer(peerServerId, networkTransportContext); * // 4. Perform mutations (Changes queue up internally into the AutoFlush layer) syncMap.notifyChanged("session_uuid_123", "worker_node_nodeB"); syncMap.flush(); // Forces the batch out to the network layer immediatelyThe type of keys maintained by this map, serialized via FastMetaType- See Also:
ConsistentHashRing,SyncMapInternalApi
-
-
Field Summary
Fields Modifier and Type Field Description protected static intALL_OWNERSSentinel used by storage adapters to iterate over every owner.protected java.util.Map<java.lang.Integer,java.lang.Long>dbMaxSeqNoCacheio.aether.utils.interfaces.ABiConsumer<java.lang.Integer,byte[]>onSendToPeer
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddPeer(int serverId)voidclose()protected voidclosePersistence()Lifecycle hook for persistence implementations with owned resources.protected abstract io.aether.utils.futures.ARFuture<SyncContainer<V>>dbGet(K key)protected longdbGetMaxSeqNo(int ownerSid)protected abstract voiddbPut(K key, SyncContainer<V> container)protected booleandbPutApplied(K key, SyncContainer<V> container)voiddelete(K key)Creates and replicates a durable tombstone for an existing key.protected voidexecuteAsync(io.aether.utils.interfaces.ARunnable task)protected abstract voidforEachStorageEntry(int ownerSid, long sinceSeqNo, java.util.function.BiConsumer<K,SyncContainer<V>> consumer)io.aether.utils.futures.ARFuture<V>get(K key)VgetData(K key)protected Vmerge(V existing, V incoming)Простой вариант: пользователь работает только с V.protected SyncContainer<V>mergeContainers(SyncContainer<V> existing, SyncContainer<V> incoming)Продвинутый вариант: пользователь работает с SyncContainer и может принимать решения на основе seqNo, ownerSid, isDeleted.protected io.aether.utils.futures.ARFuture<java.lang.Boolean>persistAsync(K key, SyncContainer<V> container)Schedules persistence of one immutable version.voidput(K key, V newValue)voidputRemote(SyncPut data)voidreceiveFromPeer(int sid, byte[] data)voidremovePeer(int serverId)voidrequestFullReconciliation()voidrequestKey(K key)protected voidrestoreKnownSeqNo(int ownerSid, long seqNo)Restores durable sequence information loaded from storage.protected voidsendReconciliationEntry(int peerSid, SyncPut data)protected voidsendToPeer(int sid, byte[] data)io.aether.utils.futures.ARFuture<SyncContainer<V>>storageGet(K key)voidstoragePut(K key, SyncContainer<V> container)voidsyncRequest(SyncRequest data)
-
-
-
Field Detail
-
ALL_OWNERS
protected static final int ALL_OWNERS
Sentinel used by storage adapters to iterate over every owner.- See Also:
- Constant Field Values
-
dbMaxSeqNoCache
protected final java.util.Map<java.lang.Integer,java.lang.Long> dbMaxSeqNoCache
-
onSendToPeer
public io.aether.utils.interfaces.ABiConsumer<java.lang.Integer,byte[]> onSendToPeer
-
-
Method Detail
-
close
public final void close()
-
restoreKnownSeqNo
protected final void restoreKnownSeqNo(int ownerSid, long seqNo)Restores durable sequence information loaded from storage. The local counter must never move backwards after a process restart.
-
merge
protected V merge(V existing, V incoming)
Простой вариант: пользователь работает только с V. По умолчанию incoming побеждает existing.
-
mergeContainers
protected SyncContainer<V> mergeContainers(SyncContainer<V> existing, SyncContainer<V> incoming)
Продвинутый вариант: пользователь работает с SyncContainer и может принимать решения на основе seqNo, ownerSid, isDeleted. По умолчанию делегирует простому merge.
-
dbGet
protected abstract io.aether.utils.futures.ARFuture<SyncContainer<V>> dbGet(K key)
-
dbPut
protected abstract void dbPut(K key, SyncContainer<V> container)
-
dbPutApplied
protected boolean dbPutApplied(K key, SyncContainer<V> container)
-
dbGetMaxSeqNo
protected long dbGetMaxSeqNo(int ownerSid)
-
storageGet
public final io.aether.utils.futures.ARFuture<SyncContainer<V>> storageGet(K key)
-
storagePut
public final void storagePut(K key, SyncContainer<V> container)
-
forEachStorageEntry
protected abstract void forEachStorageEntry(int ownerSid, long sinceSeqNo, java.util.function.BiConsumer<K,SyncContainer<V>> consumer)
-
sendToPeer
protected void sendToPeer(int sid, byte[] data)
-
receiveFromPeer
public void receiveFromPeer(int sid, byte[] data)
-
persistAsync
protected io.aether.utils.futures.ARFuture<java.lang.Boolean> persistAsync(K key, SyncContainer<V> container)
Schedules persistence of one immutable version.Production adapters may override this hook with a bounded retry pipeline. The default preserves the existing asynchronous behavior while making synchronous adapter failures observable.
-
closePersistence
protected void closePersistence()
Lifecycle hook for persistence implementations with owned resources.
-
executeAsync
protected void executeAsync(io.aether.utils.interfaces.ARunnable task)
-
putRemote
public void putRemote(SyncPut data)
-
syncRequest
public void syncRequest(SyncRequest data)
-
sendReconciliationEntry
protected void sendReconciliationEntry(int peerSid, SyncPut data)
-
addPeer
public void addPeer(int serverId)
-
requestKey
public void requestKey(K key)
-
removePeer
public void removePeer(int serverId)
-
delete
public void delete(K key)
Creates and replicates a durable tombstone for an existing key.The previous value is retained inside the container because value serializers are not required to support null. Public reads still return null for deleted containers.
-
requestFullReconciliation
public final void requestFullReconciliation()
-
-