Search in sources :

Example 31 with BackendEntry

use of com.baidu.hugegraph.backend.store.BackendEntry 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 32 with BackendEntry

use of com.baidu.hugegraph.backend.store.BackendEntry in project incubator-hugegraph by apache.

the class SchemaTransaction method getSchema.

protected <T extends SchemaElement> T getSchema(HugeType type, Id id) {
    LOG.debug("SchemaTransaction get {} by id '{}'", type.readableName(), id);
    this.beforeRead();
    BackendEntry entry = this.query(type, id);
    if (entry == null) {
        return null;
    }
    T schema = this.deserialize(entry, type);
    this.afterRead();
    return schema;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry)

Example 33 with BackendEntry

use of com.baidu.hugegraph.backend.store.BackendEntry in project incubator-hugegraph by apache.

the class SchemaTransaction method getSchema.

/**
 * Currently doesn't allow to exist schema with the same name
 * @param type the query schema type
 * @param name the query schema name
 * @param <T>  SubClass of SchemaElement
 * @return     the queried schema object
 */
protected <T extends SchemaElement> T getSchema(HugeType type, String name) {
    LOG.debug("SchemaTransaction get {} by name '{}'", type.readableName(), name);
    this.beforeRead();
    ConditionQuery query = new ConditionQuery(type);
    query.eq(HugeKeys.NAME, name);
    QueryResults<BackendEntry> results = this.indexTx.query(query);
    this.afterRead();
    // Should not exist schema with same name
    BackendEntry entry = results.one();
    if (entry == null) {
        return null;
    }
    return this.deserialize(entry, type);
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery)

Example 34 with BackendEntry

use of com.baidu.hugegraph.backend.store.BackendEntry in project incubator-hugegraph by apache.

the class BinarySerializer method parse.

public BackendEntry parse(BackendEntry originEntry) {
    byte[] bytes = originEntry.id().asBytes();
    BinaryBackendEntry parsedEntry = new BinaryBackendEntry(originEntry.type(), bytes, this.enablePartition);
    if (this.enablePartition) {
        bytes = Arrays.copyOfRange(bytes, parsedEntry.id().length() + 2, bytes.length);
    } else {
        bytes = Arrays.copyOfRange(bytes, parsedEntry.id().length(), bytes.length);
    }
    BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID);
    buffer.write(parsedEntry.id().asBytes());
    buffer.write(bytes);
    parsedEntry = new BinaryBackendEntry(originEntry.type(), new BinaryId(buffer.bytes(), BytesBuffer.wrap(buffer.bytes()).readEdgeId()));
    for (BackendEntry.BackendColumn col : originEntry.columns()) {
        parsedEntry.column(buffer.bytes(), col.value);
    }
    return parsedEntry;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) BackendColumn(com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn)

Example 35 with BackendEntry

use of com.baidu.hugegraph.backend.store.BackendEntry in project incubator-hugegraph by apache.

the class InMemoryDBStore method mutate.

protected void mutate(BackendAction item) {
    BackendEntry e = item.entry();
    assert e instanceof TextBackendEntry;
    TextBackendEntry entry = (TextBackendEntry) e;
    InMemoryDBTable table = this.table(entry.type());
    switch(item.action()) {
        case INSERT:
            LOG.debug("[store {}] add entry: {}", this.store, entry);
            table.insert(null, entry);
            break;
        case DELETE:
            LOG.debug("[store {}] remove id: {}", this.store, entry.id());
            table.delete(null, entry);
            break;
        case APPEND:
            LOG.debug("[store {}] append entry: {}", this.store, entry);
            table.append(null, entry);
            break;
        case ELIMINATE:
            LOG.debug("[store {}] eliminate entry: {}", this.store, entry);
            table.eliminate(null, entry);
            break;
        default:
            throw new BackendException("Unsupported mutate type: %s", item.action());
    }
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) TextBackendEntry(com.baidu.hugegraph.backend.serializer.TextBackendEntry) TextBackendEntry(com.baidu.hugegraph.backend.serializer.TextBackendEntry) BackendException(com.baidu.hugegraph.backend.BackendException)

Aggregations

BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)54 Test (org.junit.Test)27 TextBackendEntry (com.baidu.hugegraph.backend.serializer.TextBackendEntry)26 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)26 BackendMutation (com.baidu.hugegraph.backend.store.BackendMutation)21 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)7 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)7 Id (com.baidu.hugegraph.backend.id.Id)6 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)6 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)5 BinaryBackendEntry (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)5 HugeIndex (com.baidu.hugegraph.structure.HugeIndex)5 Query (com.baidu.hugegraph.backend.query.Query)4 BinarySerializer (com.baidu.hugegraph.backend.serializer.BinarySerializer)4 HugeConfig (com.baidu.hugegraph.config.HugeConfig)4 ArrayList (java.util.ArrayList)4 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)3 LockUtil (com.baidu.hugegraph.util.LockUtil)3 BackendException (com.baidu.hugegraph.backend.BackendException)2 Condition (com.baidu.hugegraph.backend.query.Condition)2