@@ -13,6 +13,8 @@ import (
13
13
"time"
14
14
15
15
"github.com/pkg/errors"
16
+ "go.uber.org/atomic"
17
+
16
18
"github.com/scylladb/go-log"
17
19
"github.com/scylladb/go-set/strset"
18
20
"github.com/scylladb/gocqlx/v2"
@@ -30,7 +32,6 @@ import (
30
32
"github.com/scylladb/scylla-manager/v3/pkg/util/parallel"
31
33
"github.com/scylladb/scylla-manager/v3/pkg/util/timeutc"
32
34
"github.com/scylladb/scylla-manager/v3/pkg/util/uuid"
33
- "go.uber.org/atomic"
34
35
)
35
36
36
37
var (
@@ -1190,24 +1191,23 @@ func (s *Service) DeleteSnapshot(ctx context.Context, clusterID uuid.UUID, locat
1190
1191
//
1191
1192
// It returns deleted Manifests. if dryRun is true nothing is deleted.
1192
1193
func (s * Service ) PurgeBackups (ctx context.Context , clusterID uuid.UUID , locations Locations , retentionMap RetentionMap , dryRun bool ) (deleted Manifests , err error ) {
1193
- if locations .Len () == 0 {
1194
- return nil , errorNoLocation
1195
- }
1196
- locations = locations .Unique ()
1197
- logger := s .logger
1194
+ logger := s .logger .Named ("PurgeBackups" )
1198
1195
if dryRun {
1199
1196
logger = log .NopLogger
1200
1197
}
1201
-
1202
- logger .Info (ctx , "Purging stale snapshots..." )
1203
-
1204
- defer func (start time.Time ) {
1198
+ logger .Debug (ctx , "Start" , "cluster" , clusterID , "locations" , locations , "retentionMap" , retentionMap , "dryRun" , dryRun )
1199
+ start := timeutc .Now ()
1200
+ defer func () {
1205
1201
if err != nil {
1206
- logger .Error (ctx , "Manual purging stale snapshots failed see exact errors above" , "duration" , timeutc .Since (start ))
1207
- } else {
1208
- logger .Info (ctx , "Done manual purging stale snapshots" , "duration" , timeutc .Since (start ))
1202
+ logger .Error (ctx , "Got an error" , "error" , err , "duration" , timeutc .Since (start ))
1209
1203
}
1210
- }(timeutc .Now ())
1204
+ logger .Debug (ctx , "Done" , "deleted manifests" , deleted , "duration" , timeutc .Since (start ))
1205
+ }()
1206
+
1207
+ if locations .Len () == 0 {
1208
+ return nil , errorNoLocation
1209
+ }
1210
+ locations = locations .Unique ()
1211
1211
1212
1212
deleted = make (Manifests , 0 )
1213
1213
@@ -1229,11 +1229,11 @@ func (s *Service) PurgeBackups(ctx context.Context, clusterID uuid.UUID, locatio
1229
1229
}
1230
1230
1231
1231
// List manifests in all locations
1232
- manifests , err := listManifestsInAllLocations (ctx , client , hosts , clusterID )
1232
+ var manifests Manifests
1233
+ manifests , err = listManifestsInAllLocations (ctx , client , hosts , clusterID )
1233
1234
if err != nil {
1234
1235
return nil , errors .Wrap (err , "list manifests" )
1235
1236
}
1236
-
1237
1237
// Get a list of stale tags
1238
1238
tags , oldest , err := staleTags (manifests , retentionMap , true )
1239
1239
if err != nil {
@@ -1262,16 +1262,17 @@ func (s *Service) PurgeBackups(ctx context.Context, clusterID uuid.UUID, locatio
1262
1262
p := newPurger (client , hostIP , logg )
1263
1263
1264
1264
p .OnDelete = func (total , success int ) {
1265
- if ! dryRun {
1266
- s . metrics . Backup . SetPurgeFiles ( clusterID , hostIP , total , success )
1265
+ if dryRun {
1266
+ return
1267
1267
}
1268
+ s .metrics .Backup .SetPurgeFiles (clusterID , hostIP , total , success )
1268
1269
}
1269
1270
1270
1271
logg .Info (ctx , "Purging stale snapshots of node from host" )
1271
1272
defer logg .Info (ctx , "Done purging stale snapshots of node from host" )
1272
1273
1273
1274
var del Manifests
1274
- del , err = p .PurgeSnapshotTags (ctx , manifests , tags , oldest , dryRun )
1275
+ del , err = p .PurgeSnapshotTags (ctx , m , tags , oldest , dryRun )
1275
1276
1276
1277
if err != nil {
1277
1278
return err
@@ -1286,9 +1287,7 @@ func (s *Service) PurgeBackups(ctx context.Context, clusterID uuid.UUID, locatio
1286
1287
if dryRun {
1287
1288
return nil
1288
1289
}
1289
-
1290
- for idx := range del {
1291
- snapshot := del [idx ].SnapshotTag
1290
+ for _ , snapshot := range del .GetSnapshots () {
1292
1291
if err = client .DeleteSnapshot (ctx , hostIP , snapshot ); err != nil {
1293
1292
logg .Error (ctx , "Failed to delete uploaded snapshot" ,
1294
1293
"host" , hostIP ,
@@ -1306,6 +1305,5 @@ func (s *Service) PurgeBackups(ctx context.Context, clusterID uuid.UUID, locatio
1306
1305
}
1307
1306
1308
1307
parallel .RunMap [string , Manifests ](nodeIDManifests , runFunc , nil , 10 )
1309
-
1310
1308
return deleted , err
1311
1309
}
0 commit comments