Search in sources :

Example 1 with MetaService

use of com.alibaba.graphscope.groot.meta.MetaService in project GraphScope by alibaba.

the class SchemaManagerTest method testSchemaManager.

@Test
void testSchemaManager() throws IOException, InterruptedException {
    SnapshotManager mockSnapshotManager = mock(SnapshotManager.class);
    doAnswer(invocationOnMock -> {
        SnapshotListener listener = invocationOnMock.getArgument(1);
        listener.onSnapshotAvailable();
        return null;
    }).when(mockSnapshotManager).addSnapshotListener(anyLong(), any());
    when(mockSnapshotManager.increaseWriteSnapshotId()).thenReturn(1L);
    when(mockSnapshotManager.getCurrentWriteSnapshotId()).thenReturn(1L);
    DdlExecutors ddlExecutors = new DdlExecutors();
    DdlWriter mockDdlWriter = mock(DdlWriter.class);
    when(mockDdlWriter.writeOperations(anyString(), any())).thenReturn(new BatchId(1L));
    MetaService mockMetaService = mock(MetaService.class);
    GraphDefFetcher mockGraphDefFetcher = mock(GraphDefFetcher.class);
    GraphDef initialGraphDef = GraphDef.newBuilder().build();
    when(mockGraphDefFetcher.fetchGraphDef()).thenReturn(initialGraphDef);
    SchemaManager schemaManager = new SchemaManager(mockSnapshotManager, ddlExecutors, mockDdlWriter, mockMetaService, mockGraphDefFetcher);
    schemaManager.start();
    assertEquals(initialGraphDef, schemaManager.getGraphDef());
    PropertyValue defaultValue = new PropertyValue(DataType.INT, ByteBuffer.allocate(Integer.BYTES).putInt(1).array());
    PropertyDef propertyDef = new PropertyDef(1, 1, "p1", DataType.INT, defaultValue, true, "property_1");
    TypeDef typeDef = TypeDef.newBuilder().setLabel("vertex1").addPropertyDef(propertyDef).setTypeEnum(TypeEnum.VERTEX).build();
    DdlRequestBatch ddlRequestBatch = DdlRequestBatch.newBuilder().addDdlRequest(new CreateVertexTypeRequest(typeDef)).build();
    CountDownLatch latch = new CountDownLatch(1);
    schemaManager.submitBatchDdl("requestId", "sessionId", ddlRequestBatch, new CompletionCallback<Long>() {

        @Override
        public void onCompleted(Long res) {
            latch.countDown();
        }

        @Override
        public void onError(Throwable t) {
        }
    });
    assertTrue(latch.await(5L, TimeUnit.SECONDS));
    schemaManager.stop();
}
Also used : MetaService(com.alibaba.graphscope.groot.meta.MetaService) PropertyDef(com.alibaba.maxgraph.sdkcommon.schema.PropertyDef) BatchId(com.alibaba.graphscope.groot.operation.BatchId) PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue) SchemaManager(com.alibaba.graphscope.groot.coordinator.SchemaManager) CountDownLatch(java.util.concurrent.CountDownLatch) GraphDefFetcher(com.alibaba.graphscope.groot.coordinator.GraphDefFetcher) GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef) SnapshotListener(com.alibaba.graphscope.groot.SnapshotListener) DdlWriter(com.alibaba.graphscope.groot.coordinator.DdlWriter) TypeDef(com.alibaba.maxgraph.sdkcommon.schema.TypeDef) DdlExecutors(com.alibaba.graphscope.groot.schema.ddl.DdlExecutors) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) CreateVertexTypeRequest(com.alibaba.graphscope.groot.schema.request.CreateVertexTypeRequest) DdlRequestBatch(com.alibaba.graphscope.groot.schema.request.DdlRequestBatch) SnapshotManager(com.alibaba.graphscope.groot.coordinator.SnapshotManager) Test(org.junit.jupiter.api.Test)

Example 2 with MetaService

use of com.alibaba.graphscope.groot.meta.MetaService in project GraphScope by alibaba.

the class DefaultMetaServiceTest method testMeta.

@Test
void testMeta() {
    Configs configs = Configs.newBuilder().put("partition.count", "10").put("ingestor.queue.count", "3").put("store.node.count", "4").build();
    /**
     * Partitions assignment
     *
     * <p>| storeID | Partitions | | 0 | 0, 1, 2 | | 1 | 3, 4, 5 | | 2 | 6, 7 | | 3 | 8, 9 |
     */
    MetaService metaService = new DefaultMetaService(configs);
    metaService.start();
    Assertions.assertAll(() -> assertEquals(metaService.getPartitionCount(), 10), () -> assertEquals(metaService.getStoreIdByPartition(0), 0), () -> assertEquals(metaService.getStoreIdByPartition(5), 1), () -> assertEquals(metaService.getStoreIdByPartition(6), 2), () -> assertEquals(metaService.getStoreIdByPartition(8), 3), () -> assertEquals(metaService.getPartitionsByStoreId(2), Arrays.asList(6, 7)), () -> assertEquals(metaService.getQueueCount(), 3), () -> assertEquals(metaService.getQueueIdsForIngestor(2), Arrays.asList(2)), () -> assertEquals(metaService.getIngestorIdForQueue(1), 1));
    metaService.stop();
}
Also used : DefaultMetaService(com.alibaba.graphscope.groot.meta.DefaultMetaService) DefaultMetaService(com.alibaba.graphscope.groot.meta.DefaultMetaService) MetaService(com.alibaba.graphscope.groot.meta.MetaService) Configs(com.alibaba.maxgraph.common.config.Configs) Test(org.junit.jupiter.api.Test)

Example 3 with MetaService

use of com.alibaba.graphscope.groot.meta.MetaService in project GraphScope by alibaba.

the class SnapshotSortQueueTest method testQueue.

@Test
void testQueue() throws InterruptedException {
    Configs configs = Configs.newBuilder().build();
    MetaService mockMetaService = mock(MetaService.class);
    when(mockMetaService.getQueueCount()).thenReturn(2);
    SnapshotSortQueue snapshotSortQueue = new SnapshotSortQueue(configs, mockMetaService);
    /**
     * Q1: 4, 5, 7, 7 Q0: 4, 5, 6, 7
     *
     * <p>(Q1, 4) (Q0, 4) (Q1, 5) (Q0, 5) (Q0, 6) (Q1, 7) (Q1, 7) (Q0, 7)
     */
    snapshotSortQueue.offerQueue(1, StoreDataBatch.newBuilder().snapshotId(4L).queueId(1).build());
    snapshotSortQueue.offerQueue(1, StoreDataBatch.newBuilder().snapshotId(5L).queueId(1).build());
    snapshotSortQueue.offerQueue(1, StoreDataBatch.newBuilder().snapshotId(7L).queueId(1).build());
    snapshotSortQueue.offerQueue(1, StoreDataBatch.newBuilder().snapshotId(7L).queueId(1).build());
    // For end snapshot 7
    snapshotSortQueue.offerQueue(1, StoreDataBatch.newBuilder().snapshotId(100L).queueId(1).build());
    snapshotSortQueue.offerQueue(0, StoreDataBatch.newBuilder().snapshotId(4L).queueId(0).build());
    snapshotSortQueue.offerQueue(0, StoreDataBatch.newBuilder().snapshotId(5L).queueId(0).build());
    snapshotSortQueue.offerQueue(0, StoreDataBatch.newBuilder().snapshotId(6L).queueId(0).build());
    snapshotSortQueue.offerQueue(0, StoreDataBatch.newBuilder().snapshotId(7L).queueId(0).build());
    StoreDataBatch entry = snapshotSortQueue.poll();
    assertEquals(entry.getQueueId(), 1);
    assertEquals(entry.getSnapshotId(), 4L);
    entry = snapshotSortQueue.poll();
    assertEquals(entry.getQueueId(), 0);
    assertEquals(entry.getSnapshotId(), 4L);
    entry = snapshotSortQueue.poll();
    assertEquals(entry.getQueueId(), 1);
    assertEquals(entry.getSnapshotId(), 5L);
    entry = snapshotSortQueue.poll();
    assertEquals(entry.getQueueId(), 0);
    assertEquals(entry.getSnapshotId(), 5L);
    entry = snapshotSortQueue.poll();
    assertEquals(entry.getQueueId(), 0);
    assertEquals(entry.getSnapshotId(), 6L);
    entry = snapshotSortQueue.poll();
    assertEquals(entry.getQueueId(), 1);
    assertEquals(entry.getSnapshotId(), 7L);
    entry = snapshotSortQueue.poll();
    assertEquals(entry.getQueueId(), 1);
    assertEquals(entry.getSnapshotId(), 7L);
    entry = snapshotSortQueue.poll();
    assertEquals(entry.getQueueId(), 0);
    assertEquals(entry.getSnapshotId(), 7L);
}
Also used : MetaService(com.alibaba.graphscope.groot.meta.MetaService) SnapshotSortQueue(com.alibaba.graphscope.groot.store.SnapshotSortQueue) Configs(com.alibaba.maxgraph.common.config.Configs) StoreDataBatch(com.alibaba.graphscope.groot.operation.StoreDataBatch) Test(org.junit.jupiter.api.Test)

Example 4 with MetaService

use of com.alibaba.graphscope.groot.meta.MetaService 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 5 with MetaService

use of com.alibaba.graphscope.groot.meta.MetaService 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)

Aggregations

MetaService (com.alibaba.graphscope.groot.meta.MetaService)8 Test (org.junit.jupiter.api.Test)8 Configs (com.alibaba.maxgraph.common.config.Configs)7 MetricsCollector (com.alibaba.graphscope.groot.metrics.MetricsCollector)4 StoreDataBatch (com.alibaba.graphscope.groot.operation.StoreDataBatch)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 StoreWriter (com.alibaba.graphscope.groot.ingestor.StoreWriter)2 StoreService (com.alibaba.graphscope.groot.store.StoreService)2 GraphDef (com.alibaba.maxgraph.sdkcommon.schema.GraphDef)2 CompletionCallback (com.alibaba.graphscope.groot.CompletionCallback)1 SnapshotCache (com.alibaba.graphscope.groot.SnapshotCache)1 SnapshotListener (com.alibaba.graphscope.groot.SnapshotListener)1 SnapshotWithSchema (com.alibaba.graphscope.groot.SnapshotWithSchema)1 BackupManager (com.alibaba.graphscope.groot.coordinator.BackupManager)1 DdlWriter (com.alibaba.graphscope.groot.coordinator.DdlWriter)1 GraphDefFetcher (com.alibaba.graphscope.groot.coordinator.GraphDefFetcher)1 SchemaManager (com.alibaba.graphscope.groot.coordinator.SchemaManager)1 SnapshotManager (com.alibaba.graphscope.groot.coordinator.SnapshotManager)1 BatchSender (com.alibaba.graphscope.groot.ingestor.BatchSender)1 IngestProcessor (com.alibaba.graphscope.groot.ingestor.IngestProcessor)1