java.lang.Object
org.apache.ignite.internal.DataStructure
org.apache.ignite.internal.persistence.freelist.PagesList
org.apache.ignite.internal.persistence.freelist.FreeListImpl
All Implemented Interfaces:
FreeList, MetaStorage, ReuseList

public final class FreeListImpl extends PagesList implements FreeList, ReuseList
  • Constructor Details

    • FreeListImpl

      public FreeListImpl(int cacheId, String name, int pageSize, DataRegionMetrics memMetrics, PageMemory pageMemory, ReuseList reuseList, WalManager wal, org.apache.ignite.internal.PageAccessHelper pageHandler, long metaPageId, boolean initNew, PageLockListener lockLsnr, IgniteLogger log, AtomicLong pageListCacheLimit) throws IgniteCheckedException
      Parameters:
      cacheId - Cache ID.
      name - Name (for debug purpose).
      pageSize - Page size.
      memMetrics - Memory metrics.
      pageMemory - Page memory.
      reuseList - Reuse list or null if this free list will be a reuse list for itself.
      wal - Write ahead log manager.
      pageHandler - Page access helper.
      metaPageId - Metadata page ID.
      initNew - True if new metadata should be initialized.
      lockLsnr - Page lock listener.
      log - Log.
      pageListCacheLimit - Page list cache limit.
      Throws:
      IgniteCheckedException - If failed.
  • Method Details

    • freeSpace

      public long freeSpace()
      Calculates free space tracked by this FreeListImpl instance.
      Returns:
      Free space available for use, in bytes.
    • dumpStatistics

      public void dumpStatistics(IgniteLogger log)
      Specified by:
      dumpStatistics in interface FreeList
      Parameters:
      log - Logger.
    • getBucketIndex

      protected int getBucketIndex(int freeSpace)
      Gets bucket index by page freespace.
      Specified by:
      getBucketIndex in class PagesList
      Returns:
      Bucket index or -1 if page doesn't belong to any bucket.
    • insertDataRow

      public void insertDataRow(org.apache.ignite.internal.Storable row, IoStatisticsHolder statHolder) throws IgniteCheckedException
      Specified by:
      insertDataRow in interface FreeList
      Parameters:
      row - Row.
      statHolder - Statistics holder to track IO operations.
      Throws:
      IgniteCheckedException - If failed.
    • insertDataRows

      public void insertDataRows(Collection<? extends org.apache.ignite.internal.Storable> rows, IoStatisticsHolder statHolder) throws IgniteCheckedException
      Reduces the workload on the free list by writing multiple rows into a single memory page at once.

      Rows are sequentially added to the page as long as there is enough free space on it. If the row is large then those fragments that occupy the whole memory page are written to other pages, and the remainder is added to the current one.
      Specified by:
      insertDataRows in interface FreeList
      Parameters:
      rows - Rows.
      statHolder - Statistics holder to track IO operations.
      Throws:
      IgniteCheckedException - If failed.
    • updateDataRow

      public boolean updateDataRow(long link, org.apache.ignite.internal.Storable row, IoStatisticsHolder statHolder) throws IgniteCheckedException
      Specified by:
      updateDataRow in interface FreeList
      Parameters:
      link - Row link.
      row - New row data.
      statHolder - Statistics holder to track IO operations.
      Returns:
      True if was able to update row.
      Throws:
      IgniteCheckedException - If failed.
    • updateDataRow

      public <S, R> R updateDataRow(long link, org.apache.ignite.internal.PageHandler<S,R> pageHnd, S arg, IoStatisticsHolder statHolder) throws IgniteCheckedException
      Specified by:
      updateDataRow in interface FreeList
      Type Parameters:
      S - Argument type.
      R - Result type.
      Parameters:
      link - Row link.
      pageHnd - Page handler.
      arg - Handler argument.
      statHolder - Statistics holder to track IO operations.
      Returns:
      Result.
      Throws:
      IgniteCheckedException - If failed.
    • removeDataRowByLink

      public void removeDataRowByLink(long link, IoStatisticsHolder statHolder) throws IgniteCheckedException
      Specified by:
      removeDataRowByLink in interface FreeList
      Parameters:
      link - Row link.
      statHolder - Statistics holder to track IO operations.
      Throws:
      IgniteCheckedException - If failed.
    • getBucket

      protected PagesList.Stripe[] getBucket(int bucket)
      Specified by:
      getBucket in class PagesList
      Parameters:
      bucket - Bucket index.
      Returns:
      Bucket.
    • casBucket

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

      protected boolean isReuseBucket(int bucket)
      Specified by:
      isReuseBucket in class PagesList
      Parameters:
      bucket - Bucket index.
      Returns:
      true If it is a reuse bucket.
    • getBucketCache

      protected PagesList.PagesCache getBucketCache(int bucket, boolean create)
      Specified by:
      getBucketCache in class PagesList
      Parameters:
      bucket - Bucket index.
      Returns:
      Bucket cache.
    • emptyDataPages

      public int emptyDataPages()
      Returns:
      Number of empty data pages in free list.
    • addForRecycle

      public void addForRecycle(ReuseBag bag) throws IgniteCheckedException
      Specified by:
      addForRecycle in interface ReuseList
      Parameters:
      bag - Reuse bag.
      Throws:
      IgniteCheckedException - If failed.
    • takeRecycledPage

      public long takeRecycledPage() throws IgniteCheckedException
      Specified by:
      takeRecycledPage in interface ReuseList
      Returns:
      Page ID or 0 if none available.
      Throws:
      IgniteCheckedException - If failed.
    • initRecycledPage

      public long initRecycledPage(long pageId, byte flag, PageIO initIO) throws IgniteCheckedException
      Converts recycled page id back to a usable id. Might modify page content as well if flag is changing.
      Specified by:
      initRecycledPage in interface ReuseList
      Parameters:
      pageId - Id of the recycled page.
      flag - Flag value for the page. One of PageIdAllocator#FLAG_DATA, PageIdAllocator#FLAG_IDX or PageIdAllocator#FLAG_AUX.
      initIO - Page IO to reinit reused page.
      Returns:
      Updated page id.
      Throws:
      IgniteCheckedException - If failed.
    • recycledPagesCount

      public long recycledPagesCount() throws IgniteCheckedException
      Specified by:
      recycledPagesCount in interface ReuseList
      Returns:
      Number of recycled pages it contains.
      Throws:
      IgniteCheckedException - If failed.
    • toString

      public String toString()
      Overrides:
      toString in class Object