Search in sources :

Example 6 with FileTxnLog

use of org.apache.zookeeper.server.persistence.FileTxnLog in project zookeeper by apache.

the class ZooKeeperServerTest method testForceSyncDefaultEnabled.

@Test
public void testForceSyncDefaultEnabled() {
    File file = new File("foo.10027c6de");
    FileTxnLog log = new FileTxnLog(file);
    Assert.assertTrue(log.isForceSync());
}
Also used : FileTxnLog(org.apache.zookeeper.server.persistence.FileTxnLog) File(java.io.File) Test(org.junit.Test)

Example 7 with FileTxnLog

use of org.apache.zookeeper.server.persistence.FileTxnLog 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());
    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();
    Assert.assertEquals(1, hdr.getZxid());
    Assert.assertTrue(txn instanceof SetDataTxn);
    iter.next();
    hdr = iter.getHeader();
    txn = iter.getTxn();
    Assert.assertEquals(200, hdr.getZxid());
    Assert.assertTrue(txn instanceof SetDataTxn);
    iter.close();
    ClientBase.recursiveDelete(tmpdir);
}
Also used : FileTxnLog(org.apache.zookeeper.server.persistence.FileTxnLog) Record(org.apache.jute.Record) SetDataTxn(org.apache.zookeeper.txn.SetDataTxn) File(java.io.File) ZKDatabase(org.apache.zookeeper.server.ZKDatabase) TxnIterator(org.apache.zookeeper.server.persistence.TxnLog.TxnIterator) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog) TxnHeader(org.apache.zookeeper.txn.TxnHeader) Test(org.junit.Test)

Aggregations

File (java.io.File)7 FileTxnLog (org.apache.zookeeper.server.persistence.FileTxnLog)7 Test (org.junit.Test)7 TxnIterator (org.apache.zookeeper.server.persistence.TxnLog.TxnIterator)4 ZooKeeper (org.apache.zookeeper.ZooKeeper)3 TxnHeader (org.apache.zookeeper.txn.TxnHeader)3 Record (org.apache.jute.Record)2 ServerCnxnFactory (org.apache.zookeeper.server.ServerCnxnFactory)2 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)2 FileTxnIterator (org.apache.zookeeper.server.persistence.FileTxnLog.FileTxnIterator)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 BinaryInputArchive (org.apache.jute.BinaryInputArchive)1 ZKDatabase (org.apache.zookeeper.server.ZKDatabase)1 FileHeader (org.apache.zookeeper.server.persistence.FileHeader)1 FileSnap (org.apache.zookeeper.server.persistence.FileSnap)1 FileTxnSnapLog (org.apache.zookeeper.server.persistence.FileTxnSnapLog)1 CreateTxn (org.apache.zookeeper.txn.CreateTxn)1 SetDataTxn (org.apache.zookeeper.txn.SetDataTxn)1