rocketmq-rust icon indicating copy to clipboard operation
rocketmq-rust copied to clipboard

[Refactor♻️] Use async fn for BrokerMasterAddressStore address updates

Open mxsm opened this issue 1 week ago • 1 comments

Target Code

Edit BrokerMasterAddressStore in rocketmq-store/src/capability.rs. It accepts either one address for both roles or a separate HA address and logical broker address. Broker registration supplies distinct values from its registration response. Trait definition / Registration caller

Problems

The two asynchronous methods repeat impl Future<Output = ()> + Send. Native async fn declarations can express this using the macro already used by the neighboring broker capabilities.

Proposed Changes

Add #[trait_variant::make(Send)] above pub trait BrokerMasterAddressStore: BrokerReadStore. Use async fn for the two methods below. Keep update_logical_master_address(&self, new_addr: &CheetahString) synchronous. Existing macro pattern

async fn update_master_address(&self, new_addr: &CheetahString) {
    self.update_master_addresses(new_addr.as_str(), new_addr)
}

async fn update_master_addresses(&self, ha_address: &str, logical_address: &CheetahString) {
    async move {
        MessageStoreEngine::update_ha_master_address(self.message_store(), ha_address).await;
        self.update_logical_master_address(logical_address);
    }
}

Keep the existing default bodies. The macro turns the signatures back into functions returning futures, so the async move block in the two-address method supplies that future. The single-address entry point must still pass its input for both roles. With two addresses, the HA update must finish before the logical update receives logical_address. Both futures must be Send for a generic S: BrokerMasterAddressStore. Broker caller using both addresses

Run from the repository root to check formatting and type-check the store together with its broker callers.

cargo fmt -p rocketmq-store -- --check
cargo check --locked -p rocketmq-broker --lib

mxsm avatar Nov 25 '26 06:11 mxsm

I'll take this one. I'll convert the two BrokerMasterAddressStore address updates to async fn while preserving the Send futures and update order.

lipeh1 avatar Nov 25 '26 06:11 lipeh1