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

IMPROVE: Lock mechanism and migration to storage class for the maintain operation #5331

Merged
merged 5 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions aiida/cmdline/commands/cmd_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,8 @@ def storage_info(statistics):
storage = manager.get_profile_storage()

with spinner():
data = {
'database': get_database_summary(QueryBuilder, statistics),
'repository': storage.get_info(statistics=statistics),
}
data = storage.get_info(statistics=statistics)
data['database']['summary'] = get_database_summary(QueryBuilder, statistics)

echo.echo_dictionary(data, sort_keys=False, fmt='yaml')

Expand Down
3 changes: 2 additions & 1 deletion aiida/orm/implementation/storage_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def get_info(self, statistics: bool = False) -> dict:
flag to request more detailed information about the content of the storage.

:returns:
a nested dict with the relevant information.
a nested dict with the relevant information (with at least one key for `database`
and one for `repository`).
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is the abstract class, it should not require that these keys are present. There could be some storage that doesn't have a separate database and repository

Copy link
Member Author

Choose a reason for hiding this comment

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

Mmm ok, true, but as it is right now I need at least database to add the summary entry. Options for this:

  1. We just accept this description for now and once we deal with get_database_summary we change it.
  2. I put the output of get_database_summary in a separateoutput_dict['database_summary'] instead of output_dict['database']['summary'].
  3. I put the output of get_database_summary in output_dict['database'], risking overwriting what could come in that key from storage.get_info (which is currently empty).

Copy link
Member Author

Choose a reason for hiding this comment

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

Bah, there is also the option of adding the database key if it is not there. I will default to that now and push, let me know if you prefer one of the other 3.


"""
6 changes: 5 additions & 1 deletion aiida/storage/psql_dos/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,8 @@ def get_unreferenced_keyset(self, check_consistency: bool = True) -> Set[str]:

def get_info(self, statistics: bool = False) -> dict:
repository = self.get_repository()
return repository.get_info(statistics)
output_dict = {
'database': {},
'repository': repository.get_info(statistics),
}
return output_dict
9 changes: 7 additions & 2 deletions tests/storage/psql_dos/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,17 @@ def mock_get_info(self, statistics=False, **kwargs): # pylint: disable=unused-a
RepoBackendClass = get_manager().get_profile_storage().get_repository().__class__ # pylint: disable=invalid-name
monkeypatch.setattr(RepoBackendClass, 'get_info', mock_get_info)

repository_info_out = storage_backend.get_info()
storage_info_out = storage_backend.get_info()
assert 'database' in storage_info_out
assert 'repository' in storage_info_out

repository_info_out = storage_info_out['repository']
assert 'value' in repository_info_out
assert 'extra_value' not in repository_info_out
assert repository_info_out['value'] == 42

repository_info_out = storage_backend.get_info(statistics=True)
storage_info_out = storage_backend.get_info(statistics=True)
repository_info_out = storage_info_out['repository']
assert 'value' in repository_info_out
assert 'extra_value' in repository_info_out
assert repository_info_out['value'] == 42
Expand Down