Search in sources :

Example 11 with HugeType

use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.

the class StoreDumper method main.

public static void main(String[] args) throws Exception {
    E.checkArgument(args.length >= 1, "StoreDumper need a config file.");
    String conf = args[0];
    RegisterUtil.registerBackends();
    HugeType table = HugeType.valueOf(arg(args, 1, "VERTEX").toUpperCase());
    long offset = Long.parseLong(arg(args, 2, "0"));
    long limit = Long.parseLong(arg(args, 3, "20"));
    StoreDumper dumper = new StoreDumper(conf);
    dumper.dump(table, offset, limit);
    dumper.close();
    // Stop daemon thread
    HugeFactory.shutdown(30L);
}
Also used : HugeType(com.baidu.hugegraph.type.HugeType)

Example 12 with HugeType

use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.

the class SchemaTransaction method removeIndexLabelFromBaseLabel.

@Watched(prefix = "schema")
public void removeIndexLabelFromBaseLabel(IndexLabel indexLabel) {
    HugeType baseType = indexLabel.baseType();
    Id baseValue = indexLabel.baseValue();
    SchemaLabel schemaLabel;
    if (baseType == HugeType.VERTEX_LABEL) {
        schemaLabel = this.getVertexLabel(baseValue);
    } else {
        assert baseType == HugeType.EDGE_LABEL;
        schemaLabel = this.getEdgeLabel(baseValue);
    }
    if (schemaLabel == null) {
        LOG.info("The base label '{}' of index label '{}' " + "may be deleted before", baseValue, indexLabel);
        return;
    }
    if (schemaLabel.equals(VertexLabel.OLAP_VL)) {
        return;
    }
    // FIXME: move schemaLabel update into updateSchema() lock block instead
    synchronized (schemaLabel) {
        schemaLabel.removeIndexLabel(indexLabel.id());
        this.updateSchema(schemaLabel);
    }
}
Also used : SchemaLabel(com.baidu.hugegraph.schema.SchemaLabel) Id(com.baidu.hugegraph.backend.id.Id) HugeType(com.baidu.hugegraph.type.HugeType) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 13 with HugeType

use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.

the class EdgeId method parse.

public static EdgeId parse(String id, boolean returnNullIfError) throws NotFoundException {
    String[] idParts = SplicingIdGenerator.split(id);
    if (!(idParts.length == 4 || idParts.length == 5)) {
        if (returnNullIfError) {
            return null;
        }
        throw new NotFoundException("Edge id must be formatted as 4~5 " + "parts, but got %s parts: '%s'", idParts.length, id);
    }
    try {
        if (idParts.length == 4) {
            Id ownerVertexId = IdUtil.readString(idParts[0]);
            Id edgeLabelId = IdUtil.readLong(idParts[1]);
            String sortValues = idParts[2];
            Id otherVertexId = IdUtil.readString(idParts[3]);
            return new EdgeId(ownerVertexId, Directions.OUT, edgeLabelId, sortValues, otherVertexId);
        } else {
            assert idParts.length == 5;
            Id ownerVertexId = IdUtil.readString(idParts[0]);
            HugeType direction = HugeType.fromString(idParts[1]);
            Id edgeLabelId = IdUtil.readLong(idParts[2]);
            String sortValues = idParts[3];
            Id otherVertexId = IdUtil.readString(idParts[4]);
            return new EdgeId(ownerVertexId, Directions.convert(direction), edgeLabelId, sortValues, otherVertexId);
        }
    } catch (Throwable e) {
        if (returnNullIfError) {
            return null;
        }
        throw new NotFoundException("Invalid format of edge id '%s'", e, id);
    }
}
Also used : NotFoundException(com.baidu.hugegraph.exception.NotFoundException) HugeType(com.baidu.hugegraph.type.HugeType)

Example 14 with HugeType

use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.

the class CachedGraphTransaction method listenChanges.

private void listenChanges() {
    // Listen store event: "store.init", "store.clear", ...
    Set<String> storeEvents = ImmutableSet.of(Events.STORE_INIT, Events.STORE_CLEAR, Events.STORE_TRUNCATE);
    this.storeEventListener = event -> {
        if (storeEvents.contains(event.name())) {
            LOG.debug("Graph {} clear graph cache on event '{}'", this.graph(), event.name());
            this.clearCache(null, true);
            return true;
        }
        return false;
    };
    this.store().provider().listen(this.storeEventListener);
    // Listen cache event: "cache"(invalid cache item)
    this.cacheEventListener = event -> {
        LOG.debug("Graph {} received graph cache event: {}", this.graph(), event);
        Object[] args = event.args();
        E.checkArgument(args.length > 0 && args[0] instanceof String, "Expect event action argument");
        if (Cache.ACTION_INVALID.equals(args[0])) {
            event.checkArgs(String.class, HugeType.class, Object.class);
            HugeType type = (HugeType) args[1];
            if (type.isVertex()) {
                // Invalidate vertex cache
                Object arg2 = args[2];
                if (arg2 instanceof Id) {
                    Id id = (Id) arg2;
                    this.verticesCache.invalidate(id);
                } else if (arg2 != null && arg2.getClass().isArray()) {
                    int size = Array.getLength(arg2);
                    for (int i = 0; i < size; i++) {
                        Object id = Array.get(arg2, i);
                        E.checkArgument(id instanceof Id, "Expect instance of Id in array, " + "but got '%s'", id.getClass());
                        this.verticesCache.invalidate((Id) id);
                    }
                } else {
                    E.checkArgument(false, "Expect Id or Id[], but got: %s", arg2);
                }
            } else if (type.isEdge()) {
                /*
                     * Invalidate edge cache via clear instead of invalidate
                     * because of the cacheKey is QueryId not EdgeId
                     */
                // this.edgesCache.invalidate(id);
                this.edgesCache.clear();
            }
            return true;
        } else if (Cache.ACTION_CLEAR.equals(args[0])) {
            event.checkArgs(String.class, HugeType.class);
            HugeType type = (HugeType) args[1];
            this.clearCache(type, false);
            return true;
        }
        return false;
    };
    EventHub graphEventHub = this.params().graphEventHub();
    if (!graphEventHub.containsListener(Events.CACHE)) {
        graphEventHub.listen(Events.CACHE, this.cacheEventListener);
    }
}
Also used : EventHub(com.baidu.hugegraph.event.EventHub) QueryId(com.baidu.hugegraph.backend.cache.CachedBackendStore.QueryId) Id(com.baidu.hugegraph.backend.id.Id) HugeType(com.baidu.hugegraph.type.HugeType)

Example 15 with HugeType

use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.

the class TableSerializer method readIndexLabel.

@Override
public IndexLabel readIndexLabel(HugeGraph graph, BackendEntry backendEntry) {
    if (backendEntry == null) {
        return null;
    }
    TableBackendEntry entry = this.convertEntry(backendEntry);
    Number id = schemaColumn(entry, HugeKeys.ID);
    String name = schemaColumn(entry, HugeKeys.NAME);
    HugeType baseType = schemaEnum(entry, HugeKeys.BASE_TYPE, HugeType.class);
    Number baseValueId = schemaColumn(entry, HugeKeys.BASE_VALUE);
    IndexType indexType = schemaEnum(entry, HugeKeys.INDEX_TYPE, IndexType.class);
    Object indexFields = schemaColumn(entry, HugeKeys.FIELDS);
    SchemaStatus status = schemaEnum(entry, HugeKeys.STATUS, SchemaStatus.class);
    IndexLabel indexLabel = new IndexLabel(graph, this.toId(id), name);
    indexLabel.baseType(baseType);
    indexLabel.baseValue(this.toId(baseValueId));
    indexLabel.indexType(indexType);
    indexLabel.indexFields(this.toIdArray(indexFields));
    indexLabel.status(status);
    this.readUserdata(indexLabel, entry);
    return indexLabel;
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) IndexType(com.baidu.hugegraph.type.define.IndexType) HugeType(com.baidu.hugegraph.type.HugeType) SchemaStatus(com.baidu.hugegraph.type.define.SchemaStatus)

Aggregations

HugeType (com.baidu.hugegraph.type.HugeType)34 Id (com.baidu.hugegraph.backend.id.Id)16 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)5 Query (com.baidu.hugegraph.backend.query.Query)4 ExistedException (com.baidu.hugegraph.exception.ExistedException)4 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)4 ArrayList (java.util.ArrayList)4 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)3 Condition (com.baidu.hugegraph.backend.query.Condition)3 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)3 BinaryBackendEntry (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)3 BinaryId (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId)3 BackendAction (com.baidu.hugegraph.backend.store.BackendAction)3 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)3 Lock (java.util.concurrent.locks.Lock)3 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)3 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)3 HugeException (com.baidu.hugegraph.HugeException)2 BackendException (com.baidu.hugegraph.backend.BackendException)2 BinaryEntryIterator (com.baidu.hugegraph.backend.serializer.BinaryEntryIterator)2