mozilla-magnet / magnet-client

A nearby content discovery client for Android & iOS
Mozilla Public License 2.0
19 stars 10 forks source link

Moving db to an independant file. #352

Closed arcturus closed 8 years ago

arcturus commented 8 years ago

Also adding locking and transactions to ensure sanity.

Fixes #306

arcturus commented 8 years ago

@sgiles r?

wilsonpage commented 8 years ago

@arcturus can you explain what was the cause of the issue?

arcturus commented 8 years ago

@arcturus can you explain what was the cause of the issue?

Sorry for not appending the explanation, did an update offline to @samgiles and forgot to add it here.

The bigger problem came because history and channels where using the same sqlite file. In an environment like the office, where we have several beacons we are constantly updateing the history database, cause we find and update the timestamp constantly. So when you use the channel you can have situations where two different threads class trying to write to same db, but different tables.

Now each component writes on its own db, also added transactions and locking, to be sure we don't have any problem when writing on the DBs.

arcturus commented 8 years ago

In this file is it necessary to lock and have transactions in the other file? It looks odd in here that we lock around operations that are supposedly atomic?

If the extra lock was necessary, can we move them into SubscriptionsDB (and then use only one lock in there for initialisation and operations)?

Fair enough, I'll give it a try without the looking now that we have it in a separate file. Sure, makes sense just with transactions we should not have this error.

arcturus commented 8 years ago

Just tried out without the locking, just transactions and works smoothly, so, once travis gives me a green will merge.

samgiles commented 8 years ago

Nice! 🏆