Package org.apache.sling.discovery.oak
Class SlingIdCleanupTask
java.lang.Object
org.apache.sling.discovery.oak.SlingIdCleanupTask
- All Implemented Interfaces:
 Runnable,TopologyEventListener
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)
 
- as child node under /var/discovery/oak/clusterInstances : this is the most performance critical garbage
 - as a property key in /var/discovery/oak/syncTokens
 
- 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
 
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 - 
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.slf4j.Loggerprotected ResourceResolverFactoryprotected Scheduler - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionprotected voidactivate(org.osgi.framework.BundleContext bc, SlingIdCleanupTask.Conf config) protected voidvoidhandleTopologyEvent(TopologyEvent event) Inform the service about an event in the topology - or in the discovery of the topology.protected voidmodified(org.osgi.framework.BundleContext bc, SlingIdCleanupTask.Conf config) voidrun()Invoked via sling.commons.scheduler triggered from resetCleanupSchedule(). 
- 
Field Details
- 
logger
protected final org.slf4j.Logger logger - 
scheduler
 - 
resourceResolverFactory
 
 - 
 - 
Constructor Details
- 
SlingIdCleanupTask
public SlingIdCleanupTask() 
 - 
 - 
Method Details
- 
activate
 - 
modified
 - 
deactivate
protected void deactivate() - 
handleTopologyEvent
Description copied from interface:TopologyEventListenerInform the service about an event in the topology - or in the discovery of the topology.Implementors of this method must ensure that this method returns quickly and that no locks are being acquired that could cause deadlocks (ie the framework might call this method holding locks).
The
TopologyEventcontains details about what changed. The supported event types are:TOPOLOGY_INITsent when theTopologyEventListenerwas first bound to the discovery service - represents the initial state of the topology at that time.TOPOLOGY_CHANGINGsent when the discovery service discovered a change in the topology and has started to settle the change. This event is sent beforeTOPOLOGY_CHANGEDbut is optionalTOPOLOGY_CHANGEDsent when the discovery service discovered a change in the topology and has settled it.PROPERTIES_CHANGEDsent when the one or many properties have changed in an instance in the current topology
- Specified by:
 handleTopologyEventin interfaceTopologyEventListener- Parameters:
 event- The topology event
 - 
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. 
 -