Search in sources :

Example 1 with HugeIndex

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;
}
Also used : HugeGraphParams(com.baidu.hugegraph.HugeGraphParams) GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) HugeIndex(com.baidu.hugegraph.structure.HugeIndex)

Example 2 with HugeIndex

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;
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) HugeIndex(com.baidu.hugegraph.structure.HugeIndex)

Example 3 with HugeIndex

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;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) HugeIndex(com.baidu.hugegraph.structure.HugeIndex)

Example 4 with HugeIndex

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));
}
Also used : HugeIndex(com.baidu.hugegraph.structure.HugeIndex)

Example 5 with HugeIndex

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);
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) HugeIndex(com.baidu.hugegraph.structure.HugeIndex)

Aggregations

HugeIndex (com.baidu.hugegraph.structure.HugeIndex)14 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)5 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)5 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)4 Id (com.baidu.hugegraph.backend.id.Id)3 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)2 LockUtil (com.baidu.hugegraph.util.LockUtil)2 HugeGraphParams (com.baidu.hugegraph.HugeGraphParams)1 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)1 BatchIdHolder (com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder)1 PageIds (com.baidu.hugegraph.backend.page.PageIds)1 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)1 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)1 Metadatable (com.baidu.hugegraph.iterator.Metadatable)1 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)1 IdWithExpiredTime (com.baidu.hugegraph.structure.HugeIndex.IdWithExpiredTime)1 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)1