You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "tkalkirill (via GitHub)" <gi...@apache.org> on 2023/06/27 08:35:46 UTC

[GitHub] [ignite-3] tkalkirill opened a new pull request, #2261: IGNITE-19851 Add MetaStorage update update listeners and use instead of configuration revision update listeners

tkalkirill opened a new pull request, #2261:
URL: https://github.com/apache/ignite-3/pull/2261

   https://issues.apache.org/jira/browse/IGNITE-19851


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage revision update listeners and use instead of configuration revision update listeners

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1244882338


##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -754,7 +754,30 @@ public CompletableFuture<Ignite> start(Path configPath) {
                                 fut -> new ConfigurationCatchUpListener(cfgStorage, fut, LOG)
                         );
 
-                        return notifyConfigurationListeners()
+                        // Temporary workaround.

Review Comment:
   Sure, why not



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage revision update listeners and use instead of configuration revision update listeners

Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1245012622


##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -987,6 +954,49 @@ public void init(
         cmgMgr.initCluster(metaStorageNodeNames, cmgNodeNames, clusterName, clusterConfiguration);
     }
 
+    /**
+     * Recovers components state on start by invoking configuration listeners ({@link #notifyConfigurationListeners()}
+     * and deploying watches after that.
+     */
+    private CompletableFuture<?> recoverComponentsStateOnStart(ExecutorService startupExecutor) {

Review Comment:
   The parameter could be omitted, the field seems to be accessible here



##########
modules/metastorage-api/src/main/java/org/apache/ignite/internal/metastorage/RevisionUpdateListener.java:
##########
@@ -20,12 +20,15 @@
 import java.util.concurrent.CompletableFuture;
 
 /**
- * The listener which receives and handles the Meta Storage revision update.
+ * The listener which receives and handles the Meta Storage revision update. No listeners for revision {@code N+1} will be invoked until
+ * all listeners for revision {@code N} are completed.
+ * Also, this listeners is only triggered strictly after all {@link WatchListener#onUpdate(WatchEvent)} are executed, but not necessarily
+ * completed, for the specified revision.

Review Comment:
   ```suggestion
    * Also, this listener is only triggered strictly after all {@link WatchListener#onUpdate(WatchEvent)} are invoked (but the returned futures
    *  might not still be completed completed), for the specified revision.
   ```



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage revision update listeners and use instead of configuration revision update listeners

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1244920862


##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItMetaStorageManagerImplTest.java:
##########
@@ -284,4 +286,24 @@ void testMetaStorageStopBeforeRaftServiceStarted() throws Exception {
 
         assertThat(metaStorageManager.metaStorageServiceFuture(), willThrowFast(CancellationException.class));
     }
+
+    @Test
+    void testUpdateRevisionListener() {
+        // I'm using the future because mock+verify doesn't work.

Review Comment:
   It didn't work because the code was wrong, I guess. Verifying with timeout resolved the issue. I already changed the test anyway...



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] tkalkirill commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage update update listeners and use instead of configuration revision update listeners

Posted by "tkalkirill (via GitHub)" <gi...@apache.org>.
tkalkirill commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1243613403


##########
modules/metastorage-api/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java:
##########
@@ -216,4 +216,10 @@ public interface MetaStorageManager extends IgniteComponent {
      * @return Cluster time.
      */
     ClusterTime clusterTime();
+
+    /** Registers a Meta Storage revision update listener. */
+    void registerUpdateRevisionListener(UpdateRevisionListener listener);

Review Comment:
   fix it



##########
modules/metastorage-api/src/main/java/org/apache/ignite/internal/metastorage/UpdateRevisionListener.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.metastorage;
+
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * The listener which receives and handles the Meta Storage revision update.
+ */
+@FunctionalInterface
+public interface UpdateRevisionListener {

Review Comment:
   fix it



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov merged pull request #2261: IGNITE-19851 Add MetaStorage revision update listeners and use instead of configuration revision update listeners

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov merged PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage revision update listeners and use instead of configuration revision update listeners

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1244884100


##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/WatchProcessor.java:
##########
@@ -158,7 +158,7 @@ private static CompletableFuture<Void> notifyWatches(List<WatchAndEvents> watchA
 
             try {
                 notifyWatchFuture = watchAndEvents.events.isEmpty()
-                        ? watchAndEvents.watch.onRevisionUpdated(revision)
+                        ? completedFuture(null)

Review Comment:
   In reality, no one should use it after this commit, but we leave the code to get rid of it later, in a separate issue



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] tkalkirill commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage update update listeners and use instead of configuration revision update listeners

Posted by "tkalkirill (via GitHub)" <gi...@apache.org>.
tkalkirill commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1243613669


##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/MetaStorageManagerImpl.java:
##########
@@ -671,7 +677,9 @@ private CompletableFuture<Void> onRevisionApplied(WatchEvent watchEvent, HybridT
                 saveToVaultFuture = vaultMgr.putAll(batch);
             }
 
-            return saveToVaultFuture.thenRun(() -> appliedRevision = watchEvent.revision());
+            return saveToVaultFuture
+                    .thenRun(() -> appliedRevision = watchEvent.revision())
+                    .thenCompose(unused -> notifyUpdateRevisionListeners(watchEvent.revision()));

Review Comment:
   fix it



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage update update listeners and use instead of configuration revision update listeners

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1243365841


##########
modules/metastorage-api/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java:
##########
@@ -216,4 +216,10 @@ public interface MetaStorageManager extends IgniteComponent {
      * @return Cluster time.
      */
     ClusterTime clusterTime();
+
+    /** Registers a Meta Storage revision update listener. */
+    void registerUpdateRevisionListener(UpdateRevisionListener listener);

Review Comment:
   "revision update", not "update revision"



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/MetaStorageManagerImpl.java:
##########
@@ -671,7 +677,9 @@ private CompletableFuture<Void> onRevisionApplied(WatchEvent watchEvent, HybridT
                 saveToVaultFuture = vaultMgr.putAll(batch);
             }
 
-            return saveToVaultFuture.thenRun(() -> appliedRevision = watchEvent.revision());
+            return saveToVaultFuture
+                    .thenRun(() -> appliedRevision = watchEvent.revision())
+                    .thenCompose(unused -> notifyUpdateRevisionListeners(watchEvent.revision()));

Review Comment:
   It's a wrong place, meta-storage is completely broken now



##########
modules/metastorage-api/src/main/java/org/apache/ignite/internal/metastorage/UpdateRevisionListener.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.metastorage;
+
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * The listener which receives and handles the Meta Storage revision update.
+ */
+@FunctionalInterface
+public interface UpdateRevisionListener {

Review Comment:
   I suggest renaming this interface as well



##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -454,7 +454,7 @@ public class IgniteImpl implements Ignite {
         );
 
         Consumer<LongFunction<CompletableFuture<?>>> registry =
-                c -> clusterConfigRegistry.listenUpdateStorageRevision(c::apply);
+                c -> metaStorageMgr.registerUpdateRevisionListener(revision -> (CompletableFuture<Void>) c.apply(revision));

Review Comment:
   Why "c::apply" stopped working? Maybe `onUpdate` should return `CompletableFuture<?>`? Would be convenient I guess



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] tkalkirill commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage update update listeners and use instead of configuration revision update listeners

Posted by "tkalkirill (via GitHub)" <gi...@apache.org>.
tkalkirill commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1243614330


##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -454,7 +454,7 @@ public class IgniteImpl implements Ignite {
         );
 
         Consumer<LongFunction<CompletableFuture<?>>> registry =
-                c -> clusterConfigRegistry.listenUpdateStorageRevision(c::apply);
+                c -> metaStorageMgr.registerUpdateRevisionListener(revision -> (CompletableFuture<Void>) c.apply(revision));

Review Comment:
   It is necessary then to do refactoring, I propose to do it in a separate ticket.



##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -454,7 +454,7 @@ public class IgniteImpl implements Ignite {
         );
 
         Consumer<LongFunction<CompletableFuture<?>>> registry =
-                c -> clusterConfigRegistry.listenUpdateStorageRevision(c::apply);
+                c -> metaStorageMgr.registerUpdateRevisionListener(revision -> (CompletableFuture<Void>) c.apply(revision));

Review Comment:
   It is necessary then to do refactoring шт vv, I propose to do it in a separate ticket.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage revision update listeners and use instead of configuration revision update listeners

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1244848815


##########
modules/metastorage-api/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java:
##########
@@ -222,4 +222,13 @@ public interface MetaStorageManager extends IgniteComponent {
      * The value of the future is the revision which must be used for state recovery by other components.
      */
     CompletableFuture<Long> recoveryFinishedFuture();
+
+    /** Registers a Meta Storage revision update listener. */
+    void registerRevisionUpdateListener(RevisionUpdateListener listener);
+
+    /** Unregisters a Meta Storage revision update listener. */
+    void unregisterRevisionUpdateListener(RevisionUpdateListener listener);
+
+    /** Explicitly notifies revision update listeners. */
+    CompletableFuture<Void> notifyRevisionUpdateListenerOnStart(long newRevision);

Review Comment:
   No, we can hide it, I agree



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage revision update listeners and use instead of configuration revision update listeners

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1244852795


##########
modules/metastorage-api/src/main/java/org/apache/ignite/internal/metastorage/RevisionUpdateListener.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.metastorage;
+
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * The listener which receives and handles the Meta Storage revision update.

Review Comment:
   Ok, I'll expand the documentation



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage revision update listeners and use instead of configuration revision update listeners

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1244882963


##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/WatchProcessor.java:
##########
@@ -128,75 +131,94 @@ public void notifyWatches(List<Entry> updatedEntries, HybridTimestamp time) {
                     // Revision must be the same for all entries.
                     long newRevision = updatedEntries.get(0).revision();
 
-                    // Notify all watches in parallel, then aggregate the entries that they have processed.
-                    CompletableFuture<List<EntryEvent>>[] notificationFutures = watches.stream()
-                            .map(watch -> notifyWatch(watch, updatedEntries, newRevision, time))
-                            .toArray(CompletableFuture[]::new);
+                    // Collect all the events for each watch.
+                    CompletableFuture<List<WatchAndEvents>> watchAndEventsFuture = collectWatchAndEvents(updatedEntries, newRevision);
 
-                    return allOf(notificationFutures)
-                            .thenComposeAsync(ignored -> invokeOnRevisionCallback(notificationFutures, newRevision, time), watchExecutor);
+                    return watchAndEventsFuture
+                            .thenComposeAsync(watchAndEvents -> allOf(
+                                    notifyWatches(watchAndEvents, newRevision, time),
+                                    notifyUpdateRevisionListeners(newRevision)
+                            ), watchExecutor)
+                            .thenComposeAsync(ignored -> invokeOnRevisionCallback(watchAndEventsFuture, newRevision, time), watchExecutor);
                 }, watchExecutor);
     }
 
-    private CompletableFuture<List<EntryEvent>> notifyWatch(Watch watch, List<Entry> updatedEntries, long revision, HybridTimestamp time) {
-        CompletableFuture<List<EntryEvent>> eventFuture = supplyAsync(() -> {
-            List<EntryEvent> entryEvents = List.of();
 
-            for (Entry newEntry : updatedEntries) {
-                byte[] newKey = newEntry.key();
+    private static CompletableFuture<Void> notifyWatches(List<WatchAndEvents> watchAndEventsList, long revision, HybridTimestamp time) {
+        if (watchAndEventsList.isEmpty()) {
+            return completedFuture(null);
+        }
 
-                assert newEntry.revision() == revision;
+        CompletableFuture<?>[] notifyWatchFutures = new CompletableFuture[watchAndEventsList.size()];
 
-                if (watch.matches(newKey, revision)) {
-                    Entry oldEntry = entryReader.get(newKey, revision - 1);
+        int i = 0;
 
-                    if (entryEvents.isEmpty()) {
-                        entryEvents = new ArrayList<>();
-                    }
+        for (WatchAndEvents watchAndEvents : watchAndEventsList) {
+            CompletableFuture<Void> notifyWatchFuture;
 
-                    entryEvents.add(new EntryEvent(oldEntry, newEntry));
-                }
+            try {
+                notifyWatchFuture = watchAndEvents.events.isEmpty()
+                        ? watchAndEvents.watch.onRevisionUpdated(revision)
+                        : watchAndEvents.watch.onUpdate(new WatchEvent(watchAndEvents.events, revision, time));

Review Comment:
   Yes, this is the contract



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage revision update listeners and use instead of configuration revision update listeners

Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1244805715


##########
modules/configuration/src/main/java/org/apache/ignite/internal/configuration/notifications/ConfigurationStorageRevisionListener.java:
##########
@@ -24,6 +24,7 @@
  *
  * <p>Storage revision - monotonously increasing counter, linked to the specific storage for current configuration values.
  */
+// TODO: IGNITE-19801 Get rid of

Review Comment:
   ```suggestion
   // TODO: IGNITE-19801 Get rid of this interface
   ```



##########
modules/metastorage-api/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java:
##########
@@ -222,4 +222,13 @@ public interface MetaStorageManager extends IgniteComponent {
      * The value of the future is the revision which must be used for state recovery by other components.
      */
     CompletableFuture<Long> recoveryFinishedFuture();
+
+    /** Registers a Meta Storage revision update listener. */
+    void registerRevisionUpdateListener(RevisionUpdateListener listener);
+
+    /** Unregisters a Meta Storage revision update listener. */
+    void unregisterRevisionUpdateListener(RevisionUpdateListener listener);
+
+    /** Explicitly notifies revision update listeners. */
+    CompletableFuture<Void> notifyRevisionUpdateListenerOnStart(long newRevision);

Review Comment:
   Is this method needed on the 'public' interface? Would it be enough to have it on the main implementation?



##########
modules/metastorage-api/src/main/java/org/apache/ignite/internal/metastorage/WatchListener.java:
##########
@@ -37,6 +37,7 @@ public interface WatchListener {
      * @param revision Meta Storage revision.
      * @return Future that will be completed when the event is processed.
      */
+    // TODO: IGNITE-19801 Get rid of

Review Comment:
   ```suggestion
       // TODO: IGNITE-19801 Get rid of this method
   ```



##########
modules/metastorage-api/src/main/java/org/apache/ignite/internal/metastorage/RevisionUpdateListener.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.metastorage;
+
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * The listener which receives and handles the Meta Storage revision update.

Review Comment:
   Are there any guarantees that no listener will be notified about revision N+1 before all listeners have finished processing a notification about revision N? I think it makes sense to document it somewhere, maybe here.



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/WatchProcessor.java:
##########
@@ -128,75 +131,94 @@ public void notifyWatches(List<Entry> updatedEntries, HybridTimestamp time) {
                     // Revision must be the same for all entries.
                     long newRevision = updatedEntries.get(0).revision();
 
-                    // Notify all watches in parallel, then aggregate the entries that they have processed.
-                    CompletableFuture<List<EntryEvent>>[] notificationFutures = watches.stream()
-                            .map(watch -> notifyWatch(watch, updatedEntries, newRevision, time))
-                            .toArray(CompletableFuture[]::new);
+                    // Collect all the events for each watch.
+                    CompletableFuture<List<WatchAndEvents>> watchAndEventsFuture = collectWatchAndEvents(updatedEntries, newRevision);
 
-                    return allOf(notificationFutures)
-                            .thenComposeAsync(ignored -> invokeOnRevisionCallback(notificationFutures, newRevision, time), watchExecutor);
+                    return watchAndEventsFuture
+                            .thenComposeAsync(watchAndEvents -> allOf(
+                                    notifyWatches(watchAndEvents, newRevision, time),
+                                    notifyUpdateRevisionListeners(newRevision)

Review Comment:
   So both types of notifications are run in parallel. Is this ok? I would expect the revision update listeners to be notified after all watches have been notified.



##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -754,7 +754,30 @@ public CompletableFuture<Ignite> start(Path configPath) {
                                 fut -> new ConfigurationCatchUpListener(cfgStorage, fut, LOG)
                         );
 
-                        return notifyConfigurationListeners()
+                        // Temporary workaround.
+                        // In order to avoid making a public getter for configuration revision, I read it from the startup notification.
+                        // It should be removed once we start using up-to-date meta-storage revision for node startup.

Review Comment:
   Let's add a TODO



##########
modules/configuration/src/testFixtures/java/org/apache/ignite/internal/configuration/testframework/InjectRevisionListenerHolder.java:
##########
@@ -30,5 +30,6 @@
  */
 @Retention(RetentionPolicy.RUNTIME)
 @Target({ElementType.FIELD, ElementType.PARAMETER})
+// TODO: IGNITE-19853 Get rid of

Review Comment:
   ```suggestion
   // TODO: IGNITE-19853 Get rid of this annotation
   ```



##########
modules/metastorage-api/src/main/java/org/apache/ignite/internal/metastorage/RevisionUpdateListener.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.metastorage;
+
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * The listener which receives and handles the Meta Storage revision update.
+ */
+@FunctionalInterface
+public interface RevisionUpdateListener {
+    /**
+     * Callback that will be invoked if a Meta Storage revision update has been received.

Review Comment:
   ```suggestion
        * Callback that will be invoked when a Meta Storage revision update has been received.
   ```



##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItMetaStorageManagerImplTest.java:
##########
@@ -284,4 +286,24 @@ void testMetaStorageStopBeforeRaftServiceStarted() throws Exception {
 
         assertThat(metaStorageManager.metaStorageServiceFuture(), willThrowFast(CancellationException.class));
     }
+
+    @Test
+    void testUpdateRevisionListener() {
+        // I'm using the future because mock+verify doesn't work.

Review Comment:
   I'm curious, what does not work here?



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/WatchProcessor.java:
##########
@@ -128,75 +131,94 @@ public void notifyWatches(List<Entry> updatedEntries, HybridTimestamp time) {
                     // Revision must be the same for all entries.
                     long newRevision = updatedEntries.get(0).revision();
 
-                    // Notify all watches in parallel, then aggregate the entries that they have processed.
-                    CompletableFuture<List<EntryEvent>>[] notificationFutures = watches.stream()
-                            .map(watch -> notifyWatch(watch, updatedEntries, newRevision, time))
-                            .toArray(CompletableFuture[]::new);
+                    // Collect all the events for each watch.
+                    CompletableFuture<List<WatchAndEvents>> watchAndEventsFuture = collectWatchAndEvents(updatedEntries, newRevision);

Review Comment:
   ```suggestion
                       CompletableFuture<List<WatchAndEvents>> watchesAndEventsFuture = collectWatchAndEvents(updatedEntries, newRevision);
   ```



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/WatchProcessor.java:
##########
@@ -128,75 +131,94 @@ public void notifyWatches(List<Entry> updatedEntries, HybridTimestamp time) {
                     // Revision must be the same for all entries.
                     long newRevision = updatedEntries.get(0).revision();
 
-                    // Notify all watches in parallel, then aggregate the entries that they have processed.
-                    CompletableFuture<List<EntryEvent>>[] notificationFutures = watches.stream()
-                            .map(watch -> notifyWatch(watch, updatedEntries, newRevision, time))
-                            .toArray(CompletableFuture[]::new);
+                    // Collect all the events for each watch.
+                    CompletableFuture<List<WatchAndEvents>> watchAndEventsFuture = collectWatchAndEvents(updatedEntries, newRevision);
 
-                    return allOf(notificationFutures)
-                            .thenComposeAsync(ignored -> invokeOnRevisionCallback(notificationFutures, newRevision, time), watchExecutor);
+                    return watchAndEventsFuture
+                            .thenComposeAsync(watchAndEvents -> allOf(
+                                    notifyWatches(watchAndEvents, newRevision, time),
+                                    notifyUpdateRevisionListeners(newRevision)
+                            ), watchExecutor)
+                            .thenComposeAsync(ignored -> invokeOnRevisionCallback(watchAndEventsFuture, newRevision, time), watchExecutor);
                 }, watchExecutor);
     }
 
-    private CompletableFuture<List<EntryEvent>> notifyWatch(Watch watch, List<Entry> updatedEntries, long revision, HybridTimestamp time) {
-        CompletableFuture<List<EntryEvent>> eventFuture = supplyAsync(() -> {
-            List<EntryEvent> entryEvents = List.of();
 
-            for (Entry newEntry : updatedEntries) {
-                byte[] newKey = newEntry.key();
+    private static CompletableFuture<Void> notifyWatches(List<WatchAndEvents> watchAndEventsList, long revision, HybridTimestamp time) {
+        if (watchAndEventsList.isEmpty()) {
+            return completedFuture(null);
+        }
 
-                assert newEntry.revision() == revision;
+        CompletableFuture<?>[] notifyWatchFutures = new CompletableFuture[watchAndEventsList.size()];
 
-                if (watch.matches(newKey, revision)) {
-                    Entry oldEntry = entryReader.get(newKey, revision - 1);
+        int i = 0;
 
-                    if (entryEvents.isEmpty()) {
-                        entryEvents = new ArrayList<>();
-                    }
+        for (WatchAndEvents watchAndEvents : watchAndEventsList) {
+            CompletableFuture<Void> notifyWatchFuture;
 
-                    entryEvents.add(new EntryEvent(oldEntry, newEntry));
-                }
+            try {
+                notifyWatchFuture = watchAndEvents.events.isEmpty()
+                        ? watchAndEvents.watch.onRevisionUpdated(revision)
+                        : watchAndEvents.watch.onUpdate(new WatchEvent(watchAndEvents.events, revision, time));
+            } catch (Throwable throwable) {
+                watchAndEvents.watch.onError(throwable);
+
+                notifyWatchFuture = failedFuture(throwable);
             }
 
-            return entryEvents;
-        }, watchExecutor);
+            notifyWatchFutures[i++] = notifyWatchFuture;
+        }
 
-        return eventFuture
-                .thenCompose(entryEvents -> {
-                    CompletableFuture<Void> eventNotificationFuture = entryEvents.isEmpty()
-                            ? watch.onRevisionUpdated(revision)
-                            : watch.onUpdate(new WatchEvent(entryEvents, revision, time));
-
-                    return eventNotificationFuture.thenApply(v -> entryEvents);
-                })
-                .whenComplete((v, e) -> {
-                    if (e != null) {
-                        if (e instanceof CompletionException) {
-                            e = e.getCause();
-                        }
+        return allOf(notifyWatchFutures);
+    }
 
-                        // TODO: IGNITE-14693 Implement Meta storage exception handling logic.
-                        LOG.error("Error occurred when processing a watch event", e);
+    private CompletableFuture<List<WatchAndEvents>> collectWatchAndEvents(List<Entry> updatedEntries, long revision) {

Review Comment:
   ```suggestion
       private CompletableFuture<List<WatchAndEvents>> collectWatchesAndEvents(List<Entry> updatedEntries, long revision) {
   ```



##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -754,7 +754,30 @@ public CompletableFuture<Ignite> start(Path configPath) {
                                 fut -> new ConfigurationCatchUpListener(cfgStorage, fut, LOG)
                         );
 
-                        return notifyConfigurationListeners()
+                        // Temporary workaround.

Review Comment:
   How about trying to extract this (maybe the whole 'recovery' block) to a method? It's ugly to have such long methods as this `start()`, it's really difficult to navigate. The workaround could (if possible) be extracted too, to improve readability.



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/WatchProcessor.java:
##########
@@ -128,75 +131,94 @@ public void notifyWatches(List<Entry> updatedEntries, HybridTimestamp time) {
                     // Revision must be the same for all entries.
                     long newRevision = updatedEntries.get(0).revision();
 
-                    // Notify all watches in parallel, then aggregate the entries that they have processed.
-                    CompletableFuture<List<EntryEvent>>[] notificationFutures = watches.stream()
-                            .map(watch -> notifyWatch(watch, updatedEntries, newRevision, time))
-                            .toArray(CompletableFuture[]::new);
+                    // Collect all the events for each watch.
+                    CompletableFuture<List<WatchAndEvents>> watchAndEventsFuture = collectWatchAndEvents(updatedEntries, newRevision);
 
-                    return allOf(notificationFutures)
-                            .thenComposeAsync(ignored -> invokeOnRevisionCallback(notificationFutures, newRevision, time), watchExecutor);
+                    return watchAndEventsFuture
+                            .thenComposeAsync(watchAndEvents -> allOf(
+                                    notifyWatches(watchAndEvents, newRevision, time),
+                                    notifyUpdateRevisionListeners(newRevision)
+                            ), watchExecutor)
+                            .thenComposeAsync(ignored -> invokeOnRevisionCallback(watchAndEventsFuture, newRevision, time), watchExecutor);
                 }, watchExecutor);
     }
 
-    private CompletableFuture<List<EntryEvent>> notifyWatch(Watch watch, List<Entry> updatedEntries, long revision, HybridTimestamp time) {
-        CompletableFuture<List<EntryEvent>> eventFuture = supplyAsync(() -> {
-            List<EntryEvent> entryEvents = List.of();
 
-            for (Entry newEntry : updatedEntries) {
-                byte[] newKey = newEntry.key();
+    private static CompletableFuture<Void> notifyWatches(List<WatchAndEvents> watchAndEventsList, long revision, HybridTimestamp time) {
+        if (watchAndEventsList.isEmpty()) {
+            return completedFuture(null);
+        }
 
-                assert newEntry.revision() == revision;
+        CompletableFuture<?>[] notifyWatchFutures = new CompletableFuture[watchAndEventsList.size()];
 
-                if (watch.matches(newKey, revision)) {
-                    Entry oldEntry = entryReader.get(newKey, revision - 1);
+        int i = 0;
 
-                    if (entryEvents.isEmpty()) {
-                        entryEvents = new ArrayList<>();
-                    }
+        for (WatchAndEvents watchAndEvents : watchAndEventsList) {
+            CompletableFuture<Void> notifyWatchFuture;
 
-                    entryEvents.add(new EntryEvent(oldEntry, newEntry));
-                }
+            try {
+                notifyWatchFuture = watchAndEvents.events.isEmpty()
+                        ? watchAndEvents.watch.onRevisionUpdated(revision)
+                        : watchAndEvents.watch.onUpdate(new WatchEvent(watchAndEvents.events, revision, time));

Review Comment:
   Is it ok that we invoke the listener if there are events, and 'revision updated' callback when there are no events? If this the contract?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage revision update listeners and use instead of configuration revision update listeners

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1244856173


##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItMetaStorageManagerImplTest.java:
##########
@@ -284,4 +286,24 @@ void testMetaStorageStopBeforeRaftServiceStarted() throws Exception {
 
         assertThat(metaStorageManager.metaStorageServiceFuture(), willThrowFast(CancellationException.class));
     }
+
+    @Test
+    void testUpdateRevisionListener() {
+        // I'm using the future because mock+verify doesn't work.

Review Comment:
   I don't know, this is Kirill's code. I'll check what can be done here



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] tkalkirill commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage update update listeners and use instead of configuration revision update listeners

Posted by "tkalkirill (via GitHub)" <gi...@apache.org>.
tkalkirill commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1243614330


##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -454,7 +454,7 @@ public class IgniteImpl implements Ignite {
         );
 
         Consumer<LongFunction<CompletableFuture<?>>> registry =
-                c -> clusterConfigRegistry.listenUpdateStorageRevision(c::apply);
+                c -> metaStorageMgr.registerUpdateRevisionListener(revision -> (CompletableFuture<Void>) c.apply(revision));

Review Comment:
   It is necessary then to do refactoring vv, I propose to do it in a separate ticket.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage revision update listeners and use instead of configuration revision update listeners

Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1244842192


##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/WatchProcessor.java:
##########
@@ -158,7 +158,7 @@ private static CompletableFuture<Void> notifyWatches(List<WatchAndEvents> watchA
 
             try {
                 notifyWatchFuture = watchAndEvents.events.isEmpty()
-                        ? watchAndEvents.watch.onRevisionUpdated(revision)
+                        ? completedFuture(null)

Review Comment:
   Why isn't `onRevisionUpdated() invoked anymore?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage revision update listeners and use instead of configuration revision update listeners

Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1244868161


##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItMetaStorageManagerImplTest.java:
##########
@@ -284,4 +286,24 @@ void testMetaStorageStopBeforeRaftServiceStarted() throws Exception {
 
         assertThat(metaStorageManager.metaStorageServiceFuture(), willThrowFast(CancellationException.class));
     }
+
+    @Test
+    void testUpdateRevisionListener() {
+        // I'm using the future because mock+verify doesn't work.

Review Comment:
   Actually, the code looks fine, just the comment caused some confusion :)



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage revision update listeners and use instead of configuration revision update listeners

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1245021456


##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -987,6 +954,49 @@ public void init(
         cmgMgr.initCluster(metaStorageNodeNames, cmgNodeNames, clusterName, clusterConfiguration);
     }
 
+    /**
+     * Recovers components state on start by invoking configuration listeners ({@link #notifyConfigurationListeners()}
+     * and deploying watches after that.
+     */
+    private CompletableFuture<?> recoverComponentsStateOnStart(ExecutorService startupExecutor) {

Review Comment:
   It's not a field, it's a local variable in "start" method



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage revision update listeners and use instead of configuration revision update listeners

Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1245023160


##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -987,6 +954,49 @@ public void init(
         cmgMgr.initCluster(metaStorageNodeNames, cmgNodeNames, clusterName, clusterConfiguration);
     }
 
+    /**
+     * Recovers components state on start by invoking configuration listeners ({@link #notifyConfigurationListeners()}
+     * and deploying watches after that.
+     */
+    private CompletableFuture<?> recoverComponentsStateOnStart(ExecutorService startupExecutor) {

Review Comment:
   Oops, indeed



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #2261: IGNITE-19851 Add MetaStorage revision update listeners and use instead of configuration revision update listeners

Posted by "ibessonov (via GitHub)" <gi...@apache.org>.
ibessonov commented on code in PR #2261:
URL: https://github.com/apache/ignite-3/pull/2261#discussion_r1244872366


##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/WatchProcessor.java:
##########
@@ -128,75 +131,94 @@ public void notifyWatches(List<Entry> updatedEntries, HybridTimestamp time) {
                     // Revision must be the same for all entries.
                     long newRevision = updatedEntries.get(0).revision();
 
-                    // Notify all watches in parallel, then aggregate the entries that they have processed.
-                    CompletableFuture<List<EntryEvent>>[] notificationFutures = watches.stream()
-                            .map(watch -> notifyWatch(watch, updatedEntries, newRevision, time))
-                            .toArray(CompletableFuture[]::new);
+                    // Collect all the events for each watch.
+                    CompletableFuture<List<WatchAndEvents>> watchAndEventsFuture = collectWatchAndEvents(updatedEntries, newRevision);
 
-                    return allOf(notificationFutures)
-                            .thenComposeAsync(ignored -> invokeOnRevisionCallback(notificationFutures, newRevision, time), watchExecutor);
+                    return watchAndEventsFuture
+                            .thenComposeAsync(watchAndEvents -> allOf(
+                                    notifyWatches(watchAndEvents, newRevision, time),
+                                    notifyUpdateRevisionListeners(newRevision)

Review Comment:
   I made the same mistake. Let me refactor this code a little bit.
   Methods are called sequentially, but because we see them as arguments of "allOf", we perceive them as being in parallel. At least that was my reaction



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org