You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/08/26 12:39:28 UTC

[GitHub] [ignite-3] ibessonov opened a new pull request, #1038: IGNITE-17577 Timestamp replaced with HybridTimestamp in MvPartitionStorage.

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

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


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


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1038: IGNITE-17577 Timestamp replaced with HybridTimestamp in MvPartitionStorage.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1038:
URL: https://github.com/apache/ignite-3/pull/1038#discussion_r957395723


##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/Timestamps.java:
##########
@@ -17,62 +17,72 @@
 
 package org.apache.ignite.internal.storage.pagememory.mv;
 
+import static org.apache.ignite.hlc.HybridTimestamp.HYBRID_TIMESTAMP_SIZE;
+import static org.apache.ignite.internal.pagememory.util.PageUtils.getInt;
 import static org.apache.ignite.internal.pagememory.util.PageUtils.getLong;
+import static org.apache.ignite.internal.pagememory.util.PageUtils.putInt;
 import static org.apache.ignite.internal.pagememory.util.PageUtils.putLong;
 
 import java.nio.ByteBuffer;
-import org.apache.ignite.internal.tx.Timestamp;
+import org.apache.ignite.hlc.HybridTimestamp;
 import org.jetbrains.annotations.Nullable;
 
 /**
- * Code to work with {@link Timestamp}s.
+ * Code to work with {@link HybridTimestamp}s.
  */
 public class Timestamps {

Review Comment:
   I'll rename 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


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1038: IGNITE-17577 Timestamp replaced with HybridTimestamp in MvPartitionStorage.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1038:
URL: https://github.com/apache/ignite-3/pull/1038#discussion_r957396889


##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/Timestamps.java:
##########
@@ -17,62 +17,72 @@
 
 package org.apache.ignite.internal.storage.pagememory.mv;
 
+import static org.apache.ignite.hlc.HybridTimestamp.HYBRID_TIMESTAMP_SIZE;
+import static org.apache.ignite.internal.pagememory.util.PageUtils.getInt;
 import static org.apache.ignite.internal.pagememory.util.PageUtils.getLong;
+import static org.apache.ignite.internal.pagememory.util.PageUtils.putInt;
 import static org.apache.ignite.internal.pagememory.util.PageUtils.putLong;
 
 import java.nio.ByteBuffer;
-import org.apache.ignite.internal.tx.Timestamp;
+import org.apache.ignite.hlc.HybridTimestamp;
 import org.jetbrains.annotations.Nullable;
 
 /**
- * Code to work with {@link Timestamp}s.
+ * Code to work with {@link HybridTimestamp}s.
  */
 public class Timestamps {
     /**
-     * Reads a {@link Timestamp} value from memory.
+     * Reads a {@link HybridTimestamp} value from memory.
      *
      * @param pageAddr Address where page data starts.
      * @param offset Offset to the timestamp value relative to pageAddr.
      */
-    static @Nullable Timestamp readTimestamp(long pageAddr, int offset) {
-        long nodeId = getLong(pageAddr, offset);
-        long localTimestamp = getLong(pageAddr, offset + Long.BYTES);
+    static @Nullable HybridTimestamp readTimestamp(long pageAddr, int offset) {
+        long physical = getLong(pageAddr, offset);
+        int logical = getInt(pageAddr, offset + Long.BYTES);
 
-        Timestamp timestamp = new Timestamp(localTimestamp, nodeId);
-        if (timestamp.equals(RowVersion.NULL_TIMESTAMP)) {
-            timestamp = null;
+        if (physical == 0L && logical == 0) {

Review Comment:
   Ok, although I don't think it's necessary. Not every 0 deserve a constant :)



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


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1038: IGNITE-17577 Timestamp replaced with HybridTimestamp in MvPartitionStorage.

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1038:
URL: https://github.com/apache/ignite-3/pull/1038#discussion_r957300303


##########
modules/storage-api/src/main/java/org/apache/ignite/internal/storage/MvPartitionStorage.java:
##########
@@ -85,6 +86,21 @@ public interface MvPartitionStorage extends AutoCloseable {
      */
     long persistedIndex();
 
+    /**
+     * Converts {@link Timestamp} into {@link HybridTimestamp} with preserving local node time order.

Review Comment:
   ```suggestion
        * Converts {@link Timestamp} to {@link HybridTimestamp} preserving local node time order.
   ```



##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/RowVersion.java:
##########
@@ -17,41 +17,39 @@
 
 package org.apache.ignite.internal.storage.pagememory.mv;
 
+import static org.apache.ignite.hlc.HybridTimestamp.HYBRID_TIMESTAMP_SIZE;
+
 import java.nio.ByteBuffer;
 import java.util.Objects;
+import org.apache.ignite.hlc.HybridTimestamp;
 import org.apache.ignite.internal.pagememory.Storable;
 import org.apache.ignite.internal.pagememory.io.AbstractDataPageIo;
 import org.apache.ignite.internal.pagememory.io.IoVersions;
 import org.apache.ignite.internal.storage.pagememory.mv.io.RowVersionDataIo;
 import org.apache.ignite.internal.tostring.IgniteToStringExclude;
 import org.apache.ignite.internal.tostring.S;
-import org.apache.ignite.internal.tx.Timestamp;
 import org.jetbrains.annotations.Nullable;
 
 /**
  * Represents row version inside row version chain.
  */
-public class RowVersion implements Storable {
-    /** A 'timestamp' representing absense of a timestamp. */
-    public static final Timestamp NULL_TIMESTAMP = new Timestamp(Long.MIN_VALUE, Long.MIN_VALUE);
-
+public final class RowVersion implements Storable {
     /** Represents an absent partitionless link. */
     public static final long NULL_LINK = 0;
 
-    private static final int TIMESTAMP_STORE_SIZE_BYTES = 2 * Long.BYTES;
     private static final int NEXT_LINK_STORE_SIZE_BYTES = PartitionlessLinks.PARTITIONLESS_LINK_SIZE_BYTES;
     private static final int VALUE_SIZE_STORE_SIZE_BYTES = Integer.BYTES;
 
     public static final int TIMESTAMP_OFFSET = 0;
-    public static final int NEXT_LINK_OFFSET = TIMESTAMP_STORE_SIZE_BYTES;
+    public static final int NEXT_LINK_OFFSET = HYBRID_TIMESTAMP_SIZE;

Review Comment:
   ```suggestion
       public static final int NEXT_LINK_OFFSET = TIMESTAMP_OFFSET + HYBRID_TIMESTAMP_SIZE;
   ```
   
   I should have probably done this myself for consistency: prev field offet plus prev field size



##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/Timestamps.java:
##########
@@ -17,62 +17,72 @@
 
 package org.apache.ignite.internal.storage.pagememory.mv;
 
+import static org.apache.ignite.hlc.HybridTimestamp.HYBRID_TIMESTAMP_SIZE;
+import static org.apache.ignite.internal.pagememory.util.PageUtils.getInt;
 import static org.apache.ignite.internal.pagememory.util.PageUtils.getLong;
+import static org.apache.ignite.internal.pagememory.util.PageUtils.putInt;
 import static org.apache.ignite.internal.pagememory.util.PageUtils.putLong;
 
 import java.nio.ByteBuffer;
-import org.apache.ignite.internal.tx.Timestamp;
+import org.apache.ignite.hlc.HybridTimestamp;
 import org.jetbrains.annotations.Nullable;
 
 /**
- * Code to work with {@link Timestamp}s.
+ * Code to work with {@link HybridTimestamp}s.
  */
 public class Timestamps {

Review Comment:
   Should the class be renamed as it now works with `HybridTimestamp`s, not with `Timestamp`s?



##########
modules/storage-rocksdb/src/main/java/org/apache/ignite/internal/storage/rocksdb/RocksDbMvPartitionStorage.java:
##########
@@ -807,14 +814,12 @@ private ByteBuffer prepareHeapKeyBuf(RowId rowId) {
     /**
      * Writes a timestamp into a byte buffer, in descending lexicographical bytes order.
      */
-    private static void putTimestamp(ByteBuffer buf, Timestamp ts) {
+    private static void putTimestamp(ByteBuffer buf, HybridTimestamp ts) {
         assert buf.order() == BIG_ENDIAN;
 
-        // Two things to note here:
-        //  - "xor" with a single sign bit makes long values comparable according to RocksDB convention, where bytes are unsigned.

Review Comment:
   Why is this xoring removed? Do we rely on the fact that both components are non-negative?



##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/Timestamps.java:
##########
@@ -17,62 +17,72 @@
 
 package org.apache.ignite.internal.storage.pagememory.mv;
 
+import static org.apache.ignite.hlc.HybridTimestamp.HYBRID_TIMESTAMP_SIZE;
+import static org.apache.ignite.internal.pagememory.util.PageUtils.getInt;
 import static org.apache.ignite.internal.pagememory.util.PageUtils.getLong;
+import static org.apache.ignite.internal.pagememory.util.PageUtils.putInt;
 import static org.apache.ignite.internal.pagememory.util.PageUtils.putLong;
 
 import java.nio.ByteBuffer;
-import org.apache.ignite.internal.tx.Timestamp;
+import org.apache.ignite.hlc.HybridTimestamp;
 import org.jetbrains.annotations.Nullable;
 
 /**
- * Code to work with {@link Timestamp}s.
+ * Code to work with {@link HybridTimestamp}s.
  */
 public class Timestamps {
     /**
-     * Reads a {@link Timestamp} value from memory.
+     * Reads a {@link HybridTimestamp} value from memory.
      *
      * @param pageAddr Address where page data starts.
      * @param offset Offset to the timestamp value relative to pageAddr.
      */
-    static @Nullable Timestamp readTimestamp(long pageAddr, int offset) {
-        long nodeId = getLong(pageAddr, offset);
-        long localTimestamp = getLong(pageAddr, offset + Long.BYTES);
+    static @Nullable HybridTimestamp readTimestamp(long pageAddr, int offset) {
+        long physical = getLong(pageAddr, offset);
+        int logical = getInt(pageAddr, offset + Long.BYTES);
 
-        Timestamp timestamp = new Timestamp(localTimestamp, nodeId);
-        if (timestamp.equals(RowVersion.NULL_TIMESTAMP)) {
-            timestamp = null;
+        if (physical == 0L && logical == 0) {

Review Comment:
   I suggest to extract these zeroes as constants and use them in writing methods as well. Just a little more connectivity in the code seems to be a good thing.



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


[GitHub] [ignite-3] ibessonov merged pull request #1038: IGNITE-17577 Timestamp replaced with HybridTimestamp in MvPartitionStorage.

Posted by GitBox <gi...@apache.org>.
ibessonov merged PR #1038:
URL: https://github.com/apache/ignite-3/pull/1038


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


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1038: IGNITE-17577 Timestamp replaced with HybridTimestamp in MvPartitionStorage.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1038:
URL: https://github.com/apache/ignite-3/pull/1038#discussion_r957393522


##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/RowVersion.java:
##########
@@ -17,41 +17,39 @@
 
 package org.apache.ignite.internal.storage.pagememory.mv;
 
+import static org.apache.ignite.hlc.HybridTimestamp.HYBRID_TIMESTAMP_SIZE;
+
 import java.nio.ByteBuffer;
 import java.util.Objects;
+import org.apache.ignite.hlc.HybridTimestamp;
 import org.apache.ignite.internal.pagememory.Storable;
 import org.apache.ignite.internal.pagememory.io.AbstractDataPageIo;
 import org.apache.ignite.internal.pagememory.io.IoVersions;
 import org.apache.ignite.internal.storage.pagememory.mv.io.RowVersionDataIo;
 import org.apache.ignite.internal.tostring.IgniteToStringExclude;
 import org.apache.ignite.internal.tostring.S;
-import org.apache.ignite.internal.tx.Timestamp;
 import org.jetbrains.annotations.Nullable;
 
 /**
  * Represents row version inside row version chain.
  */
-public class RowVersion implements Storable {
-    /** A 'timestamp' representing absense of a timestamp. */
-    public static final Timestamp NULL_TIMESTAMP = new Timestamp(Long.MIN_VALUE, Long.MIN_VALUE);
-
+public final class RowVersion implements Storable {
     /** Represents an absent partitionless link. */
     public static final long NULL_LINK = 0;
 
-    private static final int TIMESTAMP_STORE_SIZE_BYTES = 2 * Long.BYTES;
     private static final int NEXT_LINK_STORE_SIZE_BYTES = PartitionlessLinks.PARTITIONLESS_LINK_SIZE_BYTES;
     private static final int VALUE_SIZE_STORE_SIZE_BYTES = Integer.BYTES;
 
     public static final int TIMESTAMP_OFFSET = 0;
-    public static final int NEXT_LINK_OFFSET = TIMESTAMP_STORE_SIZE_BYTES;
+    public static final int NEXT_LINK_OFFSET = HYBRID_TIMESTAMP_SIZE;

Review Comment:
   Makes sense, thank you!



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


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1038: IGNITE-17577 Timestamp replaced with HybridTimestamp in MvPartitionStorage.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1038:
URL: https://github.com/apache/ignite-3/pull/1038#discussion_r957402048


##########
modules/storage-rocksdb/src/main/java/org/apache/ignite/internal/storage/rocksdb/RocksDbMvPartitionStorage.java:
##########
@@ -807,14 +814,12 @@ private ByteBuffer prepareHeapKeyBuf(RowId rowId) {
     /**
      * Writes a timestamp into a byte buffer, in descending lexicographical bytes order.
      */
-    private static void putTimestamp(ByteBuffer buf, Timestamp ts) {
+    private static void putTimestamp(ByteBuffer buf, HybridTimestamp ts) {
         assert buf.order() == BIG_ENDIAN;
 
-        // Two things to note here:
-        //  - "xor" with a single sign bit makes long values comparable according to RocksDB convention, where bytes are unsigned.

Review Comment:
   Yes, we do rely on this fact right now. If anything changes, I'll bring them back.
   They used to confuse readers, you know



##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/Timestamps.java:
##########
@@ -17,62 +17,72 @@
 
 package org.apache.ignite.internal.storage.pagememory.mv;
 
+import static org.apache.ignite.hlc.HybridTimestamp.HYBRID_TIMESTAMP_SIZE;
+import static org.apache.ignite.internal.pagememory.util.PageUtils.getInt;
 import static org.apache.ignite.internal.pagememory.util.PageUtils.getLong;
+import static org.apache.ignite.internal.pagememory.util.PageUtils.putInt;
 import static org.apache.ignite.internal.pagememory.util.PageUtils.putLong;
 
 import java.nio.ByteBuffer;
-import org.apache.ignite.internal.tx.Timestamp;
+import org.apache.ignite.hlc.HybridTimestamp;
 import org.jetbrains.annotations.Nullable;
 
 /**
- * Code to work with {@link Timestamp}s.
+ * Code to work with {@link HybridTimestamp}s.
  */
 public class Timestamps {
     /**
-     * Reads a {@link Timestamp} value from memory.
+     * Reads a {@link HybridTimestamp} value from memory.
      *
      * @param pageAddr Address where page data starts.
      * @param offset Offset to the timestamp value relative to pageAddr.
      */
-    static @Nullable Timestamp readTimestamp(long pageAddr, int offset) {
-        long nodeId = getLong(pageAddr, offset);
-        long localTimestamp = getLong(pageAddr, offset + Long.BYTES);
+    static @Nullable HybridTimestamp readTimestamp(long pageAddr, int offset) {
+        long physical = getLong(pageAddr, offset);
+        int logical = getInt(pageAddr, offset + Long.BYTES);
 
-        Timestamp timestamp = new Timestamp(localTimestamp, nodeId);
-        if (timestamp.equals(RowVersion.NULL_TIMESTAMP)) {
-            timestamp = null;
+        if (physical == 0L && logical == 0) {

Review Comment:
   Ok, although I don't think it's necessary. Not every 0 deserves a constant :)



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