public class FilePageStore extends Object implements PageStore
Actual read and write operations are performed with FileIO
abstract 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 FilePageStoreManager
for regular cache operations like assignment
of new partition to the local node or checkpoint event and by IgniteSnapshotManager
during snapshot creation.
Modifier and Type | Field and Description |
---|---|
protected DataStorageConfiguration |
dbCfg
Database configuration.
|
protected FileIO |
fileIO
I/O interface for read/write operations with file
|
static int |
HEADER_SIZE
Allocated field offset.
|
protected int |
pageSize |
static int |
VERSION
File version.
|
Constructor and Description |
---|
FilePageStore(byte type,
IgniteOutClosure<Path> pathProvider,
FileIOFactory factory,
DataStorageConfiguration cfg,
LongConsumer allocatedTracker) |
Modifier and Type | Method and Description |
---|---|
void |
addWriteListener(PageWriteListener lsnr) |
long |
allocatePage()
Allocates next page index.
|
void |
beginRecover()
Starts recover process.
|
void |
close() |
void |
ensure() |
boolean |
exists()
Checks if page exists.
|
void |
finishRecover()
Ends recover process.
|
int |
getBlockSize() |
String |
getFileAbsolutePath() |
int |
getPageSize() |
long |
getSparseSize() |
ByteBuffer |
header(byte type,
int pageSize)
Creates header for current version file store.
|
int |
headerSize()
Size of page store header.
|
void |
init() |
long |
pageOffset(long pageId)
Gets page offset within the store file.
|
int |
pages()
Gets number of allocated pages.
|
void |
punchHole(long pageId,
int usefulBytes)
Should free all the extra storage space after the given number of useful bytes in the given page.
|
boolean |
read(long pageId,
ByteBuffer pageBuf,
boolean keepCrc)
Reads a page.
|
void |
readHeader(ByteBuffer buf)
Reads a header.
|
void |
removeWriteListener(PageWriteListener lsnr) |
long |
size() |
void |
stop(boolean delete) |
void |
sync()
Sync method used to ensure that the given pages are guaranteed to be written to the store.
|
void |
truncate(int tag)
Truncates and deletes partition file.
|
int |
version()
Page store version.
|
void |
write(long pageId,
ByteBuffer pageBuf,
int tag,
boolean calculateCrc)
Writes a page.
|
public static final int VERSION
public static final int HEADER_SIZE
protected final DataStorageConfiguration dbCfg
protected volatile FileIO fileIO
protected final int pageSize
public FilePageStore(byte type, IgniteOutClosure<Path> pathProvider, FileIOFactory factory, DataStorageConfiguration cfg, LongConsumer allocatedTracker)
public void addWriteListener(PageWriteListener lsnr)
addWriteListener
in interface PageStore
lsnr
- Page write listener to set.public void removeWriteListener(PageWriteListener lsnr)
removeWriteListener
in interface PageStore
lsnr
- Page write listener to remove.public int getPageSize()
getPageSize
in interface PageStore
public int getBlockSize()
getBlockSize
in interface PageStore
public long size()
size
in interface PageStore
PageStore.pages()
* PageStore.getPageSize()
due to delayed writes or due to other implementation specific details.public long getSparseSize()
getSparseSize
in interface PageStore
PageStore.size()
.PageStore.punchHole(long, int)
public void punchHole(long pageId, int usefulBytes)
public boolean exists()
public int headerSize()
public int version()
public ByteBuffer header(byte type, int pageSize)
type
- Type.pageSize
- Page size.public void stop(boolean delete) throws StorageException
stop
in interface PageStore
delete
- True
to delete file.StorageException
- If failed.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public void truncate(int tag) throws StorageException
truncate
in interface PageStore
tag
- New partition tag.StorageException
- If failed.public void beginRecover()
beginRecover
in interface PageStore
public void finishRecover() throws StorageException
finishRecover
in interface PageStore
StorageException
- If failed.public boolean read(long pageId, ByteBuffer pageBuf, boolean keepCrc) throws IgniteCheckedException
read
in interface PageStore
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 keepCrctrue
if page has been read successfully, false
if page hasn't been written yet.IgniteCheckedException
- If reading failed (IO error occurred).public void readHeader(ByteBuffer buf) throws IgniteCheckedException
readHeader
in interface PageStore
buf
- Buffer to write to.IgniteCheckedException
- If failed.public void init() throws StorageException
StorageException
- If failed to initialize store file.public void write(long pageId, ByteBuffer pageBuf, int tag, boolean calculateCrc) throws IgniteCheckedException
write
in interface PageStore
pageId
- Page ID.pageBuf
- Page buffer to write.tag
- Partition file version, 1-based incrementing counter. For outdated pages tag
has lower value,
and write does nothing.calculateCrc
- if False
crc calculation will be forcibly skipped.IgniteCheckedException
- If page writing failed (IO error occurred).public long pageOffset(long pageId)
pageOffset
in interface PageStore
pageId
- Page ID.public void sync() throws StorageException
sync
in interface PageStore
StorageException
public void ensure() throws IgniteCheckedException
ensure
in interface PageStore
IgniteCheckedException
- If sync failed (IO error occurred).public long allocatePage() throws IgniteCheckedException
allocatePage
in interface PageStore
IgniteCheckedException
- If failed to allocate.public String getFileAbsolutePath()
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.10.0 Release Date : March 10 2021