Skip to content

Safely register ClusterStateListener #38560

@pgomulka

Description

@pgomulka

This is a follow up from #37861 discussed on core-infra sync meeting on 6th of Feb19 . See the original issue for reasoning behind this.

The goal is to find usages of ClusterStateListener and make sure it is not publishing its this reference during construction. There might be multiple possible ways to fix that.
The easiest fix is to just extract a factory method. However when there is multiple overloaded constructors, it might be tempted to remove the ClusterService parameter and register in a place where the instance is created.
In some cases where constructor parameters are provided with @Inject the registration could be done in AbstractLifecycleComponent.start/doStart.
Or refactored to factory method with @Inject (that annotation might work with methods, although couldn't find usages.

  • DelayedAllocationService (org.elasticsearch.cluster.routing)
  • MlInitializationService (org.elasticsearch.xpack.ml)
  • LocalNodeMasterListeners in ClusterApplierService (org.elasticsearch.cluster.service)
  • LicenseService (org.elasticsearch.license)
  • WatcherIndexTemplateRegistry (org.elasticsearch.xpack.watcher.support)
  • DanglingIndicesState (org.elasticsearch.gateway)
  • WatcherIndexingListener (org.elasticsearch.xpack.watcher)
  • AutoFollowCoordinator (org.elasticsearch.xpack.ccr.action)
  • IndicesStore (org.elasticsearch.indices.store)
  • InternalClusterInfoService (org.elasticsearch.cluster)
  • WatcherLifeCycleService (org.elasticsearch.xpack.watcher)
  • ResponseCollectorService (org.elasticsearch.node)
  • SecurityIndexManager (org.elasticsearch.xpack.security.support)
  • PersistentTasksClusterService (org.elasticsearch.persistent)
  • MlAssignmentNotifier (org.elasticsearch.xpack.ml)
  • AutodetectProcessManager (org.elasticsearch.xpack.ml.job.process.autodetect)
  • SnapshotShardsService (org.elasticsearch.snapshots)
  • IndexLifecycleService (org.elasticsearch.xpack.indexlifecycle)
  • PersistentTasksNodeService (org.elasticsearch.persistent)
  • TaskRunner in DatafeedManager (org.elasticsearch.xpack.ml.datafeed) (inner class is indirectly also publishing the this of outter class)
  • LoggingAuditTrail (org.elasticsearch.xpack.security.audit.logfile)
  • TemplateUpgradeService (org.elasticsearch.cluster.metadata)
  • GatewayService (org.elasticsearch.gateway) sample of how to register in AbstractLifecycleComponent.doStart
  • LocalExporter (org.elasticsearch.xpack.monitoring.exporter.local)
  • RestoreClusterStateListener (org.elasticsearch.action.admin.cluster.snapshots.restore) registered in a separate method (not a static factory method) - another way of approaching this
  • GeoIpDownloaderTaskExecutor

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions