tkalkirill commented on code in PR #4663:
URL: https://github.com/apache/ignite-3/pull/4663#discussion_r1827631400


##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/RecoveryRevisionsListenerImpl.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.impl;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.locks.ReentrantLock;
+import org.apache.ignite.internal.lang.NodeStoppingException;
+import org.apache.ignite.internal.metastorage.Revisions;
+import org.apache.ignite.internal.metastorage.server.KeyValueStorage;
+import org.apache.ignite.internal.metastorage.server.RecoveryRevisionsListener;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+
+/** Implementation for {@link MetaStorageManagerImpl}. */
+class RecoveryRevisionsListenerImpl implements RecoveryRevisionsListener {
+    private final IgniteSpinBusyLock busyLock;
+
+    private final CompletableFuture<Revisions> recoveryFinishFuture;
+
+    private final KeyValueStorage storage;
+
+    private final ReentrantLock lock = new ReentrantLock();
+
+    /** Guarded by {@link #lock}. */
+    private Revisions targetRevisions;
+
+    /** Guarded by {@link #lock}. */
+    private Revisions currentRevisions;
+
+    RecoveryRevisionsListenerImpl(
+            IgniteSpinBusyLock busyLock,
+            CompletableFuture<Revisions> recoveryFinishFuture,
+            KeyValueStorage storage
+    ) {
+        this.busyLock = busyLock;
+        this.recoveryFinishFuture = recoveryFinishFuture;
+        this.storage = storage;
+    }
+
+    @Override
+    public void onUpdate(Revisions currentRevisions) {
+        lock.lock();
+
+        try {
+            this.currentRevisions = currentRevisions;
+
+            completeRecoveryFinishFutureIfPossible();
+        } finally {
+            lock.unlock();
+        }
+    }
+
+    void setTargetRevisions(Revisions targetRevisions) {
+        lock.lock();
+
+        try {
+            this.targetRevisions = targetRevisions;
+
+            completeRecoveryFinishFutureIfPossible();
+        } finally {
+            lock.unlock();
+        }
+    }
+
+    private void completeRecoveryFinishFutureIfPossible() {
+        if (!busyLock.enterBusy()) {
+            recoveryFinishFuture.completeExceptionally(new 
NodeStoppingException());
+        }
+
+        try {
+            if (targetRevisions == null
+                    || currentRevisions == null
+                    || currentRevisions.revision() < targetRevisions.revision()
+                    || currentRevisions.compactionRevision() < 
targetRevisions.compactionRevision()) {

Review Comment:
   It can't. Or I didn't understand the question.



-- 
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-unsubscr...@ignite.apache.org

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

Reply via email to