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

Warning for LMDB when library reopened #1000

Merged
merged 6 commits into from
Oct 27, 2023
Merged

Conversation

poodlewars
Copy link
Collaborator

@poodlewars poodlewars commented Oct 25, 2023

Reference Issues/PRs

#889 #520 #981

Also see PR #990 for which this is a followup.

What does this implement or fix?

It's only safe to open an LMDB database once from a given process. LMDB document this. It's because they rely on flock locking on the files, which is re-entrant within a process. This warns the user if they have multiple live Arctic instances over the same LMDB database.

We also:

  • Remove the psutil Python dep (which I considered using as an alternative solution here)
  • Put the _arctic_cfg special string down in the Native extension
  • Fix an issue with the Arctic API where it needlessly created an extra NativeVersionStore when creating a library. The new warning flagged this up.

@poodlewars poodlewars added the enhancement New feature or request label Oct 25, 2023
@poodlewars poodlewars changed the title Lmdb warning when library reopened Draft: Warning for LMDB when library reopened Oct 25, 2023
@joe-iddon joe-iddon mentioned this pull request Oct 26, 2023
5 tasks
@poodlewars poodlewars force-pushed the lmdb-warning-reopen branch 2 times, most recently from a723a8d to d54aec8 Compare October 26, 2023 16:38
An alternative approach for this PR was to use psutil to check which
files are held open by the process.

However psutil is actually not used for anything important, so I chose
instead to remove this Python dependency and make ArcticDB installation
easier for users as a result.
This is unsafe as it leaves the LMDB library temporarily opened
twice. There's a similar problem for RocksDB too.
Tests and compilation fixes
@poodlewars poodlewars marked this pull request as ready for review October 26, 2023 16:41
@poodlewars poodlewars changed the title Draft: Warning for LMDB when library reopened Warning for LMDB when library reopened Oct 26, 2023
Copy link
Collaborator

@joe-iddon joe-iddon left a comment

Choose a reason for hiding this comment

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

Presumably we'll have to have a warning for RocksDB too, so we should maybe create an issue to do that?

@@ -285,8 +285,8 @@ def create_library(self, name: str, library_options: Optional[LibraryOptions] =
if library_options is None:
library_options = LibraryOptions()

library = self._library_adapter.create_library(name, library_options)
self._library_manager.write_library_config(library._lib_cfg, name, self._library_adapter.get_masking_override())
cfg = self._library_adapter.get_library_config(name, library_options)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just noting that this will fix the PR for the RocksDB Python API #991

ac = Arctic(f"lmdb://{tmpdir}")

del ac
# should not warn
Copy link
Collaborator

Choose a reason for hiding this comment

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

Checking the warning is actually produced is carried out manually then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, checking the logging was super difficult and didn't seem worth it

def create_store_from_config(
cls, cfg, env, lib_name, open_mode=OpenMode.DELETE, encoding_version=EncodingVersion.V1
@staticmethod
def create_library_config(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This makes arctic.py much clearer now. There was no need to create a temporary Library just to get its config and delete it.

Comment on lines +351 to +358
LmdbStorage::LmdbStorage(LmdbStorage&& other) noexcept
: Storage(std::move(static_cast<Storage&>(other))),
write_mutex_(std::move(other.write_mutex_)),
env_(std::move(other.env_)),
dbi_by_key_type_(std::move(other.dbi_by_key_type_)),
lib_dir_(std::move(other.lib_dir_)) {
other.lib_dir_ = "";
}
Copy link
Collaborator

@joe-iddon joe-iddon Oct 27, 2023

Choose a reason for hiding this comment

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

Just noting that when Storages are made no move or copy in #991 I'll remove this move constructor. Is that going to be fine? It might mean the check of !lib_dir_.empty() in the destructor can go also, because lib_dir should always be passed something in the constructor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Proof of the pudding will be in the eating, but yeah that sounds good.

@poodlewars poodlewars merged commit b6911aa into master Oct 27, 2023
98 checks passed
@poodlewars poodlewars deleted the lmdb-warning-reopen branch October 27, 2023 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants