use of org.apache.bookkeeper.stream.storage.api.kv.TableStore in project bookkeeper by apache.
the class StorageContainerImpl method incr.
@Override
public CompletableFuture<StorageContainerResponse> incr(StorageContainerRequest request) {
checkArgument(KV_INCR_REQ == request.getRequestCase());
long scId = request.getScId();
IncrementRequest ir = request.getKvIncrReq();
RoutingHeader header = ir.getHeader();
RangeId rid = RangeId.of(header.getStreamId(), header.getRangeId());
TableStore store = tableStoreCache.getTableStore(rid);
if (null != store) {
return store.incr(request);
} else {
return tableStoreCache.openTableStore(scId, rid).thenCompose(s -> s.incr(request));
}
}
use of org.apache.bookkeeper.stream.storage.api.kv.TableStore in project bookkeeper by apache.
the class StorageContainerImpl method put.
@Override
public CompletableFuture<StorageContainerResponse> put(StorageContainerRequest request) {
checkArgument(KV_PUT_REQ == request.getRequestCase());
long scId = request.getScId();
PutRequest rr = request.getKvPutReq();
RoutingHeader header = rr.getHeader();
RangeId rid = RangeId.of(header.getStreamId(), header.getRangeId());
TableStore store = tableStoreCache.getTableStore(rid);
if (null != store) {
return store.put(request);
} else {
return tableStoreCache.openTableStore(scId, rid).thenCompose(s -> s.put(request));
}
}
use of org.apache.bookkeeper.stream.storage.api.kv.TableStore in project bookkeeper by apache.
the class StorageContainerImpl method txn.
@Override
public CompletableFuture<StorageContainerResponse> txn(StorageContainerRequest request) {
checkArgument(KV_TXN_REQ == request.getRequestCase());
long scId = request.getScId();
TxnRequest rr = request.getKvTxnReq();
RoutingHeader header = rr.getHeader();
RangeId rid = RangeId.of(header.getStreamId(), header.getRangeId());
TableStore store = tableStoreCache.getTableStore(rid);
if (null != store) {
return store.txn(request);
} else {
return tableStoreCache.openTableStore(scId, rid).thenCompose(s -> s.txn(request));
}
}
use of org.apache.bookkeeper.stream.storage.api.kv.TableStore in project bookkeeper by apache.
the class TableStoreCache method openTableStore.
public CompletableFuture<TableStore> openTableStore(long scId, RangeId rid) {
TableStore store = tableStores.get(rid);
if (null != store) {
return FutureUtils.value(store);
}
CompletableFuture<TableStore> openFuture = tableStoresOpening.get(rid);
if (null != openFuture) {
return openFuture;
}
// no store is cached, and there is no outstanding open request
openFuture = FutureUtils.createFuture();
CompletableFuture<TableStore> existingOpenFuture = tableStoresOpening.putIfAbsent(rid, openFuture);
if (null != existingOpenFuture) {
// there is already an ongoing open request
return existingOpenFuture;
}
// I am the first one to open a table store
final CompletableFuture<TableStore> openingFuture = openFuture;
mvccStoreFactory.openStore(scId, rid.getStreamId(), rid.getRangeId()).thenAccept(mvccStore -> {
TableStore newStore = tableStoreFactory.createStore(mvccStore);
TableStore oldStore = tableStores.putIfAbsent(rid, newStore);
if (null != oldStore) {
openingFuture.complete(oldStore);
} else {
openingFuture.complete(newStore);
}
tableStoresOpening.remove(rid, openingFuture);
}).exceptionally(cause -> {
openingFuture.completeExceptionally(cause);
tableStoresOpening.remove(rid, openingFuture);
return null;
});
return openingFuture;
}
Aggregations