Cczzzz opened a new issue #3747:
URL: https://github.com/apache/rocketmq/issues/3747


   I try to reduce raft election time,After I modified the heartbeat timeout, I 
found that.
   under low tps ,Election time is very fast, about 2s。but in high tps 
,Election time is slow。
   
   I looked at the code and found that time wasted in ,
   messageStore.dispatchBehindBytes() == 0
   
   This is waiting for the construction of the logical queue,Will it make a 
difference if I don't wait, is it necessary?
   
   
       @Override public void handle(long term, MemberState.Role role) {
           Runnable runnable = new Runnable() {
               @Override public void run() {
                   long start = System.currentTimeMillis();
                   try {
                       boolean succ = true;
                       log.info("Begin handling broker role change term={} 
role={} currStoreRole={}", term, role, 
messageStore.getMessageStoreConfig().getBrokerRole());
                       switch (role) {
                           case CANDIDATE:
                               if 
(messageStore.getMessageStoreConfig().getBrokerRole() != BrokerRole.SLAVE) {
                                   
brokerController.changeToSlave(dLedgerCommitLog.getId());
                               }
                               break;
                           case FOLLOWER:
                               
brokerController.changeToSlave(dLedgerCommitLog.getId());
                               break;
                           case LEADER:
                               while (true) {
                                   if 
(!dLegerServer.getMemberState().isLeader()) {
                                       succ = false;
                                       break;
                                   }
                                   if 
(dLegerServer.getdLedgerStore().getLedgerEndIndex() == -1) {
                                       break;
                                   }
                                   if 
(dLegerServer.getdLedgerStore().getLedgerEndIndex() == 
dLegerServer.getdLedgerStore().getCommittedIndex()
                                   ) {
                                       //&& messageStore.dispatchBehindBytes() 
== 0) { // is this necessary?
                                       break;
                                   }
                                   Thread.sleep(100);
                               }
                               if (succ) {
                                   messageStore.recoverTopicQueueTable();
                                   
brokerController.changeToMaster(BrokerRole.SYNC_MASTER);
                               }
                               break;
                           default:
                               break;
                       }
                       log.info("Finish handling broker role change succ={} 
term={} role={} currStoreRole={} cost={}", succ, term, role, 
messageStore.getMessageStoreConfig().getBrokerRole(), 
DLedgerUtils.elapsed(start));
                   } catch (Throwable t) {
                       log.info("[MONITOR]Failed handling broker role change 
term={} role={} currStoreRole={} cost={}", term, role, 
messageStore.getMessageStoreConfig().getBrokerRole(), 
DLedgerUtils.elapsed(start), t);
                   }
               }
           };
           executorService.submit(runnable);
       }
   


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