LFS Storage statistics not properly updated
Summary
LFS Storage statistics are not properly updated when adding or replacing LFS managed files with identical size
Each step is a single commit.
files are generated using: dd if=/dev/urandom of=....../file1.psd BS=...M count=1
graph LR;
A[A: Initial Commit]-->B;
B[B: Init LFS: track *.psd]-->C;
C[C: Replace file1.psd 10MB]-->D;
D[D: Replace file1.psd 1MB]-->E;
E[E: Add file2.psd 1MB];
current Size Files/Storage and Expected:
- A:143KB/143KB
- B:174KB/174KB
- C:10.2MB/10.2MB, updated instantaneously
- D:10.2MB/10.2MB, expected 11.2MB, (not an issue: updated 15minutes after to 11.2MB, ProjectCacheWorker normal lease timeout)
- E:11.2MB/11.2MB, expected 12,2MB (same file size, size not updated even after 15min)
Squash C+D+E into F, and force push, git history is now:
graph LR;
A[A: Initial Commit]-->B;
B[B: Init LFS: track *.psd]-->F;
F[F: Squash C+D+E];
- A: 143KB/143KB
- B: 174KB/174KB
- F:11.2MB/11.2MB, (still 11.2 after 15min)
- Run housekeeping, F:1.2MB/1.2MB updated instantaneously, expected ~2.2MB
Part of the issue comes from
https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/models/project.rb#L289
https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/models/lfs_object.rb#L11
and related SQL request: SELECT SUM(DISTINCT "lfs_objects"."size") FROM "lfs_objects" INNER JOIN "lfs_objects_projects" ON "lfs_objects"."id" = "lfs_objects_projects"."lfs_object_id" WHERE "lfs_objects_projects"."project_id" = 3;
Steps to reproduce
see summary
Example Project
What is the current bug behavior?
see summary
What is the expected correct behavior?
see summary
Relevant logs and/or screenshots
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
System information System: Current User: git Using RVM: no Ruby Version: 2.7.2p137 Gem Version: 3.1.4 Bundler Version:2.1.4 Rake Version: 13.0.6 Redis Version: 6.0.14 Git Version: 2.32.0 Sidekiq Version:5.2.9 Go Version: unknown GitLab information Version: 14.2.2 Revision: 8d08c6cbe51 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: PostgreSQL DB Version: 12.7 URL: http://localhost:8081 HTTP Clone URL: http://localhost:8081/some-group/some-project.git SSH Clone URL: git@localhost:some-group/some-project.git Using LDAP: no Using Omniauth: yes Omniauth Providers: GitLab Shell Version: 13.19.1 Repository storage paths: - default: /var/opt/gitlab/git-data/repositories GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell Git: /opt/gitlab/embedded/bin/git
Results of GitLab application Check
Expand for output related to the GitLab application check
Checking GitLab subtasks ...
Checking GitLab Shell ...
GitLab Shell: ... GitLab Shell version >= 13.19.1 ? ... OK (13.19.1) Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Internal API available: OK Redis available via internal API: OK gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Gitaly ...
Gitaly: ... default ... OK
Checking Gitaly ... Finished
Checking Sidekiq ...
Sidekiq: ... Running? ... yes Number of Sidekiq processes (cluster/worker) ... 1/1
Checking Sidekiq ... Finished
Checking Incoming Email ...
Incoming Email: ... Reply by email is disabled in config/gitlab.yml
Checking Incoming Email ... Finished
Checking LDAP ...
LDAP: ... LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab App ...
Git configured correctly? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... skipped (no tmp uploads folder yet) Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) Projects have namespace: ... 2/1 ... yes 4/2 ... yes 4/3 ... yes 4/4 ... yes 4/5 ... yes Redis version >= 5.0.0? ... yes Ruby version >= 2.7.2 ? ... yes (2.7.2) Git version >= 2.31.0 ? ... yes (2.32.0) Git user has default SSH configuration? ... yes Active users: ... 3 Is authorized keys file accessible? ... yes GitLab configured to store new projects in hashed storage? ... yes All projects are in hashed storage? ... yes
Checking GitLab App ... Finished
Checking GitLab subtasks ... Finished
Possible fixes
replace https://gitlab.com/gitlab-org/gitlab/-/blob/de44b68259e4c42239da93172e5c39aefad470fc/app/models/project_statistics.rb#L73 with self.lfs_objects_size = project.lfs_objects.select(:id, :size).sum(&:size)