Can you suggest a database for storage of files(1KB-2GB) which supports single document write locks. I was initially using MongoDB but got really disappointed when I found out that the locks are database based, which means that if a single user is uploading a file, all other users will have to wait for the write lock to be released.
You might want to look at the TukoMX for MongoDB. It replaces the storage engine of MongoDB and they have document locking instead of DB-scope locking.
http://www.tokutek.com/products/tokumx-for-mongodb/
Related
I have 2 collections that I am doing a map reduce into a temporary collection, let's call them collection A and collection B and collection _queue.
While I am doing the map reduce, users are trying to read and write to collection A. I am getting all sorts of locks and queued writes and reads.
I don't care if there are dirty reads or writes, is the a way to read and write to collection B and make it non-atomic?
Thanks in advance.
There is no way in MongoDB to specify anything on a query regarding it's lock policy.
First, you need to check if the time to acquire the lock is really an issue (you can use MongoDB internal Profiler for this : https://docs.mongodb.com/manual/administration/analyzing-mongodb-performance/#database-profiling)
Then, if you are not on the latest version of MongoDB (or if you upgrade to the latest without changing the storage engine), you can switch to WiredTigger that move from a lock by collection (for 3.x series, pre-3.x MongoDB have a lock by database) to a lock by document. So if you're using WiredTiger and still experience significant delays due to lock contention, I don't think you can do anything about it.
See the WiredTiger documentation here : https://docs.mongodb.com/manual/core/wiredtiger/
In a MongoDB server, there may be multiple databases, and each database can have multiple collections, and a collection can have multiple documents.
Does a lock apply to a collection, a database, or a server?
I asked this question because when designing MongoDB database, I want to determine what is stored in a database and what is in a collection. My data can be partitioned into different parts, and I hope to be able to move a part from a MongoDB server to a filesystem, without being hindered by the lock that applies to another part, so I wish to store the parts of data in a way that different parts have different locks.
Thanks.
From the official documentation : https://docs.mongodb.com/manual/faq/concurrency/
Basically, it's global / database / collection.
But with some specific storage engines, it can lock at document level too, for instance with WiredTiger (only with Mongo 3.0+)
I read some information in mongodb manual regarding locking of database. It says that mongodb implements some sort of reader-writer lock for multiple clients working with database. It seems absolutely logical, when we need to ensure data integrity.
My question is why mongodb locks databases instead of collections?
The feature simply isn't done yet. It's planned for 2.4+ (maybe 2.5?). Until 2.2, it was a global lock and not a database-level lock.
MongoDB 2.2 has a write lock per database as opposed to a global write lock on the server in previous versions. So would it be ok if i store each collection in a separate database to effectively have a write lock per collection.(This will make it look like MyISAM's table level locking). Is this approach faulty?
There's a key limitation to the locking and that is the local database. That database includes a the oplog collection which is used for replication.
If you're running in production, you should be running with Replica Sets. If you're running with Replica Sets, you need to be aware of the write lock effect on that database.
Breaking out your 10 collections into 10 DBs is useless if they all block waiting for the oplog.
Before taking a large step to re-write, please ensure that the oplog will not cause issues.
Also, be aware that MongoDB implements DB-level security. If you're using any security features, you are now creating more DBs to secure.
Yes that will work, 10gen actually offers this as an option in their talks on locking.
I probably isolate every collection, though. Most databases seem to have 2-5 high activity collections. For the sake of simplicity it's probably better to keep the low activity collections grouped in one DB and put high activity collections in their own databases.
Hi i am using mongodb as my database. My question is how can i make sure that when i do a query for one document or lots of documents. Example:
mongo.GetCollection("orders").Find(Query.EQ("OrderStatus", "unshiped")).ToList();
How to make sure that the documents that are in this list are locked and nobody can edit them and what ever i do in the code with this records when i loop them true and then save them it should unlock it
MongoDB supports atomic operations on single documents. MongoDB does
not support traditional locking and complex transactions for a number
of reasons:
First, in sharded environments, distributed locks could be expensive and slow. Mongo DB's goal is to be lightweight and fast.
We dislike the concept of deadlocks. We want the system to be simple and predictable without these sort of surprises.
We want Mongo DB to work well for realtime problems. If an operation may execute which locks large amounts of data, it might stop
some small light queries for an extended period of time.
I think your best bet is adding a locked property to your documents, and to go from there.
You can add the isLocked field in collection. Before update you can lock and unlock to finish the work. If you want more spesific lock mechanism, Add Guid in LockedId field.