java.lang.Object
org.apache.ignite.internal.DataStructure
org.apache.ignite.internal.persistence.freelist.PagesList
All Implemented Interfaces:
MetaStorage
Direct Known Subclasses:
FreeListImpl, ReuseListImpl

public abstract class PagesList extends org.apache.ignite.internal.DataStructure implements MetaStorage
Striped doubly-linked list of page IDs optionally organized in buckets.
  • Field Details

    • bucketsSize

      protected final AtomicLongArray bucketsSize
    • changed

      protected volatile boolean changed
    • pageCacheChanged

      protected volatile boolean pageCacheChanged
      Page cache changed.
    • name

      protected final String name
      Name (for debug purposes).
    • log

      protected final IgniteLogger log
      Logger.
  • Constructor Details

    • PagesList

      protected PagesList(int cacheId, String name, PageMemory pageMem, int buckets, int pageSize, WalManager wal, org.apache.ignite.internal.PageAccessHelper pageHandler, long metaPageId, PageLockListener lockLsnr, IgniteLogger log, byte pageFlag)
      Parameters:
      cacheId - Cache ID.
      name - Name (for debug purpose).
      pageMem - Page memory.
      buckets - Number of buckets.
      pageSize - Page size.
      wal - Write ahead log manager.
      pageHandler - Page access helper.
      metaPageId - Metadata page ID.
      lockLsnr - Page lock listener.
      log - Log.
      pageFlag - Default flag value for allocated pages.
  • Method Details

    • init

      protected final void init(long metaPageId, boolean initNew) throws IgniteCheckedException
      Parameters:
      metaPageId - Metadata page ID.
      initNew - True if new list if created, false if should be initialized from metadata.
      Throws:
      IgniteCheckedException - If failed.
    • saveMetadata

      public void saveMetadata(IoStatisticsHolder statHolder) throws IgniteCheckedException
      Save metadata without exclusive lock on it.
      Specified by:
      saveMetadata in interface MetaStorage
      Throws:
      IgniteCheckedException - If failed.
    • getBucketIndex

      protected abstract int getBucketIndex(int freeSpace)
      Gets bucket index by page freespace.
      Returns:
      Bucket index or -1 if page doesn't belong to any bucket.
    • getBucket

      protected abstract PagesList.Stripe[] getBucket(int bucket)
      Parameters:
      bucket - Bucket index.
      Returns:
      Bucket.
    • casBucket

      protected abstract boolean casBucket(int bucket, PagesList.Stripe[] exp, PagesList.Stripe[] upd)
      Parameters:
      bucket - Bucket index.
      exp - Expected bucket.
      upd - Updated bucket.
      Returns:
      true If succeeded.
    • isReuseBucket

      protected abstract boolean isReuseBucket(int bucket)
      Parameters:
      bucket - Bucket index.
      Returns:
      true If it is a reuse bucket.
    • getBucketCache

      protected abstract PagesList.PagesCache getBucketCache(int bucket, boolean create)
      Parameters:
      bucket - Bucket index.
      Returns:
      Bucket cache.
    • storedPagesCount

      protected final long storedPagesCount(int bucket) throws IgniteCheckedException
      !!! For tests only, does not provide any correctness guarantees for concurrent access.
      Parameters:
      bucket - Bucket index.
      Returns:
      Number of pages stored in this list.
      Throws:
      IgniteCheckedException - If failed.
    • put

      protected final void put(ReuseBag bag, long dataId, long dataPage, long dataAddr, int bucket, IoStatisticsHolder statHolder) throws IgniteCheckedException
      Parameters:
      bag - Reuse bag.
      dataId - Data page ID.
      dataPage - Data page pointer.
      dataAddr - Data page address.
      bucket - Bucket.
      statHolder - Statistics holder to track IO operations.
      Throws:
      IgniteCheckedException - If failed.
    • takeEmptyPage

      protected long takeEmptyPage(int bucket, IOVersions initIoVers, IoStatisticsHolder statHolder) throws IgniteCheckedException
      Parameters:
      bucket - Bucket index.
      initIoVers - Optional IO to initialize page.
      statHolder - Statistics holder to track IO operations.
      Returns:
      Removed page ID.
      Throws:
      IgniteCheckedException - If failed.
    • initRecycledPage0

      protected long initRecycledPage0(long pageId, byte flag, PageIO initIO) throws IgniteCheckedException
      Create new page id and update page content accordingly if it's necessary.
      Parameters:
      pageId - Id of the recycled page from reuse bucket.
      flag - New flag for the page.
      Returns:
      New page id.
      Throws:
      IgniteCheckedException - If failed.
      See Also:
      • PagesList#initReusedPage(long, long, long, int, byte, PageIO)
    • initReusedPage

      protected final long initReusedPage(long reusedPageId, long reusedPage, long reusedPageAddr, byte flag, PageIO initIo) throws IgniteCheckedException
      Reused page must obtain correctly assembled page id, then initialized by proper PageIO instance and non-zero itemId of reused page id must be saved into special place.
      Parameters:
      reusedPageId - Reused page id.
      reusedPage - Reused page.
      reusedPageAddr - Reused page address.
      partId - Partition id.
      flag - Flag.
      initIo - Initial io.
      Returns:
      Prepared page id.
      Throws:
      IgniteCheckedException - In case of failure.
    • removeDataPage

      protected final boolean removeDataPage(long dataId, long dataPage, long dataAddr, AbstractDataPageIO dataIO, int bucket, IoStatisticsHolder statHolder) throws IgniteCheckedException
      Removes data page from bucket, merges bucket list if needed.
      Parameters:
      dataId - Data page ID.
      dataPage - Data page pointer.
      dataAddr - Data page address.
      dataIO - Data page IO.
      bucket - Bucket index.
      statHolder - Statistics holder to track IO operations.
      Returns:
      True if page was removed.
      Throws:
      IgniteCheckedException - If failed.
    • name

      public String name()
      Pages list name.
    • bucketsCount

      public int bucketsCount()
      Buckets count.
    • bucketSize

      public long bucketSize(int bucket)
      Bucket size.
      Parameters:
      bucket - Bucket.
    • stripesCount

      public int stripesCount(int bucket)
      Stripes count.
      Parameters:
      bucket - Bucket.
    • cachedPagesCount

      public int cachedPagesCount(int bucket)
      Cached pages count.
      Parameters:
      bucket - Bucket.
    • corruptedFreeListException

      protected CorruptedFreeListException corruptedFreeListException(Throwable err, long... pageIds)
      Parameters:
      err - Error that caused this exception.
      pageIds - Ids of possibly corrupted pages.
      Returns:
      Exception of type CorruptedFreeListException that wraps original error and ids of possibly corrupted pages.
    • corruptedFreeListException

      protected CorruptedFreeListException corruptedFreeListException(String msg, long... pageIds)
      Parameters:
      msg - Exception message.
      pageIds - Ids of possibly corrupted pages.
      Returns:
      Exception of type CorruptedFreeListException that wraps original error and ids of possibly corrupted pages.
    • corruptedFreeListException

      protected CorruptedFreeListException corruptedFreeListException(String msg, Throwable err, long... pageIds)
      Parameters:
      msg - Exception message.
      err - Error that caused this exception.
      pageIds - Ids of possibly corrupted pages.
      Returns:
      Exception of type CorruptedFreeListException that wraps original error and ids of possibly corrupted pages.