Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single-writer/Multi-reader Classes: Object Transaction and Read Only Database Pool #327

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Single-writer/Multi-reader Classes: Object Transaction and Read Only Database Pool #327

wants to merge 1 commit into from

Conversation

blakewatters
Copy link
Contributor

Hey there -

I wanted to offer up some FMDB extension classes that my team has been relying on internally to develop LayerKit. Our framework has two main pieces: a sync engine that is running constantly and a public API that performs database queries and mutations to drive synchronization activities. Because of the amount of concurrency on-going at any given time, we have opted to implement single writer / multi-reader on top of FMDB. These classes provide a few things:

  1. The FMDatabaseTransaction class provides an object interface for mediating concurrent access to a single writable connection. It uses a semaphore to ensure that only one object can acquire write access to the database at any time. This is a more convenient interface for us than blocks in some cases because of how write access flows through the sync system.
  2. The FMReadOnlyDatabasePool class provides an interface for mediating access to a finite pool of readers. Under the hood a hash map table of proxy objects guarantees that connections return to the pool as objects are reaped by ARC.

There’s some obvious overlap with the FMDatabaseQueue implementation, but this API is tailored to the reader use-case and the automatic management of connections returning to the pool is very convenient in practice. Anyway, we thought we’d share and see if there’s interest. Happy to make any adjustments necessary. I also have some test cases for the classes, but they are dependent on Expecta so I didn’t pull them in yet.

@ccgus
Copy link
Owner

ccgus commented Dec 22, 2014

There is interest in this! I actually want to do this in FMDB 3.0, which is in the planning stages right now. So- I won't merge this with the current branch, but I will most likely borrow heavily from it for v3. You've done a lot of work here- thanks for that.

@blakewatters
Copy link
Contributor Author

@ccgus: Ping me when you have critical mass on the planning/architecture for 3.0. I’ve been working extensively with FMDB over the last few months and can definitely point to a few more things that could be streamlined or improved. Happy to write things up or jump on a Skype call.

@ccgus
Copy link
Owner

ccgus commented Dec 29, 2014

Cool, will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants