Liking cljdoc? Tell your friends :D

igeldb.io


*entries-read*clj

Test instrumentation: bind to an atom and read-kv-pair! counts every entry it deserializes, so a test can prove an index-directed read touches only its block rather than scanning the file. nil in production -- a nil check, no atom traffic on the read path.

Test instrumentation: bind to an atom and `read-kv-pair!` counts every entry it
deserializes, so a test can prove an index-directed read touches only its block
rather than scanning the file. nil in production -- a nil check, no atom traffic
on the read path.
sourceraw docstring

append-entry!clj

(append-entry! out-stream [ikey data])

Write one entry: key segment (seq ++ user_key) then value segment (or a length-0 tombstone). Used by both the WAL and SSTable writers.

Write one entry: key segment (`seq ++ user_key`) then value segment (or a
length-0 tombstone). Used by both the WAL and SSTable writers.
sourceraw docstring

crc32clj

(crc32 data)

Return the unsigned CRC32 value for data.

File formats choose how many bytes encode the value: regular framed segments store it as a long, while the manifest's fixed header stores it as an int.

Return the unsigned CRC32 value for `data`.

File formats choose how many bytes encode the value: regular framed segments
store it as a long, while the manifest's fixed header stores it as an int.
sourceraw docstring

decode-ikeyclj

(decode-ikey b)
source

decode-indexclj

(decode-index payload)

Parse an index payload into a vector of [first-user_key block-offset], in user_key order (ready for binary search).

Parse an index payload into a vector of [first-user_key block-offset], in
user_key order (ready for binary search).
sourceraw docstring

decode-wal-recordclj

(decode-wal-record payload)

Parse a WAL record payload into [seq entries], where each entry is [ikey data] with ikey's seq set to the record's seq.

Parse a WAL record payload into `[seq entries]`, where each entry is
`[ikey data]` with `ikey`'s seq set to the record's seq.
sourceraw docstring

delete-fileclj

(delete-file file-path)
source

deserialize-longclj

(deserialize-long bytes)
source

encode-ikeyclj

(encode-ikey ikey)
source

encode-indexclj

(encode-index blocks)

Serialize the sparse index: block-count, then per block keylen ++ first-user_key ++ block-start-offset.

Serialize the sparse index: block-count, then per block
keylen ++ first-user_key ++ block-start-offset.
sourceraw docstring

encode-wal-recordclj

(encode-wal-record seq entries)

Serialize one tx (its seq and folded [ikey data] entries) into the record payload bytes. The caller frames it with write-bytes! (length + CRC).

Serialize one tx (its `seq` and folded `[ikey data]` entries) into the record
payload bytes. The caller frames it with `write-bytes!` (length + CRC).
sourceraw docstring

entry-size-on-diskclj

(entry-size-on-disk ikey data)

Exact number of bytes append-entry! writes for one entry: the key segment (len + seq + user_key + CRC) plus the value segment (len + value + CRC, or a bare length-0 long for a tombstone). Authoritative -- the SSTable writer uses it to cut index blocks and compaction uses it to size output tables.

Exact number of bytes `append-entry!` writes for one entry: the key segment
(len + seq + user_key + CRC) plus the value segment (len + value + CRC, or a
bare length-0 long for a tombstone). Authoritative -- the SSTable writer uses it
to cut index blocks and compaction uses it to size output tables.
sourceraw docstring

floor-block-offsetclj

(floor-block-offset index target-key)

Byte offset of the block a read for target-key must start at (see floor-block-idx). Offset 1 -- just past the format byte -- when there is no index.

Byte offset of the block a read for `target-key` must start at (see
`floor-block-idx`). Offset 1 -- just past the format byte -- when there is no
index.
sourceraw docstring

floor-block-spanclj

(floor-block-span index target-key index-start)

[start end) for a read of target-key: the floor block's offset and where that block ends (the next block's offset, or the end of the entries region). Sizing the first channel read to the block avoids pulling in bytes the read will never look at.

`[start end)` for a read of `target-key`: the floor block's offset and where
that block ends (the next block's offset, or the end of the entries region).
Sizing the first channel read to the block avoids pulling in bytes the read will
never look at.
sourceraw docstring

FRAME_OVERHEADclj

source

list-filesclj

(list-files dir)
source

make-dirclj

(make-dir dir)
source

read-all-entriesclj

(read-all-entries file-path)

Every [ikey data] entry of an SSTable, in file order (compaction reads whole tables). Bounded by the entries region -- reading to EOF would run into the index/trailer footer and misparse it as entries. Opens its own channel: a compaction reads each input exactly once, so it bypasses the read cache.

Every [ikey data] entry of an SSTable, in file order (compaction reads whole
tables). Bounded by the entries region -- reading to EOF would run into the
index/trailer footer and misparse it as entries. Opens its own channel: a
compaction reads each input exactly once, so it bypasses the read cache.
sourceraw docstring

read-bytes!clj

(read-bytes! in-stream file-path)

Read a data segment that is required to be present and valid, e.g. a field of a fixed-format file (SSTable info). Throws on any EOF/truncation/corruption.

Read a data segment that is required to be present and valid, e.g. a field of
a fixed-format file (SSTable info). Throws on any EOF/truncation/corruption.
sourceraw docstring

read-data!clj

(read-data! in-stream)

Read one length-prefixed, CRC-checked data segment, classifying the outcome so callers can distinguish the four error classes. Returns one of:

:eof - a clean end at a record boundary (nothing left to read) :truncated - an incomplete entry: EOF was reached partway through the length prefix, the data, or the CRC. Normal only at a WAL tail (a crash before the write's fsync completed). :tombstone - a deletion marker (segment length 0) :corrupt - the whole segment was read but its CRC did not match, or the length prefix is nonsensical (mid-file corruption) {:ok bytes} - a valid data segment

Read one length-prefixed, CRC-checked data segment, classifying the outcome
so callers can distinguish the four error classes. Returns one of:

  :eof        - a clean end at a record boundary (nothing left to read)
  :truncated  - an incomplete entry: EOF was reached partway through the
                length prefix, the data, or the CRC. Normal only at a WAL
                tail (a crash before the write's fsync completed).
  :tombstone  - a deletion marker (segment length 0)
  :corrupt    - the whole segment was read but its CRC did not match, or the
                length prefix is nonsensical (mid-file corruption)
  {:ok bytes} - a valid data segment
sourceraw docstring

read-footer!clj

(read-footer! file-path)

Read the trailer from the file end, then the index region. Returns {:index-start <byte offset where entries end> :index [[user_key offset]...]}. Raises on a corrupt/truncated footer or an unsupported format version.

Read the trailer from the file end, then the index region. Returns
`{:index-start <byte offset where entries end> :index [[user_key offset]...]}`.
Raises on a corrupt/truncated footer or an unsupported format version.
sourceraw docstring

read-format-byte!clj

(read-format-byte! in-stream file-path)

Consume and validate the leading SSTable format-version byte.

Consume and validate the leading SSTable format-version byte.
sourceraw docstring

read-kv-pair!clj

(read-kv-pair! in-stream)

Read one entry (key segment then value segment). Returns: :eof - a clean end at a record boundary :truncated - an incomplete entry at the tail :corrupt - a CRC mismatch (mid-file corruption) [ikey data] - a complete entry; ikey is an InternalKey, data a Data

Read one entry (key segment then value segment). Returns:
:eof         - a clean end at a record boundary
:truncated   - an incomplete entry at the tail
:corrupt     - a CRC mismatch (mid-file corruption)
[ikey data]  - a complete entry; `ikey` is an InternalKey, `data` a `Data`
sourceraw docstring

read-latest-seqclj

(read-latest-seq ch file-path target-key {:keys [index index-start]})

The seq of the newest version of target-key in an SSTable, or nil if absent. Entries are user_key-asc / seq-desc, so the first entry with user_key == target is the newest. Used by commit-time write-write conflict detection.

The seq of the *newest* version of `target-key` in an SSTable, or nil if absent.
Entries are user_key-asc / seq-desc, so the first entry with user_key == target
is the newest. Used by commit-time write-write conflict detection.
sourceraw docstring

read-valueclj

(read-value ch file-path target-key snapshot-seq {:keys [index index-start]})

Point read: the newest version of target-key (a user_key) with seq <= snapshot-seq, or nil. Entries are user_key-asc / seq-desc, so the first entry with user_key == target and seq <= snapshot is the answer.

footer is the table's in-memory {:index :index-start}: the read starts at the floor block for target-key rather than the file start, and stops where the entries end. It keeps scanning past block ends until the user_key exceeds the target, so a user_key whose versions straddle a block boundary is still found in full. Bytes come off the cached channel via absolute positional reads.

Point read: the newest version of `target-key` (a user_key) with seq <=
`snapshot-seq`, or nil. Entries are user_key-asc / seq-desc, so the first entry
with user_key == target and seq <= snapshot is the answer.

`footer` is the table's in-memory `{:index :index-start}`: the read starts at the
floor block for `target-key` rather than the file start, and stops where the
entries end. It keeps scanning past block ends until the user_key exceeds the
target, so a user_key whose versions straddle a block boundary is still found in
full. Bytes come off the cached channel via absolute positional reads.
sourceraw docstring

read-wal-record!clj

(read-wal-record! in-stream)

Read one framed WAL record. Returns :eof / :truncated / :corrupt (as read-data! classifies the frame) or [seq entries] for a complete tx.

Read one framed WAL record. Returns `:eof` / `:truncated` / `:corrupt` (as
`read-data!` classifies the frame) or `[seq entries]` for a complete tx.
sourceraw docstring

scan-pairsclj

(scan-pairs ch
            file-path
            from-key
            to-key
            snapshot-seq
            {:keys [index index-start]})

Range read: for each user_key in [from-key, to-key), its newest version with seq <= snapshot-seq, as [user_key data] (tombstones included; callers filter). Entries are user_key-asc / seq-desc. Starts at the block covering from-key.

Range read: for each user_key in [from-key, to-key), its newest version with
seq <= `snapshot-seq`, as [user_key data] (tombstones included; callers filter).
Entries are user_key-asc / seq-desc. Starts at the block covering `from-key`.
sourceraw docstring

serialize-longclj

(serialize-long value)
source

SSTABLE_FORMAT_VERSIONclj

source

TRAILER_SIZEclj

source

WAL_FORMAT_VERSIONclj

source

write-bytes!clj

(write-bytes! out-stream b)
source

write-footer!clj

(write-footer! out-stream blocks index-start)

Append the index region then the fixed-size trailer. index-start is the byte offset just past the last entry (i.e. where the index region begins).

Append the index region then the fixed-size trailer. `index-start` is the byte
offset just past the last entry (i.e. where the index region begins).
sourceraw docstring

write-format-byte!clj

(write-format-byte! out-stream)

Write the one-byte SSTable format version at the start of a file.

Write the one-byte SSTable format version at the start of a file.
sourceraw docstring

write-tombstone!clj

(write-tombstone! out-stream)
source

write-wal-record!clj

(write-wal-record! out-stream seq entries)

Append one framed WAL record (one tx) to a WAL output stream.

Append one framed WAL record (one tx) to a WAL output stream.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close