You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ea...@apache.org on 2019/05/27 01:56:48 UTC
[incubator-iotdb] branch cluster updated: update RaftUtil
This is an automated email from the ASF dual-hosted git repository.
east pushed a commit to branch cluster
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
The following commit(s) were added to refs/heads/cluster by this push:
new 3964bcd update RaftUtil
new cff0544 Merge remote-tracking branch 'origin/cluster' into cluster
3964bcd is described below
commit 3964bcd0a7c6992caf1658a2edfade9cbfe9623e
Author: mdf369 <95...@qq.com>
AuthorDate: Mon May 27 09:34:23 2019 +0800
update RaftUtil
---
.../src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java b/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java
index 3213472..59fddf8 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java
@@ -144,8 +144,13 @@ public class RaftUtils {
* @return leader id
*/
public static PeerId getLocalLeaderPeerID(String groupId) {
- groupLeaderCache.putIfAbsent(groupId, getRandomPeerID(groupId));
- PeerId leader = groupLeaderCache.get(groupId);
+ PeerId leader;
+ if (groupLeaderCache.containsKey(groupId)) {
+ leader = groupLeaderCache.get(groupId);
+ } else {
+ leader = getRandomPeerID(groupId);
+ groupLeaderCache.put(groupId, leader);
+ }
LOGGER.debug("Get local cached leader {} of group {}.", leader, groupId);
return leader;
}