Skip to content

opam update: Avoid reloading repository contents when the repo has not changed#5043

Merged
rjbou merged 4 commits intoocaml:masterfrom
Armael:update-no-changes
May 20, 2022
Merged

opam update: Avoid reloading repository contents when the repo has not changed#5043
rjbou merged 4 commits intoocaml:masterfrom
Armael:update-no-changes

Conversation

@Armael
Copy link
Copy Markdown
Member

@Armael Armael commented Feb 6, 2022

Currently, opam update will reload the state of a repository (reading .opam files, etc) even when the repository has not changed (as detected by the backend).
This PR is an attempt at optimizing this case: if the backend says that a repository has not changed, avoid reloading its contents, allowing for quicker opam updates.

(a review is particularly welcome as I am not familiar with this part of opam's code; I might have missed some subtleties wrt synchronization of the on-disk view of the repo and the "repo" in-memory data structure...)

job { r with repo_url = new_url } (n-1)
in
job repo max_loop @@+ fun repo ->
job repo max_loop @@+ fun has_changes ->
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
job repo max_loop @@+ fun has_changes ->
job repo max_loop @@+ fun repo, has_changes ->

repo is not return by the job function anymore. I belive this would break repositories with redirections from a glance at the code. Could you either return repo as before in a tuple or inside the new [no_changes | changes] state (whichever you think is better)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

you are right of course! I had missed the fact that the repo is returned by job to account for redirections. should be fixed now.

@Armael Armael force-pushed the update-no-changes branch 2 times, most recently from 6407321 to 9604c13 Compare February 6, 2022 19:35
@kit-ty-kate
Copy link
Copy Markdown
Member

note for opam devs: this is going to conflict with #5015 and I think #5015 should be prioritized. I’ll handle rebase of this PR after the merge.

@Armael once #5015 is merged I think a simple test could also be added to tests/reftest/repository.test (file added by #5015). An entry to the changelog could also be added at that moment (it’s not useful to add it now and would only serve to make CI rerun for nothing)

@kit-ty-kate kit-ty-kate added the PR: QUEUED Pending pull request, waiting for other work to be merged or closed label Feb 6, 2022
@Armael Armael force-pushed the update-no-changes branch from 9604c13 to 355bbd7 Compare March 30, 2022 11:42
@Armael
Copy link
Copy Markdown
Member Author

Armael commented Mar 30, 2022

I have rebased the PR now that #5015 has been merged. I can try to add a test, but I'm not exactly sure how to test the PR, maybe by testing that .tar has not been regenerated by checking the modification date after doing a second opam update?

@rjbou rjbou removed the PR: QUEUED Pending pull request, waiting for other work to be merged or closed label Mar 30, 2022
@rjbou
Copy link
Copy Markdown
Collaborator

rjbou commented Mar 30, 2022

For the test, you can check also check -vv output, see repository test

@Armael Armael force-pushed the update-no-changes branch from 355bbd7 to 1c31257 Compare April 1, 2022 16:01
@kit-ty-kate
Copy link
Copy Markdown
Member

The tests failed with:

File "tests/reftests/lint.test", line 1, characters 0-0:
File "tests/reftests/repository.test", line 1, characters 0-0:
diff --git a/tests/reftests/lint.test b/tests/reftests/lint.out
index 3d7e6cc..d0b4fb7 100644
--- a/tests/reftests/lint.test
+++ b/tests/reftests/lint.out
@@ -543,8 +543,9 @@ ${BASEDIR}/OPAM/repo/default/packages/lint/lint.1/opam: Errors.
 <><> Updating package repositories ><><><><><><><><><><><><><><><><><><><><><><>
 [default] no changes from file://${BASEDIR}/REPO
 ### opam lint --package lint
-[ERROR] File ${OPAMTMP}/default/packages/lint/lint.1/opam not found
-# Return code 2 #
+${BASEDIR}/OPAM/repo/default/packages/lint/lint.1/opam: Errors.
+             error 53: Mismatching 'extra-files:' field: "more-file"
+# Return code 1 #
 ### : W54: External dependencies should not contain spaces nor empty string
 ### <lint.opam>
 opam-version: "2.0"
diff --git a/tests/reftests/repository.test b/tests/reftests/repository.out
index f5a3ba1..a1563af 100644
--- a/tests/reftests/repository.test
+++ b/tests/reftests/repository.out
@@ -8,6 +8,7 @@ some content
 ### : Internal repository storage as archive or plain directory :
 ### opam update -vv | grep '^\+' | '.*(/|\\)diff(\.exe)?"? "' -> 'diff "'
 diff "-ruaN" "default" "default.new" (CWD=${BASEDIR}/OPAM/repo)
++ /usr/bin/patch "-p1" "-i" "${BASEDIR}/OPAM/log/patch-13897-8e7306" (CWD=${BASEDIR}/OPAM/repo/default)
 ### ls $OPAMROOT/repo | grep -v "cache"
 default
 lock
@@ -36,8 +37,10 @@ opam-version: "2.0"
 ### opam update -vv | grep '^\+' | '.*tar(\.exe)?"? "xfz" ".*(/|\\)OPAM(/|\\)repo(/|\\)tarred\.tar\.gz" "-C" ".*"' -> 'tar xfz OPAM/repo/tarred.tar.gz -C TMPDIR' | '.*tar(\.exe)?"? "cfz" ".*(/|\\)OPAM(/|\\)repo(/|\\)tarred\.tar\.gz\.tmp" "-C" ".*" "tarred"' -> 'tar cfz OPAM/repo/tarred.tar.gz.tmp -C TMPDIR tarred' | '.*(/|\\)diff(\.exe)?"? "' -> 'diff "'
 tar xfz OPAM/repo/tarred.tar.gz -C TMPDIR
 diff "-ruaN" "tarred" "tarred.new" (CWD=${OPAMTMP})
++ /usr/bin/patch "-p1" "-i" "${BASEDIR}/OPAM/log/patch-14054-60ee40" (CWD=${OPAMTMP}/tarred)
 tar cfz OPAM/repo/tarred.tar.gz.tmp -C TMPDIR tarred
 ### opam update -vv --debug | grep '^[^ ]+( )+UPDATE'
+00:00.024  UPDATE                          Repository did not change: nothing to do.
 ### opam install foo -vv | grep '^\+' | '.*(/|\\|")test(\.exe)?"? "' -> 'test "' | '.*tar(\.exe)?"? "xfz" ".*(/|\\)OPAM(/|\\)repo(/|\\)tarred\.tar\.gz" "-C" ".*"' -> 'tar xfz OPAM/repo/tarred.tar.gz -C TMPDIR'
 tar xfz OPAM/repo/tarred.tar.gz -C TMPDIR
 test "-f" "bar" (CWD=${BASEDIR}/OPAM/tarring/.opam-switch/build/foo.1)
@@ -51,6 +54,7 @@ opam-version: "2.0"
 ### opam update -vv | grep '^\+' | '.*tar(\.exe)?"? "xfz" ".*(/|\\)OPAM(/|\\)repo(/|\\)tarred\.tar\.gz" "-C" ".*"' -> 'tar xfz OPAM/repo/tarred.tar.gz -C TMPDIR' | '.*(/|\\)diff(\.exe)?"? "' -> 'diff "'
 tar xfz OPAM/repo/tarred.tar.gz -C TMPDIR
 diff "-ruaN" "tarred" "tarred.new" (CWD=${OPAMTMP})
++ /usr/bin/patch "-p1" "-i" "${BASEDIR}/OPAM/log/patch-14154-fc73fc" (CWD=${OPAMTMP}/tarred)
 tar xfz OPAM/repo/tarred.tar.gz -C TMPDIR
 ### ls $OPAMROOT/repo | grep -v "cache"
 lock
@@ -60,3 +64,5 @@ tarred
 packages
 repo
 ### diff -ru ./REPO $OPAMROOT/repo/tarred
+Only in ./REPO/packages/toto: toto.2
+# Return code 1 #

@rjbou rjbou force-pushed the update-no-changes branch from 1c31257 to 9758961 Compare April 4, 2022 14:40
@rjbou rjbou added the PR: QUEUED Pending pull request, waiting for other work to be merged or closed label Apr 4, 2022
@rjbou rjbou force-pushed the update-no-changes branch from 9758961 to b6c6b90 Compare May 19, 2022 13:13
@rjbou rjbou removed the PR: QUEUED Pending pull request, waiting for other work to be merged or closed label May 19, 2022
@rjbou rjbou force-pushed the update-no-changes branch 3 times, most recently from 73eb1fc to 530b9fd Compare May 19, 2022 15:08
@rjbou rjbou force-pushed the update-no-changes branch from 530b9fd to e2d24d0 Compare May 20, 2022 09:05
@rjbou rjbou merged commit 063e5d8 into ocaml:master May 20, 2022
@Armael
Copy link
Copy Markdown
Member Author

Armael commented May 20, 2022

Thanks a lot!

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.

4 participants