Search in sources :

Example 6 with HugeIndex

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

Example 7 with HugeIndex

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();
        }
    });
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) LockUtil(com.baidu.hugegraph.util.LockUtil) Id(com.baidu.hugegraph.backend.id.Id) HugeIndex(com.baidu.hugegraph.structure.HugeIndex) BatchIdHolder(com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 8 with HugeIndex

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));
    }
}
Also used : SchemaLabel(com.baidu.hugegraph.schema.SchemaLabel) HugeIndex(com.baidu.hugegraph.structure.HugeIndex) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 9 with HugeIndex

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

Example 10 with HugeIndex

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;
}
Also used : 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