Skip to content

Share snapshots between read-only transactions

Sami Hiltunen requested to merge smh-share-read-snapshots into master

Gitaly is currently creating a unique snapshot for every single transaction. Each snapshot operation has overhead as the snapshotting requires copying repository directory hierarchy and hard linking all of their files in place. This effectively changes every read into a write. While this is needed to isolate writes, read-only transactions could share their snapshots as they don't modify them. All reads targeting the same repositories on the same LSN could share the snapshot. This would significanly reduce the number of snapshotting operations performed under high read load.

This MR adds a new type that manages snapshots. It provides two types of snapshots:

  1. Exclusive snaphots are used by writes. They largely work the same as before and each write transaction gets their own snapshot.
  2. Shared snapshots are shared by multiple read-only transactions targeting the same repositories at the same LSN. The manager tracks the number of users a snapshot has and keeps it open as long as there are still some users. The last user cleans up the snapshot.

Closes #5619 (closed)

Merge request reports