Interface Sorter
public interface Sorter
Utility for sorting and filling up new indexes.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(byte[] key, byte[] value) Add an entry into the sorter.default void
Add all remaining items from the given scanner into the sorter.void
addBatch
(byte[][] kvPairs, int offset, int size) Add a batch of entries into the sorter, which can be more efficient than adding each entry separately.finish()
Finish sorting the entries, and return a temporary index with the results.Returns a single-use Scanner over the sorted results, which deletes temporary resources as it goes.finishScan
(Scanner<Entry> s) Returns a single-use Scanner over the sorted results, which deletes temporary resources as it goes.Same asfinishScan
, but in reverse order.Same asfinishScan
, but in reverse order.long
progress()
Returns an approximate count of entries which have finished, which is only updated while sort results are being finished.void
reset()
Discards all the entries and frees up space in the database.
-
Method Details
-
add
Add an entry into the sorter. If multiple entries are added with matching keys, only the last one added is kept. After a sorter is fully finished or reset, no entries exist in the sorter, and new entries can be added for another sort.- Throws:
IllegalStateException
- if sort is finishing in another threadInterruptedIOException
- if reset by another threadIOException
-
addBatch
Add a batch of entries into the sorter, which can be more efficient than adding each entry separately. If multiple entries are added with matching keys, only the last one added is kept. After a sorter is fully finished or reset, no entries exist in the sorter, and new entries can be added for another sort.- Parameters:
kvPairs
- alternating key-value pairsoffset
- offset into key-value pair arraysize
- batch size (number of key-value pairs)- Throws:
IllegalStateException
- if sort is finishing in another threadInterruptedIOException
- if reset by another threadIOException
-
addAll
Add all remaining items from the given scanner into the sorter. If multiple entries are added with matching keys, only the last one added is kept. After a sorter is fully finished or reset, no entries exist in the sorter, and new entries can be added for another sort.- Throws:
IllegalStateException
- if sort is finishing in another threadInterruptedIOException
- if reset by another threadIOException
-
finish
Finish sorting the entries, and return a temporary index with the results.- Throws:
IllegalStateException
- if sort is finishing in another threadInterruptedIOException
- if reset by another threadIOException
- See Also:
-
finishScan
Returns a single-use Scanner over the sorted results, which deletes temporary resources as it goes. Invoking this method causes the sort to be asynchronously finished, and the Scanner might block waiting for entries to become available. Closing the Scanner before the sort is finished interrupts it.- Throws:
IllegalStateException
- if sort is finishing in another threadInterruptedIOException
- if reset by another threadIOException
-
finishScan
Returns a single-use Scanner over the sorted results, which deletes temporary resources as it goes. Invoking this method causes the sort to be asynchronously finished, and the Scanner might block waiting for entries to become available. Closing the Scanner before the sort is finished interrupts it.- Parameters:
s
- source of additional entries to add to the sorter before finishing- Throws:
IllegalStateException
- if sort is finishing in another threadInterruptedIOException
- if reset by another threadIOException
-
finishScanReverse
Same asfinishScan
, but in reverse order.- Throws:
IllegalStateException
- if sort is finishing in another threadInterruptedIOException
- if reset by another threadIOException
-
finishScanReverse
Same asfinishScan
, but in reverse order.- Parameters:
s
- source of additional entries to add to the sorter before finishing- Throws:
IllegalStateException
- if sort is finishing in another threadInterruptedIOException
- if reset by another threadIOException
-
progress
long progress()Returns an approximate count of entries which have finished, which is only updated while sort results are being finished. -
reset
Discards all the entries and frees up space in the database. Can be called to interrupt any sort which is in progress.- Throws:
IOException
-