rpuch commented on code in PR #3475:
URL: https://github.com/apache/ignite-3/pull/3475#discussion_r1538671441


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/LowWatermarkImpl.java:
##########
@@ -292,9 +272,87 @@ private void setLowWatermark(@Nullable HybridTimestamp 
newLowWatermark) {
         updateLowWatermarkLock.writeLock().lock();
 
         try {
+            assert newLowWatermark == null || lowWatermark == null || 
newLowWatermark.compareTo(lowWatermark) > 0 :
+                    "Low watermark should only grow: [cur=" + lowWatermark + 
", new=" + newLowWatermark + "]";
+
             lowWatermark = newLowWatermark;
         } finally {
             updateLowWatermarkLock.writeLock().unlock();
         }
     }
+
+    void onReceiveNetworkMessage(NetworkMessage message, ClusterNode sender, 
@Nullable Long correlationId) {
+        inBusyLock(busyLock, () -> {
+            if (!(message instanceof GetLowWatermarkRequest)) {
+                return;
+            }
+
+            assert correlationId != null : sender;
+
+            messagingService.respond(
+                    sender,
+                    
MESSAGES_FACTORY.getLowWatermarkResponse().lowWatermark(hybridTimestampToLong(lowWatermark)).build(),
+                    correlationId
+            );
+        });
+    }
+
+    @Override
+    public void updateLowWatermark(HybridTimestamp newLowWatermark) {
+        inBusyLock(busyLock, () -> {
+            LowWatermarkCandidate newLowWatermarkCandidate = new 
LowWatermarkCandidate(newLowWatermark, new CompletableFuture<>());
+            LowWatermarkCandidate oldLowWatermarkCandidate;
+
+            do {
+                oldLowWatermarkCandidate = lowWatermarkCandidate.get();
+
+                // If another candidate contains a larger low watermark, then 
there is no need to update.
+                if 
(oldLowWatermarkCandidate.lowWatermark().compareTo(newLowWatermark) >= 0) {
+                    return;
+                }
+            } while 
(!lowWatermarkCandidate.compareAndSet(oldLowWatermarkCandidate, 
newLowWatermarkCandidate));
+
+            // We will start the update as soon as the previous one finishes.
+            oldLowWatermarkCandidate.updateFuture()
+                    .thenComposeAsync(unused -> 
updateAndNotify(newLowWatermark), scheduledThreadPool)
+                    .whenComplete((unused, throwable) -> {
+                        if (throwable != null) {
+                            
newLowWatermarkCandidate.updateFuture().completeExceptionally(throwable);

Review Comment:
   It's not critical, so it's up to you. But such little fixes, if applied 
systematically, can make it substantially easier to work with the code as a 
whole :)



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

Reply via email to