Search in sources :

Example 1 with MetaStore

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

the class ZkMetaStoreTest method testMetaStore.

@Test
void testMetaStore() throws Exception {
    try (TestingServer testingServer = new TestingServer(-1)) {
        int zkPort = testingServer.getPort();
        Configs configs = Configs.newBuilder().put(ZkConfig.ZK_CONNECT_STRING.getKey(), "localhost:" + zkPort).put(ZkConfig.ZK_BASE_PATH.getKey(), "test_meta_store").build();
        CuratorFramework curator = CuratorUtils.makeCurator(configs);
        curator.start();
        MetaStore metaStore = new ZkMetaStore(configs, curator);
        String path = "test_path";
        String data = "test_data";
        assertFalse(metaStore.exists(path));
        metaStore.write(path, data.getBytes());
        assertTrue(metaStore.exists(path));
        assertEquals(new String(metaStore.read(path)), data);
        metaStore.delete(path);
        assertFalse(metaStore.exists(path));
        curator.close();
    }
}
Also used : TestingServer(org.apache.curator.test.TestingServer) ZkMetaStore(com.alibaba.graphscope.groot.coordinator.ZkMetaStore) MetaStore(com.alibaba.graphscope.groot.meta.MetaStore) CuratorFramework(org.apache.curator.framework.CuratorFramework) Configs(com.alibaba.maxgraph.common.config.Configs) ZkMetaStore(com.alibaba.graphscope.groot.coordinator.ZkMetaStore) Test(org.junit.jupiter.api.Test)

Example 2 with MetaStore

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

the class SnapshotManagerTest method testSnapshotManager.

@Test
void testSnapshotManager() throws IOException, InterruptedException {
    Configs configs = Configs.newBuilder().put(CommonConfig.INGESTOR_QUEUE_COUNT.getKey(), "1").put(CommonConfig.STORE_NODE_COUNT.getKey(), "2").put(CommonConfig.FRONTEND_NODE_COUNT.getKey(), "1").put(CommonConfig.INGESTOR_NODE_COUNT.getKey(), "1").put(CoordinatorConfig.SNAPSHOT_INCREASE_INTERVAL_MS.getKey(), "1000").put(CoordinatorConfig.OFFSETS_PERSIST_INTERVAL_MS.getKey(), "1000").build();
    long querySnapshotId = 10L;
    long writeSnapshotId = 12L;
    List<Long> queueOffsets = Arrays.asList(50L);
    long commitSnapshotId1 = 11L;
    long commitSnapshotId2 = 12L;
    List<Long> commitQueueOffsets1 = Arrays.asList(60L);
    List<Long> commitQueueOffsets2 = Arrays.asList(70L);
    ObjectMapper objectMapper = new ObjectMapper();
    MetaStore mockMetaStore = mock(MetaStore.class);
    when(mockMetaStore.exists(anyString())).thenReturn(true);
    when(mockMetaStore.read(QUERY_SNAPSHOT_INFO_PATH)).thenReturn(objectMapper.writeValueAsBytes(new SnapshotInfo(querySnapshotId, querySnapshotId)));
    when(mockMetaStore.read(WRITE_SNAPSHOT_ID_PATH)).thenReturn(objectMapper.writeValueAsBytes(writeSnapshotId));
    when(mockMetaStore.read(QUEUE_OFFSETS_PATH)).thenReturn(objectMapper.writeValueAsBytes(queueOffsets));
    CountDownLatch updateWriteSnapshotLatch = new CountDownLatch(1);
    doAnswer(invocationOnMock -> {
        updateWriteSnapshotLatch.countDown();
        return null;
    }).when(mockMetaStore).write(WRITE_SNAPSHOT_ID_PATH, objectMapper.writeValueAsBytes(writeSnapshotId + 1));
    CountDownLatch updateQueueOffsetLatch = new CountDownLatch(1);
    doAnswer(invocationOnMock -> {
        updateQueueOffsetLatch.countDown();
        return null;
    }).when(mockMetaStore).write(QUEUE_OFFSETS_PATH, objectMapper.writeValueAsBytes(commitQueueOffsets1));
    IngestorWriteSnapshotIdNotifier mockWriteSnapshotIdNotifier = mock(IngestorWriteSnapshotIdNotifier.class);
    CountDownLatch updateIngestorLatch = new CountDownLatch(1);
    doAnswer(invocationOnMock -> {
        updateIngestorLatch.countDown();
        return null;
    }).when(mockWriteSnapshotIdNotifier).notifyWriteSnapshotIdChanged(writeSnapshotId + 1);
    LogService mockLogService = mock(LogService.class);
    SnapshotManager snapshotManager = new SnapshotManager(configs, mockMetaStore, mockLogService, mockWriteSnapshotIdNotifier);
    snapshotManager.start();
    assertEquals(snapshotManager.getQueueOffsets(), queueOffsets);
    assertTrue(updateWriteSnapshotLatch.await(5L, TimeUnit.SECONDS));
    assertTrue(updateIngestorLatch.await(5L, TimeUnit.SECONDS));
    snapshotManager.commitSnapshotId(0, commitSnapshotId1, 10L, commitQueueOffsets1);
    snapshotManager.commitSnapshotId(1, commitSnapshotId2, 10L, commitQueueOffsets2);
    verify(mockMetaStore).write(QUERY_SNAPSHOT_INFO_PATH, objectMapper.writeValueAsBytes(new SnapshotInfo(commitSnapshotId1, 10L)));
    assertTrue(updateQueueOffsetLatch.await(5L, TimeUnit.SECONDS));
    assertEquals(snapshotManager.getQueueOffsets(), commitQueueOffsets1);
    snapshotManager.stop();
}
Also used : MetaStore(com.alibaba.graphscope.groot.meta.MetaStore) SnapshotInfo(com.alibaba.graphscope.groot.coordinator.SnapshotInfo) Configs(com.alibaba.maxgraph.common.config.Configs) CountDownLatch(java.util.concurrent.CountDownLatch) IngestorWriteSnapshotIdNotifier(com.alibaba.graphscope.groot.coordinator.IngestorWriteSnapshotIdNotifier) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LogService(com.alibaba.graphscope.groot.wal.LogService) SnapshotManager(com.alibaba.graphscope.groot.coordinator.SnapshotManager) Test(org.junit.jupiter.api.Test)

Example 3 with MetaStore

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

the class BackupManagerTest method testBackupManager.

@Test
void testBackupManager() throws IOException, InterruptedException {
    // init config
    Configs configs = Configs.newBuilder().put(CommonConfig.STORE_NODE_COUNT.getKey(), "2").put(BackupConfig.BACKUP_ENABLE.getKey(), "true").put(BackupConfig.BACKUP_CREATION_BUFFER_MAX_COUNT.getKey(), "4").put(BackupConfig.BACKUP_GC_INTERVAL_HOURS.getKey(), "24").put(BackupConfig.BACKUP_AUTO_SUBMIT.getKey(), "false").put(BackupConfig.BACKUP_AUTO_SUBMIT_INTERVAL_HOURS.getKey(), "24").build();
    // init data
    long querySnapshotId = 10L;
    GraphDef graphDef = GraphDef.newBuilder().setVersion(10L).build();
    SnapshotWithSchema snapshotWithSchema = new SnapshotWithSchema(querySnapshotId, graphDef);
    List<Long> queueOffsets = new ArrayList<>();
    Map<Integer, Integer> partitionToBackupId1 = new HashMap<>();
    partitionToBackupId1.put(0, 1);
    partitionToBackupId1.put(1, 1);
    Map<Integer, Integer> partitionToBackupId2 = new HashMap<>();
    partitionToBackupId2.put(0, 2);
    partitionToBackupId2.put(1, 2);
    BackupInfo backupInfo1 = new BackupInfo(1, querySnapshotId, graphDef.toProto().toByteArray(), queueOffsets, partitionToBackupId1);
    BackupInfo backupInfo2 = new BackupInfo(2, querySnapshotId, graphDef.toProto().toByteArray(), queueOffsets, partitionToBackupId2);
    // mock MetaStore behaviours
    ObjectMapper objectMapper = new ObjectMapper();
    MetaStore mockMetaStore = mock(MetaStore.class);
    when(mockMetaStore.exists(anyString())).thenReturn(true);
    when(mockMetaStore.read(GLOBAL_BACKUP_ID_PATH)).thenReturn(objectMapper.writeValueAsBytes(0));
    when(mockMetaStore.read(BACKUP_INFO_PATH)).thenReturn(objectMapper.writeValueAsBytes(new ArrayList<BackupInfo>()));
    // mock MetaService behaviours
    MetaService mockMetaService = mock(MetaService.class);
    when(mockMetaService.getPartitionCount()).thenReturn(2);
    when(mockMetaService.getStoreIdByPartition(0)).thenReturn(0);
    when(mockMetaService.getStoreIdByPartition(1)).thenReturn(1);
    // mock SnapshotManager behaviours
    SnapshotManager mockSnapshotManager = mock(SnapshotManager.class);
    when(mockSnapshotManager.getQueueOffsets()).thenReturn(queueOffsets);
    // mock SchemaManager
    SchemaManager mockSchemaManager = mock(SchemaManager.class);
    when(mockSchemaManager.getGraphDef()).thenReturn(graphDef);
    // mock SnapshotCache
    SnapshotCache mockSnapshotCache = mock(SnapshotCache.class);
    when(mockSnapshotCache.getSnapshotWithSchema()).thenReturn(snapshotWithSchema);
    // mock StoreBackupTaskSender behaviours
    StoreBackupTaskSender mockStoreBackupTaskSender = mock(StoreBackupTaskSender.class);
    doAnswer(invocation -> {
        int partitionOrStoreId = invocation.getArgument(0);
        int globalBackupId = invocation.getArgument(1);
        CompletionCallback<StoreBackupId> callback = invocation.getArgument(2);
        StoreBackupId storeBackupId = new StoreBackupId(globalBackupId);
        storeBackupId.addPartitionBackupId(partitionOrStoreId, globalBackupId);
        callback.onCompleted(storeBackupId);
        return null;
    }).when(mockStoreBackupTaskSender).createStoreBackup(anyInt(), anyInt(), any());
    doAnswer(invocation -> {
        CompletionCallback<Void> callback = invocation.getArgument(3);
        callback.onCompleted(null);
        return null;
    }).when(mockStoreBackupTaskSender).restoreFromStoreBackup(anyInt(), any(), anyString(), any());
    doAnswer(invocation -> {
        CompletionCallback<Void> callback = invocation.getArgument(2);
        callback.onCompleted(null);
        return null;
    }).when(mockStoreBackupTaskSender).verifyStoreBackup(anyInt(), any(), any());
    BackupManager backupManager = new BackupManager(configs, mockMetaService, mockMetaStore, mockSnapshotManager, mockSchemaManager, mockSnapshotCache, mockStoreBackupTaskSender);
    backupManager.start();
    verify(mockSnapshotManager).addListener(any());
    // create the first backup
    CountDownLatch updateBackupIdLatch1 = new CountDownLatch(1);
    CountDownLatch updateBackupInfoByCreation1Latch = new CountDownLatch(1);
    doAnswer(invocation -> {
        updateBackupIdLatch1.countDown();
        return null;
    }).when(mockMetaStore).write(GLOBAL_BACKUP_ID_PATH, objectMapper.writeValueAsBytes(1));
    doAnswer(invocation -> {
        byte[] backupInfoBytes = invocation.getArgument(1);
        List<BackupInfo> backupInfoList = objectMapper.readValue(backupInfoBytes, new TypeReference<List<BackupInfo>>() {
        });
        assertEquals(backupInfoList.size(), 1);
        assertEquals(backupInfoList.get(0), backupInfo1);
        updateBackupInfoByCreation1Latch.countDown();
        return null;
    }).when(mockMetaStore).write(BACKUP_INFO_PATH, objectMapper.writeValueAsBytes(Collections.singletonList(backupInfo1)));
    int backupId1 = backupManager.createNewBackup();
    assertEquals(backupId1, 1);
    assertTrue(updateBackupIdLatch1.await(5L, TimeUnit.SECONDS));
    assertTrue(updateBackupInfoByCreation1Latch.await(5L, TimeUnit.SECONDS));
    // create the second backup
    CountDownLatch updateBackupIdLatch2 = new CountDownLatch(1);
    CountDownLatch updateBackupInfoByCreation2Latch = new CountDownLatch(1);
    doAnswer(invocation -> {
        updateBackupIdLatch2.countDown();
        return null;
    }).when(mockMetaStore).write(GLOBAL_BACKUP_ID_PATH, objectMapper.writeValueAsBytes(2));
    doAnswer(invocation -> {
        byte[] backupInfoBytes = invocation.getArgument(1);
        List<BackupInfo> backupInfoList = objectMapper.readValue(backupInfoBytes, new TypeReference<List<BackupInfo>>() {
        });
        backupInfoList.sort(new Comparator<BackupInfo>() {

            @Override
            public int compare(BackupInfo o1, BackupInfo o2) {
                return o1.getGlobalBackupId() - o2.getGlobalBackupId();
            }
        });
        assertEquals(backupInfoList.size(), 2);
        assertEquals(backupInfoList.get(0), backupInfo1);
        assertEquals(backupInfoList.get(1), backupInfo2);
        updateBackupInfoByCreation2Latch.countDown();
        return null;
    }).when(mockMetaStore).write(BACKUP_INFO_PATH, objectMapper.writeValueAsBytes(Arrays.asList(backupInfo1, backupInfo2)));
    int backupId2 = backupManager.createNewBackup();
    assertEquals(backupId2, 2);
    assertTrue(updateBackupIdLatch2.await(5L, TimeUnit.SECONDS));
    assertTrue(updateBackupInfoByCreation2Latch.await(5L, TimeUnit.SECONDS));
    // get backup info list and check
    assertEquals(backupManager.getBackupInfoList().size(), 2);
    // verify backups
    try {
        backupManager.verifyBackup(backupId1);
        backupManager.verifyBackup(backupId2);
    } catch (Exception e) {
        fail("should not have thrown any exception during backup verification");
    }
    // restore from the second backup
    try {
        backupManager.restoreFromBackup(backupId2, "restore_meta", "restore_store");
        assertTrue(Files.exists(Paths.get("restore_meta", "query_snapshot_id")));
        assertTrue(Files.exists(Paths.get("restore_meta", "graph_def_proto_bytes")));
        assertTrue(Files.exists(Paths.get("restore_meta", "queue_offsets")));
    } catch (Exception e) {
        fail("should not have thrown any exception during backup restoring");
    } finally {
        FileUtils.deleteDirectory(new File("restore_meta"));
    }
    // purge 1 old backup
    CountDownLatch updateBackupInfoByPurgingLatch = new CountDownLatch(1);
    doAnswer(invocation -> {
        byte[] backupInfoBytes = invocation.getArgument(1);
        List<BackupInfo> backupInfoList = objectMapper.readValue(backupInfoBytes, new TypeReference<List<BackupInfo>>() {
        });
        assertEquals(backupInfoList.size(), 1);
        assertEquals(backupInfoList.get(0), backupInfo2);
        updateBackupInfoByPurgingLatch.countDown();
        return null;
    }).when(mockMetaStore).write(BACKUP_INFO_PATH, objectMapper.writeValueAsBytes(Collections.singletonList(backupInfo2)));
    backupManager.purgeOldBackups(1);
    assertTrue(updateBackupInfoByPurgingLatch.await(5L, TimeUnit.SECONDS));
    // get backup info list and check
    assertEquals(backupManager.getBackupInfoList().size(), 1);
    // delete the remaining backup '2'
    CountDownLatch updateBackupInfoByDeletionLatch = new CountDownLatch(1);
    doAnswer(invocation -> {
        byte[] backupInfoBytes = invocation.getArgument(1);
        List<BackupInfo> backupInfoList = objectMapper.readValue(backupInfoBytes, new TypeReference<List<BackupInfo>>() {
        });
        assertTrue(backupInfoList.isEmpty());
        updateBackupInfoByDeletionLatch.countDown();
        return null;
    }).when(mockMetaStore).write(BACKUP_INFO_PATH, objectMapper.writeValueAsBytes(new ArrayList<BackupInfo>()));
    backupManager.deleteBackup(2);
    assertTrue(updateBackupInfoByDeletionLatch.await(5L, TimeUnit.SECONDS));
    // get backup info list and check
    assertTrue(backupManager.getBackupInfoList().isEmpty());
    backupManager.stop();
    verify(mockSnapshotManager).removeListener(any());
}
Also used : MetaService(com.alibaba.graphscope.groot.meta.MetaService) SnapshotCache(com.alibaba.graphscope.groot.SnapshotCache) BackupInfo(com.alibaba.maxgraph.sdkcommon.common.BackupInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SnapshotWithSchema(com.alibaba.graphscope.groot.SnapshotWithSchema) CountDownLatch(java.util.concurrent.CountDownLatch) GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef) BackupManager(com.alibaba.graphscope.groot.coordinator.BackupManager) IOException(java.io.IOException) MetaStore(com.alibaba.graphscope.groot.meta.MetaStore) StoreBackupId(com.alibaba.graphscope.groot.store.StoreBackupId) Configs(com.alibaba.maxgraph.common.config.Configs) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 4 with MetaStore

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

the class BackupManager method restoreGraphMeta.

private void restoreGraphMeta(int globalBackupId, String metaRestorePath) throws IOException {
    BackupInfo restoredBackupInfo = this.globalBackupIdToInfo.get(globalBackupId);
    Configs.Builder builder = Configs.newBuilder();
    builder.put("file.meta.store.path", metaRestorePath);
    MetaStore restoredMetaStore = new FileMetaStore(builder.build());
    long restoredSnapshotId = restoredBackupInfo.getSnapshotId();
    restoredMetaStore.write("query_snapshot_id", this.objectMapper.writeValueAsBytes(restoredSnapshotId));
    restoredMetaStore.write("graph_def_proto_bytes", restoredBackupInfo.getGraphDefBytes());
    List<Long> restoredWalOffsets = restoredBackupInfo.getWalOffsets();
    restoredMetaStore.write("queue_offsets", this.objectMapper.writeValueAsBytes(restoredWalOffsets));
// Restore all graph meta restore in the future.
// To be implemented.
}
Also used : BackupInfo(com.alibaba.maxgraph.sdkcommon.common.BackupInfo) MetaStore(com.alibaba.graphscope.groot.meta.MetaStore) Configs(com.alibaba.maxgraph.common.config.Configs)

Aggregations

MetaStore (com.alibaba.graphscope.groot.meta.MetaStore)4 Configs (com.alibaba.maxgraph.common.config.Configs)4 Test (org.junit.jupiter.api.Test)3 BackupInfo (com.alibaba.maxgraph.sdkcommon.common.BackupInfo)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 SnapshotCache (com.alibaba.graphscope.groot.SnapshotCache)1 SnapshotWithSchema (com.alibaba.graphscope.groot.SnapshotWithSchema)1 BackupManager (com.alibaba.graphscope.groot.coordinator.BackupManager)1 IngestorWriteSnapshotIdNotifier (com.alibaba.graphscope.groot.coordinator.IngestorWriteSnapshotIdNotifier)1 SnapshotInfo (com.alibaba.graphscope.groot.coordinator.SnapshotInfo)1 SnapshotManager (com.alibaba.graphscope.groot.coordinator.SnapshotManager)1 ZkMetaStore (com.alibaba.graphscope.groot.coordinator.ZkMetaStore)1 MetaService (com.alibaba.graphscope.groot.meta.MetaService)1 StoreBackupId (com.alibaba.graphscope.groot.store.StoreBackupId)1 LogService (com.alibaba.graphscope.groot.wal.LogService)1 GraphDef (com.alibaba.maxgraph.sdkcommon.schema.GraphDef)1 File (java.io.File)1 IOException (java.io.IOException)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1