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


##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/ReadOperationForCompactionTracker.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.server;
+
+import static java.util.stream.Collectors.collectingAndThen;
+import static java.util.stream.Collectors.toList;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.ignite.internal.metastorage.MetaStorageCompactionManager;
+import org.apache.ignite.internal.tostring.IgniteToStringInclude;
+import org.apache.ignite.internal.tostring.S;
+import org.apache.ignite.internal.util.CompletableFutures;
+
+/**
+ * Tracker of read operations from metastorage or its storage. Used to track 
the completion of read operations before start local
+ * compaction of metastorage.
+ *
+ * <p>Expected usage:</p>
+ * <ul>
+ *     <li>Before starting execution, the reading command invoke {@link 
#track} with its ID and the compaction revision that is currently
+ *     set ({@link 
MetaStorageCompactionManager#setCompactionRevisionLocally}/{@link 
KeyValueStorage#setCompactionRevision}).</li>
+ *     <li>After completion, the reading command will invoke {@link #untrack} 
with the same arguments as when calling {@link #track},
+ *     regardless of whether the operation was successful or not.</li>
+ *     <li>{@link #collect} will be invoked only after a new compaction 
revision has been set
+ *     ({@link 
MetaStorageCompactionManager#setCompactionRevisionLocally}/{@link 
KeyValueStorage#setCompactionRevision}) for a new
+ *     compaction revision.</li>
+ * </ul>
+ */
+public class ReadOperationForCompactionTracker {
+    private final Map<ReadOperationKey, CompletableFuture<Void>> 
readOperationFutureByKey = new ConcurrentHashMap<>();
+
+    /**
+     * Starts tracking the completion of a read operation on the current 
compaction revision.
+     *
+     * <p>Method is expected not to be called more than once for the same 
arguments.</p>
+     *
+     * <p>Expected usage pattern:</p>
+     * <pre><code>
+     *     Object readOperationId = ...;
+     *     int compactionRevision = ...;
+     *
+     *     tracker.track(readOperationId, compactionRevision);
+     *
+     *     try {
+     *         doReadOperation(...);
+     *     } finally {
+     *         tracker.untrack(readOperationId, compactionRevision);
+     *     }
+     * </code></pre>
+     *
+     * @see #untrack(Object, long)
+     */
+    public void track(Object readOperationId, long compactionRevision) {

Review Comment:
   For now I think not, since it does not have much impact and will not require 
changes in the future if we change the ID. 
   I will replace the use of UUID with long.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to