in src/main/java/org/apache/sling/discovery/commons/providers/spi/base/OakBacklogClusterSyncService.java [180:260]
private BacklogStatus getBacklogStatus(BaseTopologyView view) {
logger.trace("getBacklogStatus: start");
ResourceResolver resourceResolver = null;
try{
resourceResolver = getResourceResolver();
DiscoveryLiteDescriptor descriptor =
DiscoveryLiteDescriptor.getDescriptorFrom(resourceResolver);
// backlog-free means:
// 1) 'deactivating' must be empty
// (otherwise we indeed have a backlog)
// 2) all active ids of the descriptor must have a mapping to slingIds
// (otherwise the init failed or is pending for some instance(s))
// 3) all 'active' instances must be in the view
// (otherwise discovery lite might not yet consider
// an instance dead but discovery-service does)
// instead what is fine from a backlog point of view
// * instances in the view but listed as 'inactive'
// (this might be the case for just-started instances)
// * instances in the view but not contained in the descriptor at all
// (this might be the case for just-started instances)
int[] activeIds = descriptor.getActiveIds();
int[] deactivatingIds = descriptor.getDeactivatingIds();
// we're not worried about 'inactive' ones - as that could
// be a larger list filled with legacy entries too
// plus once the instance is inactive there's no need to
// check anything further - that one is then backlog-free
// 1) 'deactivating' must be empty
if (deactivatingIds.length!=0) {
logSilencer.infoOrDebug("getBacklogStatus-hasBacklog-" + view.toShortString(),
"getBacklogStatus: there are deactivating instances: "+Arrays.toString(deactivatingIds));
return BacklogStatus.HAS_BACKLOG;
}
ClusterView cluster = view.getLocalInstance().getClusterView();
LocalClusterView localCluster = null;
if (cluster instanceof LocalClusterView) {
localCluster = (LocalClusterView)cluster;
}
Set<String> slingIds = new HashSet<>();
for (InstanceDescription instance : cluster.getInstances()) {
slingIds.add(instance.getSlingId());
}
for(int i=0; i<activeIds.length; i++) {
int activeId = activeIds[i];
if (localCluster != null && localCluster.isPartiallyStarted(activeId)) {
// ignore this one then
continue;
}
String slingId = idMapService.toSlingId(activeId, resourceResolver);
// 2) all ids of the descriptor must have a mapping to slingIds
if (slingId == null) {
logSilencer.infoOrDebug("getBacklogStatus-undefined-" + view.toShortString(),
"getBacklogStatus: no slingId found for active id: "+activeId);
return BacklogStatus.UNDEFINED;
}
// 3) all 'active' instances must be in the view
if (!slingIds.contains(slingId)) {
logSilencer.infoOrDebug("getBacklogStatus-hasBacklog-" + view.toShortString(),
"getBacklogStatus: active instance's ("+activeId+") slingId ("+slingId+") not found in cluster ("+cluster+")");
return BacklogStatus.HAS_BACKLOG;
}
}
logSilencer.infoOrDebug("getBacklogStatus-" + view.toShortString(),
"getBacklogStatus: no backlog (anymore)");
return BacklogStatus.NO_BACKLOG;
} catch(Exception e) {
logSilencer.infoOrDebug("getBacklogStatus-undefined-" + view.toShortString(),
"getBacklogStatus: failed to determine backlog status: "+e);
return BacklogStatus.UNDEFINED;
} finally {
logger.trace("getBacklogStatus: end");
if (resourceResolver!=null) {
resourceResolver.close();
}
}
}