diff --git a/storagenode/collector/service_test.go b/storagenode/collector/service_test.go index cf7cbd1ad..82c8b5485 100644 --- a/storagenode/collector/service_test.go +++ b/storagenode/collector/service_test.go @@ -99,8 +99,6 @@ func TestCollector(t *testing.T) { require.Equal(t, 0, serialsPresent) - serialsPresent = 0 - // imagine we are 10 days in the future for _, storageNode := range planet.StorageNodes { pieceinfos := storageNode.DB.PieceInfo() @@ -123,5 +121,7 @@ func TestCollector(t *testing.T) { collections++ } + + require.Equal(t, 0, serialsPresent) }) } diff --git a/storagenode/pieces/db_test.go b/storagenode/pieces/db_test.go index f0bc557bc..e94ae2688 100644 --- a/storagenode/pieces/db_test.go +++ b/storagenode/pieces/db_test.go @@ -86,13 +86,17 @@ func TestPieceInfo(t *testing.T) { }) require.NoError(t, err) + // use different timezones + location := time.FixedZone("XYZ", int((8 * time.Hour).Seconds())) + now2 := now.In(location) + info2 := &pieces.Info{ SatelliteID: satellite2.ID, PieceID: pieceid0, PieceSize: 123, - PieceCreation: now, - PieceExpiration: now, + PieceCreation: now2, + PieceExpiration: now2, UplinkPieceHash: piecehash2, } diff --git a/storagenode/piecestore/serials_test.go b/storagenode/piecestore/serials_test.go index 9250ebd03..3fb620d75 100644 --- a/storagenode/piecestore/serials_test.go +++ b/storagenode/piecestore/serials_test.go @@ -49,11 +49,14 @@ func TestUsedSerials(t *testing.T) { Expiration time.Time } + // use different timezones + location := time.FixedZone("XYZ", int((8 * time.Hour).Seconds())) + serialNumbers := []Serial{ {node0.ID, serial1, now.Add(time.Minute)}, {node0.ID, serial2, now.Add(4 * time.Minute)}, - {node0.ID, serial3, now.Add(8 * time.Minute)}, - {node1.ID, serial1, now.Add(time.Minute)}, + {node0.ID, serial3, now.In(location).Add(8 * time.Minute)}, + {node1.ID, serial1, now.In(location).Add(time.Minute)}, {node1.ID, serial2, now.Add(4 * time.Minute)}, {node1.ID, serial3, now.Add(8 * time.Minute)}, } diff --git a/storagenode/storagenodedb/bandwidthdb.go b/storagenode/storagenodedb/bandwidthdb.go index ace2e8b93..27f0cbc8f 100644 --- a/storagenode/storagenodedb/bandwidthdb.go +++ b/storagenode/storagenodedb/bandwidthdb.go @@ -88,7 +88,7 @@ func (db *bandwidthdb) Summary(ctx context.Context, from, to time.Time) (_ *band rows, err := db.db.Query(` SELECT action, sum(amount) FROM bandwidth_usage - WHERE ? <= created_at AND created_at <= ? + WHERE datetime(?) <= datetime(created_at) AND datetime(created_at) <= datetime(?) GROUP BY action`, from, to) if err != nil { if err == sql.ErrNoRows { @@ -120,7 +120,7 @@ func (db *bandwidthdb) SummaryBySatellite(ctx context.Context, from, to time.Tim rows, err := db.db.Query(` SELECT satellite_id, action, sum(amount) FROM bandwidth_usage - WHERE ? <= created_at AND created_at <= ? + WHERE datetime(?) <= datetime(created_at) AND datetime(created_at) <= datetime(?) GROUP BY satellite_id, action`, from, to) if err != nil { if err == sql.ErrNoRows { diff --git a/storagenode/storagenodedb/pieceinfo.go b/storagenode/storagenodedb/pieceinfo.go index 488e55c00..51015cdfd 100644 --- a/storagenode/storagenodedb/pieceinfo.go +++ b/storagenode/storagenodedb/pieceinfo.go @@ -160,7 +160,7 @@ func (db *pieceinfo) GetExpired(ctx context.Context, expiredAt time.Time, limit rows, err := db.db.QueryContext(ctx, db.Rebind(` SELECT satellite_id, piece_id, piece_size FROM pieceinfo - WHERE piece_expiration < ? AND ((deletion_failed_at IS NULL) OR deletion_failed_at <> ?) + WHERE datetime(piece_expiration) < datetime(?) AND ((deletion_failed_at IS NULL) OR datetime(deletion_failed_at) <> datetime(?)) ORDER BY satellite_id LIMIT ? `), expiredAt, expiredAt, limit) diff --git a/storagenode/storagenodedb/usedserials.go b/storagenode/storagenodedb/usedserials.go index 73c334810..861803c59 100644 --- a/storagenode/storagenodedb/usedserials.go +++ b/storagenode/storagenodedb/usedserials.go @@ -39,7 +39,7 @@ func (db *usedSerials) Add(ctx context.Context, satelliteID storj.NodeID, serial func (db *usedSerials) DeleteExpired(ctx context.Context, now time.Time) (err error) { defer mon.Task()(&ctx)(&err) - _, err = db.db.Exec(`DELETE FROM used_serial WHERE expiration < ?`, now) + _, err = db.db.Exec(`DELETE FROM used_serial WHERE datetime(expiration) < datetime(?)`, now) return ErrInfo.Wrap(err) }