Skip to content

Serialize partition ID assignment attempts

Sami Hiltunen requested to merge smh-fix-partition-no-assign into master

If multiple goroutines attempt to assign a partition ID concurrently, Gitaly currently allows the first to assign the partition ID. The others wait and then return the assigned partition ID. This worked in the past but we've since changed the logic and this is no longer sufficient.

Assignments are only created if the repository exists, or if the RPC is a repository creating one.

If the RPC repository does not exist and this is not a repository creating RPC, we should return an error indicating the repository does not exist. This is currently done by the goroutine that attempted to assign a partition but noticed the repository does not exist. The blocked goroutines return a 'partition assignment not found' error. Simply catching the error and returning the correct one is not that simple as if the RPC is a repository creating one, it should create the assignment and not error out because the previous one didn't create it.

Solve this issue by serializing repository assignment attempts into a given repository. If an assignment exists, all goroutines just read it from the database and proceed without locking. If there's no assignment for the repository yet, the requests are handled sequentially. This should be fine as non-existent repositories shouldn't be receiving lots of requests anyway. If the repository exists or is created, the follow up requests will read the assignment directly from the database.

Closes #6109 (closed)

Merge request reports