Skip to content

Commit

Permalink
fix select in ttl watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Pleshakov committed Nov 19, 2024
1 parent f83aa2f commit 839cccc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
4 changes: 4 additions & 0 deletions internal/connectors/db/yql/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ $last_backup_id = SELECT MAX_BY(b.id, b.completed_at) AS last_backup_id FROM Bac
SELECT s.*, $last_backup_id AS last_backup_id, $rpo_info.recovery_point AS recovery_point, $rpo_info.last_successful_backup_id AS last_successful_backup_id FROM BackupSchedules AS s WHERE s.id = $schedule_id
`, types.BackupStateAvailable,
)
GetBackupsToDeleteQuery = fmt.Sprintf(
`SELECT * FROM Backups VIEW idx_expire_at WHERE status != '%s' and status != '%s' AND expire_at < CurrentUtcTimestamp() LIMIT 100`,
types.BackupStateDeleted,
types.BackupStateDeleting)
)
1 change: 1 addition & 0 deletions internal/connectors/db/yql/schema/create_tables.yql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CREATE TABLE Backups (

INDEX idx_container_id GLOBAL ON (container_id),
INDEX idx_created_at GLOBAL ON (created_at),
INDEX idx_expire_at GLOBAL ON (status, expire_at),
PRIMARY KEY (id)
);

Expand Down
15 changes: 2 additions & 13 deletions internal/watchers/ttl_watcher/ttl_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ttl_watcher

import (
"context"
table_types "github.com/ydb-platform/ydb-go-sdk/v3/table/types"
"go.uber.org/zap"
"google.golang.org/protobuf/types/known/timestamppb"
"sync"
Expand All @@ -28,7 +27,7 @@ func NewTtlWatcher(
func(ctx context.Context, period time.Duration) {
TtlWatcherAction(ctx, period, db, queryBuilderFactory)
},
time.Hour,
time.Minute,
"Ttl",
options...,
)
Expand All @@ -45,17 +44,7 @@ func TtlWatcherAction(

backups, err := db.SelectBackups(
ctx, queries.NewReadTableQuery(
queries.WithTableName("Backups"),
queries.WithQueryFilters(
queries.QueryFilter{
Field: "status",
Values: []table_types.Value{
table_types.StringValueFromString(types.BackupStateAvailable),
table_types.StringValueFromString(types.BackupStateError),
table_types.StringValueFromString(types.BackupStateCancelled),
},
},
),
queries.WithRawQuery(queries.GetBackupsToDeleteQuery),
),
)

Expand Down
2 changes: 1 addition & 1 deletion internal/watchers/ttl_watcher/ttl_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestTtlWatcher(t *testing.T) {
case <-ctx.Done():
t.Error("ticker not initialized")
case <-tickerInitialized:
assert.Equal(t, fakeTicker.Period, time.Hour, "incorrect period")
assert.Equal(t, fakeTicker.Period, time.Minute, "incorrect period")
}

// Send a tick to the fake ticker
Expand Down

0 comments on commit 839cccc

Please sign in to comment.