[improve][fn] make built-in connector reload incremental - #25773
Conversation
Signed-off-by: Dream95 <zhou_8621@163.com>
lhotari
left a comment
There was a problem hiding this comment.
good work. some minor comments
lhotari
left a comment
There was a problem hiding this comment.
good work. some minor comments
dao-jun
left a comment
There was a problem hiding this comment.
ConnectorsManager.connectors is volatile, and reloadConnectors assigns a new map atomically. The closeConnectors is called on only the evicted set. Between the assignment this.connectors = reload.getLeft() and the close of evicted connectors, there's a brief window where a caller could be using an evicted connector.
However, this was already the case before the change (old behavior also swapped the map then closed the old one), so this PR doesn't regress thread safety. Worth noting but not a new concern.
…ex to ConnectorUtils Signed-off-by: Dream95 <zhou_8621@163.com>
|
/pulsarbot rerun-failure-checks |
lhotari
left a comment
There was a problem hiding this comment.
LGTM.
The existing code (before this PR) unnecessarily uses TreeMap as parameter, field, or variable types. A general recommendation is to use the minimal Map interface type, usually one of java.util.Map, java.util.SequencedMap, or java.util.SortedMap. In the case of connectors, the use the TreeMap is justified as the implementation to get stable iteration order by key. This is available when java.util.Map is the parameter, field, or variable type.
I'd suggest addressing the refactoring to get rid of unnecessary use of TreeMap in parameter, field, and variable types for connector related classes after this current PR has been merged. For example,
In ConnectorsManager
@Getter
private volatile Map<String, Connector> connectors;The implementation instance would remain as TreeMap, so this change would only be about the types for fields, variables and parameters.
public record ReloadConnectorsResult(Map<String, Connector> connectors, List<Connector> connectorsToClose) {
}This change could also be made part of this PR since it already closes touches the code where TreeMap is used and also adds a new TreeMap parameter/field in ReloadConnectorsResult.
|
@lhotari Yes, I'll take separate PR. Besides the connector changes here, FunctionsManager has the same unnecessary TreeMap usage; I'll address both together. |
…reload Signed-off-by: Dream95 <zhou_8621@163.com>
|
Since reload is admin-driven and usually serialized, If we need stricter ordering, I’m happy to add synchronization in a follow-up. |
Signed-off-by: Dream95 <zhou_8621@163.com> (cherry picked from commit 02cab7a)
Signed-off-by: Dream95 <zhou_8621@163.com> (cherry picked from commit 02cab7a)
Signed-off-by: Dream95 <zhou_8621@163.com> (cherry picked from commit 02cab7a)
Motivation
reloadBuiltInSources/reloadBuiltInSinkscurrently reload connectors by rebuilding the full connector map and closing all existing connector instances.This causes unnecessary classloader churn and can invalidate previously referenced connector instances even when the archive content has not changed.
Modifications
ConnectorUtils.reloadConnectors(...):Connectorinstances when both archive path and archive MD5 are unchanged.Connectorinstances only for added/changed archives.ConnectorsManager.reloadConnectors(...)to use the incremental reload result and close only evicted connectors.Connectorto keep archive MD5 (archiveMd5Hex) for identity checks during reload.pulsar-commonFileUtilsand reused them from both connector reload andNarUnpacker.ConnectorUtilsReloadTestConnectorsManagerReloadConnectorsTestVerifying this change
This change added tests and can be verified as follows:
pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/io/ConnectorUtilsReloadTest.javapulsar-functions/runtime/src/test/java/org/apache/pulsar/functions/worker/ConnectorsManagerReloadConnectorsTest.javaDoes this pull request potentially affect one of the following parts:
Matching PR in forked repository
PR in forked repository: Dream95#9