use of org.apache.zookeeper.server.persistence.FileTxnSnapLog in project fabric8 by jboss-fuse.
the class ZKServerFactoryBean method afterPropertiesSet.
public void afterPropertiesSet() throws Exception {
if (purge) {
deleteFilesInDir(getDataLogDir());
deleteFilesInDir(getDataDir());
}
FileTxnSnapLog ftxn = new FileTxnSnapLog(getDataLogDir(), getDataDir());
zooKeeperServer.setTxnLogFactory(ftxn);
zooKeeperServer.setTickTime(getTickTime());
zooKeeperServer.setMinSessionTimeout(getMinSessionTimeout());
zooKeeperServer.setMaxSessionTimeout(getMaxSessionTimeout());
connectionFactory = new NIOServerCnxnFactory();
connectionFactory.configure(getClientPortAddress(), getMaxClientConnections());
connectionFactory.startup(zooKeeperServer);
}
use of org.apache.zookeeper.server.persistence.FileTxnSnapLog in project zookeeper by apache.
the class PurgeTxnLog method purge.
/**
* Purges the snapshot and logs keeping the last num snapshots and the
* corresponding logs. If logs are rolling or a new snapshot is created
* during this process, these newest N snapshots or any data logs will be
* excluded from current purging cycle.
*
* @param dataDir the dir that has the logs
* @param snapDir the dir that has the snapshots
* @param num the number of snapshots to keep
* @throws IOException
*/
public static void purge(File dataDir, File snapDir, int num) throws IOException {
if (num < 3) {
throw new IllegalArgumentException(COUNT_ERR_MSG);
}
FileTxnSnapLog txnLog = new FileTxnSnapLog(dataDir, snapDir);
List<File> snaps = txnLog.findNValidSnapshots(num);
int numSnaps = snaps.size();
if (numSnaps > 0) {
purgeOlderSnapshots(txnLog, snaps.get(numSnaps - 1));
}
}
use of org.apache.zookeeper.server.persistence.FileTxnSnapLog in project zookeeper by apache.
the class QuorumPeerMainTest method testDataDirAndDataLogDir.
@Test
public void testDataDirAndDataLogDir() throws Exception {
File dataDir = createEmptyTestDir();
File dataLogDir = createEmptyTestDir();
// Arrange
try {
QuorumPeerConfig configMock = mock(QuorumPeerConfig.class);
when(configMock.getDataDir()).thenReturn(dataDir);
when(configMock.getDataLogDir()).thenReturn(dataLogDir);
when(configMock.getMetricsProviderClassName()).thenReturn(NullMetricsProvider.class.getName());
QuorumPeer qpMock = mock(QuorumPeer.class);
doCallRealMethod().when(qpMock).setTxnFactory(any(FileTxnSnapLog.class));
when(qpMock.getTxnFactory()).thenCallRealMethod();
InjectableQuorumPeerMain qpMain = new InjectableQuorumPeerMain(qpMock);
// Act
qpMain.runFromConfig(configMock);
// Assert
FileTxnSnapLog txnFactory = qpMain.getQuorumPeer().getTxnFactory();
assertEquals(Paths.get(dataLogDir.getAbsolutePath(), "version-2").toString(), txnFactory.getDataDir().getAbsolutePath());
assertEquals(Paths.get(dataDir.getAbsolutePath(), "version-2").toString(), txnFactory.getSnapDir().getAbsolutePath());
} finally {
FileUtils.deleteDirectory(dataDir);
FileUtils.deleteDirectory(dataLogDir);
}
}
use of org.apache.zookeeper.server.persistence.FileTxnSnapLog in project zookeeper by apache.
the class LeaderBeanTest method setUp.
@BeforeEach
public void setUp() throws IOException, X509Exception {
qp = new QuorumPeer();
quorumVerifierMock = mock(QuorumVerifier.class);
when(quorumVerifierMock.getAllMembers()).thenReturn(getMockedPeerViews(qp.getId()));
qp.setQuorumVerifier(quorumVerifierMock, false);
File tmpDir = ClientBase.createEmptyTestDir();
fileTxnSnapLog = new FileTxnSnapLog(new File(tmpDir, "data"), new File(tmpDir, "data_txnlog"));
ZKDatabase zkDb = new ZKDatabase(fileTxnSnapLog);
zks = new LeaderZooKeeperServer(fileTxnSnapLog, qp, zkDb);
leader = new Leader(qp, zks);
leaderBean = new LeaderBean(leader, zks);
}
use of org.apache.zookeeper.server.persistence.FileTxnSnapLog in project zookeeper by apache.
the class LearnerTest method truncFailTest.
@Test
public void truncFailTest() throws Exception {
final boolean[] exitProcCalled = { false };
ServiceUtils.setSystemExitProcedure(new Consumer<Integer>() {
@Override
public void accept(Integer exitCode) {
exitProcCalled[0] = true;
assertThat("System.exit() was called with invalid exit code", exitCode, equalTo(ExitCode.QUORUM_PACKET_ERROR.getValue()));
}
});
File tmpFile = File.createTempFile("test", ".dir", testData);
tmpFile.delete();
try {
FileTxnSnapLog txnSnapLog = new FileTxnSnapLog(tmpFile, tmpFile);
SimpleLearner sl = new SimpleLearner(txnSnapLog);
long startZxid = sl.zk.getLastProcessedZxid();
// Set up bogus streams
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
sl.leaderOs = BinaryOutputArchive.getArchive(new ByteArrayOutputStream());
// make streams and socket do something innocuous
sl.bufferedOutput = new BufferedOutputStream(System.out);
sl.sock = new Socket();
// fake messages from the server
QuorumPacket qp = new QuorumPacket(Leader.TRUNC, 0, null, null);
oa.writeRecord(qp, null);
// setup the messages to be streamed to follower
sl.leaderIs = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray()));
try {
sl.syncWithLeader(3);
} catch (EOFException e) {
}
sl.zk.shutdown();
assertThat("System.exit() should have been called", exitProcCalled[0], is(true));
} finally {
TestUtils.deleteFileRecursively(tmpFile);
}
}
Aggregations