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

datalad-annex:: Test for a repository deposit before establishing mirrorrepo #638

Merged
merged 4 commits into from
Feb 20, 2024

Conversation

mih
Copy link
Member

@mih mih commented Feb 15, 2024

The mirrorrepo property of the datalad-annex Git remote helper implementation creates an empty repository, if the remote has no refs (or does not exist). This is sensible behavior for enabling initial pushes.

However, it leads to successful but empty clones/fetches for any misspecified URL or connectivity failure. This is undesirable.

This change adds an explicit test for an available/accessible repository deposit, whenever a clone/fetch is performed. Wrong URL specifications or connectivity issues will now lead to an explicit error exit. This fact is communicated via a non-verbose message, and the full error is available at verbosity level 2, i.e. with a git clone -v.

TODO

  • Add test
  • Look into test failure with create-sibling-webdav

@mih
Copy link
Member Author

mih commented Feb 15, 2024

The current implementation is not yet optimal:

Initial push to a not yet existing repo deposit

❯ git push 127.0.0.1
[DATALAD-ANNEX] Cannot query remote's refs (repository deposit does not exist, or is inaccessible
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
...

Initial datalad push

❯ datalad push --to 127.0.0.1
copy(ok): testfile.dat (file) [to 127.0.0.1-storage...]                                      
Update availability for '127.0.0.1':  75%|████████▎  | 3.00/4.00 [00:00<00:00, 29.9k Steps/s]CommandError: 'git -c diff.ignoreSubmodules=none -c core.quotepath=false fetch 127.0.0.1 git-annex' failed with exitcode 128                                                              
[DATALAD-ANNEX] Cannot query remote's refs (repository deposit does not exist, or is inaccessible
-> exit(128)

The latter fails in the git-push, even though that git-push succeeds when ran on its own.

@mslw
Copy link
Collaborator

mslw commented Feb 15, 2024

Verify the fix for #373 (@mslw can you give that a try please?)

As of now, the local side seems OK (DataLad produces an understandable error message):

❱ datalad clone "datalad-annex::?type=webdav&encryption=none&exporttree=no&url=https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/test-2024-02-15/bogus-directory" clone-bogus-directory
install(error): /tmp/clone-bogus-directory (dataset) [Failed to clone from any candidate source URL. Encountered errors per each url were:
- datalad-annex::?type=webdav&encryption=none&exporttree=no&url=https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/test-2024-02-15/bogus-directory
  CommandError: 'git -c diff.ignoreSubmodules=none -c core.quotepath=false clone --progress 'datalad-annex::?type=webdav&encryption=none&exporttree=no&url=https://fz-juelich.sciebo.de/remote.php/dav/files/m.szczepanik%40fz-juelich.de/test-2024-02-15/bogus-directory' /tmp/clone-bogus-directory' failed with exitcode 128 [err: 'Cloning into '/tmp/clone-bogus-directory'...
[DATALAD-ANNEX] Cannot query remote's refs (repository deposit does not exist, or is inaccessible']]

But on the remote side (in Sciebo), bogus-directory (which did not exist) gets created by the clone operation.

So I'd say it is not fixed, or partially fixed.

@mih
Copy link
Member Author

mih commented Feb 15, 2024

Thanks for the feedback @mslw -- with that info, it looks like there is something specific to the remote type. I will detach #373 from the set of ambitions here. Needs to have a dedicated investigation.

@mih
Copy link
Member Author

mih commented Feb 16, 2024

I found one of the issues that are a problem here. In _sync_remote_annex_branch() (in the push patch optimize), it does error handling on fetch failure:

    except mod_push.CommandError as e:
        # it is OK if the remote doesn't have a git-annex branch yet
        # (e.g. fresh repo)
        # TODO is this possible? we just copied? Maybe check if anything
        # was actually copied?
        if "fatal: couldn't find remote ref git-annex" not in e.stderr.lower():
            raise
        lgr.debug('Remote does not have a git-annex branch: %s', e)

The messaging from git that it expects is not happening, because the actual message is coming from datalad-annex in this case. This same would be true for other Git remote helpers.

I believe that this check needs to be replaced. Not sure how to handle that yet. It would be useful to stop there in cases where something other than a missing ref causes an error exit.

Maybe the test is shortened to fatal: couldn't find remote ref

Previously, one had to call `git-clone/fetch` directly with some
`-v` options in order to trigger verbose output of the remote helper.

With this change a DataLad log level of 'debug' (or more verbose),
also triggers verbose output in the helper. This helps with
accessibility of this feature for internal Git calls.

Note that due to a limitation of the `datalad -l` CLI option handling
the log-level is not propagated to subprocesses. This only works
for env specification ala DATALAD_LOG_LEVEL=debug
Copy link

codecov bot commented Feb 19, 2024

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (ee5e7de) 92.67% compared to head (e415687) 93.05%.
Report is 5 commits behind head on main.

❗ Current head e415687 differs from pull request most recent head 08e2213. Consider uploading reports for the commit 08e2213 to get more accurate results

Files Patch % Lines
datalad_next/gitremotes/datalad_annex.py 92.45% 3 Missing and 1 partial ⚠️
datalad_next/patches/push_optimize.py 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #638      +/-   ##
==========================================
+ Coverage   92.67%   93.05%   +0.38%     
==========================================
  Files         171      171              
  Lines       11564    11945     +381     
  Branches     1781     1806      +25     
==========================================
+ Hits        10717    11116     +399     
+ Misses        657      642      -15     
+ Partials      190      187       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@mslw mslw 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 investigating this. I tried clone, and I like the improved error message and the fact that an empty repo is not created.

The commit message for e415687 says that it would also close #373 but as far as I understand the webdav case still warrants investigation (which I cannot commit to at the moment), as clone would still create an empty directory on the webdav end.

@mih
Copy link
Member Author

mih commented Feb 20, 2024

Thanks for catching that!

The `mirrorrepo` property of the datalad-annex Git remote helper
implementation creates an empty repository, if the remote has no
refs (or does not exist). This is sensible behavior for enabling
initial pushes.

However, it leads to successful but empty clones/fetches for any
misspecified URL or connectivity failure. This is undesirable.

This change adds an explicit test for an available/accessible
repository deposit, whenever a clone/fetch is performed. Wrong URL
specifications or connectivity issues will now lead to an explicit
error exit. This fact is communicated via a non-verbose message,
and the full error is available at verbosity level 2, i.e. with a
`git clone -v`.

Closes: dataladgh-636
@mih mih merged commit aefe74c into datalad:main Feb 20, 2024
3 of 6 checks passed
@mih mih deleted the bf-636 branch February 20, 2024 10:40
@mih mih added this to the 1.3 milestone Mar 19, 2024
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.

Improve error handling of datalad-annex:: git remote helper
2 participants