Search in sources :

Example 1 with ReleasedIdHolder

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);
        }
    }
}
Also used : ReleasedIdsHolder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder) ReleasedIdsHolderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder) ReleasedIdHolder(org.opendaylight.genius.idmanager.ReleasedIdHolder)

Aggregations

ReleasedIdHolder (org.opendaylight.genius.idmanager.ReleasedIdHolder)1 ReleasedIdsHolder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder)1 ReleasedIdsHolderBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder)1