Search in sources :

Example 21 with DiskChecker

use of org.apache.bookkeeper.util.DiskChecker in project bookkeeper by apache.

the class DbLedgerStorage method readLedgerIndexEntries.

/**
 * Reads ledger index entries to get list of entry-logger that contains given ledgerId.
 *
 * @param ledgerId
 * @param serverConf
 * @param processor
 * @throws IOException
 */
public static void readLedgerIndexEntries(long ledgerId, ServerConfiguration serverConf, LedgerLoggerProcessor processor) throws IOException {
    checkNotNull(serverConf, "ServerConfiguration can't be null");
    checkNotNull(processor, "LedgerLoggger info processor can't null");
    LedgerDirsManager ledgerDirsManager = new LedgerDirsManager(serverConf, serverConf.getLedgerDirs(), new DiskChecker(serverConf.getDiskUsageThreshold(), serverConf.getDiskUsageWarnThreshold()));
    String ledgerBasePath = ledgerDirsManager.getAllLedgerDirs().get(0).toString();
    EntryLocationIndex entryLocationIndex = new EntryLocationIndex(serverConf, (path, dbConfigType, conf1) -> new KeyValueStorageRocksDB(path, DbConfigType.Small, conf1, true), ledgerBasePath, NullStatsLogger.INSTANCE);
    try {
        long lastEntryId = entryLocationIndex.getLastEntryInLedger(ledgerId);
        for (long currentEntry = 0; currentEntry <= lastEntryId; currentEntry++) {
            long offset = entryLocationIndex.getLocation(ledgerId, currentEntry);
            if (offset <= 0) {
                // entry not found in this bookie
                continue;
            }
            long entryLogId = offset >> 32L;
            long position = offset & 0xffffffffL;
            processor.process(currentEntry, entryLogId, position);
        }
    } finally {
        entryLocationIndex.close();
    }
}
Also used : LedgerDirsManager(org.apache.bookkeeper.bookie.LedgerDirsManager) DiskChecker(org.apache.bookkeeper.util.DiskChecker) ByteString(com.google.protobuf.ByteString)

Aggregations

DiskChecker (org.apache.bookkeeper.util.DiskChecker)21 File (java.io.File)17 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)12 Test (org.junit.Test)11 LedgerDirsManager (org.apache.bookkeeper.bookie.LedgerDirsManager)7 ByteBuf (io.netty.buffer.ByteBuf)4 IOException (java.io.IOException)4 Checkpoint (org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint)4 LedgerManager (org.apache.bookkeeper.meta.LedgerManager)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 BookieShell (org.apache.bookkeeper.bookie.BookieShell)3 Before (org.junit.Before)3 InterleavedLedgerStorage (org.apache.bookkeeper.bookie.InterleavedLedgerStorage)2 Journal (org.apache.bookkeeper.bookie.Journal)2 NoWritableLedgerDirException (org.apache.bookkeeper.bookie.LedgerDirsManager.NoWritableLedgerDirException)2 LogMark (org.apache.bookkeeper.bookie.LogMark)2 TestStatsProvider (org.apache.bookkeeper.test.TestStatsProvider)2 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 ByteString (com.google.protobuf.ByteString)1 FileNotFoundException (java.io.FileNotFoundException)1