Search in sources :

Example 1 with DefaultEntryLogger

use of org.apache.bookkeeper.bookie.DefaultEntryLogger in project bookkeeper by apache.

the class LocationsIndexRebuildOp method initiate.

public void initiate() throws IOException {
    LOG.info("Starting locations index rebuilding");
    // Move locations index to a backup directory
    String basePath = BookieImpl.getCurrentDirectory(conf.getLedgerDirs()[0]).toString();
    Path currentPath = FileSystems.getDefault().getPath(basePath, "locations");
    String timestamp = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date());
    Path backupPath = FileSystems.getDefault().getPath(basePath, "locations.BACKUP-" + timestamp);
    Files.move(currentPath, backupPath);
    LOG.info("Created locations index backup at {}", backupPath);
    long startTime = System.nanoTime();
    DefaultEntryLogger entryLogger = new DefaultEntryLogger(conf, new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold())));
    Set<Long> entryLogs = entryLogger.getEntryLogsSet();
    Set<Long> activeLedgers = getActiveLedgers(conf, KeyValueStorageRocksDB.factory, basePath);
    LOG.info("Found {} active ledgers in ledger manager", activeLedgers.size());
    KeyValueStorage newIndex = KeyValueStorageRocksDB.factory.newKeyValueStorage(basePath, "locations", DbConfigType.Default, conf);
    int totalEntryLogs = entryLogs.size();
    int completedEntryLogs = 0;
    LOG.info("Scanning {} entry logs", totalEntryLogs);
    for (long entryLogId : entryLogs) {
        entryLogger.scanEntryLog(entryLogId, new EntryLogScanner() {

            @Override
            public void process(long ledgerId, long offset, ByteBuf entry) throws IOException {
                long entryId = entry.getLong(8);
                // Actual location indexed is pointing past the entry size
                long location = (entryLogId << 32L) | (offset + 4);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Rebuilding {}:{} at location {} / {}", ledgerId, entryId, location >> 32, location & (Integer.MAX_VALUE - 1));
                }
                // Update the ledger index page
                LongPairWrapper key = LongPairWrapper.get(ledgerId, entryId);
                LongWrapper value = LongWrapper.get(location);
                newIndex.put(key.array, value.array);
            }

            @Override
            public boolean accept(long ledgerId) {
                return activeLedgers.contains(ledgerId);
            }
        });
        ++completedEntryLogs;
        LOG.info("Completed scanning of log {}.log -- {} / {}", Long.toHexString(entryLogId), completedEntryLogs, totalEntryLogs);
    }
    newIndex.sync();
    newIndex.close();
    LOG.info("Rebuilding index is done. Total time: {}", DurationFormatUtils.formatDurationHMS(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime)));
}
Also used : Path(java.nio.file.Path) LedgerDirsManager(org.apache.bookkeeper.bookie.LedgerDirsManager) DiskChecker(org.apache.bookkeeper.util.DiskChecker) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf) Date(java.util.Date) DefaultEntryLogger(org.apache.bookkeeper.bookie.DefaultEntryLogger) EntryLogScanner(org.apache.bookkeeper.bookie.storage.EntryLogScanner) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with DefaultEntryLogger

use of org.apache.bookkeeper.bookie.DefaultEntryLogger in project bookkeeper by apache.

the class EntryLogTestUtils method newLegacyEntryLogger.

public static EntryLogger newLegacyEntryLogger(int logSizeLimit, File... ledgerDir) throws Exception {
    ServerConfiguration conf = new ServerConfiguration();
    conf.setEntryLogSizeLimit(logSizeLimit);
    return new DefaultEntryLogger(conf, newDirsManager(ledgerDir), null, NullStatsLogger.INSTANCE, ByteBufAllocator.DEFAULT);
}
Also used : DefaultEntryLogger(org.apache.bookkeeper.bookie.DefaultEntryLogger) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration)

Example 3 with DefaultEntryLogger

use of org.apache.bookkeeper.bookie.DefaultEntryLogger in project bookkeeper by apache.

the class LedgersIndexRebuildOp method scanEntryLogFiles.

private void scanEntryLogFiles(Set<Long> ledgers) throws IOException {
    DefaultEntryLogger entryLogger = new DefaultEntryLogger(conf, new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold())));
    Set<Long> entryLogs = entryLogger.getEntryLogsSet();
    int totalEntryLogs = entryLogs.size();
    int completedEntryLogs = 0;
    LOG.info("Scanning {} entry logs", totalEntryLogs);
    for (long entryLogId : entryLogs) {
        entryLogger.scanEntryLog(entryLogId, new EntryLogScanner() {

            @Override
            public void process(long ledgerId, long offset, ByteBuf entry) throws IOException {
                if (ledgers.add(ledgerId)) {
                    if (verbose) {
                        LOG.info("Found ledger {} in entry log", ledgerId);
                    }
                }
            }

            @Override
            public boolean accept(long ledgerId) {
                return true;
            }
        });
        ++completedEntryLogs;
        LOG.info("Completed scanning of log {}.log -- {} / {}", Long.toHexString(entryLogId), completedEntryLogs, totalEntryLogs);
    }
}
Also used : DefaultEntryLogger(org.apache.bookkeeper.bookie.DefaultEntryLogger) LedgerDirsManager(org.apache.bookkeeper.bookie.LedgerDirsManager) DiskChecker(org.apache.bookkeeper.util.DiskChecker) EntryLogScanner(org.apache.bookkeeper.bookie.storage.EntryLogScanner) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf)

Example 4 with DefaultEntryLogger

use of org.apache.bookkeeper.bookie.DefaultEntryLogger in project bookkeeper by apache.

the class ListActiveLedgersCommand method handler.

public void handler(ServerConfiguration bkConf, ActiveLedgerFlags cmdFlags) throws ExecutionException, MetadataException {
    runFunctionWithLedgerManagerFactory(bkConf, mFactory -> {
        try (LedgerManager ledgerManager = mFactory.newLedgerManager()) {
            Set<Long> activeLedgersOnMetadata = new HashSet<Long>();
            BookkeeperInternalCallbacks.Processor<Long> ledgerProcessor = (ledger, cb) -> {
                activeLedgersOnMetadata.add(ledger);
                cb.processResult(BKException.Code.OK, null, null);
            };
            CountDownLatch done = new CountDownLatch(1);
            AtomicInteger resultCode = new AtomicInteger(BKException.Code.OK);
            VoidCallback endCallback = (rs, s, obj) -> {
                resultCode.set(rs);
                done.countDown();
            };
            ledgerManager.asyncProcessLedgers(ledgerProcessor, endCallback, null, BKException.Code.OK, BKException.Code.ReadException);
            if (done.await(cmdFlags.timeout, TimeUnit.MILLISECONDS)) {
                if (resultCode.get() == BKException.Code.OK) {
                    DefaultEntryLogger entryLogger = new ReadOnlyDefaultEntryLogger(bkConf);
                    EntryLogMetadata entryLogMetadata = entryLogger.getEntryLogMetadata(cmdFlags.logId);
                    List<Long> ledgersOnEntryLog = entryLogMetadata.getLedgersMap().keys();
                    if (ledgersOnEntryLog.size() == 0) {
                        LOG.info("Ledgers on log file {} is empty", cmdFlags.logId);
                    }
                    List<Long> activeLedgersOnEntryLog = new ArrayList<Long>(ledgersOnEntryLog.size());
                    for (long ledger : ledgersOnEntryLog) {
                        if (activeLedgersOnMetadata.contains(ledger)) {
                            activeLedgersOnEntryLog.add(ledger);
                        }
                    }
                    printActiveLedgerOnEntryLog(cmdFlags.logId, activeLedgersOnEntryLog);
                } else {
                    LOG.info("Read active ledgers id from metadata store,fail code {}", resultCode.get());
                    throw BKException.create(resultCode.get());
                }
            } else {
                LOG.info("Read active ledgers id from metadata store timeout");
            }
        } catch (BKException | InterruptedException | IOException e) {
            LOG.error("Received Exception while processing ledgers", e);
            throw new UncheckedExecutionException(e);
        }
        return null;
    });
}
Also used : MetadataException(org.apache.bookkeeper.meta.exceptions.MetadataException) Setter(lombok.Setter) Accessors(lombok.experimental.Accessors) Parameter(com.beust.jcommander.Parameter) ReadOnlyDefaultEntryLogger(org.apache.bookkeeper.bookie.ReadOnlyDefaultEntryLogger) LoggerFactory(org.slf4j.LoggerFactory) VoidCallback(org.apache.zookeeper.AsyncCallback.VoidCallback) BookkeeperInternalCallbacks(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks) CliFlags(org.apache.bookkeeper.tools.framework.CliFlags) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) MetadataDrivers.runFunctionWithLedgerManagerFactory(org.apache.bookkeeper.meta.MetadataDrivers.runFunctionWithLedgerManagerFactory) ActiveLedgerFlags(org.apache.bookkeeper.tools.cli.commands.bookie.ListActiveLedgersCommand.ActiveLedgerFlags) BookieCommand(org.apache.bookkeeper.tools.cli.helpers.BookieCommand) Logger(org.slf4j.Logger) LedgerManager(org.apache.bookkeeper.meta.LedgerManager) Set(java.util.Set) IOException(java.io.IOException) CliSpec(org.apache.bookkeeper.tools.framework.CliSpec) DefaultEntryLogger(org.apache.bookkeeper.bookie.DefaultEntryLogger) BKException(org.apache.bookkeeper.client.BKException) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) EntryLogMetadata(org.apache.bookkeeper.bookie.EntryLogMetadata) LedgerIdFormatter(org.apache.bookkeeper.util.LedgerIdFormatter) Collections(java.util.Collections) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) LedgerManager(org.apache.bookkeeper.meta.LedgerManager) ReadOnlyDefaultEntryLogger(org.apache.bookkeeper.bookie.ReadOnlyDefaultEntryLogger) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) VoidCallback(org.apache.zookeeper.AsyncCallback.VoidCallback) ReadOnlyDefaultEntryLogger(org.apache.bookkeeper.bookie.ReadOnlyDefaultEntryLogger) DefaultEntryLogger(org.apache.bookkeeper.bookie.DefaultEntryLogger) BookkeeperInternalCallbacks(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks) EntryLogMetadata(org.apache.bookkeeper.bookie.EntryLogMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BKException(org.apache.bookkeeper.client.BKException) HashSet(java.util.HashSet)

Aggregations

DefaultEntryLogger (org.apache.bookkeeper.bookie.DefaultEntryLogger)4 IOException (java.io.IOException)3 ByteBuf (io.netty.buffer.ByteBuf)2 LedgerDirsManager (org.apache.bookkeeper.bookie.LedgerDirsManager)2 EntryLogScanner (org.apache.bookkeeper.bookie.storage.EntryLogScanner)2 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)2 DiskChecker (org.apache.bookkeeper.util.DiskChecker)2 Parameter (com.beust.jcommander.Parameter)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Path (java.nio.file.Path)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1