Search in sources :

Example 1 with StoreService

use of com.alibaba.graphscope.groot.store.StoreService in project GraphScope by alibaba.

the class FfiTest method testFfi.

@Test
public void testFfi() throws Exception {
    GraphProvider provider = new MaxTestGraphProvider();
    LoadGraphWith.GraphData modern = LoadGraphWith.GraphData.MODERN;
    Map<String, Object> conf = new HashMap<>();
    conf.put(CommonConfig.STORE_NODE_COUNT.getKey(), "1");
    conf.put(CommonConfig.PARTITION_COUNT.getKey(), "1");
    Configuration graphConf = provider.newGraphConfiguration("ffi-test", FfiTest.class, "testFfi", conf, modern);
    provider.clear(graphConf);
    Graph graph = provider.openTestGraph(graphConf);
    LoadGraphWith loadGraphWith = new LoadGraphWith() {

        @Override
        public Class<? extends Annotation> annotationType() {
            return null;
        }

        @Override
        public GraphData value() {
            return modern;
        }
    };
    provider.loadGraphData(graph, loadGraphWith, FfiTest.class, "testFfi");
    MaxNode maxNode = ((MaxTestGraph) graph).getMaxNode();
    List<NodeBase> storeNodes = maxNode.getStores();
    assertEquals(storeNodes.size(), 1);
    Store store = (Store) storeNodes.get(0);
    StoreService storeService = store.getStoreService();
    JnaGraphStore jnaGraphStore = (JnaGraphStore) storeService.getIdToPartition().get(0);
    Pointer wrapperPartitionGraph = GraphLibrary.INSTANCE.createWrapperPartitionGraph(jnaGraphStore.getPointer());
    GnnLibrary.INSTANCE.setPartitionGraph(wrapperPartitionGraph);
    GnnLibrary.TestResult testResult = new GnnLibrary.TestResult(GnnLibrary.INSTANCE.runLocalTests());
    logger.info(testResult.getInfo());
    assertTrue(testResult.getFlag());
    provider.clear(graph, graphConf);
    maxNode.close();
}
Also used : MaxNode(com.alibaba.maxgraph.servers.MaxNode) Configuration(org.apache.commons.configuration2.Configuration) HashMap(java.util.HashMap) Store(com.alibaba.maxgraph.servers.Store) JnaGraphStore(com.alibaba.graphscope.groot.store.jna.JnaGraphStore) StoreService(com.alibaba.graphscope.groot.store.StoreService) Pointer(com.sun.jna.Pointer) LoadGraphWith(org.apache.tinkerpop.gremlin.LoadGraphWith) JnaGraphStore(com.alibaba.graphscope.groot.store.jna.JnaGraphStore) NodeBase(com.alibaba.maxgraph.servers.NodeBase) Graph(org.apache.tinkerpop.gremlin.structure.Graph) MaxTestGraph(com.alibaba.maxgraph.tests.gremlin.MaxTestGraph) MaxTestGraph(com.alibaba.maxgraph.tests.gremlin.MaxTestGraph) MaxTestGraphProvider(com.alibaba.maxgraph.tests.gremlin.MaxTestGraphProvider) MaxTestGraphProvider(com.alibaba.maxgraph.tests.gremlin.MaxTestGraphProvider) GraphProvider(org.apache.tinkerpop.gremlin.GraphProvider) Test(org.junit.Test)

Example 2 with StoreService

use of com.alibaba.graphscope.groot.store.StoreService 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 3 with StoreService

use of com.alibaba.graphscope.groot.store.StoreService 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 4 with StoreService

use of com.alibaba.graphscope.groot.store.StoreService in project GraphScope by alibaba.

the class BackupAgentTest method testBackupAgent.

@Test
void testBackupAgent() throws IOException {
    Configs configs = Configs.newBuilder().put(CommonConfig.NODE_IDX.getKey(), "0").put(BackupConfig.BACKUP_ENABLE.getKey(), "true").put(BackupConfig.STORE_BACKUP_THREAD_COUNT.getKey(), "2").build();
    StoreService mockStoreService = mock(StoreService.class);
    JnaGraphStore mockJnaStore0 = mock(JnaGraphStore.class);
    JnaGraphStore mockJnaStore1 = mock(JnaGraphStore.class);
    JnaGraphBackupEngine mockJnaBackupEngine0 = mock(JnaGraphBackupEngine.class);
    JnaGraphBackupEngine mockJnaBackupEngine1 = mock(JnaGraphBackupEngine.class);
    Map<Integer, GraphPartition> idToPartition = new HashMap<>();
    idToPartition.put(0, mockJnaStore0);
    idToPartition.put(1, mockJnaStore1);
    when(mockStoreService.getIdToPartition()).thenReturn(idToPartition);
    when(mockJnaStore0.openBackupEngine()).thenReturn(mockJnaBackupEngine0);
    when(mockJnaStore1.openBackupEngine()).thenReturn(mockJnaBackupEngine1);
    BackupAgent backupAgent = new BackupAgent(configs, mockStoreService);
    backupAgent.start();
    StoreBackupId storeBackupId = new StoreBackupId(5);
    storeBackupId.addPartitionBackupId(0, 7);
    storeBackupId.addPartitionBackupId(1, 6);
    Map<Integer, List<Integer>> readyPartitionBackupIds = new HashMap<>();
    readyPartitionBackupIds.put(0, Arrays.asList(2, 4, 6));
    readyPartitionBackupIds.put(1, Arrays.asList(3, 5, 7));
    when(mockJnaBackupEngine0.createNewPartitionBackup()).thenReturn(7);
    when(mockJnaBackupEngine1.createNewPartitionBackup()).thenReturn(6);
    CompletionCallback<StoreBackupId> createCallback = mock(CompletionCallback.class);
    backupAgent.createNewStoreBackup(5, createCallback);
    verify(createCallback, timeout(5000L)).onCompleted(storeBackupId);
    CompletionCallback<Void> verifyCallback = mock(CompletionCallback.class);
    backupAgent.verifyStoreBackup(storeBackupId, verifyCallback);
    verify(mockJnaBackupEngine0, timeout(5000L)).verifyPartitionBackup(7);
    verify(mockJnaBackupEngine1, timeout(5000L)).verifyPartitionBackup(6);
    verify(verifyCallback, timeout(5000L)).onCompleted(null);
    CompletionCallback<Void> clearCallback = mock(CompletionCallback.class);
    backupAgent.clearUnavailableStoreBackups(readyPartitionBackupIds, clearCallback);
    verify(mockJnaBackupEngine0, timeout(5000L)).partitionBackupGc(Arrays.asList(2, 4, 6));
    verify(mockJnaBackupEngine1, timeout(5000L)).partitionBackupGc(Arrays.asList(3, 5, 7));
    verify(clearCallback, timeout(5000L)).onCompleted(null);
    CompletionCallback<Void> restoreCallback = mock(CompletionCallback.class);
    backupAgent.restoreFromStoreBackup(storeBackupId, "restore_root", restoreCallback);
    verify(mockJnaBackupEngine0, timeout(5000L)).restoreFromPartitionBackup(7, Paths.get("restore_root", "0").toString());
    verify(mockJnaBackupEngine1, timeout(5000L)).restoreFromPartitionBackup(6, Paths.get("restore_root", "1").toString());
    verify(restoreCallback, timeout(5000L)).onCompleted(null);
    backupAgent.stop();
}
Also used : JnaGraphBackupEngine(com.alibaba.graphscope.groot.store.jna.JnaGraphBackupEngine) HashMap(java.util.HashMap) GraphPartition(com.alibaba.graphscope.groot.store.GraphPartition) StoreService(com.alibaba.graphscope.groot.store.StoreService) JnaGraphStore(com.alibaba.graphscope.groot.store.jna.JnaGraphStore) StoreBackupId(com.alibaba.graphscope.groot.store.StoreBackupId) Configs(com.alibaba.maxgraph.common.config.Configs) BackupAgent(com.alibaba.graphscope.groot.store.BackupAgent) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

StoreService (com.alibaba.graphscope.groot.store.StoreService)4 Configs (com.alibaba.maxgraph.common.config.Configs)3 Test (org.junit.jupiter.api.Test)3 MetaService (com.alibaba.graphscope.groot.meta.MetaService)2 MetricsCollector (com.alibaba.graphscope.groot.metrics.MetricsCollector)2 StoreDataBatch (com.alibaba.graphscope.groot.operation.StoreDataBatch)2 GraphPartition (com.alibaba.graphscope.groot.store.GraphPartition)2 JnaGraphStore (com.alibaba.graphscope.groot.store.jna.JnaGraphStore)2 HashMap (java.util.HashMap)2 BackupAgent (com.alibaba.graphscope.groot.store.BackupAgent)1 SnapshotCommitter (com.alibaba.graphscope.groot.store.SnapshotCommitter)1 StoreBackupId (com.alibaba.graphscope.groot.store.StoreBackupId)1 WriterAgent (com.alibaba.graphscope.groot.store.WriterAgent)1 JnaGraphBackupEngine (com.alibaba.graphscope.groot.store.jna.JnaGraphBackupEngine)1 MaxNode (com.alibaba.maxgraph.servers.MaxNode)1 NodeBase (com.alibaba.maxgraph.servers.NodeBase)1 Store (com.alibaba.maxgraph.servers.Store)1 MaxTestGraph (com.alibaba.maxgraph.tests.gremlin.MaxTestGraph)1 MaxTestGraphProvider (com.alibaba.maxgraph.tests.gremlin.MaxTestGraphProvider)1 Pointer (com.sun.jna.Pointer)1