public class DataTree extends Object
The tree maintains two parallel data structures: a hashtable that maps from full paths to DataNodes and a tree of DataNodes. All accesses to a path is through the hashtable. The tree is traversed only when serializing to disk.
Modifier and Type | Class and Description |
---|---|
static class |
DataTree.ProcessTxnResult |
class |
DataTree.ZxidDigest
A helper class to maintain the digest meta associated with specific zxid.
|
Modifier and Type | Field and Description |
---|---|
static int |
DIGEST_LOG_INTERVAL |
static int |
DIGEST_LOG_LIMIT |
long |
lastProcessedZxid |
static int |
STAT_OVERHEAD_BYTES
over-the-wire size of znode's stat.
|
Constructor and Description |
---|
DataTree() |
Modifier and Type | Method and Description |
---|---|
int |
aclCacheSize() |
void |
addConfigNode()
create a /zookeeper/config node for maintaining the configuration (membership and quorum system) info for
zookeeper
|
void |
addDigestWatcher(DigestWatcher digestWatcher)
Add digest mismatch event handler.
|
void |
addWatch(String basePath,
Watcher watcher,
int mode) |
long |
approximateDataSize()
Get the size of the nodes based on path and data length.
|
long |
cachedApproximateDataSize() |
boolean |
compareDigest(TxnHeader header,
Record txn,
TxnDigest digest)
Compares the digest of the tree with the digest present in transaction digest.
|
void |
compareSnapshotDigests(long zxid)
Compares the actual tree's digest with that in the snapshot.
|
boolean |
containsWatcher(String path,
Watcher.WatcherType type,
Watcher watcher) |
static void |
copyStat(Stat from,
Stat to) |
static void |
copyStatPersisted(StatPersisted from,
StatPersisted to) |
void |
createNode(String path,
byte[] data,
List<ACL> acl,
long ephemeralOwner,
int parentCVersion,
long zxid,
long time)
Add a new node to the DataTree.
|
void |
createNode(String path,
byte[] data,
List<ACL> acl,
long ephemeralOwner,
int parentCVersion,
long zxid,
long time,
Stat outputStat)
Add a new node to the DataTree.
|
static StatPersisted |
createStat(long zxid,
long time,
long ephemeralOwner)
Create a node stat from the given params.
|
void |
deleteNode(String path,
long zxid)
remove the path from the datatree
|
void |
deserialize(InputArchive ia,
String tag) |
boolean |
deserializeZxidDigest(InputArchive ia,
long startZxidOfSnapshot)
Deserializing the zxid digest from the input stream and update the
digestFromLoadedSnapshot.
|
void |
dumpEphemerals(PrintWriter pwriter)
Write a text dump of all the ephemerals in the datatree.
|
void |
dumpWatches(PrintWriter pwriter,
boolean byPath)
Write a text dump of all the watches on the datatree.
|
void |
dumpWatchesSummary(PrintWriter pwriter)
Summary of the watches on the datatree.
|
List<ACL> |
getACL(DataNode node) |
List<ACL> |
getACL(String path,
Stat stat) |
int |
getAllChildrenNumber(String path) |
List<String> |
getChildren(String path,
Stat stat,
Watcher watcher) |
Set<String> |
getContainers() |
byte[] |
getData(String path,
Stat stat,
Watcher watcher) |
DataTree.ZxidDigest |
getDigestFromLoadedSnapshot() |
List<DataTree.ZxidDigest> |
getDigestLog()
Return all the digests in the historical digest list.
|
Map<Long,Set<String>> |
getEphemerals()
Returns a mapping of session ID to ephemeral znodes.
|
Set<String> |
getEphemerals(long sessionId) |
int |
getEphemeralsCount() |
DataTree.ZxidDigest |
getLastProcessedZxidDigest() |
String |
getMaxPrefixWithQuota(String path)
If there is a quota set, return the appropriate prefix for that quota
Else return null
|
DataNode |
getNode(String path) |
int |
getNodeCount() |
ReferenceCountedACLCache |
getReferenceCountedAclCache() |
Collection<Long> |
getSessions() |
long |
getTreeDigest() |
Set<String> |
getTtls() |
int |
getWatchCount() |
WatchesReport |
getWatches()
Returns a watch report.
|
WatchesPathReport |
getWatchesByPath()
Returns a watch report by path.
|
WatchesSummary |
getWatchesSummary()
Returns a watch summary.
|
DataTree.ProcessTxnResult |
processTxn(TxnHeader header,
Record txn) |
DataTree.ProcessTxnResult |
processTxn(TxnHeader header,
Record txn,
boolean isSubTxn) |
DataTree.ProcessTxnResult |
processTxn(TxnHeader header,
Record txn,
TxnDigest digest) |
void |
removeCnxn(Watcher watcher) |
boolean |
removeWatch(String path,
Watcher.WatcherType type,
Watcher watcher) |
void |
reportDigestMismatch(long zxid)
Reports any mismatch in the transaction digest.
|
void |
serialize(OutputArchive oa,
String tag) |
void |
serializeAcls(OutputArchive oa) |
void |
serializeNodeData(OutputArchive oa,
String path,
DataNode node) |
void |
serializeNodes(OutputArchive oa) |
boolean |
serializeZxidDigest(OutputArchive oa)
Serializing the digest to snapshot, this is done after the data tree
is being serialized, so when we replay the txns and it hits this zxid
we know we should be in a non-fuzzy state, and have the same digest.
|
Stat |
setACL(String path,
List<ACL> acl,
int version) |
void |
setCversionPzxid(String path,
int newCversion,
long zxid)
This method sets the Cversion and Pzxid for the specified node to the
values passed as arguments.
|
Stat |
setData(String path,
byte[] data,
int version,
long zxid,
long time) |
void |
setWatches(long relativeZxid,
List<String> dataWatches,
List<String> existWatches,
List<String> childWatches,
List<String> persistentWatches,
List<String> persistentRecursiveWatches,
Watcher watcher) |
void |
shutdownWatcher() |
Stat |
statNode(String path,
Watcher watcher) |
void |
updateCountBytes(String lastPrefix,
long bytesDiff,
int countDiff)
update the count/count of bytes of this stat datanode
|
public static final int STAT_OVERHEAD_BYTES
public static final int DIGEST_LOG_LIMIT
public static final int DIGEST_LOG_INTERVAL
public volatile long lastProcessedZxid
public Collection<Long> getSessions()
public int getNodeCount()
public int getWatchCount()
public int getEphemeralsCount()
public long approximateDataSize()
public long cachedApproximateDataSize()
public void addConfigNode()
public static void copyStatPersisted(StatPersisted from, StatPersisted to)
public void updateCountBytes(String lastPrefix, long bytesDiff, int countDiff)
lastPrefix
- the path of the node that is quotaed.bytesDiff
- the diff to be added to number of bytescountDiff
- the diff to be added to the countpublic void createNode(String path, byte[] data, List<ACL> acl, long ephemeralOwner, int parentCVersion, long zxid, long time) throws KeeperException.NoNodeException, KeeperException.NodeExistsException
path
- Path for the new node.data
- Data to store in the node.acl
- Node aclsephemeralOwner
- the session id that owns this node. -1 indicates this is not
an ephemeral node.zxid
- Transaction IDtime
- KeeperException.NodeExistsException
KeeperException.NoNodeException
public void createNode(String path, byte[] data, List<ACL> acl, long ephemeralOwner, int parentCVersion, long zxid, long time, Stat outputStat) throws KeeperException.NoNodeException, KeeperException.NodeExistsException
path
- Path for the new node.data
- Data to store in the node.acl
- Node aclsephemeralOwner
- the session id that owns this node. -1 indicates this is not
an ephemeral node.zxid
- Transaction IDtime
- outputStat
- A Stat object to store Stat output results into.KeeperException.NodeExistsException
KeeperException.NoNodeException
public void deleteNode(String path, long zxid) throws KeeperException.NoNodeException
path
- the path to of the node to be deletedzxid
- the current zxidKeeperException.NoNodeException
public Stat setData(String path, byte[] data, int version, long zxid, long time) throws KeeperException.NoNodeException
KeeperException.NoNodeException
public String getMaxPrefixWithQuota(String path)
path
- The ZK path to check for quotapublic byte[] getData(String path, Stat stat, Watcher watcher) throws KeeperException.NoNodeException
KeeperException.NoNodeException
public Stat statNode(String path, Watcher watcher) throws KeeperException.NoNodeException
KeeperException.NoNodeException
public List<String> getChildren(String path, Stat stat, Watcher watcher) throws KeeperException.NoNodeException
KeeperException.NoNodeException
public int getAllChildrenNumber(String path)
public Stat setACL(String path, List<ACL> acl, int version) throws KeeperException.NoNodeException
KeeperException.NoNodeException
public List<ACL> getACL(String path, Stat stat) throws KeeperException.NoNodeException
KeeperException.NoNodeException
public int aclCacheSize()
public DataTree.ProcessTxnResult processTxn(TxnHeader header, Record txn, TxnDigest digest)
public DataTree.ProcessTxnResult processTxn(TxnHeader header, Record txn)
public DataTree.ProcessTxnResult processTxn(TxnHeader header, Record txn, boolean isSubTxn)
public void serializeNodeData(OutputArchive oa, String path, DataNode node) throws IOException
IOException
public void serializeAcls(OutputArchive oa) throws IOException
IOException
public void serializeNodes(OutputArchive oa) throws IOException
IOException
public void serialize(OutputArchive oa, String tag) throws IOException
IOException
public void deserialize(InputArchive ia, String tag) throws IOException
IOException
public void dumpWatchesSummary(PrintWriter pwriter)
pwriter
- the output to write topublic void dumpWatches(PrintWriter pwriter, boolean byPath)
pwriter
- the output to write topublic WatchesReport getWatches()
WatchesReport
public WatchesPathReport getWatchesByPath()
WatchesPathReport
public WatchesSummary getWatchesSummary()
WatchesSummary
public void dumpEphemerals(PrintWriter pwriter)
pwriter
- the output to write topublic void shutdownWatcher()
public Map<Long,Set<String>> getEphemerals()
public void removeCnxn(Watcher watcher)
public void setWatches(long relativeZxid, List<String> dataWatches, List<String> existWatches, List<String> childWatches, List<String> persistentWatches, List<String> persistentRecursiveWatches, Watcher watcher)
public void setCversionPzxid(String path, int newCversion, long zxid) throws KeeperException.NoNodeException
path
- Full path to the znode whose Cversion needs to be modified.
A "/" at the end of the path is ignored.newCversion
- Value to be assigned to Cversionzxid
- Value to be assigned to PzxidKeeperException.NoNodeException
- If znode not found.public boolean containsWatcher(String path, Watcher.WatcherType type, Watcher watcher)
public boolean removeWatch(String path, Watcher.WatcherType type, Watcher watcher)
public ReferenceCountedACLCache getReferenceCountedAclCache()
public boolean serializeZxidDigest(OutputArchive oa) throws IOException
oa
- the output stream to write toIOException
public boolean deserializeZxidDigest(InputArchive ia, long startZxidOfSnapshot) throws IOException
ia
- the input stream to read fromstartZxidOfSnapshot
- the zxid of snapshot fileIOException
public void compareSnapshotDigests(long zxid)
zxid
- zxidpublic boolean compareDigest(TxnHeader header, Record txn, TxnDigest digest)
header
- transaction header being appliedtxn
- transactiondigest
- transaction digestpublic void reportDigestMismatch(long zxid)
zxid
- zxid for which the error is being reported.public long getTreeDigest()
public DataTree.ZxidDigest getLastProcessedZxidDigest()
public DataTree.ZxidDigest getDigestFromLoadedSnapshot()
public void addDigestWatcher(DigestWatcher digestWatcher)
digestWatcher
- the handler to addpublic List<DataTree.ZxidDigest> getDigestLog()
public static StatPersisted createStat(long zxid, long time, long ephemeralOwner)
zxid
- the zxid associated with the txntime
- the time when the txn is createdephemeralOwner
- the owner if the node is an ephemeralCopyright © 2008–2020 The Apache Software Foundation. All rights reserved.