use of org.apache.bookkeeper.stream.protocol.RangeId 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.protocol.RangeId 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