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));
}
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));
}
}
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)));
}
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()));
}
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));
}
}
Aggregations