DocumentCursor

An ordered walk over the documents a store holds, as one view of it sees them.

store.scan(from = Key.of("user:"), to = Key.of("user:~")).use { cursor ->
while (cursor.next()) println("${cursor.key} -> ${cursor.document.toJsonString()}")
}

One entry per key, newest first, tombstones skipped. Underneath, a key exists once per commit that touched it, spread across memtables and every level of the tree; the merge emits all of them in order and this collapses them. A deleted key produces nothing rather than an entry with no document, because a caller iterating documents should not have to know that deletions are stored.

A cursor is a view, not a copy. document reads straight out of a mapped segment, so the cursor holds the segments it is walking for as long as it is open — which is why it is AutoCloseable and why leaving one open holds disk space the way a Snapshot does. Both key and document are valid until the next next.

Not thread-safe: one cursor belongs to one thread. Any number of cursors may run at once.

Properties

Link copied to clipboard

The document the cursor is on. See key for when it is valid.

Link copied to clipboard
val key: Key

The key the cursor is on.

Functions

Link copied to clipboard
open override fun close()

Releases the segments this cursor was reading. Idempotent.

Link copied to clipboard
fun next(): Boolean

Advances to the next document, and returns whether there is one.