Interface Sorter


public interface Sorter
Utility for sorting and filling up new indexes.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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 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.
    Returns a single-use Scanner over the sorted results, which deletes temporary resources as it goes.
    Same as finishScan, but in reverse order.
    Same as finishScan, but in reverse order.
    long
    Returns an approximate count of entries which have finished, which is only updated while sort results are being finished.
    void
    Discards all the entries and frees up space in the database.
  • Method Details

    • add

      void add(byte[] key, byte[] value) throws IOException
      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 thread
      InterruptedIOException - if reset by another thread
      IOException
    • addBatch

      void addBatch(byte[][] kvPairs, int offset, int size) throws IOException
      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 pairs
      offset - offset into key-value pair array
      size - batch size (number of key-value pairs)
      Throws:
      IllegalStateException - if sort is finishing in another thread
      InterruptedIOException - if reset by another thread
      IOException
    • addAll

      default void addAll(Scanner<Entry> s) throws IOException
      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 thread
      InterruptedIOException - if reset by another thread
      IOException
    • finish

      Index finish() throws IOException
      Finish sorting the entries, and return a temporary index with the results.
      Throws:
      IllegalStateException - if sort is finishing in another thread
      InterruptedIOException - if reset by another thread
      IOException
      See Also:
    • finishScan

      Scanner<Entry> finishScan() throws IOException
      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 thread
      InterruptedIOException - if reset by another thread
      IOException
    • finishScan

      Scanner<Entry> finishScan(Scanner<Entry> s) throws IOException
      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 thread
      InterruptedIOException - if reset by another thread
      IOException
    • finishScanReverse

      Scanner<Entry> finishScanReverse() throws IOException
      Same as finishScan, but in reverse order.
      Throws:
      IllegalStateException - if sort is finishing in another thread
      InterruptedIOException - if reset by another thread
      IOException
    • finishScanReverse

      Scanner<Entry> finishScanReverse(Scanner<Entry> s) throws IOException
      Same as finishScan, 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 thread
      InterruptedIOException - if reset by another thread
      IOException
    • progress

      long progress()
      Returns an approximate count of entries which have finished, which is only updated while sort results are being finished.
    • reset

      void reset() throws IOException
      Discards all the entries and frees up space in the database. Can be called to interrupt any sort which is in progress.
      Throws:
      IOException