Search in sources :

Example 1 with MetricsCollector

use of com.alibaba.graphscope.groot.metrics.MetricsCollector in project GraphScope by alibaba.

the class StoreServiceTest method testStoreService.

@Test
void testStoreService() throws IOException, InterruptedException, ExecutionException {
    Configs configs = Configs.newBuilder().put(CommonConfig.NODE_IDX.getKey(), "0").build();
    MetaService mockMetaService = mock(MetaService.class);
    when(mockMetaService.getPartitionsByStoreId(0)).thenReturn(Arrays.asList(0));
    StoreService spyStoreService = spy(new StoreService(configs, mockMetaService, new MetricsCollector(configs)));
    GraphPartition mockGraphPartition = mock(GraphPartition.class);
    when(mockGraphPartition.recover()).thenReturn(10L);
    doReturn(mockGraphPartition).when(spyStoreService).makeGraphPartition(any(), eq(0));
    spyStoreService.start();
    assertEquals(spyStoreService.recover(), 10L);
    StoreDataBatch storeDataBatch = StoreDataBatch.newBuilder().snapshotId(20L).addOperation(0, OperationBlob.MARKER_OPERATION_BLOB).build();
    spyStoreService.batchWrite(storeDataBatch);
    verify(mockGraphPartition, timeout(100L)).writeBatch(20L, OperationBatch.newBuilder().addOperationBlob(OperationBlob.MARKER_OPERATION_BLOB).build());
    spyStoreService.stop();
    verify(mockGraphPartition).close();
}
Also used : MetricsCollector(com.alibaba.graphscope.groot.metrics.MetricsCollector) MetaService(com.alibaba.graphscope.groot.meta.MetaService) GraphPartition(com.alibaba.graphscope.groot.store.GraphPartition) Configs(com.alibaba.maxgraph.common.config.Configs) StoreDataBatch(com.alibaba.graphscope.groot.operation.StoreDataBatch) StoreService(com.alibaba.graphscope.groot.store.StoreService) Test(org.junit.jupiter.api.Test)

Example 2 with MetricsCollector

use of com.alibaba.graphscope.groot.metrics.MetricsCollector in project GraphScope by alibaba.

the class WriterAgentTest method testWriterAgent.

@Test
void testWriterAgent() throws InterruptedException, ExecutionException {
    Configs configs = Configs.newBuilder().put(CommonConfig.NODE_IDX.getKey(), "0").put(StoreConfig.STORE_COMMIT_INTERVAL_MS.getKey(), "10").build();
    StoreService mockStoreService = mock(StoreService.class);
    MetaService mockMetaService = mock(MetaService.class);
    when(mockMetaService.getQueueCount()).thenReturn(1);
    SnapshotCommitter mockSnapshotCommitter = mock(SnapshotCommitter.class);
    WriterAgent writerAgent = new WriterAgent(configs, mockStoreService, mockMetaService, mockSnapshotCommitter, new MetricsCollector(configs));
    writerAgent.init(0L);
    writerAgent.start();
    StoreDataBatch storeDataBatch = StoreDataBatch.newBuilder().snapshotId(2L).queueId(0).offset(10L).build();
    writerAgent.writeStore(storeDataBatch);
    verify(mockStoreService, timeout(5000L).times(1)).batchWrite(storeDataBatch);
    verify(mockSnapshotCommitter, timeout(5000L).times(1)).commitSnapshotId(0, 1L, 0L, Collections.singletonList(10L));
    writerAgent.stop();
}
Also used : MetricsCollector(com.alibaba.graphscope.groot.metrics.MetricsCollector) SnapshotCommitter(com.alibaba.graphscope.groot.store.SnapshotCommitter) MetaService(com.alibaba.graphscope.groot.meta.MetaService) Configs(com.alibaba.maxgraph.common.config.Configs) StoreDataBatch(com.alibaba.graphscope.groot.operation.StoreDataBatch) StoreService(com.alibaba.graphscope.groot.store.StoreService) WriterAgent(com.alibaba.graphscope.groot.store.WriterAgent) Test(org.junit.jupiter.api.Test)

Example 3 with MetricsCollector

use of com.alibaba.graphscope.groot.metrics.MetricsCollector in project GraphScope by alibaba.

the class BatchSenderTest method testSend.

@Test
void testSend() throws InterruptedException {
    Configs configs = Configs.newBuilder().put(CommonConfig.STORE_NODE_COUNT.getKey(), "1").build();
    MetaService mockMetaService = mock(MetaService.class);
    when(mockMetaService.getPartitionCount()).thenReturn(2);
    when(mockMetaService.getStoreIdByPartition(anyInt())).thenReturn(0);
    StoreWriter mockStoreWriter = mock(StoreWriter.class);
    String requestId = "test_batch_sender";
    int queueId = 0;
    long snapshotId = 10L;
    long offset = 50L;
    LabelId labelId = new LabelId(0);
    OperationBlob writeVertexBlob1 = new OverwriteVertexOperation(new VertexId(0L), labelId, Collections.EMPTY_MAP).toBlob();
    OperationBlob writeVertexBlob2 = new OverwriteVertexOperation(new VertexId(1L), labelId, Collections.EMPTY_MAP).toBlob();
    OperationBatch batch = OperationBatch.newBuilder().addOperationBlob(writeVertexBlob1).addOperationBlob(writeVertexBlob2).addOperationBlob(OperationBlob.MARKER_OPERATION_BLOB).build();
    CountDownLatch latch = new CountDownLatch(1);
    doAnswer(invocationOnMock -> {
        StoreDataBatch storeBatch = invocationOnMock.getArgument(1);
        CompletionCallback callback = invocationOnMock.getArgument(2);
        assertAll(() -> assertEquals(storeBatch.getRequestId(), requestId), () -> assertEquals(storeBatch.getQueueId(), queueId), () -> assertEquals(storeBatch.getSnapshotId(), snapshotId), () -> assertEquals(storeBatch.getOffset(), offset), () -> assertEquals(storeBatch.getDataBatch().size(), 2));
        List<Map<Integer, OperationBatch>> dataBatch = storeBatch.getDataBatch();
        Map<Integer, OperationBatch> partitionToBatch = dataBatch.get(0);
        assertAll(() -> assertEquals(partitionToBatch.get(0).getOperationBlob(0), writeVertexBlob1), () -> assertEquals(partitionToBatch.get(1).getOperationBlob(0), writeVertexBlob2));
        assertEquals(dataBatch.get(1).get(-1).getOperationBlob(0), OperationBlob.MARKER_OPERATION_BLOB);
        callback.onCompleted(0);
        latch.countDown();
        return null;
    }).when(mockStoreWriter).write(anyInt(), any(), any());
    BatchSender batchSender = new BatchSender(configs, mockMetaService, mockStoreWriter, new MetricsCollector(configs));
    batchSender.start();
    batchSender.asyncSendWithRetry(requestId, queueId, snapshotId, offset, batch);
    assertTrue(latch.await(5L, TimeUnit.SECONDS));
    batchSender.stop();
}
Also used : MetricsCollector(com.alibaba.graphscope.groot.metrics.MetricsCollector) BatchSender(com.alibaba.graphscope.groot.ingestor.BatchSender) MetaService(com.alibaba.graphscope.groot.meta.MetaService) StoreDataBatch(com.alibaba.graphscope.groot.operation.StoreDataBatch) VertexId(com.alibaba.graphscope.groot.operation.VertexId) CountDownLatch(java.util.concurrent.CountDownLatch) OperationBatch(com.alibaba.graphscope.groot.operation.OperationBatch) CompletionCallback(com.alibaba.graphscope.groot.CompletionCallback) StoreWriter(com.alibaba.graphscope.groot.ingestor.StoreWriter) OperationBlob(com.alibaba.graphscope.groot.operation.OperationBlob) OverwriteVertexOperation(com.alibaba.graphscope.groot.operation.dml.OverwriteVertexOperation) Configs(com.alibaba.maxgraph.common.config.Configs) LabelId(com.alibaba.maxgraph.sdkcommon.schema.LabelId) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 4 with MetricsCollector

use of com.alibaba.graphscope.groot.metrics.MetricsCollector in project GraphScope by alibaba.

the class IngestProcessorTest method testIngestProcessor.

@Test
void testIngestProcessor() throws IOException {
    long tailOffset = 50L;
    int queueId = 0;
    Configs configs = Configs.newBuilder().build();
    LogService mockLogService = mock(LogService.class);
    LogReader mockLogReader = mock(LogReader.class);
    when(mockLogService.createReader(queueId, tailOffset + 1)).thenReturn(mockLogReader);
    LogWriter mockLogWriter = mock(LogWriter.class);
    when(mockLogService.createWriter(queueId)).thenReturn(mockLogWriter);
    when(mockLogWriter.append(any())).thenReturn(tailOffset + 3);
    OperationBatch emptyBatch = OperationBatch.newBuilder().build();
    long readSnapshotId = 5L;
    ReadLogEntry readLogEntry1 = new ReadLogEntry(tailOffset + 1, readSnapshotId, emptyBatch);
    ReadLogEntry readLogEntry2 = new ReadLogEntry(tailOffset + 2, readSnapshotId, emptyBatch);
    when(mockLogReader.readNext()).thenReturn(readLogEntry1).thenReturn(readLogEntry2).thenReturn(null);
    BatchSender mockBatchSender = mock(BatchSender.class);
    AtomicLong ingestSnapshotId = new AtomicLong(10L);
    IngestProcessor ingestProcessor = new IngestProcessor(configs, mockLogService, mockBatchSender, queueId, ingestSnapshotId, new MetricsCollector(configs));
    ingestProcessor.setTailOffset(tailOffset);
    ingestProcessor.start();
    verify(mockBatchSender, timeout(5000L)).asyncSendWithRetry(eq(""), eq(queueId), eq(readSnapshotId), eq(tailOffset + 1), any());
    verify(mockBatchSender, timeout(5000L)).asyncSendWithRetry(eq(""), eq(queueId), eq(readSnapshotId), eq(tailOffset + 2), any());
    verify(mockLogReader).close();
    String requestId = "test_ingest_processor";
    IngestCallback mockIngestCallback = mock(IngestCallback.class);
    ingestProcessor.ingestBatch(requestId, emptyBatch, mockIngestCallback);
    verify(mockBatchSender, timeout(5000L)).asyncSendWithRetry(requestId, queueId, ingestSnapshotId.get(), tailOffset + 3, emptyBatch);
    verify(mockIngestCallback, timeout(5000L)).onSuccess(ingestSnapshotId.get());
    ingestProcessor.stop();
    verify(mockLogWriter, timeout(5000L)).close();
}
Also used : MetricsCollector(com.alibaba.graphscope.groot.metrics.MetricsCollector) BatchSender(com.alibaba.graphscope.groot.ingestor.BatchSender) ReadLogEntry(com.alibaba.graphscope.groot.wal.ReadLogEntry) IngestProcessor(com.alibaba.graphscope.groot.ingestor.IngestProcessor) OperationBatch(com.alibaba.graphscope.groot.operation.OperationBatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) LogWriter(com.alibaba.graphscope.groot.wal.LogWriter) Configs(com.alibaba.maxgraph.common.config.Configs) LogReader(com.alibaba.graphscope.groot.wal.LogReader) IngestCallback(com.alibaba.graphscope.groot.ingestor.IngestCallback) LogService(com.alibaba.graphscope.groot.wal.LogService) Test(org.junit.jupiter.api.Test)

Example 5 with MetricsCollector

use of com.alibaba.graphscope.groot.metrics.MetricsCollector in project GraphScope by alibaba.

the class IngestServiceTest method testIngestService.

@Test
void testIngestService() {
    Configs configs = Configs.newBuilder().put(CommonConfig.NODE_IDX.getKey(), "0").put(CommonConfig.STORE_NODE_COUNT.getKey(), "1").put(IngestorConfig.INGESTOR_CHECK_PROCESSOR_INTERVAL_MS.getKey(), "100").build();
    MockDiscovery mockDiscovery = new MockDiscovery();
    MetaService mockMetaService = mock(MetaService.class);
    when(mockMetaService.getQueueIdsForIngestor(0)).thenReturn(Arrays.asList(0));
    LogService mockLogService = mock(LogService.class);
    IngestProgressFetcher mockIngestProgressFetcher = mock(IngestProgressFetcher.class);
    when(mockIngestProgressFetcher.getTailOffsets(Arrays.asList(0))).thenReturn(Arrays.asList(50L));
    StoreWriter mockStoreWriter = mock(StoreWriter.class);
    IngestService spyIngestService = spy(new IngestService(configs, mockDiscovery, mockMetaService, mockLogService, mockIngestProgressFetcher, mockStoreWriter, new MetricsCollector(configs)));
    IngestProcessor mockIngestProcessor = mock(IngestProcessor.class);
    doReturn(mockIngestProcessor).when(spyIngestService).makeIngestProcessor(any(), any(), any(), eq(0), any(), any());
    spyIngestService.start();
    verify(mockIngestProcessor, never()).start();
    mockDiscovery.addNode(RoleType.STORE, Collections.singletonMap(0, null));
    verify(mockIngestProcessor, timeout(5000L)).setTailOffset(50L);
    verify(mockIngestProcessor, timeout(5000L)).start();
    spyIngestService.advanceIngestSnapshotId(5L, null);
    verify(mockIngestProcessor).ingestBatch(eq("marker"), eq(IngestService.MARKER_BATCH), any());
    mockDiscovery.removeNode(RoleType.STORE, Collections.singletonMap(0, null));
    verify(mockIngestProcessor, timeout(5000L).times(2)).stop();
    spyIngestService.stop();
}
Also used : MetricsCollector(com.alibaba.graphscope.groot.metrics.MetricsCollector) IngestService(com.alibaba.graphscope.groot.ingestor.IngestService) MetaService(com.alibaba.graphscope.groot.meta.MetaService) StoreWriter(com.alibaba.graphscope.groot.ingestor.StoreWriter) Configs(com.alibaba.maxgraph.common.config.Configs) IngestProgressFetcher(com.alibaba.graphscope.groot.ingestor.IngestProgressFetcher) LogService(com.alibaba.graphscope.groot.wal.LogService) IngestProcessor(com.alibaba.graphscope.groot.ingestor.IngestProcessor) Test(org.junit.jupiter.api.Test)

Aggregations

MetricsCollector (com.alibaba.graphscope.groot.metrics.MetricsCollector)5 Configs (com.alibaba.maxgraph.common.config.Configs)5 Test (org.junit.jupiter.api.Test)5 MetaService (com.alibaba.graphscope.groot.meta.MetaService)4 StoreDataBatch (com.alibaba.graphscope.groot.operation.StoreDataBatch)3 BatchSender (com.alibaba.graphscope.groot.ingestor.BatchSender)2 IngestProcessor (com.alibaba.graphscope.groot.ingestor.IngestProcessor)2 StoreWriter (com.alibaba.graphscope.groot.ingestor.StoreWriter)2 OperationBatch (com.alibaba.graphscope.groot.operation.OperationBatch)2 StoreService (com.alibaba.graphscope.groot.store.StoreService)2 LogService (com.alibaba.graphscope.groot.wal.LogService)2 CompletionCallback (com.alibaba.graphscope.groot.CompletionCallback)1 IngestCallback (com.alibaba.graphscope.groot.ingestor.IngestCallback)1 IngestProgressFetcher (com.alibaba.graphscope.groot.ingestor.IngestProgressFetcher)1 IngestService (com.alibaba.graphscope.groot.ingestor.IngestService)1 OperationBlob (com.alibaba.graphscope.groot.operation.OperationBlob)1 VertexId (com.alibaba.graphscope.groot.operation.VertexId)1 OverwriteVertexOperation (com.alibaba.graphscope.groot.operation.dml.OverwriteVertexOperation)1 GraphPartition (com.alibaba.graphscope.groot.store.GraphPartition)1 SnapshotCommitter (com.alibaba.graphscope.groot.store.SnapshotCommitter)1