Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce cost of various SQL queries #382

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/operator-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ tasks performed by the janitor.

| Task | Explanation |
| ---- | ----------- |
| ![Number 1:](./icon-green-1.png) Manifest reference validation | Takes a manifest, parses its contents and check that the references to other manifests and blobs included therein are correctly entered in the database.<br><br>*Rhythm:* every 24 hours (per manifest)<br>*Clock:* database field `manifests.validated_at`<br>*Signal:* Prometheus counter `keppel_manifest_validations`<br>*Success signal:* database field `manifests.validation_error_message` cleared<br>*Failure signal:* database field `manifests.validation_error_message` filled |
| ![Number 2:](./icon-green-2.png) Blob content validation | Takes a blob and computes the digest of its contents to see if it checks the digest stored in the database.<br><br>*Rhythm:* every 7 days (per blob)<br>*Clock:* database field `blobs.validated_at`<br>*Success signal:* Prometheus counter `keppel_blob_validations`<br>*Success signal:* database field `blobs.validation_error_message` cleared<br>*Failure signal:* Prometheus counter `keppel_blob_validations`<br>*Failure signal:* database field `blobs.validation_error_message` filled |
| ![Number 1:](./icon-green-1.png) Manifest reference validation | Takes a manifest, parses its contents and check that the references to other manifests and blobs included therein are correctly entered in the database.<br><br>*Rhythm:* every 24 hours (per manifest)<br>*Clock:* database field `manifests.next_validation_at`<br>*Signal:* Prometheus counter `keppel_manifest_validations`<br>*Success signal:* database field `manifests.validation_error_message` cleared<br>*Failure signal:* database field `manifests.validation_error_message` filled |
| ![Number 2:](./icon-green-2.png) Blob content validation | Takes a blob and computes the digest of its contents to see if it checks the digest stored in the database.<br><br>*Rhythm:* every 7 days (per blob)<br>*Clock:* database field `blobs.next_validation_at`<br>*Success signal:* Prometheus counter `keppel_blob_validations`<br>*Success signal:* database field `blobs.validation_error_message` cleared<br>*Failure signal:* Prometheus counter `keppel_blob_validations`<br>*Failure signal:* database field `blobs.validation_error_message` filled |
| ![Number 1:](./icon-red-1.png) Blob mount GC | Takes a repository and unmounts all blobs that are not referenced by any manifest in this repository.<br><br>*Rhythm:* every hour (per repository), **BUT** not while any manifests in the repository fail validation<br>*Clock:* database field `repos.next_blob_mount_sweep_at`<br>*Signal:* Prometheus counter `keppel_mount_sweeps` |
| ![Number 2:](./icon-red-2.png) Blob GC | Takes an account and deletes all blobs that are not mounted into any repository.<br><br>*Rhythm:* every hour (per account)<br>*Clock:* database field `accounts.next_blob_sweep_at`<br>*Signal:* Prometheus counter `keppel_blob_sweeps` |
| ![Number 3:](./icon-red-3.png) Storage GC | Takes an account's backing storage and deletes all blobs and manifests in it that are not referenced in the database.<br><br>*Rhythm:* every 6 hours (per account)<br>*Clock:* database field `accounts.next_storage_sweep_at`<br>*Signal:* Prometheus counter `keppel_storage_sweeps` |
Expand Down
36 changes: 18 additions & 18 deletions internal/api/keppel/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1780,12 +1780,12 @@ func uploadManifest(t *testing.T, s test.Setup, account *models.Account, repo *m
t.Helper()

dbManifest := models.Manifest{
RepositoryID: repo.ID,
Digest: manifest.Digest,
MediaType: manifest.MediaType,
SizeBytes: sizeBytes,
PushedAt: s.Clock.Now(),
ValidatedAt: s.Clock.Now(),
RepositoryID: repo.ID,
Digest: manifest.Digest,
MediaType: manifest.MediaType,
SizeBytes: sizeBytes,
PushedAt: s.Clock.Now(),
NextValidationAt: s.Clock.Now().Add(models.ManifestValidationInterval),
}
mustDo(t, s.DB.Insert(&dbManifest))
mustDo(t, s.DB.Insert(&models.TrivySecurityInfo{
Expand Down Expand Up @@ -1836,12 +1836,12 @@ func TestDeleteAccount(t *testing.T) {
for idx, testBlob := range append(image.Layers, image.Config) {
storageID := sidGen.Next()
blob := models.Blob{
AccountName: accounts[0].Name,
Digest: testBlob.Digest,
SizeBytes: uint64(len(testBlob.Contents)),
StorageID: storageID,
PushedAt: time.Unix(int64(idx), 0),
ValidatedAt: time.Unix(int64(idx), 0),
AccountName: accounts[0].Name,
Digest: testBlob.Digest,
SizeBytes: uint64(len(testBlob.Contents)),
StorageID: storageID,
PushedAt: time.Unix(int64(idx), 0),
NextValidationAt: time.Unix(int64(idx), 0).Add(models.BlobValidationInterval),
}
mustInsert(t, s.DB, &blob)
blobs = append(blobs, blob)
Expand All @@ -1861,12 +1861,12 @@ func TestDeleteAccount(t *testing.T) {
}

mustInsert(t, s.DB, &models.Manifest{
RepositoryID: repos[0].ID,
Digest: image.Manifest.Digest,
MediaType: image.Manifest.MediaType,
SizeBytes: uint64(len(image.Manifest.Contents)),
PushedAt: time.Unix(100, 0),
ValidatedAt: time.Unix(100, 0),
RepositoryID: repos[0].ID,
Digest: image.Manifest.Digest,
MediaType: image.Manifest.MediaType,
SizeBytes: uint64(len(image.Manifest.Contents)),
PushedAt: time.Unix(100, 0),
NextValidationAt: time.Unix(100, 0).Add(models.ManifestValidationInterval),
})
mustInsert(t, s.DB, &models.TrivySecurityInfo{
RepositoryID: repos[0].ID,
Expand Down