-
Notifications
You must be signed in to change notification settings - Fork 296
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
Repo write operations (e.g. pulls, commits) should respect exclusive locks even when not using transaction API #2474
Comments
More context for this in coreos/fedora-coreos-releng-automation#79. |
In the case we're using transactions, that's already done for us. Otherwise, we should do it ourselves. Otherwise we run the risk of racing with the pruner. For more context, see: ostreedev/ostree#2474 coreos/fedora-coreos-releng-automation#79
In the case we're using transactions, that's already done for us. Otherwise, we should do it ourselves. Otherwise we run the risk of racing with e.g. a prune operation. For more context, see: ostreedev/ostree#2474 coreos/fedora-coreos-releng-automation#79
I was re-reading the pull code more carefully and actually it does prepare a transaction by default, unless ostree/src/libostree/ostree-repo-pull.c Lines 4871 to 4875 in 1e6077a
So I think |
Nice.. In the case of |
Just to sanity-check, I've confirmed this with: diff --git a/src/libostree/ostree-repo-prune.c b/src/libostree/ostree-repo-prune.c
index c4ce64ab..dfb9be88 100644
--- a/src/libostree/ostree-repo-prune.c
+++ b/src/libostree/ostree-repo-prune.c
@@ -404,6 +404,12 @@ ostree_repo_prune (OstreeRepo *self,
if (!lock)
return FALSE;
+ if (g_getenv ("OSTREE_PRUNE_LOCKED") != NULL)
+ {
+ g_print ("took lock and stopping\n");
+ raise (SIGSTOP);
+ }
+
g_autoptr(GHashTable) objects = NULL;
gboolean refs_only = flags & OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY;
@@ -490,6 +496,13 @@ ostree_repo_prune_from_reachable (OstreeRepo *self,
if (!lock)
return FALSE;
+ if (g_getenv ("OSTREE_PRUNE_LOCKED") != NULL)
+ {
+ g_print ("took lock and stopping\n");
+ raise (SIGSTOP);
+ }
+
+
g_autoptr(GHashTable) objects = NULL;
if (!ostree_repo_list_objects (self, OSTREE_REPO_LIST_OBJECTS_ALL | OSTREE_REPO_LIST_OBJECTS_NO_PARENTS, Then in one terminal, running:
And running
And similarly for
|
I don't think this is true. This was one of my primary motivations for writing the locking. Pruning takes an exclusive lock and a transaction takes a shared lock. Unless you're somehow avoiding the transaction in the pull, then you should avoid this. BTW, |
Hey @dbnicholson, can you specify which part isn't correct? I'm not sure if you saw the follow-up in #2474 (comment) or not. |
Sorry, I just didn't read the entire thread before commenting. You're correct in what you've written that pulls are safe from the lock taken when preparing the transaction. If you're composing a tree from the repo, though, then you currently would need to take the lock yourself. It might be possible to do it in ostree when constructing an mtree, but that's really the type of multi step operation where you need the composer to do the locking since it's the one that knows when the operation is done. |
Right yup, agreed. This is the gap that coreos/rpm-ostree#3193 fixes for rpm-ostree. It makes sense to bake this into the pull API because the entrypoint is more well-defined (basically just a call to |
In the case we're using transactions, that's already done for us. Otherwise, we should do it ourselves. Otherwise we run the risk of racing with e.g. a prune operation. For more context, see: ostreedev/ostree#2474 coreos/fedora-coreos-releng-automation#79
With coreos/rpm-ostree#3193 merged, I think we can close this. |
Right now, there is nothing preventing e.g.
ostree pull/pull-local
to write things to the repo while it's actively being pruned. This introduces possible races resulting in incomplete commit objects. E.g. an object might not get pulled because it's already present, but the pruner has already decided it is unreachable and plans to delete it.It looks like
ostree commit
currently always uses transactions, thoughrpm-ostree compose tree
is susceptible to this because it will disable transactions in some situations. We should adapt it to try to get a shared lock if not using transactions.ostree pull
andostree pull-local
don't currently use transactions AFAICT, so they are susceptible as well. We could use transactions there, though that would change the semantics. Just getting a shared lock would be enough and be more lightweight.I guess another approach would be to do this at the API level, though there's quite a few, and it'd be more invasive and prone to cause regressions.
The text was updated successfully, but these errors were encountered: