From 31cad9f33846dfced016700f3166902fee068cb0 Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Wed, 6 Mar 2024 11:13:29 +0100 Subject: [PATCH 1/3] stores: migration to update object health to 1 when size is 0 --- .../mysql/main/migration_00005_zero_size_object_health.sql | 1 + .../sqlite/main/migration_00005_zero_size_object_health.sql | 1 + 2 files changed, 2 insertions(+) create mode 100644 stores/migrations/mysql/main/migration_00005_zero_size_object_health.sql create mode 100644 stores/migrations/sqlite/main/migration_00005_zero_size_object_health.sql diff --git a/stores/migrations/mysql/main/migration_00005_zero_size_object_health.sql b/stores/migrations/mysql/main/migration_00005_zero_size_object_health.sql new file mode 100644 index 000000000..1a0799394 --- /dev/null +++ b/stores/migrations/mysql/main/migration_00005_zero_size_object_health.sql @@ -0,0 +1 @@ +UPDATE objects SET health = 1 WHERE size = 0; diff --git a/stores/migrations/sqlite/main/migration_00005_zero_size_object_health.sql b/stores/migrations/sqlite/main/migration_00005_zero_size_object_health.sql new file mode 100644 index 000000000..1a0799394 --- /dev/null +++ b/stores/migrations/sqlite/main/migration_00005_zero_size_object_health.sql @@ -0,0 +1 @@ +UPDATE objects SET health = 1 WHERE size = 0; From 1c496f7fa581770d4f4b6683ca5dbf41faa767fa Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Wed, 6 Mar 2024 11:15:55 +0100 Subject: [PATCH 2/3] stores: extend TestRefreshHealth --- stores/metadata_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/stores/metadata_test.go b/stores/metadata_test.go index 27aa26a13..f5461147c 100644 --- a/stores/metadata_test.go +++ b/stores/metadata_test.go @@ -3990,6 +3990,34 @@ func TestRefreshHealth(t *testing.T) { } else if health(o2) != .6 { t.Fatal("expected health to be .6, got", health(o2)) } + + // add another object that is empty + o3 := t.Name() + "3" + if added, err := ss.addTestObject(o3, object.Object{ + Key: object.GenerateEncryptionKey(), + }); err != nil { + t.Fatal(err) + } else if added.Health != 1 { + t.Fatal("expected health to be 1, got", added.Health) + } + + // update its health to .1 + if err := ss.db. + Model(&dbObject{}). + Where("object_id", o3). + Update("health", 0.1). + Error; err != nil { + t.Fatal(err) + } else if health(o3) != .1 { + t.Fatalf("expected health to be .1, got %v", health(o3)) + } + + // a refresh should not update its health + if err := ss.RefreshHealth(context.Background()); err != nil { + t.Fatal(err) + } else if health(o3) != .1 { + t.Fatalf("expected health to be .1, got %v", health(o3)) + } } func TestSlabCleanupTrigger(t *testing.T) { From e4e5a8eed6d2b17222aa28e9b442366840435dde Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Wed, 6 Mar 2024 11:17:34 +0100 Subject: [PATCH 3/3] stores: add migration to performMigrations --- stores/migrations.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/stores/migrations.go b/stores/migrations.go index d89be7ab5..cb0a38b18 100644 --- a/stores/migrations.go +++ b/stores/migrations.go @@ -50,6 +50,12 @@ func performMigrations(db *gorm.DB, logger *zap.SugaredLogger) error { return performMigration(tx, dbIdentifier, "00004_prune_slabs_cascade", logger) }, }, + { + ID: "00005_zero_size_object_health", + Migrate: func(tx *gorm.DB) error { + return performMigration(tx, dbIdentifier, "00005_zero_size_object_health", logger) + }, + }, } // Create migrator.