public class PageMemoryImpl extends Object implements PageMemoryEx
+--------+------------------------------------------------------+ |8 bytes | PAGE_SIZE + PAGE_OVERHEAD - 8 bytes | +--------+------------------------------------------------------+ |Next ptr| Page data | +--------+------------------------------------------------------+When page is allocated and is in use:
+------------------+--------+--------+----+----+--------+--------+----------------------+ | 8 bytes |8 bytes |8 bytes |4 b |4 b |8 bytes |8 bytes | PAGE_SIZE | +------------------+--------+--------+----+----+--------+--------+----------------------+ | Marker/Timestamp |Rel ptr |Page ID |C ID|PIN | LOCK |TMP BUF | Page data | +------------------+--------+--------+----+----+--------+--------+----------------------+Note that first 8 bytes of page header are used either for page marker or for next relative pointer depending on whether the page is in use or not.
Modifier and Type | Class and Description |
---|---|
static class |
PageMemoryImpl.ThrottlingPolicy
Throttling enabled and its type enum.
|
Modifier and Type | Field and Description |
---|---|
static String |
CHECKPOINT_POOL_OVERFLOW_ERROR_MSG
Checkpoint pool overflow error message.
|
static boolean |
DFLT_DELAYED_REPLACED_PAGE_WRITE |
static boolean |
DFLT_LOADED_PAGES_BACKWARD_SHIFT_MAP |
static long |
INVALID_REL_PTR
Invalid relative pointer value.
|
static int |
PAGE_LOCK_OFFSET
Page lock offset.
|
static int |
PAGE_OVERHEAD
8b Marker/timestamp
8b Relative pointer
8b Page ID
4b Cache group ID
4b Pin count
8b Lock
8b Temporary buffer
|
static int |
RANDOM_PAGES_EVICT_NUM
Number of random pages that will be picked for eviction.
|
static long |
RELATIVE_PTR_MASK
Full relative pointer mask.
|
static int |
TRY_AGAIN_TAG
Try again tag.
|
FLAG_AUX, FLAG_DATA, FLAG_IDX, INDEX_PARTITION, MAX_PARTITION_ID, META_PAGE_ID, METASTORE_PARTITION, OLD_METASTORE_PARTITION
Constructor and Description |
---|
PageMemoryImpl(DirectMemoryProvider directMemoryProvider,
long[] sizes,
GridCacheSharedContext<?,?> ctx,
PageReadWriteManager pmPageMgr,
int pageSize,
PageStoreWriter flushDirtyPage,
@Nullable GridInClosure3X<Long,FullPageId,PageMemoryEx> changeTracker,
CheckpointLockStateChecker stateChecker,
DataRegionMetricsImpl memMetrics,
@Nullable PageMemoryImpl.ThrottlingPolicy throttlingPlc,
IgniteOutClosure<CheckpointProgress> cpProgressProvider) |
Modifier and Type | Method and Description |
---|---|
long |
acquiredPages() |
long |
acquirePage(int grpId,
long pageId)
Gets the page absolute pointer associated with the given page ID.
|
long |
acquirePage(int grpId,
long pageId,
AtomicBoolean pageAllocated) |
long |
acquirePage(int grpId,
long pageId,
IoStatisticsHolder statHolder)
Gets the page absolute pointer associated with the given page ID.
|
long |
acquirePage(int grpId,
long pageId,
IoStatisticsHolder statHolder,
boolean restore) |
int |
activePagesCount()
Gets the number of active pages across all segments.
|
long |
allocatePage(int grpId,
int partId,
byte flags)
Allocates a page from the space for the given partition ID and the given flags.
|
GridMultiCollectionWrapper<FullPageId> |
beginCheckpoint(IgniteInternalFuture allowToReplace)
Gets a collection of dirty page IDs since the last checkpoint.
|
int |
checkpointBufferPagesCount()
Number of pages used in checkpoint buffer.
|
int |
checkpointBufferPagesSize()
Number of used pages in checkpoint buffer.
|
void |
checkpointWritePage(FullPageId fullId,
ByteBuffer buf,
PageStoreWriter pageStoreWriter,
CheckpointMetricsTracker metricsTracker)
Prepare page for write during checkpoint.
|
IgniteInternalFuture<Void> |
clearAsync(LoadedPagesMap.KeyPredicate pred,
boolean cleanDirty)
Asynchronously clears pages satisfying the given predicate.
|
Collection<FullPageId> |
dirtyPages()
Gets a collection of all pages currently marked as dirty.
|
void |
finishCheckpoint()
Finishes checkpoint operation.
|
boolean |
freePage(int grpId,
long pageId)
The given page is free now.
|
boolean |
hasLoadedPage(FullPageId fullPageId) |
boolean |
hasTempCopy(long absPtr)
Checks if a page has temp copy buffer.
|
int |
invalidate(int grpId,
int partId)
Marks partition as invalid / outdated.
|
boolean |
isDirty(int grpId,
long pageId,
long page) |
long |
loadedPages() |
DataRegionMetricsImpl |
metrics() |
void |
onCacheGroupDestroyed(int grpId)
Clears internal metadata of destroyed cache group.
|
ByteBuffer |
pageBuffer(long pageAddr) |
PageReadWriteManager |
pageManager() |
int |
pageSize() |
long |
partitionMetaPageId(int grpId,
int partId)
Gets partition metadata page for specified grpId and partId.
|
FullPageId |
pullPageFromCpBuffer()
Get arbitrary page from cp buffer.
|
long |
readLock(int grpId,
long pageId,
long page) |
long |
readLock(long absPtr,
long pageId,
boolean force,
boolean touch) |
long |
readLockForce(int grpId,
long pageId,
long page)
Obtains read lock without checking page tag.
|
void |
readUnlock(int grpId,
long pageId,
long page)
Releases locked page.
|
int |
realPageSize(int grpId) |
void |
releasePage(int grpId,
long pageId,
long page) |
boolean |
safeToUpdate()
Heuristic method which allows a thread to check if it safe to start memory struture modifications
in regard with checkpointing.
|
static int |
segmentIndex(int grpId,
long pageId,
int segments) |
boolean |
shouldThrottle()
Calculates throttling condition.
|
void |
start()
Start page memory.
|
void |
stop(boolean deallocate)
Stop page memory.
|
int |
systemPageSize() |
long |
totalPages()
Total pages can be placed to memory.
|
long |
tryWriteLock(int grpId,
long pageId,
long page) |
long |
writeLock(int grpId,
long pageId,
long page) |
long |
writeLock(int grpId,
long pageId,
long page,
boolean restore) |
void |
writeUnlock(int grpId,
long pageId,
long page,
Boolean walPlc,
boolean dirtyFlag)
Releases locked page.
|
void |
writeUnlock(int grpId,
long pageId,
long page,
Boolean walPlc,
boolean dirtyFlag,
boolean restore) |
public static final long RELATIVE_PTR_MASK
public static final long INVALID_REL_PTR
public static final int PAGE_LOCK_OFFSET
public static final int PAGE_OVERHEAD
public static final int RANDOM_PAGES_EVICT_NUM
public static final int TRY_AGAIN_TAG
public static final boolean DFLT_DELAYED_REPLACED_PAGE_WRITE
public static final boolean DFLT_LOADED_PAGES_BACKWARD_SHIFT_MAP
public static final String CHECKPOINT_POOL_OVERFLOW_ERROR_MSG
public PageMemoryImpl(DirectMemoryProvider directMemoryProvider, long[] sizes, GridCacheSharedContext<?,?> ctx, PageReadWriteManager pmPageMgr, int pageSize, PageStoreWriter flushDirtyPage, @Nullable @Nullable GridInClosure3X<Long,FullPageId,PageMemoryEx> changeTracker, CheckpointLockStateChecker stateChecker, DataRegionMetricsImpl memMetrics, @Nullable @Nullable PageMemoryImpl.ThrottlingPolicy throttlingPlc, IgniteOutClosure<CheckpointProgress> cpProgressProvider)
directMemoryProvider
- Memory allocator to use.sizes
- segments sizes, last is checkpoint pool size.ctx
- Cache shared context.pmPageMgr
- Page store manager.pageSize
- Page size.flushDirtyPage
- write callback invoked when a dirty page is removed for replacement.changeTracker
- Callback invoked to track changes in pages.stateChecker
- Checkpoint lock state provider. Used to ensure lock is held by thread, which modify pages.memMetrics
- Memory metrics to track dirty pages count and page replace rate.throttlingPlc
- Write throttle enabled and its type. Null equal to none.cpProgressProvider
- checkpoint progress, base for throttling. Null disables throttling.public void start() throws IgniteException
start
in interface PageMemory
IgniteException
public void stop(boolean deallocate) throws IgniteException
stop
in interface PageMemory
deallocate
- True
to deallocate memory, false
to allow memory reuse on subsequent PageMemory.start()
IgniteException
public void releasePage(int grpId, long pageId, long page)
releasePage
in interface PageSupport
grpId
- Cache group ID.pageId
- Page ID to release.page
- Page pointer.public long readLock(int grpId, long pageId, long page)
readLock
in interface PageSupport
grpId
- Cache group ID.pageId
- Page ID.page
- Page pointer.public void readUnlock(int grpId, long pageId, long page)
readUnlock
in interface PageSupport
grpId
- Cache group ID.pageId
- Page ID.page
- Page pointer.public long writeLock(int grpId, long pageId, long page)
writeLock
in interface PageSupport
grpId
- Cache group ID.pageId
- Page ID.page
- Page pointer.0L
if attempt to take the write lock failed.public long writeLock(int grpId, long pageId, long page, boolean restore)
writeLock
in interface PageMemoryEx
grpId
- Group ID.pageId
- Page ID.page
- Page pointer.restore
- Determines if the page is locked for restore memory (crash recovery).public long tryWriteLock(int grpId, long pageId, long page)
tryWriteLock
in interface PageSupport
grpId
- Cache group ID.pageId
- Page ID.page
- Page pointer.0L
if attempt to take the write lock failed.public void writeUnlock(int grpId, long pageId, long page, Boolean walPlc, boolean dirtyFlag)
writeUnlock
in interface PageSupport
grpId
- Cache group ID.pageId
- Page ID.page
- Page pointer.walPlc
- True
if page should be recorded to WAL, false
if the page must not
be recorded and null
for the default behavior.dirtyFlag
- Determines whether the page was modified since the last checkpoint.public void writeUnlock(int grpId, long pageId, long page, Boolean walPlc, boolean dirtyFlag, boolean restore)
writeUnlock
in interface PageMemoryEx
grpId
- Group ID.pageId
- Page ID.page
- Page pointer.walPlc
- True
if page should be recorded to WAL, false
if the page must not
be recorded and null
for the default behavior.dirtyFlag
- Determines whether the page was modified since the last checkpoint.restore
- Determines if the page is locked for restore.public boolean isDirty(int grpId, long pageId, long page)
isDirty
in interface PageSupport
grpId
- Cache group ID.pageId
- Page ID.page
- Page pointer.True
if the page is dirty.public long allocatePage(int grpId, int partId, byte flags) throws IgniteCheckedException
allocatePage
in interface PageIdAllocator
grpId
- Cache Group ID.partId
- Partition ID.IgniteCheckedException
public ByteBuffer pageBuffer(long pageAddr)
pageBuffer
in interface PageMemory
pageAddr
- Page address.public boolean freePage(int grpId, long pageId)
freePage
in interface PageIdAllocator
grpId
- Cache Group ID.pageId
- Page ID.public long partitionMetaPageId(int grpId, int partId)
partitionMetaPageId
in interface PageMemoryEx
grpId
- Group ID.partId
- Partition ID.public long acquirePage(int grpId, long pageId) throws IgniteCheckedException
PageSupport.releasePage(int, long, long)
. This method will allocate page with given ID if it doesn't
exist.acquirePage
in interface PageSupport
grpId
- Cache group ID.pageId
- Page ID.IgniteCheckedException
- If failed.public long acquirePage(int grpId, long pageId, IoStatisticsHolder statHolder) throws IgniteCheckedException
PageSupport.releasePage(int, long, long)
. This method will allocate page with given ID if it
doesn't exist.acquirePage
in interface PageSupport
grpId
- Cache group ID.pageId
- Page ID.statHolder
- Statistics holder to track IO operations.IgniteCheckedException
- If failed.public long acquirePage(int grpId, long pageId, AtomicBoolean pageAllocated) throws IgniteCheckedException
acquirePage
in interface PageMemoryEx
grpId
- Cache group ID.pageId
- Page ID.pageAllocated
- Flag is set if new page was allocated in offheap memory.IgniteCheckedException
Sets additional flag indicating that page was not found in memory and had to be allocated.
public long acquirePage(int grpId, long pageId, IoStatisticsHolder statHolder, boolean restore) throws IgniteCheckedException
acquirePage
in interface PageMemoryEx
grpId
- Cache group ID.pageId
- Page id.restore
- Get page for restoreIgniteCheckedException
- If failed.StorageException
- If page reading failed from storage.Will read page from file if it is not present in memory
public int pageSize()
pageSize
in interface PageMemory
public int systemPageSize()
systemPageSize
in interface PageMemory
public int realPageSize(int grpId)
realPageSize
in interface PageMemory
grpId
- Group id.public boolean safeToUpdate()
safeToUpdate
in interface PageMemoryEx
False
if there are too many dirty pages and a thread should wait for a
checkpoint to begin.public long totalPages()
PageMemoryEx
totalPages
in interface PageMemoryEx
public GridMultiCollectionWrapper<FullPageId> beginCheckpoint(IgniteInternalFuture allowToReplace) throws IgniteException
beginCheckpoint
in interface PageMemoryEx
allowToReplace
- The sign which allows to replace pages from a checkpoint by page replacer.IgniteException
- If checkpoint has been already started and was not finished.public void finishCheckpoint()
finishCheckpoint
in interface PageMemoryEx
public PageReadWriteManager pageManager()
pageManager
in interface PageMemoryEx
public void checkpointWritePage(FullPageId fullId, ByteBuffer buf, PageStoreWriter pageStoreWriter, CheckpointMetricsTracker metricsTracker) throws IgniteCheckedException
PageStoreWriter
will be called when the page will be ready to write.checkpointWritePage
in interface PageMemoryEx
fullId
- Page ID to get byte buffer for. The page ID must be present in the collection returned by
the PageMemoryEx.beginCheckpoint(IgniteInternalFuture)
method call.buf
- Temporary buffer to write changes into.pageStoreWriter
- Checkpoint page write context.metricsTracker
- Checkpoint metrics tracker.IgniteCheckedException
- If failed to obtain page data.public int invalidate(int grpId, int partId)
invalidate
in interface PageMemoryEx
grpId
- Group ID.partId
- Partition ID.public void onCacheGroupDestroyed(int grpId)
onCacheGroupDestroyed
in interface PageMemoryEx
grpId
- Cache group ID.public IgniteInternalFuture<Void> clearAsync(LoadedPagesMap.KeyPredicate pred, boolean cleanDirty)
clearAsync
in interface PageMemoryEx
pred
- Predicate for cache group id, pageId.cleanDirty
- Flag indicating that dirty pages collection should be cleaned.public long loadedPages()
loadedPages
in interface PageMemory
public long acquiredPages()
public boolean hasLoadedPage(FullPageId fullPageId)
fullPageId
- Full page ID to check.true
if the page is contained in the loaded pages table, false
otherwise.public long readLock(long absPtr, long pageId, boolean force, boolean touch)
readLock
in interface PageMemoryEx
absPtr
- Absolute pointer to read lock.pageId
- Page ID.force
- Force flag.touch
- Update page timestamp.public long readLockForce(int grpId, long pageId, long page)
readLockForce
in interface PageSupport
grpId
- Cache group ID.pageId
- Page ID.page
- Page pointer.public boolean hasTempCopy(long absPtr)
absPtr
- Absolute pointer.True
if a page has temp buffer.public int activePagesCount()
public int checkpointBufferPagesCount()
checkpointBufferPagesCount
in interface PageMemory
public int checkpointBufferPagesSize()
public static int segmentIndex(int grpId, long pageId, int segments)
pageId
- Page ID.public DataRegionMetricsImpl metrics()
public boolean shouldThrottle()
shouldThrottle
in interface PageMemoryEx
public FullPageId pullPageFromCpBuffer()
pullPageFromCpBuffer
in interface PageMemoryEx
@TestOnly public Collection<FullPageId> dirtyPages()
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.10.0 Release Date : March 10 2021