Databases Reference
In-Depth Information
transaction either happens in totality or rolls back. Consistency means each modifi cation to the
database takes it from one consistent state to the other. Inconsistent and unresolved states do not
exist. Isolation provides the assurance that some other process cannot modify a piece of data when
an operation in progress is using it. Durability implies all committed data can be recovered from
any sort of a system failure.
As in the other sections, I go over the different types of NoSQL databases one at a time, starting
with MongoDB.
Updating and Modifying Data in MongoDB, HBase, and Redis
Unlike relational databases, the concept of locking doesn't exist in NoSQL stores. This is a choice
by design, not coincidence. Databases like MongoDB are meant to be sharded and scalable. In such
a situation, locking across distributed shards can be complex and make the process of data updates
very slow.
However, despite the lack of locking, a few tips and tricks could help you in updating data in an
atomic manner. First of all, update an entire document and not just a few fi elds of a document.
Preferably use the atomic methods to update the document. Available atomic methods are as
follows:
$set — Set a value
$inc — Increment a particular value by a given amount
$push — Append a value to an array
$pushAll — Append several values to an array
$pull — Remove a value from an existing array
$pullAll — Remove several value(s) from an existing array
For example, { $set : { “order_date” : new Date(2010, 10, 01) } } updates the order_
date in the orders collection in an atomic manner.
An alternative strategy to using atomic operations is to use the update if current principle.
Essentially this involves three steps:
1. Fetch the object.
2. Modify the object locally.
3. Send an update request that says “update the object to this new value if it still matches its
old value.”
The document or row-level locking and atomicity also applies to HBase.
HBase supports a row-level read-write lock. This means rows are locked when any column in that
row is being modifi ed, updated, or created. In HBase terms the distinction between create and
update is not clear. Both operations perform similar logic. If the value is not present, it's inserted or
else updated.
Search WWH ::




Custom Search