Class MappedPageFactoryImpl

  • All Implemented Interfaces:
    IMappedPageFactory

    public class MappedPageFactoryImpl
    extends Object
    implements IMappedPageFactory
    Mapped mapped page resource manager, responsible for the creation, cache, recycle of the mapped pages. automatic paging and swapping algorithm is leveraged to ensure fast page fetch while keep memory usage efficient at the same time.
    Author:
    bulldog
    • Constructor Detail

      • MappedPageFactoryImpl

        public MappedPageFactoryImpl​(int pageSize,
                                     String pageDir,
                                     long cacheTTL,
                                     Clock clock,
                                     FileFactory fileFactory)
      • MappedPageFactoryImpl

        public MappedPageFactoryImpl​(int pageSize,
                                     String pageDir,
                                     long cacheTTL)
    • Method Detail

      • acquirePage

        public IMappedPage acquirePage​(long index)
                                throws IOException
        Description copied from interface: IMappedPageFactory
        Acquire a mapped page with specific index from the factory
        Specified by:
        acquirePage in interface IMappedPageFactory
        Parameters:
        index - the index of the page
        Returns:
        a mapped page
        Throws:
        IOException - exception thrown if there was any IO error during the acquire operation
      • getPageSize

        public int getPageSize()
        Description copied from interface: IMappedPageFactory
        Current set page size, when creating pages, the factory will only create pages with this size.
        Specified by:
        getPageSize in interface IMappedPageFactory
        Returns:
        an integer number
      • releasePage

        public void releasePage​(long index)
        Description copied from interface: IMappedPageFactory
        Return the mapped page to the factory, calling thread release the page to inform the factory that it has finished with the page, so the factory get a chance to recycle the page to save memory.
        Specified by:
        releasePage in interface IMappedPageFactory
        Parameters:
        index - the index of the page
      • deletePage

        public void deletePage​(long index)
                        throws IOException
        thread unsafe, caller need synchronization
        Specified by:
        deletePage in interface IMappedPageFactory
        Parameters:
        index - the index of the page
        Throws:
        IOException - exception thrown if there was any IO error during the delete operation.
      • getPageIndexSetBefore

        public Set<Long> getPageIndexSetBefore​(long timestamp)
        Description copied from interface: IMappedPageFactory
        Get all indexes of pages with last modified timestamp before the specific timestamp.
        Specified by:
        getPageIndexSetBefore in interface IMappedPageFactory
        Parameters:
        timestamp - the timestamp to check
        Returns:
        a set of indexes
      • deletePagesBefore

        public void deletePagesBefore​(long timestamp)
                               throws IOException
        thread unsafe, caller need synchronization
        Specified by:
        deletePagesBefore in interface IMappedPageFactory
        Parameters:
        timestamp - the timestamp to check
        Throws:
        IOException - exception thrown if IO error occurs
      • deletePagesBeforePageIndex

        public void deletePagesBeforePageIndex​(long pageIndex)
                                        throws IOException
        Description copied from interface: IMappedPageFactory
        Delete all pages before the specific index
        Specified by:
        deletePagesBeforePageIndex in interface IMappedPageFactory
        Parameters:
        pageIndex - page file index to check
        Throws:
        IOException - exception thrown if there was any IO error during the delete operation.
      • getPageFileLastModifiedTime

        public long getPageFileLastModifiedTime​(long index)
        Description copied from interface: IMappedPageFactory
        Get last modified timestamp of page file index
        Specified by:
        getPageFileLastModifiedTime in interface IMappedPageFactory
        Parameters:
        index - page index
        Returns:
        last modified time
      • getFirstPageIndexBefore

        public long getFirstPageIndexBefore​(long timestamp)
        Description copied from interface: IMappedPageFactory
        Get index of a page file with last modified timestamp closest to specific timestamp.
        Specified by:
        getFirstPageIndexBefore in interface IMappedPageFactory
        Parameters:
        timestamp - the timestamp to check
        Returns:
        a page index
      • flush

        public void flush()
        thread unsafe, caller need synchronization
        Specified by:
        flush in interface IMappedPageFactory