Class PageIO
- java.lang.Object
-
- org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO
-
- Direct Known Subclasses:
AbstractDataPageIO,BPlusIO,BPlusMetaIO,PageMetaIO,PagePartitionCountersIO,PagesListMetaIO,PagesListNodeIO,TrackingPageIO
public abstract class PageIO extends Object
Base format for all the page types. Checklist for page IO implementations and usage (The Rules): 1. IO should not have any `public static` methods. We have versioned IOs and any static method will mean that it have to always work in backward compatible way between all the IO versions. The base classPageIOhas static methods (like{@link #getPageId(long)}) intentionally: this base format can not be changed between versions. 2. IO must correctly overrideinitNewPage(long, long, int, PageMetrics)method and call super. We have logic that relies on this behavior. 3. Page IO type ID constant must be declared in this class to have a list of all the existing IO types in a single place. 4. IO must be added togetBPlusIO(int, int)or togetPageIO(int, int). 5. Always keep in mind that IOs are versioned and their format can change from version to version. In this respect it is a good practice to avoid exposing details of IO internal format on it's API. The API should be minimalistic and abstract, so that internal format in future IO version can be completely changed without any changes to the API of this page IO. 6. Page IO API should not have any version dependent semantics and should not change API semantics in newer versions. 7. It is almost always preferable to read or write (especially write) page contents using static methods onPageHandler. To just initialize new page usePageHandler.initPage(PageMemory, int, long, PageIO, IgniteWriteAheadLogManager, PageLockListener, IoStatisticsHolder)method with needed IO instance.
-
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description protectedPageIO(int type, int ver)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidassertPageType(long pageAddr)Asserts that page type of the page stored at pageAddr matches page type of this PageIO.protected voidassertPageType(ByteBuffer buf)Asserts that page type of the page stored in the given buffer matches page type of this PageIO.protected voidcopyPage(ByteBuffer page, ByteBuffer out, int pageSize)static IndexPageTypederiveIndexPageType(long pageAddr)static <Q extends BPlusIO<?>>
QgetBPlusIO(int type, int ver)static <Q extends BPlusIO<?>>
QgetBPlusIO(long pageAddr)static shortgetCompactedSize(long pageAddr)static shortgetCompactedSize(ByteBuffer page)static shortgetCompressedSize(long pageAddr)static shortgetCompressedSize(ByteBuffer page)static bytegetCompressionType(long pageAddr)static bytegetCompressionType(ByteBuffer page)static intgetCrc(long pageAddr)static intgetCrc(ByteBuffer buf)abstract intgetFreeSpace(int pageSize, long pageAddr)Count of bytes that is currently free in this page and possibly can be used to place additional payload.static IOVersions<? extends BPlusInnerIO<?>>getInnerVersions(int idx)static IOVersions<? extends BPlusLeafIO<?>>getLeafVersions(int idx)static longgetPageId(long pageAddr)static longgetPageId(ByteBuffer buf)static <Q extends PageIO>
QgetPageIO(int type, int ver)static <Q extends PageIO>
QgetPageIO(long pageAddr)static <Q extends PageIO>
QgetPageIO(ByteBuffer page)static intgetRotatedIdPart(long pageAddr)intgetType()static intgetType(long pageAddr)static intgetType(ByteBuffer buf)intgetVersion()static intgetVersion(long pageAddr)static intgetVersion(ByteBuffer buf)voidinitNewPage(long pageAddr, long pageId, int pageSize, @Nullable PageMetrics metrics)static booleanisDataPageType(int type)static booleanisIndexPage(int pageType)Returnstrueif the given page type is related to SQL index data pages.static StringprintPage(long addr, int pageSize)protected abstract voidprintPage(long addr, int pageSize, GridStringBuilder sb)static voidregisterH2(IOVersions<? extends BPlusInnerIO<?>> innerIOs, IOVersions<? extends BPlusLeafIO<?>> leafIOs)Registers this B+Tree IO versions.static voidregisterH2ExtraInner(IOVersions<? extends BPlusInnerIO<?>> innerExtIOs)Registers extra inner IO versions.static voidregisterH2ExtraLeaf(IOVersions<? extends BPlusLeafIO<?>> leafExtIOs)Registers extra inner IO versions.static voidregisterTest(BPlusInnerIO<?> innerIO, BPlusLeafIO<?> leafIO)Registers IOs for testing.static voidregisterTest(PageIO io)Registers IO for testing.static voidsetCompactedSize(ByteBuffer page, short compactedSize)static voidsetCompressedSize(ByteBuffer page, short compressedSize)static voidsetCompressionType(ByteBuffer page, byte compressType)static voidsetCrc(long pageAddr, int crc)static voidsetCrc(ByteBuffer buf, int crc)static voidsetPageId(long pageAddr, long pageId)static voidsetRotatedIdPart(long pageAddr, int rotatedIdPart)static voidsetType(long pageAddr, int type)protected static voidsetVersion(long pageAddr, int ver)StringtoString()
-
-
-
Field Detail
-
MAX_PAYLOAD_SIZE
public static final short MAX_PAYLOAD_SIZE
Maximum payload size.- See Also:
- Constant Field Values
-
TYPE_OFF
public static final int TYPE_OFF
- See Also:
- Constant Field Values
-
VER_OFF
public static final int VER_OFF
- See Also:
- Constant Field Values
-
CRC_OFF
public static final int CRC_OFF
- See Also:
- Constant Field Values
-
PAGE_ID_OFF
public static final int PAGE_ID_OFF
- See Also:
- Constant Field Values
-
ROTATED_ID_PART_OFF
public static final int ROTATED_ID_PART_OFF
- See Also:
- Constant Field Values
-
COMMON_HEADER_END
public static final int COMMON_HEADER_END
- See Also:
- Constant Field Values
-
T_DATA
public static final short T_DATA
- See Also:
- Constant Field Values
-
T_BPLUS_META
public static final short T_BPLUS_META
- See Also:
- Constant Field Values
-
T_H2_REF_LEAF
public static final short T_H2_REF_LEAF
- See Also:
- Constant Field Values
-
T_H2_REF_INNER
public static final short T_H2_REF_INNER
- See Also:
- Constant Field Values
-
T_DATA_REF_INNER
public static final short T_DATA_REF_INNER
- See Also:
- Constant Field Values
-
T_DATA_REF_LEAF
public static final short T_DATA_REF_LEAF
- See Also:
- Constant Field Values
-
T_METASTORE_INNER
public static final short T_METASTORE_INNER
- See Also:
- Constant Field Values
-
T_METASTORE_LEAF
public static final short T_METASTORE_LEAF
- See Also:
- Constant Field Values
-
T_PENDING_REF_INNER
public static final short T_PENDING_REF_INNER
- See Also:
- Constant Field Values
-
T_PENDING_REF_LEAF
public static final short T_PENDING_REF_LEAF
- See Also:
- Constant Field Values
-
T_META
public static final short T_META
- See Also:
- Constant Field Values
-
T_PAGE_LIST_META
public static final short T_PAGE_LIST_META
- See Also:
- Constant Field Values
-
T_PAGE_LIST_NODE
public static final short T_PAGE_LIST_NODE
- See Also:
- Constant Field Values
-
T_PART_META
public static final short T_PART_META
- See Also:
- Constant Field Values
-
T_PAGE_UPDATE_TRACKING
public static final short T_PAGE_UPDATE_TRACKING
- See Also:
- Constant Field Values
-
T_CACHE_ID_AWARE_DATA_REF_INNER
public static final short T_CACHE_ID_AWARE_DATA_REF_INNER
- See Also:
- Constant Field Values
-
T_CACHE_ID_AWARE_DATA_REF_LEAF
public static final short T_CACHE_ID_AWARE_DATA_REF_LEAF
- See Also:
- Constant Field Values
-
T_CACHE_ID_AWARE_PENDING_REF_INNER
public static final short T_CACHE_ID_AWARE_PENDING_REF_INNER
- See Also:
- Constant Field Values
-
T_CACHE_ID_AWARE_PENDING_REF_LEAF
public static final short T_CACHE_ID_AWARE_PENDING_REF_LEAF
- See Also:
- Constant Field Values
-
T_PART_CNTRS
public static final short T_PART_CNTRS
- See Also:
- Constant Field Values
-
T_DATA_METASTORAGE
public static final short T_DATA_METASTORAGE
- See Also:
- Constant Field Values
-
T_DATA_REF_METASTORAGE_INNER
public static final short T_DATA_REF_METASTORAGE_INNER
- See Also:
- Constant Field Values
-
T_DATA_REF_METASTORAGE_LEAF
public static final short T_DATA_REF_METASTORAGE_LEAF
- See Also:
- Constant Field Values
-
T_DATA_PART
public static final short T_DATA_PART
- See Also:
- Constant Field Values
-
T_MARKER_PAGE
public static final short T_MARKER_PAGE
- See Also:
- Constant Field Values
-
T_DEFRAG_LINK_MAPPING_INNER
public static final short T_DEFRAG_LINK_MAPPING_INNER
- See Also:
- Constant Field Values
-
T_DEFRAG_LINK_MAPPING_LEAF
public static final short T_DEFRAG_LINK_MAPPING_LEAF
- See Also:
- Constant Field Values
-
T_H2_EX_REF_LEAF_START
public static final short T_H2_EX_REF_LEAF_START
Index for payload == 1.- See Also:
- Constant Field Values
-
T_H2_EX_REF_LEAF_END
public static final short T_H2_EX_REF_LEAF_END
- See Also:
- Constant Field Values
-
T_H2_EX_REF_INNER_START
public static final short T_H2_EX_REF_INNER_START
- See Also:
- Constant Field Values
-
T_H2_EX_REF_INNER_END
public static final short T_H2_EX_REF_INNER_END
- See Also:
- Constant Field Values
-
-
Method Detail
-
getType
public static int getType(ByteBuffer buf)
- Parameters:
buf- Buffer.- Returns:
- Page type.
-
getType
public static int getType(long pageAddr)
- Parameters:
pageAddr- Page address.- Returns:
- Page type.
-
setType
public static void setType(long pageAddr, int type)- Parameters:
pageAddr- Page address.type- Type.
-
getVersion
public static int getVersion(ByteBuffer buf)
- Parameters:
buf- Buffer.- Returns:
- Version.
-
getVersion
public static int getVersion(long pageAddr)
- Parameters:
pageAddr- Page address.- Returns:
- Version.
-
setVersion
protected static void setVersion(long pageAddr, int ver)- Parameters:
pageAddr- Page address.ver- Version.
-
getPageId
public static long getPageId(ByteBuffer buf)
- Parameters:
buf- Buffer.- Returns:
- Page ID.
-
getPageId
public static long getPageId(long pageAddr)
- Parameters:
pageAddr- Page address.- Returns:
- Page ID.
-
setPageId
public static void setPageId(long pageAddr, long pageId)- Parameters:
pageAddr- Page address.pageId- Page ID.
-
getRotatedIdPart
public static int getRotatedIdPart(long pageAddr)
- Parameters:
pageAddr- Page address.- Returns:
- Rotated page ID part.
-
setRotatedIdPart
public static void setRotatedIdPart(long pageAddr, int rotatedIdPart)- Parameters:
pageAddr- Page address.rotatedIdPart- Rotated page ID part.
-
setCompressionType
public static void setCompressionType(ByteBuffer page, byte compressType)
- Parameters:
page- Page buffer.compressType- Compression type.
-
getCompressionType
public static byte getCompressionType(ByteBuffer page)
- Parameters:
page- Page buffer.- Returns:
- Compression type.
-
getCompressionType
public static byte getCompressionType(long pageAddr)
- Parameters:
pageAddr- Page address.- Returns:
- Compression type.
-
setCompressedSize
public static void setCompressedSize(ByteBuffer page, short compressedSize)
- Parameters:
page- Page buffer.compressedSize- Compressed size.
-
getCompressedSize
public static short getCompressedSize(ByteBuffer page)
- Parameters:
page- Page buffer.- Returns:
- Compressed size.
-
getCompressedSize
public static short getCompressedSize(long pageAddr)
- Parameters:
pageAddr- Page address.- Returns:
- Compressed size.
-
setCompactedSize
public static void setCompactedSize(ByteBuffer page, short compactedSize)
- Parameters:
page- Page buffer.compactedSize- Compacted size.
-
getCompactedSize
public static short getCompactedSize(ByteBuffer page)
- Parameters:
page- Page buffer.- Returns:
- Compacted size.
-
getCompactedSize
public static short getCompactedSize(long pageAddr)
- Parameters:
pageAddr- Page address.- Returns:
- Compacted size.
-
getCrc
public static int getCrc(long pageAddr)
- Parameters:
pageAddr- Page address.- Returns:
- Checksum.
-
setCrc
public static void setCrc(long pageAddr, int crc)- Parameters:
pageAddr- Page address.crc- Checksum.
-
getCrc
public static int getCrc(ByteBuffer buf)
- Parameters:
buf- Buffer.- Returns:
- Checksum.
-
setCrc
public static void setCrc(ByteBuffer buf, int crc)
- Parameters:
buf- Buffer.crc- Checksum.
-
registerH2
public static void registerH2(IOVersions<? extends BPlusInnerIO<?>> innerIOs, IOVersions<? extends BPlusLeafIO<?>> leafIOs)
Registers this B+Tree IO versions.- Parameters:
innerIOs- Inner IO versions.leafIOs- Leaf IO versions.
-
registerH2ExtraInner
public static void registerH2ExtraInner(IOVersions<? extends BPlusInnerIO<?>> innerExtIOs)
Registers extra inner IO versions.- Parameters:
innerExtIOs- Extra versions.
-
registerH2ExtraLeaf
public static void registerH2ExtraLeaf(IOVersions<? extends BPlusLeafIO<?>> leafExtIOs)
Registers extra inner IO versions.- Parameters:
leafExtIOs- Extra versions.
-
getInnerVersions
public static IOVersions<? extends BPlusInnerIO<?>> getInnerVersions(int idx)
- Parameters:
idx- Index.- Returns:
- IOVersions for given idx.
-
getLeafVersions
public static IOVersions<? extends BPlusLeafIO<?>> getLeafVersions(int idx)
- Parameters:
idx- Index.- Returns:
- IOVersions for given idx.
-
registerTest
public static void registerTest(BPlusInnerIO<?> innerIO, BPlusLeafIO<?> leafIO)
Registers IOs for testing.- Parameters:
innerIO- Inner IO.leafIO- Leaf IO.
-
registerTest
public static void registerTest(PageIO io)
Registers IO for testing.- Parameters:
io- Page IO.
-
getType
public final int getType()
- Returns:
- Type.
-
getVersion
public final int getVersion()
- Returns:
- Version.
-
initNewPage
public void initNewPage(long pageAddr, long pageId, int pageSize, @Nullable @Nullable PageMetrics metrics)- Parameters:
pageAddr- Page address.pageId- Page ID.pageSize- Page size.metrics- Page metrics for tracking page allocation. Can benullif no tracking is required.- See Also:
EncryptionSpi.encryptedSize(int)
-
isIndexPage
public static boolean isIndexPage(int pageType)
Returnstrueif the given page type is related to SQL index data pages.- Parameters:
pageType- Page type (can be obtained bygetType(long)orgetType(ByteBuffer)methods).
-
getPageIO
public static <Q extends PageIO> Q getPageIO(long pageAddr) throws IgniteCheckedException
- Parameters:
pageAddr- Page address.- Returns:
- IO.
- Throws:
IgniteCheckedException- If failed.
-
getPageIO
public static <Q extends PageIO> Q getPageIO(ByteBuffer page) throws IgniteCheckedException
- Parameters:
page- Page.- Returns:
- Page IO.
- Throws:
IgniteCheckedException- If failed.
-
getPageIO
public static <Q extends PageIO> Q getPageIO(int type, int ver) throws IgniteCheckedException
- Parameters:
type- IO Type.ver- IO Version.- Returns:
- Page IO.
- Throws:
IgniteCheckedException- If failed.
-
getBPlusIO
public static <Q extends BPlusIO<?>> Q getBPlusIO(long pageAddr) throws IgniteCheckedException
- Parameters:
pageAddr- Page address.- Returns:
- IO for either inner or leaf B+Tree page.
- Throws:
IgniteCheckedException- If failed.
-
getBPlusIO
public static <Q extends BPlusIO<?>> Q getBPlusIO(int type, int ver) throws IgniteCheckedException
- Parameters:
type- IO Type.ver- IO Version.- Returns:
- IO for either inner or leaf B+Tree page.
- Throws:
IgniteCheckedException- If failed.
-
deriveIndexPageType
public static IndexPageType deriveIndexPageType(long pageAddr)
- Parameters:
pageAddr- Address of page.- Returns:
- Index page type.
-
isDataPageType
public static boolean isDataPageType(int type)
- Parameters:
type- Type to test.- Returns:
Trueif data page.
-
printPage
protected abstract void printPage(long addr, int pageSize, GridStringBuilder sb) throws IgniteCheckedException- Parameters:
addr- Address.pageSize- Page size.sb- Sb.- Throws:
IgniteCheckedException
-
getFreeSpace
public abstract int getFreeSpace(int pageSize, long pageAddr)Count of bytes that is currently free in this page and possibly can be used to place additional payload.- Parameters:
pageSize- Page size.pageAddr- Page address.- Returns:
- Free space.
-
copyPage
protected final void copyPage(ByteBuffer page, ByteBuffer out, int pageSize)
- Parameters:
page- Page.out- Output buffer.pageSize- Page size.
-
printPage
public static String printPage(long addr, int pageSize)
- Parameters:
addr- Address.
-
assertPageType
protected final void assertPageType(long pageAddr)
Asserts that page type of the page stored at pageAddr matches page type of this PageIO.- Parameters:
pageAddr- address of a page to use for assertion
-
assertPageType
protected final void assertPageType(ByteBuffer buf)
Asserts that page type of the page stored in the given buffer matches page type of this PageIO.- Parameters:
buf- buffer where the page for assertion is stored
-
-