Search in sources :

Example 11 with OCacheEntry

use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.

the class OLocalHashTable method size.

@Override
public long size() {
    startOperation();
    try {
        atomicOperationsManager.acquireReadLock(this);
        try {
            acquireSharedLock();
            try {
                final OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
                final OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, hashStateEntryIndex, true);
                hashStateEntry.acquireSharedLock();
                try {
                    OHashIndexFileLevelMetadataPage metadataPage = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
                    return metadataPage.getRecordsCount();
                } finally {
                    hashStateEntry.releaseSharedLock();
                    releasePage(atomicOperation, hashStateEntry);
                }
            } finally {
                releaseSharedLock();
            }
        } catch (IOException e) {
            throw OException.wrapException(new OLocalHashTableException("Error during index size request", this), e);
        } finally {
            atomicOperationsManager.releaseReadLock(this);
        }
    } 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)

Example 12 with OCacheEntry

use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.

the class OLocalHashTable20 method size.

@Override
public long size() {
    atomicOperationsManager.acquireReadLock(this);
    try {
        acquireSharedLock();
        try {
            final OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
            final OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, hashStateEntryIndex, true);
            try {
                OHashIndexFileLevelMetadataPage metadataPage = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
                return metadataPage.getRecordsCount();
            } finally {
                releasePage(atomicOperation, hashStateEntry);
            }
        } finally {
            releaseSharedLock();
        }
    } catch (IOException e) {
        throw OException.wrapException(new OIndexException("Error during index size request"), e);
    } finally {
        atomicOperationsManager.releaseReadLock(this);
    }
}
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 13 with OCacheEntry

use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.

the class OLocalHashTable20 method floorEntries.

@Override
public OHashIndexBucket.Entry<K, V>[] floorEntries(K key) {
    atomicOperationsManager.acquireReadLock(this);
    try {
        acquireSharedLock();
        try {
            OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
            key = keySerializer.preprocess(key, (Object[]) keyTypes);
            final long hashCode = keyHashFunction.hashCode(key);
            BucketPath bucketPath = getBucket(hashCode);
            long bucketPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex + bucketPath.hashMapOffset);
            int fileLevel = getFileLevel(bucketPointer);
            long pageIndex = getPageIndex(bucketPointer);
            OCacheEntry cacheEntry = loadPageEntry(pageIndex, fileLevel, atomicOperation);
            try {
                OHashIndexBucket<K, V> bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
                while (bucket.size() == 0) {
                    final BucketPath prevBucketPath = prevBucketToFind(bucketPath, bucket.getDepth());
                    if (prevBucketPath == null)
                        return OCommonConst.EMPTY_BUCKET_ENTRY_ARRAY;
                    releasePage(atomicOperation, cacheEntry);
                    final long prevPointer = directory.getNodePointer(prevBucketPath.nodeIndex, prevBucketPath.itemIndex + prevBucketPath.hashMapOffset);
                    fileLevel = getFileLevel(prevPointer);
                    pageIndex = getPageIndex(prevPointer);
                    cacheEntry = loadPageEntry(pageIndex, fileLevel, atomicOperation);
                    bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
                    bucketPath = prevBucketPath;
                }
                final int startIndex = 0;
                final int index = bucket.getIndex(hashCode, key);
                final int endIndex;
                if (index >= 0)
                    endIndex = index + 1;
                else
                    endIndex = -index - 1;
                return convertBucketToEntries(bucket, startIndex, endIndex);
            } finally {
                releasePage(atomicOperation, cacheEntry);
            }
        } finally {
            releaseSharedLock();
        }
    } catch (IOException ioe) {
        throw OException.wrapException(new OIndexException("Exception during data read"), ioe);
    } finally {
        atomicOperationsManager.releaseReadLock(this);
    }
}
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 14 with OCacheEntry

use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.

the class OLocalHashTable20 method splitBucket.

private BucketSplitResult splitBucket(OHashIndexBucket<K, V> bucket, int fileLevel, long pageIndex, OAtomicOperation atomicOperation) throws IOException {
    int bucketDepth = bucket.getDepth();
    int newBucketDepth = bucketDepth + 1;
    final int newFileLevel = newBucketDepth - MAX_LEVEL_DEPTH;
    final OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, hashStateEntryIndex, true);
    hashStateEntry.acquireExclusiveLock();
    try {
        OHashIndexFileLevelMetadataPage metadataPage = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
        if (metadataPage.isRemoved(newFileLevel))
            createFileMetadata(newFileLevel, metadataPage, atomicOperation);
        final long tombstoneIndex = metadataPage.getTombstoneIndex(newFileLevel);
        final long updatedBucketIndex;
        if (tombstoneIndex >= 0) {
            final OCacheEntry tombstoneCacheEntry = loadPageEntry(tombstoneIndex, newFileLevel, atomicOperation);
            try {
                final OHashIndexBucket<K, V> tombstone = new OHashIndexBucket<K, V>(tombstoneCacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, tombstoneCacheEntry));
                metadataPage.setTombstoneIndex(newFileLevel, tombstone.getNextRemovedBucketPair());
                updatedBucketIndex = tombstoneIndex;
            } finally {
                releasePage(atomicOperation, tombstoneCacheEntry);
            }
        } else
            updatedBucketIndex = getFilledUpTo(atomicOperation, metadataPage.getFileId(newFileLevel));
        final long newBucketIndex = updatedBucketIndex + 1;
        final OCacheEntry updatedBucketCacheEntry = loadPageEntry(updatedBucketIndex, newFileLevel, atomicOperation);
        updatedBucketCacheEntry.acquireExclusiveLock();
        try {
            final OCacheEntry newBucketCacheEntry = loadPageEntry(newBucketIndex, newFileLevel, atomicOperation);
            newBucketCacheEntry.acquireExclusiveLock();
            try {
                final OHashIndexBucket<K, V> updatedBucket = new OHashIndexBucket<K, V>(newBucketDepth, updatedBucketCacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, updatedBucketCacheEntry));
                final OHashIndexBucket<K, V> newBucket = new OHashIndexBucket<K, V>(newBucketDepth, newBucketCacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, newBucketCacheEntry));
                splitBucketContent(bucket, updatedBucket, newBucket, newBucketDepth);
                assert bucket.getDepth() == bucketDepth;
                metadataPage.setBucketsCount(fileLevel, metadataPage.getBucketsCount(fileLevel) - 1);
                assert metadataPage.getBucketsCount(fileLevel) >= 0;
                updatedBucket.setSplitHistory(fileLevel, pageIndex);
                newBucket.setSplitHistory(fileLevel, pageIndex);
                metadataPage.setBucketsCount(newFileLevel, metadataPage.getBucketsCount(newFileLevel) + 2);
                final long updatedBucketPointer = createBucketPointer(updatedBucketIndex, newFileLevel);
                final long newBucketPointer = createBucketPointer(newBucketIndex, newFileLevel);
                return new BucketSplitResult(updatedBucketPointer, newBucketPointer, newBucketDepth);
            } finally {
                newBucketCacheEntry.releaseExclusiveLock();
                releasePage(atomicOperation, newBucketCacheEntry);
            }
        } finally {
            updatedBucketCacheEntry.releaseExclusiveLock();
            releasePage(atomicOperation, updatedBucketCacheEntry);
        }
    } finally {
        hashStateEntry.releaseExclusiveLock();
        releasePage(atomicOperation, hashStateEntry);
    }
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry)

Example 15 with OCacheEntry

use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.

the class OLocalHashTable20 method ceilingEntries.

@Override
public OHashIndexBucket.Entry<K, V>[] ceilingEntries(K key) {
    atomicOperationsManager.acquireReadLock(this);
    try {
        acquireSharedLock();
        try {
            OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
            key = keySerializer.preprocess(key, (Object[]) keyTypes);
            final long hashCode = keyHashFunction.hashCode(key);
            BucketPath bucketPath = getBucket(hashCode);
            long bucketPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex + bucketPath.hashMapOffset);
            int fileLevel = getFileLevel(bucketPointer);
            long pageIndex = getPageIndex(bucketPointer);
            OCacheEntry cacheEntry = loadPageEntry(pageIndex, fileLevel, atomicOperation);
            try {
                OHashIndexBucket<K, V> bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
                while (bucket.size() == 0) {
                    bucketPath = nextBucketToFind(bucketPath, bucket.getDepth());
                    if (bucketPath == null)
                        return OCommonConst.EMPTY_BUCKET_ENTRY_ARRAY;
                    releasePage(atomicOperation, cacheEntry);
                    final long nextPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex + bucketPath.hashMapOffset);
                    fileLevel = getFileLevel(nextPointer);
                    pageIndex = getPageIndex(nextPointer);
                    cacheEntry = loadPageEntry(pageIndex, fileLevel, atomicOperation);
                    bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
                }
                final int index = bucket.getIndex(hashCode, key);
                final int startIndex;
                if (index >= 0)
                    startIndex = index;
                else
                    startIndex = -index - 1;
                final int endIndex = bucket.size();
                return convertBucketToEntries(bucket, startIndex, endIndex);
            } finally {
                releasePage(atomicOperation, cacheEntry);
            }
        } finally {
            releaseSharedLock();
        }
    } catch (IOException ioe) {
        throw OException.wrapException(new OIndexException("Error during data retrieval"), ioe);
    } finally {
        atomicOperationsManager.releaseReadLock(this);
    }
}
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)

Aggregations

OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)209 ByteBuffer (java.nio.ByteBuffer)77 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)76 OLogSequenceNumber (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber)74 OByteBufferPool (com.orientechnologies.common.directmemory.OByteBufferPool)69 OCachePointer (com.orientechnologies.orient.core.storage.cache.OCachePointer)65 IOException (java.io.IOException)61 OIndexException (com.orientechnologies.orient.core.index.OIndexException)23 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)20 OSessionStoragePerformanceStatistic (com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)20 OWALChangesTree (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree)19 OException (com.orientechnologies.common.exception.OException)17 Test (org.testng.annotations.Test)17 ORecordId (com.orientechnologies.orient.core.id.ORecordId)14 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)13 OLocalHashTableException (com.orientechnologies.orient.core.exception.OLocalHashTableException)12 OSBTreeBonsaiLocalException (com.orientechnologies.orient.core.exception.OSBTreeBonsaiLocalException)11 Lock (java.util.concurrent.locks.Lock)11 Random (java.util.Random)9 HashMap (java.util.HashMap)8