use of com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.StoreType in project incubator-hugegraph by apache.
the class StoreCommand method fromBytes.
public static StoreCommand fromBytes(byte[] bytes) {
StoreType type = StoreType.valueOf(bytes[0]);
StoreAction action = StoreAction.valueOf(bytes[1]);
return new StoreCommand(type, action, bytes);
}
use of com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.StoreType in project incubator-hugegraph by apache.
the class StoreStateMachine method onApplyFollower.
private Future<?> onApplyFollower(ByteBuffer data) {
// Follower need to read mutation data
byte[] bytes = data.array();
// Let the backend thread do it directly
return this.context.backendExecutor().submit(() -> {
BytesBuffer buffer = LZ4Util.decompress(bytes, RaftSharedContext.BLOCK_SIZE);
buffer.forReadWritten();
StoreType type = StoreType.valueOf(buffer.read());
StoreAction action = StoreAction.valueOf(buffer.read());
try {
return this.applyCommand(type, action, buffer, false);
} catch (Throwable e) {
String title = "Failed to execute backend command";
LOG.error("{}: {}", title, action, e);
throw new BackendException(title, e);
}
});
}
use of com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.StoreType 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);
}
use of com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.StoreType in project incubator-hugegraph by apache.
the class StoreStateMachine method onApplyLeader.
private Future<?> onApplyLeader(RaftStoreClosure closure) {
// Leader just take the command out from the closure
StoreCommand command = closure.command();
BytesBuffer buffer = BytesBuffer.wrap(command.data());
// The first two bytes are StoreType and StoreAction
StoreType type = StoreType.valueOf(buffer.read());
StoreAction action = StoreAction.valueOf(buffer.read());
boolean forwarded = command.forwarded();
// Let the producer thread to handle it, and wait for it
CompletableFuture<Object> future = new CompletableFuture<>();
closure.complete(Status.OK(), () -> {
Object result;
try {
result = this.applyCommand(type, action, buffer, forwarded);
} catch (Throwable e) {
future.completeExceptionally(e);
throw e;
}
future.complete(result);
return result;
});
return future;
}
Aggregations