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 2024/10/31 11:28:05 UTC

[PR] IGNITE-23292 Local startup of metastorage compaction on node startup after recovery [ignite-3]

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

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


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


Re: [PR] IGNITE-23292 Local startup of metastorage compaction on node startup after recovery [ignite-3]

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


##########
modules/metastorage-api/src/main/java/org/apache/ignite/internal/metastorage/Revisions.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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 org.apache.ignite.internal.tostring.S;
+
+/** Information about metastorage revisions. */
+public class Revisions {
+    private final long revision;
+
+    private final long compactionRevision;
+
+    /**
+     * Constructor.
+     *
+     * @param revision Metastorage revision.
+     * @param compactionRevision Metastorage compaction revision.
+     */
+    public Revisions(long revision, long compactionRevision) {
+        this.revision = revision;
+        this.compactionRevision = compactionRevision;
+    }
+
+    /** Returns metastorage revision. */
+    public long revision() {
+        return revision;
+    }
+
+    /** Returns metastorage compaction revision. */

Review Comment:
   Please explain what it means: this revision is the largest revision which keys could be removed due to compaction, or it's least revision which is NOT yet affected by compaction?



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/UpdateLogImpl.java:
##########
@@ -237,11 +238,11 @@ public CompletableFuture<Boolean> saveSnapshot(SnapshotEntry update) {
     }
 
     private void recoveryStateFromMetastore(OnUpdateHandler handler) {

Review Comment:
   ```suggestion
       private void recoverStateFromMetastore(OnUpdateHandler handler) {
   ```



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/MetaStorageManagerImpl.java:
##########
@@ -311,75 +316,37 @@ public void addElectionListener(ElectionListener listener) {
         electionListeners.add(listener);
     }
 
-    private CompletableFuture<Long> recover(MetaStorageService service) {
-        if (!busyLock.enterBusy()) {
-            return failedFuture(new NodeStoppingException());
-        }
+    private CompletableFuture<?> updateTargetRevisionsForRecovery(MetaStorageService service) {
+        return inBusyLockAsync(busyLock, () -> {
+            service.currentRevisions()
+                    .thenAccept(targetRevisions -> {
+                        assert targetRevisions != null;
 
-        try {
-            service.currentRevision().whenComplete((targetRevision, throwable) -> {
-                if (throwable != null) {
-                    recoveryFinishedFuture.completeExceptionally(throwable);
+                        LOG.info("Performing MetaStorage recovery: [from={}, to={}]", storage.revisions(), targetRevisions);
 
-                    return;
-                }
+                        recoveryRevisionsListener.setTargetRevisions(targetRevisions.toRevisions());
+                    }).whenComplete((res, throwable) -> {
+                        if (throwable != null) {
+                            recoveryFinishedFuture.completeExceptionally(throwable);
+                        }
+                    });
 
-                LOG.info("Performing MetaStorage recovery from revision {} to {}", storage.revision(), targetRevision);
+            return recoveryFinishedFuture.whenComplete((revisions, throwable) -> {
+                if (throwable != null) {
+                    LOG.info("Recovery failed", throwable);
+                } else {
+                    long recoveryRevision = revisions.revision();
 
-                assert targetRevision != null;
+                    appliedRevision = recoveryRevision;
 
-                listenForRecovery(targetRevision);
-            }).whenComplete((res, ex) -> {
-                if (ex != null) {
-                    LOG.info("Recovery failed", ex);
+                    if (recoveryRevision > 0) {
+                        clusterTime.updateSafeTime(storage.timestampByRevision(recoveryRevision));
+                    }
 
-                    recoveryFinishedFuture.completeExceptionally(ex);
+                    LOG.info("Finished MetaStorage recovery");

Review Comment:
   Please add a try/catch around this block; otherwise, if something is thrown from it, we'll never know it, just the future will never be completed, and it will be difficult to see what happened



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/MetaStorageManagerImpl.java:
##########
@@ -311,75 +316,37 @@ public void addElectionListener(ElectionListener listener) {
         electionListeners.add(listener);
     }
 
-    private CompletableFuture<Long> recover(MetaStorageService service) {
-        if (!busyLock.enterBusy()) {
-            return failedFuture(new NodeStoppingException());
-        }
+    private CompletableFuture<?> updateTargetRevisionsForRecovery(MetaStorageService service) {

Review Comment:
   Why was the method renamed?



##########
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}. */

Review Comment:
   What does it mean: implementation for `MetaStorageManagerImpl`? I would understand an 'implementation of <interface>', but it would still be redundant as the code says this thing by itself...



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/AbstractKeyValueStorage.java:
##########
@@ -430,4 +455,50 @@ private List<Entry> doGetAll(List<byte[]> keys, long revUpperBound) {
 
         return res;
     }
+
+    @Override
+    public void advanceSafeTime(KeyValueUpdateContext context) {
+        rwLock.writeLock().lock();
+
+        try {
+            setIndexAndTerm(context.index, context.term);
+
+            if (isWatchesStarted()) {
+                watchProcessor.advanceSafeTime(context.timestamp);
+            }
+        } finally {
+            rwLock.writeLock().unlock();
+        }
+    }
+
+    @Override
+    public Revisions revisions() {
+        rwLock.readLock().lock();
+
+        try {
+            return createCurrentRevisions();
+        } finally {
+            rwLock.readLock().unlock();
+        }
+    }
+
+    private Revisions createCurrentRevisions() {
+        return new Revisions(rev, compactionRevision);
+    }
+
+    protected void addToNotifyWatchProcessorEventsBeforeStartWatches(NotifyWatchProcessorEvent event) {

Review Comment:
   ```suggestion
       protected void addToNotifyWatchProcessorEventsBeforeStartingWatches(NotifyWatchProcessorEvent event) {
   ```



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/AbstractKeyValueStorage.java:
##########
@@ -115,11 +125,20 @@ protected AbstractKeyValueStorage(
     protected abstract Value valueForOperation(byte[] key, long revision);
 
     /**
-     * Returns {@code true} if the storage is in the recovery state.
+     * Returns {@code true} if the metastorage is in the recovery state.
+     *
+     * <p>Method is expected to be invoked under {@link #rwLock}.</p>
+     */
+    private boolean isInRecoveryState() {
+        return recoveryRevisionListener != null;
+    }
+
+    /**
+     * Returns {@code true} if the watches have {@link #startWatches started}.
      *
      * <p>Method is expected to be invoked under {@link #rwLock}.</p>
      */
-    protected abstract boolean isInRecoveryState();
+    protected abstract boolean isWatchesStarted();

Review Comment:
   ```suggestion
       protected abstract boolean areWatchesStarted();
   ```



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/persistence/RocksDbKeyValueStorage.java:
##########
@@ -1090,21 +1097,16 @@ private void queueWatchEvent() {
                 updatedEntries.clear();
 
                 break;
-
             case IN_PROGRESS:
-                // Buffer the event while event replay is still in progress.
-                if (eventCache == null) {
-                    eventCache = new ArrayList<>();
-                }
+                UpdatedEntries copy = updatedEntries.transfer();
 
-                eventCache.add(updatedEntries.transfer());
+                var event = new UpdateEntriesEvent(copy.updatedEntries, copy.ts);
 
-                break;
+                addToNotifyWatchProcessorEventsBeforeStartWatches(event);
 
+                break;
             default:
                 notifyWatches();
-
-                break;

Review Comment:
   It seems consistent to have `break` even in the `default` branch. I would leave it here



##########
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:
   Is there a guarantee that no node can be ahead of the leader by compactionRevision? If yes, how is it established?



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/MetaStorageManagerImpl.java:
##########
@@ -311,75 +316,37 @@ public void addElectionListener(ElectionListener listener) {
         electionListeners.add(listener);
     }
 
-    private CompletableFuture<Long> recover(MetaStorageService service) {
-        if (!busyLock.enterBusy()) {
-            return failedFuture(new NodeStoppingException());
-        }
+    private CompletableFuture<?> updateTargetRevisionsForRecovery(MetaStorageService service) {
+        return inBusyLockAsync(busyLock, () -> {
+            service.currentRevisions()
+                    .thenAccept(targetRevisions -> {
+                        assert targetRevisions != null;
 
-        try {
-            service.currentRevision().whenComplete((targetRevision, throwable) -> {
-                if (throwable != null) {
-                    recoveryFinishedFuture.completeExceptionally(throwable);
+                        LOG.info("Performing MetaStorage recovery: [from={}, to={}]", storage.revisions(), targetRevisions);

Review Comment:
   Do we need information about compaction revisions in the log?



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/AbstractKeyValueStorage.java:
##########
@@ -115,11 +125,20 @@ protected AbstractKeyValueStorage(
     protected abstract Value valueForOperation(byte[] key, long revision);
 
     /**
-     * Returns {@code true} if the storage is in the recovery state.
+     * Returns {@code true} if the metastorage is in the recovery state.
+     *
+     * <p>Method is expected to be invoked under {@link #rwLock}.</p>

Review Comment:
   Should an assertion be added?



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/AbstractKeyValueStorage.java:
##########
@@ -430,4 +455,50 @@ private List<Entry> doGetAll(List<byte[]> keys, long revUpperBound) {
 
         return res;
     }
+
+    @Override
+    public void advanceSafeTime(KeyValueUpdateContext context) {
+        rwLock.writeLock().lock();
+
+        try {
+            setIndexAndTerm(context.index, context.term);
+
+            if (isWatchesStarted()) {
+                watchProcessor.advanceSafeTime(context.timestamp);
+            }
+        } finally {
+            rwLock.writeLock().unlock();
+        }
+    }
+
+    @Override
+    public Revisions revisions() {
+        rwLock.readLock().lock();
+
+        try {
+            return createCurrentRevisions();
+        } finally {
+            rwLock.readLock().unlock();
+        }
+    }
+
+    private Revisions createCurrentRevisions() {
+        return new Revisions(rev, compactionRevision);
+    }
+
+    protected void addToNotifyWatchProcessorEventsBeforeStartWatches(NotifyWatchProcessorEvent event) {
+        assert !isWatchesStarted();
+
+        boolean added = notifyWatchProcessorEventsBeforeStartWatches.add(event);
+
+        assert added : event;
+    }
+
+    protected void drainNotifyWatchProcessorEventsBeforeStartWatches() {

Review Comment:
   ```suggestion
       protected void drainNotifyWatchProcessorEventsBeforeStartingWatches() {
   ```



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/AbstractKeyValueStorage.java:
##########
@@ -88,6 +89,15 @@ public abstract class AbstractKeyValueStorage implements KeyValueStorage {
     /** Tracks only cursors, since reading a single entry or a batch is done entirely under {@link #rwLock}. */
     protected final ReadOperationForCompactionTracker readOperationForCompactionTracker;
 
+    /**
+     * Events for notification of the {@link WatchProcessor} that were created before the {@link #startWatches start of watches}, after the
+     * start of watches there will be {@code null}. Events are sorted by {@link NotifyWatchProcessorEvent#timestamp} and are expected to
+     * have no duplicates.
+     *
+     * <p>Multi-threaded access is guarded by {@link #rwLock}.</p>
+     */
+    protected @Nullable TreeSet<NotifyWatchProcessorEvent> notifyWatchProcessorEventsBeforeStartWatches = new TreeSet<>();

Review Comment:
   ```suggestion
       protected @Nullable TreeSet<NotifyWatchProcessorEvent> notifyWatchProcessorEventsBeforeStartingWatches = new TreeSet<>();
   ```



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


Re: [PR] IGNITE-23292 Local startup of metastorage compaction on node startup after recovery [ignite-3]

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


##########
modules/metastorage-api/src/main/java/org/apache/ignite/internal/metastorage/Revisions.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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 org.apache.ignite.internal.tostring.S;
+
+/** Information about metastorage revisions. */
+public class Revisions {
+    private final long revision;
+
+    private final long compactionRevision;
+
+    /**
+     * Constructor.
+     *
+     * @param revision Metastorage revision.
+     * @param compactionRevision Metastorage compaction revision.
+     */
+    public Revisions(long revision, long compactionRevision) {
+        this.revision = revision;
+        this.compactionRevision = compactionRevision;
+    }
+
+    /** Returns metastorage revision. */
+    public long revision() {
+        return revision;
+    }
+
+    /** Returns metastorage compaction revision. */

Review Comment:
   Yes, thanks



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


Re: [PR] IGNITE-23292 Local startup of metastorage compaction on node startup after recovery [ignite-3]

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


##########
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}. */

Review Comment:
   How do you propose to change 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


Re: [PR] IGNITE-23292 Local startup of metastorage compaction on node startup after recovery [ignite-3]

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


##########
modules/metastorage-api/src/main/java/org/apache/ignite/internal/metastorage/Revisions.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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 org.apache.ignite.internal.tostring.S;
+
+/** Information about metastorage revisions. */
+public class Revisions {
+    private final long revision;
+
+    private final long compactionRevision;
+
+    /**
+     * Constructor.
+     *
+     * @param revision Metastorage revision.
+     * @param compactionRevision Metastorage compaction revision.
+     */
+    public Revisions(long revision, long compactionRevision) {
+        this.revision = revision;
+        this.compactionRevision = compactionRevision;
+    }
+
+    /** Returns metastorage revision. */
+    public long revision() {
+        return revision;
+    }
+
+    /** Returns metastorage compaction revision. */

Review Comment:
   `Returns metastorage compact revision of the up to which (inclusive) key versions will be deleted and when trying to read them, {@link CompactedException} will occur.`
   
   Better?



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


Re: [PR] IGNITE-23292 Local startup of metastorage compaction on node startup after recovery [ignite-3]

Posted by "tkalkirill (via GitHub)" <gi...@apache.org>.
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-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-23292 Local startup of metastorage compaction on node startup after recovery [ignite-3]

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


##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/MetaStorageManagerImpl.java:
##########
@@ -311,75 +316,37 @@ public void addElectionListener(ElectionListener listener) {
         electionListeners.add(listener);
     }
 
-    private CompletableFuture<Long> recover(MetaStorageService service) {
-        if (!busyLock.enterBusy()) {
-            return failedFuture(new NodeStoppingException());
-        }
+    private CompletableFuture<?> updateTargetRevisionsForRecovery(MetaStorageService service) {
+        return inBusyLockAsync(busyLock, () -> {
+            service.currentRevisions()
+                    .thenAccept(targetRevisions -> {
+                        assert targetRevisions != null;
 
-        try {
-            service.currentRevision().whenComplete((targetRevision, throwable) -> {
-                if (throwable != null) {
-                    recoveryFinishedFuture.completeExceptionally(throwable);
+                        LOG.info("Performing MetaStorage recovery: [from={}, to={}]", storage.revisions(), targetRevisions);

Review Comment:
   I think this can be useful to us first of all when there are some problems at the start of the node.



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


Re: [PR] IGNITE-23292 Local startup of metastorage compaction on node startup after recovery [ignite-3]

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


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


Re: [PR] IGNITE-23292 Local startup of metastorage compaction on node startup after recovery [ignite-3]

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


##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/MetaStorageCompactionTrigger.java:
##########
@@ -319,4 +322,33 @@ private void cancelLastScheduledFutureBusy() {
             lock.unlock();
         }
     }
+
+    private void startCompactionOnRecoveryAsync() {
+        assert metaStorageManager.recoveryFinishedFuture().isDone();
+
+        long latestCompactionRevisionLocally = metaStorageManager.getCompactionRevisionLocally();
+
+        if (latestCompactionRevisionLocally != -1) {
+            runAsync(() -> inBusyLockSafe(busyLock, () -> storage.compact(latestCompactionRevisionLocally)), compactionExecutor)

Review Comment:
   There is nothing wrong with changing to a pool with several threads.
   
   The new compaction will first update the compaction revision in memory and then begin its execution. Two compactions will not interfere with each other since they write in batches on which we take a lock for recording.



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


Re: [PR] IGNITE-23292 Local startup of metastorage compaction on node startup after recovery [ignite-3]

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


##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/AbstractKeyValueStorage.java:
##########
@@ -115,11 +125,20 @@ protected AbstractKeyValueStorage(
     protected abstract Value valueForOperation(byte[] key, long revision);
 
     /**
-     * Returns {@code true} if the storage is in the recovery state.
+     * Returns {@code true} if the metastorage is in the recovery state.
+     *
+     * <p>Method is expected to be invoked under {@link #rwLock}.</p>

Review Comment:
   I don't think so.



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


Re: [PR] IGNITE-23292 Local startup of metastorage compaction on node startup after recovery [ignite-3]

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


##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/MetaStorageManagerImpl.java:
##########
@@ -311,75 +316,37 @@ public void addElectionListener(ElectionListener listener) {
         electionListeners.add(listener);
     }
 
-    private CompletableFuture<Long> recover(MetaStorageService service) {
-        if (!busyLock.enterBusy()) {
-            return failedFuture(new NodeStoppingException());
-        }
+    private CompletableFuture<?> updateTargetRevisionsForRecovery(MetaStorageService service) {
+        return inBusyLockAsync(busyLock, () -> {
+            service.currentRevisions()
+                    .thenAccept(targetRevisions -> {
+                        assert targetRevisions != null;
 
-        try {
-            service.currentRevision().whenComplete((targetRevision, throwable) -> {
-                if (throwable != null) {
-                    recoveryFinishedFuture.completeExceptionally(throwable);
+                        LOG.info("Performing MetaStorage recovery: [from={}, to={}]", storage.revisions(), targetRevisions);
 
-                    return;
-                }
+                        recoveryRevisionsListener.setTargetRevisions(targetRevisions.toRevisions());
+                    }).whenComplete((res, throwable) -> {
+                        if (throwable != null) {
+                            recoveryFinishedFuture.completeExceptionally(throwable);
+                        }
+                    });
 
-                LOG.info("Performing MetaStorage recovery from revision {} to {}", storage.revision(), targetRevision);
+            return recoveryFinishedFuture.whenComplete((revisions, throwable) -> {
+                if (throwable != null) {
+                    LOG.info("Recovery failed", throwable);
+                } else {
+                    long recoveryRevision = revisions.revision();
 
-                assert targetRevision != null;
+                    appliedRevision = recoveryRevision;
 
-                listenForRecovery(targetRevision);
-            }).whenComplete((res, ex) -> {
-                if (ex != null) {
-                    LOG.info("Recovery failed", ex);
+                    if (recoveryRevision > 0) {
+                        clusterTime.updateSafeTime(storage.timestampByRevision(recoveryRevision));
+                    }
 
-                    recoveryFinishedFuture.completeExceptionally(ex);
+                    LOG.info("Finished MetaStorage recovery");

Review Comment:
   Fix it a little differently.



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


Re: [PR] IGNITE-23292 Local startup of metastorage compaction on node startup after recovery [ignite-3]

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


##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/MetaStorageCompactionTrigger.java:
##########
@@ -319,4 +322,33 @@ private void cancelLastScheduledFutureBusy() {
             lock.unlock();
         }
     }
+
+    private void startCompactionOnRecoveryAsync() {
+        assert metaStorageManager.recoveryFinishedFuture().isDone();
+
+        long latestCompactionRevisionLocally = metaStorageManager.getCompactionRevisionLocally();
+
+        if (latestCompactionRevisionLocally != -1) {
+            runAsync(() -> inBusyLockSafe(busyLock, () -> storage.compact(latestCompactionRevisionLocally)), compactionExecutor)

Review Comment:
   Is there a guarantee this compaction will be finished before subsequent compactions will be started? If it's because `compactionExecutor` is single-threaded, could you please write a comment about this?



##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/TestMetasStorageUtils.java:
##########
@@ -55,4 +76,50 @@ public static boolean equals(Entry act, Entry exp) {
 
         return Arrays.equals(act.value(), exp.value());
     }
+
+    /** Creates a cluster configuration with metastorage compaction properties. */
+    public static String createClusterConfigWithCompactionProperties(String interval, String dataAvailabilityTime) {

Review Comment:
   Why are parameters of String type and not just ints/longs?



##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/TestMetasStorageUtils.java:
##########
@@ -55,4 +76,50 @@ public static boolean equals(Entry act, Entry exp) {
 
         return Arrays.equals(act.value(), exp.value());
     }
+
+    /** Creates a cluster configuration with metastorage compaction properties. */
+    public static String createClusterConfigWithCompactionProperties(String interval, String dataAvailabilityTime) {
+        return String.format(
+                "ignite.system.properties: {"
+                        + "%s.propertyValue= \"%s\", "
+                        + "%s.propertyValue= \"%s\""
+                        + "}",
+                INTERVAL_SYSTEM_PROPERTY_NAME, interval, DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME, dataAvailabilityTime
+        );
+    }
+
+    /** Returns the latest revision for the key from the leader. */
+    public static long latestKeyRevision(MetaStorageManager metaStorageManager, ByteArray key) {
+        CompletableFuture<Entry> latestEntryFuture = metaStorageManager.get(key);
+        assertThat(latestEntryFuture.thenApply(Entry::empty), willBe(false));
+
+        return latestEntryFuture.join().revision();
+    }
+
+    /** Returns {@code true} if the metastorage key has only one revision in the cluster. */
+    public static boolean allNodesContainsSingleRevisionForKeyLocally(Cluster cluster, ByteArray key, long revision) {

Review Comment:
   ```suggestion
       public static boolean allNodesContainSingleRevisionForKeyLocally(Cluster cluster, ByteArray key, long revision) {
   ```



##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItMetaStorageCompactionTriggerOneNodeTest.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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 static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.BAR_KEY;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.FOO_KEY;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.VALUE;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.allNodesContainsSingleRevisionForKeyLocally;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.createClusterConfigWithCompactionProperties;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.latestKeyRevision;
+import static org.apache.ignite.internal.metastorage.impl.MetaStorageCompactionTriggerConfiguration.DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME;
+import static org.apache.ignite.internal.metastorage.impl.MetaStorageCompactionTriggerConfiguration.INTERVAL_SYSTEM_PROPERTY_NAME;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.configuration.SystemDistributedExtensionConfiguration;
+import org.apache.ignite.internal.distributionzones.rebalance.DistributionZoneRebalanceEngine;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.metastorage.command.CompactionCommand;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.raft.jraft.rpc.WriteActionRequest;
+import org.junit.jupiter.api.Test;
+
+/** For {@link MetaStorageCompactionTrigger} testing for single node case. */
+@WithSystemProperty(key = DistributionZoneRebalanceEngine.SKIP_REBALANCE_TRIGGERS_RECOVERY, value = "true")
+public class ItMetaStorageCompactionTriggerOneNodeTest extends ClusterPerTestIntegrationTest {
+    @Override
+    protected int initialNodes() {
+        return 1;
+    }
+
+    @Override
+    protected void customizeInitParameters(InitParametersBuilder builder) {
+        super.customizeInitParameters(builder);
+
+        builder.clusterConfiguration(createClusterConfigWithCompactionProperties("10", "10"));
+    }
+
+    @Test
+    void testCompactionAfterRestartNode() throws Exception {
+        IgniteImpl node = aliveNode();
+
+        MetaStorageManager metaStorageManager = node.metaStorageManager();
+
+        assertThat(metaStorageManager.put(FOO_KEY, VALUE), willCompleteSuccessfully());
+        assertThat(metaStorageManager.put(BAR_KEY, VALUE), willCompleteSuccessfully());
+
+        // Let's wait until the compaction on revision of FOO_KEY creation happens.
+        long fooRevision = latestKeyRevision(metaStorageManager, FOO_KEY);
+        assertTrue(waitForCondition(() -> metaStorageManager.getCompactionRevisionLocally() >= fooRevision, 10, 1_000));
+
+        log.info("Latest revision for key: [key={}, revision={}]", FOO_KEY, fooRevision);
+
+        // Let's cancel new compactions to create a new version for the key and not compact it until we restart the node.
+        startDropCompactionCommand(node);
+        assertThat(metaStorageManager.put(FOO_KEY, VALUE), willCompleteSuccessfully());
+
+        long latestFooRevision = latestKeyRevision(metaStorageManager, FOO_KEY);
+
+        long latestCompactionRevision = metaStorageManager.getCompactionRevisionLocally();
+        // Let's change the properties before restarting so that a new scheduled compaction does not start after the node starts.
+        changeCompactionProperties(node, Long.toString(Long.MAX_VALUE), Long.toString(Long.MAX_VALUE));
+
+        IgniteImpl restartedNode = restartNode();
+
+        MetaStorageManager restartedMetaStorageManager = restartedNode.metaStorageManager();
+
+        // Let's make sure that after the restart the correct revision of the compression is restored and the compression itself will be at

Review Comment:
   What is 'compression'?



##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItMetaStorageCompactionTriggerOneNodeTest.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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 static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.BAR_KEY;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.FOO_KEY;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.VALUE;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.allNodesContainsSingleRevisionForKeyLocally;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.createClusterConfigWithCompactionProperties;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.latestKeyRevision;
+import static org.apache.ignite.internal.metastorage.impl.MetaStorageCompactionTriggerConfiguration.DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME;
+import static org.apache.ignite.internal.metastorage.impl.MetaStorageCompactionTriggerConfiguration.INTERVAL_SYSTEM_PROPERTY_NAME;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.configuration.SystemDistributedExtensionConfiguration;
+import org.apache.ignite.internal.distributionzones.rebalance.DistributionZoneRebalanceEngine;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.metastorage.command.CompactionCommand;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.raft.jraft.rpc.WriteActionRequest;
+import org.junit.jupiter.api.Test;
+
+/** For {@link MetaStorageCompactionTrigger} testing for single node case. */
+@WithSystemProperty(key = DistributionZoneRebalanceEngine.SKIP_REBALANCE_TRIGGERS_RECOVERY, value = "true")
+public class ItMetaStorageCompactionTriggerOneNodeTest extends ClusterPerTestIntegrationTest {
+    @Override
+    protected int initialNodes() {
+        return 1;
+    }
+
+    @Override
+    protected void customizeInitParameters(InitParametersBuilder builder) {
+        super.customizeInitParameters(builder);
+
+        builder.clusterConfiguration(createClusterConfigWithCompactionProperties("10", "10"));
+    }
+
+    @Test
+    void testCompactionAfterRestartNode() throws Exception {
+        IgniteImpl node = aliveNode();
+
+        MetaStorageManager metaStorageManager = node.metaStorageManager();
+
+        assertThat(metaStorageManager.put(FOO_KEY, VALUE), willCompleteSuccessfully());
+        assertThat(metaStorageManager.put(BAR_KEY, VALUE), willCompleteSuccessfully());
+
+        // Let's wait until the compaction on revision of FOO_KEY creation happens.
+        long fooRevision = latestKeyRevision(metaStorageManager, FOO_KEY);
+        assertTrue(waitForCondition(() -> metaStorageManager.getCompactionRevisionLocally() >= fooRevision, 10, 1_000));
+
+        log.info("Latest revision for key: [key={}, revision={}]", FOO_KEY, fooRevision);
+
+        // Let's cancel new compactions to create a new version for the key and not compact it until we restart the node.
+        startDropCompactionCommand(node);
+        assertThat(metaStorageManager.put(FOO_KEY, VALUE), willCompleteSuccessfully());
+
+        long latestFooRevision = latestKeyRevision(metaStorageManager, FOO_KEY);
+
+        long latestCompactionRevision = metaStorageManager.getCompactionRevisionLocally();
+        // Let's change the properties before restarting so that a new scheduled compaction does not start after the node starts.
+        changeCompactionProperties(node, Long.toString(Long.MAX_VALUE), Long.toString(Long.MAX_VALUE));
+
+        IgniteImpl restartedNode = restartNode();
+
+        MetaStorageManager restartedMetaStorageManager = restartedNode.metaStorageManager();
+
+        // Let's make sure that after the restart the correct revision of the compression is restored and the compression itself will be at
+        // the latest compaction revision.
+        assertEquals(latestCompactionRevision, restartedMetaStorageManager.getCompactionRevisionLocally());
+        assertTrue(waitForCondition(() -> allNodesContainsSingleRevisionForKeyLocally(cluster, FOO_KEY, latestFooRevision), 10, 1_000));
+    }
+
+    private IgniteImpl aliveNode() {
+        return unwrapIgniteImpl(node(0));
+    }
+
+    private IgniteImpl restartNode() {
+        return unwrapIgniteImpl(restartNode(0));
+    }
+
+    private static void startDropCompactionCommand(IgniteImpl node) {
+        node.dropMessages((s, message) -> message instanceof WriteActionRequest
+                && ((WriteActionRequest) message).deserializedCommand() instanceof CompactionCommand);
+    }
+
+    private static void changeCompactionProperties(IgniteImpl node, String interval, String dataAvailabilityTime) {

Review Comment:
   Why are parameter types Strings and not longs?



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/MetaStorageCompactionTrigger.java:
##########
@@ -319,4 +322,33 @@ private void cancelLastScheduledFutureBusy() {
             lock.unlock();
         }
     }
+
+    private void startCompactionOnRecoveryAsync() {

Review Comment:
   Why is it `Async`? It does not return a future, it just does a compaction in the background



##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItMetaStorageCompactionTriggerOneNodeTest.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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 static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.BAR_KEY;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.FOO_KEY;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.VALUE;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.allNodesContainsSingleRevisionForKeyLocally;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.createClusterConfigWithCompactionProperties;
+import static org.apache.ignite.internal.metastorage.TestMetasStorageUtils.latestKeyRevision;
+import static org.apache.ignite.internal.metastorage.impl.MetaStorageCompactionTriggerConfiguration.DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME;
+import static org.apache.ignite.internal.metastorage.impl.MetaStorageCompactionTriggerConfiguration.INTERVAL_SYSTEM_PROPERTY_NAME;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.configuration.SystemDistributedExtensionConfiguration;
+import org.apache.ignite.internal.distributionzones.rebalance.DistributionZoneRebalanceEngine;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.metastorage.command.CompactionCommand;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.raft.jraft.rpc.WriteActionRequest;
+import org.junit.jupiter.api.Test;
+
+/** For {@link MetaStorageCompactionTrigger} testing for single node case. */
+@WithSystemProperty(key = DistributionZoneRebalanceEngine.SKIP_REBALANCE_TRIGGERS_RECOVERY, value = "true")
+public class ItMetaStorageCompactionTriggerOneNodeTest extends ClusterPerTestIntegrationTest {
+    @Override
+    protected int initialNodes() {
+        return 1;
+    }
+
+    @Override
+    protected void customizeInitParameters(InitParametersBuilder builder) {
+        super.customizeInitParameters(builder);
+
+        builder.clusterConfiguration(createClusterConfigWithCompactionProperties("10", "10"));
+    }
+
+    @Test
+    void testCompactionAfterRestartNode() throws Exception {
+        IgniteImpl node = aliveNode();
+
+        MetaStorageManager metaStorageManager = node.metaStorageManager();
+
+        assertThat(metaStorageManager.put(FOO_KEY, VALUE), willCompleteSuccessfully());
+        assertThat(metaStorageManager.put(BAR_KEY, VALUE), willCompleteSuccessfully());
+
+        // Let's wait until the compaction on revision of FOO_KEY creation happens.
+        long fooRevision = latestKeyRevision(metaStorageManager, FOO_KEY);
+        assertTrue(waitForCondition(() -> metaStorageManager.getCompactionRevisionLocally() >= fooRevision, 10, 1_000));
+
+        log.info("Latest revision for key: [key={}, revision={}]", FOO_KEY, fooRevision);
+
+        // Let's cancel new compactions to create a new version for the key and not compact it until we restart the node.
+        startDropCompactionCommand(node);
+        assertThat(metaStorageManager.put(FOO_KEY, VALUE), willCompleteSuccessfully());
+
+        long latestFooRevision = latestKeyRevision(metaStorageManager, FOO_KEY);
+
+        long latestCompactionRevision = metaStorageManager.getCompactionRevisionLocally();
+        // Let's change the properties before restarting so that a new scheduled compaction does not start after the node starts.
+        changeCompactionProperties(node, Long.toString(Long.MAX_VALUE), Long.toString(Long.MAX_VALUE));
+
+        IgniteImpl restartedNode = restartNode();
+
+        MetaStorageManager restartedMetaStorageManager = restartedNode.metaStorageManager();
+
+        // Let's make sure that after the restart the correct revision of the compression is restored and the compression itself will be at
+        // the latest compaction revision.
+        assertEquals(latestCompactionRevision, restartedMetaStorageManager.getCompactionRevisionLocally());
+        assertTrue(waitForCondition(() -> allNodesContainsSingleRevisionForKeyLocally(cluster, FOO_KEY, latestFooRevision), 10, 1_000));
+    }
+
+    private IgniteImpl aliveNode() {
+        return unwrapIgniteImpl(node(0));
+    }
+
+    private IgniteImpl restartNode() {
+        return unwrapIgniteImpl(restartNode(0));
+    }
+
+    private static void startDropCompactionCommand(IgniteImpl node) {

Review Comment:
   ```suggestion
       private static void startDroppingCompactionCommand(IgniteImpl node) {
   ```



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


Re: [PR] IGNITE-23292 Local startup of metastorage compaction on node startup after recovery [ignite-3]

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


##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItMetaStorageCompactionTriggerOneNodeTest.java:
##########
@@ -75,23 +75,23 @@ void testCompactionAfterRestartNode() throws Exception {
         log.info("Latest revision for key: [key={}, revision={}]", FOO_KEY, fooRevision);
 
         // Let's cancel new compactions to create a new version for the key and not compact it until we restart the node.
-        startDropCompactionCommand(node);
+        startDroppingCompactionCommand(node);
         assertThat(metaStorageManager.put(FOO_KEY, VALUE), willCompleteSuccessfully());
 
         long latestFooRevision = latestKeyRevision(metaStorageManager, FOO_KEY);
 
         long latestCompactionRevision = metaStorageManager.getCompactionRevisionLocally();
         // Let's change the properties before restarting so that a new scheduled compaction does not start after the node starts.
-        changeCompactionProperties(node, Long.toString(Long.MAX_VALUE), Long.toString(Long.MAX_VALUE));
+        changeCompactionProperties(node, Long.MAX_VALUE, Long.MAX_VALUE);
 
         IgniteImpl restartedNode = restartNode();
 
         MetaStorageManager restartedMetaStorageManager = restartedNode.metaStorageManager();
 
-        // Let's make sure that after the restart the correct revision of the compression is restored and the compression itself will be at
+        // Let's make sure that after the restart the correct revision of the compaction is restored and the compression itself will be at

Review Comment:
   Second instance of 'compression' is still 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


Re: [PR] IGNITE-23292 Local startup of metastorage compaction on node startup after recovery [ignite-3]

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


##########
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}. */

Review Comment:
   'Implementation of RecoveryRevisionsListener'?



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