belliottsmith commented on a change in pull request #1:
URL: https://github.com/apache/cassandra-accord/pull/1#discussion_r757596322



##########
File path: accord-core/src/main/java/accord/local/Node.java
##########
@@ -116,37 +165,43 @@ public Timestamp uniqueNow()
         return now.updateAndGet(cur -> {
             // TODO: this diverges from proof; either show isomorphism or make 
consistent
             long now = nowSupplier.getAsLong();
-            if (now > cur.real) return new Timestamp(now, 0, id);
-            else return new Timestamp(cur.real, cur.logical + 1, id);
+            long epoch = Math.max(cur.epoch, topology.epoch());
+            return (now > cur.real)
+                 ? new Timestamp(epoch, now, 0, id)
+                 : new Timestamp(epoch, cur.real, cur.logical + 1, id);
         });
     }
 
     public Timestamp uniqueNow(Timestamp atLeast)
     {
         if (now.get().compareTo(atLeast) < 0)
-            now.accumulateAndGet(atLeast, (a, b) -> a.compareTo(b) < 0 ? new 
Timestamp(b.real, b.logical + 1, id) : a);
-
-        return now.updateAndGet(cur -> {
-            // TODO: this diverges from proof; either show isomorphism or make 
consistent
-            long now = nowSupplier.getAsLong();
-            if (now > cur.real) return new Timestamp(now, 0, id);
-            else return new Timestamp(cur.real, cur.logical + 1, id);
-        });
+            now.accumulateAndGet(atLeast, (current, proposed) -> {
+                Timestamp timestamp = proposed.compareTo(current) <= 0
+                        ? new Timestamp(current.epoch, current.real, 
current.logical + 1, id)
+                        : proposed;
+                return timestamp.withMinEpoch(topology.epoch());

Review comment:
       Could we just return `proposed.compareTo(current) <= 0 ? new 
Timestamp(max(current.epoch, proposed.epoch), max(current.real, proposed.real), 
current.logical + 1, id) : proposed;`?
   
   Then we could call `uniqueNow` on witnessing a new epoch with `new 
Timestamp(epoch, 0, 0, id)` and it should take care of itself without polling 
this value on each update? We probably anyway want to ensure we don't go back 
in `real` time so we don't mess up any timestamps we'll generate for Cassandra




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to