Package org.apache.sling.discovery.oak

## Class SlingIdCleanupTask

- java.lang.Object
- - org.apache.sling.discovery.oak.SlingIdCleanupTask

All Implemented Interfaces:
  `Runnable`, `org.apache.sling.discovery.TopologyEventListener`

    public class SlingIdCleanupTask
    extends Object
    implements org.apache.sling.discovery.TopologyEventListener, Runnable

A background task that cleans up garbage slingIds after topology changes.

A slingId is considered garbage when:

- it is not in the current topology
- was not ever seen in previous topologies by the now leader instance
- it is not in the current idmap (where clusterNodeIds are reused hence that list stays small and does not need cleanup)
- its leaderElectionId was created more than 7 days ago (the leaderElectionId is created at activate time of the discovery.oak bundle - hence this more or less corresponds to the startup time of that instance)

The garbage accumulates at the following places, where it will thus be cleaned up from:

- as child node under /var/discovery/oak/clusterInstances : this is the most performance critical garbage
- as a property key in /var/discovery/oak/syncTokens

The task by default is executed:

- only on the leader
- 10min after a TOPOLOGY_INIT or TOPOLOGY_CHANGED event
- with a maximum number of delete operations to avoid repository overload - that maximum is called batchSize and is 50 by default
- in subsequent intervals of 10min after the initial run, if that had to stop at the batchSize of 50 deletions

All parameters mentioned above can be configured.

Additionally, the cleanup is skipped for 13 hours after a successful cleanup. This is to avoid unnecessary load on the repository. The number of 13 incorporates some heuristics such as : about 2 cleanup rounds per day maximum makes sense, if a leader is very long living, then the 1 additional hour makes it spread somewhat throughout the day. This is to further minimize any load side-effects.

### Nested Class Summary

Nested Classes
`static interface` `SlingIdCleanupTask.Conf`

### Field Summary

Fields
`protected org.slf4j.Logger` `logger`
`protected org.apache.sling.api.resource.ResourceResolverFactory` `resourceResolverFactory`
`protected org.apache.sling.commons.scheduler.Scheduler` `scheduler`

### Constructor Summary

Constructors
`SlingIdCleanupTask()`

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `activate​(org.osgi.framework.BundleContext bc, SlingIdCleanupTask.Conf config)`
`protected void` `deactivate()`
`void` `handleTopologyEvent​(org.apache.sling.discovery.TopologyEvent event)`
`protected void` `modified​(org.osgi.framework.BundleContext bc, SlingIdCleanupTask.Conf config)`
`void` `run()` Invoked via sling.commons.scheduler triggered from resetCleanupSchedule().

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### logger

    protected final org.slf4j.Logger logger

#### scheduler

    protected org.apache.sling.commons.scheduler.Scheduler scheduler

#### resourceResolverFactory

    protected org.apache.sling.api.resource.ResourceResolverFactory resourceResolverFactory

### Constructor Detail

#### SlingIdCleanupTask

    public SlingIdCleanupTask()

### Method Detail

#### activate

    protected void activate​(org.osgi.framework.BundleContext bc,
                            SlingIdCleanupTask.Conf config)

#### modified

    protected void modified​(org.osgi.framework.BundleContext bc,
                            SlingIdCleanupTask.Conf config)

#### deactivate

    protected void deactivate()

#### handleTopologyEvent

    public void handleTopologyEvent​(org.apache.sling.discovery.TopologyEvent event)

Specified by:
  `handleTopologyEvent` in interface `org.apache.sling.discovery.TopologyEventListener`

#### run

    public void run()

Invoked via sling.commons.scheduler triggered from resetCleanupSchedule(). By default should get called at max every 5 minutes until cleanup is done or 10min after a topology change.

Specified by:
  `run` in interface `Runnable`