This is an automated email from the ASF dual-hosted git repository. kxiao pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push: new f68c14c7e8a [fix](fe) Add/remove frontends after updating BEBJE #26313 (#26385) f68c14c7e8a is described below commit f68c14c7e8adc66f02aeaefb7468283ec9406109 Author: walter <w41te...@gmail.com> AuthorDate: Fri Nov 3 17:36:34 2023 +0800 [fix](fe) Add/remove frontends after updating BEBJE #26313 (#26385) To ensure exception safety, adding or removing frontends in memory should execute after removing the electable nodes (might throw exceptions) --- .../main/java/org/apache/doris/catalog/Env.java | 32 ++++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java index a30a1cecd1b..02c85ffb39d 100755 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java @@ -2593,16 +2593,20 @@ public class Env { throw new DdlException("frontend name already exists " + nodeName + ". Try again"); } - fe = new Frontend(role, nodeName, host, editLogPort); - LOG.info("add frontend: {}", fe); - - frontends.put(nodeName, fe); BDBHA bdbha = (BDBHA) haProtocol; + bdbha.removeConflictNodeIfExist(host, editLogPort); + int targetFollowerCount = getFollowerCount() + 1; if (role == FrontendNodeType.FOLLOWER || role == FrontendNodeType.REPLICA) { helperNodes.add(new HostInfo(host, editLogPort)); - bdbha.addUnReadyElectableNode(nodeName, getFollowerCount()); + bdbha.addUnReadyElectableNode(nodeName, targetFollowerCount); } - bdbha.removeConflictNodeIfExist(host, editLogPort); + + // Only add frontend after removing the conflict nodes, to ensure the exception safety. + fe = new Frontend(role, nodeName, host, editLogPort); + frontends.put(nodeName, fe); + + LOG.info("add frontend: {}", fe); + editLog.logAddFrontend(fe); } finally { unlock(); @@ -2663,17 +2667,21 @@ public class Env { .getHostPortInAccessibleFormat(host, port) + "]"); } - LOG.info("remove frontend: {}", fe); - - frontends.remove(fe.getNodeName()); - removedFrontends.add(fe.getNodeName()); - + int targetFollowerCount = getFollowerCount() - 1; if (fe.getRole() == FrontendNodeType.FOLLOWER || fe.getRole() == FrontendNodeType.REPLICA) { haProtocol.removeElectableNode(fe.getNodeName()); removeHelperNode(host, port); BDBHA ha = (BDBHA) haProtocol; - ha.removeUnReadyElectableNode(fe.getNodeName(), getFollowerCount()); + ha.removeUnReadyElectableNode(fe.getNodeName(), targetFollowerCount); } + + LOG.info("remove frontend: {}", fe); + + // Only remove frontend after removing the electable node success, to ensure the + // exception safety. + frontends.remove(fe.getNodeName()); + removedFrontends.add(fe.getNodeName()); + editLog.logRemoveFrontend(fe); } finally { unlock(); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org