Search in sources :

Example 1 with PageIds

use of com.baidu.hugegraph.backend.page.PageIds in project incubator-hugegraph by apache.

the class GraphIndexTransaction method doIndexQueryOnce.

@Watched(prefix = "index")
private PageIds doIndexQueryOnce(IndexLabel indexLabel, ConditionQuery query) {
    // Query all or one page
    Iterator<BackendEntry> entries = null;
    LockUtil.Locks locks = new LockUtil.Locks(this.graphName());
    try {
        locks.lockReads(LockUtil.INDEX_LABEL_DELETE, indexLabel.id());
        locks.lockReads(LockUtil.INDEX_LABEL_REBUILD, indexLabel.id());
        Set<Id> ids = InsertionOrderUtil.newSet();
        entries = super.query(query).iterator();
        while (entries.hasNext()) {
            HugeIndex index = this.serializer.readIndex(graph(), query, entries.next());
            this.removeExpiredIndexIfNeeded(index, query.showExpired());
            ids.addAll(index.elementIds());
            if (query.reachLimit(ids.size())) {
                break;
            }
            Query.checkForceCapacity(ids.size());
            this.recordIndexValue(query, index);
        }
        // If there is no data, the entries is not a Metadatable object
        if (ids.isEmpty()) {
            return PageIds.EMPTY;
        }
        // NOTE: Memory backend's iterator is not Metadatable
        if (!query.paging()) {
            return new PageIds(ids, PageState.EMPTY);
        }
        E.checkState(entries instanceof Metadatable, "The entries must be Metadatable when query " + "in paging, but got '%s'", entries.getClass().getName());
        return new PageIds(ids, PageInfo.pageState(entries));
    } finally {
        locks.unlock();
        CloseableIterator.closeIterator(entries);
    }
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) Metadatable(com.baidu.hugegraph.iterator.Metadatable) LockUtil(com.baidu.hugegraph.util.LockUtil) PageIds(com.baidu.hugegraph.backend.page.PageIds) Id(com.baidu.hugegraph.backend.id.Id) HugeIndex(com.baidu.hugegraph.structure.HugeIndex) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Aggregations

Id (com.baidu.hugegraph.backend.id.Id)1 PageIds (com.baidu.hugegraph.backend.page.PageIds)1 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)1 Metadatable (com.baidu.hugegraph.iterator.Metadatable)1 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)1 HugeIndex (com.baidu.hugegraph.structure.HugeIndex)1 LockUtil (com.baidu.hugegraph.util.LockUtil)1