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; 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.command.OCommandOutputListener;
import com.orientechnologies.orient.core.storage.impl.local.OLowDiskSpaceListener; 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); 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); 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.OBinarySerializer;
import com.orientechnologies.common.serialization.types.OIntegerSerializer; import com.orientechnologies.common.serialization.types.OIntegerSerializer;
import com.orientechnologies.common.serialization.types.OLongSerializer; 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.command.OCommandOutputListener;
import com.orientechnologies.orient.core.config.OGlobalConfiguration; import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.exception.OStorageException; 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); final int intId = extractFileId(fileId);
if (pageCount < 1) if (pageCount < 1)
throw new IllegalArgumentException("Amount of pages to load should be not less than 1 but provided value is " + pageCount); 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]); PageGroup pageGroup = writeCachePages.get(pageKeys[0]);


if (pageGroup == null) { 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) if (pagePointers.length == 0)
return pagePointers; return pagePointers;
Expand All @@ -639,6 +641,9 @@ public OCachePointer[] load(long fileId, long startPageIndex, int pageCount, boo


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

cacheHit.setValue(true);

return new OCachePointer[] { pagePointer }; return new OCachePointer[] { pagePointer };
} finally { } finally {
for (Lock lock : pageLocks) { 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, 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); 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 byte[] content = new byte[pageSize + 2 * PAGE_PADDING];
final ODirectMemoryPointer pointer = ODirectMemoryPointerFactory.instance().createPointer(content); final ODirectMemoryPointer pointer = ODirectMemoryPointerFactory.instance().createPointer(content);
OCachePointer dataPointer = new OCachePointer(pointer, lastLsn, fileId, startPageIndex); OCachePointer dataPointer = new OCachePointer(pointer, lastLsn, fileId, startPageIndex);
cacheHit.setValue(true);
return new OCachePointer[] { dataPointer }; return new OCachePointer[] { dataPointer };
} else } else
return new OCachePointer[0]; return new OCachePointer[0];
Expand Down
Expand Up @@ -387,10 +387,6 @@ private UpdateCacheResult doLoad(long fileId, long pageIndex, boolean checkPinne
Lock fileLock; Lock fileLock;
Lock[] pageLocks; Lock[] pageLocks;


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

final OModifiableBoolean cacheHit = new OModifiableBoolean(false); final OModifiableBoolean cacheHit = new OModifiableBoolean(false);


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


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


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

cacheHit.setValue(true); cacheHit.setValue(true);
} }


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


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

return new UpdateCacheResult(removeColdPages, cacheEntry); 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, private UpdateCacheResult updateCache(final long fileId, final long pageIndex, final boolean addNewPages, OWriteCache writeCache,
final int pageCount, final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic, final int pageCount, final OModifiableBoolean cacheHit) throws IOException {
final OModifiableBoolean cacheHit) throws IOException {


assert pageCount > 0; assert pageCount > 0;


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


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

cacheHit.setValue(true); cacheHit.setValue(true);


return new UpdateCacheResult(entryIsInAmQueue(fileId, pageIndex, cacheEntry), cacheEntry); 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); cacheEntry = a1out.remove(fileId, pageIndex);
if (cacheEntry != null) { if (cacheEntry != null) {
dataPointers = writeCache.load(fileId, pageIndex, pageCount, false); dataPointers = writeCache.load(fileId, pageIndex, pageCount, false, cacheHit);


OCachePointer dataPointer = dataPointers[0]; OCachePointer dataPointer = dataPointers[0];
removeColdPages = entryWasInA1OutQueue(fileId, pageIndex, dataPointer, cacheEntry); 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) { if (cacheEntry != null) {
removeColdPages = entryIsInA1InQueue(fileId, pageIndex); removeColdPages = entryIsInA1InQueue(fileId, pageIndex);
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.incrementCacheHit();
}

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


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


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


storagePerformanceStatistic.stopCommitTimer(); 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.OAtomicOperation;
import com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperationsManager; 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.paginated.wal.OWALChangesTree;
import com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic;
import com.orientechnologies.orient.core.storage.impl.local.statistic.OStoragePerformanceStatistic; import com.orientechnologies.orient.core.storage.impl.local.statistic.OStoragePerformanceStatistic;


import java.io.IOException; 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, protected OCacheEntry loadPage(OAtomicOperation atomicOperation, long fileId, long pageIndex, boolean checkPinnedPages,
final int pageCount) throws IOException { final int pageCount) throws IOException {
if (atomicOperation == null) final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = OSessionStoragePerformanceStatistic
return readCache.load(fileId, pageIndex, checkPinnedPages, writeCache, pageCount, storagePerformanceStatistic); .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 { 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 { protected OCacheEntry addPage(OAtomicOperation atomicOperation, long fileId) throws IOException {
if (atomicOperation == null) final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = OSessionStoragePerformanceStatistic
return readCache.allocateNewPage(fileId, writeCache, storagePerformanceStatistic); .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) { protected void releasePage(OAtomicOperation atomicOperation, OCacheEntry cacheEntry) {
if (atomicOperation == null) final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = OSessionStoragePerformanceStatistic
readCache.release(cacheEntry, writeCache, storagePerformanceStatistic); .getStatisticInstance();
else if (sessionStoragePerformanceStatistic != null) {
atomicOperation.releasePage(cacheEntry); 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 { protected long addFile(OAtomicOperation atomicOperation, String fileName) throws IOException {
Expand Down

0 comments on commit 0dadc27

Please sign in to comment.