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

Add a note about ordering of Tree protos #223

Merged
merged 1 commit into from
May 9, 2022

Conversation

peterebden
Copy link
Contributor

We recently discovered some nondeterminism in outputs because the Tree children were coming out in different orders. It looks like that specific case got fixed by bazelbuild/remote-apis-sdks#411, but it seems worth noting for any future implementations.

@EricBurnett
Copy link
Collaborator

LGTM. I considered whether the API should take a stronger stance on what the ordering should be, but

  1. There is no trivial ordering recommendation, as Directory nodes aren't obviously sortable, and directory traversal order to compose this Tree could be specified but seems like it'd constrain the implementation too much.
  2. I actually want to relax the ordering and uniqueness constraints on various other parts of the merkle tree specs to something similar for V3 (V3 idea: Loosen the restriction of action input as Merkle tree #141), so trying to retroactively specify a specific ordering for Tree now feels backwards, if it's not certain its the direction we want to go in the future.

With all that in mind, what you have here seems like the right balance for the present API.

@EdSchouten
Copy link
Collaborator

EdSchouten commented Apr 25, 2022

  1. There is no trivial ordering recommendation, as Directory nodes aren't obviously sortable, and directory traversal order to compose this Tree could be specified but seems like it'd constrain the implementation too much.

Pieces of code that create Tree objects need to hash individual Directory objects anyway, so they can be referenced by their parent(s). It's trivial for an implementation to also use these hashes for sorting/deduplication purposes.

This is exactly what Buildbarn does, by the way. Child directories are sorted in increasing order by hash, and identical subtrees are merged together.

https://github.com/buildbarn/bb-remote-execution/blob/master/pkg/builder/output_hierarchy.go#L271-L282

@peterebden
Copy link
Contributor Author

Pieces of code that create Tree objects need to hash individual Directory objects anyway, so they can be referenced by their parent(s). It's trivial for an implementation to also use these hashes for sorting/deduplication purposes.

Yep, agreed, that was the first thing that sprung to my mind too :) Although I could also imagine an implementation that always generates them in a deterministic order and so felt that sorting it was unnecessary.

Anyway, I agree with Eric that it's not really necessary for REAPI to specify how the ordering should be done here; the ordering only matters in terms of determinism of outputs, and as long as an implementation does it the same way each time that should be sufficient (I'm sure nobody has a need for determinism between different implementations...).

@bergsieker bergsieker removed the request for review from buchgr May 9, 2022 20:26
@bergsieker bergsieker merged commit 5971c1e into bazelbuild:main May 9, 2022
moroten added a commit to moroten/remote-apis that referenced this pull request May 10, 2022
This commit updates .pb.go using hooks/pre-commit as it was forgotten
in the following commits:

2af1c43 Use fully-qualified import paths in `go_package` options. (bazelbuild#219)
5971c1e Add a note about ordering of Tree protos (bazelbuild#223)
@moroten moroten mentioned this pull request May 10, 2022
moroten added a commit to moroten/remote-apis that referenced this pull request May 10, 2022
This commit updates .pb.go using hooks/pre-commit as it was forgotten
in the following commits:

2af1c43 Use fully-qualified import paths in `go_package` options. (bazelbuild#219)
5971c1e Add a note about ordering of Tree protos (bazelbuild#223)
bergsieker pushed a commit that referenced this pull request May 10, 2022
This commit updates .pb.go using hooks/pre-commit as it was forgotten
in the following commits:

2af1c43 Use fully-qualified import paths in `go_package` options. (#219)
5971c1e Add a note about ordering of Tree protos (#223)
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