Search in sources :

Example 6 with TableStore

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));
    }
}
Also used : IncrementRequest(org.apache.bookkeeper.stream.proto.kv.rpc.IncrementRequest) 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 7 with TableStore

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));
    }
}
Also used : PutRequest(org.apache.bookkeeper.stream.proto.kv.rpc.PutRequest) 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 8 with TableStore

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));
    }
}
Also used : TxnRequest(org.apache.bookkeeper.stream.proto.kv.rpc.TxnRequest) 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 9 with TableStore

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;
}
Also used : TableStore(org.apache.bookkeeper.stream.storage.api.kv.TableStore) CompletableFuture(java.util.concurrent.CompletableFuture) MVCCStoreFactory(org.apache.bookkeeper.stream.storage.impl.store.MVCCStoreFactory) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FutureUtils(org.apache.bookkeeper.common.concurrent.FutureUtils) Maps(com.google.common.collect.Maps) RangeId(org.apache.bookkeeper.stream.protocol.RangeId) ConcurrentMap(java.util.concurrent.ConcurrentMap) 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