Search in sources :

Example 1 with OStorageException

use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.

the class OClusterPositionMapBucket method resurrect.

public void resurrect(final int index, final PositionEntry entry) throws IOException {
    final int size = getIntValue(SIZE_OFFSET);
    if (index >= size)
        throw new OStorageException("Cannot resurrect a record: provided index " + index + " is out of range");
    final int position = entryPosition(index);
    final byte flag = getByteValue(position);
    if (flag == REMOVED)
        setByteValue(position, FILLED);
    else
        throw new OStorageException("Cannot resurrect a record: provided index " + index + " points to a non removed entry");
    updateEntry(position, entry);
}
Also used : OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Example 2 with OStorageException

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);
    }
}
Also used : OStorageException(com.orientechnologies.orient.core.exception.OStorageException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OChannelBinaryAsynchClient(com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) OModificationOperationProhibitedException(com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)

Example 3 with OStorageException

use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.

the class OLocalHashTable20 method put.

private boolean put(K key, V value, OIndexEngine.Validator<K, V> validator) {
    final OAtomicOperation atomicOperation;
    try {
        atomicOperation = startAtomicOperation(true);
    } catch (IOException e) {
        throw OException.wrapException(new OIndexException("Error during hash table entry put"), e);
    }
    acquireExclusiveLock();
    try {
        checkNullSupport(key);
        key = keySerializer.preprocess(key, (Object[]) keyTypes);
        final boolean putResult = doPut(key, value, validator, atomicOperation);
        endAtomicOperation(false, null);
        return putResult;
    } catch (IOException e) {
        rollback();
        throw OException.wrapException(new OIndexException("Error during index update"), e);
    } catch (Exception e) {
        rollback();
        throw OException.wrapException(new OStorageException("Error during index update"), e);
    } finally {
        releaseExclusiveLock();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) IOException(java.io.IOException) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OIndexEngineException(com.orientechnologies.orient.core.index.OIndexEngineException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Example 4 with OStorageException

use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.

the class OLocalHashTable20 method remove.

@Override
public V remove(K key) {
    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 BucketPath nodePath = getBucket(hashCode);
            final long bucketPointer = directory.getNodePointer(nodePath.nodeIndex, nodePath.itemIndex + nodePath.hashMapOffset);
            final long pageIndex = getPageIndex(bucketPointer);
            final int fileLevel = getFileLevel(bucketPointer);
            final V removed;
            final boolean found;
            final OCacheEntry cacheEntry = loadPageEntry(pageIndex, fileLevel, atomicOperation);
            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--;
                    mergeBucketsAfterDeletion(nodePath, bucket, atomicOperation);
                } 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();
        throw OException.wrapException(new OIndexException("Error during index removal"), e);
    } catch (Exception e) {
        rollback();
        throw OException.wrapException(new OStorageException("Error during index removal"), e);
    } finally {
        releaseExclusiveLock();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OIndexException(com.orientechnologies.orient.core.index.OIndexException) IOException(java.io.IOException) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OIndexEngineException(com.orientechnologies.orient.core.index.OIndexEngineException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Example 5 with OStorageException

use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.

the class OLocalHashTable20 method setKeySerializer.

@Override
public void setKeySerializer(OBinarySerializer<K> keySerializer) {
    final OAtomicOperation atomicOperation;
    try {
        atomicOperation = startAtomicOperation(true);
    } catch (IOException e) {
        throw OException.wrapException(new OIndexException("Error during hash set serializer for index keys"), e);
    }
    acquireExclusiveLock();
    try {
        this.keySerializer = keySerializer;
        OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, hashStateEntryIndex, true);
        hashStateEntry.acquireExclusiveLock();
        try {
            OHashIndexFileLevelMetadataPage metadataPage = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
            metadataPage.setKeySerializerId(keySerializer.getId());
        } finally {
            hashStateEntry.releaseExclusiveLock();
            releasePage(atomicOperation, hashStateEntry);
        }
        endAtomicOperation(false, null);
    } catch (IOException e) {
        rollback();
        throw OException.wrapException(new OIndexException("Cannot set serializer for index keys"), e);
    } catch (Exception e) {
        rollback();
        throw OException.wrapException(new OStorageException("Cannot set serializer for index keys"), e);
    } finally {
        releaseExclusiveLock();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) IOException(java.io.IOException) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OIndexEngineException(com.orientechnologies.orient.core.index.OIndexEngineException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Aggregations

OStorageException (com.orientechnologies.orient.core.exception.OStorageException)51 OException (com.orientechnologies.common.exception.OException)14 IOException (java.io.IOException)13 OIndexException (com.orientechnologies.orient.core.index.OIndexException)10 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)10 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)10 OFileClassic (com.orientechnologies.orient.core.storage.fs.OFileClassic)7 OLocalHashTableException (com.orientechnologies.orient.core.exception.OLocalHashTableException)5 OTooBigIndexKeyException (com.orientechnologies.orient.core.exception.OTooBigIndexKeyException)5 OIndexEngineException (com.orientechnologies.orient.core.index.OIndexEngineException)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)4 OCachePointer (com.orientechnologies.orient.core.storage.cache.OCachePointer)4 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)3 OSessionStoragePerformanceStatistic (com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)3 ByteBuffer (java.nio.ByteBuffer)3 SubScheduledExecutorService (com.orientechnologies.common.concur.executors.SubScheduledExecutorService)2 OType (com.orientechnologies.orient.core.metadata.schema.OType)2 OLogSequenceNumber (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber)2 File (java.io.File)2