Search in sources :

Example 1 with SchemaLabel

use of com.baidu.hugegraph.schema.SchemaLabel in project incubator-hugegraph by apache.

the class IndexLabelBuilder method createWithTask.

/**
 * Create index label with async mode
 */
@Override
public SchemaElement.TaskWithSchema createWithTask() {
    HugeType type = HugeType.INDEX_LABEL;
    this.checkSchemaName(this.name);
    return this.lockCheckAndCreateSchema(type, this.name, name -> {
        IndexLabel indexLabel = this.indexLabelOrNull(name);
        if (indexLabel != null) {
            if (this.checkExist || !hasSameProperties(indexLabel)) {
                throw new ExistedException(type, name);
            }
            return new SchemaElement.TaskWithSchema(indexLabel, IdGenerator.ZERO);
        }
        this.checkSchemaIdIfRestoringMode(type, this.id);
        this.checkBaseType();
        this.checkIndexType();
        if (VertexLabel.OLAP_VL.name().equals(this.baseValue)) {
            return new SchemaElement.TaskWithSchema(this.build(), IdGenerator.ZERO);
        }
        SchemaLabel schemaLabel = this.loadBaseLabel();
        /*
             * If new index label is prefix of existed index label, or has
             * the same fields, fail to create new index label.
             */
        this.checkFields(schemaLabel.properties());
        this.checkRepeatIndex(schemaLabel);
        Userdata.check(this.userdata, Action.INSERT);
        // Async delete index label which is prefix of the new index label
        // TODO: use event to replace direct call
        Set<Id> removeTasks = this.removeSubIndex(schemaLabel);
        indexLabel = this.build();
        assert indexLabel.name().equals(name);
        /*
             * If not rebuild, just create index label and return.
             * The actual indexes may be rebuilt later as needed
             */
        if (!this.rebuild) {
            indexLabel.status(SchemaStatus.CREATED);
            this.graph().addIndexLabel(schemaLabel, indexLabel);
            return new SchemaElement.TaskWithSchema(indexLabel, IdGenerator.ZERO);
        }
        // Create index label (just schema)
        indexLabel.status(SchemaStatus.CREATING);
        this.graph().addIndexLabel(schemaLabel, indexLabel);
        try {
            // Async rebuild index
            Id rebuildTask = this.rebuildIndex(indexLabel, removeTasks);
            E.checkNotNull(rebuildTask, "rebuild-index task");
            return new SchemaElement.TaskWithSchema(indexLabel, rebuildTask);
        } catch (Throwable e) {
            this.updateSchemaStatus(indexLabel, SchemaStatus.INVALID);
            throw e;
        }
    });
}
Also used : ExistedException(com.baidu.hugegraph.exception.ExistedException) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) SchemaLabel(com.baidu.hugegraph.schema.SchemaLabel) Id(com.baidu.hugegraph.backend.id.Id) HugeType(com.baidu.hugegraph.type.HugeType)

Example 2 with SchemaLabel

use of com.baidu.hugegraph.schema.SchemaLabel in project incubator-hugegraph by apache.

the class HugeElement method setExpiredTimeIfNeeded.

public void setExpiredTimeIfNeeded() {
    SchemaLabel label = this.schemaLabel();
    if (label.ttl() == 0L) {
        return;
    }
    long now = this.graph.now();
    if (SchemaLabel.NONE_ID.equals(label.ttlStartTime())) {
        this.expiredTime(now + label.ttl());
        return;
    }
    Date date = this.getPropertyValue(label.ttlStartTime());
    if (date == null) {
        this.expiredTime(now + label.ttl());
        return;
    }
    long expired = date.getTime() + label.ttl();
    E.checkArgument(expired > now, "The expired time '%s' of '%s' is prior to now: %s", new Date(expired), this, now);
    this.expiredTime(expired);
}
Also used : SchemaLabel(com.baidu.hugegraph.schema.SchemaLabel) Date(java.util.Date)

Example 3 with SchemaLabel

use of com.baidu.hugegraph.schema.SchemaLabel in project incubator-hugegraph by apache.

the class HugeGraphAuthProxy method rebuildIndex.

@Override
public Id rebuildIndex(SchemaElement schema) {
    if (schema.type() == HugeType.INDEX_LABEL) {
        verifySchemaPermission(HugePermission.WRITE, schema);
    } else {
        SchemaLabel label = (SchemaLabel) schema;
        for (Id il : label.indexLabels()) {
            IndexLabel indexLabel = this.hugegraph.indexLabel(il);
            verifySchemaPermission(HugePermission.WRITE, indexLabel);
        }
    }
    return this.hugegraph.rebuildIndex(schema);
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) SchemaLabel(com.baidu.hugegraph.schema.SchemaLabel) Id(com.baidu.hugegraph.backend.id.Id)

Example 4 with SchemaLabel

use of com.baidu.hugegraph.schema.SchemaLabel 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 5 with SchemaLabel

use of com.baidu.hugegraph.schema.SchemaLabel 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)

Aggregations

SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)14 Id (com.baidu.hugegraph.backend.id.Id)8 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)8 HugeType (com.baidu.hugegraph.type.HugeType)5 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)4 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)2 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)2 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)2 HugeElement (com.baidu.hugegraph.structure.HugeElement)2 HugeException (com.baidu.hugegraph.HugeException)1 HugeGraph (com.baidu.hugegraph.HugeGraph)1 IdHolder (com.baidu.hugegraph.backend.page.IdHolder)1 BatchIdHolder (com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder)1 FixedIdHolder (com.baidu.hugegraph.backend.page.IdHolder.FixedIdHolder)1 PagingIdHolder (com.baidu.hugegraph.backend.page.IdHolder.PagingIdHolder)1 IdHolderList (com.baidu.hugegraph.backend.page.IdHolderList)1 SortByCountIdHolderList (com.baidu.hugegraph.backend.page.SortByCountIdHolderList)1 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)1 Query (com.baidu.hugegraph.backend.query.Query)1 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)1