Skip to content
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

[leap5] in undo tests, create undo_index in CB memory segment and remove removed_nodes_tracker #36

Merged
merged 2 commits into from
Jan 29, 2024

Conversation

spoonincode
Copy link
Member

Creating the undo_index on the stack (solely done in the undo tests) ultimately causes the index to contain a mixture of stack allocated and shared-memory allocated objects. Unfortunately I don't have an exact proof of how this happens but debugging through the structure's node_ptrs makes it quite clear it's occurring.

On Linux this typically is not a problem because the stack and shared-memory region tend to be very close to each other due to the implementation detail of where the mmap() is placed. However, on macOS, mmap()s get fulfilled from the "other direction": the stack will be at a high address where the mmap() will be placed at a very low address. This breaks the new compressed node_ptr structures and causes the test to crash.

It's possible to simulate this on Linux by forcing the chainbase shared memory to be located further away from the stack by gobbling up some VM space early, for example, just this line below and then run a simple test like the test_insert_fail will also crash on Linux.

diff --git a/src/pinnable_mapped_file.cpp b/src/pinnable_mapped_file.cpp
index a78cc6a..6786698 100644
--- a/src/pinnable_mapped_file.cpp
+++ b/src/pinnable_mapped_file.cpp
@@ -76,6 +76,7 @@ pinnable_mapped_file::pinnable_mapped_file(const std::filesystem::path& dir, boo
    _writable(writable),
    _sharable(mode == mapped)
 {
+   void* wut = mmap(nullptr, 16ull*1024*1024*1024*1024, PROT_NONE, MAP_PRIVATE | MAP_ANON, 0, 0);
    if(shared_file_size % _db_size_multiple_requirement) {
       std::string what_str("Database must be mulitple of " + std::to_string(_db_size_multiple_requirement) + " bytes");
       BOOST_THROW_EXCEPTION(std::system_error(make_error_code(db_error_code::bad_size), what_str));

Placing the undo_indexs in the shared memory region avoids the creation of mixed node_ptrs.

Unfortunately there still remains a similar issue in removed_nodes_tracker. I was unable to rectify this. But... removed_nodes_tracker is only used for a couple tests. I cannot find any harm in simply removing it?

fwiw a run on Leap with this branch is at,
https://github.com/AntelopeIO/leap/actions/runs/7493988034
as more clear evidence the removed code is unused.

Base automatically changed from more_ci_plats&san_leap5 to leap-5.0 January 29, 2024 15:54
@spoonincode spoonincode merged commit 21f6da1 into leap-5.0 Jan 29, 2024
14 checks passed
@spoonincode spoonincode deleted the undo_tests_seg_leap5 branch January 29, 2024 15:54
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.

3 participants