You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/sync.md
+16-9Lines changed: 16 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,9 +47,14 @@ The following commands are supported:
47
47
ahead, or restore the service-side value when the service has cleared stale state but core still
48
48
has a local hint. Then seed core with the reconciled value. Core stores the seeded value
49
49
verbatim and does not enforce monotonicity; SDKs own the reconciliation and must not seed a
50
-
stale value. `NULL` means neither side has a record for the client yet; core stores `0` in that
51
-
case so the state counts as seeded and the first allocation returns `1`. If both the client and
52
-
service have lost the value, the counter may restart.
50
+
stale value. A `NULL` payload is accepted for completeness (core stores `0`, marking the state
51
+
as seeded so the first allocation returns `1`), but SDKs should not need it in practice:
52
+
posting a checkpoint request with an id of at least `1` during reconciliation and seeding the
53
+
service's response covers the no-record case and doubles as a probe of the service's
54
+
checkpoint-request support. Blindly forwarding a raw `NULL` service response while core holds a
55
+
counter would reset it, since the store is verbatim (see
56
+
`docs/write-checkpoint-requests.md`). If both the client and service have lost the value, the
57
+
counter may restart.
53
58
54
59
When uploads request a write checkpoint, SDKs should call
55
60
`powersync_control('next_checkpoint_request_id', NULL)` inside a transaction to allocate the id to
@@ -78,7 +83,9 @@ only real sync buckets in `ps_buckets`, and drops `ps_buckets.target_op` so
78
83
older SDKs fail hard if they try to keep using the migrated database directly. Downgrading restores
79
84
the column, and restores a `$local` row only when `local_target_op` exists, so older SDKs can keep
80
85
using target-op based blocking without inventing a synthetic local bucket when there was no local
81
-
target state. Because the down migration keeps the `ps_kv` keys around, the up migration clears
86
+
target state. A restored concrete target remains satisfiable after a downgrade because checkpoint
87
+
request ids and legacy write checkpoint ids share one namespace: the service reports accepted
88
+
checkpoint request ids as the `write_checkpoint` values older-protocol clients observe. Because the down migration keeps the `ps_kv` keys around, the up migration clears
82
89
them before copying, so re-upgrading a downgraded database takes the `$local` row (including any
83
90
progress an older SDK made) as the source of truth instead of failing on the existing keys.
84
91
@@ -124,11 +131,11 @@ interface LogLine {
124
131
}
125
132
126
133
// Instructs client SDKs to open a connection to the sync service.
127
-
// last_checkpoint_request_id is core's local counter value before this stream request. On connect,
128
-
//SDKs can use it to re-request this client's last checkpoint request state from the service, then
129
-
//call powersync_control('seed_checkpoint_request_id', value) with the actual response for
130
-
//reconciliation. `value` may be null when the service has no checkpoint request state for this
131
-
//client.
134
+
// last_checkpoint_request_id is the client's current counter state before this stream request.
135
+
//On every connect, SDKs use it to re-affirm checkpoint request state with the service (which may
136
+
//have deleted its record). The re-affirmation is bidirectional: the hint can restore the
137
+
//service-side value, or the service's response can bump the local counter via
0 commit comments