org.apache.flink.runtime.state.gemini.engine.page.LogicalPageChain 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.snapshot.RegionSnapshot;
import org.apache.flink.runtime.state.gemini.engine.snapshot.SnapshotMetaFile;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* A chain of logical pages.
*/
@Internal
public interface LogicalPageChain {
/**
* Sets the page status to the given target page status
* if the current page status equals the expected page status or the expected page status is null.
*
* @param expectedStatus the expected page status
* @param targetStatus the target page status
* @return {@code true} if successful. False return indicates that
* the actual page status was not equal to the expected page status.
*/
boolean compareAndSetStatus(PageStatus expectedStatus, PageStatus targetStatus);
/**
* Returns current page status.
*
* @return current page status.
*/
PageStatus getPageStatus();
/**
* Add new page size to current overall page size.
*
* @param pageSize the new page size.
*/
void addPageSize(int pageSize);
/**
* Returns current overall page size.
*
* @return current overall page size.
*/
int getPageSize();
/**
* Returns the number of sub-pages among the overall page address.
*
* @return the number of sub-pages among the overall page address.
*/
int getSubPageNum();
/**
* Returns the data size of sub-pages among the overall page address.
*
* @return the data size of sub-pages among the overall page address.
*/
int getSubPageSize();
/**
* Get page address at given chain index.
*
* @param chainIndex the location of index where page address locates, starts from 0.
* @return pageAddress.
*/
PageAddress getPageAddress(int chainIndex);
/**
* create page or add delta page, will increase page chain.
*
* @return logic page chain index.
*/
PageAddress createPage(DataPage dataPage);
/**
* insert a existed page.
*
* @param pageAddress existed page.
* @return logic page chain index.
*/
int insertPage(PageAddress pageAddress);
/**
* Returns the current chain index of logic page, the current chain index should not larger than {@link #getPageChainCapacity()} - 1.
*
* The chain index starts from 0 and -1 means no page.
*
* @return current chain index of logic page.
*/
int getCurrentPageChainIndex();
/**
* Returns current capacity of most page address could exist.
*
* @return current capacity of most page address could exist.
*/
int getPageChainCapacity();
/**
* Copy all page address with their data pages in this logical chained page to the given map and return a new page chain.
*
*
Currently, we would "duplicate" the data page as map values to offer flexibility
* in case we could let page address mutable during snapshot.
*
* @param copiedDataPage A data page container, all data pages will be added into this container.
* @return The copied logical chained page.
*/
LogicalPageChain copy(Map copiedDataPage);
/**
* Returns the iterator of non-null page address of this chained page.
*
* @return the iterator of non-null page address of this chained page.
*/
Iterator pageIterator();
/**
* Snapshot page address and file meta information into the region snapshot.
*
* The target region snapshot size might be two due to we need to update both local and dfs snapshots.
*
*
NOTE: Implementation of this method must be careful that the snapshot phase must be executed
* at the same time to avoid the page address changed.
*/
void snapshot(Collection regionSnapshots) throws IOException;
/**
* Restore page address with the snapshot meta file reader and track the stats within pageStoreStats.
*
* @param reader The snapshot meta file reader
* @param pageStoreStats The page store stats to track
* @throws IOException thrown if reader come across IOException.
*/
void restore(SnapshotMetaFile.Reader reader, PageStoreStats pageStoreStats) throws IOException;
/**
* Get all DataPage with reference counted. Mainly used for reference count management.
* @return the all Data Page with reference counted.
*/
Set getAllDataPageReferenced();
}