Skip to content

Commit c2a44b1

Browse files
author
chengyitian
committed
AJ-672: fix issue about backupSite switch when subOnce = true;
1 parent 155df52 commit c2a44b1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/com/xxdb/streaming/client/AbstractClient.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public boolean tryReconnect(String topic) {
236236
}
237237
} else {
238238
// if set backupSites
239-
synchronized (reconnectTable) {
239+
synchronized (this) {
240240
topic = HATopicToTrueTopic.get(topic);
241241
queueManager.removeQueue(topic);
242242
Site[] sites;
@@ -289,12 +289,22 @@ public boolean tryReconnect(String topic) {
289289
siteList.remove((int) currentSiteIndex);
290290
// update sites
291291
sites = siteList.toArray(new Site[0]);
292+
trueTopicToSites.put(topic, sites);
292293

293294
// Calculate the index of the newly successful connection node after a successful deletion.
294295
if (successfulSiteIndex > currentSiteIndex) {
295296
// If the successfully connected node is after the deleted node, reduce the index by 1.
296297
successfulSiteIndex -= 1;
297298
}
299+
300+
// put sites to new sub topic.
301+
for (String key : trueTopicToSites.keySet()) {
302+
// 重新为 key 赋值
303+
if (key.contains(sites[successfulSiteIndex].host+":"+sites[successfulSiteIndex].port)) {
304+
trueTopicToSites.put(key, sites); // 更新操作是安全的
305+
}
306+
}
307+
298308
// update currentSiteIndexMap to new successfully connected site's index;
299309
currentSiteIndexMap.put(topic, successfulSiteIndex);
300310
} else if (reconnected) {

0 commit comments

Comments
 (0)