Search in sources :

Example 1 with CompletionCallback

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

use of com.alibaba.graphscope.groot.CompletionCallback in project GraphScope by alibaba.

the class IngestorRpcTest method testStoreWriteClient.

@Test
void testStoreWriteClient() {
    StoreWriteGrpc.StoreWriteStub stub = mock(StoreWriteGrpc.StoreWriteStub.class);
    StoreWriteClient client = new StoreWriteClient(stub);
    CompletionCallback callback = mock(CompletionCallback.class);
    doAnswer(invocation -> {
        StreamObserver<WriteStoreResponse> observer = invocation.getArgument(1);
        observer.onNext(WriteStoreResponse.newBuilder().setSuccess(true).build());
        return null;
    }).when(stub).writeStore(any(), any());
    client.writeStore(Arrays.asList(StoreDataBatch.newBuilder().requestId("test_req").build()), callback);
    verify(callback).onCompleted(10);
}
Also used : WriteStoreResponse(com.alibaba.maxgraph.proto.groot.WriteStoreResponse) StoreWriteGrpc(com.alibaba.maxgraph.proto.groot.StoreWriteGrpc) CompletionCallback(com.alibaba.graphscope.groot.CompletionCallback) StoreWriteClient(com.alibaba.graphscope.groot.ingestor.StoreWriteClient) Test(org.junit.jupiter.api.Test)

Example 3 with CompletionCallback

use of com.alibaba.graphscope.groot.CompletionCallback in project GraphScope by alibaba.

the class CoordinatorRpcTest method testStoreBackupClient.

@Test
void testStoreBackupClient() {
    StoreBackupGrpc.StoreBackupStub stub = mock(StoreBackupGrpc.StoreBackupStub.class);
    StoreBackupClient client = new StoreBackupClient(stub);
    StoreBackupId storeBackupId = new StoreBackupId(3);
    storeBackupId.addPartitionBackupId(0, 3);
    storeBackupId.addPartitionBackupId(1, 3);
    Map<Integer, List<Integer>> readyPartitionBackupIds = new HashMap<>();
    readyPartitionBackupIds.put(6, new ArrayList<>());
    String storeRestoreRootPath = "store_restore_path";
    doAnswer(invocation -> {
        CreateStoreBackupRequest request = invocation.getArgument(0);
        assertEquals(request.getGlobalBackupId(), 3);
        StreamObserver<CreateStoreBackupResponse> observer = invocation.getArgument(1);
        observer.onNext(CreateStoreBackupResponse.newBuilder().setStoreBackupId(storeBackupId.toProto()).build());
        observer.onError(null);
        return null;
    }).when(stub).createStoreBackup(any(), any());
    doAnswer(invocation -> {
        ClearUnavailableStoreBackupsRequest request = invocation.getArgument(0);
        assertEquals(request.getPartitionToReadyBackupIdsCount(), 1);
        assertTrue(request.getPartitionToReadyBackupIdsMap().containsKey(6));
        StreamObserver<ClearUnavailableStoreBackupsResponse> observer = invocation.getArgument(1);
        observer.onNext(ClearUnavailableStoreBackupsResponse.newBuilder().build());
        observer.onError(null);
        return null;
    }).when(stub).clearUnavailableStoreBackups(any(), any());
    doAnswer(invocation -> {
        RestoreFromStoreBackupRequest request = invocation.getArgument(0);
        assertEquals(StoreBackupId.parseProto(request.getStoreBackupId()), storeBackupId);
        assertEquals(request.getRestoreRootPath(), storeRestoreRootPath);
        StreamObserver<RestoreFromStoreBackupResponse> observer = invocation.getArgument(1);
        observer.onNext(RestoreFromStoreBackupResponse.newBuilder().build());
        observer.onError(null);
        return null;
    }).when(stub).restoreFromStoreBackup(any(), any());
    doAnswer(invocation -> {
        VerifyStoreBackupRequest request = invocation.getArgument(0);
        assertEquals(StoreBackupId.parseProto(request.getStoreBackupId()), storeBackupId);
        StreamObserver<VerifyStoreBackupResponse> observer = invocation.getArgument(1);
        observer.onNext(VerifyStoreBackupResponse.newBuilder().build());
        observer.onError(null);
        return null;
    }).when(stub).verifyStoreBackup(any(), any());
    CompletionCallback creationCallback = mock(CompletionCallback.class);
    client.createStoreBackup(3, creationCallback);
    verify(creationCallback).onCompleted(storeBackupId);
    verify(creationCallback).onError(null);
    CompletionCallback voidCallback = mock(CompletionCallback.class);
    client.clearUnavailableBackups(readyPartitionBackupIds, voidCallback);
    client.restoreFromStoreBackup(storeBackupId, storeRestoreRootPath, voidCallback);
    client.verifyStoreBackup(storeBackupId, voidCallback);
    verify(voidCallback, times(3)).onCompleted(null);
    verify(voidCallback, times(3)).onError(null);
}
Also used : StoreBackupId(com.alibaba.graphscope.groot.store.StoreBackupId) CompletionCallback(com.alibaba.graphscope.groot.CompletionCallback) Test(org.junit.jupiter.api.Test)

Example 4 with CompletionCallback

use of com.alibaba.graphscope.groot.CompletionCallback in project GraphScope by alibaba.

the class CoordinatorRpcTest method testIngestorSnapshotClient.

@Test
void testIngestorSnapshotClient() {
    IngestorSnapshotGrpc.IngestorSnapshotStub stub = mock(IngestorSnapshotGrpc.IngestorSnapshotStub.class);
    IngestorSnapshotClient client = new IngestorSnapshotClient(stub);
    CompletionCallback callback = mock(CompletionCallback.class);
    doAnswer(invocation -> {
        AdvanceIngestSnapshotIdRequest req = invocation.getArgument(0);
        assertEquals(req.getSnapshotId(), 10L);
        StreamObserver<AdvanceIngestSnapshotIdResponse> observer = invocation.getArgument(1);
        observer.onNext(AdvanceIngestSnapshotIdResponse.newBuilder().setPreviousSnapshotId(8L).build());
        observer.onError(null);
        return null;
    }).when(stub).advanceIngestSnapshotId(any(), any());
    client.advanceIngestSnapshotId(10L, callback);
    verify(callback).onCompleted(8L);
    verify(callback).onError(null);
}
Also used : CompletionCallback(com.alibaba.graphscope.groot.CompletionCallback) Test(org.junit.jupiter.api.Test)

Example 5 with CompletionCallback

use of com.alibaba.graphscope.groot.CompletionCallback in project GraphScope by alibaba.

the class CoordinatorRpcTest method testFrontendSnapshotClient.

@Test
void testFrontendSnapshotClient() {
    FrontendSnapshotGrpc.FrontendSnapshotStub stub = mock(FrontendSnapshotGrpc.FrontendSnapshotStub.class);
    FrontendSnapshotClient client = new FrontendSnapshotClient(stub);
    GraphDef graphDef = GraphDef.newBuilder().build();
    doAnswer(invocationOnMock -> {
        AdvanceQuerySnapshotRequest req = invocationOnMock.getArgument(0);
        StreamObserver<AdvanceQuerySnapshotResponse> observer = invocationOnMock.getArgument(1);
        assertEquals(req.getGraphDef(), graphDef.toProto());
        assertEquals(req.getSnapshotId(), 10L);
        observer.onNext(AdvanceQuerySnapshotResponse.newBuilder().setPreviousSnapshotId(9L).build());
        return null;
    }).when(stub).advanceQuerySnapshot(any(), any());
    CompletionCallback completionCallback = mock(CompletionCallback.class);
    client.advanceQuerySnapshot(10L, graphDef, completionCallback);
    verify(completionCallback).onCompleted(9L);
}
Also used : CompletionCallback(com.alibaba.graphscope.groot.CompletionCallback) GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef) Test(org.junit.jupiter.api.Test)

Aggregations

CompletionCallback (com.alibaba.graphscope.groot.CompletionCallback)8 Test (org.junit.jupiter.api.Test)5 MetaService (com.alibaba.graphscope.groot.meta.MetaService)3 MetricsCollector (com.alibaba.graphscope.groot.metrics.MetricsCollector)3 OperationBatch (com.alibaba.graphscope.groot.operation.OperationBatch)3 Map (java.util.Map)3 MetricsAgent (com.alibaba.graphscope.groot.metrics.MetricsAgent)2 OperationBlob (com.alibaba.graphscope.groot.operation.OperationBlob)2 StoreDataBatch (com.alibaba.graphscope.groot.operation.StoreDataBatch)2 VertexId (com.alibaba.graphscope.groot.operation.VertexId)2 Configs (com.alibaba.maxgraph.common.config.Configs)2 GraphDef (com.alibaba.maxgraph.sdkcommon.schema.GraphDef)2 LabelId (com.alibaba.maxgraph.sdkcommon.schema.LabelId)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Logger (org.slf4j.Logger)2