purgeDocument within inTransaction creating sub-transactions

8 views
Skip to first unread message

Brendan Duddridge

unread,
Jan 7, 2018, 5:20:13 AM1/7/18
to Couchbase Mobile
Hi,

I'm writing a method for macOS and iOS using CBL 1.4.1 which purges all the deleted documents in the database.

But when I run my code, it looks like all the calls to purgeDocument are creating and committing its own transactions, even though I've surrounded the purgeDocument call within a CBLDatabase inTransaction block.

I thought that only the one transaction would be created.

This is the output I'm seeing:

03:13:26.782 Database: }} Commit transaction (level 2)

03:13:26.795 Database: {{ Begin transaction (level 2)...

03:13:26.795 Database: Purging doc 'rec-f2d55a0bb90149f69e95ba4fe0c38f91'

03:13:26.796 Database: ---> Added: (null) as seq 0

03:13:26.796 Database: }} Commit transaction (level 2)

03:13:26.796 Database: {{ Begin transaction (level 2)...

03:13:26.796 Database: Purging doc 'rec-f2d60a9d4f3d4fb688d4a0609f9a4eeb'

03:13:26.797 Database: ---> Added: (null) as seq 0

03:13:26.797 Database: }} Commit transaction (level 2)

03:13:26.798 Database: {{ Begin transaction (level 2)...

03:13:26.798 Database: Purging doc 'rec-f2d6429208da44c8b66fe7ace7b1467f'

03:13:26.799 Database: ---> Added: (null) as seq 0


I see it says Level 2 though, so does that mean that the main transaction (Level 1) was created by the inTransaction call and these are just sub-transactions of that one transaction?

Is there a way to prevent the sub-transactions from being created and committed for every purgeDocument call? It's operating quite slowly with all these transactions.

Is it possible that the purgeDocument code creates its own transaction?

Thanks,

Brendan

Jens Alfke

unread,
Jan 8, 2018, 1:18:43 PM1/8/18
to mobile-c...@googlegroups.com


On Jan 7, 2018, at 2:20 AM, Brendan Duddridge <bren...@gmail.com> wrote:

I see it says Level 2 though, so does that mean that the main transaction (Level 1) was created by the inTransaction call and these are just sub-transactions of that one transaction?

They’re just sub-transactions. Not even that really; they just bump a transaction-level counter. We only commit the SQLite transaction when the counter decrements to zero.

Is there a way to prevent the sub-transactions from being created and committed for every purgeDocument call? It's operating quite slowly with all these transactions.

They shouldn’t affect performance, because all they do is alter an internal counter.

Try profiling with Instruments to see where the time is going. It may be something else about the purge process that’s slow.

—Jens

Brendan Duddridge

unread,
Jan 8, 2018, 2:34:09 PM1/8/18
to Couchbase Mobile
Ah ok. Thanks Jens for confirming that there's still only one database write at the end when the parent transaction is committed.

I've seen this behaviour when calling deleteLocalDocument as well.

I'll do some profiling then.

Thanks,

Brendan
Reply all
Reply to author
Forward
0 new messages