Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-14-2012, 03:43 PM   #1
Registered: Jul 2009
Posts: 42

Rep: Reputation: 0
is write() with O_DIRECT ACID compliant?

My database engine writes records of 64 bytes by issuing write() syscall of the entire disk block. The device is opened with O_DIRECT mode. For example third record within a block starts at byte 128 and ends at position 192, when I do an UPDATE the entire disk block (which is by default 512 bytes) is written.

My question is, can I calim ACID compliance if I am writing the record over itself every time UPDATE occurs? Usually database engines do this in 2 steps by writing modified disk block to another (free) place and then updating an index to new block with one (atomic) write immediately after first write returned success. But I am not doing this, I am overwriting current data with new one expecting the write to be successful. Does my method has any potential problems? Is it ACID compliant? What if the hardware writes only half of the block and my record is exactly in the middle? Or does the hardware already does the 2 step write process I described , but at block level, so I don't need to repeat the same in software?

(note: no record is larger than physical disk block (512 bytes by default) and fsync goes after each write(), this is for Linux only)
Old 03-15-2012, 10:54 AM   #2
LQ Newbie
Registered: Mar 2012
Posts: 16

Rep: Reputation: Disabled

The way I see it, O_DIRECT guarantees nothing of the sort: it only bypasses the system caches, which could be far from enough to guarantee any kind of ACID-like integrity.

On the other hand, calling fsync() after each write does guarantee that all information necessary to re-read all data that has been written to the file is indeed written to disk (both file data *and* filesystem metadata). This should take care of the 'D' ("durability") part of ACID.

Regarding the "A"tomicity, "C"onsistency and "I"solation parts, I don't really think they come into play in the scenario you described above.

Durval Menezes.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing files using O_DIRECT in C anchit87 Programming 2 08-16-2016 04:39 AM
O_DIRECT option of bonnie++ hellfire911 Linux - Newbie 4 03-07-2011 07:13 PM
how to use O_DIRECT ? Stephan_Craft Linux - Server 1 10-05-2009 05:16 AM
IO write using O_DIRECT flag with and without memset() after malloc() naik_yogesh Linux - Software 0 04-01-2009 06:28 AM
Troubleshooting Acid (why Is Acid Console Displayed In Html Text??) njugs79 Linux - Newbie 4 03-30-2005 09:31 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:19 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration