use of com.baidu.hugegraph.backend.store.BackendMutation 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;
}
use of com.baidu.hugegraph.backend.store.BackendMutation in project incubator-hugegraph by apache.
the class IndexableTransaction method commit2Backend.
@Override
protected void commit2Backend() {
BackendMutation mutation = this.prepareCommit();
BackendMutation idxMutation = this.indexTransaction().prepareCommit();
assert !mutation.isEmpty() || !idxMutation.isEmpty();
// Commit graph/schema updates and index updates with graph/schema tx
this.commitMutation2Backend(mutation, idxMutation);
}
use of com.baidu.hugegraph.backend.store.BackendMutation in project incubator-hugegraph by apache.
the class BackendMutationTest method testAppendAndAppendEntryWithSameId.
@Test
public void testAppendAndAppendEntryWithSameId() {
BackendMutation mutation = new BackendMutation();
BackendEntry entry1 = constructBackendEntry("1", "name", "marko");
BackendEntry entry2 = constructBackendEntry("1", "city", "Wuhan");
mutation.add(entry1, Action.APPEND);
mutation.add(entry2, Action.APPEND);
Assert.assertEquals(2, get(mutation, "1").size());
Assert.assertEquals(Action.APPEND, get(mutation, "1").get(0).action());
Assert.assertEquals(Action.APPEND, get(mutation, "1").get(1).action());
}
use of com.baidu.hugegraph.backend.store.BackendMutation in project incubator-hugegraph by apache.
the class BackendMutationTest method testEliminateAndAppendEntryWithSameEntry.
@Test
public void testEliminateAndAppendEntryWithSameEntry() {
BackendMutation mutation = new BackendMutation();
BackendEntry entry1 = constructBackendEntry("1", "name", "marko");
BackendEntry entry2 = constructBackendEntry("1", "name", "marko");
mutation.add(entry1, Action.ELIMINATE);
mutation.add(entry2, Action.APPEND);
Assert.assertEquals(1, get(mutation, "1").size());
Assert.assertEquals(Action.APPEND, get(mutation, "1").get(0).action());
}
use of com.baidu.hugegraph.backend.store.BackendMutation in project incubator-hugegraph by apache.
the class BackendMutationTest method testAppendAndEliminateEntryWithSameId.
@Test
public void testAppendAndEliminateEntryWithSameId() {
BackendMutation mutation = new BackendMutation();
BackendEntry entry1 = constructBackendEntry("1", "name", "marko");
BackendEntry entry2 = constructBackendEntry("1", "city", "Wuhan");
mutation.add(entry1, Action.APPEND);
mutation.add(entry2, Action.ELIMINATE);
Assert.assertEquals(2, get(mutation, "1").size());
Assert.assertEquals(Action.APPEND, get(mutation, "1").get(0).action());
Assert.assertEquals(Action.ELIMINATE, get(mutation, "1").get(1).action());
}
Aggregations