incubator-hugegraph icon indicating copy to clipboard operation
incubator-hugegraph copied to clipboard

[TASK] Refactor: phase 2 cleanup — remove legacy master-worker scheduler dead code

Open bitflicker64 opened this issue 4 months ago • 2 comments

Background

PR #3082 soft-disabled the pre-PD master-worker scheduling path and intentionally left
deprecated config handling, role-election wiring, and ServerInfoManager persistence as
compatibility scaffolding. This issue tracks the follow-up physical removal ("phase 2")
called out in the merge comment ("TODO: cleanup legacy code/configs in phrase2").

Scope of removal

1. Deprecated config warnings + transition tests (low risk)

  • task.scheduler_type warning block in StandardHugeGraph
  • ENABLE_SERVER_ROLE_ELECTION warning in GraphManager.initNodeRole()
  • ServerOptions.ENABLE_SERVER_ROLE_ELECTION config key declaration
  • Transition-only tests: testOpenGraphWithDeprecatedTaskSchedulerType and
    testGraphManagerWarnsOnRoleElection

2. Role election infrastructure (medium risk — touches HugeGraph interface)

All of the following are dead code — nothing starts the state machine after #3082:

  • StandardHugeGraph.initRoleStateMachine(Id) and the roleElectionStateMachine field
  • roleElectionStateMachine() from the HugeGraph interface and HugeGraphAuthProxy
  • GraphManager.initRoleStateMachine() and GraphManager.supportRoleElection() (never called)
  • StandardRoleListener class (never instantiated)
  • TaskManager.onAsRoleMaster() / onAsRoleWorker() no-ops
  • TaskManager.schedulerExecutor (task-scheduler-%d) zombie thread pool and closeSchedulerTx()
  • RoleElectionOptions config key declarations

3. ServerInfoManager dead persistence path + HugeServerInfo deletion (medium risk)

  • ServerInfoManager.init() (no-op), heartbeat() (no-op), tx(), call(), and the
    dbExecutor field — the live methods (selfNodeId, selfIsMaster, initServerInfo, etc.)
    must be kept since DistributedTaskScheduler still uses them
  • HugeServerInfo.java — entire class, including ~server vertex schema and load tracking
  • serverInfoDbExecutor thread pool and SERVER_INFO_DB_WORKER constant from TaskManager
  • serverInfoDbExecutor parameter from StandardTaskScheduler, TaskAndResultScheduler,
    and DistributedTaskScheduler constructors
  • Update ServerInfoManagerTest and TaskSchedulerServerInfoTest accordingly

Suggested PR split

PR Scope Risk
PR A Deprecated config warnings + transition tests Low
PR B Role election infrastructure Medium
PR C ServerInfoManager surgery + HugeServerInfo deletion Medium

Important constraints

  • ServerInfoManager itself is not deleted — DistributedTaskScheduler still uses
    selfNodeId() for task lock scoping.
  • TaskScheduler.serverManager() interface method stays for the same reason.
  • StandardHugeGraph.serverStarted() must keep the initServerInfo(nodeInfo) call —
    only the initRoleStateMachine(nodeInfo.nodeId()) call is removed.
  • Before deleting HugeServerInfo, audit HugeVertex.java for fromVertex dispatch
    references and any initSchemaIfNeeded() call sites in system init.

Related

  • #3082

bitflicker64 avatar Jul 09 '26 08:07 bitflicker64

Implementation Plan

Splitting into 3 PRs ordered by risk. Each PR is independently reviewable and mergeable.


PR A — Remove deprecated config warnings + transition tests

Files to change:

  • hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java

    • Delete the task.scheduler_type containsKey warning block (~lines 229-234)
  • hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java

    • In initNodeRole(): remove the enableRoleElection local variable and the if (enableRoleElection) warning block; keep only the SERVER_ROLE read and initNodeRole() call
  • hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java

    • Delete the ENABLE_SERVER_ROLE_ELECTION config key declaration
  • hugegraph-server/hugegraph-test/.../core/MultiGraphsTest.java

    • Delete testOpenGraphWithDeprecatedTaskSchedulerType
  • hugegraph-server/hugegraph-test/.../unit/core/TaskSchedulerServerInfoTest.java

    • Delete testGraphManagerWarnsOnRoleElection

No interface changes. Compile + existing tests should pass as-is.


PR B — Remove role election infrastructure

Files to change:

  • StandardHugeGraph.java

    • In serverStarted(): remove the this.initRoleStateMachine(nodeInfo.nodeId()) call (keep initServerInfo)
    • Delete the entire initRoleStateMachine(Id serverId) private method
    • Delete the roleElectionStateMachine field declaration
    • Delete the roleElectionStateMachine() public method
  • HugeGraph.java (interface)

    • Remove the roleElectionStateMachine() method declaration
  • HugeGraphAuthProxy.java

    • Remove the roleElectionStateMachine() override and its delegate call
  • GraphManager.java

    • Delete initRoleStateMachine() method entirely (never called)
    • Delete supportRoleElection() method entirely (never called)
    • In serverStarted(): delete the dead if (!this.globalNodeRoleInfo.nodeRole().computer() && ...) block
  • TaskManager.java

    • Delete onAsRoleMaster() and onAsRoleWorker() no-op methods
    • Delete schedulerExecutor field and TASK_SCHEDULER constant
    • Delete schedulerExecutor allocation in constructor
    • Delete closeSchedulerTx() private method
    • Remove closeSchedulerTx(graph) call inside closeScheduler()
    • Delete schedulerExecutor shutdown block in shutdown()
  • StandardRoleListener.java — delete entire file

  • RoleElectionOptions.java — remove all config key declarations (or delete the class if nothing else references it; grep first)

Verify: HugeGraph interface has multiple implementations — make sure all of them compile after removing roleElectionStateMachine().


PR C — Slim ServerInfoManager, delete HugeServerInfo, drop serverInfoDbExecutor

Important constraint: ServerInfoManager is NOT deleted. DistributedTaskScheduler still uses selfNodeId() and selfIsMaster(). The serverManager() method on the TaskScheduler interface stays.

Files to change:

  • ServerInfoManager.java

    • Remove dbExecutor field
    • Remove dbExecutor parameter from constructor (and its E.checkNotNull guard)
    • Delete init() method
    • Delete heartbeat() method
    • Delete tx() private method
    • Delete call() private method
    • Remove dead imports (Callable, ExecutorService, GraphTransaction, HugeException)
    • close() stays but simplify to just this.closed = true
  • StandardTaskScheduler.java

    • Remove serverInfoDbExecutor parameter from constructor
    • Change new ServerInfoManager(graph, serverInfoDbExecutor) → new ServerInfoManager(graph)
    • If synchronized (this.serverManager) is used as a monitor in tx(), replace with synchronized (this) or a dedicated lock field
  • TaskAndResultScheduler.java

    • Remove serverInfoDbExecutor parameter from constructor
    • Change new ServerInfoManager(graph, serverInfoDbExecutor) → new ServerInfoManager(graph)
  • DistributedTaskScheduler.java

    • Remove serverInfoDbExecutor parameter from constructor
    • Update super(graph, serverInfoDbExecutor) → super(graph)
  • TaskManager.java

    • Delete serverInfoDbExecutor field and SERVER_INFO_DB_WORKER constant
    • Delete serverInfoDbExecutor allocation in constructor
    • Remove serverInfoDbExecutor argument from both addScheduler() constructor calls
    • Delete serverInfoDbExecutor shutdown block in shutdown()
  • HugeVertex.java

    • Audit for HugeServerInfo references (2 matches) — likely a fromVertex dispatch case; remove it
  • StandardHugeGraph.java

    • Audit for initSchemaIfNeeded() call on HugeServerInfo.Schema in initSystemInfo() — remove it
  • HugeServerInfo.java — delete entire file (after removing all call sites above)

  • ServerInfoManagerTest.java

    • Delete testInitDoesNotAccessBackendStore (method no longer exists)
    • Update constructor calls: remove the executor argument everywhere
  • TaskSchedulerServerInfoTest.java

    • Remove serverInfoDbExecutor local variable, its shutdownNow() call, and the constructor argument from the remaining tests
  • TaskAndResultSchedulerTest.java

    • Same: remove serverInfoDbExecutor from all constructor calls (~10 occurrences)

Checklist before each PR merges

  • [ ] mvn compile passes
  • [ ] mvn test -pl hugegraph-server/hugegraph-test passes
  • [ ] No remaining references to deleted classes/methods (grep for HugeServerInfo, roleElectionStateMachine, schedulerExecutor, serverInfoDbExecutor as appropriate)

bitflicker64 avatar Jul 09 '26 09:07 bitflicker64

#3244 has been merged as 82034fb, which completes the phase 2 cleanup tracked here. It did not close this issue automatically, so could a maintainer close it? The remaining RedirectFilter dead code is tracked separately in #3245 (fix in #3246).

byteayan avatar Oct 01 '26 14:10 byteayan