Search in sources :

Example 81 with OAtomicOperation

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

the class OSBTreeBonsaiLocal method clear.

/**
   * Removes all entries from bonsai tree. Put all but the root page to free list for further reuse.
   */
@Override
public void clear() {
    startOperation();
    try {
        final OAtomicOperation atomicOperation;
        try {
            atomicOperation = startAtomicOperation(true);
        } catch (IOException e) {
            throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during sbtree entrie clear", this), e);
        }
        final Lock lock = FILE_LOCK_MANAGER.acquireExclusiveLock(fileId);
        try {
            final Queue<OBonsaiBucketPointer> subTreesToDelete = new LinkedList<OBonsaiBucketPointer>();
            OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, rootBucketPointer.getPageIndex(), false);
            cacheEntry.acquireExclusiveLock();
            try {
                OSBTreeBonsaiBucket<K, V> rootBucket = new OSBTreeBonsaiBucket<K, V>(cacheEntry, rootBucketPointer.getPageOffset(), keySerializer, valueSerializer, getChanges(atomicOperation, cacheEntry), this);
                addChildrenToQueue(subTreesToDelete, rootBucket);
                rootBucket.shrink(0);
                rootBucket = new OSBTreeBonsaiBucket<K, V>(cacheEntry, rootBucketPointer.getPageOffset(), true, keySerializer, valueSerializer, getChanges(atomicOperation, cacheEntry), this);
                rootBucket.setTreeSize(0);
            } finally {
                cacheEntry.releaseExclusiveLock();
                releasePage(atomicOperation, cacheEntry);
            }
            recycleSubTrees(subTreesToDelete, atomicOperation);
            endAtomicOperation(false, null);
        } catch (IOException e) {
            rollback(e);
            throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during clear of sbtree with name " + getName(), this), e);
        } catch (RuntimeException e) {
            rollback(e);
            throw e;
        } finally {
            lock.unlock();
        }
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OSBTreeBonsaiLocalException(com.orientechnologies.orient.core.exception.OSBTreeBonsaiLocalException) IOException(java.io.IOException) Lock(java.util.concurrent.locks.Lock) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry)

Example 82 with OAtomicOperation

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

the class OLocalHashTable method load.

@Override
public void load(String name, OType[] keyTypes, boolean nullKeyIsSupported) {
    startOperation();
    try {
        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);
            hashStateEntry.acquireSharedLock();
            try {
                OHashIndexFileLevelMetadataPage page = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
                OBinarySerializerFactory serializerFactory = OBinarySerializerFactory.create(storage.getConfiguration().binaryFormatVersion);
                keySerializer = (OBinarySerializer<K>) serializerFactory.getObjectSerializer(page.getKeySerializerId());
                valueSerializer = (OBinarySerializer<V>) serializerFactory.getObjectSerializer(page.getValueSerializerId());
            } finally {
                hashStateEntry.releaseSharedLock();
                releasePage(atomicOperation, hashStateEntry);
            }
            if (nullKeyIsSupported)
                nullBucketFileId = openFile(atomicOperation, name + nullBucketFileExtension);
            fileId = openFile(atomicOperation, getFullName());
        } catch (IOException e) {
            throw OException.wrapException(new OLocalHashTableException("Exception during hash table loading", this), 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) OLocalHashTableException(com.orientechnologies.orient.core.exception.OLocalHashTableException) IOException(java.io.IOException) OBinarySerializerFactory(com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)

Example 83 with OAtomicOperation

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

the class OLocalHashTable method delete.

@Override
public void delete() {
    startOperation();
    try {
        final OAtomicOperation atomicOperation;
        try {
            atomicOperation = startAtomicOperation(false);
        } catch (IOException e) {
            throw OException.wrapException(new OLocalHashTableException("Error during hash table deletion", this), e);
        }
        acquireExclusiveLock();
        try {
            directory.delete();
            deleteFile(atomicOperation, fileStateId);
            deleteFile(atomicOperation, fileId);
            if (nullKeyIsSupported)
                deleteFile(atomicOperation, nullBucketFileId);
            endAtomicOperation(false, null);
        } catch (IOException e) {
            rollback(e);
            throw OException.wrapException(new OLocalHashTableException("Exception during index deletion", this), e);
        } catch (Exception e) {
            rollback(e);
            throw OException.wrapException(new OLocalHashTableException("Exception during index deletion", this), e);
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OLocalHashTableException(com.orientechnologies.orient.core.exception.OLocalHashTableException) IOException(java.io.IOException) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OLocalHashTableException(com.orientechnologies.orient.core.exception.OLocalHashTableException) OTooBigIndexKeyException(com.orientechnologies.orient.core.exception.OTooBigIndexKeyException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Example 84 with OAtomicOperation

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

the class OLocalHashTable20 method setValueSerializer.

@Override
public void setValueSerializer(OBinarySerializer<V> valueSerializer) {
    final OAtomicOperation atomicOperation;
    try {
        atomicOperation = startAtomicOperation(true);
    } catch (IOException e) {
        throw OException.wrapException(new OIndexException("Error during hash table set serializer for index values"), e);
    }
    acquireExclusiveLock();
    try {
        this.valueSerializer = valueSerializer;
        final OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, hashStateEntryIndex, true);
        hashStateEntry.acquireExclusiveLock();
        try {
            OHashIndexFileLevelMetadataPage metadataPage = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
            metadataPage.setValueSerializerId(valueSerializer.getId());
        } finally {
            hashStateEntry.releaseExclusiveLock();
            releasePage(atomicOperation, hashStateEntry);
        }
        endAtomicOperation(false, null);
    } catch (IOException e) {
        rollback();
        throw OException.wrapException(new OIndexException("Cannot set serializer for index values"), e);
    } catch (Exception e) {
        rollback();
        throw OException.wrapException(new OStorageException("Cannot set serializer for index values"), 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 85 with OAtomicOperation

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

the class OLocalHashTable20 method clear.

@Override
public void clear() {
    final OAtomicOperation atomicOperation;
    try {
        atomicOperation = startAtomicOperation(true);
    } catch (IOException e) {
        throw OException.wrapException(new OIndexException("Error during hash table clear"), e);
    }
    acquireExclusiveLock();
    try {
        final OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, hashStateEntryIndex, true);
        hashStateEntry.acquireExclusiveLock();
        try {
            OHashIndexFileLevelMetadataPage page = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
            for (int i = 0; i < HASH_CODE_SIZE; i++) {
                if (!page.isRemoved(i)) {
                    truncateFile(atomicOperation, page.getFileId(i));
                    page.setBucketsCount(i, 0);
                    page.setTombstoneIndex(i, -1);
                }
            }
        } finally {
            hashStateEntry.releaseExclusiveLock();
            releasePage(atomicOperation, hashStateEntry);
        }
        if (nullKeyIsSupported)
            truncateFile(atomicOperation, nullBucketFileId);
        initHashTreeState(atomicOperation);
        endAtomicOperation(false, null);
    } catch (IOException e) {
        rollback();
        throw OException.wrapException(new OIndexEngineException("Error during hash table clear", getName()), e);
    } catch (Exception e) {
        rollback();
        throw OException.wrapException(new OIndexEngineException("Error during hash table clear", getName()), 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) OIndexEngineException(com.orientechnologies.orient.core.index.OIndexEngineException)

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