Search in sources :

Example 1 with TableStore

use of org.apache.bookkeeper.stream.storage.api.kv.TableStore in project bookkeeper by apache.

the class TableStoreCacheTest method testOpenTableStoreSuccessWhenStoreIsNotCached.

@SuppressWarnings("unchecked")
@Test
public void testOpenTableStoreSuccessWhenStoreIsNotCached() throws Exception {
    assertNull(storeCache.getTableStore(RID));
    assertTrue(storeCache.getTableStores().isEmpty());
    assertTrue(storeCache.getTableStoresOpening().isEmpty());
    MVCCAsyncStore<byte[], byte[]> mvccStore = mock(MVCCAsyncStore.class);
    when(factory.openStore(eq(SCID), eq(RID.getStreamId()), eq(RID.getRangeId()))).thenReturn(FutureUtils.value(mvccStore));
    TableStore store = FutureUtils.result(storeCache.openTableStore(SCID, RID));
    assertEquals(1, storeCache.getTableStores().size());
    assertEquals(0, storeCache.getTableStoresOpening().size());
    assertTrue(storeCache.getTableStores().containsKey(RID));
    assertSame(store, storeCache.getTableStores().get(RID));
}
Also used : TableStore(org.apache.bookkeeper.stream.storage.api.kv.TableStore) Test(org.junit.Test)

Example 2 with TableStore

use of org.apache.bookkeeper.stream.storage.api.kv.TableStore in project bookkeeper by apache.

the class StorageContainerImpl method delete.

@Override
public CompletableFuture<StorageContainerResponse> delete(StorageContainerRequest request) {
    checkArgument(KV_DELETE_REQ == request.getRequestCase());
    long scId = request.getScId();
    DeleteRangeRequest rr = request.getKvDeleteReq();
    RoutingHeader header = rr.getHeader();
    RangeId rid = RangeId.of(header.getStreamId(), header.getRangeId());
    TableStore store = tableStoreCache.getTableStore(rid);
    if (null != store) {
        return store.delete(request);
    } else {
        return tableStoreCache.openTableStore(scId, rid).thenCompose(s -> s.delete(request));
    }
}
Also used : DeleteRangeRequest(org.apache.bookkeeper.stream.proto.kv.rpc.DeleteRangeRequest) RoutingHeader(org.apache.bookkeeper.stream.proto.kv.rpc.RoutingHeader) RangeId(org.apache.bookkeeper.stream.protocol.RangeId) TableStore(org.apache.bookkeeper.stream.storage.api.kv.TableStore)

Example 3 with TableStore

use of org.apache.bookkeeper.stream.storage.api.kv.TableStore in project bookkeeper by apache.

the class TableStoreCacheTest method testOpenTableStoreWhenStoreIsCached.

@Test
public void testOpenTableStoreWhenStoreIsCached() throws Exception {
    TableStore store = mock(TableStore.class);
    storeCache.getTableStores().put(RID, store);
    assertSame(store, storeCache.getTableStore(RID));
    assertSame(store, FutureUtils.result(storeCache.openTableStore(SCID, RID)));
}
Also used : TableStore(org.apache.bookkeeper.stream.storage.api.kv.TableStore) Test(org.junit.Test)

Example 4 with TableStore

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

Example 5 with TableStore

use of org.apache.bookkeeper.stream.storage.api.kv.TableStore in project bookkeeper by apache.

the class StorageContainerImpl method range.

// 
// Table API
// 
@Override
public CompletableFuture<StorageContainerResponse> range(StorageContainerRequest request) {
    checkArgument(KV_RANGE_REQ == request.getRequestCase());
    long scId = request.getScId();
    RangeRequest rr = request.getKvRangeReq();
    RoutingHeader header = rr.getHeader();
    RangeId rid = RangeId.of(header.getStreamId(), header.getRangeId());
    TableStore store = tableStoreCache.getTableStore(rid);
    if (null != store) {
        return store.range(request);
    } else {
        return tableStoreCache.openTableStore(scId, rid).thenCompose(s -> s.range(request));
    }
}
Also used : RangeRequest(org.apache.bookkeeper.stream.proto.kv.rpc.RangeRequest) DeleteRangeRequest(org.apache.bookkeeper.stream.proto.kv.rpc.DeleteRangeRequest) RoutingHeader(org.apache.bookkeeper.stream.proto.kv.rpc.RoutingHeader) RangeId(org.apache.bookkeeper.stream.protocol.RangeId) TableStore(org.apache.bookkeeper.stream.storage.api.kv.TableStore)

Aggregations

TableStore (org.apache.bookkeeper.stream.storage.api.kv.TableStore)9 RangeId (org.apache.bookkeeper.stream.protocol.RangeId)6 RoutingHeader (org.apache.bookkeeper.stream.proto.kv.rpc.RoutingHeader)5 Test (org.junit.Test)3 DeleteRangeRequest (org.apache.bookkeeper.stream.proto.kv.rpc.DeleteRangeRequest)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Maps (com.google.common.collect.Maps)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 FutureUtils (org.apache.bookkeeper.common.concurrent.FutureUtils)1 MVCCAsyncStore (org.apache.bookkeeper.statelib.api.mvcc.MVCCAsyncStore)1 IncrementRequest (org.apache.bookkeeper.stream.proto.kv.rpc.IncrementRequest)1 PutRequest (org.apache.bookkeeper.stream.proto.kv.rpc.PutRequest)1 RangeRequest (org.apache.bookkeeper.stream.proto.kv.rpc.RangeRequest)1 TxnRequest (org.apache.bookkeeper.stream.proto.kv.rpc.TxnRequest)1 MVCCStoreFactory (org.apache.bookkeeper.stream.storage.impl.store.MVCCStoreFactory)1