MemoryDocStore

Default in-memory DocStore, backed by a ConcurrentHashMap. Ported from yorkie-js-sdk MemoryDocStore (doc-store.ts); matches iOS's memory-only default.

Every ByteArray is copied on the way in and on the way out, so neither a caller mutating what it wrote nor one mutating what it read can corrupt the stored entry. JS relies on Uint8Array.slice() for this; Kotlin's ByteArray is a mutable, aliasable reference type (iOS skipped the equivalent copy only because Swift's Data is a value type), so without the copy a caller mutating an array after a write — or mutating a load result — would corrupt the stored envelope in place.

The mutating no-op-on-absent operations (appendChange, saveMeta) use ConcurrentHashMap.computeIfPresent, which recomputes a key's value atomically under the map's own per-key locking — this is what keeps two coroutines calling appendChange concurrently from losing an entry, without an explicit external lock.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open suspend override fun appendChange(docKey: String, change: StoredChange)

Appends one local change. This is the hot path — frequent and small — so an implementation must not rewrite the whole entry to satisfy it.

Link copied to clipboard
open suspend override fun load(docKey: String): StoredDoc?

Returns the persisted state for docKey, or null when nothing has been stored for it. StoredDoc.changes is ordered by ascending StoredChange.clientSeq.

Link copied to clipboard
open suspend override fun remove(docKey: String)

Deletes everything persisted for docKey. A no-op when nothing is stored.

Link copied to clipboard
open suspend override fun saveMeta(docKey: String, bytes: ByteArray)

Records the post-sync header. It leaves the snapshot alone — an online client syncs constantly, and re-snapshotting per sync would reintroduce the cost this interface exists to avoid — and it leaves the log alone too.

Link copied to clipboard
open suspend override fun saveSnapshot(docKey: String, bytes: ByteArray)

Replaces the snapshot and atomically drops every appended change and any stored meta. This is compaction: the new snapshot already contains those changes, so keeping them would replay them twice, and it embeds a newer header than meta holds — a snapshot envelope embeds its own checkpoint and changeID, newer than whatever meta held; applying the old header over the new snapshot would regress serverSeq and — worse — lamport, whose regression makes the next edit mint tickets that collide with identities already in the restored root.