rpuch commented on code in PR #1938:
URL: https://github.com/apache/ignite-3/pull/1938#discussion_r1169856578


##########
modules/core/src/main/java/org/apache/ignite/lang/ErrorGroups.java:
##########
@@ -291,6 +291,9 @@ public static class Transactions {
 
         /** Tx state storage rebalancing error. */
         public static final int TX_STATE_STORAGE_REBALANCE_ERR = 
TX_ERR_GROUP.registerErrorCode(10);
+
+        /** Error occurred when trying to create a read-only transaction much 
older than the data available in the tables. */
+        public static final int TX_READ_ONLY_TO_OLD_ERR = 
TX_ERR_GROUP.registerErrorCode(11);

Review Comment:
   ```suggestion
           public static final int TX_READ_ONLY_TOO_OLD_ERR = 
TX_ERR_GROUP.registerErrorCode(11);
   ```



##########
modules/core/src/main/java/org/apache/ignite/lang/ErrorGroups.java:
##########
@@ -291,6 +291,9 @@ public static class Transactions {
 
         /** Tx state storage rebalancing error. */
         public static final int TX_STATE_STORAGE_REBALANCE_ERR = 
TX_ERR_GROUP.registerErrorCode(10);
+
+        /** Error occurred when trying to create a read-only transaction much 
older than the data available in the tables. */

Review Comment:
   ```suggestion
           /** Error occurred when trying to create a read-only transaction 
with a timestamp older than the data available in the tables. */
   ```



##########
modules/schema/src/main/java/org/apache/ignite/internal/schema/configuration/LowWatermarkConfigurationSchema.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.schema.configuration;
+
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.configuration.annotation.Config;
+import org.apache.ignite.configuration.annotation.Value;
+import org.apache.ignite.configuration.validation.Range;
+
+/**
+ * Low watermark configuration schema.
+ */
+@Config
+public class LowWatermarkConfigurationSchema {
+    /**
+     * Data availability time (in milliseconds), after they have been removed.
+     *
+     * <p>It is also used for read-only transactions that can read data in the 
past.
+     *
+     * <p>Value is used when calculating the new low watermark, which at the 
time of the update is calculated as

Review Comment:
   ```suggestion
        * <p>Value is used when calculating the new low watermark candidate, 
which at the time of the update is calculated as
   ```



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/TxManager.java:
##########
@@ -124,4 +128,20 @@ CompletableFuture<Void> cleanup(
      */
     @TestOnly
     int finished();
+
+    /**
+     * Updates the low watermark, the value is expected to only increase.
+     *
+     * <p>All new read-only transactions will need to be created with a read 
time greater than this value.
+     *
+     * @param newLowWatermark New low watermark.
+     */
+    void updateLowWatermark(HybridTimestamp newLowWatermark);
+
+    /**
+     * Returns the future of all read-only transactions witch less or equals 
the timestamp.

Review Comment:
   ```suggestion
        * Returns the future of all read-only transactions with read timestamp 
less or equals the given timestamp.
   ```



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/ReadOnlyTxId.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.tx.impl;
+
+import java.util.UUID;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.tostring.S;
+
+/**
+ * Read-only transaction ID.
+ */
+class ReadOnlyTxId {

Review Comment:
   The class name does not seem to be perfect as it only mentions the ID, but 
it contains both ID and a timestamp. How about `TxIdAndTimestamp`?



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxManagerImpl.java:
##########
@@ -162,27 +206,62 @@ public CompletableFuture<Void> cleanup(
         return allOf(cleanupFutures);
     }
 
-    /** {@inheritDoc} */
     @Override
     public int finished() {
         return (int) states.entrySet().stream().filter(e -> e.getValue() == 
TxState.COMMITED || e.getValue() == TxState.ABORTED).count();
     }
 
-    /** {@inheritDoc} */
     @Override
     public void start() {
         // No-op.
     }
 
-    /** {@inheritDoc} */
     @Override
-    public void stop() throws Exception {
+    public void stop() {
         // No-op.
     }
 
-    /** {@inheritDoc} */
     @Override
     public LockManager lockManager() {
         return lockManager;
     }
+
+    CompletableFuture<Void> completeReadOnlyTransactionFuture(ReadOnlyTxId 
readOnlyTxId) {
+        CompletableFuture<Void> readOnlyTxFuture = 
readOnlyTxFutureById.remove(readOnlyTxId);
+
+        assert readOnlyTxFuture != null : readOnlyTxId;
+
+        readOnlyTxFuture.complete(null);
+
+        return readOnlyTxFuture;
+    }
+
+    @Override
+    public void updateLowWatermark(HybridTimestamp newLowWatermark) {
+        lowWatermarkReadWriteLock.writeLock().lock();
+
+        try {
+            lowWatermark.updateAndGet(previousLowWatermark -> {
+                if (previousLowWatermark == null) {
+                    return newLowWatermark;
+                }
+
+                assert newLowWatermark.compareTo(previousLowWatermark) > 0 :
+                        "lower watermark should be growing: [previous=" + 
previousLowWatermark + ", new=" + newLowWatermark + ']';
+
+                return newLowWatermark;
+            });
+        } finally {
+            lowWatermarkReadWriteLock.writeLock().unlock();
+        }
+    }
+
+    @Override
+    public CompletableFuture<Void> 
getFutureAllReadOnlyTransactionsWhichLessOrEqualTo(HybridTimestamp timestamp) {
+        ReadOnlyTxId upperBound = new ReadOnlyTxId(timestamp, new 
UUID(Long.MAX_VALUE, Long.MAX_VALUE));
+
+        List<CompletableFuture<Void>> readOnlyTxFutures = 
List.copyOf(readOnlyTxFutureById.headMap(upperBound, true).values());

Review Comment:
   I missed this first time, but: this method will only work correctly if the 
`timestamp` that was passed is <= than the current LWM. Could you please add 
the corresponding assertion and mention this in the javadoc?



##########
modules/schema/src/main/java/org/apache/ignite/internal/schema/configuration/LowWatermarkConfigurationSchema.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.schema.configuration;
+
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.configuration.annotation.Config;
+import org.apache.ignite.configuration.annotation.Value;
+import org.apache.ignite.configuration.validation.Range;
+
+/**
+ * Low watermark configuration schema.
+ */
+@Config
+public class LowWatermarkConfigurationSchema {
+    /**
+     * Data availability time (in milliseconds), after they have been removed.

Review Comment:
   ```suggestion
        * Data availability time (in milliseconds), after which the 
overwritten/deleted data can be finally removed from storage.
   ```



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/ReadOnlyTxId.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.tx.impl;
+
+import java.util.UUID;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.tostring.S;
+
+/**
+ * Read-only transaction ID.
+ */
+class ReadOnlyTxId {
+    /** Start timestamp of the transaction. */
+    private final HybridTimestamp readTimestamp;
+
+    /** Transaction ID. */
+    private final UUID txId;
+
+    /**
+     * Constructor.
+     *
+     * @param readTimestamp Start timestamp of the transaction.
+     * @param txId Transaction ID.
+     */
+    ReadOnlyTxId(HybridTimestamp readTimestamp, UUID txId) {
+        this.readTimestamp = readTimestamp;
+        this.txId = txId;
+    }
+
+    /**
+     * Returns start timestamp of the transaction.
+     */
+    public HybridTimestamp getReadTimestamp() {
+        return readTimestamp;
+    }
+
+    /**
+     * Returns the transaction ID.
+     */
+    public UUID getTxId() {
+        return txId;
+    }
+
+    @Override
+    public boolean equals(Object o) {

Review Comment:
   `hashCode()` method is missing (should be present if `equals()` is defined 
to avoid confusion if someone wants to use this as a hashmap key)



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