Safe publication of AutoFollowCoordinator (#40153)
We were leaking a reference to an AutoFollowCoordinator during construction, violating safe publication according to the JLS specification. This commit addresses this by waiting to register AutoFollowCoordinator with the ClusterApplierService after the AutoFollowCoordinator is fully constructed. We also remove ourselves as a listener when stopping.
This commit is contained in:
parent
791814bb47
commit
5be12e0999
|
@ -101,7 +101,6 @@ public class AutoFollowCoordinator extends AbstractLifecycleComponent implements
|
||||||
this.ccrLicenseChecker = Objects.requireNonNull(ccrLicenseChecker, "ccrLicenseChecker");
|
this.ccrLicenseChecker = Objects.requireNonNull(ccrLicenseChecker, "ccrLicenseChecker");
|
||||||
this.relativeMillisTimeProvider = relativeMillisTimeProvider;
|
this.relativeMillisTimeProvider = relativeMillisTimeProvider;
|
||||||
this.absoluteMillisTimeProvider = absoluteMillisTimeProvider;
|
this.absoluteMillisTimeProvider = absoluteMillisTimeProvider;
|
||||||
clusterService.addListener(this);
|
|
||||||
this.recentAutoFollowErrors = new LinkedHashMap<String, Tuple<Long, ElasticsearchException>>() {
|
this.recentAutoFollowErrors = new LinkedHashMap<String, Tuple<Long, ElasticsearchException>>() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean removeEldestEntry(final Map.Entry<String, Tuple<Long, ElasticsearchException>> eldest) {
|
protected boolean removeEldestEntry(final Map.Entry<String, Tuple<Long, ElasticsearchException>> eldest) {
|
||||||
|
@ -121,11 +120,12 @@ public class AutoFollowCoordinator extends AbstractLifecycleComponent implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doStart() {
|
protected void doStart() {
|
||||||
|
clusterService.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doStop() {
|
protected void doStop() {
|
||||||
|
clusterService.removeListener(this);
|
||||||
LOGGER.trace("stopping all auto-followers");
|
LOGGER.trace("stopping all auto-followers");
|
||||||
/*
|
/*
|
||||||
* Synchronization is not necessary here; the field is volatile and the map is a copy-on-write map, any new auto-followers will not
|
* Synchronization is not necessary here; the field is volatile and the map is a copy-on-write map, any new auto-followers will not
|
||||||
|
|
Loading…
Reference in New Issue