use of org.opendaylight.genius.idmanager.ReleasedIdHolder in project genius by opendaylight.
the class CleanUpJob method cleanupExcessIds.
private void cleanupExcessIds() throws IdManagerException, ReadFailedException, TransactionCommitFailedException {
// We can update the availableCount here... and update it in DS using IdHolderSyncJob
long totalAvailableIdCount = idLocalPool.getAvailableIds().getAvailableIdCount() + idLocalPool.getReleasedIds().getAvailableIdCount();
if (totalAvailableIdCount > blockSize * 2) {
if (LOG.isDebugEnabled()) {
LOG.debug("Condition for cleanUp Satisfied for localPool {} - totalAvailableIdCount {}", idLocalPool, totalAvailableIdCount);
}
String parentPoolNameIntern = parentPoolName.intern();
InstanceIdentifier<ReleasedIdsHolder> releasedIdInstanceIdentifier = idUtils.getReleasedIdsHolderInstance(parentPoolNameIntern);
// cannot rely on DSJC because that is not cluster-aware
try {
idUtils.lock(lockManager, parentPoolNameIntern);
Optional<ReleasedIdsHolder> releasedIdsHolder = SingleTransactionDataBroker.syncReadOptional(broker, CONFIGURATION, releasedIdInstanceIdentifier);
if (!releasedIdsHolder.isPresent()) {
LOG.error("ReleasedIds not present in parent pool. Unable to cleanup excess ids");
return;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Releasing excesss Ids from local pool");
}
ReleasedIdHolder releasedIds = (ReleasedIdHolder) idLocalPool.getReleasedIds();
ReleasedIdsHolderBuilder releasedIdsParent = new ReleasedIdsHolderBuilder(releasedIdsHolder.get());
idUtils.freeExcessAvailableIds(releasedIds, releasedIdsParent, totalAvailableIdCount - blockSize * 2);
IdHolderSyncJob job = new IdHolderSyncJob(idLocalPool.getPoolName(), releasedIds, txRunner, idUtils);
jobCoordinator.enqueueJob(idLocalPool.getPoolName(), job, IdUtils.RETRY_COUNT);
SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, releasedIdInstanceIdentifier, releasedIdsParent.build());
} finally {
idUtils.unlock(lockManager, parentPoolNameIntern);
}
}
}
Aggregations