Package org.apache.solr.cloud
Class ZkShardTerms
java.lang.Object
org.apache.solr.cloud.ZkShardTerms
- All Implemented Interfaces:
AutoCloseable
Class used for interact with a ZK term node. Each ZK term node relates to a shard of a collection
and have this format (in json)
{
"replicaNodeName1" : 1,
"replicaNodeName2" : 2,
..
}
The values correspond to replicas are called terms. Only replicas with highest term value are considered up to date and be able to become leader and serve queries.
Terms can only updated in two strict ways:
- A replica sets its term equals to leader's term
- The leader increase its term and some other replicas by 1
Watcher.Event.KeeperState.Expired event-
Constructor Summary
ConstructorsConstructorDescriptionZkShardTerms(String collection, String shard, org.apache.solr.common.cloud.SolrZkClient zkClient) -
Method Summary
Modifier and TypeMethodDescriptionbooleancanBecomeLeader(String coreNodeName) Can this replica become leader?voidclose()voiddoneRecovering(String coreNodeName) MarkcoreNodeNameas finished recoveringvoidWhen first updates come in, all replicas have some data now, so we must switch from term 0 (registered) to 1 (have some data)voidensureTermsIsHigher(String leader, Set<String> replicasNeedingRecovery) Ensure that terms are higher than some replica's terms.longlongbooleanisRecovering(String name) voidFetch latest terms from ZKbooleanregistered(String coreNodeName) Did this replica registered its term? This is a sign to check fvoidsetTermEqualsToLeader(String coreNodeName) Set a replica's term equals to leader's term, and remove recovering flag of a replica.voidsetTermToZero(String coreNodeName) Set a replica's term to 0.booleanskipSendingUpdatesTo(String coreNodeName) Should leader skip sending updates to this replica?voidstartRecovering(String coreNodeName) MarkcoreNodeNameas recovering
-
Constructor Details
-
ZkShardTerms
-
-
Method Details
-
ensureTermsIsHigher
Ensure that terms are higher than some replica's terms. If the current leader is attempting to give up leadership and included in replicasNeedingRecovery, then other replicas that are in sync will have higher terms, while the leader will stay where it is.- Parameters:
leader- coreNodeName of leaderreplicasNeedingRecovery- set of replicas in which their terms should be lower than leader's term
-
getShardTerms
-
canBecomeLeader
Can this replica become leader?- Parameters:
coreNodeName- of the replica- Returns:
- true if this replica can become leader, false if otherwise
-
skipSendingUpdatesTo
Should leader skip sending updates to this replica?- Parameters:
coreNodeName- of the replica- Returns:
- true if this replica has term equals to leader's term, false if otherwise
-
registered
Did this replica registered its term? This is a sign to check f- Parameters:
coreNodeName- of the replica- Returns:
- true if this replica registered its term, false if otherwise
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
setTermEqualsToLeader
Set a replica's term equals to leader's term, and remove recovering flag of a replica. This call should only be used byCollectionParams.CollectionAction.FORCELEADER- Parameters:
coreNodeName- of the replica
-
setTermToZero
Set a replica's term to 0. If the term does not exist, create it.- Parameters:
coreNodeName- of the replica
-
startRecovering
MarkcoreNodeNameas recovering -
doneRecovering
MarkcoreNodeNameas finished recovering -
isRecovering
-
ensureHighestTermsAreNotZero
public void ensureHighestTermsAreNotZero()When first updates come in, all replicas have some data now, so we must switch from term 0 (registered) to 1 (have some data) -
getHighestTerm
public long getHighestTerm() -
getTerm
-
refreshTerms
public void refreshTerms()Fetch latest terms from ZK
-