Search in sources :

Example 11 with OSessionStoragePerformanceStatistic

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

the class OPerformanceStatisticManager method fetchComponentCounters.

/**
   * Iterates over all live threads and accumulates performance statics gathered form threads for provided component,
   * also accumulates statistic from dead threads which were alive when when gathering of performance measurements is started.
   *
   * @param componentCountersHolder Holder which is used to accumulate all performance statistic data for given component
   * @param componentName           Name of component
   */
private void fetchComponentCounters(String componentName, PerformanceCountersHolder componentCountersHolder) {
    //go through all threads and accumulate statistic only for live threads
    //all dead threads will be removed and statistics from them will be
    //later accumulated in #deadThreadsStatistic field, then result statistic from this field
    //will be aggregated to componentCountersHolder
    //To decrease inter thread communication delay we fetch snapshots first
    //and only after that we aggregate data from immutable snapshots
    final Collection<ORawPair<Thread, PerformanceSnapshot>> snapshots = new ArrayList<ORawPair<Thread, PerformanceSnapshot>>(statistics.size());
    final List<Thread> threadsToRemove = new ArrayList<Thread>();
    for (Map.Entry<Thread, OSessionStoragePerformanceStatistic> entry : statistics.entrySet()) {
        final Thread thread = entry.getKey();
        final OSessionStoragePerformanceStatistic statistic = entry.getValue();
        snapshots.add(new ORawPair<Thread, PerformanceSnapshot>(thread, statistic.getSnapshot()));
    }
    for (ORawPair<Thread, PerformanceSnapshot> pair : snapshots) {
        final Thread thread = pair.getFirst();
        if (thread.isAlive()) {
            final PerformanceSnapshot snapshot = pair.getSecond();
            final PerformanceCountersHolder holder = snapshot.countersByComponent.get(componentName);
            if (holder != null)
                holder.pushData(componentCountersHolder);
        } else {
            threadsToRemove.add(thread);
        }
    }
    if (!threadsToRemove.isEmpty()) {
        updateDeadThreadsStatistic(threadsToRemove);
    }
    final ImmutableStatistic ds = deadThreadsStatistic;
    if (ds != null) {
        final PerformanceCountersHolder dch = ds.countersByComponents.get(componentName);
        if (dch != null) {
            dch.pushData(componentCountersHolder);
        }
    }
}
Also used : ORawPair(com.orientechnologies.common.util.ORawPair) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 12 with OSessionStoragePerformanceStatistic

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

the class OPerformanceStatisticManager method fetchWALCounters.

/**
   * Iterates over all live threads and accumulates write ahead log performance statics gathered form threads,
   * also accumulates statistic from dead threads which were alive when when gathering of performance measurements is started.
   *
   * @return Aggregated write ahead log performance statistic
   */
private WALCountersHolder fetchWALCounters() {
    //go through all threads and accumulate statistic only for live threads
    //all dead threads will be removed and statistics from them will be
    //later accumulated in #deadThreadsStatistic field, then result statistic from this field
    //will be aggregated to countersHolder
    //To decrease inter thread communication delay we fetch snapshots first
    //and only after that we aggregate data from immutable snapshots
    final Collection<ORawPair<Thread, PerformanceSnapshot>> snapshots = new ArrayList<ORawPair<Thread, PerformanceSnapshot>>(statistics.size());
    final Collection<Thread> threadsToRemove = new ArrayList<Thread>();
    for (Map.Entry<Thread, OSessionStoragePerformanceStatistic> entry : statistics.entrySet()) {
        final Thread thread = entry.getKey();
        final OSessionStoragePerformanceStatistic statistic = entry.getValue();
        snapshots.add(new ORawPair<Thread, PerformanceSnapshot>(thread, statistic.getSnapshot()));
    }
    WALCountersHolder holder = null;
    for (ORawPair<Thread, PerformanceSnapshot> pair : snapshots) {
        final Thread thread = pair.getFirst();
        if (thread.isAlive()) {
            final PerformanceSnapshot snapshot = pair.getSecond();
            if (snapshot.walCountersHolder != null) {
                if (holder == null)
                    holder = new WALCountersHolder();
                snapshot.walCountersHolder.pushData(holder);
            }
        } else {
            threadsToRemove.add(thread);
        }
    }
    if (!threadsToRemove.isEmpty()) {
        updateDeadThreadsStatistic(threadsToRemove);
    }
    final ImmutableStatistic ds = deadThreadsStatistic;
    if (ds != null) {
        final WALCountersHolder wch = ds.walCountersHolder;
        if (wch != null) {
            if (holder == null)
                holder = new WALCountersHolder();
            wch.pushData(holder);
        }
    }
    return holder;
}
Also used : ORawPair(com.orientechnologies.common.util.ORawPair) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 13 with OSessionStoragePerformanceStatistic

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

the class OSBTree method keyCursor.

public OSBTreeKeyCursor<K> keyCursor() {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    startOperation();
    if (statistic != null)
        statistic.startIndexEntryReadTimer();
    try {
        atomicOperationsManager.acquireReadLock(this);
        try {
            acquireSharedLock();
            try {
                OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
                final BucketSearchResult searchResult = firstItem(atomicOperation);
                if (searchResult == null)
                    return new OSBTreeKeyCursor<K>() {

                        @Override
                        public K next(int prefetchSize) {
                            return null;
                        }
                    };
                return new OSBTreeFullKeyCursor(searchResult.getLastPathItem());
            } finally {
                releaseSharedLock();
            }
        } catch (IOException e) {
            throw OException.wrapException(new OSBTreeException("Error during finding first key in sbtree [" + getName() + "]", this), e);
        } 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 14 with OSessionStoragePerformanceStatistic

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

the class OSBTree method iterateEntriesBetween.

public OSBTreeCursor<K, V> iterateEntriesBetween(K keyFrom, boolean fromInclusive, K keyTo, boolean toInclusive, 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 iterateEntriesBetweenAscOrder(keyFrom, fromInclusive, keyTo, toInclusive, atomicOperation);
                else
                    return iterateEntriesBetweenDescOrder(keyFrom, fromInclusive, keyTo, toInclusive, atomicOperation);
            } finally {
                releaseSharedLock();
            }
        } catch (IOException ioe) {
            throw OException.wrapException(new OSBTreeException("Error during fetch of values between key " + keyFrom + " and key " + keyTo + " 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 15 with OSessionStoragePerformanceStatistic

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

the class OSBTree method put.

@SuppressWarnings("unchecked")
private boolean put(K key, V value, OIndexEngine.Validator<K, V> validator) {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    startOperation();
    if (statistic != null)
        statistic.startIndexEntryUpdateTimer();
    try {
        final OAtomicOperation atomicOperation;
        try {
            atomicOperation = startAtomicOperation(true);
        } catch (IOException e) {
            throw OException.wrapException(new OSBTreeException("Error during sbtree entrie put", this), e);
        }
        acquireExclusiveLock();
        try {
            checkNullSupport(key);
            if (key != null) {
                final int keySize = keySerializer.getObjectSize(key, (Object[]) keyTypes);
                final int valueSize = valueSerializer.getObjectSize(value);
                if (keySize > MAX_KEY_SIZE)
                    throw new OTooBigIndexKeyException("Key size is more than allowed, operation was canceled. Current key size " + keySize + ", allowed  " + MAX_KEY_SIZE, getName());
                final boolean createLinkToTheValue = valueSize > MAX_EMBEDDED_VALUE_SIZE;
                key = keySerializer.preprocess(key, (Object[]) keyTypes);
                long valueLink = -1;
                if (createLinkToTheValue)
                    valueLink = createLinkToTheValue(value, atomicOperation);
                final OSBTreeValue<V> treeValue = new OSBTreeValue<V>(createLinkToTheValue, valueLink, createLinkToTheValue ? null : value);
                BucketSearchResult bucketSearchResult = findBucket(key, atomicOperation);
                OCacheEntry keyBucketCacheEntry = loadPage(atomicOperation, fileId, bucketSearchResult.getLastPathItem(), false);
                keyBucketCacheEntry.acquireExclusiveLock();
                OSBTreeBucket<K, V> keyBucket = new OSBTreeBucket<K, V>(keyBucketCacheEntry, keySerializer, keyTypes, valueSerializer, getChanges(atomicOperation, keyBucketCacheEntry));
                if (validator != null) {
                    // assuming validation throws by default
                    boolean failure = true;
                    boolean ignored = false;
                    try {
                        final V oldValue = bucketSearchResult.itemIndex > -1 ? readValue(keyBucket.getValue(bucketSearchResult.itemIndex), atomicOperation) : null;
                        final Object result = validator.validate(key, oldValue, value);
                        if (result == OIndexEngine.Validator.IGNORE) {
                            ignored = true;
                            failure = false;
                            return false;
                        }
                        value = (V) result;
                        failure = false;
                    } finally {
                        if (failure || ignored) {
                            keyBucketCacheEntry.releaseExclusiveLock();
                            releasePage(atomicOperation, keyBucketCacheEntry);
                        }
                        if (// in case of a failure atomic operation will be ended in a usual way below
                        ignored)
                            endAtomicOperation(false, null);
                    }
                }
                int insertionIndex;
                int sizeDiff;
                if (bucketSearchResult.itemIndex >= 0) {
                    int updateResult = keyBucket.updateValue(bucketSearchResult.itemIndex, treeValue);
                    if (updateResult >= 0) {
                        keyBucketCacheEntry.releaseExclusiveLock();
                        releasePage(atomicOperation, keyBucketCacheEntry);
                        endAtomicOperation(false, null);
                        return true;
                    } else {
                        assert updateResult == -1;
                        long removedLinkedValue = keyBucket.remove(bucketSearchResult.itemIndex);
                        if (removedLinkedValue >= 0)
                            removeLinkedValue(removedLinkedValue, atomicOperation);
                        insertionIndex = bucketSearchResult.itemIndex;
                        sizeDiff = 0;
                    }
                } else {
                    insertionIndex = -bucketSearchResult.itemIndex - 1;
                    sizeDiff = 1;
                }
                while (!keyBucket.addEntry(insertionIndex, new OSBTreeBucket.SBTreeEntry<K, V>(-1, -1, key, treeValue), true)) {
                    keyBucketCacheEntry.releaseExclusiveLock();
                    releasePage(atomicOperation, keyBucketCacheEntry);
                    bucketSearchResult = splitBucket(bucketSearchResult.path, insertionIndex, key, atomicOperation);
                    insertionIndex = bucketSearchResult.itemIndex;
                    keyBucketCacheEntry = loadPage(atomicOperation, fileId, bucketSearchResult.getLastPathItem(), false);
                    keyBucketCacheEntry.acquireExclusiveLock();
                    keyBucket = new OSBTreeBucket<K, V>(keyBucketCacheEntry, keySerializer, keyTypes, valueSerializer, getChanges(atomicOperation, keyBucketCacheEntry));
                }
                keyBucketCacheEntry.releaseExclusiveLock();
                releasePage(atomicOperation, keyBucketCacheEntry);
                if (sizeDiff != 0)
                    setSize(size() + sizeDiff, atomicOperation);
            } else {
                OCacheEntry cacheEntry;
                boolean isNew = false;
                if (getFilledUpTo(atomicOperation, nullBucketFileId) == 0) {
                    cacheEntry = addPage(atomicOperation, nullBucketFileId);
                    isNew = true;
                } else
                    cacheEntry = loadPage(atomicOperation, nullBucketFileId, 0, false);
                final int valueSize = valueSerializer.getObjectSize(value);
                final boolean createLinkToTheValue = valueSize > MAX_EMBEDDED_VALUE_SIZE;
                long valueLink = -1;
                if (createLinkToTheValue)
                    valueLink = createLinkToTheValue(value, atomicOperation);
                final OSBTreeValue<V> treeValue = new OSBTreeValue<V>(createLinkToTheValue, valueLink, createLinkToTheValue ? null : value);
                int sizeDiff = 0;
                boolean ignored = false;
                cacheEntry.acquireExclusiveLock();
                try {
                    final ONullBucket<V> nullBucket = new ONullBucket<V>(cacheEntry, getChanges(atomicOperation, cacheEntry), valueSerializer, isNew);
                    final OSBTreeValue<V> oldValue = nullBucket.getValue();
                    if (validator != null) {
                        final V oldValueValue = oldValue == null ? null : readValue(oldValue, atomicOperation);
                        final Object result = validator.validate(null, oldValueValue, value);
                        if (result == OIndexEngine.Validator.IGNORE) {
                            ignored = true;
                            return false;
                        }
                        value = (V) result;
                    }
                    if (oldValue != null)
                        sizeDiff = -1;
                    nullBucket.setValue(treeValue);
                } finally {
                    cacheEntry.releaseExclusiveLock();
                    releasePage(atomicOperation, cacheEntry);
                    if (ignored)
                        endAtomicOperation(false, null);
                }
                sizeDiff++;
                setSize(size() + sizeDiff, atomicOperation);
            }
            endAtomicOperation(false, null);
            return true;
        } catch (IOException e) {
            rollback(e);
            throw OException.wrapException(new OSBTreeException("Error during index update with key " + key + " and value " + value, this), e);
        } catch (RuntimeException e) {
            rollback(e);
            throw e;
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        if (statistic != null)
            statistic.stopIndexEntryUpdateTimer();
        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) OTooBigIndexKeyException(com.orientechnologies.orient.core.exception.OTooBigIndexKeyException)

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