Is CBLManager close method synchronous?

3 views
Skip to first unread message

Brendan Duddridge

unread,
Oct 31, 2016, 5:31:32 AM10/31/16
to Couchbase Mobile
Hi

Is the [CBLManager close] method synchronous or asynchronous? I know it not only closes the database, but also stops replications and calls saveAllModels before it closes the database. Just wondering if the app will block while the close method is executing? I would like it to block because I'm closing a window and in a windowDidClose method I'm going to call CBLManager's close method then.

I was thinking that maybe my app was occasionally terminating before the close method had a chance to finish executing. And I know that when the CBLManager closes its database, it checkpoints the WAL file and deletes the db.sqlite-shm and db.sqlite-wal files. But if the app terminates prematurely before that completes, that could cause a partial write into the db.sqlite file as the checkpoint process is being run. This is a Mac app by the way.

Thanks,

Brendan

Jens Alfke

unread,
Oct 31, 2016, 11:29:39 AM10/31/16
to mobile-c...@googlegroups.com

> On Oct 31, 2016, at 2:31 AM, Brendan Duddridge <bren...@gmail.com> wrote:
>
> Is the [CBLManager close] method synchronous or asynchronous?

Synchronous. Everything that’s async should either have ‘async’ in the method name, or else have start/stop methods like replications.

> And I know that when the CBLManager closes its database, it checkpoints the WAL file and deletes the db.sqlite-shm and db.sqlite-wal files. But if the app terminates prematurely before that completes, that could cause a partial write into the db.sqlite file as the checkpoint process is being run.

What you’re describing is SQLite’s housekeeping when it closes a database, not anything CBL is doing explicitly. And like everything else SQLite does, it should be crash-proof. If it’s interrupted in the middle of an operation like flushing the WAL, the data is still intact.

—Jens

Reply all
Reply to author
Forward
0 new messages