coldestlin opened a new issue, #15992: URL: https://github.com/apache/dolphinscheduler/issues/15992
### Search before asking - [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues. ### What happened According to PriorityBlockingQueue document, iterator order is undefined. > This class and its iterator implement all of the optional methods of the Collection and Iterator interfaces. The Iterator provided in method iterator() and the Spliterator provided in method `iterator()` are not guaranteed to traverse the elements of the PriorityBlockingQueue in any particular order. If you need ordered traversal, consider using `Arrays.sort(pq.toArray())`. In dolphinscheduler operation, Every `WorkerGroupRefreshInterval`, `ServerNodeManager.refreshNodesAndGroupMappings` will be triggerred, and the master slot index will be refreshed by `refreshMasterList`. But iterator order of MasterPriorityQueue is undefined, thus even if the host server create time is not affected, the slot index may change every `WorkerGroupRefreshInterval`. This will make slot assigment between servers change unintentionally. ```java private void refreshMasterList() { hostIndexMap.clear(); Iterator<Server> iterator = queue.iterator(); int index = 0; while (iterator.hasNext()) { Server server = iterator.next(); String addr = NetUtils.getAddr(server.getHost(), server.getPort()); hostIndexMap.put(addr, index); index += 1; } } ``` ```java class WorkerNodeInfoAndGroupDbSyncTask implements Runnable { @Override public void run() { try { // sync worker node info refreshNodesAndGroupMappings(); } catch (Exception e) { log.error("WorkerNodeInfoAndGroupDbSyncTask error:", e); } } } ``` ```java /** * Refresh master/worker nodes and worker group mapping information */ private void refreshNodesAndGroupMappings() { updateWorkerNodes(); updateWorkerGroupMappings(); notifyWorkerInfoChangeListeners(); updateMasterNodes(); notifyMasterInfoChangeListeners(); } ``` ### What you expected to happen If not server is added or removed, the slot index should be the same guranteed. ### How to reproduce According to document, the iteration order is not guranteed. ### Anything else _No response_ ### Version dev ### Are you willing to submit PR? - [X] Yes I am willing to submit a PR! ### Code of Conduct - [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
