@@ -543,7 +543,10 @@ its upstream repository.
543
543
Current subtrees include:
544
544
545
545
- src/leveldb
546
- - Upstream at https://github.com/google/leveldb ; Maintained by Google, but open important PRs to Core to avoid delay
546
+ - Upstream at https://github.com/google/leveldb ; Maintained by Google, but
547
+ open important PRs to Core to avoid delay.
548
+ - ** Note** : Follow the instructions in [ Upgrading LevelDB] ( #upgrading-leveldb ) when
549
+ merging upstream changes to the leveldb subtree.
547
550
548
551
- src/libsecp256k1
549
552
- Upstream at https://github.com/bitcoin-core/secp256k1/ ; actively maintaned by Core contributors.
@@ -554,6 +557,52 @@ Current subtrees include:
554
557
- src/univalue
555
558
- Upstream at https://github.com/jgarzik/univalue ; report important PRs to Core to avoid delay.
556
559
560
+ Upgrading LevelDB
561
+ ---------------------
562
+
563
+ Extra care must be taken when upgrading LevelDB. This section explains issues
564
+ you must be aware of.
565
+
566
+ ### File Descriptor Counts
567
+
568
+ In most configurations we use the default LevelDB value for ` max_open_files ` ,
569
+ which is 1000 at the time of this writing. If LevelDB actually uses this many
570
+ file descriptors it will cause problems with Bitcoin's ` select() ` loop, because
571
+ it may cause new sockets to be created where the fd value is >= 1024. For this
572
+ reason, on 64-bit Unix systems we rely on an internal LevelDB optimization that
573
+ uses ` mmap() ` + ` close() ` to open table files without actually retaining
574
+ references to the table file descriptors. If you are upgrading LevelDB, you must
575
+ sanity check the changes to make sure that this assumption remains valid.
576
+
577
+ In addition to reviewing the upstream changes in ` env_posix.cc ` , you can use ` lsof ` to
578
+ check this. For example, on Linux this command will show open ` .ldb ` file counts:
579
+
580
+ ``` bash
581
+ $ lsof -p $( pidof bitcoind) | \
582
+ awk ' BEGIN { fd=0; mem=0; } /ldb$/ { if ($4 == "mem") mem++; else fd++ } END { printf "mem = %s, fd = %s\n", mem, fd}'
583
+ mem = 119, fd = 0
584
+ ```
585
+
586
+ The ` mem ` value shows how many files are mmap'ed, and the ` fd ` value shows you
587
+ many file descriptors these files are using. You should check that ` fd ` is a
588
+ small number (usually 0 on 64-bit hosts).
589
+
590
+ See the notes in the ` SetMaxOpenFiles() ` function in ` dbwrapper.cc ` for more
591
+ details.
592
+
593
+ ### Consensus Compatibility
594
+
595
+ It is possible for LevelDB changes to inadvertently change consensus
596
+ compatibility between nodes. This happened in Bitcoin 0.8 (when LevelDB was
597
+ first introduced). When upgrading LevelDB you should review the upstream changes
598
+ to check for issues affecting consensus compatibility.
599
+
600
+ For example, if LevelDB had a bug that accidentally prevented a key from being
601
+ returned in an edge case, and that bug was fixed upstream, the bug "fix" would
602
+ be an incompatible consensus change. In this situation the correct behavior
603
+ would be to revert the upstream fix before applying the updates to Bitcoin's
604
+ copy of LevelDB. In general you should be wary of any upstream changes affecting
605
+ what data is returned from LevelDB queries.
557
606
558
607
Git and GitHub tips
559
608
---------------------
0 commit comments