Skip to content

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

@coldestlin

Description

@coldestlin

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions