use of com.alibaba.maxgraph.compiler.api.exception.BackupException in project GraphScope by alibaba.
the class BackupAgent method restoreFromStoreBackup.
public void restoreFromStoreBackup(StoreBackupId storeBackupId, String restoreRootPath, CompletionCallback<Void> callback) {
try {
checkEnable();
} catch (BackupException e) {
callback.onError(e);
return;
}
if (storeBackupId.getPartitionToBackupId().size() != this.idToPartitionBackup.size()) {
callback.onError(new BackupException("restoring from incorrect store backup id, globalBackupId #[" + storeBackupId.getGlobalBackupId() + "], restoreRootPath: " + restoreRootPath + ", storeId #[" + this.storeId + "]"));
return;
}
AtomicInteger counter = new AtomicInteger(this.idToPartitionBackup.size());
AtomicBoolean finished = new AtomicBoolean(false);
for (Map.Entry<Integer, GraphPartitionBackup> entry : this.idToPartitionBackup.entrySet()) {
this.backupExecutor.execute(() -> {
if (finished.get()) {
return;
}
try {
int partitionId = entry.getKey();
Path partitionRestorePath = Paths.get(restoreRootPath, "" + partitionId);
if (!Files.isDirectory(partitionRestorePath)) {
Files.createDirectories(partitionRestorePath);
}
entry.getValue().restoreFromPartitionBackup(storeBackupId.getPartitionToBackupId().get(partitionId), partitionRestorePath.toString());
if (counter.decrementAndGet() == 0) {
callback.onCompleted(null);
}
} catch (Exception e) {
if (finished.getAndSet(true)) {
return;
}
callback.onError(e);
}
});
}
}
use of com.alibaba.maxgraph.compiler.api.exception.BackupException 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.compiler.api.exception.BackupException in project GraphScope by alibaba.
the class BackupManager method verifyBackup.
public void verifyBackup(int globalBackupId) throws BackupException {
checkEnable();
if (!this.globalBackupIdToInfo.containsKey(globalBackupId)) {
throw new BackupException("backup #[" + globalBackupId + "] not ready/existed");
}
List<StoreBackupId> storeBackupIds = getStoreBackupIds(globalBackupId);
AtomicInteger counter = new AtomicInteger(storeNodeCount);
AtomicBoolean finished = new AtomicBoolean(false);
CompletableFuture<Void> future = new CompletableFuture<>();
for (int sId = 0; sId < storeNodeCount; sId++) {
storeBackupTaskSender.verifyStoreBackup(sId, storeBackupIds.get(sId), new CompletionCallback<Void>() {
@Override
public void onCompleted(Void res) {
if (!finished.get() && counter.decrementAndGet() == 0) {
future.complete(null);
}
}
@Override
public void onError(Throwable t) {
if (finished.getAndSet(true)) {
return;
}
future.completeExceptionally(t);
}
});
}
try {
future.get();
} catch (Exception e) {
throw new BackupException(e.getMessage());
}
}
use of com.alibaba.maxgraph.compiler.api.exception.BackupException in project GraphScope by alibaba.
the class BackupManager method restoreGraphStore.
private void restoreGraphStore(int globalBackupId, String storeRestorePath) throws BackupException {
List<StoreBackupId> storeBackupIds = getStoreBackupIds(globalBackupId);
AtomicInteger counter = new AtomicInteger(storeNodeCount);
AtomicBoolean finished = new AtomicBoolean(false);
CompletableFuture<Void> future = new CompletableFuture<>();
for (int sId = 0; sId < storeNodeCount; sId++) {
storeBackupTaskSender.restoreFromStoreBackup(sId, storeBackupIds.get(sId), storeRestorePath, new CompletionCallback<Void>() {
@Override
public void onCompleted(Void res) {
if (!finished.get() && counter.decrementAndGet() == 0) {
future.complete(null);
}
}
@Override
public void onError(Throwable t) {
if (finished.getAndSet(true)) {
return;
}
future.completeExceptionally(t);
}
});
}
try {
future.get();
} catch (Exception e) {
throw new BackupException(e.getMessage());
}
}
use of com.alibaba.maxgraph.compiler.api.exception.BackupException in project GraphScope by alibaba.
the class BackupAgent method verifyStoreBackup.
public void verifyStoreBackup(StoreBackupId storeBackupId, CompletionCallback<Void> callback) {
try {
checkEnable();
} catch (BackupException e) {
callback.onError(e);
return;
}
if (storeBackupId.getPartitionToBackupId().size() != this.idToPartitionBackup.size()) {
callback.onError(new BackupException("verifying from incorrect store backup id, globalBackupId #[" + storeBackupId.getGlobalBackupId() + "], storeId #[" + this.storeId + "]"));
return;
}
AtomicInteger counter = new AtomicInteger(this.idToPartitionBackup.size());
AtomicBoolean finished = new AtomicBoolean(false);
for (Map.Entry<Integer, GraphPartitionBackup> entry : this.idToPartitionBackup.entrySet()) {
this.backupExecutor.execute(() -> {
if (finished.get()) {
return;
}
try {
int partitionId = entry.getKey();
entry.getValue().verifyPartitionBackup(storeBackupId.getPartitionToBackupId().get(partitionId));
if (counter.decrementAndGet() == 0) {
callback.onCompleted(null);
}
} catch (Exception e) {
if (finished.getAndSet(true)) {
return;
}
callback.onError(e);
}
});
}
}
Aggregations