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

Profile: only initialise the repository during the migration #4900

Merged

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Apr 30, 2021

Fixes #4897

The new disk object store migration that will ship with v2.0 requires
to be initialised once and only once, and it will generate the necessary
folders and configuration file. This process was being done in the
method Profile.get_repository guarded by a check in case it was
already initialised.

The problem with this was that the container could be initialised too
early during the early stages of a profile setup. As soon as the
repository was fetched, it would be initialised generating, among other
things, the UUID. This would then trigger the check that the database
contained the same UUID, which would of course fail, since the database
was empty. This could have been fixed by ignoring the check at this
point, but the real problem is that the repository should not be
initialised at this point. The only point at which the repo should be
initialised is during the corresponding database migration that
introduced the disk object store repository. Both for existing as well
as for new profiles, they will go through this migration and so it and
it alone should be responsible for initialising the repository.

This approach did create problems for the unittests though, as they
would sometimes clean the repository. It would this not by just removing
the contents, but it would delete the entire container. This meant it
had to be recreated, but since in normal operations this only happens
during the migration (which also during tests only happens once, unless
maybe during the migration tests themselves) and so an error would be
raised that the repository is not initialised. The solution is to
reinitialise a new repo as soon as the old one was destroyed. Currently
this is done by simply deleting the folder on disk and reinitialising an
entire new instance. In the future, it would be better if the existing
container could be kept and its contents could simply be dropped, but
this would require a feature in the disk-objectstore library.

@sphuber
Copy link
Contributor Author

sphuber commented Apr 30, 2021

I haven't added a test yet that should prevent the same regression that we have twice now. But this should fix the bug and improves the code/logic in general. Will think of a test soon, but this way the code can already be reviewed

@codecov
Copy link

codecov bot commented Apr 30, 2021

Codecov Report

Merging #4900 (10dd224) into develop (46eb180) will increase coverage by 0.01%.
The diff coverage is 81.25%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4900      +/-   ##
===========================================
+ Coverage    80.06%   80.07%   +0.01%     
===========================================
  Files          518      518              
  Lines        36680    36683       +3     
===========================================
+ Hits         29366    29371       +5     
+ Misses        7314     7312       -2     
Flag Coverage Δ
django 74.56% <81.25%> (+0.02%) ⬆️
sqlalchemy 73.47% <81.25%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiida/cmdline/commands/cmd_setup.py 50.00% <0.00%> (+0.88%) ⬆️
aiida/backends/general/migrations/utils.py 88.89% <75.00%> (ø)
aiida/backends/testbase.py 93.23% <100.00%> (+0.43%) ⬆️
aiida/manage/configuration/profile.py 94.98% <100.00%> (-0.08%) ⬇️
aiida/manage/manager.py 81.47% <100.00%> (+0.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 46eb180...10dd224. Read the comment docs.

The new disk object store migration that will ship with `v2.0` requires
to be initialised once and only once, and it will generate the necessary
folders and configuration file. This process was being done in the
method `Profile.get_repository` guarded by a check in case it was
already initialised.

The problem with this was that the container could be initialised too
early during the early stages of a profile setup. As soon as the
repository was fetched, it would be initialised generating, among other
things, the UUID. This would then trigger the check that the database
contained the same UUID, which would of course fail, since the database
was empty. This could have been fixed by ignoring the check at this
point, but the real problem is that the repository should not be
initialised at this point. The only point at which the repo should be
initialised is during the corresponding database migration that
introduced the disk object store repository. Both for existing as well
as for new profiles, they will go through this migration and so it and
it alone should be responsible for initialising the repository.

This approach did create problems for the unittests though, as they
would sometimes clean the repository. It would this not by just removing
the contents, but it would delete the entire container. This meant it
had to be recreated, but since in normal operations this only happens
during the migration (which also during tests only happens once, unless
maybe during the migration tests themselves) and so an error would be
raised that the repository is not initialised. The solution is to
reinitialise a new repo as soon as the old one was destroyed. Currently
this is done by simply deleting the folder on disk and reinitialising an
entire new instance. In the future, it would be better if the existing
container could be kept and its contents could simply be dropped, but
this would require a feature in the `disk-objectstore` library.
@sphuber sphuber force-pushed the fix/4897/repository-initialisation branch from 79efc65 to 10dd224 Compare May 3, 2021 06:00
@CasperWA
Copy link
Contributor

CasperWA commented May 3, 2021

I'll test this now (for a small db only).

Edit: Done. Tested for a DB I had. It represents a part of Thibault's old data.
I got an error after migration, but not related to the (non-)existence of the /container folder.
Please see the Google Doc for a summary of the whole error message.

@sphuber
Copy link
Contributor Author

sphuber commented May 3, 2021

I'll test this now (for a small db only).

Edit: Done. Tested for a DB I had. It represents a part of Thibault's old data.
I got an error after migration, but not related to the (non-)existence of the /container folder.
Please see the Google Doc for a summary of the whole error message.

Thanks a lot for the testing @CasperWA . As responded in that document, the problem is a new one and unrelated to the issue that this PR fixes. Since you were able to migrate at all, #4897 can be considered fixed by this. We should investigate more how the failure of your test is possible at all. For reference, the migration that changes the name column to label for the DbComputer table fails (for the SqlAlchemy backend) because apparently there are null rows. The column is and was defined as:

label = Column(String(255), unique=True, nullable=False)

So it should not have been able to insert null values anyway. We should look if there ever was a time when it was nullable=True and people changed it without a migration, but then again, it should have failed at that time I think.

@sphuber
Copy link
Contributor Author

sphuber commented May 3, 2021

I think this can be merged, since it seems to fix the specific issue it aims to address. The other failures mentioned by @CasperWA are edge-cases of certain databases that are failures of other specific migrations, which should be addressed in a separate issue. @mbercx would you be able to review this PR?

Copy link
Member

@mbercx mbercx left a comment

Choose a reason for hiding this comment

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

Changes look good, thanks @sphuber! I've also tested the migration for a ~30k node database, and it seems to have gone smoothly. Also tested:

@sphuber sphuber merged commit 87ab7e3 into aiidateam:develop May 4, 2021
@sphuber sphuber deleted the fix/4897/repository-initialisation branch May 4, 2021 06:26
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.

Cannot migrate due to container folder being present
3 participants