korlov42 commented on code in PR #6563:
URL: https://github.com/apache/ignite-3/pull/6563#discussion_r2335701913


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/PartitionModificationCounter.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.table.distributed;
+
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.LongSupplier;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+
+/**
+ * Keeps track of the number of modifications of a partition.
+ * When the configured threshold value of the number of modifications is 
reached, a timestamp corresponding
+ * to the commit time of the transaction that made this update is stored in 
{@link #lastMilestoneReachedTimestamp}.
+ * The timestamp value is used to determine the staleness of related SQL 
statistics.
+ */
+public class PartitionModificationCounter {
+    public static PartitionModificationCounter NOOP =

Review Comment:
   looks like NOOP counter is used in tests only. We usually use testFixtures + 
utility class for such objects.



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/StorageUpdateHandler.java:
##########
@@ -132,6 +138,8 @@ public void handleUpdate(
 
             if (trackWriteIntent) {
                 pendingRows.addPendingRowId(txId, rowId);
+            } else if (commitTs != null) {
+                modificationCounter.updateValue(1, commitTs);

Review Comment:
   I think, this must be unconditional `else` branch with optional assertion 
`assert commitTs != null`. We have to count the update, either right now if 
this is one phase transaction, or later on commit.



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/PartitionModificationCounter.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.table.distributed;
+
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.LongSupplier;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+
+/**
+ * Keeps track of the number of modifications of a partition.
+ * When the configured threshold value of the number of modifications is 
reached, a timestamp corresponding
+ * to the commit time of the transaction that made this update is stored in 
{@link #lastMilestoneReachedTimestamp}.
+ * The timestamp value is used to determine the staleness of related SQL 
statistics.
+ */
+public class PartitionModificationCounter {
+    public static PartitionModificationCounter NOOP =
+            new PartitionModificationCounter(HybridTimestamp.MAX_VALUE, () -> 
0, 0, 0);
+
+    private final LongSupplier partitionSizeSupplier;
+    private final double staleRowsFraction;
+    private final long minStaleRowsCount;
+
+    private final AtomicLong counter = new AtomicLong(0);
+    private volatile long nextMilestone;
+    private volatile HybridTimestamp lastMilestoneReachedTimestamp;
+
+    /** Constructor. */
+    public PartitionModificationCounter(
+            HybridTimestamp initTimestamp,
+            LongSupplier partitionSizeSupplier,
+            double staleRowsFraction,
+            long minStaleRowsCount
+    ) {
+        assert staleRowsFraction >= 0 && staleRowsFraction <= 1 : 
"staleRowsFraction must be in [0, 1] range.";
+
+        this.staleRowsFraction = staleRowsFraction;
+        this.minStaleRowsCount = minStaleRowsCount;
+        this.partitionSizeSupplier = partitionSizeSupplier;
+
+        nextMilestone = 
computeNextMilestone(partitionSizeSupplier.getAsLong(), staleRowsFraction, 
minStaleRowsCount);
+        lastMilestoneReachedTimestamp = initTimestamp;
+    }
+
+    /**
+     * Gets the current counter value.
+     *
+     * @return the current counter value
+     */

Review Comment:
   nitpicking: we can use one-line comments in such cases.



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/PartitionModificationCounter.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.table.distributed;
+
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.LongSupplier;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+
+/**
+ * Keeps track of the number of modifications of a partition.
+ * When the configured threshold value of the number of modifications is 
reached, a timestamp corresponding
+ * to the commit time of the transaction that made this update is stored in 
{@link #lastMilestoneReachedTimestamp}.
+ * The timestamp value is used to determine the staleness of related SQL 
statistics.
+ */

Review Comment:
   ```suggestion
   /**
    * Keeps track of the number of modifications of a partition.
    *
    * <p>When the configured threshold value of the number of modifications is 
reached, a timestamp corresponding
    * to the commit time of the transaction that made this update is stored in 
{@link #lastMilestoneReachedTimestamp}.
    *
    * <p>The timestamp value is used to determine the staleness of related SQL 
statistics.
    */
   ```



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