use of org.opendaylight.genius.idmanager.jobs.IdHolderSyncJob in project genius by opendaylight.
the class IdManager method releaseIdFromLocalPool.
private void releaseIdFromLocalPool(String parentPoolName, String localPoolName, String idKey) throws ReadFailedException, IdManagerException {
String idLatchKey = idUtils.getUniqueKey(parentPoolName, idKey);
LOG.debug("Releasing ID {} from pool {}", idKey, localPoolName);
CountDownLatch latch = idUtils.getReleaseIdLatch(idLatchKey);
if (latch != null) {
try {
if (!latch.await(10, TimeUnit.SECONDS)) {
LOG.warn("Timed out while releasing id {} from id pool {}", idKey, parentPoolName);
}
} catch (InterruptedException ignored) {
LOG.warn("Thread interrupted while releasing id {} from id pool {}", idKey, parentPoolName);
} finally {
idUtils.removeReleaseIdLatch(idLatchKey);
}
}
localPoolName = localPoolName.intern();
InstanceIdentifier<IdPool> parentIdPoolInstanceIdentifier = idUtils.getIdPoolInstance(parentPoolName);
IdPool parentIdPool = singleTxDB.syncRead(CONFIGURATION, parentIdPoolInstanceIdentifier);
List<IdEntries> idEntries = parentIdPool.getIdEntries();
List<IdEntries> newIdEntries = idEntries;
if (idEntries == null) {
throw new IdDoesNotExistException(parentPoolName, idKey);
}
InstanceIdentifier<IdEntries> existingId = idUtils.getIdEntry(parentIdPoolInstanceIdentifier, idKey);
Optional<IdEntries> existingIdEntryObject = singleTxDB.syncReadOptional(CONFIGURATION, existingId);
if (!existingIdEntryObject.isPresent()) {
LOG.info("Specified Id key {} does not exist in id pool {}", idKey, parentPoolName);
idUtils.unlock(lockManager, idLatchKey);
return;
}
IdEntries existingIdEntry = existingIdEntryObject.get();
List<Long> idValuesList = existingIdEntry.getIdValue();
IdLocalPool localIdPoolCache = localPool.get(parentPoolName);
boolean isRemoved = newIdEntries.remove(existingIdEntry);
LOG.debug("The entry {} is removed {}", existingIdEntry, isRemoved);
updateDelayedEntriesInLocalCache(idValuesList, parentPoolName, localIdPoolCache);
IdHolderSyncJob poolSyncJob = new IdHolderSyncJob(localPoolName, localIdPoolCache.getReleasedIds(), txRunner, idUtils);
jobCoordinator.enqueueJob(localPoolName, poolSyncJob, IdUtils.RETRY_COUNT);
scheduleCleanUpTask(localIdPoolCache, parentPoolName, parentIdPool.getBlockSize());
LOG.debug("Released id ({}, {}) from pool {}", idKey, idValuesList, localPoolName);
// Updating id entries in the parent pool. This will be used for restart scenario
UpdateIdEntryJob job = new UpdateIdEntryJob(parentPoolName, localPoolName, idKey, null, txRunner, idUtils, lockManager);
jobCoordinator.enqueueJob(parentPoolName, job, IdUtils.RETRY_COUNT);
}
use of org.opendaylight.genius.idmanager.jobs.IdHolderSyncJob in project genius by opendaylight.
the class IdManager method getIdFromLocalPoolCache.
private Long getIdFromLocalPoolCache(IdLocalPool localIdPool, String parentPoolName) throws OperationFailedException, IdManagerException {
while (true) {
IdHolder availableIds = localIdPool.getAvailableIds();
if (availableIds != null) {
Optional<Long> availableId = availableIds.allocateId();
if (availableId.isPresent()) {
IdHolderSyncJob poolSyncJob = new IdHolderSyncJob(localIdPool.getPoolName(), localIdPool.getAvailableIds(), txRunner, idUtils);
jobCoordinator.enqueueJob(localIdPool.getPoolName(), poolSyncJob, IdUtils.RETRY_COUNT);
return availableId.get();
}
}
IdHolder releasedIds = localIdPool.getReleasedIds();
Optional<Long> releasedId = releasedIds.allocateId();
if (releasedId.isPresent()) {
IdHolderSyncJob poolSyncJob = new IdHolderSyncJob(localIdPool.getPoolName(), localIdPool.getReleasedIds(), txRunner, idUtils);
jobCoordinator.enqueueJob(localIdPool.getPoolName(), poolSyncJob, IdUtils.RETRY_COUNT);
return releasedId.get();
}
long idCount = getIdBlockFromParentPool(parentPoolName, localIdPool);
if (idCount <= 0) {
if (LOG.isDebugEnabled()) {
LOG.debug("Unable to allocate Id block from global pool {}", parentPoolName);
}
throw new IdManagerException(String.format("Ids exhausted for pool : %s", parentPoolName));
}
}
}
Aggregations