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;
}
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());
}
}
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;
}
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));
}
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);
}
});
}
Aggregations