On 9/29/19 3:27 AM, Gwendal Roué wrote:
> Thank you, Richard
>
> But now I fail to understand the indented use case of sqlite3 snapshots..
> Why allow to reuse snapshots with several calls to open()? Why do they
> exist at all, since we can already profit from snapshot isolation with one
> transaction (at the cost of keeping it open)?
>
> For information, my quest for snapshot protection has met some success (
> https://github.com/groue/GRDB.swift/pull/625)
>
> Given I control the connections to a given database file, I am able to open
> one writer connection, and, on demand, up to N read-only connections. Those
> N reader connections allow concurrent database reads. Those "reads" are
> generally wrapped in a deferred transaction which provides snapshot
> isolation. At the end of this transaction, the reader connection becomes
> available for another read.
>
> One can now create a "snapshot". Those snapshots use the same pool of N
> readers: snapshot reads are then wrapped in a deferred transaction and
> sqlite3_snapshot_open. At the end of this transaction, the reader
> connection becomes available for another regular read or for another
> snapshot read.
>
> In order to protect unused snapshots, checkpoints are prevented as long as
> there exists snapshots, with sqlite3_wal_hook().
>
> I **really** hope this protects snapshots for good. Of course, a
> confirmation from knowledgeable people would be appreciated :-)
>
> Gwendal
I won;t say I know why they were put in, but here is one possibility
that I can think of. First, your model assumes that you have total
control and confidence over the entire application (and if you do, then
you can protect the snapshots yourself). By passing the snapshot and not
the connection with transaction with the snapshot, you can be sure that
the receiver can't disturb the session and invalidate the snapshot. By
opening the snapshot, the receiver is able to recreate the database at
that point, to read its state, but can't accidentally invalidate it.

-- 
Richard Damon

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to