You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/06/11 11:52:08 UTC

[GitHub] [rocketmq] RongtongJin commented on a diff in pull request #4449: [Summer of code] Use confirm offset in ReputMessageService

RongtongJin commented on code in PR #4449:
URL: https://github.com/apache/rocketmq/pull/4449#discussion_r895015426


##########
store/src/main/java/org/apache/rocketmq/store/ha/autoswitch/AutoSwitchHAService.java:
##########
@@ -220,14 +220,21 @@ public void updateConnectionLastCaughtUpTime(final String slaveAddress, final lo
      * Get confirm offset (min slaveAckOffset of all syncStateSet members)
      */
     public long getConfirmOffset() {
-        final Set<String> currentSyncStateSet = getSyncStateSet();
-        long confirmOffset = this.defaultMessageStore.getMaxPhyOffset();
-        for (HAConnection connection : this.connectionList) {
-            if (currentSyncStateSet.contains(connection.getClientAddress())) {
-                confirmOffset = Math.min(confirmOffset, connection.getSlaveAckOffset());
+        if (this.defaultMessageStore.getMessageStoreConfig().getBrokerRole() == BrokerRole.SYNC_MASTER) {
+            final Set<String> currentSyncStateSet = getSyncStateSet();
+            long confirmOffset = this.defaultMessageStore.getMaxPhyOffset();
+            for (HAConnection connection : this.connectionList) {
+                if (currentSyncStateSet.contains(connection.getClientAddress())) {
+                    confirmOffset = Math.min(confirmOffset, connection.getSlaveAckOffset());
+                }
+            }
+            return confirmOffset;
+        } else {
+            if (this.haClient != null) {
+                return this.haClient.getConfirmOffset();

Review Comment:
   这里可以做一个优化。。把confirmOffset记录下来,利用空间换时间,再每次slave ack的时候更新。。不然每次reput一条消息都会调用一下,比较消耗资源。



-- 
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: dev-unsubscribe@rocketmq.apache.org

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