use of org.apache.zookeeper.server.DataTree in project zookeeper by apache.
the class FileTxnSnapLogTest method attemptAutoCreateDb.
private void attemptAutoCreateDb(File dataDir, File snapDir, Map<Long, Integer> sessions, String priorAutocreateDbValue, String autoCreateValue, long expectedValue) throws IOException {
sessions.clear();
System.setProperty(FileTxnSnapLog.ZOOKEEPER_DB_AUTOCREATE, autoCreateValue);
FileTxnSnapLog fileTxnSnapLog = new FileTxnSnapLog(dataDir, snapDir);
try {
long zxid = fileTxnSnapLog.restore(new DataTree(), sessions, new FileTxnSnapLog.PlayBackListener() {
@Override
public void onTxnLoaded(TxnHeader hdr, Record rec) {
// empty by default
}
});
Assert.assertEquals("unexpected zxid", expectedValue, zxid);
} finally {
if (priorAutocreateDbValue == null) {
System.clearProperty(FileTxnSnapLog.ZOOKEEPER_DB_AUTOCREATE);
} else {
System.setProperty(FileTxnSnapLog.ZOOKEEPER_DB_AUTOCREATE, priorAutocreateDbValue);
}
}
}
use of org.apache.zookeeper.server.DataTree in project zookeeper by apache.
the class LoadFromLogNoServerTest method testTxnFailure.
/**
* For ZOOKEEPER-1046. Verify if cversion and pzxid if incremented
* after create/delete failure during restore.
*/
@Test
public void testTxnFailure() throws Exception {
try {
ZooKeeperServer.setDigestEnabled(true);
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());
}
long digestBefore = dt.getTreeDigest();
DataNode zk = dt.getNode("/test");
// Make create to fail, then verify cversion.
LOG.info("Attempting to create /test/{}", (count - 1));
doOp(logFile, ZooDefs.OpCode.create, "/test/" + (count - 1), dt, zk, -1);
assertNotEquals(digestBefore, dt.getTreeDigest());
LOG.info("Attempting to create /test/{}", (count - 1));
digestBefore = dt.getTreeDigest();
doOp(logFile, ZooDefs.OpCode.create, "/test/" + (count - 1), dt, zk, zk.stat.getCversion() + 1);
assertNotEquals(digestBefore, dt.getTreeDigest());
LOG.info("Attempting to create /test/{}", (count - 1));
digestBefore = dt.getTreeDigest();
doOp(logFile, ZooDefs.OpCode.multi, "/test/" + (count - 1), dt, zk, zk.stat.getCversion() + 1);
assertNotEquals(digestBefore, dt.getTreeDigest());
LOG.info("Attempting to create /test/{}", (count - 1));
digestBefore = dt.getTreeDigest();
doOp(logFile, ZooDefs.OpCode.multi, "/test/" + (count - 1), dt, zk, -1);
assertNotEquals(digestBefore, dt.getTreeDigest());
// 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);
} finally {
ZooKeeperServer.setDigestEnabled(false);
}
}
use of org.apache.zookeeper.server.DataTree in project zookeeper by apache.
the class Zab1_0Test method testInitialAcceptedCurrent.
@Test
public void testInitialAcceptedCurrent() throws Exception {
File tmpDir = File.createTempFile("test", ".dir", testData);
tmpDir.delete();
tmpDir.mkdir();
try {
FileTxnSnapLog logFactory = new FileTxnSnapLog(tmpDir, tmpDir);
File version2 = new File(tmpDir, "version-2");
version2.mkdir();
logFactory.save(new DataTree(), new ConcurrentHashMap<Long, Integer>(), false);
long zxid = ZxidUtils.makeZxid(3, 3);
logFactory.append(new Request(1, 1, ZooDefs.OpCode.error, new TxnHeader(1, 1, zxid, 1, ZooDefs.OpCode.error), new ErrorTxn(1), zxid));
logFactory.commit();
ZKDatabase zkDb = new ZKDatabase(logFactory);
QuorumPeer peer = QuorumPeer.testingQuorumPeer();
peer.setZKDatabase(zkDb);
peer.setTxnFactory(logFactory);
peer.getLastLoggedZxid();
assertEquals(3, peer.getAcceptedEpoch());
assertEquals(3, peer.getCurrentEpoch());
assertEquals(3, Integer.parseInt(readContentsOfFile(new File(version2, QuorumPeer.CURRENT_EPOCH_FILENAME))));
assertEquals(3, Integer.parseInt(readContentsOfFile(new File(version2, QuorumPeer.ACCEPTED_EPOCH_FILENAME))));
} finally {
TestUtils.deleteFileRecursively(tmpDir);
}
}
use of org.apache.zookeeper.server.DataTree in project zookeeper by apache.
the class QuotaMetricsUtilsTest method testQuotaMetrics_emptyDataTree.
@Test
public void testQuotaMetrics_emptyDataTree() {
// register the metrics
final String nameSuffix = UUID.randomUUID().toString();
registerQuotaMetrics(nameSuffix, new DataTree());
// validate the quota
validateQuotaMetrics(UUID.randomUUID().toString(), null, null, null, null, nameSuffix);
}
use of org.apache.zookeeper.server.DataTree in project zookeeper by apache.
the class FileTxnSnapLogTest method testSnapshotSerializationCompatibility.
void testSnapshotSerializationCompatibility(Boolean digestEnabled, Boolean snappyEnabled) throws IOException {
File dataDir = ClientBase.createEmptyTestDir();
FileTxnSnapLog snaplog = new FileTxnSnapLog(dataDir, dataDir);
DataTree dataTree = new DataTree();
ConcurrentHashMap<Long, Integer> sessions = new ConcurrentHashMap<>();
SnapStream.setStreamMode(snappyEnabled ? SnapStream.StreamMode.SNAPPY : SnapStream.StreamMode.DEFAULT_MODE);
ZooKeeperServer.setDigestEnabled(digestEnabled);
TxnHeader txnHeader = new TxnHeader(1, 1, 1, 1 + 1, ZooDefs.OpCode.create);
CreateTxn txn = new CreateTxn("/" + 1, "data".getBytes(), null, false, 1);
Request request = new Request(1, 1, 1, txnHeader, txn, 1);
dataTree.processTxn(request.getHdr(), request.getTxn());
snaplog.save(dataTree, sessions, true);
int expectedNodeCount = dataTree.getNodeCount();
ZooKeeperServer.setDigestEnabled(!digestEnabled);
snaplog.restore(dataTree, sessions, (hdr, rec, digest) -> {
});
assertEquals(expectedNodeCount, dataTree.getNodeCount());
}
Aggregations