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

Read-only database opening does not work on a read-only context #176

Merged
merged 1 commit into from
Jul 12, 2023

Conversation

darnuria
Copy link
Contributor

@darnuria darnuria commented Jul 5, 2023

This pull-request purpose a non-regrettion+functional test for opening read_only databases and fix.

The issue was already fixed in #10 but regressed in c40afad6bbd223832a2f86c38702313beb78366bd30bbfcd6d014e8cc651dafe L30-L39

EDIT: edited PR to only describe the fix+test made a separate issue #183

@darnuria darnuria changed the title ReadOnly openning does not work on a multiprocess context errno: InvalidInput EINVAL code 22 ReadOnly database opening does not work on a multiprocess context errno: InvalidInput EINVAL code 22 Jul 5, 2023
@darnuria darnuria force-pushed the open_readdb_txn_not_commited branch from 0d7fd92 to 214c5dc Compare July 6, 2023 10:23
@darnuria
Copy link
Contributor Author

darnuria commented Jul 6, 2023

(rebased against main)

@darnuria
Copy link
Contributor Author

darnuria commented Jul 6, 2023

Hello, if you want to discuss it I am on element (preferred) or discord. :)

@Kerollmops
Copy link
Member

Hey @darnuria 👋

I will not have much time to help on this, but if you want more direct messages you can create a thread in #discussion of the Meilisearch Discord channel 😊

@darnuria
Copy link
Contributor Author

darnuria commented Jul 6, 2023

Hello, no problem! But it's a major blocker for release of 0.20.x since the open_database API is disfunctionnal (at least in multiprocess env). Will join the discord today! :)

EDIT: Not in a rush take time ! :D

Copy link
Member

@Kerollmops Kerollmops left a comment

Choose a reason for hiding this comment

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

Hey @darnuria 👋

Thank you for this PR. However, could you make the tests only run on the UNIX machines and add documentation on the RoTxn::commit method to make its utility explicit (and check English quality, before submitting 😅)?

heed/src/env.rs Outdated Show resolved Hide resolved
@darnuria
Copy link
Contributor Author

darnuria commented Jul 11, 2023

Thank you for this PR. However, could you make the tests only run on the UNIX machines

About the test (on my computer) it's quite complicated got multiprocess-deadlock since cargo test does thread multi-threaded within the same environment, upon forking we also... fork inherit the memory space of the parent and share the lock overs the environments. (It's not a direct problem if you don't open with heed not from the parent process-tree).

So I should force one-thread testing, fun that it passed CI!

the straceing lead to that dead_lock between close_env test and the new one!

[pid 266355] futex(0x5598f91a2b58, FUTEX_WAIT_BITSET_PRIVATE, 4294967295, {tv_sec=54071, tv_nsec=410305923}, FUTEX_BITSET_MATCH_ANY) = -1 ETIMEDOUT (Connection timed out)
   Compiling heed v0.20.0-alpha.2 ./heed/heed)
    Finished test [unoptimized + debuginfo] target(s) in 1.31s
     Running unittests src/lib.rs (target/debug/deps/heed-56be63de59924409)

running 17 tests
test env::tests::create_database_without_commit ... ok
test env::tests::open_database_with_nosubdir ... ok
test env::tests::open_env_with_named_path ... ok
test env::tests::reopen_env_with_different_options_is_err ... ok
test iter::tests::prefix_iter_last ... ok
test iter::tests::iter_last ... ok
test env::tests::open_already_existing_database ... ok
test env::tests::open_database_with_writemap_flag ... ok
test env::tests::resize_database ... ok
test mdb::lmdb_error::test::test_description ... ok
test tests::error_is_send_sync ... ok
test iter::tests::prefix_iter_with_byte_255 ... ok
test iter::tests::range_iter_last ... ok
test iter::tests::rev_prefix_iter_last ... ok
test iter::tests::rev_range_iter_last ... ok
test env::tests::close_env ... ok
test env::tests::open_already_existing_database_multiprocess has been running for over 60 seconds

Maybe just documentation about the txn::commit()? ^_^'

Will exclude that it's due to the tempfile that keep something open just to be sure.

The more 'ideal' solution would be to add examples to CI like suggest in #146 and check return code to have "read-world-complex test" but it also-show an issue with the current design in the case of a process-fork and share locks.

@Kerollmops
Copy link
Member

Is it related to this part of the documentation, and can we do anything about it apart from documenting it?

@darnuria darnuria changed the title ReadOnly database opening does not work on a multiprocess context errno: InvalidInput EINVAL code 22 ReadOnly database opening does not work on a read-only context lead errno: InvalidInput EINVAL code 22 Jul 11, 2023
@darnuria darnuria force-pushed the open_readdb_txn_not_commited branch 2 times, most recently from be032ca to 2161650 Compare July 11, 2023 15:58
heed/src/env.rs Outdated Show resolved Hide resolved
@darnuria darnuria force-pushed the open_readdb_txn_not_commited branch 3 times, most recently from 770d52d to 05e1734 Compare July 11, 2023 18:33
@darnuria
Copy link
Contributor Author

Should be ok, force-pushed some typo and clippy.

@darnuria
Copy link
Contributor Author

darnuria commented Jul 12, 2023

Yeah found a way to make the test relying on the same process space! It needs to be the only one having an Env I hope it didn't cause too much problems. But it's more usable than the forking way. :/

Edit: Removed the paste, I found a way to test what happens if open_database is not commited

Copy link
Member

@Kerollmops Kerollmops left a comment

Choose a reason for hiding this comment

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

Thank you for PR. I noticed some little English mistakes and a test to change a little bit 👌

heed/src/env.rs Outdated Show resolved Hide resolved
heed/src/txn.rs Outdated Show resolved Hide resolved
heed/src/env.rs Outdated Show resolved Hide resolved
@darnuria darnuria changed the title ReadOnly database opening does not work on a read-only context lead errno: InvalidInput EINVAL code 22 Fix #183 ReadOnly database opening does not work on a read-only context lead errno: InvalidInput EINVAL code 22 Jul 12, 2023
@Kerollmops Kerollmops changed the title Fix #183 ReadOnly database opening does not work on a read-only context lead errno: InvalidInput EINVAL code 22 ReadOnly database opening does not work on a read-only context Jul 12, 2023
@Kerollmops Kerollmops changed the title ReadOnly database opening does not work on a read-only context Read-only database opening does not work on a read-only context Jul 12, 2023
@darnuria darnuria force-pushed the open_readdb_txn_not_commited branch 6 times, most recently from 6c46e4d to f69d8fc Compare July 12, 2023 13:13
Opening of databases with Env::open_database() without previous Env in memory
with a RoTxn lead to the following error:
`Io(Os { code: 22, kind: InvalidInput, message: "Invalid argument" })`

It's due to the fact that RoTxn are not commited so the env->me_numdbs cannot be
updated and will be set to CORE_DB so 2.

It can trigger from multi-process setup, read-only opening, closing write
access, and re-opening from the same process.

Thanks to @Kerollmops for the typo and review.

Co-authored-by: Clément Renault <renault.cle@gmail.com>
@darnuria darnuria force-pushed the open_readdb_txn_not_commited branch from f69d8fc to e035849 Compare July 12, 2023 13:30
@darnuria darnuria requested a review from Kerollmops July 12, 2023 14:09
Copy link
Member

@Kerollmops Kerollmops left a comment

Choose a reason for hiding this comment

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

Thank you infinitely for your help on that and the documentation addition 😍

@Kerollmops Kerollmops merged commit e1377fc into meilisearch:main Jul 12, 2023
8 checks passed
@Kerollmops Kerollmops added this to the v0.20.0 milestone Jul 12, 2023
@darnuria darnuria deleted the open_readdb_txn_not_commited branch July 12, 2023 15:58
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.

None yet

2 participants