Search in sources :

Example 1 with IncrCounter

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);
}
Also used : IncrCounter(com.baidu.hugegraph.backend.store.raft.RaftBackendStore.IncrCounter) HugeType(com.baidu.hugegraph.type.HugeType)

Example 2 with IncrCounter

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;
}
Also used : BackendMutation(com.baidu.hugegraph.backend.store.BackendMutation) IncrCounter(com.baidu.hugegraph.backend.store.raft.RaftBackendStore.IncrCounter) BackendStore(com.baidu.hugegraph.backend.store.BackendStore)

Aggregations

IncrCounter (com.baidu.hugegraph.backend.store.raft.RaftBackendStore.IncrCounter)2 BackendMutation (com.baidu.hugegraph.backend.store.BackendMutation)1 BackendStore (com.baidu.hugegraph.backend.store.BackendStore)1 HugeType (com.baidu.hugegraph.type.HugeType)1