Package org.apache.solr.cloud
Class ZkShardTerms
- java.lang.Object
-
- org.apache.solr.cloud.ZkShardTerms
-
- All Implemented Interfaces:
AutoCloseable
public class ZkShardTerms extends Object implements 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
Constructors Constructor Description ZkShardTerms(String collection, String shard, SolrZkClient zkClient)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canBecomeLeader(String coreNodeName)
Can this replica become leader?void
close()
void
doneRecovering(String coreNodeName)
MarkcoreNodeName
as finished recoveringvoid
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)void
ensureTermsIsHigher(String leader, Set<String> replicasNeedingRecovery)
Ensure that terms are higher than some replica's terms.long
getHighestTerm()
ShardTerms
getShardTerms()
long
getTerm(String coreNodeName)
boolean
isRecovering(String name)
void
refreshTerms()
Fetch latest terms from ZKboolean
registered(String coreNodeName)
Did this replica registered its term? This is a sign to check fvoid
setTermEqualsToLeader(String coreNodeName)
Set a replica's term equals to leader's term, and remove recovering flag of a replica.void
setTermToZero(String coreNodeName)
Set a replica's term to 0.boolean
skipSendingUpdatesTo(String coreNodeName)
Should leader skip sending updates to this replica?void
startRecovering(String coreNodeName)
MarkcoreNodeName
as recovering
-
-
-
Constructor Detail
-
ZkShardTerms
public ZkShardTerms(String collection, String shard, SolrZkClient zkClient)
-
-
Method Detail
-
ensureTermsIsHigher
public void ensureTermsIsHigher(String leader, Set<String> replicasNeedingRecovery)
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
public ShardTerms getShardTerms()
-
canBecomeLeader
public boolean canBecomeLeader(String coreNodeName)
Can this replica become leader?- Parameters:
coreNodeName
- of the replica- Returns:
- true if this replica can become leader, false if otherwise
-
skipSendingUpdatesTo
public boolean skipSendingUpdatesTo(String coreNodeName)
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
public boolean registered(String coreNodeName)
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:
close
in interfaceAutoCloseable
-
setTermEqualsToLeader
public void setTermEqualsToLeader(String coreNodeName)
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
public void setTermToZero(String coreNodeName)
Set a replica's term to 0. If the term does not exist, create it.- Parameters:
coreNodeName
- of the replica
-
startRecovering
public void startRecovering(String coreNodeName)
MarkcoreNodeName
as recovering
-
doneRecovering
public void doneRecovering(String coreNodeName)
MarkcoreNodeName
as finished recovering
-
isRecovering
public boolean isRecovering(String name)
-
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
public long getTerm(String coreNodeName)
-
refreshTerms
public void refreshTerms()
Fetch latest terms from ZK
-
-