Skip to content

[Enhancement] (fe) Hand over mastership with BDB JE transferMaster during graceful shutdown #70848

Open

Description

@matanper

Search before asking

  • I had searched in the issues and found no similar issues.

Description

A planned restart of the master FE (rolling upgrade, config change, node maintenance) always costs an unplanned master election, even though the FE has a graceful shutdown path.

On SIGTERM, the shutdown hook (fe/fe-core/src/main/java/org/apache/doris/DorisFE.java:186 on master) does the following:

  1. It sets serverReady to false, so /api/health reports not ready and load balancers stop sending new connections.
  2. gracefulShutdown() (DorisFE.java:743) waits up to 300 s for the queries this FE coordinates.
  3. It stops the query, thrift and HTTP servers, and the JVM exits.

Nothing in this path concerns the master role. During the drain, the master keeps serving metadata writes and the requests followers forward to it. When the JVM exits, the remaining electable FEs learn that the master is gone only through the replication heartbeat timeout, and then hold an election. Metadata writes and forwarded requests stall or fail for the whole failure-detection-plus-election window.

The bundled BDB JE (org.apache.doris:je:18.3.14-doris-SNAPSHOT) already supports a controlled handover:

  • ReplicatedEnvironment.transferMaster(Set<String> replicas, int timeout, TimeUnit unit)
  • an overload with a force flag

It blocks new transactions on the current master, waits until one of the named replicas has caught up, and makes that replica master. Doris does not call it anywhere (no reference in fe/), so even a planned restart of the master is handled like a crash.

Solution

During graceful shutdown, before the query drain, if this FE is the master:

  1. Pick the electable followers that are alive (from the frontend list / BDBHA).
  2. Call transferMaster(followers, timeout, unit) through the existing BDB JE environment wrapper, with a bounded timeout (for example 30-60 s, configurable).
  3. On success, continue the shutdown as a follower. On MasterTransferFailureException or a timeout, log it and fall back to the current behaviour (shut down and let the group elect).

Optionally, expose the same handover as an admin statement (something like ALTER SYSTEM TRANSFER MASTER TO "<host>:<edit_log_port>"), so that operators and orchestrators can move mastership before restarting a node, without sending a signal.

This turns a planned master restart into one short write pause, without waiting for failure detection. Together with restarting followers first and the master last, a rolling FE restart then moves mastership exactly once and never through a timeout.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions