Bahaa Khateib
Bahaa Khateib

Reputation: 135

Pessimistic lock on orientDB graph API

I am creating a system in orientDB I have some cases where i need to make the system where multiple threads adding edges to certain vertex and updating a property on that vertex. My Question is that is there any method where i can block operations on this vertex until other threads finish a block of code this block for both read and write?

My case i have vertex for hotel and number of available rooms as property, any reservation, my code will work the following order

1- Make sure the remaining rooms size is more than 1

2- Create an edge to the customer vertex

3- Decrease the number of available rooms by one

Upvotes: 0

Views: 149

Answers (1)

Oleksandr Gubchenko
Oleksandr Gubchenko

Reputation: 1369

OrientDB has an optimistic concurrency control system, but on very high concurrent updates on the few records it could be more efficient locking records to avoid retries. You could synchronize the access by yourself or by using the storage API. Note that this works only with non-remote databases.

((OStorageEmbedded)db.getStorage()).acquireWriteLock(final ORID iRid)
((OStorageEmbedded)db.getStorage()).acquireSharedLock(final ORID iRid)
((OStorageEmbedded)db.getStorage()).releaseWriteLock(final ORID iRid)
((OStorageEmbedded)db.getStorage()).releaseSharedLock(final ORID iRid)

Source and examples of usage can be found on the official documentation.

Upvotes: 1

Related Questions