/** * @param fullPageId Page ID to clear. * @return {@code True} if remove successfully. */ boolean clearCheckpoint(FullPageId fullPageId) { Segment seg = segment(fullPageId.groupId(), fullPageId.pageId()); Collection<FullPageId> pages0 = seg.segCheckpointPages; assert pages0 != null; return pages0.remove(fullPageId); }
/** * @param pageId Page ID to check if it was added to the checkpoint list. * @return {@code True} if it was added to the checkpoint list. */ boolean isInCheckpoint(FullPageId pageId) { Segment seg = segment(pageId.groupId(), pageId.pageId()); Collection<FullPageId> pages0 = seg.segCheckpointPages; return pages0 != null && pages0.contains(pageId); }
/** * @param id Full page ID * @return stripe related to current page identifier. */ private Stripe stripe(FullPageId id) { int segmentIdx = PageMemoryImpl.segmentIndex(id.groupId(), id.pageId(), stripes.length); return stripes[segmentIdx]; }
/** * Extracts partition information from full page ID * * @param fullId page related to some cache * @return pair of cache ID and partition ID */ @NotNull public static GroupPartitionId createCachePartId(@NotNull final FullPageId fullId) { return new GroupPartitionId(fullId.groupId(), PageIdUtils.partId(fullId.pageId())); }
/** * @param fullId page ID. * @return Printable string for page ID. */ @NotNull private String getPageString(FullPageId fullId) { return "(grp=" + fullId.groupId() + "," + "page=" + fullId.pageId() + ")"; }
/** * @param absPtr Absolute pointer. * @return Pointer to the page write buffer or {@code 0} if page was not locked. */ long tryWriteLockPage(long absPtr, FullPageId fullId, boolean checkTag) { int tag = checkTag ? PageIdUtils.tag(fullId.pageId()) : OffheapReadWriteLock.TAG_LOCK_ALWAYS; if (!rwLock.tryWriteLock(absPtr + PAGE_LOCK_OFFSET, tag)) return 0; return postWriteLockPage(absPtr, fullId); }
/** * Writes page ID and cache group ID from the page at the given absolute pointer. * * @param absPtr Absolute memory pointer to the page header. * @param fullPageId Full page ID to write. */ private static void fullPageId(final long absPtr, final FullPageId fullPageId) { pageId(absPtr, fullPageId.pageId()); pageGroupId(absPtr, fullPageId.groupId()); } }
/** * @param absPtr Absolute pointer. * @return Pointer to the page write buffer. */ private long writeLockPage(long absPtr, FullPageId fullId, boolean checkTag) { int tag = checkTag ? PageIdUtils.tag(fullId.pageId()) : OffheapReadWriteLock.TAG_LOCK_ALWAYS; boolean locked = rwLock.writeLock(absPtr + PAGE_LOCK_OFFSET, tag); return locked ? postWriteLockPage(absPtr, fullId) : 0; }
/** * @param memory Memory. * @param fullPageId Full page id. * @throws IgniteCheckedException If acquiring lock failed. */ private void acquireAndReleaseWriteLock(PageMemoryImpl memory, FullPageId fullPageId) throws IgniteCheckedException { long page = memory.acquirePage(1, fullPageId.pageId()); long address = memory.writeLock(1, fullPageId.pageId(), page); PageIO.setPageId(address, fullPageId.pageId()); PageIO.setType(address, PageIO.T_BPLUS_META); PageUtils.putShort(address, PageIO.VER_OFF, (short)1); memory.writeUnlock(1, fullPageId.pageId(), page, Boolean.FALSE, true); memory.releasePage(1, fullPageId.pageId(), page); }
/** * @param mem Page memory. * @param fullId Page ID. * @param page Page pointer. * @param val Value to write. */ private void writePage(PageMemory mem, FullPageId fullId, long page, int val) { long pageAddr = mem.writeLock(-1, fullId.pageId(), page); try { PAGE_IO.initNewPage(pageAddr, fullId.pageId(), mem.realPageSize(fullId.groupId())); for (int i = PageIO.COMMON_HEADER_END; i < PAGE_SIZE; i++) PageUtils.putByte(pageAddr, i, (byte)val); } finally { mem.writeUnlock(-1, fullId.pageId(), page, null, true); } }
/** * @param record page snapshot record to handle. */ private void registerPageSnapshot(PageSnapshot record) { FullPageId fullPageId = record.fullPageId(); long pageId = fullPageId.pageId(); incrementStat(getPageType(record), record, pageSnapshotTypes); final int idx = PageIdUtils.pageIndex(pageId); final String idxAsStr = idx <= 100 ? Integer.toString(idx) : ">100"; incrementStat(idxAsStr, record, pageSnapshotIndexes); incrementStat(fullPageId.groupId(), record, pageSnapshotCacheGrp); incrementStat(PageIdUtils.partId(pageId), record, pageSnapshotPartId); }
/** * @param fullPageId page ID to determine segment for * @return segment related */ private ReentrantReadWriteLock getSegment(FullPageId fullPageId) { ReentrantReadWriteLock[] segments = U.field(pageMemory, "segments"); int idx = PageMemoryImpl.segmentIndex(fullPageId.groupId(), fullPageId.pageId(), segments.length); return segments[idx]; }
@Override public void onPartitionDestroyed(int grpId, int partId, int tag) throws IgniteCheckedException { super.onPartitionDestroyed(grpId, partId, tag); cleanupPages(fullPageId -> fullPageId.groupId() == grpId && PageIdUtils.partId(fullPageId.pageId()) == partId); } };
/** * @param db Database. */ private void initInternal(IgniteCacheDatabaseSharedManager db) throws IgniteCheckedException { if (PRESERVE_LEGACY_METASTORAGE_PARTITION_ID) getOrAllocateMetas(partId = PageIdAllocator.OLD_METASTORE_PARTITION); else if (!readOnly || getOrAllocateMetas(partId = PageIdAllocator.OLD_METASTORE_PARTITION)) getOrAllocateMetas(partId = PageIdAllocator.METASTORE_PARTITION); if (!empty) { freeList = new FreeListImpl(METASTORAGE_CACHE_ID, "metastorage", regionMetrics, dataRegion, null, wal, reuseListRoot.pageId().pageId(), reuseListRoot.isAllocated()); MetastorageRowStore rowStore = new MetastorageRowStore(freeList, db); tree = new MetastorageTree(METASTORAGE_CACHE_ID, dataRegion.pageMemory(), wal, rmvId, freeList, rowStore, treeRoot.pageId().pageId(), treeRoot.isAllocated(), failureProcessor, partId); if (!readOnly) ((GridCacheDatabaseSharedManager)db).addCheckpointListener(this); } }
/** * @throws Exception if failed. */ private void writePageData(FullPageId fullId, PageMemory mem) throws Exception { long page = mem.acquirePage(fullId.groupId(), fullId.pageId()); try { long pageAddr = mem.writeLock(fullId.groupId(), fullId.pageId(), page); try { DataPageIO.VERSIONS.latest().initNewPage(pageAddr, fullId.pageId(), mem.realPageSize(fullId.groupId())); ThreadLocalRandom rnd = ThreadLocalRandom.current(); for (int i = PageIO.COMMON_HEADER_END; i < mem.pageSize(); i++) PageUtils.putByte(pageAddr, i, (byte)rnd.nextInt(255)); } finally { mem.writeUnlock(fullId.groupId(), fullId.pageId(), page, null, true); } } finally { mem.releasePage(fullId.groupId(), fullId.pageId(), page); } }
/** * @return collection with pages locked * @param fullPageId page id to check lock. */ private Collection<FullPageId> getLockedPages(FullPageId fullPageId) { Object tracker = delayedReplacementTracker(); Object[] stripes = U.field(tracker, "stripes"); int idx = PageMemoryImpl.segmentIndex(fullPageId.groupId(), fullPageId.pageId(), stripes.length); return U.field(stripes[idx], "locked"); }
/** * @param pageMem Page memory. * @param pageSnapshotRecord Page snapshot record. * @throws IgniteCheckedException If failed. */ public void applyPageSnapshot(PageMemoryEx pageMem, PageSnapshot pageSnapshotRecord) throws IgniteCheckedException { int grpId = pageSnapshotRecord.fullPageId().groupId(); long pageId = pageSnapshotRecord.fullPageId().pageId(); long page = pageMem.acquirePage(grpId, pageId, IoStatisticsHolderNoOp.INSTANCE, true); try { long pageAddr = pageMem.writeLock(grpId, pageId, page, true); try { PageUtils.putBytes(pageAddr, 0, pageSnapshotRecord.pageData()); } finally { pageMem.writeUnlock(grpId, pageId, page, null, true, true); } } finally { pageMem.releasePage(grpId, pageId, page); } }
/** * */ @Test public void testCollisionOnRemove() { Map<FullPageId, Long> ctrl = new LinkedHashMap<>(); int cap = 10; FullPageId baseId = new FullPageId(0, 1); withMap(map -> { for (int i = 0; i < cap; i++) { int grpId = i + 1; int pageId = findPageIdForCollision(grpId, baseId, cap); ctrl.put(new FullPageId(pageId, grpId), (long)grpId); map.put(grpId, pageId, (long)grpId, 1); } for (FullPageId next : ctrl.keySet()) { assertTrue(map.remove(next.groupId(), next.pageId())); } }, cap); }
/** * @param canGetRow Can get row from inner page. * @return Test tree instance. * @throws IgniteCheckedException If failed. */ protected TestTree createTestTree(boolean canGetRow) throws IgniteCheckedException { TestTree tree = new TestTree(reuseList, canGetRow, CACHE_ID, pageMem, allocateMetaPage().pageId()); assertEquals(0, tree.size()); assertEquals(0, tree.rootLevel()); return tree; }
/** * @param pageStore Page store. * @param cacheId Cache id. * @param page Page. */ private void eraseDataFromDisk( FilePageStoreManager pageStore, int cacheId, FullPageId page ) throws IgniteCheckedException, IOException { PageStore store = pageStore.getStore( cacheId, PageIdUtils.partId(page.pageId()) ); FilePageStore filePageStore = (FilePageStore)store; FileIO fileIO = U.field(filePageStore, "fileIO"); long size = fileIO.size(); fileIO.writeFully(ByteBuffer.allocate((int)size - filePageStore.headerSize()), filePageStore.headerSize()); fileIO.force(); }