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

[Bug] [dolphinscheduler-service] iterator order of MasterPriorityQueue is undefined #15992

Closed
3 tasks done
coldestlin opened this issue May 13, 2024 · 0 comments · Fixed by #15993
Closed
3 tasks done
Assignees
Labels
bug Something isn't working priority:high

Comments

@coldestlin
Copy link
Contributor

Search before asking

  • I had searched in the issues 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.

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;
        }
    }
    class WorkerNodeInfoAndGroupDbSyncTask implements Runnable {

        @Override
        public void run() {
            try {
                // sync worker node info
                refreshNodesAndGroupMappings();
            } catch (Exception e) {
                log.error("WorkerNodeInfoAndGroupDbSyncTask error:", e);
            }
        }
    }
    /**
     * 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?

  • Yes I am willing to submit a PR!

Code of Conduct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants