Search in sources :

Example 1 with OAllCacheEntriesAreUsedException

use of com.orientechnologies.orient.core.exception.OAllCacheEntriesAreUsedException in project orientdb by orientechnologies.

the class O2QCache method removeColdPagesWithoutCacheLock.

private void removeColdPagesWithoutCacheLock() {
    Lock fileLock;
    Lock pageLock;
    int iterationsCounter = 0;
    final MemoryData memoryData = this.memoryDataContainer.get();
    while (am.size() + a1in.size() > memoryData.get2QCacheSize() && iterationsCounter < 1000) {
        iterationsCounter++;
        if (a1in.size() > memoryData.K_IN) {
            OCacheEntry removedFromAInEntry = a1in.getLRU();
            if (removedFromAInEntry == null) {
                throw new OAllCacheEntriesAreUsedException("All records in aIn queue in 2q cache are used!");
            } else {
                fileLock = fileLockManager.acquireSharedLock(removedFromAInEntry.getFileId());
                try {
                    final PageKey k = new PageKey(removedFromAInEntry.getFileId(), removedFromAInEntry.getPageIndex());
                    pageLockManager.acquireExclusiveLock(k);
                    try {
                        if (a1in.get(removedFromAInEntry.getFileId(), removedFromAInEntry.getPageIndex()) == null)
                            continue;
                        if (removedFromAInEntry.getUsagesCount() > 0)
                            continue;
                        assert !removedFromAInEntry.isDirty();
                        a1in.remove(removedFromAInEntry.getFileId(), removedFromAInEntry.getPageIndex());
                        final OCachePointer cachePointer = removedFromAInEntry.getCachePointer();
                        cachePointer.decrementReadersReferrer();
                        removedFromAInEntry.clearCachePointer();
                        if (OLogManager.instance().isDebugEnabled())
                            OLogManager.instance().debug(this, "Moving page in disk cache from a1in to a1out area: %s", removedFromAInEntry);
                        a1out.putToMRU(removedFromAInEntry);
                    } finally {
                        pageLockManager.releaseExclusiveLock(k);
                    }
                } finally {
                    fileLockManager.releaseSharedLock(removedFromAInEntry.getFileId());
                }
            }
            while (a1out.size() > memoryData.K_OUT) {
                OCacheEntry removedEntry = a1out.getLRU();
                fileLock = fileLockManager.acquireSharedLock(removedEntry.getFileId());
                try {
                    final PageKey k = new PageKey(removedEntry.getFileId(), removedEntry.getPageIndex());
                    pageLock = pageLockManager.acquireExclusiveLock(k);
                    try {
                        if (a1out.remove(removedEntry.getFileId(), removedEntry.getPageIndex()) == null)
                            continue;
                        assert removedEntry.getUsagesCount() == 0;
                        assert removedEntry.getCachePointer() == null;
                        assert !removedEntry.isDirty();
                        Set<Long> pageEntries = filePages.get(removedEntry.getFileId());
                        pageEntries.remove(removedEntry.getPageIndex());
                    } finally {
                        pageLockManager.releaseExclusiveLock(k);
                    }
                } finally {
                    fileLockManager.releaseSharedLock(removedEntry.getFileId());
                }
            }
        } else {
            OCacheEntry removedEntry = am.getLRU();
            if (removedEntry == null) {
                throw new OAllCacheEntriesAreUsedException("All records in aIn queue in 2q cache are used!");
            } else {
                fileLock = fileLockManager.acquireSharedLock(removedEntry.getFileId());
                try {
                    final PageKey k = new PageKey(removedEntry.getFileId(), removedEntry.getPageIndex());
                    pageLock = pageLockManager.acquireExclusiveLock(k);
                    try {
                        if (am.get(removedEntry.getFileId(), removedEntry.getPageIndex()) == null)
                            continue;
                        if (removedEntry.getUsagesCount() > 0)
                            continue;
                        assert !removedEntry.isDirty();
                        am.remove(removedEntry.getFileId(), removedEntry.getPageIndex());
                        final OCachePointer cachePointer = removedEntry.getCachePointer();
                        cachePointer.decrementReadersReferrer();
                        removedEntry.clearCachePointer();
                        Set<Long> pageEntries = filePages.get(removedEntry.getFileId());
                        pageEntries.remove(removedEntry.getPageIndex());
                    } finally {
                        pageLockManager.releaseExclusiveLock(k);
                    }
                } finally {
                    fileLockManager.releaseSharedLock(removedEntry.getFileId());
                }
            }
        }
    }
}
Also used : OAllCacheEntriesAreUsedException(com.orientechnologies.orient.core.exception.OAllCacheEntriesAreUsedException) Lock(java.util.concurrent.locks.Lock)

Aggregations

OAllCacheEntriesAreUsedException (com.orientechnologies.orient.core.exception.OAllCacheEntriesAreUsedException)1 Lock (java.util.concurrent.locks.Lock)1