Search in sources :

Example 1 with BackupException

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);
            }
        });
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Path(java.nio.file.Path) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BackupException(com.alibaba.maxgraph.compiler.api.exception.BackupException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) Map(java.util.Map) BackupException(com.alibaba.maxgraph.compiler.api.exception.BackupException) IOException(java.io.IOException)

Example 2 with BackupException

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);
    }
}
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 3 with BackupException

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());
    }
}
Also used : BackupException(com.alibaba.maxgraph.compiler.api.exception.BackupException) BackupException(com.alibaba.maxgraph.compiler.api.exception.BackupException) MaxGraphException(com.alibaba.maxgraph.compiler.api.exception.MaxGraphException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StoreBackupId(com.alibaba.graphscope.groot.store.StoreBackupId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 4 with BackupException

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());
    }
}
Also used : BackupException(com.alibaba.maxgraph.compiler.api.exception.BackupException) BackupException(com.alibaba.maxgraph.compiler.api.exception.BackupException) MaxGraphException(com.alibaba.maxgraph.compiler.api.exception.MaxGraphException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StoreBackupId(com.alibaba.graphscope.groot.store.StoreBackupId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 5 with BackupException

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);
            }
        });
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BackupException(com.alibaba.maxgraph.compiler.api.exception.BackupException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) Map(java.util.Map) BackupException(com.alibaba.maxgraph.compiler.api.exception.BackupException) IOException(java.io.IOException)

Aggregations

BackupException (com.alibaba.maxgraph.compiler.api.exception.BackupException)7 IOException (java.io.IOException)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 HashMap (java.util.HashMap)4 Map (java.util.Map)4 StoreBackupId (com.alibaba.graphscope.groot.store.StoreBackupId)3 MaxGraphException (com.alibaba.maxgraph.compiler.api.exception.MaxGraphException)3 FileNotFoundException (java.io.FileNotFoundException)3 SnapshotWithSchema (com.alibaba.graphscope.groot.SnapshotWithSchema)1 BackupInfo (com.alibaba.maxgraph.sdkcommon.common.BackupInfo)1 Path (java.nio.file.Path)1