org.apache.flink.runtime.state.gemini.engine.page.PageAddress Maven / Gradle / Ivy
/*
* 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.flink.runtime.state.gemini.engine.page;
import org.apache.flink.annotation.Internal;
import org.apache.flink.runtime.state.gemini.engine.GRegionContext;
import org.apache.flink.runtime.state.gemini.engine.filecache.FileCache;
import org.apache.flink.runtime.state.gemini.engine.page.bmap.GBinaryHashMap;
import org.apache.flink.runtime.state.gemini.engine.rm.GByteBuffer;
import org.apache.flink.runtime.state.gemini.engine.snapshot.RegionSnapshot;
import org.apache.flink.shaded.netty4.io.netty.util.concurrent.EventExecutor;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
/**
* PageAddress consists of its dfs or local address on storage or memory address on heap.
*
* After restore, the {@link DataPage} might not contain the actual value and need to fetch the data via address.
*/
@Internal
public interface PageAddress {
byte PAGE_VALID_MASK = (byte) 0x01;
byte LOCAL_VALID_MASK = (byte) 0x02;
byte DFS_VALID_MASK = (byte) 0x04;
byte SINGLE_PAGE_ADDRESS = (byte) 0x01;
byte COMPOSITE_PAGE_ADDRESS = (byte) 0x02;
/**
* Get the data page address on heap.
*
*
We encapsulate this address as a {@link DataPage} which acts as a field of {@link PageAddress} to leverage
* Java's feature of object reference, this field actually points to a memory address within Java heap.
*/
DataPage getDataPage();
/**
* getDataPage with adding reference for this page if this page existed.
*/
GByteBuffer getGByteBufferWithReference();
/**
* getDataPage without adding reference.
*/
GByteBuffer getGByteBufferNoReference();
/**
* getDataPage without adding reference.
*/
DataPage getDataPageNoReference();
/**
* check if DataPage exists.
*/
boolean hasDataPage();
/**
* Get Dfs Address for this Page.
*/
long getDfsAddress();
/**
* Get Local Address for this Page.
*/
long getLocalAddress();
/**
* Get version of this Page, if DataPage isn't exist return -1.
*/
long getVersion();
/**
* Load DataPage into this PageAddress.
*/
void setDataPage(DataPage dataPage);
/**
* Set dfs address into this PageAddress.
*/
void setDfsAddress(long dfsAddress);
/**
* Set local address into this PageAddress.
*/
void setLocalAddress(long localAddress);
/**
* Set status of page, true is valid, and false is invalid.
*/
void setPageStatus(boolean flag);
/**
* Check if page is valid.
*/
boolean isPageValid();
/**
* Set status of local address, true is valid, and false is invalid.
*/
void setLocalStatus(boolean flag);
/**
* check if local address is valid.
*/
boolean isLocalValid();
/**
* Set status of dfs address, true is valid, and false is invalid.
*/
void setDfsStatus(boolean flag);
/**
* Check if dfs address is valid.
*/
boolean isDfsValid();
/**
* Get data len of this pageAddress.
* so, PageAddressCompositeImpl will return the total size of mainPage and all subPages.
*/
int getDataLen();
/**
* Get the data len of main page.
* for PageAddressCompositeImpl, return the data len of main page.
* for PageAddressSingleImpl, return data len of this pageAddress.
*/
int getMainPageDataLen();
/**
* Get num of sub page.
* for PageAddressSingleImpl, return 0;
* for PageAddressCompositeImpl, return the num of sub page
*/
int getSubPageNum();
/**
* Get the data len of sub pages.
* for PageAddressSingleImpl, return 0;
* for PageAddressCompositeImpl, return the total data len of sub pages
*/
int getSubPageDataLen();
/**
* Get checksum of this page.
*/
int getChecksum();
/**
* Execute snapshot phase for this PageAddress.
*/
void snapshot(Collection regionSnapshots) throws IOException;
/**
* Get type of this PageAddress, now support single and composite pageAddress.
*/
byte getPageAddressType();
/**
* Set current index for this PageAddress.
*/
void setChainIndex(int chainIndex);
/**
* Returns the data page size of pages in memory.
*/
int getMemorySize();
/**
* Discard a PageAddress.
*/
void discard(FileCache fileCache, GRegionContext gRegionContext, EventExecutor eventExecutor);
/**
* Box the GBinaryHashMap according to the PageAddress type.
*/
GBinaryHashMap toBoxGBinaryHashMap(GBinaryHashMap gBinaryHashMap, GRegionContext gRegionContext, int logicPageChainIndex, int logicPageChainHashCode);
/**
* Returns an iterator over all pages in this PageAddress. For {@link PageAddressSingleImpl},
* the iterator only has one page which is just 'this'. For {@link PageAddressCompositeImpl},
* the iterator will iterates the main page and all sub-pages, and the iteration order is up
* to the implementation.
*
* @return an iterator over all pages in this PageAddress
*/
Iterator pageIterator();
/**
* For {@link PageAddressSingleImpl} returns a single element contains the main page.
* For {@link PageAddressCompositeImpl} returns a collection contains main page and all subpages,
* the order of the pages is like `main page`, `subpage_0`, `subpage_1`, ..., `subpage_n`.
*
* @return
*/
Iterator pageIteratorOrdered();
/**
* Add requestCount for a new page.
*/
void addRequestCountForNewPage(long currentTickTime, int requestCount);
/**
* number of pages in this pageAddress.
* @return number of pages in this pageAddress.
*/
int getPageNum();
}