Search in sources :

Example 1 with IncrementRequest

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

the class TestKvUtils method testNewIncrementRequest.

@Test
public void testNewIncrementRequest() {
    try (IncrementOption<ByteBuf> option = Options.incrementAndGet()) {
        IncrementRequest rr = newIncrementRequest(key, 100L, option).build();
        assertEquals(keyBs, rr.getKey());
        assertEquals(100L, rr.getAmount());
        assertTrue(rr.getGetTotal());
        assertFalse(rr.hasHeader());
    }
}
Also used : KvUtils.newIncrementRequest(org.apache.bookkeeper.clients.impl.kv.KvUtils.newIncrementRequest) KvUtils.newKvIncrementRequest(org.apache.bookkeeper.clients.impl.kv.KvUtils.newKvIncrementRequest) IncrementRequest(org.apache.bookkeeper.stream.proto.kv.rpc.IncrementRequest) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 2 with IncrementRequest

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

IncrementRequest (org.apache.bookkeeper.stream.proto.kv.rpc.IncrementRequest)2 ByteBuf (io.netty.buffer.ByteBuf)1 KvUtils.newIncrementRequest (org.apache.bookkeeper.clients.impl.kv.KvUtils.newIncrementRequest)1 KvUtils.newKvIncrementRequest (org.apache.bookkeeper.clients.impl.kv.KvUtils.newKvIncrementRequest)1 RoutingHeader (org.apache.bookkeeper.stream.proto.kv.rpc.RoutingHeader)1 RangeId (org.apache.bookkeeper.stream.protocol.RangeId)1 TableStore (org.apache.bookkeeper.stream.storage.api.kv.TableStore)1 Test (org.junit.Test)1