use of com.baidu.hugegraph.structure.HugeIndex in project incubator-hugegraph by apache.
the class GraphIndexTransaction method removeExpiredIndexIfNeeded.
private void removeExpiredIndexIfNeeded(HugeIndex index, boolean showExpired) {
if (this.store().features().supportsTtl() || showExpired) {
return;
}
for (HugeIndex.IdWithExpiredTime id : index.expiredElementIds()) {
HugeIndex removeIndex = index.clone();
removeIndex.resetElementIds();
removeIndex.elementIds(id.id(), id.expiredTime());
DeleteExpiredJob.asyncDeleteExpiredObject(this.graph(), removeIndex);
}
}
use of com.baidu.hugegraph.structure.HugeIndex 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.structure.HugeIndex in project incubator-hugegraph by apache.
the class GraphIndexTransaction method updateLabelIndex.
@Watched(prefix = "index")
public void updateLabelIndex(HugeElement element, boolean removed) {
if (element instanceof HugeVertex && ((HugeVertex) element).olap()) {
return;
}
if (!this.needIndexForLabel()) {
return;
}
// Don't update label index if it's not enabled
SchemaLabel label = element.schemaLabel();
if (!label.enableLabelIndex()) {
return;
}
// Update label index if backend store not supports label-query
HugeIndex index = new HugeIndex(this.graph(), IndexLabel.label(element.type()));
index.fieldValues(element.schemaLabel().id());
index.elementIds(element.id(), element.expiredTime());
if (removed) {
this.doEliminate(this.serializer.writeIndex(index));
} else {
this.doAppend(this.serializer.writeIndex(index));
}
}
use of com.baidu.hugegraph.structure.HugeIndex in project incubator-hugegraph by apache.
the class TextSerializer method readIndex.
@Override
public HugeIndex readIndex(HugeGraph graph, ConditionQuery query, BackendEntry backendEntry) {
E.checkNotNull(graph, "serializer graph");
if (backendEntry == null) {
return null;
}
TextBackendEntry entry = this.convertEntry(backendEntry);
String indexValues = entry.column(formatSyspropName(HugeKeys.FIELD_VALUES));
String indexLabelId = entry.column(formatSyspropName(HugeKeys.INDEX_LABEL_ID));
String elemIds = entry.column(formatSyspropName(HugeKeys.ELEMENT_IDS));
IndexLabel indexLabel = IndexLabel.label(graph, readId(indexLabelId));
HugeIndex index = new HugeIndex(graph, indexLabel);
index.fieldValues(JsonUtil.fromJson(indexValues, Object.class));
for (IdWithExpiredTime elemId : readElementIds(elemIds)) {
long expiredTime = elemId.expiredTime();
Id id;
if (indexLabel.queryType().isEdge()) {
id = EdgeId.parse(elemId.id().asString());
} else {
id = elemId.id();
}
index.elementIds(id, expiredTime);
}
// Memory backend might return empty BackendEntry
return index;
}
use of com.baidu.hugegraph.structure.HugeIndex in project incubator-hugegraph by apache.
the class BinarySerializer method readIndex.
@Override
public HugeIndex readIndex(HugeGraph graph, ConditionQuery query, BackendEntry bytesEntry) {
if (bytesEntry == null) {
return null;
}
BinaryBackendEntry entry = this.convertEntry(bytesEntry);
// NOTE: index id without length prefix
byte[] bytes = entry.id().asBytes();
HugeIndex index = HugeIndex.parseIndexId(graph, entry.type(), bytes);
Object fieldValues = null;
if (!index.type().isRangeIndex()) {
fieldValues = query.condition(HugeKeys.FIELD_VALUES);
if (!index.fieldValues().equals(fieldValues)) {
// Update field-values for hashed or encoded index-id
index.fieldValues(fieldValues);
}
}
this.parseIndexName(graph, query, entry, index, fieldValues);
return index;
}
Aggregations