Search in sources :

Example 6 with OAtomicOperation

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation 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 7 with OAtomicOperation

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.

the class OLocalHashTable20 method load.

@Override
public void load(String name, OType[] keyTypes, boolean nullKeyIsSupported) {
    acquireExclusiveLock();
    try {
        if (keyTypes != null)
            this.keyTypes = Arrays.copyOf(keyTypes, keyTypes.length);
        else
            this.keyTypes = null;
        this.nullKeyIsSupported = nullKeyIsSupported;
        OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
        fileStateId = openFile(atomicOperation, name + metadataConfigurationFileExtension);
        final OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, 0, true);
        hashStateEntryIndex = hashStateEntry.getPageIndex();
        directory = new OHashTableDirectory(treeStateFileExtension, name, getFullName(), durableInNonTxMode, storage);
        directory.open();
        pinPage(atomicOperation, hashStateEntry);
        try {
            OHashIndexFileLevelMetadataPage page = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
            keySerializer = (OBinarySerializer<K>) storage.getComponentsFactory().binarySerializerFactory.getObjectSerializer(page.getKeySerializerId());
            valueSerializer = (OBinarySerializer<V>) storage.getComponentsFactory().binarySerializerFactory.getObjectSerializer(page.getValueSerializerId());
        } finally {
            releasePage(atomicOperation, hashStateEntry);
        }
        if (nullKeyIsSupported)
            nullBucketFileId = openFile(atomicOperation, name + nullBucketFileExtension);
    } catch (IOException e) {
        throw OException.wrapException(new OIndexException("Exception during hash table loading"), 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) IOException(java.io.IOException)

Example 8 with OAtomicOperation

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.

the class OLocalHashTable20 method create.

@Override
public void create(OBinarySerializer<K> keySerializer, OBinarySerializer<V> valueSerializer, OType[] keyTypes, boolean nullKeyIsSupported) {
    final OAtomicOperation atomicOperation;
    try {
        atomicOperation = startAtomicOperation(false);
    } catch (IOException e) {
        throw OException.wrapException(new OIndexException("Error during hash table creation"), e);
    }
    acquireExclusiveLock();
    try {
        try {
            if (keyTypes != null)
                this.keyTypes = Arrays.copyOf(keyTypes, keyTypes.length);
            else
                this.keyTypes = null;
            this.nullKeyIsSupported = nullKeyIsSupported;
            this.directory = new OHashTableDirectory(treeStateFileExtension, getName(), getFullName(), durableInNonTxMode, storage);
            fileStateId = addFile(atomicOperation, getName() + metadataConfigurationFileExtension);
            directory.create();
            final OCacheEntry hashStateEntry = addPage(atomicOperation, fileStateId);
            pinPage(atomicOperation, hashStateEntry);
            hashStateEntry.acquireExclusiveLock();
            try {
                OHashIndexFileLevelMetadataPage page = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), true);
                createFileMetadata(0, page, atomicOperation);
                hashStateEntryIndex = hashStateEntry.getPageIndex();
            } finally {
                hashStateEntry.releaseExclusiveLock();
                releasePage(atomicOperation, hashStateEntry);
            }
            setKeySerializer(keySerializer);
            setValueSerializer(valueSerializer);
            initHashTreeState(atomicOperation);
            if (nullKeyIsSupported)
                nullBucketFileId = addFile(atomicOperation, getName() + nullBucketFileExtension);
            endAtomicOperation(false, null);
        } catch (IOException e) {
            endAtomicOperation(true, e);
            throw e;
        } catch (Exception e) {
            endAtomicOperation(true, e);
            throw OException.wrapException(new OStorageException("Error during local hash table creation"), e);
        }
    } catch (IOException e) {
        throw OException.wrapException(new OIndexException("Error during local hash table creation"), 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)

Example 9 with OAtomicOperation

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.

the class OLocalHashTable20 method deleteWithoutLoad.

@Override
public void deleteWithoutLoad(String name, OAbstractPaginatedStorage storageLocal) {
    final OAtomicOperation atomicOperation;
    try {
        atomicOperation = startAtomicOperation(false);
    } catch (IOException e) {
        throw OException.wrapException(new OIndexException("Error during hash table deletion"), e);
    }
    acquireExclusiveLock();
    try {
        if (isFileExists(atomicOperation, name + metadataConfigurationFileExtension)) {
            fileStateId = openFile(atomicOperation, name + metadataConfigurationFileExtension);
            OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, 0, true);
            try {
                OHashIndexFileLevelMetadataPage metadataPage = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
                for (int i = 0; i < HASH_CODE_SIZE; i++) {
                    if (!metadataPage.isRemoved(i)) {
                        final long fileId = metadataPage.getFileId(i);
                        deleteFile(atomicOperation, fileId);
                    }
                }
            } finally {
                releasePage(atomicOperation, hashStateEntry);
            }
            if (isFileExists(atomicOperation, fileStateId))
                deleteFile(atomicOperation, fileStateId);
            directory = new OHashTableDirectory(treeStateFileExtension, name, getFullName(), durableInNonTxMode, storage);
            directory.deleteWithoutOpen();
            if (isFileExists(atomicOperation, name + nullBucketFileExtension)) {
                final long nullBucketId = openFile(atomicOperation, name + nullBucketFileExtension);
                deleteFile(atomicOperation, nullBucketId);
            }
        }
        endAtomicOperation(false, null);
    } catch (IOException ioe) {
        rollback();
        throw OException.wrapException(new OIndexException("Cannot delete hash table with name " + name), ioe);
    } catch (Exception e) {
        rollback();
        throw OException.wrapException(new OIndexException("Cannot delete hash table with name " + name), 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) 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 10 with OAtomicOperation

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.

the class OSBTree method clear.

public void clear() {
    startOperation();
    try {
        final OAtomicOperation atomicOperation;
        try {
            atomicOperation = startAtomicOperation(true);
        } catch (IOException e) {
            throw OException.wrapException(new OSBTreeException("Error during sbtree clear", this), e);
        }
        acquireExclusiveLock();
        try {
            truncateFile(atomicOperation, fileId);
            if (nullPointerSupport)
                truncateFile(atomicOperation, nullBucketFileId);
            OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, ROOT_INDEX, false);
            if (cacheEntry == null) {
                cacheEntry = addPage(atomicOperation, fileId);
            }
            cacheEntry.acquireExclusiveLock();
            try {
                OSBTreeBucket<K, V> rootBucket = new OSBTreeBucket<K, V>(cacheEntry, true, keySerializer, keyTypes, valueSerializer, getChanges(atomicOperation, cacheEntry));
                rootBucket.setTreeSize(0);
            } finally {
                cacheEntry.releaseExclusiveLock();
                releasePage(atomicOperation, cacheEntry);
            }
            endAtomicOperation(false, null);
        } catch (IOException e) {
            rollback(e);
            throw OException.wrapException(new OSBTreeException("Error during clear of sbtree with name " + getName(), this), e);
        } catch (RuntimeException e) {
            rollback(e);
            throw e;
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) IOException(java.io.IOException)

Aggregations

OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)118 IOException (java.io.IOException)94 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)76 OException (com.orientechnologies.common.exception.OException)42 OIndexException (com.orientechnologies.orient.core.index.OIndexException)28 OSessionStoragePerformanceStatistic (com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)25 OLocalHashTableException (com.orientechnologies.orient.core.exception.OLocalHashTableException)16 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)16 OSBTreeBonsaiLocalException (com.orientechnologies.orient.core.exception.OSBTreeBonsaiLocalException)13 Lock (java.util.concurrent.locks.Lock)13 OHashTableDirectoryException (com.orientechnologies.orient.core.exception.OHashTableDirectoryException)11 OTooBigIndexKeyException (com.orientechnologies.orient.core.exception.OTooBigIndexKeyException)11 OPaginatedClusterException (com.orientechnologies.orient.core.exception.OPaginatedClusterException)9 OIndexEngineException (com.orientechnologies.orient.core.index.OIndexEngineException)9 OClusterPositionMapException (com.orientechnologies.orient.core.exception.OClusterPositionMapException)8 ORecordId (com.orientechnologies.orient.core.id.ORecordId)7 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)6 OReadCache (com.orientechnologies.orient.core.storage.cache.OReadCache)2 OWriteCache (com.orientechnologies.orient.core.storage.cache.OWriteCache)2 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1