use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OLocalHashTable method remove.
@Override
public V remove(K key) {
final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
startOperation();
if (statistic != null)
statistic.startIndexEntryDeletionTimer();
try {
final OAtomicOperation atomicOperation;
try {
atomicOperation = startAtomicOperation(true);
} catch (IOException e) {
throw OException.wrapException(new OIndexException("Error during hash table entry deletion"), e);
}
acquireExclusiveLock();
try {
checkNullSupport(key);
int sizeDiff = 0;
if (key != null) {
key = keySerializer.preprocess(key, (Object[]) keyTypes);
final long hashCode = keyHashFunction.hashCode(key);
final OHashTable.BucketPath nodePath = getBucket(hashCode);
final long bucketPointer = directory.getNodePointer(nodePath.nodeIndex, nodePath.itemIndex + nodePath.hashMapOffset);
final long pageIndex = getPageIndex(bucketPointer);
final V removed;
final boolean found;
final OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
cacheEntry.acquireExclusiveLock();
try {
final OHashIndexBucket<K, V> bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
final int positionIndex = bucket.getIndex(hashCode, key);
found = positionIndex >= 0;
if (found) {
removed = bucket.deleteEntry(positionIndex).value;
sizeDiff--;
} else
removed = null;
} finally {
cacheEntry.releaseExclusiveLock();
releasePage(atomicOperation, cacheEntry);
}
if (found) {
if (nodePath.parent != null) {
final int hashMapSize = 1 << nodePath.nodeLocalDepth;
final boolean allMapsContainSameBucket = checkAllMapsContainSameBucket(directory.getNode(nodePath.nodeIndex), hashMapSize);
if (allMapsContainSameBucket)
mergeNodeToParent(nodePath);
}
changeSize(sizeDiff, atomicOperation);
}
endAtomicOperation(false, null);
return removed;
} else {
if (getFilledUpTo(atomicOperation, nullBucketFileId) == 0) {
endAtomicOperation(false, null);
return null;
}
V removed = null;
OCacheEntry cacheEntry = loadPage(atomicOperation, nullBucketFileId, 0, false);
if (cacheEntry == null)
cacheEntry = addPage(atomicOperation, nullBucketFileId);
cacheEntry.acquireExclusiveLock();
try {
final ONullBucket<V> nullBucket = new ONullBucket<V>(cacheEntry, getChanges(atomicOperation, cacheEntry), valueSerializer, false);
removed = nullBucket.getValue();
if (removed != null) {
nullBucket.removeValue();
sizeDiff--;
}
} finally {
cacheEntry.releaseExclusiveLock();
releasePage(atomicOperation, cacheEntry);
}
changeSize(sizeDiff, atomicOperation);
endAtomicOperation(false, null);
return removed;
}
} catch (IOException e) {
rollback(e);
throw OException.wrapException(new OIndexException("Error during index removal"), e);
} catch (Exception e) {
rollback(e);
throw OException.wrapException(new OStorageException("Error during index removal"), e);
} finally {
releaseExclusiveLock();
}
} finally {
if (statistic != null)
statistic.stopIndexEntryDeletionTimer();
completeOperation();
}
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OServerAdmin method networkAdminOperation.
protected <T> T networkAdminOperation(final OStorageRemoteOperation<T> operation, final String errorMessage) {
OChannelBinaryAsynchClient network = null;
try {
//TODO:replace this api with one that get connection for only the specified url.
String serverUrl = storage.getNextAvailableServerURL(false, session);
do {
try {
network = storage.getNetwork(serverUrl);
} catch (OException e) {
serverUrl = storage.useNewServerURL(serverUrl);
if (serverUrl == null)
throw e;
}
} while (network == null);
T res = operation.execute(network, storage.getCurrentSession());
storage.connectionManager.release(network);
return res;
} catch (Exception e) {
if (network != null)
storage.connectionManager.release(network);
storage.close(true, false);
throw OException.wrapException(new OStorageException(errorMessage), e);
}
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OAtomicOperation method addPage.
public OCacheEntry addPage(long fileId) throws IOException {
fileId = checkFileIdCompatibilty(fileId, storageId);
if (deletedFiles.contains(fileId))
throw new OStorageException("File with id " + fileId + " is deleted.");
final FileChanges changesContainer = fileChanges.get(fileId);
assert changesContainer != null;
final long filledUpTo = internalFilledUpTo(fileId, changesContainer);
FilePageChanges pageChangesContainer = changesContainer.pageChangesMap.get(filledUpTo);
assert pageChangesContainer == null;
pageChangesContainer = new FilePageChanges();
pageChangesContainer.isNew = true;
changesContainer.pageChangesMap.put(filledUpTo, pageChangesContainer);
changesContainer.maxNewPageIndex = filledUpTo;
return new OCacheEntry(fileId, filledUpTo, new OCachePointer(null, null, new OLogSequenceNumber(-1, -1), fileId, filledUpTo), false);
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OAtomicOperation method pinPage.
public void pinPage(OCacheEntry cacheEntry) throws IOException {
if (deletedFiles.contains(cacheEntry.getFileId()))
throw new OStorageException("File with id " + cacheEntry.getFileId() + " is deleted.");
final FileChanges changesContainer = fileChanges.get(cacheEntry.getFileId());
assert changesContainer != null;
final FilePageChanges pageChangesContainer = changesContainer.pageChangesMap.get(cacheEntry.getPageIndex());
assert pageChangesContainer != null;
pageChangesContainer.pinPage = true;
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OAtomicOperation method fileNameById.
public String fileNameById(long fileId) {
fileId = checkFileIdCompatibilty(fileId, storageId);
FileChanges fileChanges = this.fileChanges.get(fileId);
if (fileChanges != null && fileChanges.fileName != null)
return fileChanges.fileName;
if (deletedFiles.contains(fileId))
throw new OStorageException("File with id " + fileId + " was deleted.");
return writeCache.fileNameById(fileId);
}
Aggregations