use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic in project orientdb by orientechnologies.
the class OPaginatedCluster method recycleRecord.
/**
* Recycles a deleted record.
*/
public void recycleRecord(final long clusterPosition, byte[] content, final int recordVersion, final byte recordType) throws IOException {
startOperation();
OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
if (statistic != null)
statistic.startRecordUpdateTimer();
try {
OAtomicOperation atomicOperation = startAtomicOperation(true);
acquireExclusiveLock();
try {
final OClusterPositionMapBucket.PositionEntry positionEntry = clusterPositionMap.get(clusterPosition, 1);
if (positionEntry != null) {
// NOT DELETED
throw new OPaginatedClusterException("Record with rid " + new ORecordId(id, clusterPosition) + " was not deleted", this);
}
content = compression.compress(content);
content = encryption.encrypt(content);
int entryContentLength = getEntryContentLength(content.length);
if (entryContentLength < OClusterPage.MAX_RECORD_SIZE) {
try {
byte[] entryContent = new byte[entryContentLength];
int entryPosition = 0;
entryContent[entryPosition] = recordType;
entryPosition++;
OIntegerSerializer.INSTANCE.serializeNative(content.length, entryContent, entryPosition);
entryPosition += OIntegerSerializer.INT_SIZE;
System.arraycopy(content, 0, entryContent, entryPosition, content.length);
entryPosition += content.length;
entryContent[entryPosition] = 1;
entryPosition++;
OLongSerializer.INSTANCE.serializeNative(-1L, entryContent, entryPosition);
final AddEntryResult addEntryResult = addEntry(fileId, pinnedStateEntryIndex, recordVersion, entryContent, atomicOperation);
updateClusterState(fileId, pinnedStateEntryIndex, 1, addEntryResult.recordsSizeDiff, atomicOperation);
clusterPositionMap.resurrect(clusterPosition, new OClusterPositionMapBucket.PositionEntry(addEntryResult.pageIndex, addEntryResult.pagePosition));
addAtomicOperationMetadata(new ORecordId(id, clusterPosition), atomicOperation);
endAtomicOperation(false, null);
} catch (Exception e) {
endAtomicOperation(true, e);
throw OException.wrapException(new OPaginatedClusterException("Error during record recycling", this), e);
}
} else {
try {
int entrySize = content.length + OIntegerSerializer.INT_SIZE + OByteSerializer.BYTE_SIZE;
int fullEntryPosition = 0;
byte[] fullEntry = new byte[entrySize];
fullEntry[fullEntryPosition] = recordType;
fullEntryPosition++;
OIntegerSerializer.INSTANCE.serializeNative(content.length, fullEntry, fullEntryPosition);
fullEntryPosition += OIntegerSerializer.INT_SIZE;
System.arraycopy(content, 0, fullEntry, fullEntryPosition, content.length);
long prevPageRecordPointer = -1;
long firstPageIndex = -1;
int firstPagePosition = -1;
int from = 0;
int to = from + (OClusterPage.MAX_RECORD_SIZE - OByteSerializer.BYTE_SIZE - OLongSerializer.LONG_SIZE);
int recordsSizeDiff = 0;
do {
byte[] entryContent = new byte[to - from + OByteSerializer.BYTE_SIZE + OLongSerializer.LONG_SIZE];
System.arraycopy(fullEntry, from, entryContent, 0, to - from);
if (from > 0)
entryContent[entryContent.length - OLongSerializer.LONG_SIZE - OByteSerializer.BYTE_SIZE] = 0;
else
entryContent[entryContent.length - OLongSerializer.LONG_SIZE - OByteSerializer.BYTE_SIZE] = 1;
OLongSerializer.INSTANCE.serializeNative(-1L, entryContent, entryContent.length - OLongSerializer.LONG_SIZE);
final AddEntryResult addEntryResult = addEntry(fileId, pinnedStateEntryIndex, recordVersion, entryContent, atomicOperation);
recordsSizeDiff += addEntryResult.recordsSizeDiff;
if (firstPageIndex == -1) {
firstPageIndex = addEntryResult.pageIndex;
firstPagePosition = addEntryResult.pagePosition;
}
long addedPagePointer = createPagePointer(addEntryResult.pageIndex, addEntryResult.pagePosition);
if (prevPageRecordPointer >= 0) {
long prevPageIndex = getPageIndex(prevPageRecordPointer);
int prevPageRecordPosition = getRecordPosition(prevPageRecordPointer);
final OCacheEntry prevPageCacheEntry = loadPage(atomicOperation, fileId, prevPageIndex, false);
prevPageCacheEntry.acquireExclusiveLock();
try {
final OClusterPage prevPage = new OClusterPage(prevPageCacheEntry, false, getChanges(atomicOperation, prevPageCacheEntry));
prevPage.setRecordLongValue(prevPageRecordPosition, -OLongSerializer.LONG_SIZE, addedPagePointer);
} finally {
prevPageCacheEntry.releaseExclusiveLock();
releasePage(atomicOperation, prevPageCacheEntry);
}
}
prevPageRecordPointer = addedPagePointer;
from = to;
to = to + (OClusterPage.MAX_RECORD_SIZE - OLongSerializer.LONG_SIZE - OByteSerializer.BYTE_SIZE);
if (to > fullEntry.length)
to = fullEntry.length;
} while (from < to);
updateClusterState(fileId, pinnedStateEntryIndex, 1, recordsSizeDiff, atomicOperation);
clusterPositionMap.update(clusterPosition, new OClusterPositionMapBucket.PositionEntry(firstPageIndex, firstPagePosition));
addAtomicOperationMetadata(new ORecordId(id, clusterPosition), atomicOperation);
endAtomicOperation(false, null);
} catch (RuntimeException e) {
endAtomicOperation(true, e);
if (e instanceof OPaginatedClusterException)
throw e;
else
throw OException.wrapException(new OPaginatedClusterException("Error during record recycling", this), e);
}
}
} catch (RuntimeException e) {
endAtomicOperation(true, e);
if (e instanceof OPaginatedClusterException)
throw e;
else
throw OException.wrapException(new OPaginatedClusterException("Error during record recycling", this), e);
} finally {
releaseExclusiveLock();
}
} finally {
if (statistic != null)
statistic.stopRecordUpdateTimer();
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic in project orientdb by orientechnologies.
the class OPaginatedCluster method readRecord.
private ORawBuffer readRecord(final long clusterPosition, final int pageCount) throws IOException {
startOperation();
OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
if (statistic != null)
statistic.startRecordReadTimer();
try {
atomicOperationsManager.acquireReadLock(this);
try {
acquireSharedLock();
try {
final OClusterPositionMapBucket.PositionEntry positionEntry = clusterPositionMap.get(clusterPosition, pageCount);
if (positionEntry == null)
return null;
return readRecordBuffer(clusterPosition, pageCount, positionEntry);
} finally {
releaseSharedLock();
}
} finally {
atomicOperationsManager.releaseReadLock(this);
}
} finally {
if (statistic != null)
statistic.stopRecordReadTimer();
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic in project orientdb by orientechnologies.
the class ODirectMemoryOnlyDiskCache method load.
@Override
public OCacheEntry load(long fileId, long pageIndex, boolean checkPinnedPages, OWriteCache writeCache, final int pageCount) {
final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = performanceStatisticManager.getSessionPerformanceStatistic();
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.startPageReadFromCacheTimer();
}
try {
int intId = extractFileId(fileId);
final MemoryFile memoryFile = getFile(intId);
final OCacheEntry cacheEntry = memoryFile.loadPage(pageIndex);
if (cacheEntry == null)
return null;
synchronized (cacheEntry) {
cacheEntry.incrementUsages();
}
return cacheEntry;
} finally {
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.stopPageReadFromCacheTimer();
}
}
}
use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic in project orientdb by orientechnologies.
the class OPerformanceStatisticManager method updateDeadThreadsStatistic.
/**
* Removes provided dead threads from {@link #statistics} field and accumulates data from them in {@link #deadThreadsStatistic}.
*
* @param threadsToRemove Dead threads statistic of which should be moved to {@link #deadThreadsStatistic} field.
*/
private void updateDeadThreadsStatistic(Collection<Thread> threadsToRemove) {
deadThreadsUpdateLock.lock();
try {
//we accumulate all statistic in intermediate fields and only then put
//results in #deadThreadsStatistic field to preserve thread safety features
final ImmutableStatistic oldDS = deadThreadsStatistic;
final PerformanceCountersHolder countersHolder = ComponentType.GENERAL.newCountersHolder();
final Map<String, PerformanceCountersHolder> countersByComponents = new HashMap<String, PerformanceCountersHolder>();
WritCacheCountersHolder writeCacheCountersHolder = null;
StorageCountersHolder storageCountersHolder = null;
WALCountersHolder walCountersHolder = null;
//fetch data from old statistic first
if (oldDS != null) {
oldDS.countersHolder.pushData(countersHolder);
for (Map.Entry<String, PerformanceCountersHolder> oldEntry : oldDS.countersByComponents.entrySet()) {
final PerformanceCountersHolder holder = oldEntry.getValue().newInstance();
oldEntry.getValue().pushData(holder);
countersByComponents.put(oldEntry.getKey(), holder);
}
if (oldDS.writCacheCountersHolder != null) {
writeCacheCountersHolder = new WritCacheCountersHolder();
oldDS.writCacheCountersHolder.pushData(writeCacheCountersHolder);
}
if (oldDS.storageCountersHolder != null) {
storageCountersHolder = new StorageCountersHolder();
oldDS.storageCountersHolder.pushData(storageCountersHolder);
}
if (oldDS.walCountersHolder != null) {
walCountersHolder = new WALCountersHolder();
oldDS.walCountersHolder.pushData(walCountersHolder);
}
}
//remove all threads from active statistic and put all in #deadThreadsStatistic field
for (Thread deadThread : threadsToRemove) {
final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = statistics.remove(deadThread);
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.pushSystemCounters(countersHolder);
sessionStoragePerformanceStatistic.pushComponentCounters(countersByComponents);
writeCacheCountersHolder = sessionStoragePerformanceStatistic.pushWriteCacheCounters(writeCacheCountersHolder);
storageCountersHolder = sessionStoragePerformanceStatistic.pushStorageCounters(storageCountersHolder);
walCountersHolder = sessionStoragePerformanceStatistic.pushWALCounters(walCountersHolder);
}
}
deadThreadsStatistic = new ImmutableStatistic(countersHolder, countersByComponents, writeCacheCountersHolder, storageCountersHolder, walCountersHolder);
} finally {
deadThreadsUpdateLock.unlock();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic in project orientdb by orientechnologies.
the class OPerformanceStatisticManager method startThreadMonitoring.
/**
* Starts performance monitoring only for single thread.
* After call of this method you can not start system wide monitoring till call of {@link #stopThreadMonitoring()} is performed.
*/
public void startThreadMonitoring() {
switchLock.acquireWriteLock();
try {
if (enabled)
throw new IllegalStateException("Monitoring is already started on system level and can not be started on thread level");
enabledForCurrentThread.set(true);
statistics.put(Thread.currentThread(), new OSessionStoragePerformanceStatistic(intervalBetweenSnapshots, Long.MAX_VALUE));
} finally {
switchLock.releaseWriteLock();
}
}
Aggregations