Class ZkStateWriter
- java.lang.Object
-
- org.apache.solr.cloud.overseer.ZkStateWriter
-
public class ZkStateWriter extends Object
ZkStateWriter is responsible for writing updates to the cluster state stored in ZooKeeper for collections each of which gets their own individual state.json in ZK.Updates to the cluster state are specified using the
enqueueUpdate(ClusterState, List, ZkWriteCallback)
method. The class buffers updates to reduce the number of writes to ZK. The buffered updates are flushed duringenqueueUpdate
automatically if necessary. ThewritePendingUpdates()
can be used to force flush any pending updates.If either
enqueueUpdate(ClusterState, List, ZkWriteCallback)
orwritePendingUpdates()
throws aKeeperException.BadVersionException
then the internal buffered state of the class is suspect and the current instance of the class should be discarded and a new instance should be created and used for any future updates.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ZkStateWriter.ZkWriteCallback
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.solr.common.cloud.ClusterState
clusterState
protected org.apache.solr.common.util.Compressor
compressor
protected boolean
invalidState
Set to true if we ever get a BadVersionException so that we can disallow future operations with this instanceprotected long
lastUpdatedTime
protected int
minStateByteLenForCompression
static ZkWriteCommand
NO_OP
Represents a no-opZkWriteCommand
which will result in no modification to cluster stateprotected org.apache.solr.common.cloud.ZkStateReader
reader
protected Stats
stats
protected Map<String,ZkWriteCommand>
updates
-
Constructor Summary
Constructors Constructor Description ZkStateWriter(org.apache.solr.common.cloud.ZkStateReader zkStateReader, Stats stats, int minStateByteLenForCompression, org.apache.solr.common.util.Compressor compressor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.solr.common.cloud.ClusterState
enqueueUpdate(org.apache.solr.common.cloud.ClusterState prevState, List<ZkWriteCommand> cmds, ZkStateWriter.ZkWriteCallback callback)
Applies the givenZkWriteCommand
on theprevState
.org.apache.solr.common.cloud.ClusterState
getClusterState()
boolean
hasPendingUpdates()
void
resetPendingUpdateCounters()
void
updateClusterState(Function<org.apache.solr.common.cloud.ClusterState,org.apache.solr.common.cloud.ClusterState> fun)
if any collection is updated not through this class (directly written to ZK, then it needs to be updated locally)org.apache.solr.common.cloud.ClusterState
writePendingUpdates()
org.apache.solr.common.cloud.ClusterState
writePendingUpdates(Map<String,ZkWriteCommand> updates, boolean resetPendingUpdateCounters)
Writes all pending updates to ZooKeeper and returns the modified cluster stateorg.apache.solr.common.cloud.ClusterState
writeUpdate(ZkWriteCommand command)
-
-
-
Field Detail
-
NO_OP
public static ZkWriteCommand NO_OP
Represents a no-opZkWriteCommand
which will result in no modification to cluster state
-
reader
protected final org.apache.solr.common.cloud.ZkStateReader reader
-
stats
protected final Stats stats
-
updates
protected Map<String,ZkWriteCommand> updates
-
clusterState
protected org.apache.solr.common.cloud.ClusterState clusterState
-
lastUpdatedTime
protected long lastUpdatedTime
-
invalidState
protected boolean invalidState
Set to true if we ever get a BadVersionException so that we can disallow future operations with this instance
-
minStateByteLenForCompression
protected int minStateByteLenForCompression
-
compressor
protected org.apache.solr.common.util.Compressor compressor
-
-
Constructor Detail
-
ZkStateWriter
public ZkStateWriter(org.apache.solr.common.cloud.ZkStateReader zkStateReader, Stats stats, int minStateByteLenForCompression, org.apache.solr.common.util.Compressor compressor)
-
-
Method Detail
-
updateClusterState
public void updateClusterState(Function<org.apache.solr.common.cloud.ClusterState,org.apache.solr.common.cloud.ClusterState> fun)
if any collection is updated not through this class (directly written to ZK, then it needs to be updated locally)
-
enqueueUpdate
public org.apache.solr.common.cloud.ClusterState enqueueUpdate(org.apache.solr.common.cloud.ClusterState prevState, List<ZkWriteCommand> cmds, ZkStateWriter.ZkWriteCallback callback) throws IllegalStateException, Exception
Applies the givenZkWriteCommand
on theprevState
. The modifiedClusterState
is returned and it is expected that the caller will use the returned cluster state for the subsequent invocation of this method.The modified state may be buffered or flushed to ZooKeeper depending on the internal buffering logic of this class. The
hasPendingUpdates()
method may be used to determine if the last enqueue operation resulted in buffered state. The methodwritePendingUpdates()
can be used to force an immediate flush of pending cluster state changes.- Parameters:
prevState
- the cluster state information on which the givencmd
is appliedcmds
- the list ofZkWriteCommand
which specifies the change to be applied to cluster state in atomiccallback
- aZkStateWriter.ZkWriteCallback
object to be used for any callbacks- Returns:
- modified cluster state created after applying
cmd
toprevState
. Ifcmd
is a no-op (NO_OP
) then theprevState
is returned unmodified. - Throws:
IllegalStateException
- if the current instance is no longer usable. The current instance must be discarded.Exception
- on an error in ZK operations or callback. If a flush to ZooKeeper results in aKeeperException.BadVersionException
this instance becomes unusable and must be discarded
-
hasPendingUpdates
public boolean hasPendingUpdates()
-
writeUpdate
public org.apache.solr.common.cloud.ClusterState writeUpdate(ZkWriteCommand command) throws IllegalStateException, org.apache.zookeeper.KeeperException, InterruptedException
- Throws:
IllegalStateException
org.apache.zookeeper.KeeperException
InterruptedException
-
writePendingUpdates
public org.apache.solr.common.cloud.ClusterState writePendingUpdates() throws org.apache.zookeeper.KeeperException, InterruptedException
- Throws:
org.apache.zookeeper.KeeperException
InterruptedException
-
writePendingUpdates
public org.apache.solr.common.cloud.ClusterState writePendingUpdates(Map<String,ZkWriteCommand> updates, boolean resetPendingUpdateCounters) throws IllegalStateException, org.apache.zookeeper.KeeperException, InterruptedException
Writes all pending updates to ZooKeeper and returns the modified cluster state- Returns:
- the modified cluster state
- Throws:
IllegalStateException
- if the current instance is no longer usable and must be discardedorg.apache.zookeeper.KeeperException
- if any ZooKeeper operation results in an errorInterruptedException
- if the current thread is interrupted
-
resetPendingUpdateCounters
public void resetPendingUpdateCounters()
-
getClusterState
public org.apache.solr.common.cloud.ClusterState getClusterState()
- Returns:
- the most up-to-date cluster state until the last enqueueUpdate operation
-
-