Was finally able to dig into this today. Turns out that I was missing almost half of my documents in my index because of the database busy errors. So I built a test app to try out some variations.
TL;DR: CBL lite will run just fine if you do everything in one thread (or a dispatch_queue). The problem is there's no way I can find to force all automated actions through the main thread or a designated queue. This will likely never affect most installations - this requires serious document creation. Also: I have not tested this with any kind of sync.
I started this test after seeing this is
CBLManager.h@property (strong) dispatch_queue_t dispatchQueue;
I created a serial queue and wrote everything to take advantage of it. Unfortunately, this doesn't force the internal features to use this queue. For instance, I was using CBLModel's autosave feature - that always triggers on a separate thread. CBLLiveQuery's indexing is done on a separate thread too.
When under load, these background threads don't serialize access to the database and start throwing database busy errors. Looking at the code, there does not currently appear to be a way to trap or report on those errors - they just go to NSLog. The load I was working with was just over 1 new document/model per second. This is on an older MacBook Pro with a spinning drive. Faster equipment probably makes this less of an issue.
My solution:
1. Use [CBLModel save:] on the insert thread. I've left autosave on for now as a backup - but it doesn't fire if there's nothing to save.
2. Built a version of "live updating" on the main thread by counting the number of items I'm inserting and triggering an occasional [QBLQuery run:] synchronous on the main thread.
With those changes, I can insert as fast as the machine can create and save them without any database busy errors - which is impressive. It's less ideal, especially the livequery change, but doable.
This is an edge case even for me so I'm not sure if I'm going to port this work back out of the test app, but I wanted to report the outcome. Couchbase, if you want any of this as bug reports, let me know. I can see 3 potential:
1. Better handling of "Database busy" errors - even if it just throws a NSNotification so the app can be aware.
2. If dispatchQueue is set, run "automated tasks" in that queue.
3. Some version of validation test for view indices.
Maybe ForestDB fixes some of these for free?