-
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
SQL and locking strategies #2010
Comments
Started working on the branch "newlocks" |
After a reconsideration about pros/cons I think the most common use cases are:
By letting to permanently lock records even outside the command is dangerous and requires more work to assure all is unlocked upon the client connection is closed. So I'd like to introduce this changes:
Where:
And the same with DELETE command:
|
+1 (especially for command locks not connection scope) Would be nice if pessimistic locking could be used in TX_COMMIT, RECORD_UPDATE. In addition with introducing partial update it would be a killer feature. |
It will be ROW level lock. About pessimistic locking on other operation would be easy to implement once this issue is implemented. About PARTIAL UPDATE how to manage removal of one field? |
This is very good question :), seems that field removal would be tricky to define. Because it's rare case it always can be adressed by non-partial update. |
So probably it could be done with SQL UPDATE command? |
I think so. I said sub syntax because SQL UPDATE can be range command with WHERE keywords and so on. In that case all what is needed is only functionality equivalent to one record modifications like: UPDATE #rid |
This syntax is already supported |
Yep that's true, therefore it may be a base of partial update and make TX_COMMIT useable in terms of pessimistic locking in transactions. |
Supported and tested only on UPDATE |
I've also created a test to measure on high-concurrency the benefit of LOCKS:
The test raise 10 threads that execute 100 cycles each (1000 operation in total) of SQL UPDATE |
The RETURNING part has been moved on issue #1056 |
I'm changing the keyword |
Ok, close this one and put the rename into #1056. |
can the lock or unlock statement use in orientdb? |
It's time to start discussing about the record locking strategies we'll support in OrientDB. I prefer to open this thread to all the users here, instead of talk about it internally in Orient Technologies, because I'm confident we could receive good idea and contributions.
Even tough Optimistic approach (CAS like) is great for many use cases, sometimes users need a more "Pessimistic" approach by locking resources. This is the case of persistent queues or any other operation I need to be sure no other thread/client is fetching the same record.
Few of the issues related to this topic:
Now we've the ORecordLockManager that extends the OLockManager (that has been developed more than 2 years ago, so probably it would need a refresh about better synchronization policies?) that does the job: locking RID in read or write mode.
We already use it internally, but I'd like to let to the user to expressly lock resources. I don't know if I'd like the classic RDBMS way to just use the transaction (or some variant of SQL like SELECT FOR UPDATE) or better to offer a more explicit way to lock resources giving more control/power to developers.
Below my initial proposal.
Support LOCK/UNLOCK directly in SELECT, UPDATE AND DELETE
Examples:
New SQL LOCK command
Syntax:
New SQL UNLOCK command
Syntax:
Where:
Automatic releasing of locks
Locks are kept by ODatabase instance that represents a client connection. Once the server disconnects a database it should close it. The ODatabase.close() should free all the acquired locks.
Real use cases: FIFO queue management
Even though we could provide better way to manage a queue, this would work. Push a message into a queue (class Queue):
Pop the first message (returning is a new keyword part of the issue #1056):
This is also related to the issue #1056
Full thread on:
https://groups.google.com/forum/#!searchin/orient-database/Record$20Locking/orient-database/fD-UNnq9zmc/Gw1DiV6zK1EJ
The text was updated successfully, but these errors were encountered: