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);
}
}
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.
}
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());
}
Aggregations