Atomicity (database Systems) - Implementation

Implementation

Typically, systems implement atomicity by providing some mechanism to indicate which transactions have started and which finished; or by keeping a copy of the data before any changes occurred. Several filesystems have developed methods for avoiding the need to keep multiple copies of data, using journaling (see journaling file system). Databases usually implement this using some form of logging/journaling to track changes. The system synchronizes the logs (often the metadata) as necessary once the actual changes have successfully taken place. Afterwards, crash recovery simply ignores incomplete entries. Although implementations vary depending on factors such as concurrency issues, the principle of atomicity — i.e. complete success or complete failure — remain.

Ultimately, any application-level implementation relies on operating-system functionality, which in turn makes use of specialized hardware to guarantee that an operation remains non-interruptible: either by software attempting to re-divert system resources (see pre-emptive multitasking) or by resource-unavailability (such as power-outages). For example, POSIX-compliant systems provide the open(2) system call that allows applications to atomically open a file. Other popular system-calls that may assist in achieving atomic operations from userspace include fcntl(2), fdatasync(2), flock(2), fsync(2), mkdir(2), rasctl(2) (NetBSD re-startable sequences), rename(2), semop(2), sem_post(2), and sem_wait(2).

The hardware level requires atomic operations such as test-and-set (TAS), or atomic increment/decrement operations. In their absence, or when necessary, raising the interrupt level to disable all possible interrupts (of hardware and software origin) may serve to implement the atomic synchronization function primitives. Systems often implement these low-level operations in machine language or in assembly language.

In NoSQL data stores with eventual consistency, the atomicity is also weaker specified than in relational database systems, and exists only in rows (i.e. column families).

Read more about this topic:  Atomicity (database Systems)