Class ReadReplicaManager
java.lang.Object
com.loomcache.server.replication.ReadReplicaManager
Manages read replicas that receive replicated data but do not participate in Raft votes.
Read replicas are non-voting followers that receive log entries from the leader. They can serve read requests at various consistency levels (EVENTUAL, BOUNDED_STALENESS, etc.) and automatically track their replication lag.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordAggregated stats about all replicas.static final recordInformation about a read replica.static enumEnumeration of read replica states. -
Constructor Summary
ConstructorsConstructorDescriptionReadReplicaManager(String nodeId, int instanceNumber) Initialize the ReadReplicaManager. -
Method Summary
Modifier and TypeMethodDescriptionGet all active replicas (state == ACTIVE).Get all registered replicas.@Nullable ReadReplicaManager.ReplicaInfogetReplicaInfo(String replicaId) Get replica info by ID.longgetReplicaLag(String replicaId) Get the replication lag for a replica in milliseconds.getReplicasWithinLag(long maxLagMs) Get replicas that are safe to serve bounded-staleness reads within the given lag threshold.getStats()Get aggregated statistics about all replicas.voidmarkDisconnected(String replicaId) Mark a replica as disconnected (e.g., on connection failure).voidmarkSyncing(String replicaId) Mark a replica as syncing (e.g., on reconnection start).registerReplica(String address) Register a new read replica.voidunregisterReplica(String replicaId) Unregister a read replica.voidupdateReplicaLag(String replicaId, long lastSyncedIndex, long leaderLastLogIndex) Update the synced index for a replica and check lag threshold.
-
Constructor Details
-
ReadReplicaManager
Initialize the ReadReplicaManager.- Parameters:
nodeId- The node identifier (must not be null)instanceNumber- The instance number for logging
-
-
Method Details
-
registerReplica
-
unregisterReplica
Unregister a read replica.- Parameters:
replicaId- The replica ID (must not be null)
-
getActiveReplicas
Get all active replicas (state == ACTIVE).- Returns:
- List of active replica infos
-
getReplicasWithinLag
Get replicas that are safe to serve bounded-staleness reads within the given lag threshold. Excludes replicas that are still syncing or fully disconnected.- Parameters:
maxLagMs- maximum acceptable lag in milliseconds- Returns:
- replicas whose lag is within the threshold and that are ready to serve reads
-
getReplicaLag
Get the replication lag for a replica in milliseconds.- Parameters:
replicaId- The replica ID (must not be null)- Returns:
- Lag in milliseconds, or -1 if replica not found
-
updateReplicaLag
Update the synced index for a replica and check lag threshold.- Parameters:
replicaId- The replica ID (must not be null)lastSyncedIndex- The last index synced to this replicaleaderLastLogIndex- The leader's current last log index
-
markDisconnected
Mark a replica as disconnected (e.g., on connection failure).- Parameters:
replicaId- The replica ID (must not be null)
-
markSyncing
Mark a replica as syncing (e.g., on reconnection start).- Parameters:
replicaId- The replica ID (must not be null)
-
getReplicaInfo
Get replica info by ID.- Parameters:
replicaId- The replica ID (must not be null)- Returns:
- ReplicaInfo or null if not found
-
getAllReplicas
Get all registered replicas.- Returns:
- List of all replica infos
-
getStats
Get aggregated statistics about all replicas.- Returns:
- ReadReplicaStats record
-