Search in sources :

Example 1 with MVCCAsyncStore

use of org.apache.bookkeeper.statelib.api.mvcc.MVCCAsyncStore 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 MVCCAsyncStore

use of org.apache.bookkeeper.statelib.api.mvcc.MVCCAsyncStore in project bookkeeper by apache.

the class MVCCStoreFactoryImpl method addStore.

private synchronized void addStore(long scId, long streamId, long rangeId, MVCCAsyncStore<byte[], byte[]> store) {
    Map<RangeId, MVCCAsyncStore<byte[], byte[]>> scStores = stores.get(scId);
    if (null == scStores) {
        scStores = Maps.newHashMap();
    }
    RangeId rid = RangeId.of(streamId, rangeId);
    MVCCAsyncStore<byte[], byte[]> oldStore = scStores.get(rid);
    if (null != oldStore) {
        store.closeAsync();
    } else {
        log.info("Add store (scId = {}, streamId = {}, rangeId = {})", scId, streamId, rangeId);
        scStores.put(rid, store);
    }
}
Also used : MVCCAsyncStore(org.apache.bookkeeper.statelib.api.mvcc.MVCCAsyncStore) RangeId(org.apache.bookkeeper.stream.protocol.RangeId)

Example 3 with MVCCAsyncStore

use of org.apache.bookkeeper.statelib.api.mvcc.MVCCAsyncStore in project bookkeeper by apache.

the class TableStoreCacheTest method testConcurrentOpenTableStore.

@SuppressWarnings("unchecked")
@Test
public void testConcurrentOpenTableStore() throws Exception {
    MVCCAsyncStore<byte[], byte[]> mvccStore1 = mock(MVCCAsyncStore.class);
    MVCCAsyncStore<byte[], byte[]> mvccStore2 = mock(MVCCAsyncStore.class);
    CompletableFuture<MVCCAsyncStore<byte[], byte[]>> future1 = FutureUtils.createFuture();
    CompletableFuture<MVCCAsyncStore<byte[], byte[]>> future2 = FutureUtils.createFuture();
    when(factory.openStore(eq(SCID), eq(RID.getStreamId()), eq(RID.getRangeId()))).thenReturn(future1).thenReturn(future2);
    CompletableFuture<TableStore> openFuture1 = storeCache.openTableStore(SCID, RID);
    assertEquals(0, storeCache.getTableStores().size());
    assertEquals(1, storeCache.getTableStoresOpening().size());
    CompletableFuture<TableStore> openFuture2 = storeCache.openTableStore(SCID, RID);
    assertEquals(0, storeCache.getTableStores().size());
    assertEquals(1, storeCache.getTableStoresOpening().size());
    assertSame(openFuture1, openFuture2);
    future1.complete(mvccStore1);
    future1.complete(mvccStore2);
    TableStore store1 = FutureUtils.result(openFuture1);
    TableStore store2 = FutureUtils.result(openFuture2);
    assertSame(store1, store2);
    assertEquals(0, storeCache.getTableStoresOpening().size());
    assertEquals(1, storeCache.getTableStores().size());
    assertSame(store1, storeCache.getTableStores().get(RID));
    verify(factory, times(1)).openStore(eq(SCID), eq(RID.getStreamId()), eq(RID.getRangeId()));
}
Also used : MVCCAsyncStore(org.apache.bookkeeper.statelib.api.mvcc.MVCCAsyncStore) TableStore(org.apache.bookkeeper.stream.storage.api.kv.TableStore) Test(org.junit.Test)

Aggregations

MVCCAsyncStore (org.apache.bookkeeper.statelib.api.mvcc.MVCCAsyncStore)3 ByteString (com.google.protobuf.ByteString)1 Status (io.grpc.Status)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 URI (java.net.URI)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 Slf4j (lombok.extern.slf4j.Slf4j)1 FutureUtils (org.apache.bookkeeper.common.concurrent.FutureUtils)1 NamespaceConfiguration (org.apache.bookkeeper.stream.proto.NamespaceConfiguration)1 StreamName (org.apache.bookkeeper.stream.proto.StreamName)1 StreamProperties (org.apache.bookkeeper.stream.proto.StreamProperties)1 Endpoint (org.apache.bookkeeper.stream.proto.common.Endpoint)1 DeleteRangeRequest (org.apache.bookkeeper.stream.proto.kv.rpc.DeleteRangeRequest)1 DeleteRangeResponse (org.apache.bookkeeper.stream.proto.kv.rpc.DeleteRangeResponse)1 PutRequest (org.apache.bookkeeper.stream.proto.kv.rpc.PutRequest)1 PutResponse (org.apache.bookkeeper.stream.proto.kv.rpc.PutResponse)1 RangeRequest (org.apache.bookkeeper.stream.proto.kv.rpc.RangeRequest)1 RangeResponse (org.apache.bookkeeper.stream.proto.kv.rpc.RangeResponse)1 ResponseHeader (org.apache.bookkeeper.stream.proto.kv.rpc.ResponseHeader)1