Search in sources :

Example 1 with OperationType

use of com.alibaba.graphscope.groot.operation.OperationType in project GraphScope by alibaba.

the class GraphWriter method writeBatch.

public void writeBatch(String requestId, String writeSession, List<WriteRequest> writeRequests, CompletionCallback<Long> callback) {
    this.pendingWriteCount.incrementAndGet();
    GraphSchema schema = snapshotCache.getSnapshotWithSchema().getGraphDef();
    OperationBatch.Builder batchBuilder = OperationBatch.newBuilder();
    for (WriteRequest writeRequest : writeRequests) {
        OperationType operationType = writeRequest.getOperationType();
        DataRecord dataRecord = writeRequest.getDataRecord();
        switch(operationType) {
            case OVERWRITE_VERTEX:
                addOverwriteVertexOperation(batchBuilder, schema, dataRecord);
                break;
            case UPDATE_VERTEX:
                addUpdateVertexOperation(batchBuilder, schema, dataRecord);
                break;
            case DELETE_VERTEX:
                addDeleteVertexOperation(batchBuilder, schema, dataRecord);
                break;
            case OVERWRITE_EDGE:
                addOverwriteEdgeOperation(batchBuilder, schema, dataRecord);
                break;
            case UPDATE_EDGE:
                addUpdateEdgeOperation(batchBuilder, schema, dataRecord);
                break;
            case DELETE_EDGE:
                addDeleteEdgeOperation(batchBuilder, schema, dataRecord);
                break;
            default:
                throw new IllegalArgumentException("Invalid operationType [" + operationType + "]");
        }
    }
    OperationBatch operationBatch = batchBuilder.build();
    int writeQueueId = getWriteQueueId(writeSession);
    int ingestorId = this.metaService.getIngestorIdForQueue(writeQueueId);
    long startTimeNano = System.nanoTime();
    this.ingestWriteClients.getClient(ingestorId).writeIngestorAsync(requestId, writeQueueId, operationBatch, new CompletionCallback<Long>() {

        @Override
        public void onCompleted(Long res) {
            long writeSnapshotId = res;
            lastWrittenSnapshotId.updateAndGet(x -> x < writeSnapshotId ? writeSnapshotId : x);
            writeRequestsTotal.addAndGet(writeRequests.size());
            finish();
            callback.onCompleted(res);
        }

        @Override
        public void onError(Throwable t) {
            finish();
            callback.onError(t);
        }

        void finish() {
            long ingestorCompleteTimeNano = System.nanoTime();
            ingestorBlockTimeNano.addAndGet(ingestorCompleteTimeNano - startTimeNano);
            pendingWriteCount.decrementAndGet();
        }
    });
}
Also used : VertexRecordKey(com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) PkHashUtils(com.alibaba.maxgraph.sdkcommon.util.PkHashUtils) EdgeRecordKey(com.alibaba.maxgraph.sdkcommon.common.EdgeRecordKey) OperationBatch(com.alibaba.graphscope.groot.operation.OperationBatch) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) DataType(com.alibaba.maxgraph.compiler.api.schema.DataType) ArrayList(java.util.ArrayList) WriteSessionUtil(com.alibaba.maxgraph.common.util.WriteSessionUtil) PropertyDefNotFoundException(com.alibaba.maxgraph.compiler.api.exception.PropertyDefNotFoundException) MetricsCollector(com.alibaba.graphscope.groot.metrics.MetricsCollector) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MetricsAgent(com.alibaba.graphscope.groot.metrics.MetricsAgent) LabelId(com.alibaba.maxgraph.sdkcommon.schema.LabelId) VertexId(com.alibaba.graphscope.groot.operation.VertexId) com.alibaba.graphscope.groot.operation.dml(com.alibaba.graphscope.groot.operation.dml) Map(java.util.Map) PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue) MaxGraphException(com.alibaba.maxgraph.compiler.api.exception.MaxGraphException) EdgeId(com.alibaba.graphscope.groot.operation.EdgeId) CompletionCallback(com.alibaba.graphscope.groot.CompletionCallback) GraphProperty(com.alibaba.maxgraph.compiler.api.schema.GraphProperty) MetaService(com.alibaba.graphscope.groot.meta.MetaService) EdgeKind(com.alibaba.maxgraph.sdkcommon.schema.EdgeKind) OperationType(com.alibaba.graphscope.groot.operation.OperationType) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) RoleClients(com.alibaba.graphscope.groot.rpc.RoleClients) List(java.util.List) SnapshotCache(com.alibaba.graphscope.groot.SnapshotCache) IngestorWriteClient(com.alibaba.graphscope.groot.frontend.IngestorWriteClient) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) OperationBatch(com.alibaba.graphscope.groot.operation.OperationBatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) OperationType(com.alibaba.graphscope.groot.operation.OperationType)

Example 2 with OperationType

use of com.alibaba.graphscope.groot.operation.OperationType 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

OperationType (com.alibaba.graphscope.groot.operation.OperationType)2 ArrayList (java.util.ArrayList)2 CompletionCallback (com.alibaba.graphscope.groot.CompletionCallback)1 SnapshotCache (com.alibaba.graphscope.groot.SnapshotCache)1 IngestorWriteClient (com.alibaba.graphscope.groot.frontend.IngestorWriteClient)1 MetaService (com.alibaba.graphscope.groot.meta.MetaService)1 MetricsAgent (com.alibaba.graphscope.groot.metrics.MetricsAgent)1 MetricsCollector (com.alibaba.graphscope.groot.metrics.MetricsCollector)1 EdgeId (com.alibaba.graphscope.groot.operation.EdgeId)1 Operation (com.alibaba.graphscope.groot.operation.Operation)1 OperationBatch (com.alibaba.graphscope.groot.operation.OperationBatch)1 VertexId (com.alibaba.graphscope.groot.operation.VertexId)1 com.alibaba.graphscope.groot.operation.dml (com.alibaba.graphscope.groot.operation.dml)1 RoleClients (com.alibaba.graphscope.groot.rpc.RoleClients)1 DdlRequestBlob (com.alibaba.graphscope.groot.schema.request.DdlRequestBlob)1 WriteSessionUtil (com.alibaba.maxgraph.common.util.WriteSessionUtil)1 MaxGraphException (com.alibaba.maxgraph.compiler.api.exception.MaxGraphException)1 PropertyDefNotFoundException (com.alibaba.maxgraph.compiler.api.exception.PropertyDefNotFoundException)1 DataType (com.alibaba.maxgraph.compiler.api.schema.DataType)1 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)1