-
Notifications
You must be signed in to change notification settings - Fork 872
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
Support atomic operation (separate from ACID) [moved] #1056
Comments
Is there any plan to support this? Until this happens, I can't see OrientDB replacing MongoDB for any of my clients. |
What are your specific use cases? Are you using MongoDB like a queue? |
My use cases are large data-driven web applications. It's simply impossible to program anything useful without atomicity. OrientDB supports transactions, but those are heavy and are also not supported in a cluster. The right way to go is atomic compare-and-set operations per document. |
This is relatively easy to implement with the following syntax:
"RETURNING" has been taken from Postgres and indicate what to return. We could use before and after to decide what return. This could be supported by UPDATE and DELETE statements. Any other better names? |
Sorry for closing, actually I was going to add my 5 cents. To be atomic operation should be trully atomic, I mean server crash should not make data to be in the middle (right ?), it will be introduced here #1604 that is 2-nd task and I am working on it now. Also new LINKBAG (LINKSET which allows duplicates) and document are two different instances but they are updated using CAS style (MVCC actually but I think we talk about the same thing). |
@Laa you're right. That is fundamental to have true ATOMIC operation. Here the focused is more about the SQL commands: they should return something to let to the app to do operation with just one call instead of executing SELECT + UPDATE / DELETE. |
Well, structured document databased are a bit different than relational ones. Look closely at the options available for you in MongoDB: you can increase integers deep inside the structure, pull/push elements in arrays, and many others, as well as the regular compare-and-set. I'm honestly not picky about the syntax: as long as OrientDB can reach feature parity with MongoDB on this. I was just brainstorming some ideas that I thought could keep the SQL style and still do what MongoDB does. My "ulterior motive" here is that I'm the developer behind Diligence, a very comprehensive web framework based on Prudence and MongoDB. It's JVM-based, and as such OrientDB could potentially be a very good fit. |
This is needed also to build persistent queue-like structures:
|
You're absolutely right: but queues are just the tip of the iceberg of what's needed. |
@tliron, could you explain all your use cases to be sure to cover them with one issue? I mean what kind of atomic operations do you need? |
I will do my best. Quick update, the MongoDB documentation has changed a bit, you can see all the atomic operators here: http://docs.mongodb.org/manual/reference/operator/update/ Pay special attention to the "$" placeholder, which can do some very powerful things: http://docs.mongodb.org/manual/reference/operator/update/positional/ The truth is that I use practically all of these operators, a lot! The general principle is this: in the web world, all user requests can happen concurrently, so you must always be prepared for handling multiple conflicting requests without losing data or duplicating it. Here are some examples from Diligence: Diligence Documents/Wiki: Two people editing a wiki page at the same time. All versions of the wiki page in the same document. Via a "$push" operation, you can add an element to a JSON array atomically, thus making sure that if a different user edits the wiki page at the same time, no version is lost. Diligence Notification: This is a classic queue as you noted. Notifications are added to one or more queues are then atomically removed via a MongoDB findAndRemove operation. Diligence Serials: A service used by other services to generate unique IDs. Relies on the "$inc" operation. Diligence Authentication/Registration: An "unauthorized" document is created for users when they first sign in, with another document specifying a special unique token (which expires after a time). They will be sent an email with a link they must click to authorize the account, based on that token. Atomic operations are used here to make sure that the account is only authorized once, and that the token is removed once. Something similar is done with the external authentication providers (OpenID, Facebook, Google, etc.) Diligence Discussion: This service lets you add a mini-forum to any document, where people can post comments and reply, so it is built like a tree that can handle concurrent posts. Perhaps this is the strongest example for when atomic operations are absolutely necessary, but it's also quite complex. I do various tricks to support a tree format with MongoDB, which is a special problem field. Actually, OrientDB would offer graphs, which could be a better approach, but not necessarily: the big advantage of having it as a single document is for extremely fast fetches. Diligence Shopping Cart: If you are adding to the same document concurrently, you must be sure not to account for all simultaneous changes, which can only be done atomically. And that's just in basic Diligence: application built on top of Diligence of course do a lot of other work that would require atomicity. |
What we can support is the RETURNING keyword to let DELETE and UPDATE commands to return the record before or after the change. Example to pop a record:
|
Ok, changed RETURNING -> RETURN with accepted:
|
Let me share my preliminary test results of that functionality, showing clearly how beneficial it is. 1 thread LOCK NONE (MVCC) - 2500 increments /sec 1 thread LOCK RECORD - 2200 increments /sec Nothing more to add :) I hope you will reconsider to add pessimistic locking to TX_COMMIT as well. |
These numbers are super good! We have the issue #12 for that |
This is Issue 1056 moved from a Google Code project.
Added by 2012-09-13T18:10:57.000Z by tal.liron.
Please review that bug for more context and additional comments, but update this bug.
Original labels: Type-Defect, Priority-Medium, Release
Original description
The text was updated successfully, but these errors were encountered: