ibessonov commented on a change in pull request #566: URL: https://github.com/apache/ignite-3/pull/566#discussion_r789633971
########## File path: modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/util/PageIdUtils.java ########## @@ -0,0 +1,264 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.pagememory.util; + +import org.apache.ignite.internal.pagememory.PageIdAllocator; +import org.apache.ignite.internal.util.IgniteUtils; + +/** + * Utility class for page ID parts manipulation. + * + * @see FullPageId + */ +public final class PageIdUtils { + /** Size of the page index portion. */ + public static final int PAGE_IDX_SIZE = Integer.SIZE; + + /** Size of the partition ID portion. */ + public static final int PART_ID_SIZE = Short.SIZE; + + /** Size of the flags portion. */ + public static final int FLAG_SIZE = Byte.SIZE; + + /** Size of the offset portion. */ + public static final int OFFSET_SIZE = Byte.SIZE; + + /** Size of a tag portion. */ + public static final int TAG_SIZE = 2 * Byte.SIZE; + + /** Page index mask. */ + public static final long PAGE_IDX_MASK = ~(-1L << PAGE_IDX_SIZE); + + /** Offset mask. */ + public static final long OFFSET_MASK = ~(-1L << OFFSET_SIZE); + + /** Tag mask. */ + public static final long TAG_MASK = ~(-1L << TAG_SIZE); + + /** Page Index is a monotonically growing number within each partition. */ + public static final long PART_ID_MASK = ~(-1L << PART_ID_SIZE); + + /** Flags mask. Flags consists from a number of reserved bits, and page type (data/index page). */ + public static final long FLAG_MASK = ~(-1L << FLAG_SIZE); + + /** Effective page ID mask. */ + private static final long EFFECTIVE_PAGE_ID_MASK = ~(-1L << (PAGE_IDX_SIZE + PART_ID_SIZE)); + + /** + * Offset of a Rotation ID inside a Page ID. + */ + private static final long ROTATION_ID_OFFSET = PAGE_IDX_SIZE + PART_ID_SIZE + FLAG_SIZE; + + /** Page ID mask that excludes link. */ + private static final long PAGE_ID_MASK = ~(-1L << ROTATION_ID_OFFSET); + + /** Max itemid number. */ + public static final int MAX_ITEMID_NUM = 0xFE; + + /** Maximum page number. */ + public static final long MAX_PAGE_NUM = (1L << PAGE_IDX_SIZE) - 1; + + /** Maximum page number. */ + public static final int MAX_PART_ID = (1 << PART_ID_SIZE) - 1; + + /** Private constructor. */ + private PageIdUtils() { + // No-op. + } + + /** + * Constructs a page link by the given page ID and 8-byte words within the page. + * + * @param pageId Page ID. + * @param itemId Item ID. + * @return Page link. + */ + public static long link(long pageId, int itemId) { + assert itemId >= 0 && itemId <= MAX_ITEMID_NUM : itemId; + assert (pageId >> ROTATION_ID_OFFSET) == 0 : IgniteUtils.hexLong(pageId); + + return pageId | (((long) itemId) << ROTATION_ID_OFFSET); + } + + /** + * Extracts a page index from the given page ID. + * + * @param pageId Page ID. + * @return Page index. + */ + public static int pageIndex(long pageId) { + return (int) (pageId & PAGE_IDX_MASK); // 4 bytes + } + + /** + * Extracts a page ID from the given page link. + * + * @param link Page link. + * @return Page ID. + */ + public static long pageId(long link) { + return flag(link) == PageIdAllocator.FLAG_DATA ? link & PAGE_ID_MASK : link; + } + + /** + * Creates page ID from its components. + * + * @param partId Partition ID. + * @param flag Flags (a number of reserved bits, and page type (data/index page)) + * @param pageIdx Page index, monotonically growing number within each partition + * @return Page ID constructed from the given pageIdx and partition ID, see {@link FullPageId} + */ + public static long pageId(int partId, byte flag, int pageIdx) { Review comment: I agree with you, all "partId" will be replaced with "partitionId" -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
