use of org.apache.zookeeper.server.persistence.FileTxnSnapLog in project zookeeper by apache.
the class PurgeTxnTest method testSnapFilesGreaterThanToRetain.
/**
* Tests purge where the data directory contains old snapshots and data
* logs, newest snapshots and data logs, (newest + n) snapshots and data
* logs
*/
@Test
public void testSnapFilesGreaterThanToRetain() throws Exception {
int nRecentCount = 4;
int fileAboveRecentCount = 4;
int fileToPurgeCount = 2;
AtomicInteger offset = new AtomicInteger(0);
File version2 = new File(tmpDir.toString(), "version-2");
assertTrue(version2.mkdir(), "Failed to create version_2 dir:" + version2.toString());
List<File> snapsToPurge = new ArrayList<File>();
List<File> logsToPurge = new ArrayList<File>();
List<File> snaps = new ArrayList<File>();
List<File> logs = new ArrayList<File>();
List<File> snapsAboveRecentFiles = new ArrayList<File>();
List<File> logsAboveRecentFiles = new ArrayList<File>();
createDataDirFiles(offset, fileToPurgeCount, false, version2, snapsToPurge, logsToPurge);
createDataDirFiles(offset, nRecentCount, false, version2, snaps, logs);
// log that precedes first retained snapshot is also retained
logs.add(logsToPurge.remove(0));
createDataDirFiles(offset, fileAboveRecentCount, false, version2, snapsAboveRecentFiles, logsAboveRecentFiles);
/**
* The newest log file preceding the oldest retained snapshot is not removed as it may
* contain transactions newer than the oldest snapshot.
*/
logsToPurge.remove(0);
FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
PurgeTxnLog.purgeOlderSnapshots(txnLog, snaps.get(snaps.size() - 1));
txnLog.close();
verifyFilesAfterPurge(snapsToPurge, false);
verifyFilesAfterPurge(logsToPurge, false);
verifyFilesAfterPurge(snaps, true);
verifyFilesAfterPurge(logs, true);
verifyFilesAfterPurge(snapsAboveRecentFiles, true);
verifyFilesAfterPurge(logsAboveRecentFiles, true);
}
use of org.apache.zookeeper.server.persistence.FileTxnSnapLog in project zookeeper by apache.
the class PurgeTxnTest method testSnapFilesLessThanToRetain.
/**
* Tests purge where the data directory contains old snapshots and data
* logs, newest snapshots and data logs
*/
@Test
public void testSnapFilesLessThanToRetain() throws Exception {
int nRecentCount = 4;
int fileToPurgeCount = 2;
AtomicInteger offset = new AtomicInteger(0);
File version2 = new File(tmpDir.toString(), "version-2");
assertTrue(version2.mkdir(), "Failed to create version_2 dir:" + version2.toString());
List<File> snapsToPurge = new ArrayList<File>();
List<File> logsToPurge = new ArrayList<File>();
List<File> snaps = new ArrayList<File>();
List<File> logs = new ArrayList<File>();
createDataDirFiles(offset, fileToPurgeCount, false, version2, snapsToPurge, logsToPurge);
createDataDirFiles(offset, nRecentCount, false, version2, snaps, logs);
// log that precedes first retained snapshot is also retained
logs.add(logsToPurge.remove(0));
/**
* The newest log file preceding the oldest retained snapshot is not removed as it may
* contain transactions newer than the oldest snapshot.
*/
logsToPurge.remove(0);
FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
PurgeTxnLog.purgeOlderSnapshots(txnLog, snaps.get(snaps.size() - 1));
txnLog.close();
verifyFilesAfterPurge(snapsToPurge, false);
verifyFilesAfterPurge(logsToPurge, false);
verifyFilesAfterPurge(snaps, true);
verifyFilesAfterPurge(logs, true);
}
use of org.apache.zookeeper.server.persistence.FileTxnSnapLog in project zookeeper by apache.
the class PrepRequestProcessorTest method testReconfigWithAnotherOutstandingChange.
@Test
public void testReconfigWithAnotherOutstandingChange() throws Exception {
QuorumPeerConfig.setReconfigEnabled(true);
QuorumPeerConfig.setStandaloneEnabled(false);
QuorumPeer qp = new QuorumPeer();
QuorumVerifier quorumVerifierMock = mock(QuorumVerifier.class);
when(quorumVerifierMock.getAllMembers()).thenReturn(LeaderBeanTest.getMockedPeerViews(qp.getId()));
qp.setQuorumVerifier(quorumVerifierMock, false);
FileTxnSnapLog snapLog = new FileTxnSnapLog(tmpDir, tmpDir);
LeaderZooKeeperServer lzks = new LeaderZooKeeperServer(snapLog, qp, new ZKDatabase(snapLog));
qp.leader = new Leader(qp, lzks);
lzks.sessionTracker = new MySessionTracker();
ZooKeeperServer.setDigestEnabled(true);
processor = new PrepRequestProcessor(lzks, new MyRequestProcessor());
Record record = new CreateRequest("/foo", "data".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT.toFlag());
pLatch = new CountDownLatch(1);
processor.pRequest(createRequest(record, OpCode.create, false));
assertTrue(pLatch.await(5, TimeUnit.SECONDS), "request hasn't been processed in chain");
String newMember = "server.0=localhost:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ":participant";
record = new ReconfigRequest(null, null, newMember, 0);
pLatch = new CountDownLatch(1);
processor.pRequest(createRequest(record, OpCode.reconfig, true));
assertTrue(pLatch.await(5, TimeUnit.SECONDS), "request hasn't been processed in chain");
// Verifies that there was no error.
assertEquals(outcome.getHdr().getType(), OpCode.reconfig);
}
use of org.apache.zookeeper.server.persistence.FileTxnSnapLog in project zookeeper by apache.
the class TxnLogCountTest method testTxnLogCount.
/**
* Test ZkDatabase's txnCount
*/
@Test
public void testTxnLogCount() throws IOException {
File tmpDir = ClientBase.createTmpDir();
FileTxnSnapLog snapLog = new FileTxnSnapLog(tmpDir, tmpDir);
ZKDatabase zkDatabase = new ZKDatabase(snapLog);
int txnRequestCnt = 10;
int nonTxnRequestCnt = 10;
for (int i = 0; i < txnRequestCnt && zkDatabase.append(mockTxnRequest()); i++) {
}
assertEquals(txnRequestCnt, zkDatabase.getTxnCount());
for (int i = 0; i < nonTxnRequestCnt && !zkDatabase.append(mockNonTxnRequest()); i++) {
}
assertEquals(txnRequestCnt, zkDatabase.getTxnCount());
}
use of org.apache.zookeeper.server.persistence.FileTxnSnapLog in project zookeeper by apache.
the class TruncateTest method testTruncationStreamReset.
@Test
public void testTruncationStreamReset() throws Exception {
File tmpdir = ClientBase.createTmpDir();
FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpdir, tmpdir);
ZKDatabase zkdb = new ZKDatabase(snaplog);
// make sure to snapshot, so that we have something there when
// truncateLog reloads the db
snaplog.save(zkdb.getDataTree(), zkdb.getSessionWithTimeOuts(), false);
for (int i = 1; i <= 100; i++) {
append(zkdb, i);
}
zkdb.truncateLog(1);
append(zkdb, 200);
zkdb.close();
// verify that the truncation and subsequent append were processed
// correctly
FileTxnLog txnlog = new FileTxnLog(new File(tmpdir, "version-2"));
TxnIterator iter = txnlog.read(1);
TxnHeader hdr = iter.getHeader();
Record txn = iter.getTxn();
assertEquals(1, hdr.getZxid());
assertTrue(txn instanceof SetDataTxn);
iter.next();
hdr = iter.getHeader();
txn = iter.getTxn();
assertEquals(200, hdr.getZxid());
assertTrue(txn instanceof SetDataTxn);
iter.close();
ClientBase.recursiveDelete(tmpdir);
}
Aggregations