Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ public JavaScriptTieredBrokerSelectorStrategy(
}

@Override
public Optional<String> getBrokerServiceName(TieredBrokerConfig config, Query query)
public synchronized Optional<String> getBrokerServiceName(TieredBrokerConfig config, Query query)

@FrankChen021 FrankChen021 Aug 2, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although Codex reports 'LGTM', I have different opinons.

If you look at the usage of compileSelectorFunction, there's another place that uses it, and the 'synchronized' is not added. So adding 'synchronized' to caller is not good, we may forget to add it in new places.

As this is due to script engine layer problem, I think it's the compileSelectorFunction that ensures that the returned fnSelector is a concurrent safe version.

One way is that we can use dynamic proxy inside compileSelectorFunction to wrap existing object and forward the call in a synchronized block

{
fnSelector = fnSelector == null ? JavaScriptUtil.compileSelectorFunction(SelectorFunction.class, function) : fnSelector;
if (fnSelector == null) {
fnSelector = JavaScriptUtil.compileSelectorFunction(SelectorFunction.class, function);
}
return Optional.fromNullable(fnSelector.apply(config, query));
}

Expand Down
Loading