java.lang.Object
org.cojen.tupl.io.PageArray
org.cojen.tupl.io.JoinedPageArray
- All Implemented Interfaces:
Closeable
,AutoCloseable
,CauseCloseable
Joins
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 joined 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 TypeMethodDescriptionvoid
long
copyPage
(long srcIndex, long dstIndex) long
copyPageFromPointer
(long srcPointer, long dstIndex) long
directPagePointer
(long index) final int
Returns a positive page size if not using direct I/O, else negate to get the page size to allocate for direct I/O.byte[]
evictPage
(long index, byte[] buf) Same as writePage, except that the given buffer might be altered and a replacement might be returned.long
evictPage
(long index, long bufPtr) Same as writePage, except that the given buffer might be altered and a replacement might be returned.void
expandPageCount
(long count) Attempt to expand the total count of pages.boolean
isEmpty()
boolean
boolean
static PageArray
open()
Attempt to open or reopen the page array.long
Returns the total count of pages in the array, or Long.MAX_VALUE if not applicable.long
Return maximum allowed page count, or -1 if not applicable.void
readPage
(long index, byte[] dst, int offset, int length) void
readPage
(long index, long dstPtr, int offset, int length) void
sync
(boolean metadata) Durably flushes all writes to the underlying device.void
syncPage
(long index) Durably flushes the page at the given index, but implementation might flush more pages.void
truncatePageCount
(long count) Attempt to truncate the total count of pages.void
writePage
(long index, byte[] src, int offset) Writes a page, which is lazily flushed.void
writePage
(long index, long srcPtr, int offset) Writes a page, which is lazily flushed.
-
Method Details
-
join
- Parameters:
first
- array for all pages lower than the join indexjoinIndex
- join index which separates the two page arrayssecond
- array for all pages at or higher than the join index- Throws:
IllegalArgumentException
- if page sizes don't match or if join index isn't greater than 0IllegalStateException
- if the highest index of the first array is higher than the join indexIOException
-
directPageSize
public final int directPageSize()Description copied from class:PageArray
Returns a positive page size if not using direct I/O, else negate to get the page size to allocate for direct I/O.- Overrides:
directPageSize
in classPageArray
-
isReadOnly
public boolean isReadOnly()- Specified by:
isReadOnly
in classPageArray
-
isFullyMapped
public boolean isFullyMapped()- Overrides:
isFullyMapped
in classPageArray
-
isEmpty
- Specified by:
isEmpty
in classPageArray
- Throws:
IOException
-
pageCount
Description copied from class:PageArray
Returns the total count of pages in the array, or Long.MAX_VALUE if not applicable.- Specified by:
pageCount
in classPageArray
- Throws:
IOException
-
truncatePageCount
Description copied from class:PageArray
Attempt 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:
truncatePageCount
in classPageArray
- Throws:
IOException
-
expandPageCount
Description copied from class:PageArray
Attempt 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:
expandPageCount
in classPageArray
- Throws:
IOException
-
pageCountLimit
Description copied from class:PageArray
Return maximum allowed page count, or -1 if not applicable.- Overrides:
pageCountLimit
in classPageArray
- Throws:
IOException
-
readPage
- Specified by:
readPage
in classPageArray
- Parameters:
index
- zero-based page index to readdst
- receives read dataoffset
- offset into data buffer- Throws:
IOException
- if index is greater than or equal to page count
-
readPage
- Overrides:
readPage
in classPageArray
- Parameters:
index
- zero-based page index to readdstPtr
- receives read dataoffset
- offset into data buffer- Throws:
IOException
- if index is greater than or equal to page count
-
writePage
Description copied from class:PageArray
Writes 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:
writePage
in classPageArray
- Parameters:
index
- zero-based page index to writesrc
- data to writeoffset
- offset into data buffer- Throws:
IOException
-
writePage
Description copied from class:PageArray
Writes 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.- Overrides:
writePage
in classPageArray
- Parameters:
index
- zero-based page index to writesrcPtr
- data to writeoffset
- offset into data buffer- Throws:
IOException
-
evictPage
Description copied from class:PageArray
Same 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:
evictPage
in classPageArray
- Parameters:
index
- zero-based page index to writebuf
- data to write; implementation might alter the contents- Returns:
- replacement buffer, or same instance if replacement was not performed
- Throws:
IOException
-
evictPage
Description copied from class:PageArray
Same 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:
evictPage
in classPageArray
- Parameters:
index
- zero-based page index to writebufPtr
- data to write; implementation might alter the contents- Returns:
- replacement buffer, or same instance if replacement was not performed
- Throws:
IOException
-
directPagePointer
- Overrides:
directPagePointer
in classPageArray
- Throws:
IOException
-
copyPage
- Overrides:
copyPage
in classPageArray
- Returns:
- direct pointer to destination
- Throws:
IOException
-
copyPageFromPointer
- Overrides:
copyPageFromPointer
in classPageArray
- Returns:
- direct pointer to destination
- Throws:
IOException
-
sync
Description copied from class:PageArray
Durably flushes all writes to the underlying device.- Specified by:
sync
in classPageArray
- Parameters:
metadata
- pass true to flush all file metadata- Throws:
IOException
-
syncPage
Description copied from class:PageArray
Durably flushes the page at the given index, but implementation might flush more pages. File metadata is not flushed.- Overrides:
syncPage
in classPageArray
- Throws:
IOException
-
close
- Specified by:
close
in interfaceCauseCloseable
- Specified by:
close
in classPageArray
- Parameters:
cause
- null if close is not caused by a failure- Throws:
IOException
-
open
Description copied from class:PageArray
Attempt to open or reopen the page array.- Overrides:
open
in classPageArray
- Returns:
- existing or new page array
- Throws:
IOException
-