You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2017/07/18 13:10:51 UTC

[5/5] curator git commit: The entire migration set should be 1 transaction - not each inidividual migration

The entire migration set should be 1 transaction - not each inidividual migration


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/33e41388
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/33e41388
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/33e41388

Branch: refs/heads/CURATOR-421
Commit: 33e4138840904635a1793084051fd50b643794f1
Parents: c77ef82
Author: randgalt <ra...@apache.org>
Authored: Tue Jul 18 08:10:43 2017 -0500
Committer: randgalt <ra...@apache.org>
Committed: Tue Jul 18 08:10:43 2017 -0500

----------------------------------------------------------------------
 .../x/async/migrations/MigrationManager.java     | 19 +++++++++----------
 .../src/site/confluence/migrations.confluence    |  4 +++-
 .../x/async/migrations/TestMigrationManager.java |  2 +-
 3 files changed, 13 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/33e41388/curator-x-async/src/main/java/org/apache/curator/x/async/migrations/MigrationManager.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/migrations/MigrationManager.java b/curator-x-async/src/main/java/org/apache/curator/x/async/migrations/MigrationManager.java
index 56e7f04..e51f0e4 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/migrations/MigrationManager.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/migrations/MigrationManager.java
@@ -106,7 +106,6 @@ public class MigrationManager
         }
 
         int compareSize = Math.min(set.migrations().size(), operationHashesInOrder.size());
-        List<Migration> subList = set.migrations().subList(0, compareSize);
         for ( int i = 0; i < compareSize; ++i )
         {
             byte[] setHash = hash(set.migrations().get(i).operations());
@@ -184,23 +183,23 @@ public class MigrationManager
         }
 
         return asyncEnsureContainers(client, thisMetaDataPath)
-            .thenCompose(__ -> applyMetaDataAfterEnsure(set, toBeApplied, thisMetaDataPath));
+            .thenCompose(__ -> applyMetaDataAfterEnsure(toBeApplied, thisMetaDataPath));
     }
 
     @VisibleForTesting
     volatile AtomicInteger debugCount = null;
 
-    private CompletionStage<Void> applyMetaDataAfterEnsure(MigrationSet set, List<Migration> toBeApplied, String thisMetaDataPath)
+    private CompletionStage<Void> applyMetaDataAfterEnsure(List<Migration> toBeApplied, String thisMetaDataPath)
     {
         debugCount.incrementAndGet();
 
+        List<CuratorOp> operations = new ArrayList<>();
         String metaDataBasePath = ZKPaths.makePath(thisMetaDataPath, META_DATA_NODE_NAME);
-        List<CompletableFuture<Object>> stages = toBeApplied.stream().map(migration -> {
-            List<CuratorOp> operations = new ArrayList<>();
-            operations.addAll(migration.operations());
-            operations.add(client.transactionOp().create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(metaDataBasePath, hash(operations)));
-            return client.transaction().forOperations(operations).thenApply(__ -> null).toCompletableFuture();
-        }).collect(Collectors.toList());
-        return CompletableFuture.allOf(stages.toArray(new CompletableFuture[stages.size()]));
+        toBeApplied.forEach(migration -> {
+            List<CuratorOp> thisMigrationOperations = migration.operations();
+            operations.addAll(thisMigrationOperations);
+            operations.add(client.transactionOp().create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(metaDataBasePath, hash(thisMigrationOperations)));
+        });
+        return client.transaction().forOperations(operations).thenApply(__ -> null);
     }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/33e41388/curator-x-async/src/site/confluence/migrations.confluence
----------------------------------------------------------------------
diff --git a/curator-x-async/src/site/confluence/migrations.confluence b/curator-x-async/src/site/confluence/migrations.confluence
index 4775fac..bd2d36f 100644
--- a/curator-x-async/src/site/confluence/migrations.confluence
+++ b/curator-x-async/src/site/confluence/migrations.confluence
@@ -91,7 +91,9 @@ manager.migrate(set).exceptionally(e -> {
 });
 {code}
 
-Each migration in the set is applied in a transaction. MigrationManager stores a hash
+Each migration in the set is applied in a single transaction - i.e. all operations that comprise
+a migration set (the sum of all individual migration operations) are sent to ZooKeeper as a single
+transaction. MigrationManager stores a hash
 of all operations in a migration so that it can be compared for future operations. i.e.
 if, in the future, a migration set is attempted but the hash of one of the previous migrations
 does not match, the stage completes exceptionally with {{MigrationException}}.

http://git-wip-us.apache.org/repos/asf/curator/blob/33e41388/curator-x-async/src/test/java/org/apache/curator/x/async/migrations/TestMigrationManager.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/test/java/org/apache/curator/x/async/migrations/TestMigrationManager.java b/curator-x-async/src/test/java/org/apache/curator/x/async/migrations/TestMigrationManager.java
index 786e704..47d09ab 100644
--- a/curator-x-async/src/test/java/org/apache/curator/x/async/migrations/TestMigrationManager.java
+++ b/curator-x-async/src/test/java/org/apache/curator/x/async/migrations/TestMigrationManager.java
@@ -268,7 +268,7 @@ public class TestMigrationManager extends CompletableBaseClassForTests
             Assert.assertTrue(Throwables.getRootCause(e) instanceof KeeperException.NoNodeException);
         }
 
-        Assert.assertEquals(client.unwrap().getData().forPath("/test"), "something".getBytes());
+        Assert.assertNull(client.unwrap().checkExists().forPath("/test"));  // should be all or nothing
     }
 
     @Test