ascherbakoff commented on code in PR #4700:
URL: https://github.com/apache/ignite-3/pull/4700#discussion_r1848367854


##########
modules/core/src/main/java/org/apache/ignite/internal/hlc/HybridClockImpl.java:
##########
@@ -38,45 +37,34 @@ public class HybridClockImpl implements HybridClock {
     /**
      * Var handle for {@link #latestTime}.
      */
-    private static final VarHandle LATEST_TIME;
-
-    static {
-        try {
-            LATEST_TIME = 
MethodHandles.lookup().findVarHandle(HybridClockImpl.class, "latestTime", 
long.class);
-        } catch (NoSuchFieldException | IllegalAccessException e) {
-            throw new ExceptionInInitializerError(e);
-        }
-    }
+    private static final AtomicLongFieldUpdater<HybridClockImpl> LATEST_TIME = 
AtomicLongFieldUpdater.newUpdater(HybridClockImpl.class,
+            "latestTime");
 
     private volatile long latestTime;
 
     private final List<ClockUpdateListener> updateListeners = new 
CopyOnWriteArrayList<>();
 
     /**
-     * The constructor which initializes the latest time to current time by 
system clock.
-     */
-    public HybridClockImpl() {
-        this.latestTime = currentTime();
-    }
-
-    /**
-     * System current time in milliseconds shifting left to free insignificant 
bytes.
-     * This method is marked with a public modifier to mock in tests because 
there is no way to mock currentTimeMillis.
+     * Returns current physical time in milliseconds.
      *
-     * @return Current time in milliseconds shifted right on two bytes.
+     * @return Current time.
      */
-    public static long currentTime() {
-        return System.currentTimeMillis() << LOGICAL_TIME_BITS_SIZE;
+    protected long physicalTime() {
+        return System.currentTimeMillis();
     }
 
     @Override
-    public long nowLong() {
+    public final long nowLong() {
         while (true) {
-            long now = currentTime();
+            long now = physicalTime() << LOGICAL_TIME_BITS_SIZE;
 
             // Read the latest time after accessing UTC time to reduce 
contention.
             long oldLatestTime = latestTime;
 
+            if (oldLatestTime >= now) {
+                return LATEST_TIME.incrementAndGet(this);
+            }
+
             long newLatestTime = max(oldLatestTime + 1, now);

Review 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-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to