rpuch commented on code in PR #924:
URL: https://github.com/apache/ignite-3/pull/924#discussion_r913898510


##########
modules/rocksdb-common/src/main/java/org/apache/ignite/internal/rocksdb/snapshot/RocksSnapshotManager.java:
##########
@@ -77,18 +78,22 @@ public RocksSnapshotManager(RocksDB db, 
Collection<ColumnFamilyRange> ranges, Ex
     public CompletableFuture<Void> createSnapshot(Path snapshotDir) {
         Path tmpPath = Paths.get(snapshotDir.toString() + TMP_SUFFIX);
 
-        return CompletableFuture.supplyAsync(db::getSnapshot, executor)
-                .thenComposeAsync(snapshot -> {
+        // The snapshot reference must be taken synchronously, otherwise we 
might let more writes sneak into the snapshot than needed.
+        Snapshot snapshot = db.getSnapshot();
+
+        return CompletableFuture.supplyAsync(
+                () -> {
                     createTmpSnapshotDir(tmpPath);
 
                     // Create futures for capturing SST snapshots of the 
column families
                     CompletableFuture<?>[] sstFutures = ranges.stream()
                             .map(cf -> createSstFileAsync(cf, snapshot, 
tmpPath))
                             .toArray(CompletableFuture[]::new);
 
-                    return CompletableFuture.allOf(sstFutures).thenApply(v -> 
snapshot);
+                    return CompletableFuture.allOf(sstFutures);
                 }, executor)
-                .whenCompleteAsync((snapshot, e) -> {
+                .thenCompose(Function.identity())
+                .whenCompleteAsync((ignored, e) -> {
                     if (e != null) {

Review Comment:
   Thanks for catching this



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to