Search in sources :

Example 6 with BookKeeperAdmin

use of org.apache.bookkeeper.client.BookKeeperAdmin in project bookkeeper by apache.

the class Auditor method initialize.

private void initialize(ServerConfiguration conf, ZooKeeper zkc) throws UnavailableException {
    try {
        ClientConfiguration clientConfiguration = new ClientConfiguration(conf);
        clientConfiguration.setClientRole(ClientConfiguration.CLIENT_ROLE_SYSTEM);
        LOG.info("AuthProvider used by the Auditor is {}", clientConfiguration.getClientAuthProviderFactoryClass());
        this.bkc = new BookKeeper(clientConfiguration, zkc);
        LedgerManagerFactory ledgerManagerFactory = AbstractZkLedgerManagerFactory.newLedgerManagerFactory(conf, bkc.getMetadataClientDriver().getLayoutManager());
        ledgerManager = ledgerManagerFactory.newLedgerManager();
        this.bookieLedgerIndexer = new BookieLedgerIndexer(ledgerManager);
        this.ledgerUnderreplicationManager = ledgerManagerFactory.newLedgerUnderreplicationManager();
        this.admin = new BookKeeperAdmin(bkc, statsLogger);
        if (this.ledgerUnderreplicationManager.initializeLostBookieRecoveryDelay(conf.getLostBookieRecoveryDelay())) {
            LOG.info("Initializing lostBookieRecoveryDelay zNode to the conif value: {}", conf.getLostBookieRecoveryDelay());
        } else {
            LOG.info("Valid lostBookieRecoveryDelay zNode is available, so not creating " + "lostBookieRecoveryDelay zNode as part of Auditor initialization ");
        }
        lostBookieRecoveryDelayBeforeChange = this.ledgerUnderreplicationManager.getLostBookieRecoveryDelay();
    } catch (CompatibilityException ce) {
        throw new UnavailableException("CompatibilityException while initializing Auditor", ce);
    } catch (IOException | BKException | KeeperException ioe) {
        throw new UnavailableException("Exception while initializing Auditor", ioe);
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
        throw new UnavailableException("Interrupted while initializing Auditor", ie);
    }
}
Also used : CompatibilityException(org.apache.bookkeeper.replication.ReplicationException.CompatibilityException) UnavailableException(org.apache.bookkeeper.replication.ReplicationException.UnavailableException) BookKeeper(org.apache.bookkeeper.client.BookKeeper) BKException(org.apache.bookkeeper.client.BKException) IOException(java.io.IOException) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) LedgerManagerFactory(org.apache.bookkeeper.meta.LedgerManagerFactory) AbstractZkLedgerManagerFactory(org.apache.bookkeeper.meta.AbstractZkLedgerManagerFactory) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin) KeeperException(org.apache.zookeeper.KeeperException)

Example 7 with BookKeeperAdmin

use of org.apache.bookkeeper.client.BookKeeperAdmin in project pravega by pravega.

the class BookKeeperCleanupCommand method execute.

@Override
public void execute() throws Exception {
    ensureArgCount(0);
    @Cleanup val context = createContext();
    // Get all BK ledger ids.
    output("Searching for all the ledgers ...");
    @Cleanup val bkAdmin = new BookKeeperAdmin((BookKeeper) context.logFactory.getBookKeeperClient());
    val allLedgerIds = new ArrayList<Long>();
    bkAdmin.listLedgers().forEach(allLedgerIds::add);
    output("Searching for all referenced ledgers ...");
    // We will not be deleting any ledger id above the highest referenced Ledger Id since we may be inadvertently
    // deleting freshly created Ledgers that have not yet been added to a Ledger Metadata yet (BookKeeperLog.initialize
    // first creates a new Ledger and then updates the Metadata in ZK with its existence).
    AtomicLong highestReferencedLedgerId = new AtomicLong();
    val referencedLedgerIds = new HashSet<Long>();
    collectAllReferencedLedgerIds(referencedLedgerIds, context);
    highestReferencedLedgerId.set(referencedLedgerIds.stream().max(Long::compareTo).orElse(-1L));
    // We want to do our due diligence and verify there are no more other BookKeeperLogs that the user hasn't told us about.
    output("Searching for possible other BookKeeperLogs ...");
    checkForExtraLogs(context);
    // Determine deletion candidates.
    val deletionCandidates = allLedgerIds.stream().filter(id -> id < highestReferencedLedgerId.get() && !referencedLedgerIds.contains(id)).collect(Collectors.toList());
    output("\nTotal Count: %d, Referenced Count: %d, Highest Referenced Id: %s, To Delete Count: %d.", allLedgerIds.size(), referencedLedgerIds.size(), highestReferencedLedgerId, deletionCandidates.size());
    if (deletionCandidates.isEmpty()) {
        output("There are no Ledgers eligible for deletion at this time.");
        return;
    }
    output("\nDeletion candidates:");
    listCandidates(deletionCandidates, context);
    if (!confirmContinue()) {
        output("Not deleting anything at this time.");
        return;
    }
    // Search again for referenced ledger ids, in case any new ones were just referenced.
    collectAllReferencedLedgerIds(referencedLedgerIds, context);
    highestReferencedLedgerId.set(referencedLedgerIds.stream().max(Long::compareTo).orElse(-1L));
    deleteCandidates(deletionCandidates, referencedLedgerIds, context);
}
Also used : lombok.val(lombok.val) AdminCommand(io.pravega.cli.admin.AdminCommand) Collection(java.util.Collection) Exceptions(io.pravega.common.Exceptions) lombok.val(lombok.val) Cleanup(lombok.Cleanup) BookKeeper(org.apache.bookkeeper.client.BookKeeper) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin) DebugBookKeeperLogWrapper(io.pravega.segmentstore.storage.impl.bookkeeper.DebugBookKeeperLogWrapper) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CommandArgs(io.pravega.cli.admin.CommandArgs) AtomicLong(java.util.concurrent.atomic.AtomicLong) ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong) Cleanup(lombok.Cleanup) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin) HashSet(java.util.HashSet)

Example 8 with BookKeeperAdmin

use of org.apache.bookkeeper.client.BookKeeperAdmin in project pravega by pravega.

the class ContainerCommand method createContext.

/**
 * Creates a new Context to be used by the BookKeeper command.
 *
 * @return A new Context.
 * @throws DurableDataLogException If the BookKeeperLogFactory could not be initialized.
 */
@Override
public Context createContext() throws DurableDataLogException {
    val serviceConfig = getServiceConfig();
    val containerConfig = getCommandArgs().getState().getConfigBuilder().build().getConfig(ContainerConfig::builder);
    val bkConfig = getCommandArgs().getState().getConfigBuilder().include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, serviceConfig.getZkURL())).build().getConfig(BookKeeperConfig::builder);
    val zkClient = createZKClient();
    val factory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor());
    try {
        factory.initialize();
    } catch (DurableDataLogException ex) {
        zkClient.close();
        throw ex;
    }
    val bkAdmin = new BookKeeperAdmin((BookKeeper) factory.getBookKeeperClient());
    return new Context(serviceConfig, containerConfig, bkConfig, zkClient, factory, bkAdmin);
}
Also used : lombok.val(lombok.val) ContainerConfig(io.pravega.segmentstore.server.containers.ContainerConfig) DurableDataLogException(io.pravega.segmentstore.storage.DurableDataLogException) BookKeeperConfig(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin)

Example 9 with BookKeeperAdmin

use of org.apache.bookkeeper.client.BookKeeperAdmin in project pravega by pravega.

the class BookKeeperLogTests method testReconcileMetadata.

@Test
public void testReconcileMetadata() throws Exception {
    @Cleanup BookKeeperAdmin a = new BookKeeperAdmin((org.apache.bookkeeper.client.BookKeeper) this.factory.get().getBookKeeperClient());
    val initialLedgers = Sets.newHashSet(a.listLedgers());
    // Test initialization (node creation).
    try (val log = new TestBookKeeperLog()) {
        // Data not persisted and we throw an error - this is a real fencing event.
        log.setThrowZkException(true);
        log.setPersistData(false);
        AssertExtensions.assertThrows("Create(Persist=False, Throw=True)", () -> log.initialize(TIMEOUT), ex -> ex instanceof DataLogWriterNotPrimaryException);
        Assert.assertEquals(1, log.getCreateExceptionCount());
        // Data persisted correctly and we throw an error - reconciliation needed.
        log.setPersistData(true);
        log.initialize(TIMEOUT);
        Assert.assertEquals("Create(Persist=True, Throw=True)", 2, log.getCreateExceptionCount());
    }
    val expectedLedgerIds = new HashSet<Long>();
    // Test updates (subsequent recoveries).
    try (val log = new TestBookKeeperLog()) {
        // Data not persisted and we throw an error - this is a real fencing event.
        log.setThrowZkException(true);
        log.setPersistData(false);
        AssertExtensions.assertThrows("Update(Persist=False, Throw=True)", () -> log.initialize(TIMEOUT), ex -> ex instanceof DataLogWriterNotPrimaryException);
        Assert.assertEquals(1, log.getUpdateExceptionCount());
        // Data persisted correctly and we throw an error - reconciliation needed.
        log.setPersistData(true);
        log.initialize(TIMEOUT);
        Assert.assertEquals("Update(Persist=True, Throw=True)", 2, log.getUpdateExceptionCount());
        log.loadMetadata().getLedgers().stream().map(LedgerMetadata::getLedgerId).forEach(expectedLedgerIds::add);
    }
    // Verify ledger cleanup.
    val allLedgers = Sets.newHashSet(a.listLedgers());
    allLedgers.removeAll(initialLedgers);
    Assert.assertEquals("Unexpected ledgers in BK.", expectedLedgerIds, allLedgers);
}
Also used : lombok.val(lombok.val) DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) Cleanup(lombok.Cleanup) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with BookKeeperAdmin

use of org.apache.bookkeeper.client.BookKeeperAdmin in project pravega by pravega.

the class BookKeeperCleanupCommand method execute.

@Override
public void execute() throws Exception {
    ensureArgCount(0);
    @Cleanup val context = createContext();
    // Get all BK ledger ids.
    output("Searching for all the ledgers ...");
    val bkAdmin = new BookKeeperAdmin(context.logFactory.getBookKeeperClient());
    val allLedgerIds = new ArrayList<Long>();
    bkAdmin.listLedgers().forEach(allLedgerIds::add);
    output("Searching for all referenced ledgers ...");
    // We will not be deleting any ledger id above the highest referenced Ledger Id since we may be inadvertently
    // deleting freshly created Ledgers that have not yet been added to a Ledger Metadata yet (BookKeeperLog.initialize
    // first creates a new Ledger and then updates the Metadata in ZK with its existence).
    AtomicLong highestReferencedLedgerId = new AtomicLong();
    val referencedLedgerIds = new HashSet<Long>();
    collectAllReferencedLedgerIds(referencedLedgerIds, context);
    highestReferencedLedgerId.set(referencedLedgerIds.stream().max(Long::compareTo).orElse(-1L));
    // We want to do our due diligence and verify there are no more other BookKeeperLogs that the user hasn't told us about.
    output("Searching for possible other BookKeeperLogs ...");
    checkForExtraLogs(context);
    // Determine deletion candidates.
    val deletionCandidates = allLedgerIds.stream().filter(id -> id < highestReferencedLedgerId.get() && !referencedLedgerIds.contains(id)).collect(Collectors.toList());
    output("\nTotal Count: %d, Referenced Count: %d, Highest Referenced Id: %s, To Delete Count: %d.", allLedgerIds.size(), referencedLedgerIds.size(), highestReferencedLedgerId, deletionCandidates.size());
    if (deletionCandidates.isEmpty()) {
        output("There are no Ledgers eligible for deletion at this time.");
        return;
    }
    output("\nDeletion candidates:");
    listCandidates(deletionCandidates, context);
    if (!confirmContinue()) {
        output("Not deleting anything at this time.");
        return;
    }
    // Search again for referenced ledger ids, in case any new ones were just referenced.
    collectAllReferencedLedgerIds(referencedLedgerIds, context);
    highestReferencedLedgerId.set(referencedLedgerIds.stream().max(Long::compareTo).orElse(-1L));
    deleteCandidates(deletionCandidates, referencedLedgerIds, context);
}
Also used : lombok.val(lombok.val) HashSet(java.util.HashSet) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Collection(java.util.Collection) Exceptions(io.pravega.common.Exceptions) lombok.val(lombok.val) Cleanup(lombok.Cleanup) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin) DebugLogWrapper(io.pravega.segmentstore.storage.impl.bookkeeper.DebugLogWrapper) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong) ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong) Cleanup(lombok.Cleanup) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin) HashSet(java.util.HashSet)

Aggregations

BookKeeperAdmin (org.apache.bookkeeper.client.BookKeeperAdmin)16 lombok.val (lombok.val)7 BookKeeper (org.apache.bookkeeper.client.BookKeeper)6 Test (org.junit.Test)5 DurableDataLogException (io.pravega.segmentstore.storage.DurableDataLogException)4 BookKeeperConfig (io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig)4 BookKeeperLogFactory (io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory)4 HashSet (java.util.HashSet)4 BKException (org.apache.bookkeeper.client.BKException)4 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)4 Cleanup (lombok.Cleanup)3 LedgerEntry (org.apache.bookkeeper.client.LedgerEntry)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 BookkeeperCommitLog (herddb.cluster.BookkeeperCommitLog)2 TableSpaceManager (herddb.core.TableSpaceManager)2 DataScanner (herddb.model.DataScanner)2 StatementExecutionException (herddb.model.StatementExecutionException)2 StatementExecutionResult (herddb.model.StatementExecutionResult)2 Table (herddb.model.Table)2