Search in sources :

Example 21 with GraphDef

use of com.alibaba.maxgraph.sdkcommon.schema.GraphDef in project GraphScope by alibaba.

the class SchemaManager method recoverInternal.

private void recoverInternal() throws IOException, ExecutionException, InterruptedException {
    logger.info("start recover");
    long snapshotId = this.snapshotManager.increaseWriteSnapshotId();
    CompletableFuture<Void> future = new CompletableFuture<>();
    this.snapshotManager.addSnapshotListener(snapshotId, () -> future.complete(null));
    future.get();
    GraphDef graphDef = this.graphDefFetcher.fetchGraphDef();
    this.graphDefRef.set(graphDef);
    this.ready = true;
    logger.info("SchemaManager recovered. version [" + graphDef.getVersion() + "]");
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef)

Example 22 with GraphDef

use of com.alibaba.maxgraph.sdkcommon.schema.GraphDef in project GraphScope by alibaba.

the class ClientTest method testGetSchema.

@Test
void testGetSchema() {
    GraphSchema schema = client.getSchema();
    System.out.println(((GraphDef) schema).toProto().toString());
}
Also used : GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) Test(org.junit.jupiter.api.Test)

Example 23 with GraphDef

use of com.alibaba.maxgraph.sdkcommon.schema.GraphDef in project GraphScope by alibaba.

the class DataLoadingTest method testGetSchema.

@Test
public void testGetSchema() {
    GraphSchema schema = client.getSchema();
    System.out.println(((GraphDef) schema).toProto().toString());
}
Also used : GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) Test(org.junit.jupiter.api.Test)

Example 24 with GraphDef

use of com.alibaba.maxgraph.sdkcommon.schema.GraphDef in project GraphScope by alibaba.

the class CommitDataLoadExecutor method execute.

@Override
public DdlResult execute(ByteString ddlBlob, GraphDef graphDef, int partitionCount) throws InvalidProtocolBufferException {
    CommitDataLoadPb commitDataLoadPb = CommitDataLoadPb.parseFrom(ddlBlob);
    DataLoadTargetPb dataLoadTargetPb = commitDataLoadPb.getTarget();
    DataLoadTarget dataLoadTarget = DataLoadTarget.parseProto(dataLoadTargetPb);
    String label = dataLoadTarget.getLabel();
    String srcLabel = dataLoadTarget.getSrcLabel();
    String dstLabel = dataLoadTarget.getDstLabel();
    long version = graphDef.getSchemaVersion();
    if (!graphDef.hasLabel(label)) {
        throw new DdlException("label [" + label + "] not exists, schema version [" + version + "]");
    }
    GraphDef.Builder graphDefBuilder = GraphDef.newBuilder(graphDef);
    TypeDef typeDef = graphDef.getTypeDef(label);
    DataLoadTarget.Builder targetBuilder = DataLoadTarget.newBuilder(dataLoadTarget);
    if (srcLabel == null || srcLabel.isEmpty()) {
        // Vertex type
        if (typeDef.getTypeEnum() != TypeEnum.VERTEX) {
            throw new DdlException("invalid data load target [" + dataLoadTarget + "], label is not a vertex");
        }
        targetBuilder.setLabelId(typeDef.getLabelId());
    } else {
        // Edge kind
        if (typeDef.getTypeEnum() != TypeEnum.EDGE) {
            throw new DdlException("invalid data load target [" + dataLoadTarget + "], label is not an edge");
        }
        EdgeKind.Builder edgeKindBuilder = EdgeKind.newBuilder();
        LabelId edgeLabelId = graphDef.getLabelId(label);
        if (edgeLabelId == null) {
            throw new DdlException("invalid edgeLabel [" + label + "], schema version [" + version + "]");
        }
        edgeKindBuilder.setEdgeLabelId(edgeLabelId);
        targetBuilder.setLabelId(edgeLabelId.getId());
        LabelId srcVertexLabelId = graphDef.getLabelId(srcLabel);
        if (srcVertexLabelId == null) {
            throw new DdlException("invalid srcVertexLabel [" + srcLabel + "], schema version [" + version + "]");
        }
        edgeKindBuilder.setSrcVertexLabelId(srcVertexLabelId);
        targetBuilder.setSrcLabelId(srcVertexLabelId.getId());
        LabelId dstVertexLabelId = graphDef.getLabelId(dstLabel);
        if (dstVertexLabelId == null) {
            throw new DdlException("invalid dstVertexLabel [" + dstLabel + "], schema version [" + version + "]");
        }
        edgeKindBuilder.setDstVertexLabelId(dstVertexLabelId);
        targetBuilder.setDstLabelId(dstVertexLabelId.getId());
        EdgeKind edgeKind = edgeKindBuilder.build();
        if (!graphDef.hasEdgeKind(edgeKind)) {
            throw new DdlException("invalid data load target [" + dataLoadTarget + "], edgeKind not exists");
        }
    }
    version++;
    graphDefBuilder.setVersion(version);
    GraphDef newGraphDef = graphDefBuilder.build();
    List<Operation> operations = new ArrayList<>(partitionCount);
    for (int i = 0; i < partitionCount; i++) {
        operations.add(new CommitDataLoadOperation(i, version, CommitDataLoadPb.newBuilder().setTableIdx(commitDataLoadPb.getTableIdx()).setTarget(targetBuilder.build().toProto()).build()));
    }
    return new DdlResult(newGraphDef, operations);
}
Also used : DdlException(com.alibaba.graphscope.groot.schema.request.DdlException) EdgeKind(com.alibaba.maxgraph.sdkcommon.schema.EdgeKind) CommitDataLoadOperation(com.alibaba.graphscope.groot.operation.ddl.CommitDataLoadOperation) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Operation(com.alibaba.graphscope.groot.operation.Operation) CommitDataLoadOperation(com.alibaba.graphscope.groot.operation.ddl.CommitDataLoadOperation) CommitDataLoadPb(com.alibaba.maxgraph.proto.CommitDataLoadPb) DataLoadTargetPb(com.alibaba.maxgraph.proto.DataLoadTargetPb) GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef) DataLoadTarget(com.alibaba.maxgraph.sdkcommon.common.DataLoadTarget) TypeDef(com.alibaba.maxgraph.sdkcommon.schema.TypeDef) LabelId(com.alibaba.maxgraph.sdkcommon.schema.LabelId)

Example 25 with GraphDef

use of com.alibaba.maxgraph.sdkcommon.schema.GraphDef in project GraphScope by alibaba.

the class DdlExecutors method executeDdlRequestBatch.

public DdlResult executeDdlRequestBatch(DdlRequestBatch ddlRequestBatch, GraphDef graphDef, int partitionCount) throws InvalidProtocolBufferException {
    List<Operation> operations = new ArrayList<>();
    GraphDef tmpGraphDef = graphDef;
    for (DdlRequestBlob ddlRequestBlob : ddlRequestBatch) {
        OperationType operationType = ddlRequestBlob.getOperationType();
        ByteString ddlBlob = ddlRequestBlob.getBytes();
        DdlResult ddlResult = getExecutor(operationType).execute(ddlBlob, tmpGraphDef, partitionCount);
        operations.addAll(ddlResult.getDdlOperations());
        tmpGraphDef = ddlResult.getGraphDef();
    }
    return new DdlResult(tmpGraphDef, operations);
}
Also used : ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) DdlRequestBlob(com.alibaba.graphscope.groot.schema.request.DdlRequestBlob) Operation(com.alibaba.graphscope.groot.operation.Operation) OperationType(com.alibaba.graphscope.groot.operation.OperationType) GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef)

Aggregations

GraphDef (com.alibaba.maxgraph.sdkcommon.schema.GraphDef)25 Operation (com.alibaba.graphscope.groot.operation.Operation)9 Test (org.junit.jupiter.api.Test)9 ByteString (com.google.protobuf.ByteString)8 ArrayList (java.util.ArrayList)8 EdgeKind (com.alibaba.maxgraph.sdkcommon.schema.EdgeKind)7 LabelId (com.alibaba.maxgraph.sdkcommon.schema.LabelId)7 DdlException (com.alibaba.graphscope.groot.schema.request.DdlException)6 TypeDef (com.alibaba.maxgraph.sdkcommon.schema.TypeDef)6 PropertyDef (com.alibaba.maxgraph.sdkcommon.schema.PropertyDef)4 SnapshotCache (com.alibaba.graphscope.groot.SnapshotCache)3 SchemaManager (com.alibaba.graphscope.groot.coordinator.SchemaManager)3 CompletionCallback (com.alibaba.graphscope.groot.CompletionCallback)2 SnapshotListener (com.alibaba.graphscope.groot.SnapshotListener)2 MetaService (com.alibaba.graphscope.groot.meta.MetaService)2 BatchId (com.alibaba.graphscope.groot.operation.BatchId)2 AddEdgeKindOperation (com.alibaba.graphscope.groot.operation.ddl.AddEdgeKindOperation)2 RemoveEdgeKindOperation (com.alibaba.graphscope.groot.operation.ddl.RemoveEdgeKindOperation)2 DdlExecutors (com.alibaba.graphscope.groot.schema.ddl.DdlExecutors)2 DdlResult (com.alibaba.graphscope.groot.schema.ddl.DdlResult)2