Search in sources :

Example 1 with StorageResources

use of org.apache.bookkeeper.stream.storage.StorageResources in project bookkeeper by apache.

the class TestRangeStoreImpl method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    storageResources = StorageResources.create();
    Endpoint endpoint = createEndpoint("127.0.0.1", 0);
    // create the client manager
    MVCCStoreFactory storeFactory = mock(MVCCStoreFactory.class);
    MVCCAsyncStore<byte[], byte[]> store = mock(MVCCAsyncStore.class);
    when(storeFactory.openStore(anyLong(), anyLong(), anyLong())).thenReturn(FutureUtils.value(store));
    when(storeFactory.closeStores(anyLong())).thenReturn(FutureUtils.Void());
    rangeStore = (RangeStoreImpl) RangeStoreBuilder.newBuilder().withStorageConfiguration(storageConf).withStorageResources(storageResources).withStorageContainerManagerFactory((numScs, storeConf, rgRegistry) -> new LocalStorageContainerManager(endpoint, storeConf, rgRegistry, 2)).withRangeStoreFactory(storeFactory).withDefaultBackendUri(URI.create("distributedlog://127.0.0.1/stream/storage")).build();
    rangeStore.start();
}
Also used : ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) LocalStorageContainerManager(org.apache.bookkeeper.stream.storage.impl.sc.LocalStorageContainerManager) DeleteNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) PutRequest(org.apache.bookkeeper.stream.proto.kv.rpc.PutRequest) StreamName(org.apache.bookkeeper.stream.proto.StreamName) DeleteStreamResponse(org.apache.bookkeeper.stream.proto.storage.DeleteStreamResponse) ProtoUtils.createGetNamespaceRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetNamespaceRequest) ProtoUtils.createCreateNamespaceRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createCreateNamespaceRequest) PutResponse(org.apache.bookkeeper.stream.proto.kv.rpc.PutResponse) After(org.junit.After) Status(io.grpc.Status) URI(java.net.URI) DEFAULT_STREAM_CONF(org.apache.bookkeeper.stream.protocol.ProtocolConstants.DEFAULT_STREAM_CONF) ProtoUtils.createGetActiveRangesRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetActiveRangesRequest) CreateNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.CreateNamespaceResponse) StorageResources(org.apache.bookkeeper.stream.storage.StorageResources) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) FutureUtils(org.apache.bookkeeper.common.concurrent.FutureUtils) RangeRequest(org.apache.bookkeeper.stream.proto.kv.rpc.RangeRequest) ResponseHeader(org.apache.bookkeeper.stream.proto.kv.rpc.ResponseHeader) ByteString(com.google.protobuf.ByteString) Slf4j(lombok.extern.slf4j.Slf4j) ProtoUtils.createGetStreamRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetStreamRequest) CreateNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.CreateNamespaceRequest) StorageConfiguration(org.apache.bookkeeper.stream.storage.conf.StorageConfiguration) StreamProperties(org.apache.bookkeeper.stream.proto.StreamProperties) MVCCStoreFactory(org.apache.bookkeeper.stream.storage.impl.store.MVCCStoreFactory) StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) ProtoUtils.createDeleteStreamRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteStreamRequest) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) GetStreamRequest(org.apache.bookkeeper.stream.proto.storage.GetStreamRequest) CompletableFuture(java.util.concurrent.CompletableFuture) DeleteRangeResponse(org.apache.bookkeeper.stream.proto.kv.rpc.DeleteRangeResponse) CreateStreamRequest(org.apache.bookkeeper.stream.proto.storage.CreateStreamRequest) GetStreamResponse(org.apache.bookkeeper.stream.proto.storage.GetStreamResponse) DeleteStreamRequest(org.apache.bookkeeper.stream.proto.storage.DeleteStreamRequest) ProtoUtils.createDeleteNamespaceRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteNamespaceRequest) CreateStreamResponse(org.apache.bookkeeper.stream.proto.storage.CreateStreamResponse) MVCCAsyncStore(org.apache.bookkeeper.statelib.api.mvcc.MVCCAsyncStore) DeleteNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse) RangeStoreBuilder(org.apache.bookkeeper.stream.storage.RangeStoreBuilder) NamespaceConfiguration(org.apache.bookkeeper.stream.proto.NamespaceConfiguration) StatusCode(org.apache.bookkeeper.stream.proto.storage.StatusCode) ProtoUtils.createCreateStreamRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createCreateStreamRequest) Before(org.junit.Before) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ROOT_STORAGE_CONTAINER_ID(org.apache.bookkeeper.stream.protocol.ProtocolConstants.ROOT_STORAGE_CONTAINER_ID) Mockito.verify(org.mockito.Mockito.verify) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) DeleteRangeRequest(org.apache.bookkeeper.stream.proto.kv.rpc.DeleteRangeRequest) RangeResponse(org.apache.bookkeeper.stream.proto.kv.rpc.RangeResponse) Assert.assertEquals(org.junit.Assert.assertEquals) RoutingHeader(org.apache.bookkeeper.stream.proto.kv.rpc.RoutingHeader) GetNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.GetNamespaceRequest) GetNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.GetNamespaceResponse) MVCCStoreFactory(org.apache.bookkeeper.stream.storage.impl.store.MVCCStoreFactory) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) LocalStorageContainerManager(org.apache.bookkeeper.stream.storage.impl.sc.LocalStorageContainerManager) Before(org.junit.Before)

Example 2 with StorageResources

use of org.apache.bookkeeper.stream.storage.StorageResources 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)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Endpoint (org.apache.bookkeeper.stream.proto.common.Endpoint)2 RangeStoreBuilder (org.apache.bookkeeper.stream.storage.RangeStoreBuilder)2 StorageResources (org.apache.bookkeeper.stream.storage.StorageResources)2 StorageConfiguration (org.apache.bookkeeper.stream.storage.conf.StorageConfiguration)2 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)2 JCommander (com.beust.jcommander.JCommander)1 Parameter (com.beust.jcommander.Parameter)1 ByteString (com.google.protobuf.ByteString)1 Status (io.grpc.Status)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 File (java.io.File)1 InetAddress (java.net.InetAddress)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 UnknownHostException (java.net.UnknownHostException)1 Optional (java.util.Optional)1 ComponentStarter (org.apache.bookkeeper.common.component.ComponentStarter)1