Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CouchDB should provide advice on safe use with BTRFS storage #4227

Open
ceremcem opened this issue Dec 19, 2020 · 10 comments
Open

CouchDB should provide advice on safe use with BTRFS storage #4227

ceremcem opened this issue Dec 19, 2020 · 10 comments

Comments

@ceremcem
Copy link
Contributor

ceremcem commented Dec 19, 2020

Summary

BTRFS filesystem does not play well with database files due to its Copy-on-Write feature. This kind of files should be created inside a folder whose CoW feature is turned off.

See https://btrfs.wiki.kernel.org/index.php/Gotchas#Fragmentation

Files with a lot of random writes can become heavily fragmented (10000+ extents) causing thrashing on HDDs and excessive multi-second spikes of CPU load on systems with an SSD or large amount a RAM.
On servers and workstations this affects databases and virtual machine images.

Disabling CoW for "data" folder on a BTRFS filesystem would be a wise move.

Possible Solution

Following script fixes the issue:

#!/bin/bash
set -eu

curr="/var/lib/couchdb"
new="$curr.new"

if lsattr $curr -a | grep /\.$ | grep -- "-C-" > /dev/null; then
    echo "CoW is already disabled for $curr. Doing nothing."
    exit 0
fi
systemctl stop couchdb
mkdir $new
chown couchdb:couchdb $new
chattr +C $new
rsync -avxHAX --info=progress2 $curr/ $new/
mv $curr $curr.bak
mv $new $curr
systemctl start couchdb

echo "---------------------------------------------"
echo "Changes made successfully."
echo "You can delete $curr.bak if everything works correctly."
echo "---------------------------------------------"
@wohali
Copy link
Member

wohali commented Dec 19, 2020

This looks like something that could go in our documentation. Would you be willing to write a PR for this?

@wohali wohali transferred this issue from apache/couchdb Dec 19, 2020
@ceremcem
Copy link
Contributor Author

I would expect CouchDB to make (or at least ask) that setting during the installation, but if you think that this is user's responsibility, then it's related to the documentation. I would love to create a PR for this.

@wohali
Copy link
Member

wohali commented Dec 19, 2020

I read the links a bit more carefully, so I want to ask: are you sure this is a problem for btrfs? Have you seen a significant CouchDB performance change when altering the file setting? Alternatively, what does filefrag say on those files on a system that has been in production for a while?

Unlike traditional SQL databases, CouchDB doesn't do random writes to its database files. It only ever appends to a file. (It is, in fact, a copy-on-write B-tree database itself, just like btrfs.) The link you gave suggests that this is only an issue for files that have lots of random writes. That never happens with CouchDB: it will only ever write to a disk block once.

Also, compaction will rewrite the database and all of its views/indexes to new files when necessary. CouchDB 3.x has a fairly aggressive compaction setting, meaning databases will get compacted if they see a lot of writes anyway. In this scenario, given the entire database & index files are rewritten as part of compaction, I wonder how bad the situation really is.

If this is really an issue (and I'm not saying it's not, I'd just like to be sure that it is), it is a pretty specific, narrow use case. In general, we don't detect or address this sort of thing automatically at installation or setup time. Given how long CouchDB's been around, and this is the first we're hearing of this, I'm guessing there's either not a problem (see above) or CouchDB+btrfs use in production is limited. (Most deployments I know of use ext4, xfs, or zfs.)


I would add this as a callout at this line, just before the "Installation from source" section. You can use a warning box, like this one.

I would not include the entire script, especially not with all of the moves/etc. We like to treat our users as capable system administrators, it should be enough to provide the basics. So I would say something like:

*Note*: On btrfs, performance is improved by disabling copy-on-write for the ``data/`` directory. This is done by moving the old directory aside, creating a new one, then setting `chattr +C` on it. You may want to copy your databases and indexes back over, if you have any data to keep.

That's only suggested text, please rewrite however you see fit.

@wohali
Copy link
Member

wohali commented Dec 19, 2020

And - thank you so much for helping us build and maintain CouchDB! 🥰👨‍🚀🏋️‍♀️

@ceremcem
Copy link
Contributor Author

ceremcem commented Dec 19, 2020

Have you seen a significant CouchDB performance change when altering the file setting? Alternatively, what does filefrag say on those files on a system that has been in production for a while?

This needs to be measured. Luckily I have a production setup on BTRFS where I forgot to change that CoW flag, so system was running without CoW flag disabled for a year. I was experiencing lots of interesting issues with database microservice, but that might not be related directly with this topic. Let's see.

CouchDB 3.x on my Laptop in LXC container (Debian Buster, freshly installed), with ~20K documents synced after chattr +C /var/lib/couchdb with the production server :

root@couchdb-erik:/var/lib# find couchdb -type f -exec filefrag {} \; 
couchdb/couchdb/_dbs.couch: 1 extent found
couchdb/couchdb/_nodes.couch: 1 extent found
couchdb/couchdb/shards/80000000-ffffffff/_users.1608348635.couch: 1 extent found
couchdb/couchdb/shards/80000000-ffffffff/_replicator.1608348637.couch: 1 extent found
couchdb/couchdb/shards/80000000-ffffffff/test.1608349285.couch: 1 extent found
couchdb/couchdb/shards/00000000-7fffffff/_users.1608348635.couch: 1 extent found
couchdb/couchdb/shards/00000000-7fffffff/_replicator.1608348637.couch: 1 extent found
couchdb/couchdb/shards/00000000-7fffffff/test.1608349285.couch: 1 extent found
couchdb/_dbs.couch: 5 extents found
couchdb/_nodes.couch: 1 extent found
couchdb/shards/80000000-ffffffff/_users.1608348635.couch: 1 extent found
couchdb/shards/80000000-ffffffff/_replicator.1608348637.couch: 3 extents found
couchdb/shards/80000000-ffffffff/test.1608349285.couch: 1 extent found
couchdb/shards/80000000-ffffffff/foo2.1608351797.couch: 2 extents found
couchdb/shards/80000000-ffffffff/foo2.1608353430.couch.compact.meta: 2 extents found
couchdb/shards/80000000-ffffffff/foo2.1608353430.couch: 31 extents found
couchdb/shards/00000000-7fffffff/_users.1608348635.couch: 1 extent found
couchdb/shards/00000000-7fffffff/_replicator.1608348637.couch: 18 extents found
couchdb/shards/00000000-7fffffff/test.1608349285.couch: 1 extent found
couchdb/shards/00000000-7fffffff/foo2.1608351797.couch: 2 extents found
couchdb/shards/00000000-7fffffff/foo2.1608353430.couch.compact.meta: 2 extents found
couchdb/shards/00000000-7fffffff/foo2.1608353430.couch: 20 extents found

CouchDB 3.x on my server in LXC container (Debian Buster, freshly installed), with ~20K documents synced after chattr +C /var/lib/couchdb with the production server :

root@aktos-couch4:/var/lib# find couchdb -type f -exec filefrag {} \;
couchdb/_dbs.couch: 2 extents found
couchdb/_nodes.couch: 1 extent found
couchdb/shards/80000000-ffffffff/_users.1608390062.couch: 1 extent found
couchdb/shards/80000000-ffffffff/_replicator.1608390062.couch: 3 extents found
couchdb/shards/80000000-ffffffff/foo2.1608390979.couch.compact.meta: 3 extents found
couchdb/shards/80000000-ffffffff/foo2.1608390979.couch: 922 extents found
couchdb/shards/00000000-7fffffff/_users.1608390062.couch: 1 extent found
couchdb/shards/00000000-7fffffff/_replicator.1608390062.couch: 1 extent found
couchdb/shards/00000000-7fffffff/foo2.1608390979.couch.compact.meta: 6 extents found
couchdb/shards/00000000-7fffffff/foo2.1608390979.couch: 290 extents found

CouchDB 2.x on my server in LXC container (Debian Stretch), with ~20K documents. This is my production server (where CoW is not disabled):

root@aktos-couch3:/var/lib# find couchdb -type f -exec filefrag {} \; | sort -t":" -k 2 -n -r
couchdb/shards/c0000000-dfffffff/foo2.1576202327.couch: 8882 extents found
couchdb/shards/40000000-5fffffff/foo2.1576202327.couch: 8707 extents found
couchdb/shards/80000000-9fffffff/foo2.1576202327.couch: 3514 extents found
couchdb/shards/60000000-7fffffff/foo2.1576202327.couch: 2336 extents found
couchdb/shards/a0000000-bfffffff/foo2.1576202327.couch: 2320 extents found
couchdb/shards/00000000-1fffffff/foo2.1576202327.couch: 2210 extents found
couchdb/shards/e0000000-ffffffff/foo2.1576202327.couch: 2186 extents found
couchdb/shards/20000000-3fffffff/foo2.1576202327.couch: 2041 extents found
couchdb/.shards/60000000-7fffffff/foo2.1576202327_design/mrview/ff377ba3dcf6801401e64c4b47ee91f0.view: 825 extents found
couchdb/.shards/60000000-7fffffff/foo2.1576202327_design/mrview/60c0365cb541a047d8841256fb5104af.view: 824 extents found
couchdb/.shards/60000000-7fffffff/foo2.1576202327_design/mrview/54f171fe1f24ac4eb52ac24c85f9d8fc.view: 824 extents found
couchdb/.shards/a0000000-bfffffff/foo2.1576202327_design/mrview/54f171fe1f24ac4eb52ac24c85f9d8fc.view: 814 extents found
couchdb/.shards/a0000000-bfffffff/foo2.1576202327_design/mrview/ff377ba3dcf6801401e64c4b47ee91f0.view: 811 extents found
couchdb/.shards/a0000000-bfffffff/foo2.1576202327_design/mrview/60c0365cb541a047d8841256fb5104af.view: 810 extents found
couchdb/.shards/40000000-5fffffff/foo2.1576202327_design/mrview/ff377ba3dcf6801401e64c4b47ee91f0.view: 806 extents found
couchdb/.shards/40000000-5fffffff/foo2.1576202327_design/mrview/60c0365cb541a047d8841256fb5104af.view: 805 extents found
couchdb/.shards/00000000-1fffffff/foo2.1576202327_design/mrview/ff377ba3dcf6801401e64c4b47ee91f0.view: 788 extents found
couchdb/.shards/00000000-1fffffff/foo2.1576202327_design/mrview/60c0365cb541a047d8841256fb5104af.view: 788 extents found
couchdb/.shards/00000000-1fffffff/foo2.1576202327_design/mrview/54f171fe1f24ac4eb52ac24c85f9d8fc.view: 788 extents found
couchdb/.shards/20000000-3fffffff/foo2.1576202327_design/mrview/ff377ba3dcf6801401e64c4b47ee91f0.view: 782 extents found
couchdb/.shards/20000000-3fffffff/foo2.1576202327_design/mrview/54f171fe1f24ac4eb52ac24c85f9d8fc.view: 780 extents found
couchdb/.shards/20000000-3fffffff/foo2.1576202327_design/mrview/60c0365cb541a047d8841256fb5104af.view: 779 extents found
couchdb/.shards/c0000000-dfffffff/foo2.1576202327_design/mrview/60c0365cb541a047d8841256fb5104af.view: 759 extents found
couchdb/.shards/c0000000-dfffffff/foo2.1576202327_design/mrview/ff377ba3dcf6801401e64c4b47ee91f0.view: 758 extents found
couchdb/.shards/e0000000-ffffffff/foo2.1576202327_design/mrview/ff377ba3dcf6801401e64c4b47ee91f0.view: 737 extents found
couchdb/.shards/e0000000-ffffffff/foo2.1576202327_design/mrview/60c0365cb541a047d8841256fb5104af.view: 737 extents found
couchdb/.shards/e0000000-ffffffff/foo2.1576202327_design/mrview/54f171fe1f24ac4eb52ac24c85f9d8fc.view: 737 extents found
couchdb/.shards/80000000-9fffffff/foo2.1576202327_design/mrview/60c0365cb541a047d8841256fb5104af.view: 705 extents found
couchdb/.shards/80000000-9fffffff/foo2.1576202327_design/mrview/ff377ba3dcf6801401e64c4b47ee91f0.view: 704 extents found
couchdb/.shards/80000000-9fffffff/foo2.1576202327_design/mrview/54f171fe1f24ac4eb52ac24c85f9d8fc.view: 703 extents found
couchdb/.shards/20000000-3fffffff/foo2.1576202327_design/mrview/efaeb757cdb9120e0d2d312a237f955c.view: 41 extents found
couchdb/.shards/e0000000-ffffffff/foo2.1576202327_design/mrview/903132c98329dd5618a69593f92f1088.view: 34 extents found
couchdb/.shards/60000000-7fffffff/foo2.1576202327_design/mrview/efaeb757cdb9120e0d2d312a237f955c.view: 33 extents found
couchdb/shards/e0000000-ffffffff/demo.1576774963.couch: 32 extents found
couchdb/.shards/c0000000-dfffffff/foo2.1576202327_design/mrview/efaeb757cdb9120e0d2d312a237f955c.view: 32 extents found
couchdb/shards/c0000000-dfffffff/demo.1576774963.couch: 32 extents found
couchdb/shards/80000000-9fffffff/demo.1576774963.couch: 32 extents found
couchdb/shards/40000000-5fffffff/demo.1576774963.couch: 32 extents found
couchdb/shards/20000000-3fffffff/demo.1576774963.couch: 32 extents found
couchdb/shards/a0000000-bfffffff/demo.1576774963.couch: 31 extents found
couchdb/shards/60000000-7fffffff/demo.1576774963.couch: 31 extents found
couchdb/shards/00000000-1fffffff/demo.1576774963.couch: 31 extents found
couchdb/.shards/60000000-7fffffff/foo2.1576202327_design/mrview/77698c399d7c398c3fa2221d547b559a.view: 29 extents found
couchdb/.shards/e0000000-ffffffff/foo2.1576202327_design/mrview/77698c399d7c398c3fa2221d547b559a.view: 28 extents found
couchdb/shards/c0000000-dfffffff/_global_changes.1576197947.couch: 26 extents found
couchdb/.shards/00000000-1fffffff/foo2.1576202327_design/mrview/efaeb757cdb9120e0d2d312a237f955c.view: 26 extents found
couchdb/.shards/20000000-3fffffff/foo2.1576202327_design/mrview/903132c98329dd5618a69593f92f1088.view: 25 extents found
couchdb/.shards/80000000-9fffffff/foo2.1576202327_design/mrview/9e6552c45632f3e05a6ae72915e96b9b.view: 24 extents found
couchdb/.shards/c0000000-dfffffff/foo2.1576202327_design/mrview/54f171fe1f24ac4eb52ac24c85f9d8fc.view: 23 extents found
couchdb/.shards/a0000000-bfffffff/foo2.1576202327_design/mrview/1f3dc3019c5156f2aa66ab47248add61.view: 22 extents found
couchdb/.shards/80000000-9fffffff/foo2.1576202327_design/mrview/efaeb757cdb9120e0d2d312a237f955c.view: 21 extents found
couchdb/.shards/80000000-9fffffff/foo2.1576202327_design/mrview/1f3dc3019c5156f2aa66ab47248add61.view: 21 extents found
couchdb/.shards/00000000-1fffffff/foo2.1576202327_design/mrview/1f3dc3019c5156f2aa66ab47248add61.view: 21 extents found
couchdb/.shards/e0000000-ffffffff/foo2.1576202327_design/mrview/efaeb757cdb9120e0d2d312a237f955c.view: 19 extents found
couchdb/.shards/e0000000-ffffffff/foo2.1576202327_design/mrview/1f3dc3019c5156f2aa66ab47248add61.view: 19 extents found
couchdb/.shards/a0000000-bfffffff/foo2.1576202327_design/mrview/903132c98329dd5618a69593f92f1088.view: 19 extents found
couchdb/.shards/40000000-5fffffff/foo2.1576202327_design/mrview/9e6552c45632f3e05a6ae72915e96b9b.view: 19 extents found
couchdb/.shards/40000000-5fffffff/foo2.1576202327_design/mrview/37b94f6b5836a143c9db7b8a9caf45b9.view: 19 extents found
couchdb/.shards/80000000-9fffffff/foo2.1576202327_design/mrview/37b94f6b5836a143c9db7b8a9caf45b9.view: 18 extents found
couchdb/.shards/e0000000-ffffffff/foo2.1576202327_design/mrview/9e6552c45632f3e05a6ae72915e96b9b.view: 15 extents found
couchdb/.shards/a0000000-bfffffff/foo2.1576202327_design/mrview/37b94f6b5836a143c9db7b8a9caf45b9.view: 15 extents found
couchdb/.shards/40000000-5fffffff/foo2.1576202327_design/mrview/77698c399d7c398c3fa2221d547b559a.view: 15 extents found
couchdb/.shards/60000000-7fffffff/foo2.1576202327_design/mrview/9e6552c45632f3e05a6ae72915e96b9b.view: 14 extents found
couchdb/.shards/20000000-3fffffff/foo2.1576202327_design/mrview/37b94f6b5836a143c9db7b8a9caf45b9.view: 13 extents found
couchdb/.shards/c0000000-dfffffff/foo2.1576202327_design/mrview/1f3dc3019c5156f2aa66ab47248add61.view: 12 extents found
couchdb/.shards/60000000-7fffffff/foo2.1576202327_design/mrview/37b94f6b5836a143c9db7b8a9caf45b9.view: 12 extents found
couchdb/.shards/a0000000-bfffffff/foo2.1576202327_design/mrview/efaeb757cdb9120e0d2d312a237f955c.view: 9 extents found
couchdb/.shards/80000000-9fffffff/foo2.1576202327_design/mrview/77698c399d7c398c3fa2221d547b559a.view: 9 extents found
couchdb/.shards/e0000000-ffffffff/foo2.1576202327_design/mrview/37b94f6b5836a143c9db7b8a9caf45b9.view: 8 extents found
couchdb/.shards/80000000-9fffffff/foo2.1576202327_design/mrview/903132c98329dd5618a69593f92f1088.view: 8 extents found
couchdb/.shards/60000000-7fffffff/foo2.1576202327_design/mrview/1f3dc3019c5156f2aa66ab47248add61.view: 8 extents found
couchdb/.shards/20000000-3fffffff/foo2.1576202327_design/mrview/77698c399d7c398c3fa2221d547b559a.view: 8 extents found
couchdb/.shards/00000000-1fffffff/foo2.1576202327_design/mrview/903132c98329dd5618a69593f92f1088.view: 8 extents found
couchdb/.shards/40000000-5fffffff/foo2.1576202327_design/mrview/54f171fe1f24ac4eb52ac24c85f9d8fc.view: 7 extents found
couchdb/.shards/40000000-5fffffff/foo2.1576202327_design/mrview/903132c98329dd5618a69593f92f1088.view: 6 extents found
couchdb/.shards/00000000-1fffffff/foo2.1576202327_design/mrview/9e6552c45632f3e05a6ae72915e96b9b.view: 6 extents found
couchdb/shards/e0000000-ffffffff/_global_changes.1576197947.couch: 5 extents found
couchdb/.shards/a0000000-bfffffff/foo2.1576202327_design/mrview/9e6552c45632f3e05a6ae72915e96b9b.view: 5 extents found
couchdb/.shards/c0000000-dfffffff/foo2.1576202327_design/mrview/9e6552c45632f3e05a6ae72915e96b9b.view: 4 extents found
couchdb/.shards/c0000000-dfffffff/foo2.1576202327_design/mrview/37b94f6b5836a143c9db7b8a9caf45b9.view: 4 extents found
couchdb/.shards/60000000-7fffffff/foo2.1576202327_design/mrview/903132c98329dd5618a69593f92f1088.view: 4 extents found
couchdb/.shards/40000000-5fffffff/foo2.1576202327_design/mrview/efaeb757cdb9120e0d2d312a237f955c.view: 4 extents found
couchdb/.shards/40000000-5fffffff/foo2.1576202327_design/mrview/1f3dc3019c5156f2aa66ab47248add61.view: 4 extents found
couchdb/.shards/20000000-3fffffff/foo2.1576202327_design/mrview/9e6552c45632f3e05a6ae72915e96b9b.view: 4 extents found
couchdb/.shards/20000000-3fffffff/foo2.1576202327_design/mrview/1f3dc3019c5156f2aa66ab47248add61.view: 4 extents found
couchdb/shards/60000000-7fffffff/_global_changes.1576197947.couch: 3 extents found
couchdb/.shards/00000000-1fffffff/foo2.1576202327_design/mrview/77698c399d7c398c3fa2221d547b559a.view: 3 extents found
couchdb/_dbs.couch: 3 extents found
couchdb/.shards/c0000000-dfffffff/foo2.1576202327_design/mrview/77698c399d7c398c3fa2221d547b559a.view: 2 extents found
couchdb/.shards/a0000000-bfffffff/foo2.1576202327_design/mrview/77698c399d7c398c3fa2221d547b559a.view: 2 extents found
couchdb/shards/80000000-9fffffff/_global_changes.1576197947.couch: 2 extents found
couchdb/shards/20000000-3fffffff/_global_changes.1576197947.couch: 2 extents found
couchdb/shards/00000000-1fffffff/_users.1576197947.couch: 2 extents found
couchdb/.shards/00000000-1fffffff/foo2.1576202327_design/mrview/37b94f6b5836a143c9db7b8a9caf45b9.view: 2 extents found
couchdb/._users_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/_users.couch: 1 extent found
couchdb/.shards/e0000000-ffffffff/_users.1576197947_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/shards/e0000000-ffffffff/_users.1576197947.couch: 1 extent found
couchdb/.shards/e0000000-ffffffff/_replicator.1576197947_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/shards/e0000000-ffffffff/_replicator.1576197947.couch: 1 extent found
couchdb/.shards/e0000000-ffffffff/demo.1576774963_design/mrview/c12a4679354f40965b2fac59260bad86.view: 1 extent found
couchdb/.shards/c0000000-dfffffff/_users.1576197947_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/shards/c0000000-dfffffff/_users.1576197947.couch: 1 extent found
couchdb/.shards/c0000000-dfffffff/foo2.1576202327_design/mrview/903132c98329dd5618a69593f92f1088.view: 1 extent found
couchdb/.shards/c0000000-dfffffff/_replicator.1576197947_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/shards/c0000000-dfffffff/_replicator.1576197947.couch: 1 extent found
couchdb/.shards/c0000000-dfffffff/demo.1576774963_design/mrview/c12a4679354f40965b2fac59260bad86.view: 1 extent found
couchdb/.shards/a0000000-bfffffff/_users.1576197947_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/shards/a0000000-bfffffff/_users.1576197947.couch: 1 extent found
couchdb/.shards/a0000000-bfffffff/_replicator.1576197947_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/shards/a0000000-bfffffff/_replicator.1576197947.couch: 1 extent found
couchdb/shards/a0000000-bfffffff/_global_changes.1576197947.couch: 1 extent found
couchdb/.shards/a0000000-bfffffff/demo.1576774963_design/mrview/c12a4679354f40965b2fac59260bad86.view: 1 extent found
couchdb/.shards/80000000-9fffffff/_users.1576197947_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/shards/80000000-9fffffff/_users.1576197947.couch: 1 extent found
couchdb/.shards/80000000-9fffffff/_replicator.1576197947_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/shards/80000000-9fffffff/_replicator.1576197947.couch: 1 extent found
couchdb/.shards/80000000-9fffffff/demo.1576774963_design/mrview/c12a4679354f40965b2fac59260bad86.view: 1 extent found
couchdb/.shards/60000000-7fffffff/_users.1576197947_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/shards/60000000-7fffffff/_users.1576197947.couch: 1 extent found
couchdb/.shards/60000000-7fffffff/_replicator.1576197947_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/shards/60000000-7fffffff/_replicator.1576197947.couch: 1 extent found
couchdb/.shards/60000000-7fffffff/demo.1576774963_design/mrview/c12a4679354f40965b2fac59260bad86.view: 1 extent found
couchdb/.shards/40000000-5fffffff/_users.1576197947_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/shards/40000000-5fffffff/_users.1576197947.couch: 1 extent found
couchdb/.shards/40000000-5fffffff/_replicator.1576197947_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/shards/40000000-5fffffff/_replicator.1576197947.couch: 1 extent found
couchdb/shards/40000000-5fffffff/_global_changes.1576197947.couch: 1 extent found
couchdb/.shards/40000000-5fffffff/demo.1576774963_design/mrview/c12a4679354f40965b2fac59260bad86.view: 1 extent found
couchdb/.shards/20000000-3fffffff/_users.1576197947_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/shards/20000000-3fffffff/_users.1576197947.couch: 1 extent found
couchdb/.shards/20000000-3fffffff/_replicator.1576197947_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/shards/20000000-3fffffff/_replicator.1576197947.couch: 1 extent found
couchdb/.shards/20000000-3fffffff/demo.1576774963_design/mrview/c12a4679354f40965b2fac59260bad86.view: 1 extent found
couchdb/.shards/00000000-1fffffff/_users.1576197947_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/.shards/00000000-1fffffff/_replicator.1576197947_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/shards/00000000-1fffffff/_replicator.1576197947.couch: 1 extent found
couchdb/shards/00000000-1fffffff/_global_changes.1576197947.couch: 1 extent found
couchdb/.shards/00000000-1fffffff/demo.1576774963_design/mrview/c12a4679354f40965b2fac59260bad86.view: 1 extent found
couchdb/._replicator_design/mrview/3e823c2a4383ac0c18d4e574135a5b08.view: 1 extent found
couchdb/_replicator.couch: 1 extent found
couchdb/_nodes.couch: 1 extent found

How should we interpret those results?

@wohali
Copy link
Member

wohali commented Dec 26, 2020

Hm, that's more extents, but it doesn't look terrible. And 3.x will be doing more aggressive compaction than 2.x, so we're also seeing version vs. version bias here (and 2.x is end-of-life).

I'm reading that just adding -o autodefrag to the data mount may be a better choice here. "autodefrag does help, performance impact is minor at best on everyday systems." But this data is also 7 years old, so I don't know how things have progressed since then. A recent reddit post agrees.

Or it might be acceptable to simply run btrfs filesystem defragment ...

This is definitely a finer point of tuning, and while I can see that this would be useful info for CouchDB users, it's not something I'd call out as critical in the installation section. Maybe this would be better to put in the best practices under the "if it ain't broke, don't fix it" approach? I'll definitely merge a PR if it shows up, I'm just not sure we have enough data here to define this as a best practice.

@ceremcem
Copy link
Contributor Author

ceremcem commented Dec 26, 2020

I'm having an interesting trouble here, as the script I provided in my first post worked just well on my laptop (CouchDB-3.x on Debian-Buster on LXC on my-laptop which uses BTRFS), however, CouchDB-2.x refuses to build views on my production server when I applied those changes. I'm on it and I'll provide the tested directions ASAP.

btrfs fs defrag has a disadvantage of causing data bloat, so I avoid using it. See this.

it's not something I'd call out as critical in the installation section.

Well, it's hard for me to clearly state anything, but I've a feeling that this is a critical matter. I experienced a disk failure where my server got unresponsive (naturally). When I tried to recover any data I could, I realized that the corrupted files were especially belonged to CouchDB (this might be a coincidence, I'm aware). See this and this:

I was wondering
if insisting CouchDB on BTRFS would eventually cause a failure or not,
so this corrupted files list might help shedding the light on the
cause: https://gist.github.com/ceremcem/b507be2669682857f37039eb9655d7ad

I'll be get in touch as soon as I solve the puzzle.

@wohali
Copy link
Member

wohali commented Dec 27, 2020

Looking forward to it, let us know. I'm going to be away for a few days, so I can get back to this in January.

Your post on linux-btrfs and your gist suggest your root cause is disk failure to me. CouchDB insists on fsync() after every write (unconditionally in 3.x, and in 2.x by default unless you disable a poorly documented setting).

Happy Holidays!

@wohali
Copy link
Member

wohali commented Mar 29, 2021

@ceremcem Any progress on this, especially with 3.x? We're preparing for a 3.2 release, so you've got maybe 2 weeks to get a doc suggestion in before then.

The easy thing to do would be recommending the use of -o autodefrag; if that is insufficient, we may simply add a "do not use CouchDB on a BTRFS volume" warning as a known issue, and leave it at that.

@wohali wohali changed the title CouchDB should be BTRFS aware CouchDB should provide advice on safe use with BTRFS storage Mar 29, 2021
@ceremcem
Copy link
Contributor Author

Hi @wohali. I just didn't spare time to debug any further. I got the schedule, I'll do my best.

@big-r81 big-r81 transferred this issue from apache/couchdb-documentation Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants