Class FilePageStore
- java.lang.Object
-
- org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore
-
- All Implemented Interfaces:
Closeable,AutoCloseable,PageStore
- Direct Known Subclasses:
FilePageStoreV2
public class FilePageStore extends Object implements PageStore
FilePageStore is a PageStore implementation that uses regular files to store pages.Actual read and write operations are performed with
FileIOabstract interface, list of its implementations is a good source of information about functionality in Ignite Native Persistence.On a physical level each instance of FilePageStore corresponds to a partition file assigned to the local node or to index file of a particular cache if any secondary indexes were created.
Instances of FilePageStore are managed by
FilePageStoreManagerfor regular cache operations like assignment of new partition to the local node or checkpoint event and byIgniteSnapshotManagerduring snapshot creation.
-
-
Field Summary
Fields Modifier and Type Field Description protected FileIOfileIOI/O interface for read/write operations with filestatic intHEADER_SIZEAllocated field offset.protected intpageSizestatic intVERSIONFile version.
-
Constructor Summary
Constructors Constructor Description FilePageStore(byte type, IgniteOutClosure<Path> pathProvider, FileIOFactory factory, int pageSize, LongConsumer allocatedTracker)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddWriteListener(PageWriteListener lsnr)longallocatePage()Allocates next page index.voidbeginRecover()Starts recover process.voidclose()voidensure()booleanexists()Checks if page exists.voidfinishRecover()Ends recover process.intgetBlockSize()StringgetFileAbsolutePath()intgetPageSize()longgetSparseSize()ByteBufferheader(byte type, int pageSize)Creates header for current version file store.intheaderSize()Size of page store header.voidinit()longpageOffset(long pageId)Gets page offset within the store file.intpages()Gets number of allocated pages.voidpunchHole(long pageId, int usefulBytes)Should free all the extra storage space after the given number of useful bytes in the given page.booleanread(long pageId, ByteBuffer pageBuf, boolean keepCrc)Reads a page.booleanread(long pageId, ByteBuffer pageBuf, boolean checkCrc, boolean keepCrc)voidreadHeader(ByteBuffer buf)Reads a header.voidremoveWriteListener(PageWriteListener lsnr)longsize()voidstop(boolean delete)voidsync()Sync method used to ensure that the given pages are guaranteed to be written to the store.voidtruncate(int tag)Truncates and deletes partition file.intversion()Page store version.voidwrite(long pageId, ByteBuffer pageBuf, int tag, boolean calculateCrc)Writes a page.
-
-
-
Field Detail
-
VERSION
public static final int VERSION
File version.- See Also:
- Constant Field Values
-
HEADER_SIZE
public static final int HEADER_SIZE
Allocated field offset.- See Also:
- Constant Field Values
-
fileIO
protected volatile FileIO fileIO
I/O interface for read/write operations with file
-
pageSize
protected final int pageSize
-
-
Constructor Detail
-
FilePageStore
public FilePageStore(byte type, IgniteOutClosure<Path> pathProvider, FileIOFactory factory, int pageSize, LongConsumer allocatedTracker)- Parameters:
type- Type of stored pages.pathProvider- Store path.factory- Factory producing an IO accessor.pageSize- Page size.allocatedTracker- Allocation tracker.
-
-
Method Detail
-
addWriteListener
public void addWriteListener(PageWriteListener lsnr)
- Specified by:
addWriteListenerin interfacePageStore- Parameters:
lsnr- Page write listener to set.
-
removeWriteListener
public void removeWriteListener(PageWriteListener lsnr)
- Specified by:
removeWriteListenerin interfacePageStore- Parameters:
lsnr- Page write listener to remove.
-
getPageSize
public int getPageSize()
- Specified by:
getPageSizein interfacePageStore- Returns:
- Page size in bytes.
-
getBlockSize
public int getBlockSize()
- Specified by:
getBlockSizein interfacePageStore- Returns:
- Storage block size or negative value if unknown or not supported.
-
size
public long size()
- Specified by:
sizein interfacePageStore- Returns:
- Size of the storage in bytes. May differ from
PageStore.pages()*PageStore.getPageSize()due to delayed writes or due to other implementation specific details.
-
getSparseSize
public long getSparseSize()
- Specified by:
getSparseSizein interfacePageStore- Returns:
- Size of the storage adjusted for sparsity in bytes or negative
value if not supported. Should be less than or equal to
PageStore.size(). - See Also:
PageStore.punchHole(long, int)
-
punchHole
public void punchHole(long pageId, int usefulBytes)Should free all the extra storage space after the given number of useful bytes in the given page.
-
exists
public boolean exists()
Checks if page exists.
-
headerSize
public int headerSize()
Size of page store header.
-
version
public int version()
Page store version.
-
header
public ByteBuffer header(byte type, int pageSize)
Creates header for current version file store. Doesn't init the store.- Parameters:
type- Type.pageSize- Page size.- Returns:
- Byte buffer instance.
-
stop
public void stop(boolean delete) throws StorageException- Specified by:
stopin interfacePageStore- Parameters:
delete-Trueto delete file.- Throws:
StorageException- If failed.
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
truncate
public void truncate(int tag) throws StorageExceptionTruncates and deletes partition file.- Specified by:
truncatein interfacePageStore- Parameters:
tag- New partition tag.- Throws:
StorageException- If failed.
-
beginRecover
public void beginRecover()
Starts recover process.- Specified by:
beginRecoverin interfacePageStore
-
finishRecover
public void finishRecover() throws StorageExceptionEnds recover process.- Specified by:
finishRecoverin interfacePageStore- Throws:
StorageException- If failed.
-
read
public boolean read(long pageId, ByteBuffer pageBuf, boolean keepCrc) throws IgniteCheckedExceptionReads a page.- Specified by:
readin interfacePageStore- Parameters:
pageId- Page ID.pageBuf- Page buffer to read into.keepCrc- by default reading zeroes CRC which was on file, but you can keep it in pageBuf if set keepCrc- Returns:
trueif page has been read successfully,falseif page hasn't been written yet.- Throws:
IgniteCheckedException- If reading failed (IO error occurred).
-
read
public boolean read(long pageId, ByteBuffer pageBuf, boolean checkCrc, boolean keepCrc) throws IgniteCheckedException- Parameters:
pageId- Page ID.pageBuf- Page buffer to read into.checkCrc- Check CRC on page.keepCrc- By default reading zeroes CRC which was on file, but you can keep it in pageBuf if set keepCrc- Returns:
trueif page has been read successfully,falseif page hasn't been written yet.- Throws:
IgniteCheckedException- If reading failed (IO error occurred).
-
readHeader
public void readHeader(ByteBuffer buf) throws IgniteCheckedException
Reads a header.- Specified by:
readHeaderin interfacePageStore- Parameters:
buf- Buffer to write to.- Throws:
IgniteCheckedException- If failed.
-
init
public void init() throws StorageException- Throws:
StorageException- If failed to initialize store file.
-
write
public void write(long pageId, ByteBuffer pageBuf, int tag, boolean calculateCrc) throws IgniteCheckedExceptionWrites a page.- Specified by:
writein interfacePageStore- Parameters:
pageId- Page ID.pageBuf- Page buffer to write.tag- Partition file version, 1-based incrementing counter. For outdated pagestaghas lower value, and write does nothing.calculateCrc- ifFalsecrc calculation will be forcibly skipped.- Throws:
IgniteCheckedException- If page writing failed (IO error occurred).
-
pageOffset
public long pageOffset(long pageId)
Gets page offset within the store file.- Specified by:
pageOffsetin interfacePageStore- Parameters:
pageId- Page ID.- Returns:
- Page offset.
-
sync
public void sync() throws StorageExceptionSync method used to ensure that the given pages are guaranteed to be written to the store.- Specified by:
syncin interfacePageStore- Throws:
StorageException
-
ensure
public void ensure() throws IgniteCheckedException- Specified by:
ensurein interfacePageStore- Throws:
IgniteCheckedException- If sync failed (IO error occurred).
-
allocatePage
public long allocatePage() throws IgniteCheckedExceptionAllocates next page index.- Specified by:
allocatePagein interfacePageStore- Returns:
- Next page index.
- Throws:
IgniteCheckedException- If failed to allocate.
-
getFileAbsolutePath
public String getFileAbsolutePath()
- Returns:
- File absolute path.
-
-