hjun881 opened a new issue, #11670:
URL: https://github.com/apache/rocketmq/issues/11670

   ### Is Your Feature Request Related to a Problem?
   
   ### Background
   
   RocketMQ 5.x currently offers three broker deployment modes:
   
   | Mode | Replicas per broker group | Cost | Behavior on failure |
   |---|---|---|---|
   | DLedger | >= 3 | Highest | Raft elects a new leader; redundancy preserved |
   | Controller mode | 2 (configurable) | Medium | Promotes the slave when the 
master fails; the group then has no redundancy |
   | Traditional master-slave | 2 | Lowest | Manual intervention needed when 
the master fails; the master keeps serving writes when the slave fails |
   
   In terms of resource cost, the traditional master-slave architecture is the 
cheapest: only 2 nodes per group. DLedger needs at least 3 replicas, while 
Controller mode allows 2 replicas but promotes the slave to master when the 
master fails, so the write path loses its redundancy and carries higher risk.
   
   ### Problem
   
   With traditional master-slave and synchronous replication 
(`brokerRole=SYNC_MASTER`), when the slave goes down:
   
   1. The routing information in NameServer does not change, so producers keep 
sending to that broker group as a writable route.
   2. 2. The master has to wait for the slave's ACK; after the timeout it 
returns a failure to the client (e.g. `SendStatus.FLUSH_SLAVE_TIMEOUT` / system 
error).
   3. 3. Until the slave recovers, clients keep hitting a route that is 
guaranteed to fail, producing mass send failures, retries and timeouts.
   4. 4. The message may already be stored on the master while the client 
receives a failure, leaving the sender's view inconsistent with the broker's 
actual state, and retries can introduce duplicate messages.
   5. 5. The group can no longer write safely (no slave replica exists), yet it 
is still perfectly capable of serving reads.
   In short: when the slave is down, the broker group can currently only fail 
writes; it cannot automatically degrade to read-only. For cost-sensitive 
deployments this makes the otherwise cheapest architecture impractical for sync 
replication.
   
   ### Describe the Solution You'd Like
   
   Provide a mechanism that, in traditional master-slave with sync replication, 
automatically disables writes or removes the write route for the group when the 
slave becomes unavailable, so the group only serves reads, and restores writes 
once the slave recovers.
   
   Concretely:
   
   1. **Auto-disable writes**: after the broker detects that the HA slave 
connection has been down for longer than a configurable threshold (e.g. 
`slaveOfflineTimeout`), the group enters read-only state and stops accepting 
new writes.
   2. 2. **Remove write route**: report this state to NameServer so the route 
information (or a new write route) no longer advertises this broker as 
writable; consumer routes remain unchanged and reads continue to be served by 
the master.
   3. 3. **Auto-recovery**: once the slave is back and HA catch-up is complete, 
automatically clear the read-only state and restore the write route.
   4. 4. **Opt-in switch**: add a config item (e.g. 
`autoDisableWriteWhenSlaveOffline`) that is disabled by default so existing 
deployments keep their current behavior.
   5. 5. **Compatibility**: any new writability/sync-state field in the route 
must be optional and safely ignorable by older NameServer versions and clients.
   
   ### Describe Alternatives You've Considered
   
   - **DLedger**: requires at least 3 replicas per broker group. It provides 
automatic leader election, but the resource cost is too high for cost-sensitive 
clusters.
   - - **Controller mode**: allows 2 replicas, but when the master fails it 
promotes the slave to master. The group then runs with a single replica, so the 
write path has no redundancy and the risk is high.
   - - - **Manual operation**: `updateBrokerConfig` with `writable=false`, or 
taking the broker offline by hand. This needs human intervention, clients still 
receive write failures instead of the route being removed, and recovery is not 
automatic.
   - - - - **Async replication** (`brokerRole=ASYNC_MASTER`): avoids blocking 
writes on the slave, but loses the sync-replication guarantee, so it is not 
equivalent.
   
   ### Additional Context
   
   ### Affected modules (initial estimate)
   
   - **broker**: observe HA connection state (`HAService` / `HAConnection` / 
`HAClient`), tie it to `BrokerConfig` and `writable`, and track the "read-only 
because the slave is offline" state.
   - - **namesrv**: add a writability/sync-availability flag to 
`RegisterBrokerBody` / `BrokerData` / `TopicRouteData`, and distinguish read 
and write routes when building the route.
   - - - **clients** (remoting / proxy / language SDKs): skip non-writable 
brokers when sending; consumer routes stay unchanged.
   - - - - **admin / monitoring**: expose the state (event log, BrokerStats 
metrics) for operators.
   ### Notes
   
   - This is a feature request, not a bug report.
   - - The `syncStateSet` / `allAckInSyncStateSet` mechanisms in Controller 
mode may contain reusable design ideas; please evaluate whether they can be 
extended to the traditional master-slave mode.
   - - - We would like to know whether the maintainers consider this direction 
acceptable for upstream, and whether related work already exists.


-- 
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]

Reply via email to