Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NodeId n event-bus subscribers #163

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -337,6 +337,14 @@ public synchronized void stateChanged(LifecycleEvent lifecycleEvent) {
}
// Safeguard to make sure members list is OK after a partition merge
if (lifecycleEvent.getState() == LifecycleEvent.LifecycleState.MERGED) {
Member localMember = hazelcast.getCluster().getLocalMember();
UUID newNodeId = localMember.getUuid();
log.info("Updating nodeId to : " + newNodeId + " from : " + nodeId);
if (!(nodeId.toString().equals(newNodeId.toString()))) {
subsMapHelper.updateOwnSubs(nodeId.toString(), newNodeId.toString());
nodeId = newNodeId;
}

final List<String> currentNodes = getNodes();
Set<String> newNodes = new HashSet<>(currentNodes);
newNodes.removeAll(nodeIds);
Expand Down
Expand Up @@ -142,13 +142,50 @@ public void removeAllForNodes(Set<String> nodeIds) {
}
}

public void updateOwnSubs(String oldId, String newId) {
log.info("updateOwnSubs:: from " + oldId + " to " + newId);
Lock writeLock = republishLock.readLock();
writeLock.lock();

try {

ConcurrentMap<String, Set<RegistrationInfo>> tempOwnSubs = new ConcurrentHashMap<>();
for (Map.Entry<String, Set<RegistrationInfo>> entry : ownSubs.entrySet()) {
String address = entry.getKey();
tempOwnSubs.put(address, new HashSet<>());
for (RegistrationInfo registrationInfo : entry.getValue()) {
tempOwnSubs.compute(address, (add, curr) -> addToSet(registrationInfo, curr));
}
}

for (Map.Entry<String, Set<RegistrationInfo>> entry : tempOwnSubs.entrySet()) {
String address = entry.getKey();
for (RegistrationInfo registrationInfo : entry.getValue()) {
if(registrationInfo.nodeId().equals(oldId)) {
RegistrationInfo newRegistrationInfo = new RegistrationInfo(newId, registrationInfo.seq(), false);

ownSubs.computeIfPresent(address, (add, curr) -> removeFromSet(registrationInfo, curr));
ownSubs.compute(address, (add, curr) -> addToSet(newRegistrationInfo, curr));

map.remove(address, new HazelcastRegistrationInfo(registrationInfo));
map.put(address, new HazelcastRegistrationInfo(newRegistrationInfo));
}
}
}

} finally {
writeLock.unlock();
}
}

public void republishOwnSubs() {
Lock writeLock = republishLock.writeLock();
writeLock.lock();
try {
for (Map.Entry<String, Set<RegistrationInfo>> entry : ownSubs.entrySet()) {
String address = entry.getKey();
for (RegistrationInfo registrationInfo : entry.getValue()) {
log.info("republish for nodeId: " + registrationInfo.nodeId());
map.put(address, new HazelcastRegistrationInfo(registrationInfo));
}
}
Expand Down