Live data from Hacker News

Disks Lie: Building a WAL that actually survives

blog.canoozie.net

21–30 of 53 posts

Re: Disks Lie: Building a WAL that actually survives

#21
post #13

I worked with a greybeard that instilled in me that when we were about to do some RAID maintenance that we would always run sync twice. The second to make sure it immediately returns. And I added a third for my own anxiety.

You need to sync twice because Unix is dumb: "According to the standard specification (e.g., POSIX.1-2001), sync() schedules the writes, but may return before the actual writing is done." https://man7.org/linux/man-pages/man2/sync.2.html

Re: Disks Lie: Building a WAL that actually survives

#22

People consistently underestimate the many ways in which storage can and will fail in the wild. The most vexing storage failure is phantom writes. A disk read returns a "valid" page, just not the last written/fsync-ed version of that page. Reliably detecting this case is very expensive, particularly on large storage volumes, so it is rarely done for storage where performance is paramount.

Not that uncommon failure mode for some SSDs, unclean shutdown is like a dice roll for some of them: maybe you get what you wrote five seconds ago, maybe you get a snapshot of a couple hours ago.

Early SSDs were particularly prone to phantom writes due to firmware bugs. Still have scars from the many creative ways in which early SSDs would routinely fail.

Re: Disks Lie: Building a WAL that actually survives

#23
post #13

I worked with a greybeard that instilled in me that when we were about to do some RAID maintenance that we would always run sync twice. The second to make sure it immediately returns. And I added a third for my own anxiety.

  sync; sync; halt

Re: Disks Lie: Building a WAL that actually survives

#24
post #21
post #13

I worked with a greybeard that instilled in me that when we were about to do some RAID maintenance that we would always run sync twice. The second to make sure it immediately returns. And I added a third for my own anxiety.

You need to sync twice because Unix is dumb: "According to the standard specification (e.g., POSIX.1-2001), sync() schedules the writes, but may return before the actual writing is done." https://man7.org/linux/man-pages/man2/sync.2.html

> Unix is dumb

I don't know. Now async I/O is all the rage and that is the same idea.

Re: Disks Lie: Building a WAL that actually survives

#25

Earlier quoted context omitted.

Not that uncommon failure mode for some SSDs, unclean shutdown is like a dice roll for some of them: maybe you get what you wrote five seconds ago, maybe you get a snapshot of a couple hours ago.

Early SSDs were particularly prone to phantom writes due to firmware bugs. Still have scars from the many creative ways in which early SSDs would routinely fail.

In college I had a 90GB OCZ Vertex, or maybe it was a Vertex 2.

It would suddenly become blank. You have an OS and some data today, and tomorrow you wake up and everything claims it is empty. It would still work, though. You could still install a new OS and keep going, and it would work until next time.

What a friendly surprise on exam week.

Sold it to a friend for really cheap with a warning about what had been happening. It surprise wiped itself for him too.

Re: Disks Lie: Building a WAL that actually survives

#26
This article is pretty low quality. It's an important and interesting topic and the article is mostly right but it's not clear enough to rely on.

The OS page cache is not a "problem"; it's a basic feature with well-documented properties that you need to learn if you want to persist data. The writing style seems off in general (e.g. "you're lying to yourself").

AFAIK fsync is the best practice not O_DIRECT + O_DSYNC. The article mentions O_DSYNC in some places and fsync in others which is confusing. You don't need both.

Personally I would prefer to use the filesystem (RAID or ditto) to handle latent sector errors (LSEs) rather than duplicating files at the app level. A case could be made for dual WALs if you don't know or control what filesystem will be used.

Due to the page cache, attempting to verify writes by reading the data back won't verify anything. Maaaybe this will work when using O_DIRECT.

Re: Disks Lie: Building a WAL that actually survives

#27
> Submit the write to the primary file

> Link fsync to that write (IOSQE_IO_LINK)

> The fsync's completion queue entry only arrives after the write completes

> Repeat for secondary file

Wait, so the OS can re-order the fsync() to happen before the write request it is supposed to be syncing? Is there a citation or link to some code for that? It seems too ridiculous to be real.

> O_DSYNC: Synchronous writes. Don't return from write() until the data is actually stable on the disk.

If you call fsync() this isn't needed correct? And if you use this, then fsync() isn't needed right?

Re: Disks Lie: Building a WAL that actually survives

#28
post #21

Earlier quoted context omitted.

You need to sync twice because Unix is dumb: "According to the standard specification (e.g., POSIX.1-2001), sync() schedules the writes, but may return before the actual writing is done." https://man7.org/linux/man-pages/man2/sync.2.html

> Unix is dumb I don't know. Now async I/O is all the rage and that is the same idea.

The syscall is literally called "sync", though.

Re: Disks Lie: Building a WAL that actually survives

#29
post #21

Earlier quoted context omitted.

You need to sync twice because Unix is dumb: "According to the standard specification (e.g., POSIX.1-2001), sync() schedules the writes, but may return before the actual writing is done." https://man7.org/linux/man-pages/man2/sync.2.html

> Unix is dumb I don't know. Now async I/O is all the rage and that is the same idea.

If they had a sync() system call and a wait_for_sync_to_finish() system call then you'd be right. But they didn't have those.

Re: Disks Lie: Building a WAL that actually survives

#30
post #8

https://en.wikipedia.org/wiki/Data_Integrity_Field This, along with RAID-1, is probably sufficient to catch the majority of errors. But realize that these are just probabilities - if the failure can happen on the first drive, it can also happen on the second. A merkle tree is commonly used to also protect against these scenarios. Notice that using something like RAID-5 can result in data corruption migrating througho…

Note that 99% of drives don't implement DIF.
Post reply on HN