Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Cai <jcai@gitlab.com>2021-10-09 01:55:17 +0300
committerJohn Cai <jcai@gitlab.com>2021-10-09 02:39:53 +0300
commit8b02feb04f52bb9af90d446da6d8d426520cfbe2 (patch)
tree4f410ccf0a9a5ba1ef2760fb68916171b056a086
parent2df83f8447aa8b77c4a3545260c2a62981a57907 (diff)
Use UTC time zone when inserting records into storage_cleanup tablejc-fix-flaky-storage-cleanup-test
A flaky test in TestStorageCleanup_AcquireNextStorage exposed an issue whereby the time values in storage_cleanup weren't being normalized to UTC. This commit fixes that.
-rw-r--r--internal/praefect/datastore/storage_cleanup.go10
-rw-r--r--internal/praefect/datastore/storage_cleanup_test.go12
2 files changed, 15 insertions, 7 deletions
diff --git a/internal/praefect/datastore/storage_cleanup.go b/internal/praefect/datastore/storage_cleanup.go
index adc43401b..0b16ca039 100644
--- a/internal/praefect/datastore/storage_cleanup.go
+++ b/internal/praefect/datastore/storage_cleanup.go
@@ -71,13 +71,13 @@ func (ss *StorageCleanup) AcquireNextStorage(ctx context.Context, inactive, upda
if err := ss.db.QueryRowContext(
ctx,
`UPDATE storage_cleanups
- SET triggered_at = NOW()
+ SET triggered_at = NOW() AT TIME ZONE 'utc'
WHERE (virtual_storage, storage) IN (
SELECT virtual_storage, storage
FROM storage_cleanups
WHERE
- COALESCE(last_run, TO_TIMESTAMP(0)) <= (NOW() - INTERVAL '1 MILLISECOND' * $1)
- AND COALESCE(triggered_at, TO_TIMESTAMP(0)) <= (NOW() - INTERVAL '1 MILLISECOND' * $2)
+ COALESCE(last_run, TO_TIMESTAMP(0)) <= (NOW() AT TIME ZONE 'utc' - INTERVAL '1 MILLISECOND' * $1)
+ AND COALESCE(triggered_at, TO_TIMESTAMP(0)) <= (NOW() AT TIME ZONE 'utc' - INTERVAL '1 MILLISECOND' * $2)
ORDER BY last_run NULLS FIRST, virtual_storage, storage
LIMIT 1
FOR UPDATE SKIP LOCKED
@@ -111,7 +111,7 @@ func (ss *StorageCleanup) AcquireNextStorage(ctx context.Context, inactive, upda
if _, err := ss.db.ExecContext(
ctx,
`UPDATE storage_cleanups
- SET triggered_at = NOW()
+ SET triggered_at = NOW() AT TIME ZONE 'utc'
WHERE virtual_storage = $1 AND storage = $2`,
entry.VirtualStorage, entry.Storage,
); err != nil {
@@ -131,7 +131,7 @@ func (ss *StorageCleanup) AcquireNextStorage(ctx context.Context, inactive, upda
if _, err := ss.db.ExecContext(
ctx,
`UPDATE storage_cleanups
- SET last_run = NOW(), triggered_at = NULL
+ SET last_run = NOW() AT TIME ZONE 'utc', triggered_at = NULL
WHERE virtual_storage = $1 AND storage = $2`,
entry.VirtualStorage, entry.Storage,
); err != nil {
diff --git a/internal/praefect/datastore/storage_cleanup_test.go b/internal/praefect/datastore/storage_cleanup_test.go
index bb8e66d75..e0be0c4b2 100644
--- a/internal/praefect/datastore/storage_cleanup_test.go
+++ b/internal/praefect/datastore/storage_cleanup_test.go
@@ -156,7 +156,10 @@ func TestStorageCleanup_AcquireNextStorage(t *testing.T) {
check1 := getAllStoragesCleanup(t, db)
require.Len(t, check1, 1)
require.True(t, check1[0].TriggeredAt.Valid)
- require.True(t, check1[0].TriggeredAt.Time.After(start), check1[0].TriggeredAt.Time.String(), start.String())
+ require.True(t,
+ check1[0].TriggeredAt.Time.After(start),
+ "%s is not after %s", check1[0].TriggeredAt.Time.String(), start.String(),
+ )
// Check the goroutine running in the background updates triggered_at column periodically.
time.Sleep(time.Second)
@@ -164,7 +167,12 @@ func TestStorageCleanup_AcquireNextStorage(t *testing.T) {
check2 := getAllStoragesCleanup(t, db)
require.Len(t, check2, 1)
require.True(t, check2[0].TriggeredAt.Valid)
- require.True(t, check2[0].TriggeredAt.Time.After(check1[0].TriggeredAt.Time), check2[0].TriggeredAt.Time.String(), check1[0].TriggeredAt.Time.String())
+ require.True(
+ t,
+ check2[0].TriggeredAt.Time.After(check1[0].TriggeredAt.Time),
+ "%s is not after %s",
+ check2[0].TriggeredAt.Time.String(),
+ check1[0].TriggeredAt.Time.String())
require.NoError(t, release())