Skip to content

Commit ebda7ba

Browse files
authored
[Fix](FQDN) fix slow when ip changed (apache#17455)
1 parent cb7d0fd commit ebda7ba

6 files changed

Lines changed: 21 additions & 138 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,15 +1456,6 @@ private void transferToNonMaster(FrontendNodeType newType) {
14561456

14571457
// transfer from INIT/UNKNOWN to OBSERVER/FOLLOWER
14581458

1459-
// add helper sockets
1460-
if (Config.edit_log_type.equalsIgnoreCase("bdb")) {
1461-
for (Frontend fe : frontends.values()) {
1462-
if (fe.getRole() == FrontendNodeType.FOLLOWER || fe.getRole() == FrontendNodeType.REPLICA) {
1463-
((BDBHA) getHaProtocol()).addHelperSocket(fe.getIp(), fe.getEditLogPort());
1464-
}
1465-
}
1466-
}
1467-
14681459
if (replayer == null) {
14691460
createReplayer();
14701461
replayer.start();
@@ -2468,7 +2459,6 @@ public void addFrontend(FrontendNodeType role, String ip, String hostname, int e
24682459
frontends.put(nodeName, fe);
24692460
BDBHA bdbha = (BDBHA) haProtocol;
24702461
if (role == FrontendNodeType.FOLLOWER || role == FrontendNodeType.REPLICA) {
2471-
bdbha.addHelperSocket(ip, editLogPort);
24722462
helperNodes.add(new HostInfo(ip, hostname, editLogPort));
24732463
bdbha.addUnReadyElectableNode(nodeName, getFollowerCount());
24742464
}

‎fe/fe-core/src/main/java/org/apache/doris/common/proc/FrontendsProcNode.java‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import org.apache.doris.catalog.Env;
2121
import org.apache.doris.common.Config;
22-
import org.apache.doris.common.Pair;
2322
import org.apache.doris.common.util.NetUtils;
2423
import org.apache.doris.common.util.TimeUtils;
2524
import org.apache.doris.qe.ConnectContext;
@@ -142,7 +141,7 @@ public static void getFrontendsInfo(Env env, List<List<String>> infos) {
142141
}
143142

144143
private static boolean isHelperNode(List<HostInfo> helperNodes, Frontend fe) {
145-
return helperNodes.stream().anyMatch(p -> p.getIp().equals(fe.getIp()) && p.getPort() == fe.getEditLogPort());
144+
return helperNodes.stream().anyMatch(p -> fe.toHostInfo().isSame(p));
146145
}
147146

148147
private static boolean isJoin(List<InetSocketAddress> allFeHosts, Frontend fe) {
@@ -169,12 +168,4 @@ private static boolean isJoin(List<InetSocketAddress> allFeHosts, Frontend fe) {
169168
}
170169
return false;
171170
}
172-
173-
private static List<Pair<String, Integer>> convertToHostPortPair(List<InetSocketAddress> addrs) {
174-
List<Pair<String, Integer>> hostPortPair = Lists.newArrayList();
175-
for (InetSocketAddress addr : addrs) {
176-
hostPortPair.add(Pair.of(addr.getAddress().getHostAddress(), addr.getPort()));
177-
}
178-
return hostPortPair;
179-
}
180171
}

‎fe/fe-core/src/main/java/org/apache/doris/ha/BDBHA.java‎

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.apache.doris.journal.bdbje.BDBEnvironment;
2222

2323
import com.google.common.collect.Lists;
24-
import com.google.common.collect.Sets;
2524
import com.sleepycat.bind.tuple.TupleBinding;
2625
import com.sleepycat.je.Database;
2726
import com.sleepycat.je.DatabaseEntry;
@@ -68,11 +67,6 @@ public BDBHA(BDBEnvironment env, String nodeName) {
6867
this.nodeName = nodeName;
6968
}
7069

71-
@Override
72-
public long getEpochNumber() {
73-
return 0;
74-
}
75-
7670
@Override
7771
public boolean fencing() {
7872
Database epochDb = environment.getEpochDB();
@@ -162,47 +156,6 @@ public InetSocketAddress getLeader() {
162156
return rn.getSocketAddress();
163157
}
164158

165-
@Override
166-
public List<InetSocketAddress> getNoneLeaderNodes() {
167-
ReplicationGroupAdmin replicationGroupAdmin = environment.getReplicationGroupAdmin();
168-
if (replicationGroupAdmin == null) {
169-
return null;
170-
}
171-
List<InetSocketAddress> ret = new ArrayList<InetSocketAddress>();
172-
try {
173-
ReplicationGroup replicationGroup = replicationGroupAdmin.getGroup();
174-
for (ReplicationNode replicationNode : replicationGroup.getSecondaryNodes()) {
175-
ret.add(replicationNode.getSocketAddress());
176-
}
177-
for (ReplicationNode replicationNode : replicationGroup.getElectableNodes()) {
178-
if (!replicationNode.getName().equals(replicationGroupAdmin.getMasterNodeName())) {
179-
ret.add(replicationNode.getSocketAddress());
180-
}
181-
}
182-
} catch (UnknownMasterException e) {
183-
LOG.warn("Catch UnknownMasterException when calling getNoneLeaderNodes.", e);
184-
return null;
185-
}
186-
return ret;
187-
}
188-
189-
@Override
190-
public void transferToMaster() {
191-
192-
}
193-
194-
@Override
195-
public void transferToNonMaster() {
196-
197-
}
198-
199-
@Override
200-
public boolean isLeader() {
201-
ReplicationGroupAdmin replicationGroupAdmin = environment.getReplicationGroupAdmin();
202-
String leaderName = replicationGroupAdmin.getMasterNodeName();
203-
return leaderName.equals(nodeName);
204-
}
205-
206159
@Override
207160
public boolean removeElectableNode(String nodeName) {
208161
ReplicationGroupAdmin replicationGroupAdmin = environment.getReplicationGroupAdmin();
@@ -238,27 +191,6 @@ public boolean updateNodeAddress(String nodeName, String newHostName, int port)
238191
return true;
239192
}
240193

241-
// When new Follower FE is added to the cluster, it should also be added to the
242-
// helper sockets in
243-
// ReplicationGroupAdmin, in order to fix the following case:
244-
// 1. A Observer starts with helper of master FE.
245-
// 2. Master FE is dead, new Master is elected.
246-
// 3. Observer's helper sockets only contains the info of the dead master FE.
247-
// So when you try to get frontends' info from this Observer, it will throw the
248-
// Exception:
249-
// "Could not determine master from helpers at:[/dead master FE host:port]"
250-
public void addHelperSocket(String ip, Integer port) {
251-
ReplicationGroupAdmin replicationGroupAdmin = environment.getReplicationGroupAdmin();
252-
Set<InetSocketAddress> helperSockets =
253-
Sets.newHashSet(replicationGroupAdmin.getHelperSockets());
254-
InetSocketAddress newHelperSocket = new InetSocketAddress(ip, port);
255-
if (!helperSockets.contains(newHelperSocket)) {
256-
helperSockets.add(newHelperSocket);
257-
environment.setNewReplicationGroupAdmin(helperSockets);
258-
LOG.info("add {}:{} to helper sockets", ip, port);
259-
}
260-
}
261-
262194
public void removeConflictNodeIfExist(String host, int port) {
263195
ReplicationGroupAdmin replicationGroupAdmin = environment.getReplicationGroupAdmin();
264196
if (replicationGroupAdmin == null) {

‎fe/fe-core/src/main/java/org/apache/doris/ha/HAProtocol.java‎

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,18 @@
2121
import java.util.List;
2222

2323
public interface HAProtocol {
24-
// get current epoch number
25-
public long getEpochNumber();
26-
2724
// increase epoch number by one
28-
public boolean fencing();
25+
boolean fencing();
2926

3027
// get observer nodes in the current group
31-
public List<InetSocketAddress> getObserverNodes();
28+
List<InetSocketAddress> getObserverNodes();
3229

3330
// get replica nodes in the current group
34-
public List<InetSocketAddress> getElectableNodes(boolean leaderIncluded);
31+
List<InetSocketAddress> getElectableNodes(boolean leaderIncluded);
3532

3633
// get the leader of current group
37-
public InetSocketAddress getLeader();
38-
39-
// get all the nodes except leader in the current group
40-
public List<InetSocketAddress> getNoneLeaderNodes();
41-
42-
// transfer from nonMaster(unknown, follower or init) to master
43-
public void transferToMaster();
44-
45-
// transfer to non-master
46-
public void transferToNonMaster();
47-
48-
// check if the current node is leader
49-
public boolean isLeader();
34+
InetSocketAddress getLeader();
5035

5136
// remove a node from the group
52-
public boolean removeElectableNode(String nodeName);
37+
boolean removeElectableNode(String nodeName);
5338
}

‎fe/fe-core/src/main/java/org/apache/doris/journal/bdbje/BDBEnvironment.java‎

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import org.apache.doris.common.Config;
2222
import org.apache.doris.ha.BDBHA;
2323
import org.apache.doris.ha.BDBStateChangeListener;
24+
import org.apache.doris.ha.FrontendNodeType;
2425
import org.apache.doris.ha.HAProtocol;
26+
import org.apache.doris.system.Frontend;
2527

2628
import com.sleepycat.je.Database;
2729
import com.sleepycat.je.DatabaseConfig;
@@ -51,11 +53,11 @@
5153
import java.net.InetSocketAddress;
5254
import java.util.ArrayList;
5355
import java.util.Collections;
54-
import java.util.HashSet;
5556
import java.util.List;
5657
import java.util.Set;
5758
import java.util.concurrent.TimeUnit;
5859
import java.util.concurrent.locks.ReentrantReadWriteLock;
60+
import java.util.stream.Collectors;
5961

6062
/* this class contains the reference to bdb environment.
6163
* including all the opened databases and the replicationGroupAdmin.
@@ -73,7 +75,6 @@ public class BDBEnvironment {
7375
private ReplicationConfig replicationConfig;
7476
private DatabaseConfig dbConfig;
7577
private Database epochDB = null; // used for fencing
76-
private ReplicationGroupAdmin replicationGroupAdmin = null;
7778
private ReentrantReadWriteLock lock;
7879
private List<Database> openedDatabases;
7980

@@ -153,29 +154,6 @@ public void setup(File envHome, String selfNodeName, String selfNodeHostPort,
153154
// open the environment
154155
replicatedEnvironment = new ReplicatedEnvironment(envHome, replicationConfig, environmentConfig);
155156

156-
// get replicationGroupAdmin object.
157-
Set<InetSocketAddress> adminNodes = new HashSet<InetSocketAddress>();
158-
// 1. add helper node
159-
// If host is ipv6 address there will be more than one colon in host str
160-
int helperColonIdx = helperHostPort.lastIndexOf(":");
161-
String helperHost = helperHostPort.substring(0, helperColonIdx);
162-
int helperPort = Integer.parseInt(helperHostPort.substring(helperColonIdx + 1));
163-
InetSocketAddress helper = new InetSocketAddress(helperHost, helperPort);
164-
adminNodes.add(helper);
165-
LOG.info("add helper[{}] as ReplicationGroupAdmin", helperHostPort);
166-
167-
// 2. add self if is electable
168-
if (!selfNodeHostPort.equals(helperHostPort) && Env.getCurrentEnv().isElectable()) {
169-
int selfColonIdx = selfNodeHostPort.lastIndexOf(":");
170-
String selfHost = selfNodeHostPort.substring(0, selfColonIdx);
171-
int selfPort = Integer.parseInt(selfNodeHostPort.substring(selfColonIdx + 1));
172-
InetSocketAddress self = new InetSocketAddress(selfHost, selfPort);
173-
adminNodes.add(self);
174-
LOG.info("add self[{}] as ReplicationGroupAdmin", selfNodeHostPort);
175-
}
176-
177-
replicationGroupAdmin = new ReplicationGroupAdmin(PALO_JOURNAL_GROUP, adminNodes);
178-
179157
// get a BDBHA object and pass the reference to Catalog
180158
HAProtocol protocol = new BDBHA(this, selfNodeName);
181159
Env.getCurrentEnv().setHaProtocol(protocol);
@@ -211,11 +189,13 @@ public void setup(File envHome, String selfNodeName, String selfNodeHostPort,
211189
}
212190

213191
public ReplicationGroupAdmin getReplicationGroupAdmin() {
214-
return this.replicationGroupAdmin;
215-
}
216-
217-
public void setNewReplicationGroupAdmin(Set<InetSocketAddress> newHelperNodes) {
218-
this.replicationGroupAdmin = new ReplicationGroupAdmin(PALO_JOURNAL_GROUP, newHelperNodes);
192+
Set<InetSocketAddress> addresses = Env.getCurrentEnv()
193+
.getFrontends(FrontendNodeType.FOLLOWER)
194+
.stream()
195+
.filter(Frontend::isAlive)
196+
.map(fe -> new InetSocketAddress(fe.getIp(), fe.getEditLogPort()))
197+
.collect(Collectors.toSet());
198+
return new ReplicationGroupAdmin(PALO_JOURNAL_GROUP, addresses);
219199
}
220200

221201
// Return a handle to the epochDB

‎fe/fe-core/src/main/java/org/apache/doris/system/Frontend.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.doris.ha.FrontendNodeType;
2727
import org.apache.doris.persist.gson.GsonUtils;
2828
import org.apache.doris.system.HeartbeatResponse.HbStatus;
29+
import org.apache.doris.system.SystemInfoService.HostInfo;
2930

3031
import com.google.gson.annotations.SerializedName;
3132

@@ -195,4 +196,8 @@ public String toString() {
195196
public void setIp(String ip) {
196197
this.ip = ip;
197198
}
199+
200+
public HostInfo toHostInfo() {
201+
return new HostInfo(ip, hostName, editLogPort);
202+
}
198203
}

0 commit comments

Comments
 (0)