Skip to content

Commit

Permalink
feat(ydbcp): support ttl for backups
Browse files Browse the repository at this point in the history
  • Loading branch information
ulya-sidorina committed Sep 16, 2024
1 parent 02af8fd commit 06f83e4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions internal/connectors/db/process_result_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func ReadBackupFromResultSet(res result.Result) (*types.Backup, error) {
creator *string
completedAt *time.Time
createdAt *time.Time
expireAt *time.Time
expireAtTs *timestamppb.Timestamp
)

err := res.ScanNamed(
Expand All @@ -91,6 +93,7 @@ func ReadBackupFromResultSet(res result.Result) (*types.Backup, error) {
named.Optional("status", &status),
named.Optional("message", &message),
named.Optional("size", &size),
named.Optional("expire_at", &expireAt),

named.Optional("created_at", &createdAt),
named.Optional("completed_at", &completedAt),
Expand All @@ -100,6 +103,10 @@ func ReadBackupFromResultSet(res result.Result) (*types.Backup, error) {
return nil, err
}

if expireAt != nil {
expireAtTs = timestamppb.New(*expireAt)
}

return &types.Backup{
ID: backupId,
ContainerID: containerId,
Expand All @@ -113,6 +120,7 @@ func ReadBackupFromResultSet(res result.Result) (*types.Backup, error) {
Message: StringOrEmpty(message),
AuditInfo: auditFromDb(creator, createdAt, completedAt),
Size: Int64OrZero(size),
ExpireAt: expireAtTs,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/connectors/db/yql/queries/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
"initiated", "created_at", "completed_at",
"s3_endpoint", "s3_region", "s3_bucket",
"s3_path_prefix", "status", "paths", "message",
"size",
"size", "expire_at",
}
AllOperationFields = []string{
"id", "type", "container_id", "database", "endpoint", "backup_id",
Expand Down
4 changes: 4 additions & 0 deletions internal/connectors/db/yql/queries/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ func BuildCreateBackupQuery(b types.Backup, index int) WriteSingleTableQueryImpl
d.AddValueParam("$completed_at", table_types.TimestampValueFromTime(b.AuditInfo.CompletedAt.AsTime()))
}
}

if b.ExpireAt != nil {
d.AddValueParam("$expire_at", table_types.TimestampValueFromTime(b.ExpireAt.AsTime()))
}
return d
}

Expand Down
1 change: 1 addition & 0 deletions internal/server/services/backup/backup_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func (s *BackupService) MakeBackup(ctx context.Context, req *pb.MakeBackupReques
S3Bucket: s.s3.Bucket,
S3PathPrefix: destinationPrefix,
Status: types.BackupStateRunning,
ExpireAt: nil, // TODO: set ExpireAt based on user backup ttl
AuditInfo: &pb.AuditInfo{
CreatedAt: now,
Creator: subject,
Expand Down
4 changes: 3 additions & 1 deletion internal/types/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"fmt"
"google.golang.org/protobuf/types/known/timestamppb"

pb "ydbcp/pkg/proto/ydbcp/v1alpha1"

Expand Down Expand Up @@ -36,6 +37,7 @@ type Backup struct {
Message string
AuditInfo *pb.AuditInfo
Size int64
ExpireAt *timestamppb.Timestamp
}

func (o *Backup) String() string {
Expand Down Expand Up @@ -65,7 +67,7 @@ func (o *Backup) Proto() *pb.Backup {
Size: o.Size,
Status: pb.Backup_Status(pb.Backup_Status_value[o.Status]),
Message: o.Message,
ExpireAt: nil,
ExpireAt: o.ExpireAt,
}
}

Expand Down

0 comments on commit 06f83e4

Please sign in to comment.