Skip to content

repoutil: Add custom hashing logic for reftables

Karthik Nayak requested to merge 5836-support-reftables-in-praefect-voting into master

The repoutil.Create function creates a new repository in a race-free manner with transactions. When using transactions, we need to vote to ensure that the created repository is identical across all nodes.

To get an appropriate checksum for the Git repository, we go over all files and add their contents to the hash. This works perfectly well for the files backend, since refs simply contain plain text content.

With the reftable backend, the table names contain a randomly generated suffix and all tables are listed in the 'tables.list' file. Also the contents of the files themselves are binary. To get around this we could potentially skip the 'tables.list' file. Another solution, is to simply list of refs using git itself instead of reading the filesystem.

We do the latter in this commit by using the newly introduced '--include-root-refs' command in 'git-update-ref', which would also print the root refs. This is used over 'git show-refs --head' because the former fails in empty bare repositories.

We also use the '--format=%(refname) %(objectname) %(symref)' here instead of the default:

  1. The default format includes '%(objecttype)' which requires querying the object database, we want to avoid doing that.
  2. We also want to ensure that for symrefs we check the target also, cause the resolved oid could be the same while having different targets.

This does skip over dangling symrefs, however that requires fixing on Git itself.

This also requires fixing the 'create_test.go' test to ensure that it runs correctly with SHA256. Currently it always creates SHA1 repositories. This isn't captured by the CI, since the repo never has content added to it, since we're adding content in our test, this would break.

Closes #5836 (closed)

Edited by Karthik Nayak

Merge request reports