You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "SammyVimes (via GitHub)" <gi...@apache.org> on 2023/05/01 13:50:47 UTC

[GitHub] [ignite-3] SammyVimes commented on a diff in pull request #1693: IGNITE-18839 HybridTimestamp and its usages refactored to use 8-bytes representation

SammyVimes commented on code in PR #1693:
URL: https://github.com/apache/ignite-3/pull/1693#discussion_r1181537818


##########
modules/core/src/main/java/org/apache/ignite/internal/hlc/HybridTimestamp.java:
##########
@@ -55,13 +64,54 @@ public final class HybridTimestamp implements Comparable<HybridTimestamp>, Seria
      * @param logical The logical time.
      */
     public HybridTimestamp(long physical, int logical) {
-        assert physical > 0 : physical;
-        // Value -1 is used in "org.apache.ignite.internal.hlc.HybridClock.update" to produce "0" after the increment.
-        // Real usable value cannot be negative.
-        assert logical >= -1 : logical;
+        if (physical < 0 || physical >= (1L << PHYSICAL_TIME_BITS_SIZE)) {
+            throw new IllegalArgumentException("Physical time is out of bounds: " + physical);
+        }
+
+        if (logical < 0 || logical >= (1L << LOGICAL_TIME_BITS_SIZE)) {
+            throw new IllegalArgumentException("Logical time is out of bounds: " + logical);
+        }
+
+        time = (physical << LOGICAL_TIME_BITS_SIZE) | logical;
 
-        this.physical = physical;
-        this.logical = logical;
+        if (time <= 0) {

Review Comment:
   Why can't we use negative value? Because of the comparison?



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/snapshot/outgoing/OutgoingSnapshot.java:
##########
@@ -320,24 +319,28 @@ private SnapshotMvDataResponse.ResponseEntry rowEntry(RowId rowId) {
             return null;
         }
 
-        List<ByteBuffer> buffers = new ArrayList<>(rowVersionsN2O.size());
-        List<HybridTimestamp> commitTimestamps = new ArrayList<>(rowVersionsN2O.size());
+        int count = rowVersionsN2O.size();
+        List<ByteBuffer> buffers = new ArrayList<>(count);
+
+        long[] commitTimestamps = new long[rowVersionsN2O.get(0).isWriteIntent() ? count - 1 : count];

Review Comment:
   Let's extract size into another variable



##########
modules/core/src/main/java/org/apache/ignite/internal/hlc/HybridTimestamp.java:
##########
@@ -55,13 +64,54 @@ public final class HybridTimestamp implements Comparable<HybridTimestamp>, Seria
      * @param logical The logical time.
      */
     public HybridTimestamp(long physical, int logical) {
-        assert physical > 0 : physical;
-        // Value -1 is used in "org.apache.ignite.internal.hlc.HybridClock.update" to produce "0" after the increment.
-        // Real usable value cannot be negative.
-        assert logical >= -1 : logical;
+        if (physical < 0 || physical >= (1L << PHYSICAL_TIME_BITS_SIZE)) {
+            throw new IllegalArgumentException("Physical time is out of bounds: " + physical);
+        }
+
+        if (logical < 0 || logical >= (1L << LOGICAL_TIME_BITS_SIZE)) {
+            throw new IllegalArgumentException("Logical time is out of bounds: " + logical);
+        }
+
+        time = (physical << LOGICAL_TIME_BITS_SIZE) | logical;
 
-        this.physical = physical;
-        this.logical = logical;
+        if (time <= 0) {
+            throw new IllegalArgumentException("Time is out of bounds: " + time);
+        }
+    }
+
+    private HybridTimestamp(long time) {
+        if (time <= 0) {
+            throw new IllegalArgumentException("Time is out of bounds: " + time);
+        }
+
+        this.time = time;
+    }
+
+    /**
+     * Converts primitive {@code long} representation into a hybrid timestamp instance.
+     * {@link #NULL_HYBRID_TIMESTAMP} is interpreted as {@code null}.
+     *
+     * @throws IllegalArgumentException If timestamp is negative.
+     */
+    public static @Nullable HybridTimestamp ofNullable(long time) {

Review Comment:
   Looks a bit weird given that time is a primitive



##########
modules/core/src/main/java/org/apache/ignite/internal/hlc/HybridTimestamp.java:
##########
@@ -100,16 +150,14 @@ public long getPhysical() {
      * @return The logical component.
      */
     public int getLogical() {
-        assert logical >= 0;
-
-        return logical;
+        return (int) (time << PHYSICAL_TIME_BITS_SIZE >>> PHYSICAL_TIME_BITS_SIZE);

Review Comment:
   Why not just `(int) time & 0xFF_FF`?



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