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

fix select in ttl watcher #102

Merged
merged 1 commit into from
Nov 19, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading