use of org.opendaylight.genius.idmanager.jobs.UpdateIdEntryJob 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.UpdateIdEntryJob in project genius by opendaylight.
the class IdManager method allocateIdFromLocalPool.
private List<Long> allocateIdFromLocalPool(String parentPoolName, String localPoolName, String idKey, long size) throws OperationFailedException, IdManagerException {
LOG.debug("Allocating id from local pool {}. Parent pool {}. Idkey {}", localPoolName, parentPoolName, idKey);
String uniqueIdKey = idUtils.getUniqueKey(parentPoolName, idKey);
CompletableFuture<List<Long>> futureIdValues = new CompletableFuture<>();
CompletableFuture<List<Long>> existingFutureIdValue = idUtils.putAllocatedIdsIfAbsent(uniqueIdKey, futureIdValues);
if (existingFutureIdValue != null) {
try {
return existingFutureIdValue.get();
} catch (InterruptedException | ExecutionException e) {
LOG.warn("Could not obtain id from existing futureIdValue for idKey {} and pool {}.", idKey, parentPoolName);
throw new IdManagerException(e.getMessage(), e);
}
}
try {
List<Long> newIdValuesList = checkForIdInIdEntries(parentPoolName, idKey, uniqueIdKey, futureIdValues, false);
if (!newIdValuesList.isEmpty()) {
return newIdValuesList;
}
// This get will not help in concurrent reads. Hence the same read needs to be done again.
IdLocalPool localIdPool = getOrCreateLocalIdPool(parentPoolName, localPoolName);
LOG.debug("Got pool {}", localIdPool);
long newIdValue = -1;
localPoolName = localPoolName.intern();
if (size == 1) {
newIdValue = getIdFromLocalPoolCache(localIdPool, parentPoolName);
newIdValuesList.add(newIdValue);
} else {
getRangeOfIds(parentPoolName, localPoolName, size, newIdValuesList, localIdPool, newIdValue);
}
LOG.debug("The newIdValues {} for the idKey {}", newIdValuesList, idKey);
idUtils.putReleaseIdLatch(uniqueIdKey, new CountDownLatch(1));
UpdateIdEntryJob job = new UpdateIdEntryJob(parentPoolName, localPoolName, idKey, newIdValuesList, txRunner, idUtils, lockManager);
jobCoordinator.enqueueJob(parentPoolName, job, IdUtils.RETRY_COUNT);
futureIdValues.complete(newIdValuesList);
return newIdValuesList;
} catch (OperationFailedException | IdManagerException e) {
idUtils.unlock(lockManager, uniqueIdKey);
throw e;
}
}
Aggregations