cli: `debug compact` unexpectedly runs out of disk
A user reports that debug compact is unexpectedly running out of disk space:
Error: IO error: No space left on device/var/lib/cockroachdb//150076.sst: No space left on device
Attempting to reproduce the problem, I created a 2.3GB storage directory, ran debug compact while in another terminal I ran du -sh in a loop every 0.25s:
2.3G cockroach-data/1/
2.4G cockroach-data/1/
2.5G cockroach-data/1/
2.3G cockroach-data/1/
2.5G cockroach-data/1/
2.6G cockroach-data/1/
2.7G cockroach-data/1/
2.9G cockroach-data/1/
2.3G cockroach-data/1/
2.5G cockroach-data/1/
2.6G cockroach-data/1/
2.8G cockroach-data/1/
2.9G cockroach-data/1/
3.0G cockroach-data/1/
2.5G cockroach-data/1/
2.4G cockroach-data/1/
2.5G cockroach-data/1/
It is unclear what is causing the disk space to fluctuate up and down. It is possible the creation of sstables is fighting with deletion. It is possible that sstables are being deleted synchronously and the temporary increases are due to pinning sstables that are being actively compacted.
It might be worthwhile to experiment with manually breaking up the single rocksdb::DB::CompactRange() call into multiple calls. Non-overlapping ranges can be computed from the keys delimiting sstables in the bottom-most level (see rocksdb::DB::GetSSTables).
Another data point. I saw disk usage sky rocket during compaction, nearly doubling the disk usage. Output from df -h below.
Initial:
/dev/mapper/root-cockroachdb 3.9G 1.5G 2.2G 41% /var/lib/cockroachdb
Peak while compacting:
/dev/mapper/root-cockroachdb 3.9G 2.7G 981M 74% /var/lib/cockroachdb