use of com.baidu.hugegraph.structure.HugeIndex in project incubator-hugegraph by apache.
the class DeleteExpiredIndexJob method execute.
@Override
public V execute() throws Exception {
LOG.debug("Delete expired indexes: {}", this.indexes);
HugeGraphParams graph = this.params();
GraphTransaction tx = graph.graphTransaction();
try {
for (HugeIndex index : this.indexes) {
this.deleteExpiredIndex(graph, index);
}
tx.commit();
} catch (Throwable e) {
tx.rollback();
LOG.warn("Failed to delete expired indexes: {}", this.indexes);
throw e;
} finally {
JOB_COUNTERS.jobCounter(graph.graph()).decrement();
}
return null;
}
use of com.baidu.hugegraph.structure.HugeIndex in project incubator-hugegraph by apache.
the class TableSerializer method readIndex.
@Override
public HugeIndex readIndex(HugeGraph graph, ConditionQuery query, BackendEntry backendEntry) {
E.checkNotNull(graph, "serializer graph");
if (backendEntry == null) {
return null;
}
TableBackendEntry entry = this.convertEntry(backendEntry);
Object indexValues = entry.column(HugeKeys.FIELD_VALUES);
Number indexLabelId = entry.column(HugeKeys.INDEX_LABEL_ID);
Set<Object> elemIds = this.parseIndexElemIds(entry);
Number expiredTime = entry.column(HugeKeys.EXPIRED_TIME);
IndexLabel indexLabel = graph.indexLabel(this.toId(indexLabelId));
HugeIndex index = new HugeIndex(graph, indexLabel);
index.fieldValues(indexValues);
long expired = index.hasTtl() ? expiredTime.longValue() : 0L;
for (Object elemId : elemIds) {
index.elementIds(this.readId(elemId), expired);
}
return index;
}
use of com.baidu.hugegraph.structure.HugeIndex in project incubator-hugegraph by apache.
the class GraphIndexTransaction method existUniqueValueInStore.
private boolean existUniqueValueInStore(IndexLabel indexLabel, Object value) {
ConditionQuery query = new ConditionQuery(HugeType.UNIQUE_INDEX);
query.eq(HugeKeys.INDEX_LABEL_ID, indexLabel.id());
query.eq(HugeKeys.FIELD_VALUES, value);
boolean exist;
Iterator<BackendEntry> iterator = this.query(query).iterator();
try {
exist = iterator.hasNext();
if (exist) {
HugeIndex index = this.serializer.readIndex(graph(), query, iterator.next());
this.removeExpiredIndexIfNeeded(index, query.showExpired());
// Memory backend might return empty BackendEntry
if (index.elementIds().isEmpty()) {
return false;
}
LOG.debug("Already has existed unique index record {}", index.elementId());
}
while (iterator.hasNext()) {
LOG.warn("Unique constraint conflict found by record {}", iterator.next());
}
} finally {
CloseableIterator.closeIterator(iterator);
}
return exist;
}
use of com.baidu.hugegraph.structure.HugeIndex in project incubator-hugegraph by apache.
the class GraphIndexTransaction method removeIndex.
protected void removeIndex(IndexLabel indexLabel) {
HugeIndex index = new HugeIndex(this.graph(), indexLabel);
this.doRemove(this.serializer.writeIndex(index));
}
use of com.baidu.hugegraph.structure.HugeIndex in project incubator-hugegraph by apache.
the class GraphIndexTransaction method hasEliminateInTx.
private boolean hasEliminateInTx(IndexLabel indexLabel, Object value, Id elementId) {
HugeIndex index = new HugeIndex(this.graph(), indexLabel);
index.fieldValues(value);
index.elementIds(elementId);
BackendEntry entry = this.serializer.writeIndex(index);
return this.mutation().contains(entry, Action.ELIMINATE);
}
Aggregations