Search in sources :

Example 31 with OSessionStoragePerformanceStatistic

use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic in project orientdb by orientechnologies.

the class OSBTreeBonsaiLocal method loadEntriesMinor.

@Override
public void loadEntriesMinor(K key, boolean inclusive, RangeResultListener<K, V> listener) {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    startOperation();
    int readEntries = 0;
    if (statistic != null)
        statistic.startRidBagEntryReadTimer();
    try {
        atomicOperationsManager.acquireReadLock(this);
        try {
            final Lock lock = FILE_LOCK_MANAGER.acquireSharedLock(fileId);
            try {
                OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
                BucketSearchResult bucketSearchResult = findBucket(key, atomicOperation);
                OBonsaiBucketPointer bucketPointer = bucketSearchResult.getLastPathItem();
                int index;
                if (bucketSearchResult.itemIndex >= 0) {
                    index = inclusive ? bucketSearchResult.itemIndex : bucketSearchResult.itemIndex - 1;
                } else {
                    index = -bucketSearchResult.itemIndex - 2;
                }
                boolean firstBucket = true;
                do {
                    OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, bucketPointer.getPageIndex(), false);
                    cacheEntry.acquireSharedLock();
                    try {
                        OSBTreeBonsaiBucket<K, V> bucket = new OSBTreeBonsaiBucket<K, V>(cacheEntry, bucketPointer.getPageOffset(), keySerializer, valueSerializer, getChanges(atomicOperation, cacheEntry), this);
                        if (!firstBucket)
                            index = bucket.size() - 1;
                        for (int i = index; i >= 0; i--) {
                            if (!listener.addResult(bucket.getEntry(i))) {
                                readEntries++;
                                return;
                            }
                        }
                        bucketPointer = bucket.getLeftSibling();
                        firstBucket = false;
                    } finally {
                        cacheEntry.releaseSharedLock();
                        releasePage(atomicOperation, cacheEntry);
                    }
                } while (bucketPointer.getPageIndex() >= 0);
            } finally {
                lock.unlock();
            }
        } catch (IOException ioe) {
            throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during fetch of minor values for key " + key + " in sbtree " + getName(), this), ioe);
        } finally {
            atomicOperationsManager.releaseReadLock(this);
        }
    } finally {
        if (statistic != null)
            statistic.stopRidBagEntryReadTimer(readEntries);
        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) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)

Example 32 with OSessionStoragePerformanceStatistic

use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic in project orientdb by orientechnologies.

the class OSBTree method iterateEntriesMinor.

public OSBTreeCursor<K, V> iterateEntriesMinor(K key, boolean inclusive, boolean ascSortOrder) {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    startOperation();
    if (statistic != null)
        statistic.startIndexEntryReadTimer();
    try {
        atomicOperationsManager.acquireReadLock(this);
        try {
            acquireSharedLock();
            try {
                OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
                if (!ascSortOrder)
                    return iterateEntriesMinorDesc(key, inclusive, atomicOperation);
                return iterateEntriesMinorAsc(key, inclusive, atomicOperation);
            } finally {
                releaseSharedLock();
            }
        } catch (IOException ioe) {
            throw OException.wrapException(new OSBTreeException("Error during iteration of minor values for key " + key + " in sbtree " + getName(), this), ioe);
        } finally {
            atomicOperationsManager.releaseReadLock(this);
        }
    } finally {
        if (statistic != null)
            statistic.stopIndexEntryReadTimer();
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) IOException(java.io.IOException) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)

Example 33 with OSessionStoragePerformanceStatistic

use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic in project orientdb by orientechnologies.

the class OSBTree method remove.

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 OSBTreeException("Error during sbtree entrie remove", this), e);
        }
        acquireExclusiveLock();
        try {
            V removedValue;
            if (key != null) {
                key = keySerializer.preprocess(key, (Object[]) keyTypes);
                BucketSearchResult bucketSearchResult = findBucket(key, atomicOperation);
                if (bucketSearchResult.itemIndex < 0) {
                    endAtomicOperation(false, null);
                    return null;
                }
                OCacheEntry keyBucketCacheEntry = loadPage(atomicOperation, fileId, bucketSearchResult.getLastPathItem(), false);
                keyBucketCacheEntry.acquireExclusiveLock();
                try {
                    OSBTreeBucket<K, V> keyBucket = new OSBTreeBucket<K, V>(keyBucketCacheEntry, keySerializer, keyTypes, valueSerializer, getChanges(atomicOperation, keyBucketCacheEntry));
                    final OSBTreeValue<V> removed = keyBucket.getEntry(bucketSearchResult.itemIndex).value;
                    final V value = readValue(removed, atomicOperation);
                    long removedValueLink = keyBucket.remove(bucketSearchResult.itemIndex);
                    if (removedValueLink >= 0)
                        removeLinkedValue(removedValueLink, atomicOperation);
                    setSize(size() - 1, atomicOperation);
                    removedValue = value;
                } finally {
                    keyBucketCacheEntry.releaseExclusiveLock();
                    releasePage(atomicOperation, keyBucketCacheEntry);
                }
            } else {
                if (getFilledUpTo(atomicOperation, nullBucketFileId) == 0) {
                    endAtomicOperation(false, null);
                    return null;
                }
                OCacheEntry nullCacheEntry = loadPage(atomicOperation, nullBucketFileId, 0, false);
                nullCacheEntry.acquireExclusiveLock();
                try {
                    ONullBucket<V> nullBucket = new ONullBucket<V>(nullCacheEntry, getChanges(atomicOperation, nullCacheEntry), valueSerializer, false);
                    OSBTreeValue<V> treeValue = nullBucket.getValue();
                    if (treeValue != null) {
                        removedValue = readValue(treeValue, atomicOperation);
                        nullBucket.removeValue();
                    } else
                        removedValue = null;
                } finally {
                    nullCacheEntry.releaseExclusiveLock();
                    releasePage(atomicOperation, nullCacheEntry);
                }
                if (removedValue != null)
                    setSize(size() - 1, atomicOperation);
            }
            endAtomicOperation(false, null);
            return removedValue;
        } catch (IOException e) {
            rollback(e);
            throw OException.wrapException(new OSBTreeException("Error during removing key " + key + " from sbtree " + getName(), this), e);
        } catch (RuntimeException e) {
            rollback(e);
            throw e;
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        if (statistic != null)
            statistic.stopIndexEntryDeletionTimer();
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) IOException(java.io.IOException) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)

Example 34 with OSessionStoragePerformanceStatistic

use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic in project orientdb by orientechnologies.

the class OSBTree method iterateEntriesMajor.

public OSBTreeCursor<K, V> iterateEntriesMajor(K key, boolean inclusive, boolean ascSortOrder) {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    startOperation();
    if (statistic != null)
        statistic.startIndexEntryReadTimer();
    try {
        atomicOperationsManager.acquireReadLock(this);
        try {
            acquireSharedLock();
            try {
                OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
                if (ascSortOrder)
                    return iterateEntriesMajorAsc(key, inclusive, atomicOperation);
                return iterateEntriesMajorDesc(key, inclusive, atomicOperation);
            } finally {
                releaseSharedLock();
            }
        } catch (IOException ioe) {
            throw OException.wrapException(new OSBTreeException("Error during iteration of major values for key " + key + " in sbtree " + getName(), this), ioe);
        } finally {
            atomicOperationsManager.releaseReadLock(this);
        }
    } finally {
        if (statistic != null)
            statistic.stopIndexEntryReadTimer();
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) IOException(java.io.IOException) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)

Example 35 with OSessionStoragePerformanceStatistic

use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic in project orientdb by orientechnologies.

the class OWOWCache method cacheFileContent.

private OCachePointer[] cacheFileContent(final int intId, final long startPageIndex, final int pageCount, final boolean addNewPages, OModifiableBoolean cacheHit) throws IOException, InterruptedException {
    final long fileId = composeFileId(id, intId);
    final OClosableEntry<Long, OFileClassic> entry = files.acquire(fileId);
    try {
        final OFileClassic fileClassic = entry.get();
        if (fileClassic == null)
            throw new IllegalArgumentException("File with id " + intId + " not found in WOW Cache");
        final OLogSequenceNumber lastLsn;
        if (writeAheadLog != null)
            lastLsn = writeAheadLog.getFlushedLsn();
        else
            lastLsn = new OLogSequenceNumber(-1, -1);
        final long firstPageStartPosition = startPageIndex * pageSize;
        final long firstPageEndPosition = firstPageStartPosition + pageSize;
        if (fileClassic.getFileSize() >= firstPageEndPosition) {
            final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = performanceStatisticManager.getSessionPerformanceStatistic();
            if (sessionStoragePerformanceStatistic != null) {
                sessionStoragePerformanceStatistic.startPageReadFromFileTimer();
            }
            int pagesRead = 0;
            try {
                if (pageCount == 1) {
                    final ByteBuffer buffer = bufferPool.acquireDirect(false);
                    fileClassic.read(firstPageStartPosition, buffer);
                    buffer.position(0);
                    final OCachePointer dataPointer = new OCachePointer(buffer, bufferPool, lastLsn, fileId, startPageIndex);
                    pagesRead = 1;
                    return new OCachePointer[] { dataPointer };
                }
                final long maxPageCount = (fileClassic.getFileSize() - firstPageStartPosition) / pageSize;
                final int realPageCount = Math.min((int) maxPageCount, pageCount);
                final ByteBuffer[] buffers = new ByteBuffer[realPageCount];
                for (int i = 0; i < buffers.length; i++) {
                    buffers[i] = bufferPool.acquireDirect(false);
                    assert buffers[i].position() == 0;
                }
                fileClassic.read(firstPageStartPosition, buffers);
                final OCachePointer[] dataPointers = new OCachePointer[buffers.length];
                for (int n = 0; n < buffers.length; n++) {
                    buffers[n].position(0);
                    dataPointers[n] = new OCachePointer(buffers[n], bufferPool, lastLsn, fileId, startPageIndex + n);
                }
                pagesRead = dataPointers.length;
                return dataPointers;
            } finally {
                if (sessionStoragePerformanceStatistic != null) {
                    sessionStoragePerformanceStatistic.stopPageReadFromFileTimer(pagesRead);
                }
            }
        } else if (addNewPages) {
            final int space = (int) (firstPageEndPosition - fileClassic.getFileSize());
            if (space > 0)
                fileClassic.allocateSpace(space);
            freeSpaceCheckAfterNewPageAdd();
            final ByteBuffer buffer = bufferPool.acquireDirect(true);
            final OCachePointer dataPointer = new OCachePointer(buffer, bufferPool, lastLsn, fileId, startPageIndex);
            cacheHit.setValue(true);
            return new OCachePointer[] { dataPointer };
        } else
            return new OCachePointer[0];
    } finally {
        files.release(entry);
    }
}
Also used : OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) AtomicLong(java.util.concurrent.atomic.AtomicLong) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic) ByteBuffer(java.nio.ByteBuffer) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer) OFileClassic(com.orientechnologies.orient.core.storage.fs.OFileClassic)

Aggregations

OSessionStoragePerformanceStatistic (com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)47 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)25 IOException (java.io.IOException)23 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)20 Lock (java.util.concurrent.locks.Lock)11 OSBTreeBonsaiLocalException (com.orientechnologies.orient.core.exception.OSBTreeBonsaiLocalException)9 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 ORawPair (com.orientechnologies.common.util.ORawPair)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 OException (com.orientechnologies.common.exception.OException)4 ORecordId (com.orientechnologies.orient.core.id.ORecordId)4 OPaginatedClusterException (com.orientechnologies.orient.core.exception.OPaginatedClusterException)3 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)3 OTooBigIndexKeyException (com.orientechnologies.orient.core.exception.OTooBigIndexKeyException)3 OIndexException (com.orientechnologies.orient.core.index.OIndexException)3 OLocalHashTableException (com.orientechnologies.orient.core.exception.OLocalHashTableException)2 OStorage (com.orientechnologies.orient.core.storage.OStorage)2 OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)2 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 OAllCacheEntriesAreUsedException (com.orientechnologies.orient.core.exception.OAllCacheEntriesAreUsedException)1