use of org.apache.ignite.internal.metastorage.server.If in project ignite-3 by apache.
the class RocksDbKeyValueStorage method invoke.
@Override
public StatementResult invoke(If iif) {
rwLock.writeLock().lock();
try {
If currIf = iif;
byte maximumNumOfNestedBranch = 100;
while (true) {
if (maximumNumOfNestedBranch-- <= 0) {
throw new IgniteInternalException("Too many nested (" + maximumNumOfNestedBranch + ") statements in multi-invoke command.");
}
Entry[] entries = getAll(Arrays.asList(currIf.cond().keys())).toArray(new Entry[] {});
Statement branch = (currIf.cond().test(entries)) ? currIf.andThen() : currIf.orElse();
if (branch.isTerminal()) {
Update update = branch.update();
applyOperations(update.operations());
return update.result();
} else {
currIf = branch.iif();
}
}
} catch (RocksDBException e) {
throw new IgniteInternalException(e);
} finally {
rwLock.writeLock().unlock();
}
}
use of org.apache.ignite.internal.metastorage.server.If 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