use of org.apache.ignite.internal.metastorage.server.persistence.StorageColumnFamilyType.INDEX in project ignite-3 by apache.
the class RocksDbKeyValueStorage method snapshot.
/**
* {@inheritDoc}
*/
@NotNull
@Override
public CompletableFuture<Void> snapshot(Path snapshotPath) {
Path tempPath = Paths.get(snapshotPath.toString() + TMP_SUFFIX);
// Create a RocksDB point-in-time snapshot
Snapshot snapshot = db.getSnapshot();
return CompletableFuture.runAsync(() -> {
// (Re)create the temporary directory
IgniteUtils.deleteIfExists(tempPath);
try {
Files.createDirectories(tempPath);
} catch (IOException e) {
throw new IgniteInternalException("Failed to create directory: " + tempPath, e);
}
}, snapshotExecutor).thenCompose(argVoid -> CompletableFuture.allOf(CompletableFuture.runAsync(() -> createSstFile(data, snapshot, tempPath), snapshotExecutor), CompletableFuture.runAsync(() -> createSstFile(index, snapshot, tempPath), snapshotExecutor))).whenComplete((argVoid, throwable) -> {
// Release a snapshot
db.releaseSnapshot(snapshot);
// Snapshot is not actually closed here, because a Snapshot instance doesn't own a pointer, the
// database does. Calling close to maintain the AutoCloseable semantics
snapshot.close();
if (throwable != null) {
return;
}
// Delete snapshot directory if it already exists
IgniteUtils.deleteIfExists(snapshotPath);
try {
// Rename the temporary directory
IgniteUtils.atomicMoveFile(tempPath, snapshotPath, null);
} catch (IOException e) {
throw new IgniteInternalException("Failed to rename: " + tempPath + " to " + snapshotPath, e);
}
});
}
Aggregations