use of org.apache.zookeeper.server.DataTree in project zookeeper by apache.
the class LoadFromLogTest method testTxnFailure.
/**
* For ZOOKEEPER-1046. Verify if cversion and pzxid if incremented
* after create/delete failure during restore.
*/
@Test
public void testTxnFailure() throws Exception {
long count = 1;
File tmpDir = ClientBase.createTmpDir();
FileTxnSnapLog logFile = new FileTxnSnapLog(tmpDir, tmpDir);
DataTree dt = new DataTree();
dt.createNode("/test", new byte[0], null, 0, -1, 1, 1);
for (count = 1; count <= 3; count++) {
dt.createNode("/test/" + count, new byte[0], null, 0, -1, count, Time.currentElapsedTime());
}
DataNode zk = dt.getNode("/test");
// Make create to fail, then verify cversion.
LOG.info("Attempting to create " + "/test/" + (count - 1));
doOp(logFile, OpCode.create, "/test/" + (count - 1), dt, zk, -1);
LOG.info("Attempting to create " + "/test/" + (count - 1));
doOp(logFile, OpCode.create, "/test/" + (count - 1), dt, zk, zk.stat.getCversion() + 1);
LOG.info("Attempting to create " + "/test/" + (count - 1));
doOp(logFile, OpCode.multi, "/test/" + (count - 1), dt, zk, zk.stat.getCversion() + 1);
LOG.info("Attempting to create " + "/test/" + (count - 1));
doOp(logFile, OpCode.multi, "/test/" + (count - 1), dt, zk, -1);
// Make delete fo fail, then verify cversion.
// this doesn't happen anymore, we only set the cversion on create
// LOG.info("Attempting to delete " + "/test/" + (count + 1));
// doOp(logFile, OpCode.delete, "/test/" + (count + 1), dt, zk);
}
use of org.apache.zookeeper.server.DataTree in project helix by apache.
the class ZKLogFormatter method readSnapshotLog.
private static void readSnapshotLog(String snapshotPath) throws Exception {
FileInputStream fis = new FileInputStream(snapshotPath);
BinaryInputArchive ia = BinaryInputArchive.getArchive(fis);
Map<Long, Integer> sessions = new HashMap<Long, Integer>();
DataTree dt = new DataTree();
FileHeader header = new FileHeader();
header.deserialize(ia, "fileheader");
if (header.getMagic() != FileSnap.SNAP_MAGIC) {
throw new IOException("mismatching magic headers " + header.getMagic() + " != " + FileSnap.SNAP_MAGIC);
}
SerializeUtils.deserializeSnapshot(dt, ia, sessions);
if (bw != null) {
bw.write(sessions.toString());
bw.newLine();
} else {
System.out.println(sessions);
}
traverse(dt, 1, "/");
}
use of org.apache.zookeeper.server.DataTree in project zookeeper by apache.
the class QuotaMetricsUtilsTest method testQuotaMetrics_noUsage.
@Test
public void testQuotaMetrics_noUsage() throws Exception {
// register the metrics
final String nameSuffix = UUID.randomUUID().toString();
final DataTree dt = new DataTree();
registerQuotaMetrics(nameSuffix, dt);
// build the data tree
final String ns = UUID.randomUUID().toString();
final long countLimit = 20;
final long bytesLimit = 200;
final long countHardLimit = -1;
final long bytesHardLimit = -1;
// the node itself is always counted
final long countUsage = 1;
final long bytesUsage = 0;
final StatsTrack limitTrack = buildLimitStatsTrack(countLimit, bytesLimit, countHardLimit, bytesHardLimit);
final StatsTrack usageTrack = buildUsageStatsTrack(countUsage, bytesUsage);
buildDataTree("/" + ns, limitTrack, usageTrack, dt);
// validate the quota
validateQuotaMetrics(ns, countLimit, bytesLimit, countUsage, bytesUsage, nameSuffix);
}
use of org.apache.zookeeper.server.DataTree in project zookeeper by apache.
the class QuotaMetricsUtilsTest method testQuotaMetrics_multipleQuotaSubtrees.
@Test
public void testQuotaMetrics_multipleQuotaSubtrees() throws Exception {
// register the metrics
final String nameSuffix = UUID.randomUUID().toString();
final DataTree dt = new DataTree();
registerQuotaMetrics(nameSuffix, dt);
// build the data tree
final String ns = UUID.randomUUID().toString();
final long countLimit1 = 10;
final long bytesLimit1 = 100;
final long countHardLimit1 = 5;
final long bytesHardLimit1 = 50;
final long countUsage1 = 5;
final long bytesUsage1 = 40;
final StatsTrack limitTrack1 = buildLimitStatsTrack(countLimit1, bytesLimit1, countHardLimit1, bytesHardLimit1);
final StatsTrack usageTrack1 = buildUsageStatsTrack(countUsage1, bytesUsage1);
buildDataTree("/" + ns + "/a/b", limitTrack1, usageTrack1, dt);
// validate the quota metrics
validateQuotaMetrics(ns, countHardLimit1, bytesHardLimit1, countUsage1, bytesUsage1, nameSuffix);
// update the data tree with another quota subtree
final long countLimit2 = 20;
final long bytesLimit2 = 200;
final long countHardLimit2 = 10;
final long bytesHardLimit2 = 100;
final long countUsage2 = 9;
final long bytesUsage2 = 80;
final StatsTrack limitTrack2 = buildLimitStatsTrack(countLimit2, bytesLimit2, countHardLimit2, bytesHardLimit2);
final StatsTrack usageTrack2 = buildUsageStatsTrack(countUsage2, bytesUsage2);
buildDataTree("/" + ns + "/a/c/d", limitTrack2, usageTrack2, dt);
// validate the quota metrics
validateQuotaMetrics(ns, countHardLimit1 + countHardLimit2, bytesHardLimit1 + bytesHardLimit2, countUsage1 + countUsage2, bytesUsage1 + bytesUsage2, nameSuffix);
}
use of org.apache.zookeeper.server.DataTree in project zookeeper by apache.
the class QuotaMetricsUtilsTest method testQuotaMetrics_singleQuotaSubtree.
@Test
public void testQuotaMetrics_singleQuotaSubtree() throws Exception {
// register the metrics
final String nameSuffix = UUID.randomUUID().toString();
final DataTree dt = new DataTree();
registerQuotaMetrics(nameSuffix, dt);
// build the data tree
final String ns = UUID.randomUUID().toString();
final long countLimit = 10;
final long bytesLimit = 100;
final long countHardLimit = 5;
final long bytesHardLimit = 50;
final long countUsage = 5;
final long bytesUsage = 40;
final StatsTrack limitTrack = buildLimitStatsTrack(countLimit, bytesLimit, countHardLimit, bytesHardLimit);
final StatsTrack usageTrack = buildUsageStatsTrack(countUsage, bytesUsage);
buildDataTree("/" + ns, limitTrack, usageTrack, dt);
// validate the quota metrics
validateQuotaMetrics(ns, countHardLimit, bytesHardLimit, countUsage, bytesUsage, nameSuffix);
}
Aggregations