Skip to content

Conversation

@l0rinc
Copy link
Contributor

@l0rinc l0rinc commented Jan 12, 2025

To help with to debugging and traceability (in alignment with displaying other non-default args such as Command-line arg: dbcache="10000") we can extend the LevelDB opening log with an additional debug message for the used non-default settings.

To avoid showing booleans as e.g. create_if_missing=1, I've added a local ToString lambda for bool.
I wanted to use util::Join at the end, but couldn't find any way that I liked.

Example output after the change:

2025-10-15T02:39:45Z Opened LevelDB successfully
2025-10-15T02:39:45Z [leveldb] startup options: options.compression=NoCompression, options.create_if_missing=true, options.max_file_size=33554432, options.paranoid_checks=true, options.write_buffer_size=524288, readoptions.fill_cache=false, readoptions.verify_checksums=true, writeoptions.sync=true

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 12, 2025

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31644.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK pablomartin4btc

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

@l0rinc l0rinc force-pushed the l0rinc/leveldb-options-logging branch from 64b1bf4 to 8af25b0 Compare January 12, 2025 17:45
@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed.
Debug: https://github.com/bitcoin/bitcoin/runs/35494695770

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@luke-jr
Copy link
Member

luke-jr commented Jan 14, 2025

How is this useful?

@l0rinc
Copy link
Contributor Author

l0rinc commented Jan 16, 2025

How is this useful?

I've extended the description with more details.

Details
2025-01-16T10:47:35Z Opening LevelDB in /Users/lorinc/Library/Application Support/Bitcoin/blocks/index
2025-01-16T10:47:35Z Opened LevelDB successfully with options: options.compression=NoCompression, options.create_if_missing=true, options.max_file_size=33554432, options.paranoid_checks=true, options.write_buffer_size=524288, readoptions.fill_cache=false, readoptions.verify_checksums=true, writeoptions.sync=true
...
2025-01-16T10:47:51Z Opening LevelDB in /Users/lorinc/Library/Application Support/Bitcoin/chainstate
2025-01-16T10:47:51Z Opened LevelDB successfully with options: options.compression=NoCompression, options.create_if_missing=true, options.max_file_size=33554432, options.paranoid_checks=true, options.write_buffer_size=2097152, readoptions.fill_cache=false, readoptions.verify_checksums=true, writeoptions.sync=true

E.g. dbwrapper_tests/dbwrapper shows

options.compression=NoCompression, options.create_if_missing=true, options.max_file_size=33554432, options.paranoid_checks=true, options.write_buffer_size=262144, readoptions.fill_cache=false, readoptions.verify_checksums=true, writeoptions.sync=true

Logging the non-default LevelDB options during initialization makes it easier to understand and debug database behavior. For example, the blocks/index and chainstate databases already use different write_buffer_size values (512KiB vs. 2MiB) - optimized for their specific workloads (which are expected to diverge further the more we fine-tune them).

Logging these differences helps trace configuration changes, especially when command-line arguments (such as -dbcache or -dbbatchsize) can influence the settings.

Copy link
Member

@pablomartin4btc pablomartin4btc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

Perhaps the legend "with options: ..." could be debug log? Ideally in the same line but I don't think we support it actually. As an alternative (haven't tested it) maybe:

const bool log_options = LogAcceptCategory(BCLog::LEVELDB, BCLog::Level::Debug);

LogInfo("Opened LevelDB successfully%s", 
    log_options
        ? tfm::format(" with options: %s", GetChangedOptions(DBContext()))
        : "");

@l0rinc l0rinc force-pushed the l0rinc/leveldb-options-logging branch from aac1585 to 583645c Compare October 15, 2025 02:34
@l0rinc
Copy link
Contributor Author

l0rinc commented Oct 15, 2025

Thanks for the hint @pablomartin4btc, I kept the original line and added and extra debug log, when starting with -debug=leveldb.

Example output, if started with `-debug=leveldb`:
> Opened LevelDB successfully
> [leveldb] startup options: options.compression=NoCompression, options.create_if_missing=true, options.max_file_size=33554432, options.paranoid_checks=true, options.write_buffer_size=524288, readoptions.fill_cache=false, readoptions.verify_checksums=true, writeoptions.sync=true
@l0rinc l0rinc force-pushed the l0rinc/leveldb-options-logging branch from 583645c to 897a578 Compare October 15, 2025 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants