use of java.util.ConcurrentModificationException in project cloudstack by apache.
the class NetappManagerImpl method destroyVolumeOnFiler.
/**
* This method destroys the volume on netapp filer
* @param ipAddress -- ip address of filer
* @param aggrName -- name of containing aggregate
* @param volName -- name of volume to destroy
* @throws ResourceInUseException
* @throws NaException
* @throws NaAPIFailedException
*/
@Override
@DB
public void destroyVolumeOnFiler(String ipAddress, String aggrName, String volName) throws ServerException, InvalidParameterValueException, ResourceInUseException {
NaElement xi0;
NaElement xi1;
NetappVolumeVO volume = null;
volume = _volumeDao.findVolume(ipAddress, aggrName, volName);
if (volume == null) {
s_logger.warn("The volume does not exist in our system");
throw new InvalidParameterValueException("The given tuple:" + ipAddress + "," + aggrName + "," + volName + " doesn't exist in our system");
}
List<LunVO> lunsOnVol = _lunDao.listLunsByVolId(volume.getId());
if (lunsOnVol != null && lunsOnVol.size() > 0) {
s_logger.warn("There are luns on the volume");
throw new ResourceInUseException("There are luns on the volume");
}
final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
PoolVO pool = _poolDao.findById(volume.getPoolId());
if (pool == null) {
throw new InvalidParameterValueException("Failed to find pool for given volume");
//FIXME: choose a better exception. this is a db integrity exception
}
pool = _poolDao.acquireInLockTable(pool.getId());
if (pool == null) {
throw new ConcurrentModificationException("Failed to acquire lock on pool " + volume.getPoolId());
}
NaServer s = null;
try {
s = getServer(volume.getIpAddress(), volume.getUsername(), volume.getPassword());
//bring the volume down
xi0 = new NaElement("volume-offline");
xi0.addNewChild("name", volName);
s.invokeElem(xi0);
//now destroy it
xi1 = new NaElement("volume-destroy");
xi1.addNewChild("name", volName);
s.invokeElem(xi1);
//now delete from our records
_volumeDao.remove(volume.getId());
txn.commit();
} catch (UnknownHostException uhe) {
s_logger.warn("Unable to delete volume on filer ", uhe);
throw new ServerException("Unable to delete volume on filer", uhe);
} catch (NaAPIFailedException naf) {
s_logger.warn("Unable to delete volume on filer ", naf);
if (naf.getErrno() == 13040) {
s_logger.info("Deleting the volume: " + volName);
_volumeDao.remove(volume.getId());
txn.commit();
}
throw new ServerException("Unable to delete volume on filer", naf);
} catch (NaException nae) {
txn.rollback();
s_logger.warn("Unable to delete volume on filer ", nae);
throw new ServerException("Unable to delete volume on filer", nae);
} catch (IOException ioe) {
txn.rollback();
s_logger.warn("Unable to delete volume on filer ", ioe);
throw new ServerException("Unable to delete volume on filer", ioe);
} finally {
if (pool != null) {
_poolDao.releaseFromLockTable(pool.getId());
}
if (s != null)
s.close();
}
}
use of java.util.ConcurrentModificationException in project jackrabbit by apache.
the class VersionIteratorImpl method nextVersion.
/**
* {@inheritDoc}
*/
public Version nextVersion() {
if (versions.isEmpty()) {
throw new NoSuchElementException();
}
NodeId id = versions.removeFirst();
pos++;
try {
return (Version) session.getNodeById(id);
} catch (RepositoryException e) {
throw new ConcurrentModificationException("Unable to provide element: " + e.toString());
}
}
use of java.util.ConcurrentModificationException in project jackrabbit by apache.
the class ItemSaveOperation method perform.
public Object perform(SessionContext context) throws RepositoryException {
SessionItemStateManager stateMgr = context.getItemStateManager();
/**
* build list of transient (i.e. new & modified) states that
* should be persisted
*/
Collection<ItemState> dirty;
try {
dirty = getTransientStates(context.getItemStateManager());
} catch (ConcurrentModificationException e) {
String msg = "Concurrent modification; session is closed";
log.error(msg, e);
context.getSessionImpl().logout();
throw e;
}
if (dirty.size() == 0) {
// no transient items, nothing to do here
return this;
}
/**
* build list of transient descendants in the attic
* (i.e. those marked as 'removed')
*/
Collection<ItemState> removed = getRemovedStates(context.getItemStateManager());
// All affected item states. The keys are used to look up whether
// an item is affected, and the values are iterated through below
Map<ItemId, ItemState> affected = new HashMap<ItemId, ItemState>(dirty.size() + removed.size());
for (ItemState state : dirty) {
affected.put(state.getId(), state);
}
for (ItemState state : removed) {
affected.put(state.getId(), state);
}
/**
* make sure that this save operation is totally 'self-contained'
* and independent; items within the scope of this save operation
* must not have 'external' dependencies;
* (e.g. moving a node requires that the target node including both
* old and new parents are saved)
*/
for (ItemState transientState : affected.values()) {
if (transientState.isNode()) {
NodeState nodeState = (NodeState) transientState;
Set<NodeId> dependentIDs = new HashSet<NodeId>();
if (nodeState.hasOverlayedState()) {
NodeState overlayedState = (NodeState) nodeState.getOverlayedState();
NodeId oldParentId = overlayedState.getParentId();
NodeId newParentId = nodeState.getParentId();
if (oldParentId != null) {
if (newParentId == null) {
// to dependencies
if (overlayedState.isShareable()) {
dependentIDs.addAll(overlayedState.getSharedSet());
} else {
dependentIDs.add(oldParentId);
}
} else {
if (!oldParentId.equals(newParentId)) {
// node has been moved to a new location,
// add old and new parent to dependencies
dependentIDs.add(oldParentId);
dependentIDs.add(newParentId);
} else {
// the node has been renamed (JCR-1034)
if (!affected.containsKey(newParentId) && stateMgr.hasTransientItemState(newParentId)) {
try {
NodeState parent = (NodeState) stateMgr.getTransientItemState(newParentId);
// check parent's renamed child node entries
for (ChildNodeEntry cne : parent.getRenamedChildNodeEntries()) {
if (cne.getId().equals(nodeState.getId())) {
// node has been renamed,
// add parent to dependencies
dependentIDs.add(newParentId);
}
}
} catch (ItemStateException ise) {
// should never get here
log.warn("failed to retrieve transient state: " + newParentId, ise);
}
}
}
}
}
}
// removed child node entries
for (ChildNodeEntry cne : nodeState.getRemovedChildNodeEntries()) {
dependentIDs.add(cne.getId());
}
// added child node entries
for (ChildNodeEntry cne : nodeState.getAddedChildNodeEntries()) {
dependentIDs.add(cne.getId());
}
// are within the scope of this save operation
for (NodeId id : dependentIDs) {
if (!affected.containsKey(id)) {
// otherwise ignore them
if (stateMgr.hasTransientItemState(id) || stateMgr.hasTransientItemStateInAttic(id)) {
// need to save dependency as well
String msg = context.getItemManager().safeGetJCRPath(id) + " needs to be saved as well.";
log.debug(msg);
throw new ConstraintViolationException(msg);
}
}
}
}
}
// validate access and node type constraints
// (this will also validate child removals)
validateTransientItems(context, dirty, removed);
// start the update operation
try {
stateMgr.edit();
} catch (IllegalStateException e) {
throw new RepositoryException("Unable to start edit operation", e);
}
boolean succeeded = false;
try {
// process transient items marked as 'removed'
removeTransientItems(context.getItemStateManager(), removed);
// process transient items that have change in mixins
processShareableNodes(context.getRepositoryContext().getNodeTypeRegistry(), dirty);
// initialize version histories for new nodes (might generate new transient state)
if (initVersionHistories(context, dirty)) {
// re-build the list of transient states because the previous call
// generated new transient state
dirty = getTransientStates(context.getItemStateManager());
}
// process 'new' or 'modified' transient states
persistTransientItems(context.getItemManager(), dirty);
// item state which is not referenced by any node instance.
for (ItemState transientState : dirty) {
// dispose the transient state, it is no longer used
stateMgr.disposeTransientItemState(transientState);
}
// end update operation
stateMgr.update();
// update operation succeeded
succeeded = true;
} catch (StaleItemStateException e) {
throw new InvalidItemStateException("Unable to update a stale item: " + this, e);
} catch (ItemStateException e) {
throw new RepositoryException("Unable to update item: " + this, e);
} finally {
if (!succeeded) {
// update operation failed, cancel all modifications
stateMgr.cancel();
// JCR-288: if an exception has been thrown during
// update() the transient changes have already been
// applied by persistTransientItems() and we need to
// restore transient state, i.e. undo the effect of
// persistTransientItems()
restoreTransientItems(context, dirty);
}
}
// items in store().
for (ItemState transientState : removed) {
// dispose the transient state, it is no longer used
stateMgr.disposeTransientItemStateInAttic(transientState);
}
return this;
}
use of java.util.ConcurrentModificationException in project jena by apache.
the class ArrayBunch method iterator.
@Override
public ExtendedIterator<Triple> iterator(final HashCommon.NotifyEmpty container) {
// System.err.println( ">> (done)" );
return new NiceIterator<Triple>() {
protected final int initialChanges = changes;
protected int i = size;
protected final Triple[] e = elements;
@Override
public boolean hasNext() {
if (changes > initialChanges)
throw new ConcurrentModificationException();
return i > 0;
}
@Override
public Triple next() {
if (changes > initialChanges)
throw new ConcurrentModificationException();
if (i == 0)
noElements("no elements left in ArrayBunch iteration");
return e[--i];
}
@Override
public void remove() {
if (changes > initialChanges)
throw new ConcurrentModificationException();
// System.err.println( ">> ArrayBunch.iterator::remove" );
// System.err.println( "++ size currently " + size );
// System.err.println( "++ container is " + container );
// System.err.println( "++ selector currently " + i + " (triple " + e[i] + ")" );
int last = --size;
e[i] = e[last];
e[last] = null;
if (size == 0)
container.emptied();
// System.err.println( "++ post remove, triples are:" );
// for (int j = 0; j < size; j += 1) System.err.println( "== " + e[j] );
}
};
}
use of java.util.ConcurrentModificationException in project lucene-solr by apache.
the class TestLRUQueryCache method testDetectMutatedQueries.
public void testDetectMutatedQueries() throws IOException {
LuceneTestCase.assumeFalse("LUCENE-7604: For some unknown reason the non-constant BadQuery#hashCode() does not trigger ConcurrentModificationException on Java 9 b150", Constants.JRE_IS_MINIMUM_JAVA9);
Directory dir = newDirectory();
final RandomIndexWriter w = new RandomIndexWriter(random(), dir);
w.addDocument(new Document());
IndexReader reader = w.getReader();
// size of 1 so that 2nd query evicts from the cache
final LRUQueryCache queryCache = new LRUQueryCache(1, 10000, context -> true);
final IndexSearcher searcher = newSearcher(reader);
searcher.setQueryCache(queryCache);
searcher.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
BadQuery query = new BadQuery();
searcher.count(query);
// change the hashCode!
query.i[0] += 1;
try {
// trigger an eviction
searcher.search(new MatchAllDocsQuery(), new TotalHitCountCollector());
fail();
} catch (ConcurrentModificationException e) {
// expected
} catch (RuntimeException e) {
// expected: wrapped when executor is in use
Throwable cause = e.getCause();
assertTrue(cause instanceof ExecutionException);
assertTrue(cause.getCause() instanceof ConcurrentModificationException);
}
IOUtils.close(w, reader, dir);
}
Aggregations