Search in sources :

Example 1 with StorageConfiguration

use of org.apache.bookkeeper.stream.storage.conf.StorageConfiguration in project bookkeeper by apache.

the class TestHelixStorageContainerManager method testStorageContainerManager.

@Ignore
@Test
public void testStorageContainerManager() throws Exception {
    String clusterName = runtime.getMethodName();
    int numStorageContainers = 12;
    int numHosts = 3;
    controller.createCluster(clusterName, numStorageContainers, 3);
    StorageConfiguration conf = new StorageConfiguration(new CompositeConfiguration());
    Endpoint[] endpoints = new Endpoint[numHosts];
    StorageContainerRegistryImpl[] registries = new StorageContainerRegistryImpl[numHosts];
    HelixStorageContainerManager[] managers = new HelixStorageContainerManager[numHosts];
    int basePort = 80;
    for (int i = 0; i < numHosts; i++) {
        endpoints[i] = createEndpoint("127.0.0.1", basePort + i);
        registries[i] = createRegistry();
        managers[i] = createManager(clusterName, conf, registries[i], endpoints[i]);
    }
    managers[0].start();
    while (registries[0].getNumStorageContainers() < numStorageContainers) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    assertEquals(numStorageContainers, registries[0].getNumStorageContainers());
    assertEquals(0, registries[1].getNumStorageContainers());
    assertEquals(0, registries[2].getNumStorageContainers());
    // start the second node
    managers[1].start();
    while (registries[0].getNumStorageContainers() > numStorageContainers / 2) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    while (registries[1].getNumStorageContainers() < numStorageContainers / 2) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    assertEquals(numStorageContainers / 2, registries[0].getNumStorageContainers());
    assertEquals(numStorageContainers / 2, registries[1].getNumStorageContainers());
    assertEquals(0, registries[2].getNumStorageContainers());
    // start the third node
    managers[2].start();
    while (registries[0].getNumStorageContainers() > numStorageContainers / 3) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    while (registries[1].getNumStorageContainers() > numStorageContainers / 3) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    while (registries[2].getNumStorageContainers() < numStorageContainers / 3) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    int totalStorageContainers = registries[0].getNumStorageContainers() + registries[1].getNumStorageContainers() + registries[2].getNumStorageContainers();
    assertEquals("Expected " + numStorageContainers + "But " + totalStorageContainers + " found", numStorageContainers, totalStorageContainers);
    assertEquals(numStorageContainers / 3, registries[0].getNumStorageContainers());
    assertEquals(numStorageContainers / 3, registries[1].getNumStorageContainers());
    assertEquals(numStorageContainers / 3, registries[2].getNumStorageContainers());
    for (int i = 0; i < 10; i++) {
        int nid = ThreadLocalRandom.current().nextInt(numHosts);
        long scId = ThreadLocalRandom.current().nextLong(numStorageContainers);
        Endpoint endpoint = managers[nid].getStorageContainer(scId);
        if (null != endpoint) {
            assertTrue(endpoint.equals(endpoints[0]) || endpoint.equals(endpoints[1]) || endpoint.equals(endpoints[2]));
        }
    }
    for (HelixStorageContainerManager manager : managers) {
        manager.close();
    }
}
Also used : StorageContainerRegistryImpl(org.apache.bookkeeper.stream.storage.impl.sc.StorageContainerRegistryImpl) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) StorageConfiguration(org.apache.bookkeeper.stream.storage.conf.StorageConfiguration) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with StorageConfiguration

use of org.apache.bookkeeper.stream.storage.conf.StorageConfiguration in project bookkeeper by apache.

the class StreamCluster method startServer.

private LifecycleComponent startServer() throws Exception {
    int bookiePort;
    int grpcPort;
    boolean success = false;
    int retries = 0;
    while (!success) {
        synchronized (this) {
            bookiePort = nextBookiePort++;
            grpcPort = nextGrpcPort++;
        }
        LifecycleComponent server = null;
        try {
            ServerConfiguration serverConf = new ServerConfiguration();
            serverConf.loadConf(baseConf);
            serverConf.setBookiePort(bookiePort);
            File bkDir = new File(spec.storageRootDir(), "bookie_" + bookiePort);
            serverConf.setJournalDirName(bkDir.getPath());
            serverConf.setLedgerDirNames(new String[] { bkDir.getPath() });
            DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
            dlConf.loadConf(serverConf);
            File rangesStoreDir = new File(spec.storageRootDir(), "ranges_" + grpcPort);
            StorageConfiguration storageConf = new StorageConfiguration(serverConf);
            storageConf.setRangeStoreDirNames(new String[] { rangesStoreDir.getPath() });
            storageConf.setServeReadOnlyTables(spec.serveReadOnlyTable);
            log.info("Attempting to start storage server at (bookie port = {}, grpc port = {})" + " : bkDir = {}, rangesStoreDir = {}, serveReadOnlyTables = {}", bookiePort, grpcPort, bkDir, rangesStoreDir, spec.serveReadOnlyTable);
            server = StorageServer.startStorageServer(serverConf, grpcPort, spec.numServers() * 2, Optional.empty());
            server.start();
            log.info("Started storage server at (bookie port = {}, grpc port = {})", bookiePort, grpcPort);
            this.rpcEndpoints.add(StorageServer.createLocalEndpoint(grpcPort, false));
            return server;
        } catch (Throwable e) {
            log.error("Failed to start storage server", e);
            if (null != server) {
                server.stop();
            }
            if (e.getCause() instanceof BindException) {
                retries++;
                if (retries > MAX_RETRIES) {
                    throw (BindException) e.getCause();
                }
            } else {
                throw e;
            }
        }
    }
    throw new IOException("Failed to start any storage server.");
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) LifecycleComponent(org.apache.bookkeeper.common.component.LifecycleComponent) AbstractLifecycleComponent(org.apache.bookkeeper.common.component.AbstractLifecycleComponent) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) StorageConfiguration(org.apache.bookkeeper.stream.storage.conf.StorageConfiguration) BindException(java.net.BindException) IOException(java.io.IOException) File(java.io.File) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint)

Example 3 with StorageConfiguration

use of org.apache.bookkeeper.stream.storage.conf.StorageConfiguration in project bookkeeper by apache.

the class StorageServer method startStorageServer.

public static LifecycleComponent startStorageServer(CompositeConfiguration conf, int grpcPort, int numStorageContainers, Optional<String> instanceName) throws ConfigurationException, UnknownHostException {
    BookieConfiguration bkConf = BookieConfiguration.of(conf);
    bkConf.validate();
    DLConfiguration dlConf = DLConfiguration.of(conf);
    dlConf.validate();
    StorageServerConfiguration serverConf = StorageServerConfiguration.of(conf);
    serverConf.validate();
    StorageConfiguration storageConf = new StorageConfiguration(conf);
    storageConf.validate();
    // Get my local endpoint
    Endpoint myEndpoint = createLocalEndpoint(grpcPort, false);
    // Create shared resources
    StorageResources storageResources = StorageResources.create();
    // Create the stats provider
    StatsProviderService statsProviderService = new StatsProviderService(bkConf);
    StatsLogger rootStatsLogger = statsProviderService.getStatsProvider().getStatsLogger("");
    // Create the bookie service
    BookieService bookieService = new BookieService(bkConf, rootStatsLogger);
    // Create the distributedlog namespace service
    DLNamespaceProviderService dlNamespaceProvider = new DLNamespaceProviderService(bookieService.serverConf(), dlConf, rootStatsLogger.scope("dl"));
    // Create range (stream) store
    RangeStoreBuilder rangeStoreBuilder = RangeStoreBuilder.newBuilder().withStatsLogger(rootStatsLogger.scope("storage")).withStorageConfiguration(storageConf).withStorageResources(storageResources).withNumStorageContainers(numStorageContainers).withDefaultBackendUri(dlNamespaceProvider.getDlogUri()).withStorageContainerManagerFactory((ignored, storeConf, registry) -> new HelixStorageContainerManager(bookieService.serverConf().getZkServers(), "stream/helix", storeConf, registry, myEndpoint, instanceName, rootStatsLogger.scope("helix"))).withRangeStoreFactory(new MVCCStoreFactoryImpl(dlNamespaceProvider, storageConf.getRangeStoreDirs(), storageResources, storageConf.getServeReadOnlyTables()));
    StorageService storageService = new StorageService(storageConf, rangeStoreBuilder, rootStatsLogger.scope("storage"));
    // Create gRPC server
    StatsLogger rpcStatsLogger = rootStatsLogger.scope("grpc");
    GrpcServerSpec serverSpec = GrpcServerSpec.builder().storeSupplier(storageService).storeServerConf(serverConf).endpoint(myEndpoint).statsLogger(rpcStatsLogger).build();
    GrpcService grpcService = new GrpcService(serverConf, serverSpec, rpcStatsLogger);
    // Create all the service stack
    return LifecycleComponentStack.newBuilder().withName("storage-server").addComponent(// stats provider
    statsProviderService).addComponent(// bookie server
    bookieService).addComponent(// service that provides dl namespace
    dlNamespaceProvider).addComponent(// range (stream) store
    storageService).addComponent(// range (stream) server (gRPC)
    grpcService).build();
}
Also used : ComponentStarter(org.apache.bookkeeper.common.component.ComponentStarter) Configuration(org.apache.commons.configuration.Configuration) DLNamespaceProviderService(org.apache.bookkeeper.stream.server.service.DLNamespaceProviderService) Parameter(com.beust.jcommander.Parameter) CompletableFuture(java.util.concurrent.CompletableFuture) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) InetAddress(java.net.InetAddress) GrpcServerSpec(org.apache.bookkeeper.stream.server.grpc.GrpcServerSpec) LifecycleComponentStack(org.apache.bookkeeper.common.component.LifecycleComponentStack) StorageServerConfiguration(org.apache.bookkeeper.stream.server.conf.StorageServerConfiguration) RangeStoreBuilder(org.apache.bookkeeper.stream.storage.RangeStoreBuilder) HelixStorageContainerManager(org.apache.bookkeeper.stream.storage.impl.sc.helix.HelixStorageContainerManager) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) StatsProviderService(org.apache.bookkeeper.stream.server.service.StatsProviderService) LifecycleComponent(org.apache.bookkeeper.common.component.LifecycleComponent) MalformedURLException(java.net.MalformedURLException) JCommander(com.beust.jcommander.JCommander) StorageResources(org.apache.bookkeeper.stream.storage.StorageResources) StorageService(org.apache.bookkeeper.stream.server.service.StorageService) BookieService(org.apache.bookkeeper.stream.server.service.BookieService) UnknownHostException(java.net.UnknownHostException) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) BookieConfiguration(org.apache.bookkeeper.stream.server.conf.BookieConfiguration) Slf4j(lombok.extern.slf4j.Slf4j) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) StorageConfiguration(org.apache.bookkeeper.stream.storage.conf.StorageConfiguration) DLConfiguration(org.apache.bookkeeper.stream.server.conf.DLConfiguration) GrpcService(org.apache.bookkeeper.stream.server.service.GrpcService) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) MVCCStoreFactoryImpl(org.apache.bookkeeper.stream.storage.impl.store.MVCCStoreFactoryImpl) Optional(java.util.Optional) ConfigurationException(org.apache.commons.configuration.ConfigurationException) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) StorageConfiguration(org.apache.bookkeeper.stream.storage.conf.StorageConfiguration) StorageResources(org.apache.bookkeeper.stream.storage.StorageResources) HelixStorageContainerManager(org.apache.bookkeeper.stream.storage.impl.sc.helix.HelixStorageContainerManager) BookieConfiguration(org.apache.bookkeeper.stream.server.conf.BookieConfiguration) StorageService(org.apache.bookkeeper.stream.server.service.StorageService) MVCCStoreFactoryImpl(org.apache.bookkeeper.stream.storage.impl.store.MVCCStoreFactoryImpl) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) GrpcService(org.apache.bookkeeper.stream.server.service.GrpcService) DLNamespaceProviderService(org.apache.bookkeeper.stream.server.service.DLNamespaceProviderService) RangeStoreBuilder(org.apache.bookkeeper.stream.storage.RangeStoreBuilder) StorageServerConfiguration(org.apache.bookkeeper.stream.server.conf.StorageServerConfiguration) DLConfiguration(org.apache.bookkeeper.stream.server.conf.DLConfiguration) StatsProviderService(org.apache.bookkeeper.stream.server.service.StatsProviderService) GrpcServerSpec(org.apache.bookkeeper.stream.server.grpc.GrpcServerSpec) BookieService(org.apache.bookkeeper.stream.server.service.BookieService)

Example 4 with StorageConfiguration

use of org.apache.bookkeeper.stream.storage.conf.StorageConfiguration in project bookkeeper by apache.

the class TestDefaultStorageContainerFactory method testCreate.

@Test
public void testCreate() throws Exception {
    OrderedScheduler scheduler = mock(OrderedScheduler.class);
    OrderedScheduler snapshotScheduler = mock(OrderedScheduler.class);
    MVCCStoreFactory storeFactory = mock(MVCCStoreFactory.class);
    ListeningScheduledExecutorService snapshotExecutor = mock(ListeningScheduledExecutorService.class);
    when(snapshotScheduler.chooseThread(anyLong())).thenReturn(snapshotExecutor);
    Mockito.doReturn(mock(ListenableScheduledFuture.class)).when(snapshotExecutor).scheduleWithFixedDelay(any(Runnable.class), anyInt(), anyInt(), any(TimeUnit.class));
    DefaultStorageContainerFactory factory = new DefaultStorageContainerFactory(new StorageConfiguration(new CompositeConfiguration()), (streamId, rangeId) -> streamId, scheduler, storeFactory, URI.create("distributedlog://127.0.0.1/stream/storage"));
    StorageContainer sc = factory.createStorageContainer(1234L);
    assertTrue(sc instanceof StorageContainerImpl);
    assertEquals(1234L, sc.getId());
}
Also used : MVCCStoreFactory(org.apache.bookkeeper.stream.storage.impl.store.MVCCStoreFactory) ListeningScheduledExecutorService(com.google.common.util.concurrent.ListeningScheduledExecutorService) ListenableScheduledFuture(com.google.common.util.concurrent.ListenableScheduledFuture) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) TimeUnit(java.util.concurrent.TimeUnit) StorageConfiguration(org.apache.bookkeeper.stream.storage.conf.StorageConfiguration) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler) Test(org.junit.Test)

Aggregations

StorageConfiguration (org.apache.bookkeeper.stream.storage.conf.StorageConfiguration)4 Endpoint (org.apache.bookkeeper.stream.proto.common.Endpoint)3 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)3 File (java.io.File)2 LifecycleComponent (org.apache.bookkeeper.common.component.LifecycleComponent)2 JCommander (com.beust.jcommander.JCommander)1 Parameter (com.beust.jcommander.Parameter)1 ListenableScheduledFuture (com.google.common.util.concurrent.ListenableScheduledFuture)1 ListeningScheduledExecutorService (com.google.common.util.concurrent.ListeningScheduledExecutorService)1 IOException (java.io.IOException)1 BindException (java.net.BindException)1 InetAddress (java.net.InetAddress)1 MalformedURLException (java.net.MalformedURLException)1 UnknownHostException (java.net.UnknownHostException)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 Slf4j (lombok.extern.slf4j.Slf4j)1 AbstractLifecycleComponent (org.apache.bookkeeper.common.component.AbstractLifecycleComponent)1