Search in sources :

Example 1 with StoreCommand

use of com.baidu.hugegraph.backend.store.raft.StoreCommand in project incubator-hugegraph by apache.

the class StoreCommandProcessor method parseStoreCommand.

private StoreCommand parseStoreCommand(StoreCommandRequest request) {
    StoreType type = request.getType();
    StoreAction action = request.getAction();
    byte[] data = request.getData().toByteArray();
    return new StoreCommand(type, action, data, true);
}
Also used : StoreType(com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.StoreType) StoreCommand(com.baidu.hugegraph.backend.store.raft.StoreCommand) StoreAction(com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.StoreAction)

Example 2 with StoreCommand

use of com.baidu.hugegraph.backend.store.raft.StoreCommand in project incubator-hugegraph by apache.

the class StoreCommandProcessor method processRequest.

@Override
public Message processRequest(StoreCommandRequest request, RpcRequestClosure done) {
    LOG.debug("Processing StoreCommandRequest: {}", request.getAction());
    RaftNode node = this.context.node();
    try {
        StoreCommand command = this.parseStoreCommand(request);
        RaftStoreClosure closure = new RaftStoreClosure(command);
        node.submitAndWait(command, closure);
        // TODO: return the submitAndWait() result to rpc client
        return StoreCommandResponse.newBuilder().setStatus(true).build();
    } catch (Throwable e) {
        LOG.warn("Failed to process StoreCommandRequest: {}", request.getAction(), e);
        StoreCommandResponse.Builder builder = StoreCommandResponse.newBuilder().setStatus(false);
        if (e.getMessage() != null) {
            builder.setMessage(e.getMessage());
        }
        return builder.build();
    }
}
Also used : StoreCommand(com.baidu.hugegraph.backend.store.raft.StoreCommand) RaftNode(com.baidu.hugegraph.backend.store.raft.RaftNode) RaftStoreClosure(com.baidu.hugegraph.backend.store.raft.RaftStoreClosure)

Example 3 with StoreCommand

use of com.baidu.hugegraph.backend.store.raft.StoreCommand in project incubator-hugegraph by apache.

the class StoreSerializerTest method testSerializeStoreCommand.

@Test
public void testSerializeStoreCommand() {
    BinaryBackendEntry entry = new BinaryBackendEntry(HugeType.VERTEX, new byte[] { 1, 2 });
    entry.column(new byte[] { 1 }, new byte[] { 1 });
    entry.column(new byte[] { 2 }, new byte[] { 2 });
    entry.column(new byte[] { 127 }, new byte[] { 127 });
    BackendMutation origin = new BackendMutation();
    origin.add(entry, Action.INSERT);
    byte[] mutationBytes = StoreSerializer.writeMutation(origin);
    StoreCommand command = new StoreCommand(StoreType.GRAPH, StoreAction.MUTATE, mutationBytes);
    Assert.assertEquals(StoreAction.MUTATE, command.action());
    Assert.assertArrayEquals(mutationBytes, command.data());
    byte[] commandBytes = command.data();
    StoreCommand actual = StoreCommand.fromBytes(commandBytes);
    Assert.assertEquals(StoreType.GRAPH, command.type());
    Assert.assertEquals(command.action(), actual.action());
    Assert.assertArrayEquals(command.data(), actual.data());
}
Also used : BackendMutation(com.baidu.hugegraph.backend.store.BackendMutation) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) StoreCommand(com.baidu.hugegraph.backend.store.raft.StoreCommand) Test(org.junit.Test)

Aggregations

StoreCommand (com.baidu.hugegraph.backend.store.raft.StoreCommand)3 BinaryBackendEntry (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)1 BackendMutation (com.baidu.hugegraph.backend.store.BackendMutation)1 RaftNode (com.baidu.hugegraph.backend.store.raft.RaftNode)1 RaftStoreClosure (com.baidu.hugegraph.backend.store.raft.RaftStoreClosure)1 StoreAction (com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.StoreAction)1 StoreType (com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.StoreType)1 Test (org.junit.Test)1