Search in sources :

Example 16 with GraphDef

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

the class SnapshotCache method advanceQuerySnapshotId.

/**
 * This method will update querySnapshotId and returns the previous value.
 *
 * <p>SnapshotManager will gather ingest progresses from all the WriterAgents, and calculate the
 * available querySnapshotId. Then SnapshotManager will call this method to update
 * querySnapshotId for each Frontend node.
 *
 * <p>Discussion:
 *
 * <p>We need to decide whether should the write framework coupled with the implementation of
 * schema synchronization. Options are discussed here:
 * https://yuque.antfin-inc.com/graphscope/project/eibfty#EQGg9 This interface assumes write
 * framework isn't coupled with schema synchronization.
 *
 * @param snapshotId
 * @param graphDef
 * @return
 */
public synchronized long advanceQuerySnapshotId(long snapshotId, GraphDef graphDef) {
    SnapshotWithSchema snapshotWithSchema = this.snapshotWithSchemaRef.get();
    long currentSnapshotId = snapshotWithSchema.getSnapshotId();
    if (currentSnapshotId >= snapshotId) {
        throw new IllegalStateException("current currentSnapshotId [" + currentSnapshotId + "], cannot update to [" + snapshotId + "]");
    }
    SnapshotWithSchema.Builder newSnapshotInfoBuilder = SnapshotWithSchema.newBuilder(snapshotWithSchema);
    newSnapshotInfoBuilder.setSnapshotId(snapshotId);
    GraphDef oldGraphDef = snapshotWithSchema.getGraphDef();
    if (graphDef != null && (oldGraphDef == null || graphDef.getSchemaVersion() > oldGraphDef.getVersion())) {
        newSnapshotInfoBuilder.setGraphDef(graphDef);
        logger.info("schema updated. schema version [" + graphDef.getVersion() + "]");
    }
    this.snapshotWithSchemaRef.set(newSnapshotInfoBuilder.build());
    logger.debug("snapshotId update to [" + snapshotId + "]");
    synchronized (this.snapshotToListeners) {
        NavigableMap<Long, List<SnapshotListener>> listenersToTrigger = this.snapshotToListeners.headMap(snapshotId, true);
        for (Map.Entry<Long, List<SnapshotListener>> listenerEntry : listenersToTrigger.entrySet()) {
            List<SnapshotListener> listeners = listenerEntry.getValue();
            long listenSnapshotId = listenerEntry.getKey();
            for (SnapshotListener listener : listeners) {
                try {
                    listener.onSnapshotAvailable();
                    logger.info("notify listener for snapshot id [" + listenSnapshotId + "]");
                } catch (Exception e) {
                    logger.warn("trigger snapshotListener failed. snapshotId [" + snapshotId + "]");
                }
            }
        }
        listenersToTrigger.clear();
    }
    return currentSnapshotId;
}
Also used : GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef) List(java.util.List) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Map(java.util.Map) NavigableMap(java.util.NavigableMap)

Example 17 with GraphDef

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

the class ClientService method dropSchema.

@Override
public void dropSchema(DropSchemaRequest request, StreamObserver<DropSchemaResponse> responseObserver) {
    try {
        DdlRequestBatch.Builder ddlBatchBuilder = DdlRequestBatch.newBuilder();
        GraphDef graphDef = this.snapshotCache.getSnapshotWithSchema().getGraphDef();
        for (GraphEdge graphEdge : graphDef.getEdgeList()) {
            String label = graphEdge.getLabel();
            for (EdgeRelation relation : graphEdge.getRelationList()) {
                String sourceLabel = relation.getSource().getLabel();
                String destLabel = relation.getTarget().getLabel();
                EdgeKind edgeKind = EdgeKind.newBuilder().setEdgeLabel(label).setSrcVertexLabel(sourceLabel).setDstVertexLabel(destLabel).build();
                RemoveEdgeKindRequest removeEdgeKindRequest = new RemoveEdgeKindRequest(edgeKind);
                ddlBatchBuilder.addDdlRequest(removeEdgeKindRequest);
            }
            DropEdgeTypeRequest dropEdgeTypeRequest = new DropEdgeTypeRequest(label);
            ddlBatchBuilder.addDdlRequest(dropEdgeTypeRequest);
        }
        for (GraphVertex graphVertex : graphDef.getVertexList()) {
            DropVertexTypeRequest dropVertexTypeRequest = new DropVertexTypeRequest(graphVertex.getLabel());
            ddlBatchBuilder.addDdlRequest(dropVertexTypeRequest);
        }
        long snapshotId = this.batchDdlClient.batchDdl(ddlBatchBuilder.build());
        this.snapshotCache.addListener(snapshotId, () -> {
            responseObserver.onNext(DropSchemaResponse.newBuilder().setGraphDef(this.snapshotCache.getSnapshotWithSchema().getGraphDef().toProto()).build());
            responseObserver.onCompleted();
        });
    } catch (Exception e) {
        logger.error("drop schema commit failed", e);
        responseObserver.onError(Status.INTERNAL.withDescription(e.getMessage()).asRuntimeException());
    }
}
Also used : EdgeKind(com.alibaba.maxgraph.sdkcommon.schema.EdgeKind) GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef)

Example 18 with GraphDef

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

the class StoreSchemaClient method fetchSchema.

public GraphDef fetchSchema() {
    FetchSchemaResponse response = this.stub.fetchSchema(FetchSchemaRequest.newBuilder().build());
    GraphDef graphDef = GraphDef.parseProto(response.getGraphDef());
    return graphDef;
}
Also used : FetchSchemaResponse(com.alibaba.maxgraph.proto.groot.FetchSchemaResponse) GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef)

Example 19 with GraphDef

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

the class LocalSnapshotListener method snapshotAdvanced.

@Override
public void snapshotAdvanced(long snapshotId, long ddlSnapshotId) {
    logger.debug("snapshot advance to [" + snapshotId + "]-[" + ddlSnapshotId + "], will update local snapshot cache");
    GraphDef graphDef = null;
    if (ddlSnapshotId > this.lastDdlSnapshotId.get()) {
        graphDef = this.schemaManager.getGraphDef();
    }
    this.snapshotCache.advanceQuerySnapshotId(snapshotId, graphDef);
    lastDdlSnapshotId.getAndUpdate(x -> Math.max(x, ddlSnapshotId));
}
Also used : GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef)

Example 20 with GraphDef

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

the class NotifyFrontendListener method snapshotAdvanced.

@Override
public void snapshotAdvanced(long snapshotId, long ddlSnapshotId) {
    logger.debug("snapshot advance to [" + snapshotId + "]-[" + ddlSnapshotId + "], will notify frontend");
    GraphDef graphDef = null;
    if (ddlSnapshotId > this.lastDdlSnapshotId.get()) {
        graphDef = this.schemaManager.getGraphDef();
    }
    this.frontendSnapshotClient.advanceQuerySnapshot(snapshotId, graphDef, new CompletionCallback<Long>() {

        @Override
        public void onCompleted(Long res) {
            if (res >= snapshotId) {
                logger.warn("unexpected previousSnapshotId [" + res + "], should <= [" + snapshotId + "]. frontend [" + frontendId + "]");
            } else {
                lastDdlSnapshotId.getAndUpdate(x -> x < ddlSnapshotId ? ddlSnapshotId : x);
            }
        }

        @Override
        public void onError(Throwable t) {
            logger.error("error in advanceQuerySnapshot [" + snapshotId + "], ddlSnapshotId [" + ddlSnapshotId + "], frontend [" + frontendId + "]", t);
        }
    });
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Logger(org.slf4j.Logger) GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef) LoggerFactory(org.slf4j.LoggerFactory) CompletionCallback(com.alibaba.graphscope.groot.CompletionCallback) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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