Search in sources :

Example 6 with BackupInfo

use of com.alibaba.maxgraph.sdkcommon.common.BackupInfo in project GraphScope by alibaba.

the class BackupManager method doBackupCreation.

private void doBackupCreation(int newGlobalBackupId) {
    List<Long> walOffsets = snapshotManager.getQueueOffsets();
    SnapshotWithSchema snapshotWithSchema = localSnapshotCache.getSnapshotWithSchema();
    Map<Integer, Integer> partitionToBackupId = new ConcurrentHashMap<>(graphPartitionCount);
    AtomicInteger counter = new AtomicInteger(storeNodeCount);
    AtomicBoolean finished = new AtomicBoolean(false);
    CompletableFuture<Void> future = new CompletableFuture<>();
    for (int sId = 0; sId < storeNodeCount; sId++) {
        storeBackupTaskSender.createStoreBackup(sId, newGlobalBackupId, new CompletionCallback<StoreBackupId>() {

            @Override
            public void onCompleted(StoreBackupId storeBackupId) {
                if (finished.get()) {
                    return;
                }
                partitionToBackupId.putAll(storeBackupId.getPartitionToBackupId());
                if (counter.decrementAndGet() == 0) {
                    if (partitionToBackupId.size() == graphPartitionCount) {
                        try {
                            addNewBackupInfo(new BackupInfo(newGlobalBackupId, snapshotWithSchema.getSnapshotId(), snapshotWithSchema.getGraphDef().toProto().toByteArray(), walOffsets, partitionToBackupId));
                            future.complete(null);
                        } catch (Exception e) {
                            future.completeExceptionally(new BackupException("failed to persist backup info of new" + " created backup #[" + newGlobalBackupId + "], " + e.getMessage()));
                        }
                    } else {
                        future.completeExceptionally(new BackupException("got incorrect number of partition backupIds" + " when creating backup #[" + newGlobalBackupId + "], got " + partitionToBackupId.size() + ", expect " + graphPartitionCount));
                    }
                }
            }

            @Override
            public void onError(Throwable t) {
                if (finished.getAndSet(true)) {
                    return;
                }
                future.completeExceptionally(t);
            }
        });
    }
    try {
        future.get();
        logger.info("new backup [" + newGlobalBackupId + "] created");
    } catch (Exception e) {
        logger.error("create new backup [" + newGlobalBackupId + "] failed", e);
    }
}
Also used : BackupException(com.alibaba.maxgraph.compiler.api.exception.BackupException) SnapshotWithSchema(com.alibaba.graphscope.groot.SnapshotWithSchema) BackupException(com.alibaba.maxgraph.compiler.api.exception.BackupException) MaxGraphException(com.alibaba.maxgraph.compiler.api.exception.MaxGraphException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BackupInfo(com.alibaba.maxgraph.sdkcommon.common.BackupInfo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StoreBackupId(com.alibaba.graphscope.groot.store.StoreBackupId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 7 with BackupInfo

use of com.alibaba.maxgraph.sdkcommon.common.BackupInfo 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)

Example 8 with BackupInfo

use of com.alibaba.maxgraph.sdkcommon.common.BackupInfo in project GraphScope by alibaba.

the class ClientBackupTest method testBackup.

@Test
public void testBackup() throws InterruptedException, IOException, URISyntaxException {
    Thread.sleep(30000L);
    Path path = Paths.get(Thread.currentThread().getContextClassLoader().getResource("modern.schema").toURI());
    String jsonSchemaRes = client.loadJsonSchema(path);
    System.out.println(jsonSchemaRes);
    Map<String, String> properties;
    for (int i = 0; i < 10; i++) {
        properties = new HashMap<>();
        properties.put("id", "" + i);
        properties.put("name", "young_" + i);
        properties.put("age", "18");
        client.addVertex("person", properties);
    }
    client.commit();
    Thread.sleep(3000L);
    List<BackupInfo> backupInfoList;
    int backupId1 = client.createNewGraphBackup();
    Thread.sleep(3000L);
    backupInfoList = client.getGraphBackupInfo();
    Assertions.assertEquals(backupInfoList.size(), 1);
    Assertions.assertEquals(backupInfoList.get(0).getGlobalBackupId(), backupId1);
    for (int i = 0; i < 10; i++) {
        properties = new HashMap<>();
        properties.put("id", "" + i);
        properties.put("name", "lop_" + i);
        properties.put("lang", "java");
        client.addVertex("software", properties);
    }
    client.commit();
    Thread.sleep(3000L);
    int backupId2 = client.createNewGraphBackup();
    Thread.sleep(3000L);
    backupInfoList = client.getGraphBackupInfo();
    Assertions.assertEquals(backupInfoList.size(), 2);
    Assertions.assertEquals(backupInfoList.get(0).getGlobalBackupId(), backupId1);
    Assertions.assertEquals(backupInfoList.get(1).getGlobalBackupId(), backupId2);
    Assertions.assertTrue(client.verifyGraphBackup(backupId1));
    Assertions.assertTrue(client.verifyGraphBackup(backupId2));
    client.restoreFromGraphBackup(backupId1, "./restore/meta_1", "./restore/data_1");
    client.restoreFromGraphBackup(backupId2, "./restore/meta_2", "./restore/data_2");
    client.purgeOldGraphBackups(1);
    backupInfoList = client.getGraphBackupInfo();
    Assertions.assertEquals(backupInfoList.size(), 1);
    Assertions.assertEquals(backupInfoList.get(0).getGlobalBackupId(), backupId2);
    client.deleteGraphBackup(backupId2);
    backupInfoList = client.getGraphBackupInfo();
    Assertions.assertTrue(backupInfoList.isEmpty());
}
Also used : Path(java.nio.file.Path) BackupInfo(com.alibaba.maxgraph.sdkcommon.common.BackupInfo) Test(org.junit.jupiter.api.Test)

Aggregations

BackupInfo (com.alibaba.maxgraph.sdkcommon.common.BackupInfo)8 Test (org.junit.jupiter.api.Test)4 IOException (java.io.IOException)3 SnapshotWithSchema (com.alibaba.graphscope.groot.SnapshotWithSchema)2 MetaStore (com.alibaba.graphscope.groot.meta.MetaStore)2 StoreBackupId (com.alibaba.graphscope.groot.store.StoreBackupId)2 Configs (com.alibaba.maxgraph.common.config.Configs)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 SnapshotCache (com.alibaba.graphscope.groot.SnapshotCache)1 BackupManager (com.alibaba.graphscope.groot.coordinator.BackupManager)1 BackupService (com.alibaba.graphscope.groot.coordinator.BackupService)1 MetaService (com.alibaba.graphscope.groot.meta.MetaService)1 BackupException (com.alibaba.maxgraph.compiler.api.exception.BackupException)1 MaxGraphException (com.alibaba.maxgraph.compiler.api.exception.MaxGraphException)1 GraphDef (com.alibaba.maxgraph.sdkcommon.schema.GraphDef)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1