Skip to content

Commit

Permalink
Issue #5495 has been fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
laa committed Dec 22, 2015
1 parent 251951c commit 0dadc27
Show file tree
Hide file tree
Showing 10 changed files with 775 additions and 170 deletions.
Expand Up @@ -20,6 +20,7 @@

package com.orientechnologies.orient.core.storage.cache;

import com.orientechnologies.common.types.OModifiableBoolean;
import com.orientechnologies.orient.core.command.OCommandOutputListener;
import com.orientechnologies.orient.core.storage.impl.local.OLowDiskSpaceListener;

Expand Down Expand Up @@ -60,7 +61,8 @@ public interface OWriteCache {

Future store(long fileId, long pageIndex, OCachePointer dataPointer);

OCachePointer[] load(long fileId, long startPageIndex, int pageCount, boolean addNewPages) throws IOException;
OCachePointer[] load(long fileId, long startPageIndex, int pageCount, boolean addNewPages, OModifiableBoolean cacheHit)
throws IOException;

void flush(long fileId);

Expand Down
Expand Up @@ -30,6 +30,7 @@
import com.orientechnologies.common.serialization.types.OBinarySerializer;
import com.orientechnologies.common.serialization.types.OIntegerSerializer;
import com.orientechnologies.common.serialization.types.OLongSerializer;
import com.orientechnologies.common.types.OModifiableBoolean;
import com.orientechnologies.orient.core.command.OCommandOutputListener;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.exception.OStorageException;
Expand Down Expand Up @@ -598,7 +599,8 @@ public Map<String, Long> files() {
}
}

public OCachePointer[] load(long fileId, long startPageIndex, int pageCount, boolean addNewPages) throws IOException {
public OCachePointer[] load(long fileId, long startPageIndex, int pageCount, boolean addNewPages, OModifiableBoolean cacheHit)
throws IOException {
final int intId = extractFileId(fileId);
if (pageCount < 1)
throw new IllegalArgumentException("Amount of pages to load should be not less than 1 but provided value is " + pageCount);
Expand All @@ -615,7 +617,7 @@ public OCachePointer[] load(long fileId, long startPageIndex, int pageCount, boo
PageGroup pageGroup = writeCachePages.get(pageKeys[0]);

if (pageGroup == null) {
final OCachePointer pagePointers[] = cacheFileContent(fileId, intId, startPageIndex, pageCount, addNewPages);
final OCachePointer pagePointers[] = cacheFileContent(fileId, intId, startPageIndex, pageCount, addNewPages, cacheHit);

if (pagePointers.length == 0)
return pagePointers;
Expand All @@ -639,6 +641,9 @@ public OCachePointer[] load(long fileId, long startPageIndex, int pageCount, boo

final OCachePointer pagePointer = pageGroup.page;
pagePointer.incrementReadersReferrer();

cacheHit.setValue(true);

return new OCachePointer[] { pagePointer };
} finally {
for (Lock lock : pageLocks) {
Expand Down Expand Up @@ -1219,7 +1224,7 @@ private void removeCachedPages(int fileId) {
}

private OCachePointer[] cacheFileContent(final long fileId, final int intId, final long startPageIndex, final int pageCount,
final boolean addNewPages) throws IOException {
final boolean addNewPages, OModifiableBoolean cacheHit) throws IOException {

final OFileClassic fileClassic = files.get(intId);

Expand Down Expand Up @@ -1291,6 +1296,7 @@ private OCachePointer[] cacheFileContent(final long fileId, final int intId, fin
final byte[] content = new byte[pageSize + 2 * PAGE_PADDING];
final ODirectMemoryPointer pointer = ODirectMemoryPointerFactory.instance().createPointer(content);
OCachePointer dataPointer = new OCachePointer(pointer, lastLsn, fileId, startPageIndex);
cacheHit.setValue(true);
return new OCachePointer[] { dataPointer };
} else
return new OCachePointer[0];
Expand Down
Expand Up @@ -387,10 +387,6 @@ private UpdateCacheResult doLoad(long fileId, long pageIndex, boolean checkPinne
Lock fileLock;
Lock[] pageLocks;

if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.incrementPageAccessOnCacheLevel();
}

final OModifiableBoolean cacheHit = new OModifiableBoolean(false);

cacheLock.acquireReadLock();
Expand All @@ -409,18 +405,13 @@ private UpdateCacheResult doLoad(long fileId, long pageIndex, boolean checkPinne
cacheEntry = pinnedPages.get(new PinnedPage(fileId, pageIndex));

if (cacheEntry == null) {
UpdateCacheResult cacheResult = updateCache(fileId, pageIndex, addNewPages, writeCache, pageCount,
sessionStoragePerformanceStatistic, cacheHit);
UpdateCacheResult cacheResult = updateCache(fileId, pageIndex, addNewPages, writeCache, pageCount, cacheHit);
if (cacheResult == null)
return null;

cacheEntry = cacheResult.cacheEntry;
removeColdPages = cacheResult.removeColdPages;
} else {
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.incrementCacheHit();
}

cacheHit.setValue(true);
}

Expand All @@ -438,6 +429,9 @@ private UpdateCacheResult doLoad(long fileId, long pageIndex, boolean checkPinne
}

storagePerformanceStatistic.incrementPageAccessOnCacheLevel(cacheHit.getValue());
if (sessionStoragePerformanceStatistic != null)
sessionStoragePerformanceStatistic.incrementPageAccessOnCacheLevel(cacheHit.getValue());

return new UpdateCacheResult(removeColdPages, cacheEntry);
}

Expand Down Expand Up @@ -879,18 +873,13 @@ private UpdateCacheResult entryIsAbsentInQueues(long fileId, long pageIndex, OCa
}

private UpdateCacheResult updateCache(final long fileId, final long pageIndex, final boolean addNewPages, OWriteCache writeCache,
final int pageCount, final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic,
final OModifiableBoolean cacheHit) throws IOException {
final int pageCount, final OModifiableBoolean cacheHit) throws IOException {

assert pageCount > 0;

OCacheEntry cacheEntry = am.get(fileId, pageIndex);

if (cacheEntry != null) {
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.incrementCacheHit();
}

cacheHit.setValue(true);

return new UpdateCacheResult(entryIsInAmQueue(fileId, pageIndex, cacheEntry), cacheEntry);
Expand All @@ -901,7 +890,7 @@ private UpdateCacheResult updateCache(final long fileId, final long pageIndex, f

cacheEntry = a1out.remove(fileId, pageIndex);
if (cacheEntry != null) {
dataPointers = writeCache.load(fileId, pageIndex, pageCount, false);
dataPointers = writeCache.load(fileId, pageIndex, pageCount, false, cacheHit);

OCachePointer dataPointer = dataPointers[0];
removeColdPages = entryWasInA1OutQueue(fileId, pageIndex, dataPointer, cacheEntry);
Expand All @@ -910,13 +899,9 @@ private UpdateCacheResult updateCache(final long fileId, final long pageIndex, f

if (cacheEntry != null) {
removeColdPages = entryIsInA1InQueue(fileId, pageIndex);
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.incrementCacheHit();
}

cacheHit.setValue(true);
} else {
dataPointers = writeCache.load(fileId, pageIndex, pageCount, addNewPages);
dataPointers = writeCache.load(fileId, pageIndex, pageCount, addNewPages, cacheHit);

if (dataPointers.length == 0)
return null;
Expand Down
Expand Up @@ -354,6 +354,7 @@ public void commitChanges(OWriteAheadLog writeAheadLog) throws IOException {
.getStatisticInstance();
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.startCommitTimer();
sessionStoragePerformanceStatistic.setCurrentComponent("atomic operation");
}
storagePerformanceStatistic.startCommitTimer();

Expand Down Expand Up @@ -427,6 +428,7 @@ else if (fileChanges.truncate)
} finally {
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.stopCommitTimer();
sessionStoragePerformanceStatistic.clearCurrentComponent();
}

storagePerformanceStatistic.stopCommitTimer();
Expand Down
Expand Up @@ -28,6 +28,7 @@
import com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation;
import com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperationsManager;
import com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree;
import com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic;
import com.orientechnologies.orient.core.storage.impl.local.statistic.OStoragePerformanceStatistic;

import java.io.IOException;
Expand Down Expand Up @@ -135,10 +136,23 @@ protected OCacheEntry loadPage(final OAtomicOperation atomicOperation, final lon

protected OCacheEntry loadPage(OAtomicOperation atomicOperation, long fileId, long pageIndex, boolean checkPinnedPages,
final int pageCount) throws IOException {
if (atomicOperation == null)
return readCache.load(fileId, pageIndex, checkPinnedPages, writeCache, pageCount, storagePerformanceStatistic);
final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = OSessionStoragePerformanceStatistic
.getStatisticInstance();
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.setCurrentComponent(getFullName());
}

try {
if (atomicOperation == null)
return readCache.load(fileId, pageIndex, checkPinnedPages, writeCache, pageCount, storagePerformanceStatistic);

return atomicOperation.loadPage(fileId, pageIndex, checkPinnedPages, pageCount);
} finally {
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.clearCurrentComponent();
}
}

return atomicOperation.loadPage(fileId, pageIndex, checkPinnedPages, pageCount);
}

protected void pinPage(OAtomicOperation atomicOperation, OCacheEntry cacheEntry) throws IOException {
Expand All @@ -149,17 +163,41 @@ protected void pinPage(OAtomicOperation atomicOperation, OCacheEntry cacheEntry)
}

protected OCacheEntry addPage(OAtomicOperation atomicOperation, long fileId) throws IOException {
if (atomicOperation == null)
return readCache.allocateNewPage(fileId, writeCache, storagePerformanceStatistic);
final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = OSessionStoragePerformanceStatistic
.getStatisticInstance();
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.setCurrentComponent(getFullName());
}

return atomicOperation.addPage(fileId);
try {
if (atomicOperation == null)
return readCache.allocateNewPage(fileId, writeCache, storagePerformanceStatistic);

return atomicOperation.addPage(fileId);
} finally {
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.clearCurrentComponent();
}
}
}

protected void releasePage(OAtomicOperation atomicOperation, OCacheEntry cacheEntry) {
if (atomicOperation == null)
readCache.release(cacheEntry, writeCache, storagePerformanceStatistic);
else
atomicOperation.releasePage(cacheEntry);
final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = OSessionStoragePerformanceStatistic
.getStatisticInstance();
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.setCurrentComponent(getFullName());
}

try {
if (atomicOperation == null)
readCache.release(cacheEntry, writeCache, storagePerformanceStatistic);
else
atomicOperation.releasePage(cacheEntry);
} finally {
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.clearCurrentComponent();
}
}
}

protected long addFile(OAtomicOperation atomicOperation, String fileName) throws IOException {
Expand Down

0 comments on commit 0dadc27

Please sign in to comment.