Search in sources :

Example 6 with BookKeeperLogFactory

use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory in project pravega by pravega.

the class BookkeeperCommandsTest method createLedgerInBookkeeperTestCluster.

private void createLedgerInBookkeeperTestCluster(int logId) throws Exception {
    BookKeeperConfig bookKeeperConfig = BookKeeperConfig.builder().with(BookKeeperConfig.BK_ENSEMBLE_SIZE, 1).with(BookKeeperConfig.BK_WRITE_QUORUM_SIZE, 1).with(BookKeeperConfig.BK_ACK_QUORUM_SIZE, 1).with(BookKeeperConfig.ZK_METADATA_PATH, "ledgers").with(BookKeeperConfig.BK_LEDGER_PATH, "/ledgers").with(BookKeeperConfig.ZK_ADDRESS, zkUtil.getZooKeeperConnectString()).build();
    @Cleanup CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(zkUtil.getZooKeeperConnectString(), new RetryOneTime(5000));
    curatorFramework.start();
    @Cleanup("shutdownNow") ScheduledExecutorService executorService = ExecutorServiceHelpers.newScheduledThreadPool(1, "bk-test");
    @Cleanup BookKeeperLogFactory bookKeeperLogFactory = new BookKeeperLogFactory(bookKeeperConfig, curatorFramework, executorService);
    bookKeeperLogFactory.initialize();
    @Cleanup DurableDataLog log = bookKeeperLogFactory.createDurableDataLog(logId);
    log.initialize(Duration.ofSeconds(5));
}
Also used : DurableDataLog(io.pravega.segmentstore.storage.DurableDataLog) CuratorFramework(org.apache.curator.framework.CuratorFramework) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BookKeeperConfig(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig) RetryOneTime(org.apache.curator.retry.RetryOneTime) Cleanup(lombok.Cleanup) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory)

Example 7 with BookKeeperLogFactory

use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory in project pravega by pravega.

the class StorageCommandsTest method testListChunksCommand.

@Test
public void testListChunksCommand() throws Exception {
    int instanceId = 0;
    int bookieCount = 3;
    int containerCount = 1;
    @Cleanup TestUtils.PravegaRunner pravegaRunner = new TestUtils.PravegaRunner(bookieCount, containerCount);
    pravegaRunner.startBookKeeperRunner(instanceId++);
    this.factory = new BookKeeperLogFactory(pravegaRunner.getBookKeeperRunner().getBkConfig().get(), pravegaRunner.getBookKeeperRunner().getZkClient().get(), executorService());
    pravegaRunner.startControllerAndSegmentStore(this.storageFactory, this.factory, true);
    String streamName = "testListChunksCommand";
    TestUtils.createScopeStream(pravegaRunner.getControllerRunner().getController(), SCOPE, streamName, config);
    try (val clientRunner = new TestUtils.ClientRunner(pravegaRunner.getControllerRunner(), SCOPE)) {
        // Write events to the streams.
        TestUtils.writeEvents(streamName, clientRunner.getClientFactory());
    }
    ServiceBuilder.ComponentSetup componentSetup = new ServiceBuilder.ComponentSetup(pravegaRunner.getSegmentStoreRunner().getServiceBuilder());
    for (int containerId = 0; containerId < containerCount; containerId++) {
        componentSetup.getContainerRegistry().getContainer(containerId).flushToStorage(TIMEOUT).join();
    }
    STATE.set(new AdminCommandState());
    Properties pravegaProperties = new Properties();
    pravegaProperties.setProperty("pravegaservice.admin.gateway.port", String.valueOf(pravegaRunner.getSegmentStoreRunner().getAdminPort()));
    pravegaProperties.setProperty("pravegaservice.container.count", "1");
    pravegaProperties.setProperty("pravegaservice.storage.impl.name", "FILESYSTEM");
    pravegaProperties.setProperty("pravegaservice.storage.layout", "CHUNKED_STORAGE");
    pravegaProperties.setProperty("filesystem.root", this.baseDir.getAbsolutePath());
    STATE.get().getConfigBuilder().include(pravegaProperties);
    String commandResult = TestUtils.executeCommand("storage list-chunks _system/containers/metadata_0 localhost", STATE.get());
    Assert.assertTrue(commandResult.contains("List of chunks for _system/containers/metadata_0"));
}
Also used : lombok.val(lombok.val) Properties(java.util.Properties) Cleanup(lombok.Cleanup) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) TestUtils(io.pravega.cli.admin.utils.TestUtils) AdminCommandState(io.pravega.cli.admin.AdminCommandState) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory) Test(org.junit.Test)

Example 8 with BookKeeperLogFactory

use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory in project pravega by pravega.

the class BookKeeperAdapter method shutDown.

@Override
protected void shutDown() {
    for (WriteHandle lh : this.ledgers.values()) {
        try {
            lh.close();
        } catch (Exception ex) {
            System.err.println(ex);
        }
    }
    this.ledgers.clear();
    BookKeeperLogFactory lf = this.logFactory;
    if (lf != null) {
        lf.close();
        this.logFactory = null;
    }
    stopBookKeeper();
    CuratorFramework zkClient = this.zkClient;
    if (zkClient != null) {
        zkClient.close();
        this.zkClient = null;
    }
    Runtime.getRuntime().removeShutdownHook(this.stopBookKeeperProcess);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) WriteHandle(org.apache.bookkeeper.client.api.WriteHandle) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory)

Example 9 with BookKeeperLogFactory

use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory in project pravega by pravega.

the class BookKeeperCommand 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.
 */
protected Context createContext() throws DurableDataLogException {
    val serviceConfig = getServiceConfig();
    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(factory.getBookKeeperClient());
    return new Context(serviceConfig, bkConfig, zkClient, factory, bkAdmin);
}
Also used : lombok.val(lombok.val) 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 10 with BookKeeperLogFactory

use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory 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
protected 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(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)

Aggregations

BookKeeperLogFactory (io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory)16 lombok.val (lombok.val)11 BookKeeperConfig (io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig)9 Cleanup (lombok.Cleanup)8 AdminCommandState (io.pravega.cli.admin.AdminCommandState)5 TestUtils (io.pravega.cli.admin.utils.TestUtils)5 DurableDataLogException (io.pravega.segmentstore.storage.DurableDataLogException)5 Properties (java.util.Properties)5 Test (org.junit.Test)5 SegmentProperties (io.pravega.segmentstore.contracts.SegmentProperties)4 BookKeeperAdmin (org.apache.bookkeeper.client.BookKeeperAdmin)4 CommandArgs (io.pravega.cli.admin.CommandArgs)3 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)3 DurableDataLog (io.pravega.segmentstore.storage.DurableDataLog)3 ContainerConfig (io.pravega.segmentstore.server.containers.ContainerConfig)2 DebugDurableDataLogWrapper (io.pravega.segmentstore.storage.DebugDurableDataLogWrapper)2 Storage (io.pravega.segmentstore.storage.Storage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2