Class SpilloverPageArray
java.lang.Object
org.cojen.tupl.io.PageArray
org.cojen.tupl.io.SpilloverPageArray
- All Implemented Interfaces:
Closeable, AutoCloseable, CauseCloseable
Combines
PageArrays together in a sequential fashion. This is useful for
supporting overflow capacity when the first array fills up. In an emergency when all drives
are full, a spillover page array can be defined such that the second array is a remote file,
or a non-durable file, or an anonymous MappedPageArray. With this configuration in place, delete non-essential entries and then
compact the database. After verifying that space
is available again, the original page array configuration can be swapped back in.-
Method Summary
Modifier and TypeMethodDescriptionvoidlongcopyPage(long srcIndex, long dstIndex) longcopyPageFromAddress(long srcAddr, long dstIndex) longdirectPageAddress(long index) final intReturns a positive page size if not using direct I/O, else negate to get the page size to allocate for direct I/O.longevictPage(long index, long bufAddr) Same as writePage, except that the given buffer might be altered and a replacement might be returned.voidexpandPageCount(long count) Attempt to expand the total count of pages.factory(Supplier<? extends PageArray> first, long spilloverIndex, Supplier<? extends PageArray> second) booleanisClosed()booleanisEmpty()booleanbooleanstatic PageArraylongReturns the total count of pages in the array, or Long.MAX_VALUE if not applicable.longReturn maximum allowed page count, or -1 if not applicable.voidreadPage(long index, long dstAddr, int offset, int length) voidsync(boolean metadata) Durably flushes all writes to the underlying device.voidsyncPage(long index) Durably flushes the page at the given index, but implementation might flush more pages.voidtruncatePageCount(long count) Attempt to truncate the total count of pages.voidwritePage(long index, long srcAddr, int offset) Writes a page, which is lazily flushed.
-
Method Details
-
factory
public static Supplier<PageArray> factory(Supplier<? extends PageArray> first, long spilloverIndex, Supplier<? extends PageArray> second) - Parameters:
first- source for all pages lower than the spillover indexspilloverIndex- index which separates the two sourcessecond- source for all pages at or higher than the spillover index- Throws:
IllegalArgumentException- if page sizes don't match or if spillover index isn't greater than 0IllegalStateException- if the highest index of the first source is higher than the spillover index
-
make
public static PageArray make(PageArray first, long spilloverIndex, PageArray second) throws IOException - Parameters:
first- source for all pages lower than the spillover indexspilloverIndex- index which separates the two sourcessecond- source for all pages at or higher than the spillover index- Throws:
IllegalArgumentException- if page sizes don't match or if spillover index isn't greater than 0IllegalStateException- if the highest index of the first source is higher than the spillover indexIOException
-
directPageSize
public final int directPageSize()Description copied from class:PageArrayReturns a positive page size if not using direct I/O, else negate to get the page size to allocate for direct I/O.- Overrides:
directPageSizein classPageArray
-
isReadOnly
public boolean isReadOnly()- Specified by:
isReadOnlyin classPageArray
-
isFullyMapped
public boolean isFullyMapped()- Overrides:
isFullyMappedin classPageArray
-
isEmpty
- Specified by:
isEmptyin classPageArray- Throws:
IOException
-
pageCount
Description copied from class:PageArrayReturns the total count of pages in the array, or Long.MAX_VALUE if not applicable.- Specified by:
pageCountin classPageArray- Throws:
IOException
-
truncatePageCount
Description copied from class:PageArrayAttempt to truncate the total count of pages. Array implementation might not support truncating the page count, in which case this method does nothing.- Specified by:
truncatePageCountin classPageArray- Throws:
IOException
-
expandPageCount
Description copied from class:PageArrayAttempt to expand the total count of pages. Array implementation might not support expanding the page count, in which case this method does nothing.- Specified by:
expandPageCountin classPageArray- Throws:
IOException
-
pageCountLimit
Description copied from class:PageArrayReturn maximum allowed page count, or -1 if not applicable.- Overrides:
pageCountLimitin classPageArray- Throws:
IOException
-
readPage
- Specified by:
readPagein classPageArray- Parameters:
index- zero-based page index to readdstAddr- receives read dataoffset- offset into data buffer- Throws:
IOException- if index is greater than or equal to page count
-
writePage
Description copied from class:PageArrayWrites a page, which is lazily flushed. The array grows automatically if the index is greater than or equal to the current page count. If array supports caching, page must be immediately copied into it.- Specified by:
writePagein classPageArray- Parameters:
index- zero-based page index to writesrcAddr- data to writeoffset- offset into data buffer- Throws:
IOException
-
evictPage
Description copied from class:PageArraySame as writePage, except that the given buffer might be altered and a replacement might be returned. Caller must not alter the original buffer if a replacement was provided, and the contents of the replacement are undefined.- Overrides:
evictPagein classPageArray- Parameters:
index- zero-based page index to writebufAddr- data to write; implementation might alter the contents- Returns:
- replacement buffer, or same instance if replacement was not performed
- Throws:
IOException
-
directPageAddress
- Overrides:
directPageAddressin classPageArray- Throws:
IOException
-
copyPage
- Overrides:
copyPagein classPageArray- Returns:
- direct pointer to destination
- Throws:
IOException
-
copyPageFromAddress
- Overrides:
copyPageFromAddressin classPageArray- Returns:
- direct pointer to destination
- Throws:
IOException
-
sync
Description copied from class:PageArrayDurably flushes all writes to the underlying device.- Specified by:
syncin classPageArray- Parameters:
metadata- pass true to flush all file metadata- Throws:
IOException
-
syncPage
Description copied from class:PageArrayDurably flushes the page at the given index, but implementation might flush more pages. File metadata is not flushed.- Overrides:
syncPagein classPageArray- Throws:
IOException
-
close
- Specified by:
closein interfaceCauseCloseable- Specified by:
closein classPageArray- Parameters:
cause- null if close is not caused by a failure- Throws:
IOException
-
isClosed
-