xtern commented on code in PR #5121:
URL: https://github.com/apache/ignite-3/pull/5121#discussion_r1935130711


##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogApplyResult.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.catalog;
+
+
+import java.util.BitSet;
+
+/** Represent result of applying Catalog command. */
+public class CatalogApplyResult {
+    private final int catalogVersion;
+    private final long catalogTime;
+    private final BitSet applied;
+
+    /**
+     * Creates an result with a bitset of applied results and version of a 
catalog when the changes was visible.
+     *
+     * @param appliedResults Result of applying of commands. Every 1 bit say 
about applied result, otherwise 0 says that command has

Review Comment:
   ```suggestion
        * @param appliedResults Set of bits representing the result of applying 
commands. Every {@code 1} bit indicates  that the corresponding command was 
applied, {@code 0} indicates that the corresponding command has
   ```



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogApplyResult.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.catalog;
+
+
+import java.util.BitSet;
+
+/** Represent result of applying Catalog command. */
+public class CatalogApplyResult {
+    private final int catalogVersion;
+    private final long catalogTime;
+    private final BitSet applied;
+
+    /**
+     * Creates an result with a bitset of applied results and version of a 
catalog when the changes was visible.
+     *
+     * @param appliedResults Result of applying of commands. Every 1 bit say 
about applied result, otherwise 0 says that command has
+     *      not been applied. Order of bits the same as commands given for 
execution to Catalog.
+     * @param catalogVersion Version of a catalog when the changes was visible.
+     */
+    public CatalogApplyResult(BitSet appliedResults, int catalogVersion, long 
catalogTime) {
+        assert appliedResults != null;
+
+        this.applied = appliedResults;
+        this.catalogVersion = catalogVersion;
+        this.catalogTime = catalogTime;
+    }
+
+    /** Returns catalog version since applied result is available. */
+    public int getCatalogVersion() {
+        return catalogVersion;
+    }
+
+    /** Returns catalog time since applied result is available. */
+    public long getCatalogTime() {
+
+        return catalogTime;
+    }
+
+    /**
+     * Returns has been applied command by given index or not.

Review Comment:
   ```suggestion
        * Returns whether the specified command was applied or not.
   ```
   :thinking: 



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogApplyResult.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.catalog;
+
+
+import java.util.BitSet;
+
+/** Represent result of applying Catalog command. */
+public class CatalogApplyResult {
+    private final int catalogVersion;
+    private final long catalogTime;
+    private final BitSet applied;
+
+    /**
+     * Creates an result with a bitset of applied results and version of a 
catalog when the changes was visible.
+     *
+     * @param appliedResults Result of applying of commands. Every 1 bit say 
about applied result, otherwise 0 says that command has
+     *      not been applied. Order of bits the same as commands given for 
execution to Catalog.
+     * @param catalogVersion Version of a catalog when the changes was visible.
+     */
+    public CatalogApplyResult(BitSet appliedResults, int catalogVersion, long 
catalogTime) {

Review Comment:
   suggestion from IDEA :thinking: 
   ```suggestion
       CatalogApplyResult(BitSet appliedResults, int catalogVersion, long 
catalogTime) {
   ```



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogApplyResult.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.catalog;
+
+
+import java.util.BitSet;
+
+/** Represent result of applying Catalog command. */
+public class CatalogApplyResult {
+    private final int catalogVersion;
+    private final long catalogTime;
+    private final BitSet applied;
+
+    /**
+     * Creates an result with a bitset of applied results and version of a 
catalog when the changes was visible.
+     *
+     * @param appliedResults Result of applying of commands. Every 1 bit say 
about applied result, otherwise 0 says that command has
+     *      not been applied. Order of bits the same as commands given for 
execution to Catalog.
+     * @param catalogVersion Version of a catalog when the changes was visible.
+     */
+    public CatalogApplyResult(BitSet appliedResults, int catalogVersion, long 
catalogTime) {
+        assert appliedResults != null;
+
+        this.applied = appliedResults;
+        this.catalogVersion = catalogVersion;
+        this.catalogTime = catalogTime;
+    }
+
+    /** Returns catalog version since applied result is available. */
+    public int getCatalogVersion() {
+        return catalogVersion;
+    }
+
+    /** Returns catalog time since applied result is available. */
+    public long getCatalogTime() {
+

Review Comment:
   ```suggestion
   ```
   extra line



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogApplyResult.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.catalog;
+
+
+import java.util.BitSet;
+
+/** Represent result of applying Catalog command. */
+public class CatalogApplyResult {
+    private final int catalogVersion;
+    private final long catalogTime;
+    private final BitSet applied;
+
+    /**
+     * Creates an result with a bitset of applied results and version of a 
catalog when the changes was visible.

Review Comment:
   ```suggestion
        * Creates a result with a bitset of applied results and version of a 
catalog when the changes was visible.
   ```



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogManagerImpl.java:
##########
@@ -395,17 +397,32 @@ private CompletableFuture<Integer> 
saveUpdate(UpdateProducer updateProducer, int
 
             Catalog catalog = catalogByVer.lastEntry().getValue();
 
-            List<UpdateEntry> updates;
+            BitSet applyResults = new BitSet(batchUpdateProducers.size());
+            List<UpdateEntry> bulkUpdateEntries = new ArrayList<>();
             try {
-                updates = updateProducer.get(new UpdateContext(catalog));
+                UpdateContext updateContext = new UpdateContext(catalog);
+                for (int i = 0; i < batchUpdateProducers.size(); i++) {
+                    UpdateProducer update = batchUpdateProducers.get(i);
+                    List<UpdateEntry> entries = update.get(updateContext);
+
+                    for (UpdateEntry entry : entries) {
+                        updateContext.updateCatalog(cat -> 
entry.applyUpdate(cat, INITIAL_CAUSALITY_TOKEN));
+                    }
+
+                    if (!entries.isEmpty()) {
+                        applyResults.set(i);
+                        bulkUpdateEntries.addAll(entries);
+                    }
+                }
             } catch (CatalogValidationException ex) {
                 return failedFuture(new 
CatalogVersionAwareValidationException(ex, catalog.version()));
             } catch (Exception ex) {
                 return failedFuture(ex);
             }
 
-            if (updates.isEmpty()) {
-                return completedFuture(catalog.version());
+            // all results are empty.
+            if (applyResults.cardinality() == 0) {

Review Comment:
   ```suggestion
               if (bulkUpdateEntries.isEmpty()) {
   ```



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogManagerImpl.java:
##########
@@ -376,14 +377,15 @@ private HybridTimestamp 
calcClusterWideEnsureActivationTime(Catalog catalog) {
     }
 
     /**
-     * Attempts to save a versioned update using a CAS-like logic. If the 
attempt fails, makes more attempts
-     * until the max retry count is reached.
+     * Attempts to save a versioned update using a CAS-like logic. If the 
attempt fails, makes more attempts until the max retry count is
+     * reached.
      *
      * @param updateProducer Supplies simple updates to include into a 
versioned update to install.
      * @param attemptNo Ordinal number of an attempt.
-     * @return Future that completes with the new Catalog version (if update 
was saved successfully) or an exception, otherwise.
+     * @return Future that completes with the result of applying updates, 
contains the Catalog version when the updates are visible or an
+     *         exception in case of any error.
      */
-    private CompletableFuture<Integer> saveUpdate(UpdateProducer 
updateProducer, int attemptNo) {
+    private CompletableFuture<CatalogApplyResult> 
saveUpdate(List<UpdateProducer> batchUpdateProducers, int attemptNo) {

Review Comment:
   Javadoc parameter `updateProducer` should also be renamed.
   
   p.s. personally I would just leave it as `updateProducers`  :thinking: 
   



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogApplyResult.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.catalog;
+
+
+import java.util.BitSet;
+
+/** Represent result of applying Catalog command. */
+public class CatalogApplyResult {
+    private final int catalogVersion;
+    private final long catalogTime;
+    private final BitSet applied;
+
+    /**
+     * Creates an result with a bitset of applied results and version of a 
catalog when the changes was visible.
+     *
+     * @param appliedResults Result of applying of commands. Every 1 bit say 
about applied result, otherwise 0 says that command has
+     *      not been applied. Order of bits the same as commands given for 
execution to Catalog.
+     * @param catalogVersion Version of a catalog when the changes was visible.
+     */
+    public CatalogApplyResult(BitSet appliedResults, int catalogVersion, long 
catalogTime) {
+        assert appliedResults != null;
+
+        this.applied = appliedResults;
+        this.catalogVersion = catalogVersion;
+        this.catalogTime = catalogTime;
+    }
+
+    /** Returns catalog version since applied result is available. */
+    public int getCatalogVersion() {
+        return catalogVersion;
+    }
+
+    /** Returns catalog time since applied result is available. */
+    public long getCatalogTime() {
+
+        return catalogTime;
+    }
+
+    /**
+     * Returns has been applied command by given index or not.
+     *
+     * @param idx Index of command in the result.
+     * @return By given index return {@code true} if command has been 
successfully applied or {@code false} otherwise.

Review Comment:
   ```suggestion
        * @return  {@code True} if command has been successfully applied or 
{@code false} otherwise.
   ```



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogManagerImpl.java:
##########
@@ -395,17 +397,32 @@ private CompletableFuture<Integer> 
saveUpdate(UpdateProducer updateProducer, int
 
             Catalog catalog = catalogByVer.lastEntry().getValue();
 
-            List<UpdateEntry> updates;
+            BitSet applyResults = new BitSet(batchUpdateProducers.size());
+            List<UpdateEntry> bulkUpdateEntries = new ArrayList<>();
             try {
-                updates = updateProducer.get(new UpdateContext(catalog));
+                UpdateContext updateContext = new UpdateContext(catalog);
+                for (int i = 0; i < batchUpdateProducers.size(); i++) {
+                    UpdateProducer update = batchUpdateProducers.get(i);
+                    List<UpdateEntry> entries = update.get(updateContext);
+
+                    for (UpdateEntry entry : entries) {
+                        updateContext.updateCatalog(cat -> 
entry.applyUpdate(cat, INITIAL_CAUSALITY_TOKEN));
+                    }
+
+                    if (!entries.isEmpty()) {
+                        applyResults.set(i);
+                        bulkUpdateEntries.addAll(entries);
+                    }

Review Comment:
   ```suggestion
                       if (entries.isEmpty()) {
                           continue;
                       }
   
                       for (UpdateEntry entry : entries) {
                           updateContext.updateCatalog(cat -> 
entry.applyUpdate(cat, INITIAL_CAUSALITY_TOKEN));
                       }
   
                       applyResults.set(i);
                       bulkUpdateEntries.addAll(entries);
   ```



-- 
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