You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by Adam Kocoloski <ko...@apache.org> on 2010/04/07 03:03:33 UTC

silent view index file corruption

Hi all, we recently had an EC2 node go AWOL for about 12 hours.  When it came back, we noticed after a few days that a number of the view indexes stored on that node were not updating.  I did some digging into the error logs and with Paul's help pieced together what was going on.  I won't bother you with all the gory details unless you ask for them, but the gist of it is that those files are corrupted.

The troubling thing for me is that we only discovered the corruption when it completely broke the index updates.  In one case, it did this by rearranging the bits so that couch_file thought that the btree node it was reading from disk had an associated MD5 checksum. It didn't (no btree nodes do), and so couch_file threw a file_corruption exception.  But if the corruption had shown up in another part of the file I might never have known.  In fact, some of the other indices on that node probably are silently corrupted.

You might wonder how likely it is that a file becomes corrupted but still appears to be functioning.  I checked the last modified timestamps for three broken files.  One was last modified when the node went down, but the other two had timestamps in between the node's recovery and now.  To me, that means that the view indexer was able to update those files for quite a while (~2 days) before it bumped into a part of the btree that was corrupted.

I wonder what we should do about this.  My first thought is to make it optional to write  btree nodes (possibly only for view index files?) using append_term_md5 instead of append_term.  It seems like a simple patch, but I don't know a priori what the performance hit would be.  Other thoughts?

Best, Adam


Re: silent view index file corruption

Posted by Adam Kocoloski <ko...@apache.org>.
Hi Randall, I'd need to do some benchmarks before I could make a decision on the default as well.

I'm not sure I understand how hash trees help in this case.  I've used the for efficient comparison of trees that are supposed to be identical, but in this case you want to validate that you can still get out what you put in.  I suppose you could rehash all the children and compare to the parent, but at that point aren't you basically doing an md5 sum for every node anyway?

Best, Adam

On Apr 6, 2010, at 10:06 PM, Randall Leeds wrote:

> I immediately want to say 'ini file option' but I'm not sure whether to err
> on safety or speed.
> 
> Maybe this is a good candidate for merkle trees or something else we can do
> throughout the view tree that might less overhead than md5 summing all the
> nodes? After all, most inner nodes shouldn't change most of the time. Some
> incremental, cheap checksum might be a worthwhile *option*.
> 
> On Apr 6, 2010 6:04 PM, "Adam Kocoloski" <ko...@apache.org> wrote:
> 
> Hi all, we recently had an EC2 node go AWOL for about 12 hours.  When it
> came back, we noticed after a few days that a number of the view indexes
> stored on that node were not updating.  I did some digging into the error
> logs and with Paul's help pieced together what was going on.  I won't bother
> you with all the gory details unless you ask for them, but the gist of it is
> that those files are corrupted.
> 
> The troubling thing for me is that we only discovered the corruption when it
> completely broke the index updates.  In one case, it did this by rearranging
> the bits so that couch_file thought that the btree node it was reading from
> disk had an associated MD5 checksum. It didn't (no btree nodes do), and so
> couch_file threw a file_corruption exception.  But if the corruption had
> shown up in another part of the file I might never have known.  In fact,
> some of the other indices on that node probably are silently corrupted.
> 
> You might wonder how likely it is that a file becomes corrupted but still
> appears to be functioning.  I checked the last modified timestamps for three
> broken files.  One was last modified when the node went down, but the other
> two had timestamps in between the node's recovery and now.  To me, that
> means that the view indexer was able to update those files for quite a while
> (~2 days) before it bumped into a part of the btree that was corrupted.
> 
> I wonder what we should do about this.  My first thought is to make it
> optional to write  btree nodes (possibly only for view index files?) using
> append_term_md5 instead of append_term.  It seems like a simple patch, but I
> don't know a priori what the performance hit would be.  Other thoughts?
> 
> Best, Adam


Re: silent view index file corruption

Posted by Adam Kocoloski <ko...@apache.org>.
On Apr 12, 2010, at 8:12 PM, Adam Kocoloski wrote:

> Back to the corruption ... after I spent some time reviewing CouchDB's fsync settings I'm wondering why we don't fsync the view index file before writing a header.  I understand why we don't do it after the header write -- we can always just reindex the last few updates -- but the pre-sync would preserve some write ordering and possibly prevent some sources of corruption.
> 
> Adam

Dragging up this thread again ... I encountered another situation (again on EC2) where multiple .view files were not updating.  I discovered that in each case the index_header for the file claimed that the root of the ID tree was at a location where I found nothing but a bunch of zeroes.  These instances were running XFS, so the zeroes indicate to me that the btree nodes were not written to disk.  I was able to recover the indexes by chopping off the last ~20k of each file, thus causing CouchDB to use an older header for the file which pointed to durably stored btree nodes.

In theory the fsync before header write would eliminate this situation.  I'm going to add it unless there are objections.  I'll make it configurable by the "before_header" config setting that controls the sync behavior of databases.

I think it would also be nice to have a little command-line tool to look for the last few index_headers and offer to truncate the file so that one of these is used instead of the latest one.

Adam


Re: silent view index file corruption

Posted by Adam Kocoloski <ko...@apache.org>.
On Apr 7, 2010, at 2:05 PM, Robert Newson wrote:

> Being able to start a consistency checking task (that shows up in
> _active_tasks, etc) would be useful. I don't think it's something that
> ought to happen automatically, though. Possibly in the case where
> corruption is actually detected?
> 
> I'd like;
> 
> a) checksums on *everything* (don't care for crc32 vs fnv1a vs md5 vs
> sha1 debate, anything is massively better than nothing).
> b) ability to launch end-to-end verification of all checksums (with
> progress if possible).
> c) ability to store/retrieve verification checkpoints.
> 
> Further to c), it would be useful to have API access to replication
> checkpoints. Specifically so that we can interrogate one couchdb
> instance and get some idea for how up to date it is with respect to
> its replicas (which may be unreachable or offline).

Yes, we certainly need more visibility into the replication checkpoint system.  I've been thinking that the _replicator DB Chris has graciously volunteered to work on should automatically add a checkpoint_id field or some such thing to documents that are saved in there.  That way you can have all manner of nice views on the _replicator DB that identify the _local doc you need to pull to inspect the current status of a replication.

Back to the corruption ... after I spent some time reviewing CouchDB's fsync settings I'm wondering why we don't fsync the view index file before writing a header.  I understand why we don't do it after the header write -- we can always just reindex the last few updates -- but the pre-sync would preserve some write ordering and possibly prevent some sources of corruption.

Adam


Re: silent view index file corruption

Posted by Robert Newson <ro...@gmail.com>.
Being able to start a consistency checking task (that shows up in
_active_tasks, etc) would be useful. I don't think it's something that
ought to happen automatically, though. Possibly in the case where
corruption is actually detected?

I'd like;

a) checksums on *everything* (don't care for crc32 vs fnv1a vs md5 vs
sha1 debate, anything is massively better than nothing).
b) ability to launch end-to-end verification of all checksums (with
progress if possible).
c) ability to store/retrieve verification checkpoints.

Further to c), it would be useful to have API access to replication
checkpoints. Specifically so that we can interrogate one couchdb
instance and get some idea for how up to date it is with respect to
its replicas (which may be unreachable or offline).

B.

On Wed, Apr 7, 2010 at 6:30 PM, Randall Leeds <ra...@gmail.com> wrote:
> fnv1a looks interesting. I hadn't heard of this hash but I see how
> it'd be extremely fast and also easy to implement.
>
> I hadn't really thought through the merkle thing, I just kinda spat
> out words. I'll try not to do that in the future :-P
>
> As far as how paranoid to be... we obviously don't want to do a full
> table scan on writes, but could we afford a full table scan at startup
> to verify that the view index hasn't been corrupted since couch was
> last run?
>
> -Randall
>

Re: silent view index file corruption

Posted by Randall Leeds <ra...@gmail.com>.
fnv1a looks interesting. I hadn't heard of this hash but I see how
it'd be extremely fast and also easy to implement.

I hadn't really thought through the merkle thing, I just kinda spat
out words. I'll try not to do that in the future :-P

As far as how paranoid to be... we obviously don't want to do a full
table scan on writes, but could we afford a full table scan at startup
to verify that the view index hasn't been corrupted since couch was
last run?

-Randall

Re: silent view index file corruption

Posted by Christopher Brown <cb...@opscode.com>.
Out of curiosity, if the expense of the hash function is a
consideration, have you all looked at using fnv1a or similarly fast hash
in place of md5?

-Chris

Paul J Davis wrote:
> 
> On Apr 6, 2010, at 11:20 PM, Adam Kocoloski <ko...@apache.org> wrote:
> 
>> On Apr 6, 2010, at 10:50 PM, Paul J Davis wrote:
>>
>>> This corruption was quite odd in that there wasn't a conspicuous reason for it.  I didn't dive to deep into the whole thing so it's possible i missed something obvious. 
>> The instance was unresponsive to ssh for 12 hours.  The report from AWS Support was merely a "problem with the underlying host" followed by a recommendation to "launch a replacement at your earliest convenience".  I don't know what the gremlins were doing behind the scenes, but I'm not surprised the files are corrupted :)
>>
> 
> Yeah I don't think that we should worry about high energy particles flipping bits too much here.
> 
>>> There are two things at play here.  How proactive should we be in provoking theseI errors and how much should we check for situations where our data file got trounced.
>>>
>>> The extreme proactive position would be equivalent to a full table scan per write which is out of the question. So to some extent we won't be able to detect some errors until read time which is an unknowable interval.
>> I'm totally comfortable with only detecting them at read-time.
>>
>>> The other aspect is how rigorous should we check reads? This extreme would basically require a sha1 for every read or write no matter how small, not to mention the storage overhead. This part I'm not sure about. There's probably middle ground with crc sums and what not but i don't see a clear answer.
>> We currently store MD5 checksums with document bodies and validate them on reads.  It hasn't proven to be an undue burden.
>>
> 
> We do that for every doc body? Did not know that. Perhaps general append_term_md5 usage wouldn't be as big of a deal as i feared.
> 
>> Best, Adam
>>
>>> Basically, the question is how much should we attempt to detect when hardware lies.  I reckon that there's probably a middle ground to report when an assumption is violated and full on table scans. Ideally such things would be fairly configurable but i sure don't see an obvious answer.
>>>
>>>
>>> On Apr 6, 2010, at 10:06 PM, Randall Leeds <ra...@gmail.com> wrote:
>>>
>>>> I immediately want to say 'ini file option' but I'm not sure whether to err
>>>> on safety or speed.
>>>>
>>>> Maybe this is a good candidate for merkle trees or something else we can do
>>>> throughout the view tree that might less overhead than md5 summing all the
>>>> nodes? After all, most inner nodes shouldn't change most of the time. Some
>>>> incremental, cheap checksum might be a worthwhile *option*.
>>>>
>>>> On Apr 6, 2010 6:04 PM, "Adam Kocoloski" <ko...@apache.org> wrote:
>>>>
>>>> Hi all, we recently had an EC2 node go AWOL for about 12 hours.  When it
>>>> came back, we noticed after a few days that a number of the view indexes
>>>> stored on that node were not updating.  I did some digging into the error
>>>> logs and with Paul's help pieced together what was going on.  I won't bother
>>>> you with all the gory details unless you ask for them, but the gist of it is
>>>> that those files are corrupted.
>>>>
>>>> The troubling thing for me is that we only discovered the corruption when it
>>>> completely broke the index updates.  In one case, it did this by rearranging
>>>> the bits so that couch_file thought that the btree node it was reading from
>>>> disk had an associated MD5 checksum. It didn't (no btree nodes do), and so
>>>> couch_file threw a file_corruption exception.  But if the corruption had
>>>> shown up in another part of the file I might never have known.  In fact,
>>>> some of the other indices on that node probably are silently corrupted.
>>>>
>>>> You might wonder how likely it is that a file becomes corrupted but still
>>>> appears to be functioning.  I checked the last modified timestamps for three
>>>> broken files.  One was last modified when the node went down, but the other
>>>> two had timestamps in between the node's recovery and now.  To me, that
>>>> means that the view indexer was able to update those files for quite a while
>>>> (~2 days) before it bumped into a part of the btree that was corrupted.
>>>>
>>>> I wonder what we should do about this.  My first thought is to make it
>>>> optional to write  btree nodes (possibly only for view index files?) using
>>>> append_term_md5 instead of append_term.  It seems like a simple patch, but I
>>>> don't know a priori what the performance hit would be.  Other thoughts?
>>>>
>>>> Best, Adam

Re: silent view index file corruption

Posted by Paul J Davis <pa...@gmail.com>.

On Apr 6, 2010, at 11:20 PM, Adam Kocoloski <ko...@apache.org> wrote:

> On Apr 6, 2010, at 10:50 PM, Paul J Davis wrote:
> 
>> This corruption was quite odd in that there wasn't a conspicuous reason for it.  I didn't dive to deep into the whole thing so it's possible i missed something obvious. 
> 
> The instance was unresponsive to ssh for 12 hours.  The report from AWS Support was merely a "problem with the underlying host" followed by a recommendation to "launch a replacement at your earliest convenience".  I don't know what the gremlins were doing behind the scenes, but I'm not surprised the files are corrupted :)
> 

Yeah I don't think that we should worry about high energy particles flipping bits too much here.

>> There are two things at play here.  How proactive should we be in provoking theseI errors and how much should we check for situations where our data file got trounced.
>> 
>> The extreme proactive position would be equivalent to a full table scan per write which is out of the question. So to some extent we won't be able to detect some errors until read time which is an unknowable interval.
> 
> I'm totally comfortable with only detecting them at read-time.
> 
>> The other aspect is how rigorous should we check reads? This extreme would basically require a sha1 for every read or write no matter how small, not to mention the storage overhead. This part I'm not sure about. There's probably middle ground with crc sums and what not but i don't see a clear answer.
> 
> We currently store MD5 checksums with document bodies and validate them on reads.  It hasn't proven to be an undue burden.
> 

We do that for every doc body? Did not know that. Perhaps general append_term_md5 usage wouldn't be as big of a deal as i feared.

> Best, Adam
> 
>> Basically, the question is how much should we attempt to detect when hardware lies.  I reckon that there's probably a middle ground to report when an assumption is violated and full on table scans. Ideally such things would be fairly configurable but i sure don't see an obvious answer.
>> 
>> 
>> On Apr 6, 2010, at 10:06 PM, Randall Leeds <ra...@gmail.com> wrote:
>> 
>>> I immediately want to say 'ini file option' but I'm not sure whether to err
>>> on safety or speed.
>>> 
>>> Maybe this is a good candidate for merkle trees or something else we can do
>>> throughout the view tree that might less overhead than md5 summing all the
>>> nodes? After all, most inner nodes shouldn't change most of the time. Some
>>> incremental, cheap checksum might be a worthwhile *option*.
>>> 
>>> On Apr 6, 2010 6:04 PM, "Adam Kocoloski" <ko...@apache.org> wrote:
>>> 
>>> Hi all, we recently had an EC2 node go AWOL for about 12 hours.  When it
>>> came back, we noticed after a few days that a number of the view indexes
>>> stored on that node were not updating.  I did some digging into the error
>>> logs and with Paul's help pieced together what was going on.  I won't bother
>>> you with all the gory details unless you ask for them, but the gist of it is
>>> that those files are corrupted.
>>> 
>>> The troubling thing for me is that we only discovered the corruption when it
>>> completely broke the index updates.  In one case, it did this by rearranging
>>> the bits so that couch_file thought that the btree node it was reading from
>>> disk had an associated MD5 checksum. It didn't (no btree nodes do), and so
>>> couch_file threw a file_corruption exception.  But if the corruption had
>>> shown up in another part of the file I might never have known.  In fact,
>>> some of the other indices on that node probably are silently corrupted.
>>> 
>>> You might wonder how likely it is that a file becomes corrupted but still
>>> appears to be functioning.  I checked the last modified timestamps for three
>>> broken files.  One was last modified when the node went down, but the other
>>> two had timestamps in between the node's recovery and now.  To me, that
>>> means that the view indexer was able to update those files for quite a while
>>> (~2 days) before it bumped into a part of the btree that was corrupted.
>>> 
>>> I wonder what we should do about this.  My first thought is to make it
>>> optional to write  btree nodes (possibly only for view index files?) using
>>> append_term_md5 instead of append_term.  It seems like a simple patch, but I
>>> don't know a priori what the performance hit would be.  Other thoughts?
>>> 
>>> Best, Adam
> 

Re: silent view index file corruption

Posted by Adam Kocoloski <ko...@apache.org>.
On Apr 6, 2010, at 10:50 PM, Paul J Davis wrote:

> This corruption was quite odd in that there wasn't a conspicuous reason for it.  I didn't dive to deep into the whole thing so it's possible i missed something obvious. 

The instance was unresponsive to ssh for 12 hours.  The report from AWS Support was merely a "problem with the underlying host" followed by a recommendation to "launch a replacement at your earliest convenience".  I don't know what the gremlins were doing behind the scenes, but I'm not surprised the files are corrupted :)

> There are two things at play here.  How proactive should we be in provoking these errors and how much should we check for situations where our data file got trounced.
> 
> The extreme proactive position would be equivalent to a full table scan per write which is out of the question. So to some extent we won't be able to detect some errors until read time which is an unknowable interval.

I'm totally comfortable with only detecting them at read-time.

> The other aspect is how rigorous should we check reads? This extreme would basically require a sha1 for every read or write no matter how small, not to mention the storage overhead. This part I'm not sure about. There's probably middle ground with crc sums and what not but i don't see a clear answer.

We currently store MD5 checksums with document bodies and validate them on reads.  It hasn't proven to be an undue burden.

Best, Adam

> Basically, the question is how much should we attempt to detect when hardware lies.  I reckon that there's probably a middle ground to report when an assumption is violated and full on table scans. Ideally such things would be fairly configurable but i sure don't see an obvious answer.
> 
> 
> On Apr 6, 2010, at 10:06 PM, Randall Leeds <ra...@gmail.com> wrote:
> 
>> I immediately want to say 'ini file option' but I'm not sure whether to err
>> on safety or speed.
>> 
>> Maybe this is a good candidate for merkle trees or something else we can do
>> throughout the view tree that might less overhead than md5 summing all the
>> nodes? After all, most inner nodes shouldn't change most of the time. Some
>> incremental, cheap checksum might be a worthwhile *option*.
>> 
>> On Apr 6, 2010 6:04 PM, "Adam Kocoloski" <ko...@apache.org> wrote:
>> 
>> Hi all, we recently had an EC2 node go AWOL for about 12 hours.  When it
>> came back, we noticed after a few days that a number of the view indexes
>> stored on that node were not updating.  I did some digging into the error
>> logs and with Paul's help pieced together what was going on.  I won't bother
>> you with all the gory details unless you ask for them, but the gist of it is
>> that those files are corrupted.
>> 
>> The troubling thing for me is that we only discovered the corruption when it
>> completely broke the index updates.  In one case, it did this by rearranging
>> the bits so that couch_file thought that the btree node it was reading from
>> disk had an associated MD5 checksum. It didn't (no btree nodes do), and so
>> couch_file threw a file_corruption exception.  But if the corruption had
>> shown up in another part of the file I might never have known.  In fact,
>> some of the other indices on that node probably are silently corrupted.
>> 
>> You might wonder how likely it is that a file becomes corrupted but still
>> appears to be functioning.  I checked the last modified timestamps for three
>> broken files.  One was last modified when the node went down, but the other
>> two had timestamps in between the node's recovery and now.  To me, that
>> means that the view indexer was able to update those files for quite a while
>> (~2 days) before it bumped into a part of the btree that was corrupted.
>> 
>> I wonder what we should do about this.  My first thought is to make it
>> optional to write  btree nodes (possibly only for view index files?) using
>> append_term_md5 instead of append_term.  It seems like a simple patch, but I
>> don't know a priori what the performance hit would be.  Other thoughts?
>> 
>> Best, Adam


Re: silent view index file corruption

Posted by Paul J Davis <pa...@gmail.com>.
This corruption was quite odd in that there wasn't a conspicuous reason for it.  I didn't dive to deep into the whole thing so it's possible i missed something obvious. 

There are two things at play here.  How proactive should we be in provoking these errors and how much should we check for situations where our data file got trounced.

The extreme proactive position would be equivalent to a full table scan per write which is out of the question. So to some extent we won't be able to detect some errors until read time which is an unknowable interval. The other aspect is how rigorous should we check reads? This extreme would basically require a sha1 for every read or write no matter how small, not to mention the storage overhead. This part I'm not sure about. There's probably middle ground with crc sums and what not but i don't see a clear answer. 

Basically, the question is how much should we attempt to detect when hardware lies.  I reckon that there's probably a middle ground to report when an assumption is violated and full on table scans. Ideally such things would be fairly configurable but i sure don't see an obvious answer.


On Apr 6, 2010, at 10:06 PM, Randall Leeds <ra...@gmail.com> wrote:

> I immediately want to say 'ini file option' but I'm not sure whether to err
> on safety or speed.
> 
> Maybe this is a good candidate for merkle trees or something else we can do
> throughout the view tree that might less overhead than md5 summing all the
> nodes? After all, most inner nodes shouldn't change most of the time. Some
> incremental, cheap checksum might be a worthwhile *option*.
> 
> On Apr 6, 2010 6:04 PM, "Adam Kocoloski" <ko...@apache.org> wrote:
> 
> Hi all, we recently had an EC2 node go AWOL for about 12 hours.  When it
> came back, we noticed after a few days that a number of the view indexes
> stored on that node were not updating.  I did some digging into the error
> logs and with Paul's help pieced together what was going on.  I won't bother
> you with all the gory details unless you ask for them, but the gist of it is
> that those files are corrupted.
> 
> The troubling thing for me is that we only discovered the corruption when it
> completely broke the index updates.  In one case, it did this by rearranging
> the bits so that couch_file thought that the btree node it was reading from
> disk had an associated MD5 checksum. It didn't (no btree nodes do), and so
> couch_file threw a file_corruption exception.  But if the corruption had
> shown up in another part of the file I might never have known.  In fact,
> some of the other indices on that node probably are silently corrupted.
> 
> You might wonder how likely it is that a file becomes corrupted but still
> appears to be functioning.  I checked the last modified timestamps for three
> broken files.  One was last modified when the node went down, but the other
> two had timestamps in between the node's recovery and now.  To me, that
> means that the view indexer was able to update those files for quite a while
> (~2 days) before it bumped into a part of the btree that was corrupted.
> 
> I wonder what we should do about this.  My first thought is to make it
> optional to write  btree nodes (possibly only for view index files?) using
> append_term_md5 instead of append_term.  It seems like a simple patch, but I
> don't know a priori what the performance hit would be.  Other thoughts?
> 
> Best, Adam

Re: silent view index file corruption

Posted by Randall Leeds <ra...@gmail.com>.
I immediately want to say 'ini file option' but I'm not sure whether to err
on safety or speed.

Maybe this is a good candidate for merkle trees or something else we can do
throughout the view tree that might less overhead than md5 summing all the
nodes? After all, most inner nodes shouldn't change most of the time. Some
incremental, cheap checksum might be a worthwhile *option*.

On Apr 6, 2010 6:04 PM, "Adam Kocoloski" <ko...@apache.org> wrote:

Hi all, we recently had an EC2 node go AWOL for about 12 hours.  When it
came back, we noticed after a few days that a number of the view indexes
stored on that node were not updating.  I did some digging into the error
logs and with Paul's help pieced together what was going on.  I won't bother
you with all the gory details unless you ask for them, but the gist of it is
that those files are corrupted.

The troubling thing for me is that we only discovered the corruption when it
completely broke the index updates.  In one case, it did this by rearranging
the bits so that couch_file thought that the btree node it was reading from
disk had an associated MD5 checksum. It didn't (no btree nodes do), and so
couch_file threw a file_corruption exception.  But if the corruption had
shown up in another part of the file I might never have known.  In fact,
some of the other indices on that node probably are silently corrupted.

You might wonder how likely it is that a file becomes corrupted but still
appears to be functioning.  I checked the last modified timestamps for three
broken files.  One was last modified when the node went down, but the other
two had timestamps in between the node's recovery and now.  To me, that
means that the view indexer was able to update those files for quite a while
(~2 days) before it bumped into a part of the btree that was corrupted.

I wonder what we should do about this.  My first thought is to make it
optional to write  btree nodes (possibly only for view index files?) using
append_term_md5 instead of append_term.  It seems like a simple patch, but I
don't know a priori what the performance hit would be.  Other thoughts?

Best, Adam