Search in sources :

Example 1 with RoutingHeader

use of org.apache.bookkeeper.stream.proto.kv.rpc.RoutingHeader 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 2 with RoutingHeader

use of org.apache.bookkeeper.stream.proto.kv.rpc.RoutingHeader in project bookkeeper by apache.

the class TableStoreImpl method buildTxnOp.

private TxnOp<byte[], byte[]> buildTxnOp(TxnRequest request) {
    RoutingHeader header = request.getHeader();
    TxnOpBuilder<byte[], byte[]> txnBuilder = store.getOpFactory().newTxn();
    for (RequestOp requestOp : request.getSuccessList()) {
        txnBuilder.Then(buildTxnOp(header, requestOp));
    }
    for (RequestOp requestOp : request.getFailureList()) {
        txnBuilder.Else(buildTxnOp(header, requestOp));
    }
    for (Compare compare : request.getCompareList()) {
        txnBuilder.If(fromProtoCompare(store.getOpFactory(), header, compare));
    }
    return txnBuilder.build();
}
Also used : RoutingHeader(org.apache.bookkeeper.stream.proto.kv.rpc.RoutingHeader) Compare(org.apache.bookkeeper.stream.proto.kv.rpc.Compare) TableStoreUtils.fromProtoCompare(org.apache.bookkeeper.stream.storage.impl.kv.TableStoreUtils.fromProtoCompare) RequestOp(org.apache.bookkeeper.stream.proto.kv.rpc.RequestOp)

Example 3 with RoutingHeader

use of org.apache.bookkeeper.stream.proto.kv.rpc.RoutingHeader in project bookkeeper by apache.

the class StorageContainerImplTest method newStorageContainerRequest.

// 
// Table API
// 
private StorageContainerRequest newStorageContainerRequest(RequestCase type) {
    StorageContainerRequest.Builder reqBuilder = StorageContainerRequest.newBuilder().setScId(SCID);
    RoutingHeader header = RoutingHeader.newBuilder().setStreamId(STREAM_ID).setRangeId(RANGE_ID).build();
    switch(type) {
        case KV_PUT_REQ:
            reqBuilder = reqBuilder.setKvPutReq(PutRequest.newBuilder().setHeader(header));
            break;
        case KV_DELETE_REQ:
            reqBuilder = reqBuilder.setKvDeleteReq(DeleteRangeRequest.newBuilder().setHeader(header));
            break;
        case KV_RANGE_REQ:
            reqBuilder = reqBuilder.setKvRangeReq(RangeRequest.newBuilder().setHeader(header));
            break;
        case KV_TXN_REQ:
            reqBuilder = reqBuilder.setKvTxnReq(TxnRequest.newBuilder().setHeader(header));
            break;
        case KV_INCR_REQ:
            reqBuilder = reqBuilder.setKvIncrReq(IncrementRequest.newBuilder().setHeader(header));
            break;
        default:
            break;
    }
    return reqBuilder.build();
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) RoutingHeader(org.apache.bookkeeper.stream.proto.kv.rpc.RoutingHeader)

Example 4 with RoutingHeader

use of org.apache.bookkeeper.stream.proto.kv.rpc.RoutingHeader 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)

Example 5 with RoutingHeader

use of org.apache.bookkeeper.stream.proto.kv.rpc.RoutingHeader 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)

Aggregations

RoutingHeader (org.apache.bookkeeper.stream.proto.kv.rpc.RoutingHeader)7 RangeId (org.apache.bookkeeper.stream.protocol.RangeId)5 TableStore (org.apache.bookkeeper.stream.storage.api.kv.TableStore)5 DeleteRangeRequest (org.apache.bookkeeper.stream.proto.kv.rpc.DeleteRangeRequest)2 Compare (org.apache.bookkeeper.stream.proto.kv.rpc.Compare)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 RequestOp (org.apache.bookkeeper.stream.proto.kv.rpc.RequestOp)1 TxnRequest (org.apache.bookkeeper.stream.proto.kv.rpc.TxnRequest)1 StorageContainerRequest (org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest)1 TableStoreUtils.fromProtoCompare (org.apache.bookkeeper.stream.storage.impl.kv.TableStoreUtils.fromProtoCompare)1