use of com.baidu.hugegraph.backend.store.BackendMutation in project incubator-hugegraph by apache.
the class AbstractTransaction method commitMutation2Backend.
protected void commitMutation2Backend(BackendMutation... mutations) {
assert mutations.length > 0;
this.committing2Backend = true;
// If an exception occurred, catch in the upper layer and rollback
this.store.beginTx();
for (BackendMutation mutation : mutations) {
this.store.mutate(mutation);
}
this.store.commitTx();
this.committing2Backend = false;
}
use of com.baidu.hugegraph.backend.store.BackendMutation in project incubator-hugegraph by apache.
the class StoreSerializer method writeMutations.
public static byte[] writeMutations(List<BackendMutation> mutations) {
int estimateSize = mutations.size() * MUTATION_SIZE;
// The first two bytes are reserved for StoreType and StoreAction
BytesBuffer buffer = BytesBuffer.allocate(StoreCommand.HEADER_SIZE + 4 + estimateSize);
StoreCommand.writeHeader(buffer);
buffer.writeVInt(mutations.size());
for (BackendMutation mutation : mutations) {
buffer.writeBigBytes(writeMutation(mutation));
}
return buffer.bytes();
}
use of com.baidu.hugegraph.backend.store.BackendMutation in project incubator-hugegraph by apache.
the class StoreSerializer method readMutation.
public static BackendMutation readMutation(BytesBuffer buffer) {
int size = buffer.readVInt();
BackendMutation mutation = new BackendMutation(size);
for (int i = 0; i < size; i++) {
// read action
Action action = Action.fromCode(buffer.read());
// read HugeType
HugeType type = SerialEnum.fromCode(HugeType.class, buffer.read());
// read id
byte[] idBytes = buffer.readBytes();
// read subId
Id subId = buffer.readId();
if (subId.equals(IdGenerator.ZERO)) {
subId = null;
}
// read ttl
long ttl = buffer.readVLong();
BinaryBackendEntry entry = new BinaryBackendEntry(type, idBytes);
entry.subId(subId);
entry.ttl(ttl);
// read columns
int columnsSize = buffer.readVInt();
for (int c = 0; c < columnsSize; c++) {
byte[] name = buffer.readBytes();
byte[] value = buffer.readBytes();
entry.column(BackendColumn.of(name, value));
}
mutation.put(entry, action);
}
return mutation;
}
use of com.baidu.hugegraph.backend.store.BackendMutation in project incubator-hugegraph by apache.
the class StoreSerializer method readMutations.
public static List<BackendMutation> readMutations(BytesBuffer buffer) {
int size = buffer.readVInt();
List<BackendMutation> mutations = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
BytesBuffer buf = BytesBuffer.wrap(buffer.readBigBytes());
mutations.add(readMutation(buf));
}
return mutations;
}
use of com.baidu.hugegraph.backend.store.BackendMutation in project incubator-hugegraph by apache.
the class AbstractTransaction method commitOrRollback.
@Watched(prefix = "tx")
public void commitOrRollback() {
LOG.debug("Transaction commitOrRollback()");
this.checkOwnerThread();
/*
* The mutation will be reset after commit, in order to log the
* mutation after failure, let's save it to a local variable.
*/
BackendMutation mutation = this.mutation();
try {
// Do commit
this.commit();
} catch (Throwable e1) {
LOG.error("Failed to commit changes:", e1);
// Do rollback
try {
this.rollback();
} catch (Throwable e2) {
LOG.error("Failed to rollback changes:\n {}", mutation, e2);
}
/*
* Rethrow the commit exception
* The e.getMessage maybe too long to see key information,
*/
throw new BackendException("Failed to commit changes: %s(%s)", StringUtils.abbreviateMiddle(e1.getMessage(), ".", 256), HugeException.rootCause(e1));
}
}
Aggregations