use of com.baidu.hugegraph.backend.store.raft.RaftBackendStore.IncrCounter in project incubator-hugegraph by apache.
the class StoreSerializer method readIncrCounter.
public static IncrCounter readIncrCounter(BytesBuffer buffer) {
HugeType type = SerialEnum.fromCode(HugeType.class, buffer.read());
long increment = buffer.readVLong();
return new IncrCounter(type, increment);
}
use of com.baidu.hugegraph.backend.store.raft.RaftBackendStore.IncrCounter in project incubator-hugegraph by apache.
the class StoreStateMachine method applyCommand.
private Object applyCommand(StoreType type, StoreAction action, BytesBuffer buffer, boolean forwarded) {
E.checkState(type != StoreType.ALL, "Can't apply command for all store at one time");
BackendStore store = this.store(type);
switch(action) {
case CLEAR:
boolean clearSpace = buffer.read() > 0;
store.clear(clearSpace);
this.context.clearCache();
break;
case TRUNCATE:
store.truncate();
this.context.clearCache();
break;
case SNAPSHOT:
assert store == null;
this.node().snapshot();
break;
case BEGIN_TX:
store.beginTx();
break;
case COMMIT_TX:
List<BackendMutation> mutations = StoreSerializer.readMutations(buffer);
// RaftBackendStore doesn't write raft log for beginTx
store.beginTx();
for (BackendMutation mutation : mutations) {
store.mutate(mutation);
this.context.updateCacheIfNeeded(mutation, forwarded);
}
store.commitTx();
break;
case ROLLBACK_TX:
store.rollbackTx();
break;
case INCR_COUNTER:
// Do increase counter
IncrCounter counter = StoreSerializer.readIncrCounter(buffer);
store.increaseCounter(counter.type(), counter.increment());
break;
default:
throw new IllegalArgumentException("Invalid action " + action);
}
return null;
}
Aggregations