Search in sources :

Example 1 with Checkpoint

use of org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint in project bookkeeper by apache.

the class DbLedgerStorage method flush.

@Override
public void flush() throws IOException {
    Checkpoint cp = checkpointSource.newCheckpoint();
    checkpoint(cp);
    checkpointSource.checkpointComplete(cp, true);
}
Also used : Checkpoint(org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint)

Example 2 with Checkpoint

use of org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint in project bookkeeper by apache.

the class EntryMemTable method addEntry.

/**
 * Write an update.
 *
 * @param entry
 * @return approximate size of the passed key and value.
 * @throws IOException
 */
public long addEntry(long ledgerId, long entryId, final ByteBuffer entry, final CacheCallback cb) throws IOException {
    long size = 0;
    long startTimeNanos = MathUtils.nowInNano();
    boolean success = false;
    try {
        if (isSizeLimitReached() || (!previousFlushSucceeded.get())) {
            Checkpoint cp = snapshot();
            if ((null != cp) || (!previousFlushSucceeded.get())) {
                cb.onSizeLimitReached(cp);
            } else {
                throttleWriters();
            }
        }
        this.lock.readLock().lock();
        try {
            EntryKeyValue toAdd = cloneWithAllocator(ledgerId, entryId, entry);
            size = internalAdd(toAdd);
        } finally {
            this.lock.readLock().unlock();
        }
        success = true;
        return size;
    } finally {
        if (success) {
            putEntryStats.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
        } else {
            putEntryStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
        }
    }
}
Also used : Checkpoint(org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint)

Example 3 with Checkpoint

use of org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint in project bookkeeper by apache.

the class SyncThread method flush.

private void flush() {
    Checkpoint checkpoint = checkpointSource.newCheckpoint();
    try {
        ledgerStorage.flush();
    } catch (NoWritableLedgerDirException e) {
        log.error("No writeable ledger directories", e);
        dirsListener.allDisksFull();
        return;
    } catch (IOException e) {
        log.error("Exception flushing ledgers", e);
        return;
    }
    if (disableCheckpoint) {
        return;
    }
    log.info("Flush ledger storage at checkpoint {}.", checkpoint);
    try {
        checkpointSource.checkpointComplete(checkpoint, false);
    } catch (IOException e) {
        log.error("Exception marking checkpoint as complete", e);
        dirsListener.allDisksFull();
    }
}
Also used : NoWritableLedgerDirException(org.apache.bookkeeper.bookie.LedgerDirsManager.NoWritableLedgerDirException) Checkpoint(org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint) IOException(java.io.IOException)

Example 4 with Checkpoint

use of org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint in project bookkeeper by apache.

the class InterleavedLedgerStorage method onRotateEntryLog.

@Override
public void onRotateEntryLog() {
    // for interleaved ledger storage, we request a checkpoint when rotating a entry log file.
    // the checkpoint represent the point that all the entries added before this point are already
    // in ledger storage and ready to be synced to disk.
    // TODO: we could consider remove checkpointSource and checkpointSouce#newCheckpoint
    // later if we provide kind of LSN (Log/Journal Squeuence Number)
    // mechanism when adding entry. {@link https://github.com/apache/bookkeeper/issues/279}
    Checkpoint checkpoint = checkpointSource.newCheckpoint();
    checkpointer.startCheckpoint(checkpoint);
}
Also used : Checkpoint(org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint)

Example 5 with Checkpoint

use of org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint in project bookkeeper by apache.

the class SortedLedgerStorageCheckpointTest method testCheckpointAfterEntryLogRotated.

@Test
public void testCheckpointAfterEntryLogRotated() 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);
    assertEquals(20, storage.memTable.kvmap.size());
    final CountDownLatch readyLatch = new CountDownLatch(1);
    storage.getScheduler().submit(() -> {
        try {
            readyLatch.await();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    });
    // simulate entry log is rotated (due to compaction)
    storage.entryLogger.rollLog();
    long leastUnflushedLogId = storage.entryLogger.getLeastUnflushedLogId();
    long currentLogId = storage.entryLogger.getCurrentLogId();
    log.info("Least unflushed entry log : current = {}, leastUnflushed = {}", currentLogId, leastUnflushedLogId);
    readyLatch.countDown();
    assertNull(checkpoints.poll());
    assertEquals(new TestCheckpoint(0), storage.memTable.kvmap.cp);
    assertEquals(20, storage.memTable.kvmap.size());
    // trigger a memtable flush
    storage.onSizeLimitReached(checkpointSrc.newCheckpoint());
    assertEquals(new TestCheckpoint(100), checkpoints.poll(Long.MAX_VALUE, TimeUnit.MILLISECONDS));
    // all the entries are flushed out
    assertEquals(new TestCheckpoint(100), storage.memTable.kvmap.cp);
    assertEquals(0, storage.memTable.kvmap.size());
    assertTrue("current log " + currentLogId + " contains entries added from memtable should be forced to disk" + " but least unflushed log is " + storage.entryLogger.getLeastUnflushedLogId(), storage.entryLogger.getLeastUnflushedLogId() > currentLogId);
}
Also used : Checkpoint(org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint) CountDownLatch(java.util.concurrent.CountDownLatch) Checkpoint(org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint) Test(org.junit.Test)

Aggregations

Checkpoint (org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint)13 Test (org.junit.Test)6 CountDownLatch (java.util.concurrent.CountDownLatch)4 LedgerDirsListener (org.apache.bookkeeper.bookie.LedgerDirsManager.LedgerDirsListener)4 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)4 IOException (java.io.IOException)2 NoWritableLedgerDirException (org.apache.bookkeeper.bookie.LedgerDirsManager.NoWritableLedgerDirException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Batch (org.apache.bookkeeper.bookie.storage.ldb.KeyValueStorage.Batch)1