liangyepianzhou commented on code in PR #21417:
URL: https://github.com/apache/pulsar/pull/21417#discussion_r1519203094


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/TableViewImpl.java:
##########
@@ -180,96 +204,157 @@ public void close() throws PulsarClientException {
     }
 
     private void handleMessage(Message<T> msg) {
-        try {
-            if (msg.hasKey()) {
-                String key = msg.getKey();
-                T cur = msg.size() > 0 ? msg.getValue() : null;
-                if (log.isDebugEnabled()) {
-                    log.debug("Applying message from topic {}. key={} 
value={}",
+        readPositions.put(msg.getTopicName(), msg.getMessageId());
+        if (msg.hasKey()) {
+            String key = msg.getKey();
+            T cur = msg.size() > 0 ? msg.getValue() : null;
+            if (log.isDebugEnabled()) {
+                log.debug("Applying message from topic {}. key={} value={}",
+                        conf.getTopicName(),
+                        key,
+                        cur);
+            }
+
+            boolean update = true;
+            if (compactionStrategy != null) {
+                T prev = data.get(key);
+                update = !compactionStrategy.shouldKeepLeft(prev, cur);
+                if (!update) {
+                    log.info("Skipped the message from topic {}. key={} 
value={} prev={}",
                             conf.getTopicName(),
                             key,
-                            cur);
+                            cur,
+                            prev);
+                    compactionStrategy.handleSkippedMessage(key, cur);
                 }
+            }
 
-                boolean update = true;
-                if (compactionStrategy != null) {
-                    T prev = data.get(key);
-                    update = !compactionStrategy.shouldKeepLeft(prev, cur);
-                    if (!update) {
-                        log.info("Skipped the message from topic {}. key={} 
value={} prev={}",
-                                conf.getTopicName(),
-                                key,
-                                cur,
-                                prev);
-                        compactionStrategy.handleSkippedMessage(key, cur);
+            if (update) {
+                try {
+                    listenersMutex.lock();
+                    if (null == cur) {
+                        data.remove(key);
+                    } else {
+                        data.put(key, cur);
                     }
-                }
-
-                if (update) {
-                    try {
-                        listenersMutex.lock();
-                        if (null == cur) {
-                            data.remove(key);
-                        } else {
-                            data.put(key, cur);
-                        }
 
-                        for (BiConsumer<String, T> listener : listeners) {
-                            try {
-                                listener.accept(key, cur);
-                            } catch (Throwable t) {
-                                log.error("Table view listener raised an 
exception", t);
-                            }
+                    for (BiConsumer<String, T> listener : listeners) {
+                        try {
+                            listener.accept(key, cur);
+                        } catch (Throwable t) {
+                            log.error("Table view listener raised an 
exception", t);
                         }
-                    } finally {
-                        listenersMutex.unlock();
                     }
+                } finally {
+                    listenersMutex.unlock();
                 }
             }
-        } finally {
-            msg.release();
         }
     }
 
-    private CompletableFuture<Reader<T>> readAllExistingMessages(Reader<T> 
reader) {
+    @Override
+    public CompletableFuture<Void> refreshAsync() {
+        CompletableFuture<Void> completableFuture = new CompletableFuture<>();
+        reader.thenCompose(reader -> buildFreshTask(reader, 
completableFuture).thenAccept(lastMessageIds -> {
+            // After get the response of lastMessageIds, put the future and 
result into `refreshMap`
+            // and then filter out partitions that has been read to the 
lastMessageID.
+            synchronized (this) {
+                refreshRequests.put(completableFuture, lastMessageIds);
+                filterReceivedMessages(lastMessageIds);
+                // If there is no new messages, the refresh operation could be 
completed right now.
+                if (lastMessageIds.isEmpty()) {
+                    refreshRequests.remove(completableFuture);
+                    completableFuture.complete(null);

Review Comment:
   You are right. This logic does not need to be synchronized.



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