Search in sources :

Example 11 with BookKeeperLogFactory

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

the class S3IntegrationTest method createBuilder.

// endregion
// region StreamSegmentStoreTestBase Implementation
@Override
protected ServiceBuilder createBuilder(ServiceBuilderConfig.Builder configBuilder, int instanceId, boolean useChunkedSegmentStorage) {
    Preconditions.checkState(useChunkedSegmentStorage);
    ServiceBuilderConfig builderConfig = getBuilderConfig(configBuilder, instanceId);
    return ServiceBuilder.newInMemoryBuilder(builderConfig).withStorageFactory(setup -> new LocalS3SimpleStorageFactory(setup.getConfig(S3StorageConfig::builder), setup.getStorageExecutor())).withDataLogFactory(setup -> new BookKeeperLogFactory(setup.getConfig(BookKeeperConfig::builder), getBookkeeper().getZkClient(), setup.getCoreExecutor()));
}
Also used : S3Mock(io.pravega.storage.s3.S3Mock) Storage(io.pravega.segmentstore.storage.Storage) Getter(lombok.Getter) UUID(java.util.UUID) ChunkedSegmentStorageConfig(io.pravega.segmentstore.storage.chunklayer.ChunkedSegmentStorageConfig) S3StorageConfig(io.pravega.storage.s3.S3StorageConfig) ServiceBuilderConfig(io.pravega.segmentstore.server.store.ServiceBuilderConfig) BookKeeperConfig(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig) S3ChunkStorage(io.pravega.storage.s3.S3ChunkStorage) SimpleStorageFactory(io.pravega.segmentstore.storage.SimpleStorageFactory) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) S3ClientMock(io.pravega.storage.s3.S3ClientMock) ChunkMetadataStore(io.pravega.segmentstore.storage.metadata.ChunkMetadataStore) After(org.junit.After) Duration(java.time.Duration) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Preconditions(com.google.common.base.Preconditions) URI(java.net.URI) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory) ChunkedSegmentStorage(io.pravega.segmentstore.storage.chunklayer.ChunkedSegmentStorage) Before(org.junit.Before) BookKeeperConfig(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig) ServiceBuilderConfig(io.pravega.segmentstore.server.store.ServiceBuilderConfig) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory)

Example 12 with BookKeeperLogFactory

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

the class DurableLogRecoveryCommand method execute.

@Override
public void execute() throws Exception {
    @Cleanup Storage storage = this.storageFactory.createStorageAdapter();
    @Cleanup val zkClient = createZKClient();
    val bkConfig = getCommandArgs().getState().getConfigBuilder().include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, getServiceConfig().getZkURL())).build().getConfig(BookKeeperConfig::builder);
    @Cleanup val dataLogFactory = new BookKeeperLogFactory(bkConfig, zkClient, executorService);
    output("Container Count = %d", this.containerCount);
    dataLogFactory.initialize();
    output("Started ZK Client at %s.", getServiceConfig().getZkURL());
    storage.initialize(CONTAINER_EPOCH);
    output("Loaded %s Storage.", getServiceConfig().getStorageImplementation());
    output("Starting recovery...");
    // create back up of metadata segments
    Map<Integer, String> backUpMetadataSegments = ContainerRecoveryUtils.createBackUpMetadataSegments(storage, this.containerCount, executorService, TIMEOUT).get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
    @Cleanup Context context = createContext(executorService);
    // create debug segment container instances using new new dataLog and old storage.
    Map<Integer, DebugStreamSegmentContainer> debugStreamSegmentContainerMap = startDebugSegmentContainers(context, dataLogFactory);
    output("Containers started. Recovering all segments...");
    ContainerRecoveryUtils.recoverAllSegments(storage, debugStreamSegmentContainerMap, executorService, TIMEOUT);
    output("All segments recovered.");
    // Update core attributes from the backUp Metadata segments
    output("Updating core attributes for segments registered.");
    ContainerRecoveryUtils.updateCoreAttributes(backUpMetadataSegments, debugStreamSegmentContainerMap, executorService, TIMEOUT);
    // Flush new metadata segment to the storage
    flushToStorage(debugStreamSegmentContainerMap);
    // Waits for metadata segments to be flushed to LTS and then stops the debug segment containers
    stopDebugSegmentContainers(debugStreamSegmentContainerMap);
    output("Segments have been recovered.");
    output("Recovery Done!");
}
Also used : lombok.val(lombok.val) Storage(io.pravega.segmentstore.storage.Storage) CacheStorage(io.pravega.segmentstore.storage.cache.CacheStorage) BookKeeperConfig(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig) DebugStreamSegmentContainer(io.pravega.segmentstore.server.containers.DebugStreamSegmentContainer) Cleanup(lombok.Cleanup) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory)

Example 13 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.
 */
@VisibleForTesting
public 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((BookKeeper) 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) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 14 with BookKeeperLogFactory

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

the class DataRecoveryTest method testDataRecoveryCommand.

/**
 * Tests DurableLog recovery command.
 * @throws Exception    In case of any exception thrown while execution.
 */
@Test
public void testDataRecoveryCommand() throws Exception {
    int instanceId = 0;
    int bookieCount = 3;
    int containerCount = 1;
    @Cleanup TestUtils.PravegaRunner pravegaRunner = new TestUtils.PravegaRunner(bookieCount, containerCount);
    pravegaRunner.startBookKeeperRunner(instanceId++);
    pravegaRunner.startControllerAndSegmentStore(this.storageFactory, null);
    String streamName = "testDataRecoveryCommand";
    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());
    }
    // Shut down the controller
    pravegaRunner.shutDownControllerRunner();
    // Flush all Tier 1 to LTS
    ServiceBuilder.ComponentSetup componentSetup = new ServiceBuilder.ComponentSetup(pravegaRunner.getSegmentStoreRunner().getServiceBuilder());
    for (int containerId = 0; containerId < containerCount; containerId++) {
        componentSetup.getContainerRegistry().getContainer(containerId).flushToStorage(TIMEOUT).join();
    }
    // Shutdown SegmentStore
    pravegaRunner.shutDownSegmentStoreRunner();
    // Shutdown BookKeeper & ZooKeeper
    pravegaRunner.shutDownBookKeeperRunner();
    // start a new BookKeeper and ZooKeeper.
    pravegaRunner.startBookKeeperRunner(instanceId++);
    // set pravega properties for the test
    STATE.set(new AdminCommandState());
    Properties pravegaProperties = new Properties();
    pravegaProperties.setProperty("pravegaservice.container.count", "1");
    pravegaProperties.setProperty("pravegaservice.storage.impl.name", "FILESYSTEM");
    pravegaProperties.setProperty("pravegaservice.storage.layout", "ROLLING_STORAGE");
    pravegaProperties.setProperty("filesystem.root", this.baseDir.getAbsolutePath());
    pravegaProperties.setProperty("pravegaservice.zk.connect.uri", "localhost:" + pravegaRunner.getBookKeeperRunner().getBkPort());
    pravegaProperties.setProperty("bookkeeper.ledger.path", pravegaRunner.getBookKeeperRunner().getLedgerPath());
    pravegaProperties.setProperty("bookkeeper.zk.metadata.path", pravegaRunner.getBookKeeperRunner().getLogMetaNamespace());
    pravegaProperties.setProperty("pravegaservice.clusterName", pravegaRunner.getBookKeeperRunner().getBaseNamespace());
    STATE.get().getConfigBuilder().include(pravegaProperties);
    // Command under test
    TestUtils.executeCommand("data-recovery durableLog-recovery", STATE.get());
    // Start a new segment store and controller
    this.factory = new BookKeeperLogFactory(pravegaRunner.getBookKeeperRunner().getBkConfig().get(), pravegaRunner.getBookKeeperRunner().getZkClient().get(), executorService());
    pravegaRunner.startControllerAndSegmentStore(this.storageFactory, this.factory);
    log.info("Started a controller and segment store.");
    // Create the client with new controller.
    try (val clientRunner = new TestUtils.ClientRunner(pravegaRunner.getControllerRunner(), SCOPE)) {
        // Try reading all events to verify that the recovery was successful.
        TestUtils.readAllEvents(SCOPE, streamName, clientRunner.getClientFactory(), clientRunner.getReaderGroupManager(), "RG", "R");
        log.info("Read all events again to verify that segments were recovered.");
    }
    Assert.assertNotNull(StorageListSegmentsCommand.descriptor());
}
Also used : lombok.val(lombok.val) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) 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 15 with BookKeeperLogFactory

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

the class SegmentStoreAdapter method attachDataLogFactory.

private ServiceBuilder attachDataLogFactory(ServiceBuilder builder) {
    if (this.config.getBookieCount() > 0) {
        // We were instructed to start at least one Bookie.
        this.zkClient = CuratorFrameworkFactory.builder().connectString("localhost:" + this.config.getZkPort()).namespace("pravega").retryPolicy(new ExponentialBackoffRetry(1000, 5)).sessionTimeoutMs(5000).connectionTimeoutMs(5000).build();
        this.zkClient.start();
        return builder.withDataLogFactory(setup -> {
            BookKeeperConfig bkConfig = setup.getConfig(BookKeeperConfig::builder);
            return new BookKeeperLogFactory(bkConfig, this.zkClient, setup.getCoreExecutor());
        });
    } else {
        // No Bookies -> InMemory Tier1.
        return builder.withDataLogFactory(setup -> new InMemoryDurableDataLogFactory(setup.getCoreExecutor()));
    }
}
Also used : BookKeeperConfig(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) InMemoryDurableDataLogFactory(io.pravega.segmentstore.storage.mocks.InMemoryDurableDataLogFactory) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory)

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