Skip to content

Kotlin: List overwrites

overwrites(includeDismissed) reads the local journal a pull writes when a column this device changed loses to a peer's write for the same row and column: the local value is replaced, and the entry records what was lost and who won. Each entry carries the losing value, so a screen can tell the user their edit did not survive.

Examples#

Basic#

// app/src/main/kotlin/com/example/todo/TodoScreen.kt (excerpt)
val entries = kizunasync.overwrites()
for (entry in entries) {
    println("${entry.table}.${entry.column} lost to ${entry.winnerMutationId}")
}

Show the value that was lost#

// app/src/main/kotlin/com/example/todo/TodoScreen.kt (excerpt)
import org.json.JSONTokener

val entries = kizunasync.overwrites()
val entry = entries.firstOrNull() ?: return
val loserValue = JSONTokener(entry.loserValueJson).nextValue()

Parameters#

NameTypeRequiredDescription
includeDismissedBooleanNoWhether entries already acknowledged with Dismiss an overwrite are returned. Default: false.

Returns#

List<KizunaSyncOverwrite>, newest first, with these fields.

NameTypeRequiredDescription
idLong—The journal row's own identifier, the value Dismiss an overwrite takes.
tableString—The synced table the overwritten row belongs to.
pkString—The row's primary key.
columnString—The column whose value was replaced.
loserValueJsonString—The value this device wrote, before the peer's write replaced it, encoded as JSON.
winnerMutationIdString—The exactly-once identifier of the peer write that won.
conflictModeString—The rule that decided it: "arrival" or "hlc", from that table's conflictMode.
winnerSeqString?—The changelog sequence the winning write arrived on, from the pull page that recorded the conflict.
atLong—When the journal recorded it, in milliseconds since the Unix epoch.
dismissedBoolean—Whether the entry has been acknowledged. Always false unless includeDismissed is true.

Errors#

CodeCondition
STOREThe journal could not be read.
ENGINE_UNAVAILABLEThe bridge answered with an envelope carrying no code, which is not a gradeable failure.
ENGINE_UNAVAILABLEThe client has no engine because Initializing has not run.

Notes#

An overwrite is a column-level outcome, not a row rejection: the mutation that wrote the losing value was still accepted, and only this one column's value came from the peer instead. The row and every other column it carries reflect the peer's push. Conflict resolution explains when a table resolves by arrival order and when it resolves by the origin clock.

Inspector also records an Overwritten entry in its short-lived ring the moment the event fires, with reason set to "<table>.<column>". This journal is the durable twin: it survives a restart and carries the full row, while the ring is for the session a screen was open.

This method reaches the kernel through the same JSON-RPC call every typed method uses underneath; it behaves like any other client method and raises the same KizunaSyncError.Engine.

Found a problem? Edit this page on GitHub