use of org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint in project bookkeeper by apache.
the class SortedLedgerStorageCheckpointTest method testCheckpoint.
@Test
public void testCheckpoint() throws Exception {
// memory table holds the first checkpoint, but it is not completed yet.
Checkpoint memtableCp = storage.memTable.kvmap.cp;
assertEquals(new TestCheckpoint(0), memtableCp);
// write entries into ledger storage
long lid = System.currentTimeMillis();
storage.setMasterKey(lid, new byte[0]);
for (int i = 0; i < 20; i++) {
storage.addEntry(prepareEntry(lid, i));
}
// simulate journal persists the entries in journal;
checkpointSrc.advanceOffset(100);
// memory table holds the first checkpoint, but it is not completed yet.
memtableCp = storage.memTable.kvmap.cp;
assertEquals(new TestCheckpoint(0), memtableCp);
// trigger a memtable flush
storage.onSizeLimitReached(checkpointSrc.newCheckpoint());
// wait for checkpoint to complete
checkpoints.poll(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
assertEquals(new TestCheckpoint(100), storage.memTable.kvmap.cp);
assertEquals(0, storage.memTable.kvmap.size());
}
use of org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint in project bookkeeper by apache.
the class BookieAccessor method forceFlush.
/**
* Force a bookie to flush its ledger storage.
*/
public static void forceFlush(Bookie b) throws IOException {
CheckpointSourceList source = new CheckpointSourceList(b.journals);
Checkpoint cp = source.newCheckpoint();
b.ledgerStorage.flush();
source.checkpointComplete(cp, true);
}
use of org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint in project bookkeeper by apache.
the class TestSyncThread method testSyncThreadDisksFull.
/**
* Test that if the ledger storage throws
* a disk full exception, the owner of the sync
* thread will be notified.
*/
@Test
public void testSyncThreadDisksFull() throws Exception {
int flushInterval = 100;
ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
conf.setFlushInterval(flushInterval);
CheckpointSource checkpointSource = new DummyCheckpointSource();
final CountDownLatch diskFullLatch = new CountDownLatch(1);
LedgerDirsListener listener = new DummyLedgerDirsListener() {
@Override
public void allDisksFull() {
diskFullLatch.countDown();
}
};
LedgerStorage storage = new DummyLedgerStorage() {
@Override
public void checkpoint(Checkpoint checkpoint) throws IOException {
throw new NoWritableLedgerDirException("Disk full error in sync thread");
}
};
final SyncThread t = new SyncThread(conf, listener, storage, checkpointSource);
t.startCheckpoint(Checkpoint.MAX);
assertTrue("Should have disk full error", diskFullLatch.await(10, TimeUnit.SECONDS));
t.shutdown();
}
use of org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint in project bookkeeper by apache.
the class TestSyncThread method testSyncThreadShutdownOnError.
/**
* Test that if the ledger storage throws a
* runtime exception, the bookie will be told
* to shutdown.
*/
@Test
public void testSyncThreadShutdownOnError() throws Exception {
int flushInterval = 100;
ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
conf.setFlushInterval(flushInterval);
CheckpointSource checkpointSource = new DummyCheckpointSource();
final CountDownLatch fatalLatch = new CountDownLatch(1);
LedgerDirsListener listener = new DummyLedgerDirsListener() {
@Override
public void fatalError() {
fatalLatch.countDown();
}
};
LedgerStorage storage = new DummyLedgerStorage() {
@Override
public void checkpoint(Checkpoint checkpoint) throws IOException {
throw new RuntimeException("Fatal error in sync thread");
}
};
final SyncThread t = new SyncThread(conf, listener, storage, checkpointSource);
t.startCheckpoint(Checkpoint.MAX);
assertTrue("Should have called fatal error", fatalLatch.await(10, TimeUnit.SECONDS));
t.shutdown();
}
use of org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint in project bookkeeper by apache.
the class TestSyncThread method testSyncThreadLongShutdown.
/**
* Test that if a flush is taking a long time,
* the sync thread will not shutdown until it
* has finished.
*/
@Test
public void testSyncThreadLongShutdown() throws Exception {
int flushInterval = 100;
ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
conf.setFlushInterval(flushInterval);
CheckpointSource checkpointSource = new DummyCheckpointSource();
LedgerDirsListener listener = new DummyLedgerDirsListener();
final CountDownLatch checkpointCalledLatch = new CountDownLatch(1);
final CountDownLatch checkpointLatch = new CountDownLatch(1);
final CountDownLatch flushCalledLatch = new CountDownLatch(1);
final CountDownLatch flushLatch = new CountDownLatch(1);
final AtomicBoolean failedSomewhere = new AtomicBoolean(false);
LedgerStorage storage = new DummyLedgerStorage() {
@Override
public void flush() throws IOException {
flushCalledLatch.countDown();
try {
flushLatch.await();
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
LOG.error("Interrupted in flush thread", ie);
failedSomewhere.set(true);
}
}
@Override
public void checkpoint(Checkpoint checkpoint) throws IOException {
checkpointCalledLatch.countDown();
try {
checkpointLatch.await();
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
LOG.error("Interrupted in checkpoint thread", ie);
failedSomewhere.set(true);
}
}
};
final SyncThread t = new SyncThread(conf, listener, storage, checkpointSource);
t.startCheckpoint(Checkpoint.MAX);
assertTrue("Checkpoint should have been called", checkpointCalledLatch.await(10, TimeUnit.SECONDS));
Future<Boolean> done = executor.submit(() -> {
try {
t.shutdown();
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
LOG.error("Interrupted shutting down sync thread", ie);
failedSomewhere.set(true);
return false;
}
return true;
});
checkpointLatch.countDown();
assertFalse("Shutdown shouldn't have finished", done.isDone());
assertTrue("Flush should have been called", flushCalledLatch.await(10, TimeUnit.SECONDS));
assertFalse("Shutdown shouldn't have finished", done.isDone());
flushLatch.countDown();
assertTrue("Shutdown should have finished successfully", done.get(10, TimeUnit.SECONDS));
assertFalse("Shouldn't have failed anywhere", failedSomewhere.get());
}
Aggregations