Browse Source

ZKDiscoveryService: fix potential outdated server info on recalculatePartitions. info logs added on application event

pull/4460/head
Sergey Matvienko 6 years ago
committed by Andrew Shvayka
parent
commit
562637ad34
  1. 14
      common/queue/src/main/java/org/thingsboard/server/queue/discovery/ZkDiscoveryService.java

14
common/queue/src/main/java/org/thingsboard/server/queue/discovery/ZkDiscoveryService.java

@ -125,8 +125,10 @@ public class ZkDiscoveryService implements DiscoveryService, PathChildrenCacheLi
log.debug("Ignoring application ready event, ZK client is not started, ZK client state [{}]", client.getState()); log.debug("Ignoring application ready event, ZK client is not started, ZK client state [{}]", client.getState());
return; return;
} }
log.info("Going to publish current server...");
publishCurrentServer(); publishCurrentServer();
partitionService.recalculatePartitions(serviceInfoProvider.getServiceInfo(), getOtherServers()); log.info("Going to recalculate partitions...");
recalculatePartitions();
} }
public synchronized void publishCurrentServer() { public synchronized void publishCurrentServer() {
@ -281,11 +283,19 @@ public class ZkDiscoveryService implements DiscoveryService, PathChildrenCacheLi
case CHILD_ADDED: case CHILD_ADDED:
case CHILD_UPDATED: case CHILD_UPDATED:
case CHILD_REMOVED: case CHILD_REMOVED:
partitionService.recalculatePartitions(serviceInfoProvider.getServiceInfo(), getOtherServers()); recalculatePartitions();
break; break;
default: default:
break; break;
} }
} }
/**
* A single entry point to recalculate partitions
* Synchronized to ensure that other servers info is up to date
* */
synchronized void recalculatePartitions() {
partitionService.recalculatePartitions(serviceInfoProvider.getServiceInfo(), getOtherServers());
}
} }

Loading…
Cancel
Save