-
Notifications
You must be signed in to change notification settings - Fork 35.7k
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
kernel: Prune leveldb headers #28186
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
Concept ACK. |
Concept ACK |
Not sure about the motivation. I don't think any user should include the dbwrapper either? No user should be directly writing or reading from the db. The only reason why they'd have to include the header is to get access to And if you are worried about the |
It's hard to speculate on how this will be used in the future. Something calling the db directly for e.g. data science use cases would not be unheard of.
I am also thinking about the |
Thanks, makes sense. I initially wondered about the 15 commits and +100 LOC, but having more commits for this template-heavy code makes it easier to review, and I found a way to reduce the number of LOC. Just a style nit though, feel free to ignore. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
review ACK 0280dc4 🔨
Show signature
Signature:
untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: review ACK 0280dc44d227ae34e8fcbb708833bfe9d66c7b5f 🔨
EwQOJEQzugff502JSeduHe1I8VbH7Du0bAvETIvbAxyKfRuGdPQJ9HgpXRv4wHXJz97qTnvIhTIdbkKbnucEAg==
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also checked that all the intermediate commits compile and pass the tests (on Ubuntu 23.04).
I'm not familiar with the LevelBD code, but the refactor makes sense to me.
I'll look at 6005165 later since it might get simplified based on @MarcoFalke's suggestion.
0280dc4
to
e8a3a0a
Compare
Thank you for the reviews @Sjors and @MarcoFalke, Updated 0280dc4 -> e8a3a0a (cleaveLeveldbHeaders_0 -> cleaveLeveldbHeaders_1, compare)
|
re-ACK e8a3a0a 🗞 Show signatureSignature:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK e8a3a0a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK, did a first run-through of the code but will dig into it deeper.
src/dbwrapper.h
Outdated
@@ -237,6 +236,7 @@ class CDBWrapper | |||
bool m_is_memory; | |||
|
|||
bool ReadImpl(std::function<void(DataStream&)> write_key_to_stream, std::function<void(CDataStream&)> read_value_from_stream) const; | |||
bool ExistsImpl(DataStream& ssKey) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: const DataStream& ssKey
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style nit: const DataStream&
seems fine here, but if you want to pass an immutable view of raw bytes, Span<const std::byte>
may be better. (Span{ssKey}
should do the conversion, but it will likely happen implicitly by the compiler already).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, CharCast
can be moved to the cpp file in the last commit, if you want
Wrap leveldb::DestroyDB in a helper function without exposing leveldb-specifics. Also, add missing optional include. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
e8a3a0a
to
8c4481e
Compare
Thank you for the review @stickies-v, Updated e8a3a0a -> 8c4481e (cleaveLeveldbHeaders_1 -> cleaveLeveldbHeaders_2, compare)
|
8c4481e
to
f263967
Compare
Thank you for the re-review @MarcoFalke, Updated 8c4481e -> f263967 (cleaveLeveldbHeaders_2 -> cleaveLeveldbHeaders_3, compare)
|
src/dbwrapper.cpp
Outdated
size_estimate = 0; | ||
} | ||
|
||
void CDBBatch::WriteImpl(const Span<const std::byte>& key, CDataStream& ssValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void CDBBatch::WriteImpl(const Span<const std::byte>& key, CDataStream& ssValue) | |
void CDBBatch::WriteImpl(Span<const std::byte> ssKey, CDataStream& ssValue) |
Span is cheap to copy, so there is no need to add const&
. Also, it would be better to do the renames in a separate commit. (Maybe at the end for all touched lines in this pull, or not at all). Otherwise, this breaks review options such as --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
f263967
to
3fb2dac
Compare
Updated f263967 -> 3fb2dac (cleaveLeveldbHeaders_3 -> cleaveLeveldbHeaders_4, compare)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
light crACK 3fb2dac
options = GetOptions(params.cache_bytes); | ||
options.create_if_missing = true; | ||
m_db_context = std::make_unique<LevelDBContext>(); | ||
DBContext().penv = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Would this be an improvement, to highlight the reference nature of db_context
, as well as I think generally it's slightly cleaner to not call DBContext()
every time (I know it's a very cheap call)? Not sure though, would be a lot of change, happy to keep as is.
DBContext().penv = nullptr; | |
auto& db_context{DBContext()}; | |
db_context.penv = nullptr; |
delete DBContext().pdb; | ||
DBContext().pdb = nullptr; | ||
delete DBContext().options.filter_policy; | ||
DBContext().options.filter_policy = nullptr; | ||
delete DBContext().options.info_log; | ||
DBContext().options.info_log = nullptr; | ||
delete DBContext().options.block_cache; | ||
DBContext().options.block_cache = nullptr; | ||
delete DBContext().penv; | ||
DBContext().options.env = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: would it make sense to move this to the LevelDBContext
destructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would, but then we'd also have to forward-declare a destructor class for it and I don't think it's really worth doing that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. Can easily improve later if/when necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 3fb2dac
I would however strongly prefer to simplify the lambda logic, and probably this duplication should also be removed.
Keep the generic serialization in the header, while moving leveldb-specifics to the implementation file. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
Keep the generic serialization in the header, while moving leveldb-specifics to the implementation file. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
Hide the leveldb::WriteBatch member variable with a pimpl in order not to expose it directly in the header. Also move CDBBatch::Clear to the dbwrapper implementation to use the new impl_batch. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
Keep the generic serialization in the header, while moving leveldb-specifics to the implementation file. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
Keep the generic serialization in the header, while moving leveldb-specifics to the implementation file. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
Keep the generic serialization in the header, while moving leveldb-specifics to the implementation file. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
Hide the leveldb::Iterator member variable with a pimpl in order not to expose it directly in the header. Also, move CDBWrapper::NewIterator to the dbwrapper implementation to use the pimpl for CDBIterator initialziation. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
Keep the generic serialization in the header, while moving leveldb-specifics to the implementation file. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
These were uncovered as missing by the next commit.
Keep the generic serialization in the header, while moving leveldb-specifics to the implementation file. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
Make it a static function in dbwrapper.cpp, since it is not used elsewhere and when left in the header, would expose a leveldb type. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
Keep the generic serialization in the header, while moving leveldb-specifics to the implementation file. Since CharCast is no longer needed in the header, move it to the implementation file. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
Since leveldb is no longer in our header tree, move its include flags to whereever dbwrapper.cpp is built.
The ss- prefix should connotate a DataStream variable. Now that these variables are byte spans, drop the prefix.
3fb2dac
to
1be0472
Compare
Thank you for the review @stickies-v, Updated 3fb2dac -> 1be0472 (cleaveLeveldbHeaders_4 -> cleaveLeveldbHeaders_5, compare)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK 1be0472
nit: these don't seem to actually have been addressed
Addressed @stickies-v's #28186 (comment) and #28186 (comment), added some line breaks in constructor lists.
1be0472
to
d8f1222
Compare
Updated 1be0472 -> d8f1222 (cleaveLeveldbHeaders_5 -> cleaveLeveldbHeaders_6, compare) Sorry for the re-push @stickies-v, did not include two changes in my previous push by mistake that should have addressed your latest comments. Pushed now. |
re-ACK d8f1222 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK d8f1222 🔠
Show signature
Signature:
untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: ACK d8f1222ac50f089a0af29eaf8ce0555bad8366ef 🔠
9kmrmmglu0pLTAnlkFVLGRaV07BiskXJWhuBAXoJ8FtylkMHfRojj+S77g6nhGaMuZlTOzX7YETCJ4ZtX4yEAw==
CDBBatch::CDBBatch(const CDBWrapper& _parent) : parent(_parent), | ||
m_impl_batch{std::make_unique<CDBBatch::WriteBatchImpl>()}, | ||
ssValue(SER_DISK, CLIENT_VERSION){}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style nit in ea8135d: May be better to add a newline before :
to reduce the leading whitespace bloating block.
@@ -365,11 +388,12 @@ struct CDBIterator::IteratorImpl { | |||
explicit IteratorImpl(leveldb::Iterator* _iter) : iter{_iter} {} | |||
}; | |||
|
|||
CDBIterator::CDBIterator(const CDBWrapper& _parent, std::unique_ptr<IteratorImpl> _piter) : parent(_parent), m_impl_iter(std::move(_piter)) {} | |||
CDBIterator::CDBIterator(const CDBWrapper& _parent, std::unique_ptr<IteratorImpl> _piter) : parent(_parent), | |||
m_impl_iter(std::move(_piter)) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c95b37d: same
Leveldb headers are currently included in the
dbwrapper.h
file and thus available to many of Bitcoin Core's source files. However, leveldb-specific functionality should be abstracted by thedbwrapper
and does not need to be available to the rest of the code. Having leveldb included in a widely-used header such asdbwrapper.h
bloats the entire project's header tree.The
dbwrapper
is a key component of the libbitcoinkernel library. Future users of this library would not want to contend with having the leveldb headers exposed and potentially polluting their project's namespace.For these reasons, the leveldb headers are removed from the
dbwrapper
by moving leveldb-specific code to the implementation file and creating a pimpl where leveldb member variables are indispensable. As a final step, the leveldb include flags are removed from theBITCOIN_INCLUDES
and moved to places where the dbwrapper is compiled.This pull request is part of the libbitcoinkernel project, and more specifically its stage 1 step 3 "Decouple most non-consensus headers from libbitcoinkernel".