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

[rfc] cas: cmpxchg interface? #216

Open
cyphar opened this issue Nov 9, 2017 · 6 comments
Open

[rfc] cas: cmpxchg interface? #216

cyphar opened this issue Nov 9, 2017 · 6 comments
Labels
Milestone

Comments

@cyphar
Copy link
Member

cyphar commented Nov 9, 2017

I have a feeling that issues like #146 (which feel quite fundamental) would be solved much better if we had a more transaction-like interface.

@cyphar cyphar added this to the 1.0.0 milestone Nov 9, 2017
@cyphar cyphar added the oci/cas label Nov 9, 2017
@wking
Copy link
Contributor

wking commented Nov 9, 2017 via email

@cyphar
Copy link
Member Author

cyphar commented Nov 9, 2017

@wking That's not really what I'm referring to or suggesting. #146 has a more lengthy explanation of why index.json needs a better way of updating it than "just overwrite the current index.json with what I tell you". I don't think that moving away from the OCI format is a good idea -- if there isn't a way to solve the problem within OCI then OCI should be fixed, and if there is a way to solve it within the current spec then we should do it that way. One interface would be something like

var ErrReplaceConflict = errors.New("could not replace index as the 'old' index had changed")
func ReplaceIndex(ctx context.Context, old, new ispec.Index) (err error)

Effectively a cmpxchg-style interface -- if the old contents weren't identical to the previous value then the replacement fails. This would be a bit hard to implement using filesystem operations, but not impossible.

I think transactions would make this sort of style even nicer (and it would also benefit from making cleanup if an operation fails in the middle much simpler). But I think that this would break oci/cas far too much (maybe this is something that could be done as part of oci/casext).

@wking
Copy link
Contributor

wking commented Nov 9, 2017

...if there isn't a way to solve the problem within OCI then OCI should be fixed...

The racing-updates issue was a known weakness when image-spec switched to index.json. The mitigation was that it's a publication-time format, and you can use something friendlier to parallel writes in development.

func ReplaceIndex(ctx context.Context, old, new ispec.Index) (err error)

This is a good idea. And even with per-ref locks, something like that would still be a good idea. Using per-ref files or SQLite or whatever doesn't uniquely allow you to do that, it just makes the implementation easier.

@wking
Copy link
Contributor

wking commented Nov 9, 2017 via email

@cyphar
Copy link
Member Author

cyphar commented Nov 10, 2017

I think blocking for a while in a retry loop (with some sane defaults for amount-of-times-to-retry) would work fine. And personally since there are several "global" properties of index.json I feel that making it a "replace" operation for the entire struct rather than thinking of it as "modifying a single reference in the index" will probably lead to less confusion.

@cyphar cyphar changed the title [rfc] cas: transactional interface? [rfc] cas: cmpxchg interface? Nov 10, 2017
@wking
Copy link
Contributor

wking commented Nov 10, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants