use of com.baidu.hugegraph.backend.store.BackendEntry in project incubator-hugegraph by apache.
the class GraphIndexTransaction method doIndexQueryBatch.
@Watched(prefix = "index")
private IdHolder doIndexQueryBatch(IndexLabel indexLabel, ConditionQuery query) {
Iterator<BackendEntry> entries = super.query(query).iterator();
return new BatchIdHolder(query, entries, batch -> {
LockUtil.Locks locks = new LockUtil.Locks(this.graphName());
try {
// Catch lock every batch
locks.lockReads(LockUtil.INDEX_LABEL_DELETE, indexLabel.id());
locks.lockReads(LockUtil.INDEX_LABEL_REBUILD, indexLabel.id());
if (!indexLabel.system()) {
/*
* Check exist because it may be deleted after some batches
* throw exception if the index label not exists
* NOTE: graph() will return null with system index label
*/
graph().indexLabel(indexLabel.id());
}
// Iterate one batch, and keep iterator position
Set<Id> ids = InsertionOrderUtil.newSet();
while ((batch == Query.NO_LIMIT || ids.size() < batch) && entries.hasNext()) {
HugeIndex index = this.serializer.readIndex(graph(), query, entries.next());
this.removeExpiredIndexIfNeeded(index, query.showExpired());
ids.addAll(index.elementIds());
Query.checkForceCapacity(ids.size());
this.recordIndexValue(query, index);
}
return ids;
} finally {
locks.unlock();
}
});
}
use of com.baidu.hugegraph.backend.store.BackendEntry in project incubator-hugegraph by apache.
the class SchemaTransaction method getSchema.
protected <T extends SchemaElement> T getSchema(HugeType type, Id id) {
LOG.debug("SchemaTransaction get {} by id '{}'", type.readableName(), id);
this.beforeRead();
BackendEntry entry = this.query(type, id);
if (entry == null) {
return null;
}
T schema = this.deserialize(entry, type);
this.afterRead();
return schema;
}
use of com.baidu.hugegraph.backend.store.BackendEntry in project incubator-hugegraph by apache.
the class SchemaTransaction method getSchema.
/**
* Currently doesn't allow to exist schema with the same name
* @param type the query schema type
* @param name the query schema name
* @param <T> SubClass of SchemaElement
* @return the queried schema object
*/
protected <T extends SchemaElement> T getSchema(HugeType type, String name) {
LOG.debug("SchemaTransaction get {} by name '{}'", type.readableName(), name);
this.beforeRead();
ConditionQuery query = new ConditionQuery(type);
query.eq(HugeKeys.NAME, name);
QueryResults<BackendEntry> results = this.indexTx.query(query);
this.afterRead();
// Should not exist schema with same name
BackendEntry entry = results.one();
if (entry == null) {
return null;
}
return this.deserialize(entry, type);
}
use of com.baidu.hugegraph.backend.store.BackendEntry in project incubator-hugegraph by apache.
the class BinarySerializer method parse.
public BackendEntry parse(BackendEntry originEntry) {
byte[] bytes = originEntry.id().asBytes();
BinaryBackendEntry parsedEntry = new BinaryBackendEntry(originEntry.type(), bytes, this.enablePartition);
if (this.enablePartition) {
bytes = Arrays.copyOfRange(bytes, parsedEntry.id().length() + 2, bytes.length);
} else {
bytes = Arrays.copyOfRange(bytes, parsedEntry.id().length(), bytes.length);
}
BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID);
buffer.write(parsedEntry.id().asBytes());
buffer.write(bytes);
parsedEntry = new BinaryBackendEntry(originEntry.type(), new BinaryId(buffer.bytes(), BytesBuffer.wrap(buffer.bytes()).readEdgeId()));
for (BackendEntry.BackendColumn col : originEntry.columns()) {
parsedEntry.column(buffer.bytes(), col.value);
}
return parsedEntry;
}
use of com.baidu.hugegraph.backend.store.BackendEntry in project incubator-hugegraph by apache.
the class InMemoryDBStore method mutate.
protected void mutate(BackendAction item) {
BackendEntry e = item.entry();
assert e instanceof TextBackendEntry;
TextBackendEntry entry = (TextBackendEntry) e;
InMemoryDBTable table = this.table(entry.type());
switch(item.action()) {
case INSERT:
LOG.debug("[store {}] add entry: {}", this.store, entry);
table.insert(null, entry);
break;
case DELETE:
LOG.debug("[store {}] remove id: {}", this.store, entry.id());
table.delete(null, entry);
break;
case APPEND:
LOG.debug("[store {}] append entry: {}", this.store, entry);
table.append(null, entry);
break;
case ELIMINATE:
LOG.debug("[store {}] eliminate entry: {}", this.store, entry);
table.eliminate(null, entry);
break;
default:
throw new BackendException("Unsupported mutate type: %s", item.action());
}
}
Aggregations