Skip to content

Introduce transaction managing middleware

Sami Hiltunen requested to merge smh-transaction-middleware into master

This MR implements gRPC middleware for running most repository scoped RPCs using transactions. The middleware reads the target repository from the request and starts a transaction for it. It then calls the handler with the request's repository rewritten to point to the transaction's snapshot repository. If the handler returns successfully the transaction is committed. If the handler returns an error, the transaction is rolled back.

The transaction's ID is included in the context. This way it can be passed through to the hooks which can then retrieve the transaction and stage the reference updates made.

The transaction itself is also included in the context. This way RPCs can stage changes that are not captured automatically like the reference updates are. This includes for example default branch updates, custom hook updates and others.

Almost all accessors are ran transactionally. Most mutators are as well, and the ones that aren't are either deprecated or not yet supported by transactions. Maintenance RPCs aren't supported by transactions and will need to be integrated in the actual transaction manager. Unsupported mutators and maintenance RPCs are ran non-transactionally rather than erroring out to keep the tests passing.

Accessors with quarantine configuration set are passed through. Such requests should only be sent from Rails' access checks. The parent request that called into the access checks would already be running in a transaction so another one isn't started. Currently the access don't target the snapshot repository yet. Mutators with quarantine configured are rejected as such requests shouldn't arrive.

Merge request reports