public class ZkStateWriter extends Object
enqueueUpdate(ClusterState, ZkWriteCommand, ZkWriteCallback)
method. The class buffers updates
to reduce the number of writes to ZK. The buffered updates are flushed during enqueueUpdate
automatically if necessary. The writePendingUpdates()
can be used to force flush any pending updates.
If either enqueueUpdate(ClusterState, ZkWriteCommand, ZkWriteCallback)
or writePendingUpdates()
throws a KeeperException.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.Modifier and Type | Class and Description |
---|---|
static interface |
ZkStateWriter.ZkWriteCallback |
Modifier and Type | Field and Description |
---|---|
protected ClusterState |
clusterState |
protected boolean |
invalidState
Set to true if we ever get a BadVersionException so that we can disallow future operations
with this instance
|
protected boolean |
isClusterStateModified |
protected String |
lastCollectionName |
protected int |
lastStateFormat |
protected long |
lastUpdatedTime |
static ZkWriteCommand |
NO_OP
Represents a no-op
ZkWriteCommand which will result in no modification to cluster state |
protected ZkStateReader |
reader |
protected Overseer.Stats |
stats |
protected Map<String,DocCollection> |
updates |
Constructor and Description |
---|
ZkStateWriter(ZkStateReader zkStateReader,
Overseer.Stats stats) |
Modifier and Type | Method and Description |
---|---|
ClusterState |
enqueueUpdate(ClusterState prevState,
ZkWriteCommand cmd,
ZkStateWriter.ZkWriteCallback callback)
Applies the given
ZkWriteCommand on the prevState . |
ClusterState |
getClusterState() |
long |
getLastUpdatedTime() |
boolean |
hasPendingUpdates() |
protected boolean |
maybeFlushAfter(ZkWriteCommand cmd)
Logic to decide a flush after processing a ZkWriteCommand
|
protected boolean |
maybeFlushBefore(ZkWriteCommand cmd)
Logic to decide a flush before processing a ZkWriteCommand
|
ClusterState |
writePendingUpdates()
Writes all pending updates to ZooKeeper and returns the modified cluster state
|
public static ZkWriteCommand NO_OP
ZkWriteCommand
which will result in no modification to cluster stateprotected final ZkStateReader reader
protected final Overseer.Stats stats
protected Map<String,DocCollection> updates
protected ClusterState clusterState
protected boolean isClusterStateModified
protected long lastUpdatedTime
protected int lastStateFormat
protected String lastCollectionName
protected boolean invalidState
public ZkStateWriter(ZkStateReader zkStateReader, Overseer.Stats stats)
public ClusterState enqueueUpdate(ClusterState prevState, ZkWriteCommand cmd, ZkStateWriter.ZkWriteCallback callback) throws IllegalStateException, Exception
ZkWriteCommand
on the prevState
. The modified
ClusterState
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 method writePendingUpdates()
can
be used to force an immediate flush of pending cluster state changes.
prevState
- the cluster state information on which the given cmd
is appliedcmd
- the ZkWriteCommand
which specifies the change to be applied to cluster statecallback
- a ZkStateWriter.ZkWriteCallback
object to be used
for any callbackscmd
to prevState
. If
cmd
is a no-op (NO_OP
) then the prevState
is returned unmodified.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 a KeeperException.BadVersionException
this instance becomes unusable and
must be discardedprotected boolean maybeFlushBefore(ZkWriteCommand cmd)
cmd
- the ZkWriteCommand instanceprotected boolean maybeFlushAfter(ZkWriteCommand cmd)
cmd
- the ZkWriteCommand instancepublic boolean hasPendingUpdates()
public ClusterState writePendingUpdates() throws IllegalStateException, org.apache.zookeeper.KeeperException, InterruptedException
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 interruptedpublic long getLastUpdatedTime()
public ClusterState getClusterState()
Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.