Search in sources :

Example 6 with DataTree

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);
}
Also used : DataTree(org.apache.zookeeper.server.DataTree) DataNode(org.apache.zookeeper.server.DataNode) File(java.io.File) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog) Test(org.junit.Test)

Example 7 with DataTree

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, "/");
}
Also used : BinaryInputArchive(org.apache.jute.BinaryInputArchive) HashMap(java.util.HashMap) DataTree(org.apache.zookeeper.server.DataTree) IOException(java.io.IOException) FileHeader(org.apache.zookeeper.server.persistence.FileHeader) FileInputStream(java.io.FileInputStream)

Example 8 with DataTree

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);
}
Also used : DataTree(org.apache.zookeeper.server.DataTree) StatsTrack(org.apache.zookeeper.StatsTrack) Test(org.junit.jupiter.api.Test)

Example 9 with DataTree

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);
}
Also used : DataTree(org.apache.zookeeper.server.DataTree) StatsTrack(org.apache.zookeeper.StatsTrack) Test(org.junit.jupiter.api.Test)

Example 10 with DataTree

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);
}
Also used : DataTree(org.apache.zookeeper.server.DataTree) StatsTrack(org.apache.zookeeper.StatsTrack) Test(org.junit.jupiter.api.Test)

Aggregations

DataTree (org.apache.zookeeper.server.DataTree)15 Test (org.junit.jupiter.api.Test)9 File (java.io.File)7 TxnHeader (org.apache.zookeeper.txn.TxnHeader)5 Record (org.apache.jute.Record)3 StatsTrack (org.apache.zookeeper.StatsTrack)3 DataNode (org.apache.zookeeper.server.DataNode)3 FileTxnSnapLog (org.apache.zookeeper.server.persistence.FileTxnSnapLog)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 BinaryInputArchive (org.apache.jute.BinaryInputArchive)2 Request (org.apache.zookeeper.server.Request)2 CreateTxn (org.apache.zookeeper.txn.CreateTxn)2 FileOutputStream (java.io.FileOutputStream)1 HashMap (java.util.HashMap)1 BinaryOutputArchive (org.apache.jute.BinaryOutputArchive)1 InputArchive (org.apache.jute.InputArchive)1 OutputArchive (org.apache.jute.OutputArchive)1 ZKDatabase (org.apache.zookeeper.server.ZKDatabase)1