core: Apply ManagedChannelImpl's updateBalancingState() immediately

ffcc360ba adjusted updateBalancingState() to require being run within
the sync context. However, it still queued the work into the sync
context, which was unnecessary. This re-entering the sync context
unnecessarily delays the new state from being used.
This commit is contained in:
Eric Anderson 2025-03-06 07:57:32 -08:00
parent a6a041e415
commit ca4819ac6d
1 changed files with 11 additions and 17 deletions

View File

@ -1388,24 +1388,18 @@ final class ManagedChannelImpl extends ManagedChannel implements
syncContext.throwIfNotInThisSynchronizationContext();
checkNotNull(newState, "newState");
checkNotNull(newPicker, "newPicker");
final class UpdateBalancingState implements Runnable {
@Override
public void run() {
if (LbHelperImpl.this != lbHelper || panicMode) {
return;
}
updateSubchannelPicker(newPicker);
// It's not appropriate to report SHUTDOWN state from lb.
// Ignore the case of newState == SHUTDOWN for now.
if (newState != SHUTDOWN) {
channelLogger.log(
ChannelLogLevel.INFO, "Entering {0} state with picker: {1}", newState, newPicker);
channelStateManager.gotoState(newState);
}
}
}
syncContext.execute(new UpdateBalancingState());
if (LbHelperImpl.this != lbHelper || panicMode) {
return;
}
updateSubchannelPicker(newPicker);
// It's not appropriate to report SHUTDOWN state from lb.
// Ignore the case of newState == SHUTDOWN for now.
if (newState != SHUTDOWN) {
channelLogger.log(
ChannelLogLevel.INFO, "Entering {0} state with picker: {1}", newState, newPicker);
channelStateManager.gotoState(newState);
}
}
@Override