/** * @param pageId Page ID. * @param grpId Cache group ID. */ public FullPageId(long pageId, int grpId) { this.pageId = pageId; this.grpId = grpId; effectivePageId = PageIdUtils.effectivePageId(pageId); }
/** * @param grpId Cache group ID. * @param pageId Page ID. * @return Hash code. */ public static int hashCode(int grpId, long pageId) { long effectiveId = PageIdUtils.effectivePageId(pageId); return U.hash(hashCode0(grpId, effectiveId)); }
/** * @param pageId Page ID. * @return Segment index. */ public static int segmentIndex(int grpId, long pageId, int segments) { pageId = PageIdUtils.effectivePageId(pageId); // Take a prime number larger than total number of partitions. int hash = U.hash(pageId * 65537 + grpId); return U.safeAbs(hash) % segments; }
/** {@inheritDoc} */ @Override public void onWriteUnlock(int cacheId, long pageId, long page, long pageAddr) { assertEquals(effectivePageId(pageId), effectivePageId(PageIO.getPageId(pageAddr))); assertTrue(writeLocks.get().remove(pageId)); }
/** * @throws Exception If failed. */ @Test public void testEffectivePageId() throws Exception { assertEquals(0x0000FFFFFFFFFFFFL, PageIdUtils.effectivePageId(0x0002FFFFFFFFFFFFL)); assertEquals(0x0000FFFFFFFFFFFFL, PageIdUtils.effectivePageId(0x0A02FFFFFFFFFFFFL)); assertEquals(0x0000FFFFFFFFFFFFL, PageIdUtils.effectivePageId(0x0F02FFFFFFFFFFFFL)); assertEquals(0x0000FFFFFFFFFFFFL, PageIdUtils.effectivePageId(0xFF02FFFFFFFFFFFFL)); }
/** {@inheritDoc} */ @Override public void onWriteUnlock(int cacheId, long pageId, long page, long pageAddr) { if (PRINT_LOCKS) X.println(" onWriteUnlock: " + U.hexLong(pageId)); assertEquals(effectivePageId(pageId), effectivePageId(PageIO.getPageId(pageAddr))); assertEquals(Long.valueOf(pageId), locks(false).remove(pageId)); }
long relPtr = seg.loadedPages.refresh(grpId, PageIdUtils.effectivePageId(pageId), tag); seg.loadedPages.remove(grpId, PageIdUtils.effectivePageId(pageId));
PageIdUtils.effectivePageId(fullId.pageId()), tag, INVALID_REL_PTR, PageIdUtils.effectivePageId(fullId.pageId()), seg.partGeneration( fullId.groupId(), seg, fullId.groupId(), PageIdUtils.effectivePageId(fullId.pageId()), true );
/** * @param b String builder. * @param locks Locks. * @param beforeLock Before lock. */ private static void printLocks(SB b, ConcurrentMap<Object, Map<Long, Long>> locks, Map<Object, Long> beforeLock) { for (Map.Entry<Object,Map<Long,Long>> entry : locks.entrySet()) { Object thId = entry.getKey(); Long z = beforeLock.get(thId); Set<Map.Entry<Long,Long>> xx = entry.getValue().entrySet(); if (z == null && xx.isEmpty()) continue; b.a(" ## " + thId); if (z != null) b.a(" --> ").appendHex(z).a(" (").appendHex(effectivePageId(z)).a(')'); b.a('\n'); for (Map.Entry<Long,Long> x : xx) b.a(" - ").appendHex(x.getValue()).a(" (").appendHex(x.getKey()).a(")\n"); b.a('\n'); } }
long relPtr = seg.loadedPages.get( grpId, PageIdUtils.effectivePageId(pageId), seg.partGeneration(grpId, partId), INVALID_REL_PTR, PageIdUtils.effectivePageId(pageId), seg.partGeneration(grpId, partId), INVALID_REL_PTR, PageIdUtils.effectivePageId(pageId), relPtr, seg.partGeneration(grpId, partId)
PageIdUtils.effectivePageId(fullPageId.pageId()) );
loadedPages.remove( fullPageId.groupId(), PageIdUtils.effectivePageId(fullPageId.pageId()) );
long relPtr = seg.loadedPages.get( grpId, PageIdUtils.effectivePageId(pageId), seg.partGeneration(grpId, partId), INVALID_REL_PTR, seg.loadedPages.put(grpId, PageIdUtils.effectivePageId(pageId), relPtr, seg.partGeneration(grpId, partId));
/** * @param pageId Page ID. * @param grpId Cache group ID. */ public FullPageId(long pageId, int grpId) { this.pageId = pageId; this.grpId = grpId; effectivePageId = PageIdUtils.effectivePageId(pageId); }
/** * @param pageId Page ID. * @return Segment index. */ public static int segmentIndex(int grpId, long pageId, int segments) { pageId = PageIdUtils.effectivePageId(pageId); // Take a prime number larger than total number of partitions. int hash = U.hash(pageId * 65537 + grpId); return U.safeAbs(hash) % segments; }
/** * @param grpId Cache group ID. * @param pageId Page ID. * @return Hash code. */ public static int hashCode(int grpId, long pageId) { long effectiveId = PageIdUtils.effectivePageId(pageId); return U.hash(hashCode0(grpId, effectiveId)); }
/** * @param seg Segment. * @param grpId Cache group ID. * @param pageId Page ID. * @param rmv {@code True} if page should be removed. * @return Relative pointer to refreshed page. */ private long refreshOutdatedPage(Segment seg, int grpId, long pageId, boolean rmv) { assert seg.writeLock().isHeldByCurrentThread(); int tag = seg.partGeneration(grpId, PageIdUtils.partId(pageId)); long relPtr = seg.loadedPages.refresh(grpId, PageIdUtils.effectivePageId(pageId), tag); long absPtr = seg.absolute(relPtr); GridUnsafe.setMemory(absPtr + PAGE_OVERHEAD, pageSize(), (byte)0); PageHeader.dirty(absPtr, false); long tmpBufPtr = PageHeader.tempBufferPointer(absPtr); if (tmpBufPtr != INVALID_REL_PTR) { GridUnsafe.setMemory(checkpointPool.absolute(tmpBufPtr) + PAGE_OVERHEAD, pageSize(), (byte)0); PageHeader.tempBufferPointer(absPtr, INVALID_REL_PTR); // We pinned the page when allocated the temp buffer, release it now. PageHeader.releasePage(absPtr); checkpointPool.releaseFreePage(tmpBufPtr); } if (rmv) seg.loadedPages.remove(grpId, PageIdUtils.effectivePageId(pageId)); if (seg.segCheckpointPages != null) seg.segCheckpointPages.remove(new FullPageId(pageId, grpId)); if (seg.dirtyPages != null) seg.dirtyPages.remove(new FullPageId(pageId, grpId)); return relPtr; }
PageIdUtils.effectivePageId(fullId.pageId()), tag, INVALID_REL_PTR, PageIdUtils.effectivePageId(fullId.pageId()), seg.partGeneration( fullId.groupId(), seg, fullId.groupId(), PageIdUtils.effectivePageId(fullId.pageId()), true );
loadedPages.remove( fullPageId.groupId(), PageIdUtils.effectivePageId(fullPageId.pageId()) );
long relPtr = seg.loadedPages.get( grpId, PageIdUtils.effectivePageId(pageId), seg.partGeneration(grpId, partId), INVALID_REL_PTR, seg.loadedPages.put(grpId, PageIdUtils.effectivePageId(pageId), relPtr, seg.partGeneration(grpId, partId));