kangkaisen commented on a change in pull request #2052: Optimize fe start logic URL: https://github.com/apache/incubator-doris/pull/2052#discussion_r338508079
########## File path: fe/src/main/java/org/apache/doris/catalog/Catalog.java ########## @@ -2125,103 +2136,138 @@ private void setCanRead(boolean hasLog, boolean err) { } } else { - canRead = true; + canRead.set(true); + isReady.set(true); + } + } + + public void notifyNewFETypeTransfer(FrontendNodeType newType) { + try { + String msg = "notify new FE type transfer: " + newType; + LOG.warn(msg); + Util.stdoutWithTime(msg); + this.typeTransferQueue.put(newType); + } catch (InterruptedException e) { + LOG.error("failed to put new FE type: {}", newType, e); } } public void createStateListener() { - listener = new Daemon() { - protected void runOneCycle() { - if (formerFeType == feType) { - return; - } + listener = new Daemon("stateListener", STATE_CHANGE_CHECK_INTERVAL_MS) { + @Override + protected synchronized void runOneCycle() { - if (formerFeType == FrontendNodeType.INIT) { - switch (feType) { - case MASTER: { - try { - transferToMaster(); - } catch (IOException e) { - e.printStackTrace(); - } - break; - } - case UNKNOWN: - case FOLLOWER: - case OBSERVER: { - transferToNonMaster(); - break; - } - default: - break; + while (true) { + FrontendNodeType newType = null; + try { + newType = typeTransferQueue.take(); + } catch (InterruptedException e) { + LOG.error("got exception when take FE type from queue", e); + return; + } + Preconditions.checkNotNull(newType); + LOG.info("begin to transfer FE type from {} to {}", feType, newType); + if (feType == newType) { + return; } - return; - } - if (formerFeType == FrontendNodeType.UNKNOWN) { + /* + * INIT -> MASTER: transferToMaster INIT -> FOLLOWER/OBSERVER: + * transferToNonMaster UNKNOWN -> MASTER: transferToMaster UNKNOWN -> + * FOLLOWER/OBSERVER: transferToNonMaster FOLLOWER -> MASTER: transferToMaster + * FOLLOWER/OBSERVER -> INIT/UNKNOWN: set isReady to false + */ Review comment: /* * INIT -> MASTER: transferToMaster * INIT -> FOLLOWER/OBSERVER:transferToNonMaster * UNKNOWN -> MASTER: transferToMaster * UNKNOWN -> FOLLOWER/OBSERVER: transferToNonMaster * FOLLOWER -> MASTER: transferToMaster * FOLLOWER/OBSERVER -> INIT/UNKNOWN: set isReady to false */ ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org