Add flag -dbtrimlogs to occasionally remove database logs #1004

pull dooglus wants to merge 1 commits into bitcoin:master from dooglus:dbtrimlogs changing 1 files +5 −2
  1. dooglus commented at 10:25 PM on March 28, 2012: contributor

    When set, -dbtrimlogs will delete old unused database log files every 5000 blocks. Otherwise several GB of logs build up while downloading the (1GB) blockchain, and are only deleted when the client exits.

    Fixes part of the bug #999. The QT client still sometimes crashes when it runs out of disk space.

  2. sipa commented at 10:39 PM on March 28, 2012: member

    Have you tested that this actually works? I've been playing for a few hours now with DB_LOG_REMOVE, DB_LOG_AUTO_REMOVE, closing all db files occasionally, checkpoinging, flushing, stopping and restarting DbEnv, ... but all I've seen are a lot of unexplainable segfauls, and not a single deleted logfile.

    EDIT: apparently it does. I'm baffled.

  3. gavinandresen commented at 10:59 PM on March 28, 2012: contributor

    Nice! I'm baffled, too.

    I don't think this should be a command-line option, though: I think it should just happen, I can't think of any reason to keep gigabytes of logs around.

  4. dooglus commented at 11:01 PM on March 28, 2012: contributor

    @sipa: I tested it a lot before making the pull request, yes. It seems to work well in db5.1.25. I don't have db4.x. @gavinandresen: I think the logs are so you can do database recovery in the event of a crash.

    It seems that in the event of a crash we usually manage to clean up the logs before exiting however :)

    I'll update my patch so it's not a command line option.

  5. Remove database log files that are no longer needed every 5000 blocks. f17aa66bd0
  6. sipa commented at 11:45 PM on March 28, 2012: member

    I'm testing a bit more extensive patch that counts the number of transactions updated or time since last flush as condition for flushing (instead of 5000 blocks), plus a few other changes. I'm benchmarking now.

    Thanks for showing this was possible at all - I had almost given up (seems there was a bug in my load-blocks-from-file patch that didn't call txn_checkpoint at all, which prevented log cleaning).

  7. dooglus commented at 12:33 AM on March 29, 2012: contributor

    No problem. I don't care what triggers the deletion so long as it's done occasionally.

    To arrange for rapid blockchain downloading to test this I've been using a second computer on the same LAN with a complete copy of the blockchain and connecting only to it.

  8. sipa commented at 12:43 AM on March 29, 2012: member

    Ok, one full load of the blockchain up to 172000 (from a local file) completed in 35 minutes. That's a few minutes slower than a previous benchmark, but it never needed more than 12 log files (of 10 MiB again). This did a log flush every 200k transactions (which was every 0.5-2 minutes). I'll post the code tomorrow.

  9. dooglus commented at 12:44 AM on March 29, 2012: contributor

    How much of that was spent loading the blocks 168000 to 172000? The last checkpoint being at 168k makes the last 4k blocks so much slower to load.

    How about adding a new checkpoint before the release of 0.6.0?

  10. gavinandresen commented at 1:59 AM on March 29, 2012: contributor

    grrr...

    So after WASTING time testing dbenv.set_flags(DB_LOG_AUTO_REMOVE, 1) this afternoon, I discover the correct call is actually log_set_config:

    dbenv.log_set_config(DB_LOG_AUTO_REMOVE, 1);

    Testing with a 10MB logfile size and the logs are automatically being cleaned up as the blockchain is downloading.

    (the set_flags call didn't trigger an error or warning because LOG_AUTO_REMOVE and AUTO_COMMIT share the same #define)

  11. sipa commented at 11:35 AM on March 29, 2012: member

    So there are three options now: a) remove logs at given points b) flush + remove logs at given points c) use auto remove.

    I wonder if there is any danger in using auto remove (meaning logs will be removed while transactions/databases are open). I suppose not.

    Gavin, how many log files were present at most at one given time during the block chain download?

  12. gavinandresen commented at 12:29 PM on March 29, 2012: contributor

    The most log files present at one given time with LOG_AUTO_REMOVE and 10M logfiles was 5.

    Typical is 2.

    Raw data (ls -l in the database/ dir run every 2 minutes): https://gist.github.com/2236954

  13. gavinandresen commented at 5:25 PM on March 29, 2012: contributor

    Thanks for the help Chris-- without this pull I think we would have given up hope of finding a good solution. But I'm going to close, because using AUTO_REMOVE (properly) is fewer lines of code.

  14. gavinandresen closed this on Mar 29, 2012

  15. suprnurd referenced this in commit ea99764baa on Dec 5, 2017
  16. ptschip referenced this in commit 05bc69c2f9 on Mar 15, 2018
  17. lateminer referenced this in commit 89b2d2f3e7 on Jan 22, 2019
  18. Bushstar referenced this in commit ff878bd496 on Oct 7, 2019
  19. lateminer referenced this in commit 75b8ad2ae5 on Oct 30, 2019
  20. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 21:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me