You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "vldpyatkov (via GitHub)" <gi...@apache.org> on 2024/12/18 17:06:49 UTC

[PR] IGNITE-23305 Get rid of client HybridTimestampTracker [ignite-3]

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

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


-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -985,17 +1016,26 @@ private static Object unpackExtensionValue(HandshakeExtension handshakeExtension
         return null;
     }
 
+    /**
+     * Gets an observation timestamp for the operation being processed or {@link HybridTimestamp#MIN_VALUE} if the timestamp was not defined
+     * by the operation.
+     * The method returns a current timestamp for the handshake operation.
+     *
+     * @param out Output message packer.
+     * @return A long representation of the observation timestamp.
+     */
     private long observableTimestamp(@Nullable ClientMessagePacker out) {
-        // Certain operations can override the timestamp and provide it in the meta object.
-        if (out != null) {
-            Object meta = out.meta();
+        if (out == null) {
+            return clockService.currentLong();

Review Comment:
   But we have tests where we consider it.
   I mean the test where we make a schema (create table, zones) and then start a client, which has to execute a query over this schema.



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/JdbcQueryEventHandlerImpl.java:
##########
@@ -82,42 +83,48 @@ public class JdbcQueryEventHandlerImpl extends JdbcHandlerBase implements JdbcQu
     /** {@link SqlQueryType}s allowed in JDBC update statements. **/
     private static final Set<SqlQueryType> UPDATE_STATEMENT_QUERIES = Set.of(DML, SqlQueryType.DDL, SqlQueryType.KILL);
 
+    /**
+     * Observation timestamp tracker.
+     * TODO: IGNITE-24053 Remove this after the issue will be fixed.
+     * */
+    private final HybridTimestampTracker timestampTracker = new HybridTimestampTracker();

Review Comment:
   Why does the JDBC driver cannot track an observation timestamp?



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -801,13 +822,23 @@ private void processOperation(ChannelHandlerContext ctx, ClientMessageUnpacker i
                 return ClientJdbcFinishTxRequest.process(in, out, jdbcQueryEventHandler);
 
             case ClientOp.SQL_EXEC_SCRIPT:
-                return ClientSqlExecuteScriptRequest.process(in, queryProcessor, igniteTransactions);
+                return ClientSqlExecuteScriptRequest.process(in, queryProcessor).thenRun(() -> {
+                    // TODO: IGNITE-24055 Observation timestamp must be updated only for DDL "CREATE TABLE..."
+                    if (!(out.meta() instanceof HybridTimestamp)) {
+                        out.meta(clockService.current());
+                    }
+                });
 
             case ClientOp.SQL_QUERY_META:
                 return ClientSqlQueryMetadataRequest.process(in, out, queryProcessor, resources);
 
             case ClientOp.SQL_EXEC_BATCH:
-                return ClientSqlExecuteBatchRequest.process(in, out, queryProcessor, resources, igniteTransactions);
+                return ClientSqlExecuteBatchRequest.process(in, out, queryProcessor, resources).thenRun(() -> {
+                    // TODO: IGNITE-24055 Observation timestamp must be updated only for DDL "CREATE TABLE..."
+                    if (!(out.meta() instanceof HybridTimestamp)) {

Review Comment:
   Looks like meta() value is ignored if it's not a timestamp, so it makes no sense to set it.
   So why it's not 
   `if (out.meta() == null) ?`



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -985,17 +1016,26 @@ private static Object unpackExtensionValue(HandshakeExtension handshakeExtension
         return null;
     }
 
+    /**
+     * Gets an observation timestamp for the operation being processed or {@link HybridTimestamp#MIN_VALUE} if the timestamp was not defined
+     * by the operation.
+     * The method returns a current timestamp for the handshake operation.
+     *
+     * @param out Output message packer.
+     * @return A long representation of the observation timestamp.
+     */
     private long observableTimestamp(@Nullable ClientMessagePacker out) {
-        // Certain operations can override the timestamp and provide it in the meta object.
-        if (out != null) {
-            Object meta = out.meta();
+        if (out == null) {
+            return clockService.currentLong();

Review Comment:
   It doesn't make sense to pass current server time on handshake to client.



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/table/ClientTableCommon.java:
##########
@@ -420,27 +421,51 @@ public static TableNotFoundException tableIdNotFoundException(Integer tableId) {
      * @param in Unpacker.
      * @param out Packer.
      * @param resources Resource registry.
-     * @param igniteTransactions Ignite transactions.
+     * @param txManager Ignite transactions.
      * @param readOnly Read only flag.
      * @return Transaction.
      */
     public static @Nullable InternalTransaction readOrStartImplicitTx(
             ClientMessageUnpacker in,
             ClientMessagePacker out,
             ClientResourceRegistry resources,
-            IgniteTransactionsImpl igniteTransactions,
+            TxManager txManager,
             boolean readOnly
     ) {
 
-        var tx = readTx(in, out, resources);
+        InternalTransaction tx = readTx(in, out, resources);
 
         if (tx == null) {
-            tx = igniteTransactions.beginImplicit(readOnly);
+            tx = startTx(out, txManager, null, true, readOnly);

Review Comment:
   In case of implicit transaction observable ts must be transferred from the client in the message.
   It doesn't happen now.



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -801,13 +822,23 @@ private void processOperation(ChannelHandlerContext ctx, ClientMessageUnpacker i
                 return ClientJdbcFinishTxRequest.process(in, out, jdbcQueryEventHandler);
 
             case ClientOp.SQL_EXEC_SCRIPT:
-                return ClientSqlExecuteScriptRequest.process(in, queryProcessor, igniteTransactions);
+                return ClientSqlExecuteScriptRequest.process(in, queryProcessor).thenRun(() -> {
+                    // TODO: IGNITE-24055 Observation timestamp must be updated only for DDL "CREATE TABLE..."
+                    if (!(out.meta() instanceof HybridTimestamp)) {
+                        out.meta(clockService.current());
+                    }
+                });
 
             case ClientOp.SQL_QUERY_META:
                 return ClientSqlQueryMetadataRequest.process(in, out, queryProcessor, resources);
 
             case ClientOp.SQL_EXEC_BATCH:
-                return ClientSqlExecuteBatchRequest.process(in, out, queryProcessor, resources, igniteTransactions);
+                return ClientSqlExecuteBatchRequest.process(in, out, queryProcessor, resources).thenRun(() -> {
+                    // TODO: IGNITE-24055 Observation timestamp must be updated only for DDL "CREATE TABLE..."

Review Comment:
   Can you provide detailed description in the ticket which SQL statements requre passing back observable ts and which not, and fix the comment accordingly ? 
   I believe it's not only DDL "CREATE TABLE..."
   This affects all places with the TODO.



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/HybridTimestampTrackerImpl.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+import static org.apache.ignite.internal.hlc.HybridTimestamp.NULL_HYBRID_TIMESTAMP;
+
+import java.util.concurrent.atomic.AtomicLong;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Hybrid timestamp tracker.
+ */
+public class HybridTimestampTrackerImpl implements HybridTimestampTracker {

Review Comment:
   You don't need this change. It brings a lot of modified files in PR without any profit.
   Instead, change implementation in the following way:
   ```
   public class HybridTimestampTracker {
       /** Timestamp. */
       private final AtomicLong timestamp = new AtomicLong(NULL_HYBRID_TIMESTAMP);
       
       private final Consumer<HybridTimestamp> updateTs;
   
       public HybridTimestampTracker() {
           this.updateTs = timestamp -> {
               long tsVal = HybridTimestamp.hybridTimestampToLong(ts);
   
               HybridTimestampTracker.this.timestamp.updateAndGet(x -> Math.max(x, tsVal));
           };
       }
       
       public HybridTimestampTracker(@Nullable HybridTimestamp currentTs, Consumer<HybridTimestamp> updateTs) {
           this.timestamp.set(currentTs.longValue());
           this.updateTs = updateTs;
       }
   
       public @Nullable HybridTimestamp get() {
           return HybridTimestamp.nullableHybridTimestamp(timestamp.get());
       }
   
       public void update(@Nullable HybridTimestamp ts) {
           updateTs.accept(ts);
       }
   }
   ```



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/IgniteTransactionsImpl.java:
##########
@@ -35,14 +35,14 @@
 public class IgniteTransactionsImpl implements IgniteTransactions {
     private final TxManager txManager;
 
-    private final HybridTimestampTracker observableTimestampTracker;
+    private final HybridTimestampTrackerImpl observableTimestampTracker;

Review Comment:
   > there are number of methods which are not used anymore
   Good point.
   



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/IgniteTransactionsImpl.java:
##########
@@ -35,14 +35,14 @@
 public class IgniteTransactionsImpl implements IgniteTransactions {
     private final TxManager txManager;
 
-    private final HybridTimestampTracker observableTimestampTracker;
+    private final HybridTimestampTrackerImpl observableTimestampTracker;

Review Comment:
   > there are number of methods which are not used anymore
   
   Good point.
   



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -801,13 +822,23 @@ private void processOperation(ChannelHandlerContext ctx, ClientMessageUnpacker i
                 return ClientJdbcFinishTxRequest.process(in, out, jdbcQueryEventHandler);
 
             case ClientOp.SQL_EXEC_SCRIPT:
-                return ClientSqlExecuteScriptRequest.process(in, queryProcessor, igniteTransactions);
+                return ClientSqlExecuteScriptRequest.process(in, queryProcessor).thenRun(() -> {
+                    // TODO: IGNITE-24055 Observation timestamp must be updated only for DDL "CREATE TABLE..."
+                    if (!(out.meta() instanceof HybridTimestamp)) {
+                        out.meta(clockService.current());
+                    }
+                });
 
             case ClientOp.SQL_QUERY_META:
                 return ClientSqlQueryMetadataRequest.process(in, out, queryProcessor, resources);
 
             case ClientOp.SQL_EXEC_BATCH:
-                return ClientSqlExecuteBatchRequest.process(in, out, queryProcessor, resources, igniteTransactions);
+                return ClientSqlExecuteBatchRequest.process(in, out, queryProcessor, resources).thenRun(() -> {
+                    // TODO: IGNITE-24055 Observation timestamp must be updated only for DDL "CREATE TABLE..."

Review Comment:
   I changed this comment.



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/IgniteAbstractTransactionImpl.java:
##########
@@ -59,8 +63,15 @@ public abstract class IgniteAbstractTransactionImpl implements InternalTransacti
      * @param coordinatorId Transaction coordinator inconsistent ID.
      * @param implicit True for an implicit transaction, false for an ordinary one.
      */
-    public IgniteAbstractTransactionImpl(TxManager txManager, UUID id, UUID coordinatorId, boolean implicit) {
+    public IgniteAbstractTransactionImpl(
+            TxManager txManager,
+            ObservableTimestampProvider observableTsTracker,

Review Comment:
   let's update javadoc



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/sql/ClientSqlCursorCloseRequest.java:
##########
@@ -34,23 +33,19 @@ public class ClientSqlCursorCloseRequest {
      * @param in Unpacker.
      * @param out Packer.
      * @param resources Resources.
-     * @param transactions Transactional facade. Used to acquire last observed time to propagate to client in response.
      * @return Future representing result of operation.
      */
     public static CompletableFuture<Void> process(
             ClientMessageUnpacker in,
             ClientMessagePacker out,
-            ClientResourceRegistry resources,
-            IgniteTransactionsImpl transactions
+            ClientResourceRegistry resources
     ) throws IgniteInternalCheckedException {
         long resourceId = in.unpackLong();
 
         ClientSqlResultSet asyncResultSet = resources.remove(resourceId).get(ClientSqlResultSet.class);
 
         return asyncResultSet.closeAsync()
                 .thenApply(ignored -> {

Review Comment:
   you can remove `thenApply` entirely



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/ObservableTimestampProvider.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Interface is used to provide an observable timestamp into a transaction operation.
+ */
+public interface ObservableTimestampProvider {

Review Comment:
   it's better to name it `HybridTimestampTracker` and rename implementation to `HybridTimestampTrackerImpl` so w will avoid hundreds of meaningless changes. Besides, I believe `HybridTimestampTracker` is better fit for such interface



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/JdbcQueryEventHandlerImpl.java:
##########
@@ -82,42 +83,48 @@ public class JdbcQueryEventHandlerImpl extends JdbcHandlerBase implements JdbcQu
     /** {@link SqlQueryType}s allowed in JDBC update statements. **/
     private static final Set<SqlQueryType> UPDATE_STATEMENT_QUERIES = Set.of(DML, SqlQueryType.DDL, SqlQueryType.KILL);
 
+    /**
+     * Observation timestamp tracker.
+     * TODO: IGNITE-24053 Remove this after the issue will be fixed.
+     * */
+    private final HybridTimestampTracker timestampTracker = new HybridTimestampTracker();

Review Comment:
   I've checked the mentioned JIRA, and it doesn't seem correct. At the moment, JDBC driver doesn't track time on client's side, and driver cannot connect to more than one server. During connection, server issues `connectionId` for every `java.sql.Connection` instance, and every request from the connection provides `connectionId`.
   
   Given that said, we need to create one tracker per `JdbcConnectionContext` and use it for every request within this connection. Changes in JDBC-related requests processing methods are not necessary since driver doesn't track observable time



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/HybridTimestampTracker.java:
##########
@@ -17,36 +17,102 @@
 
 package org.apache.ignite.internal.tx;
 
-import static org.apache.ignite.internal.hlc.HybridTimestamp.NULL_HYBRID_TIMESTAMP;
+import static org.apache.ignite.internal.hlc.HybridTimestamp.hybridTimestampToLong;
+import static org.apache.ignite.internal.hlc.HybridTimestamp.nullableHybridTimestamp;
 
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Consumer;
 import org.apache.ignite.internal.hlc.HybridTimestamp;
 import org.jetbrains.annotations.Nullable;
 
 /**
- * Hybrid timestamp tracker.
+ * Interface is used to provide a track timestamp into a transaction operation.
  */
-public class HybridTimestampTracker {
-    /** Timestamp. */
-    private final AtomicLong timestamp = new AtomicLong(NULL_HYBRID_TIMESTAMP);
+public abstract class HybridTimestampTracker {

Review Comment:
   Ok, changed it to the inteface.



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/IgniteAbstractTransactionImpl.java:
##########
@@ -59,8 +63,15 @@ public abstract class IgniteAbstractTransactionImpl implements InternalTransacti
      * @param coordinatorId Transaction coordinator inconsistent ID.
      * @param implicit True for an implicit transaction, false for an ordinary one.
      */
-    public IgniteAbstractTransactionImpl(TxManager txManager, UUID id, UUID coordinatorId, boolean implicit) {
+    public IgniteAbstractTransactionImpl(
+            TxManager txManager,
+            ObservableTimestampProvider observableTsTracker,

Review Comment:
   Done.



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/IgniteTransactionsImpl.java:
##########
@@ -35,14 +35,14 @@
 public class IgniteTransactionsImpl implements IgniteTransactions {
     private final TxManager txManager;
 
-    private final HybridTimestampTracker observableTimestampTracker;
+    private final HybridTimestampTrackerImpl observableTimestampTracker;

Review Comment:
   In this instance, the field can only be an instance of HybridTimestampTrackerImpl.
   It is not worth overdoing with the use of interfaces.



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/HybridTimestampTracker.java:
##########
@@ -17,36 +17,102 @@
 
 package org.apache.ignite.internal.tx;
 
-import static org.apache.ignite.internal.hlc.HybridTimestamp.NULL_HYBRID_TIMESTAMP;
+import static org.apache.ignite.internal.hlc.HybridTimestamp.hybridTimestampToLong;
+import static org.apache.ignite.internal.hlc.HybridTimestamp.nullableHybridTimestamp;
 
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Consumer;
 import org.apache.ignite.internal.hlc.HybridTimestamp;
 import org.jetbrains.annotations.Nullable;
 
 /**
- * Hybrid timestamp tracker.
+ * Interface is used to provide a track timestamp into a transaction operation.
  */
-public class HybridTimestampTracker {
-    /** Timestamp. */
-    private final AtomicLong timestamp = new AtomicLong(NULL_HYBRID_TIMESTAMP);
+public abstract class HybridTimestampTracker {

Review Comment:
   Why this is not the interface ?



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -985,17 +1016,26 @@ private static Object unpackExtensionValue(HandshakeExtension handshakeExtension
         return null;
     }
 
+    /**
+     * Gets an observation timestamp for the operation being processed or {@link HybridTimestamp#MIN_VALUE} if the timestamp was not defined
+     * by the operation.
+     * The method returns a current timestamp for the handshake operation.
+     *
+     * @param out Output message packer.
+     * @return A long representation of the observation timestamp.
+     */
     private long observableTimestamp(@Nullable ClientMessagePacker out) {
-        // Certain operations can override the timestamp and provide it in the meta object.
-        if (out != null) {
-            Object meta = out.meta();
+        if (out == null) {
+            return clockService.currentLong();

Review Comment:
   Still not clear why it's needed on handshake.
   Query just should load latest table definitions and use them,



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -801,13 +822,23 @@ private void processOperation(ChannelHandlerContext ctx, ClientMessageUnpacker i
                 return ClientJdbcFinishTxRequest.process(in, out, jdbcQueryEventHandler);
 
             case ClientOp.SQL_EXEC_SCRIPT:
-                return ClientSqlExecuteScriptRequest.process(in, queryProcessor, igniteTransactions);
+                return ClientSqlExecuteScriptRequest.process(in, queryProcessor).thenRun(() -> {
+                    // TODO: IGNITE-24055 Observation timestamp must be updated only for DDL "CREATE TABLE..."
+                    if (!(out.meta() instanceof HybridTimestamp)) {
+                        out.meta(clockService.current());
+                    }
+                });
 
             case ClientOp.SQL_QUERY_META:
                 return ClientSqlQueryMetadataRequest.process(in, out, queryProcessor, resources);
 
             case ClientOp.SQL_EXEC_BATCH:
-                return ClientSqlExecuteBatchRequest.process(in, out, queryProcessor, resources, igniteTransactions);
+                return ClientSqlExecuteBatchRequest.process(in, out, queryProcessor, resources).thenRun(() -> {
+                    // TODO: IGNITE-24055 Observation timestamp must be updated only for DDL "CREATE TABLE..."

Review Comment:
   But the comment says otherwise: Observation timestamp must be updated only ..
   This is confusing.



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/ObservableTimestampProvider.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Interface is used to provide an observable timestamp into a transaction operation.
+ */
+public interface ObservableTimestampProvider {

Review Comment:
   Renamed.



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -1140,8 +1140,7 @@ public class IgniteImpl implements Ignite {
         clientHandlerModule = new ClientHandlerModule(
                 qryEngine,
                 distributedTblMgr,
-                // TODO: IGNITE-20232 The observable timestamp should be different for each client.
-                new IgniteTransactionsImpl(txManager, new HybridTimestampTracker()),
+                txManager,

Review Comment:
   Yes, I added a comment on the ticket.
   After this patch, we won't track an observation timestamp on the server side at all. The only exclusion is JDBC, but about it, I created another ticket IGNITE-24053.



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/JdbcQueryEventHandlerImpl.java:
##########
@@ -82,42 +83,48 @@ public class JdbcQueryEventHandlerImpl extends JdbcHandlerBase implements JdbcQu
     /** {@link SqlQueryType}s allowed in JDBC update statements. **/
     private static final Set<SqlQueryType> UPDATE_STATEMENT_QUERIES = Set.of(DML, SqlQueryType.DDL, SqlQueryType.KILL);
 
+    /**
+     * Observation timestamp tracker.
+     * TODO: IGNITE-24053 Remove this after the issue will be fixed.
+     * */
+    private final HybridTimestampTracker timestampTracker = new HybridTimestampTracker();

Review Comment:
   because it doesn't need to. There is no support for multi-node connections yet (simultaneous connections to several servers within the same cluster), so why should we bother?



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -993,9 +1024,11 @@ private long observableTimestamp(@Nullable ClientMessagePacker out) {
             if (meta instanceof HybridTimestamp) {
                 return ((HybridTimestamp) meta).longValue();
             }
+        } else {
+            return clockService.currentLong();
         }
 
-        return clockService.currentLong();
+        return HybridTimestamp.MIN_VALUE.longValue();

Review Comment:
   Ok



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java:
##########
@@ -362,7 +362,7 @@ public class TableManager implements IgniteTablesInternal, IgniteComponent {
 
     private final LowWatermark lowWatermark;
 
-    private final HybridTimestampTracker observableTimestampTracker;
+    private final HybridTimestampTrackerImpl observableTimestampTracker;

Review Comment:
   I prefer to use a concrete implementation until the other is not needed.



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java:
##########
@@ -362,7 +362,7 @@ public class TableManager implements IgniteTablesInternal, IgniteComponent {
 
     private final LowWatermark lowWatermark;
 
-    private final HybridTimestampTracker observableTimestampTracker;
+    private final HybridTimestampTrackerImpl observableTimestampTracker;

Review Comment:
   let's use interface here and below. Please check this kind of changes everywhere in your patch



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/IgniteTransactionsImpl.java:
##########
@@ -35,14 +35,14 @@
 public class IgniteTransactionsImpl implements IgniteTransactions {
     private final TxManager txManager;
 
-    private final HybridTimestampTracker observableTimestampTracker;
+    private final HybridTimestampTrackerImpl observableTimestampTracker;

Review Comment:
   let's use interface instead of implementation. Besides, there are number of methods which are not used anymore. Let's clean up `IgniteTransactionsImpl`



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -743,16 +757,18 @@ private void processOperation(ChannelHandlerContext ctx, ClientMessageUnpacker i
                 return ClientJdbcColumnMetadataRequest.process(in, out, jdbcQueryEventHandler);
 
             case ClientOp.JDBC_SCHEMAS_META:
-                return ClientJdbcSchemasMetadataRequest.process(in, out, jdbcQueryEventHandler);
+                return ClientJdbcSchemasMetadataRequest.process(in, out, jdbcQueryEventHandler).thenRun(() -> {
+                    out.meta(clockService.current());

Review Comment:
   `if (!(out.meta() instanceof HybridTimestamp))`
   This condition is useless for the metadata request because we never calculate an observation timestamp for this request type.



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -993,9 +1024,11 @@ private long observableTimestamp(@Nullable ClientMessagePacker out) {
             if (meta instanceof HybridTimestamp) {
                 return ((HybridTimestamp) meta).longValue();
             }
+        } else {
+            return clockService.currentLong();
         }
 
-        return clockService.currentLong();
+        return HybridTimestamp.MIN_VALUE.longValue();
     }

Review Comment:
   I suggest reworking this method a bit to see the code branching more clearly.
   ```java
   private long observableTimestamp(@Nullable ClientMessagePacker out) {
           // Certain operations can override the timestamp and provide it in the meta object.
           if (out == null) {
               return clockService.currentLong();
           }
   
           Object meta = out.meta();
   
           if (meta instanceof HybridTimestamp) {
               return ((HybridTimestamp) meta).longValue();
           }
   
           return HybridTimestamp.MIN_VALUE.longValue();
       }
   ```



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/JdbcQueryEventHandlerImpl.java:
##########
@@ -82,42 +83,48 @@ public class JdbcQueryEventHandlerImpl extends JdbcHandlerBase implements JdbcQu
     /** {@link SqlQueryType}s allowed in JDBC update statements. **/
     private static final Set<SqlQueryType> UPDATE_STATEMENT_QUERIES = Set.of(DML, SqlQueryType.DDL, SqlQueryType.KILL);
 
+    /**
+     * Observation timestamp tracker.
+     * TODO: IGNITE-24053 Remove this after the issue will be fixed.
+     * */
+    private final HybridTimestampTracker timestampTracker = new HybridTimestampTracker();

Review Comment:
   I think it is not right.
   We were not assumed to work with a client without an observation timestamp.



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -801,13 +822,23 @@ private void processOperation(ChannelHandlerContext ctx, ClientMessageUnpacker i
                 return ClientJdbcFinishTxRequest.process(in, out, jdbcQueryEventHandler);
 
             case ClientOp.SQL_EXEC_SCRIPT:
-                return ClientSqlExecuteScriptRequest.process(in, queryProcessor, igniteTransactions);
+                return ClientSqlExecuteScriptRequest.process(in, queryProcessor).thenRun(() -> {
+                    // TODO: IGNITE-24055 Observation timestamp must be updated only for DDL "CREATE TABLE..."
+                    if (!(out.meta() instanceof HybridTimestamp)) {
+                        out.meta(clockService.current());
+                    }
+                });
 
             case ClientOp.SQL_QUERY_META:
                 return ClientSqlQueryMetadataRequest.process(in, out, queryProcessor, resources);
 
             case ClientOp.SQL_EXEC_BATCH:
-                return ClientSqlExecuteBatchRequest.process(in, out, queryProcessor, resources, igniteTransactions);
+                return ClientSqlExecuteBatchRequest.process(in, out, queryProcessor, resources).thenRun(() -> {
+                    // TODO: IGNITE-24055 Observation timestamp must be updated only for DDL "CREATE TABLE..."

Review Comment:
   Unfortunately, I do not have a full list of SQL operations.
   We should do an investigation before taking this issue for implementation. It is just a marker for the SQL team.



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/table/ClientTableCommon.java:
##########
@@ -420,27 +421,51 @@ public static TableNotFoundException tableIdNotFoundException(Integer tableId) {
      * @param in Unpacker.
      * @param out Packer.
      * @param resources Resource registry.
-     * @param igniteTransactions Ignite transactions.
+     * @param txManager Ignite transactions.
      * @param readOnly Read only flag.
      * @return Transaction.
      */
     public static @Nullable InternalTransaction readOrStartImplicitTx(
             ClientMessageUnpacker in,
             ClientMessagePacker out,
             ClientResourceRegistry resources,
-            IgniteTransactionsImpl igniteTransactions,
+            TxManager txManager,
             boolean readOnly
     ) {
 
-        var tx = readTx(in, out, resources);
+        InternalTransaction tx = readTx(in, out, resources);
 
         if (tx == null) {
-            tx = igniteTransactions.beginImplicit(readOnly);
+            tx = startTx(out, txManager, null, true, readOnly);

Review Comment:
   Observation timestamp is not necessary for the implicit transaction.
   I will add a comment.



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/HybridTimestampTrackerImpl.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+import static org.apache.ignite.internal.hlc.HybridTimestamp.NULL_HYBRID_TIMESTAMP;
+
+import java.util.concurrent.atomic.AtomicLong;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Hybrid timestamp tracker.
+ */
+public class HybridTimestampTrackerImpl implements HybridTimestampTracker {

Review Comment:
   I re-wrote HybridTimestampTracker, but in a different approach.



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -1140,8 +1140,7 @@ public class IgniteImpl implements Ignite {
         clientHandlerModule = new ClientHandlerModule(
                 qryEngine,
                 distributedTblMgr,
-                // TODO: IGNITE-20232 The observable timestamp should be different for each client.
-                new IgniteTransactionsImpl(txManager, new HybridTimestampTracker()),
+                txManager,

Review Comment:
   can we also fix the last TODO related to IGNITE-20232 (in IgniteTransactionsImpl?):
   ```
   TODO:IGNITE-20232 Remove this method; instead, an interface method should be used.
   ```
   and close INIGTE-20232 when this will be resolved?



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -743,16 +757,18 @@ private void processOperation(ChannelHandlerContext ctx, ClientMessageUnpacker i
                 return ClientJdbcColumnMetadataRequest.process(in, out, jdbcQueryEventHandler);
 
             case ClientOp.JDBC_SCHEMAS_META:
-                return ClientJdbcSchemasMetadataRequest.process(in, out, jdbcQueryEventHandler);
+                return ClientJdbcSchemasMetadataRequest.process(in, out, jdbcQueryEventHandler).thenRun(() -> {
+                    out.meta(clockService.current());

Review Comment:
   why we need to update timestamp when requesting metadata?
   why most time we updating it conditionally?
   ```
   if (!(out.meta() instanceof HybridTimestamp))
   ```



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -743,16 +757,18 @@ private void processOperation(ChannelHandlerContext ctx, ClientMessageUnpacker i
                 return ClientJdbcColumnMetadataRequest.process(in, out, jdbcQueryEventHandler);
 
             case ClientOp.JDBC_SCHEMAS_META:
-                return ClientJdbcSchemasMetadataRequest.process(in, out, jdbcQueryEventHandler);
+                return ClientJdbcSchemasMetadataRequest.process(in, out, jdbcQueryEventHandler).thenRun(() -> {
+                    out.meta(clockService.current());

Review Comment:
   We ought to have a timestamp more or equal to the timestamp that is used to get the metadata. Otherwise, we may start RO before a table in the metadata was created.



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -993,9 +1024,11 @@ private long observableTimestamp(@Nullable ClientMessagePacker out) {
             if (meta instanceof HybridTimestamp) {
                 return ((HybridTimestamp) meta).longValue();
             }
+        } else {
+            return clockService.currentLong();
         }
 
-        return clockService.currentLong();
+        return HybridTimestamp.MIN_VALUE.longValue();

Review Comment:
   I suggest rework a bit this method to see the code branching more clearly.
   ```java
   private long observableTimestamp(@Nullable ClientMessagePacker out) {
           // Certain operations can override the timestamp and provide it in the meta object.
           if (out == null) {
               return clockService.currentLong();
           }
   
           Object meta = out.meta();
   
           if (meta instanceof HybridTimestamp) {
               return ((HybridTimestamp) meta).longValue();
           }
   
           return HybridTimestamp.MIN_VALUE.longValue();
       }
   ```



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -993,9 +1024,11 @@ private long observableTimestamp(@Nullable ClientMessagePacker out) {
             if (meta instanceof HybridTimestamp) {
                 return ((HybridTimestamp) meta).longValue();
             }
+        } else {
+            return clockService.currentLong();
         }
 
-        return clockService.currentLong();
+        return HybridTimestamp.MIN_VALUE.longValue();

Review Comment:
   I suggest to rework a bit this method to see the code branching more clearly.
   ```java
   private long observableTimestamp(@Nullable ClientMessagePacker out) {
           // Certain operations can override the timestamp and provide it in the meta object.
           if (out == null) {
               return clockService.currentLong();
           }
   
           Object meta = out.meta();
   
           if (meta instanceof HybridTimestamp) {
               return ((HybridTimestamp) meta).longValue();
           }
   
           return HybridTimestamp.MIN_VALUE.longValue();
       }
   ```



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -993,9 +1024,11 @@ private long observableTimestamp(@Nullable ClientMessagePacker out) {
             if (meta instanceof HybridTimestamp) {
                 return ((HybridTimestamp) meta).longValue();
             }
+        } else {
+            return clockService.currentLong();
         }
 
-        return clockService.currentLong();
+        return HybridTimestamp.MIN_VALUE.longValue();
     }

Review Comment:
   I suggest reworking this method a bit to see the code branching more clearly.
   ```java
   private long observableTimestamp(@Nullable ClientMessagePacker out) {
           // Certain operations can override the timestamp and provide it in the meta object.
           if (out == null) {
               return clockService.currentLong();
           }
   
           Object meta = out.meta();
   
           if (meta instanceof HybridTimestamp) {
               return ((HybridTimestamp) meta).longValue();
           }
   
           return HybridTimestamp.MIN_VALUE.longValue();
       }
   ```



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/HybridTimestampTracker.java:
##########
@@ -17,36 +17,102 @@
 
 package org.apache.ignite.internal.tx;
 
-import static org.apache.ignite.internal.hlc.HybridTimestamp.NULL_HYBRID_TIMESTAMP;
+import static org.apache.ignite.internal.hlc.HybridTimestamp.hybridTimestampToLong;
+import static org.apache.ignite.internal.hlc.HybridTimestamp.nullableHybridTimestamp;
 
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Consumer;
 import org.apache.ignite.internal.hlc.HybridTimestamp;
 import org.jetbrains.annotations.Nullable;
 
 /**
- * Hybrid timestamp tracker.
+ * Interface is used to provide a track timestamp into a transaction operation.
  */
-public class HybridTimestampTracker {
-    /** Timestamp. */
-    private final AtomicLong timestamp = new AtomicLong(NULL_HYBRID_TIMESTAMP);
+public abstract class HybridTimestampTracker {

Review Comment:
   Why this is not an interface ?



-- 
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-23305 Get rid of client HybridTimestampTracker [ignite-3]

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


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -985,17 +1016,26 @@ private static Object unpackExtensionValue(HandshakeExtension handshakeExtension
         return null;
     }
 
+    /**
+     * Gets an observation timestamp for the operation being processed or {@link HybridTimestamp#MIN_VALUE} if the timestamp was not defined
+     * by the operation.
+     * The method returns a current timestamp for the handshake operation.
+     *
+     * @param out Output message packer.
+     * @return A long representation of the observation timestamp.
+     */
     private long observableTimestamp(@Nullable ClientMessagePacker out) {
-        // Certain operations can override the timestamp and provide it in the meta object.
-        if (out != null) {
-            Object meta = out.meta();
+        if (out == null) {
+            return clockService.currentLong();

Review Comment:
   There is no way to do it right now because several tests are based on this behavior.



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