Skip to main content

Posts

Using locks in NoSQL database

Locks in NoSQL database In this article, we explore Read-Modify-Write (RMW) lock which is equivalent to SELECT FOR UPDATE lock often found in RDBMS.

Commonly, NoSQL databases often do not use locking as in traditional RDBMS. But Oracle NoSQL database offers a set of advanced features that can be used to implement locking semantics.
Read-Modify-Write Lock An RMW lock uses following simple API
RMWLock.update(KVStore store, PrimaryKey pk, Updater updater); where
store is a database connectionpk is the primary key of row being locked for updateupdater is a function that updates the row values pointed by pk The Updater is a functional interface where the application can implement custom update behavior.
public interface Updater { void update(Row row); } It is noteworthy that RMWLock may attempt to update the row more than once. This can happen if another thread is updating the row at the same time. In such cases, RMWLock would invoke the updater function on e…
Recent posts

Unique, monotonic sequence in NoSQL using SELECT FOR UPDATE style lock

Persistent Sequence in NoSQL database What is a Database Sequence? A database sequence is a monotonic series of unique numbers. A sequence is widely used in database for primary keys and other uniquely identifiable values. 
Database Sequence in NoSQL  Because NoSQL database does not use locks, and data is maintained in multiple copies distributed across different storage medium, generating a series of numbers that are unique and monotonic across multiple threads (and applications) becomes a non-trivial problem.
To generate a sequence, we need a mechanism that can acquire a lock on a record, update its value and ensures that no other thread/process can update the same row in the meantime. This is typical  SELECT FOR UPDATE  behavior found in in RDBMS. It is also know as Read-Modify-Write pattern in database programming. In this article, we show how advanced features of Oracle NoSQL database can achieve similar SELECT FOR UPDATE behavior.
We take a concrete example of persistence Seq…