@@ -159,7 +159,6 @@ func setErrorToRetryOperation(
159159 tbwr * types.TakeBackupWithRetryOperation ,
160160 ops []types.Operation ,
161161 clock clockwork.Clock ,
162- isEmptyDb bool ,
163162) {
164163 operationIDs := strings .Join (func () []string {
165164 var ids []string
@@ -176,29 +175,26 @@ func setErrorToRetryOperation(
176175 zap .Int ("RetriesCount" , len (ops )),
177176 }
178177
179- if isEmptyDb {
180- tbwr .Message = "empty database"
181- } else {
182- if tbwr .RetryConfig != nil {
183- switch tbwr .RetryConfig .Retries .(type ) {
184- case * pb.RetryConfig_Count :
185- {
186- tbwr .Message = fmt .Sprintf ("retry attempts exceeded limit: %d." , tbwr .Retries )
187- }
188- case * pb.RetryConfig_MaxBackoff :
189- {
190- tbwr .Message = fmt .Sprintf ("retry attempts exceeded backoff duration." )
191- }
178+ if tbwr .RetryConfig != nil {
179+ switch tbwr .RetryConfig .Retries .(type ) {
180+ case * pb.RetryConfig_Count :
181+ {
182+ tbwr .Message = fmt .Sprintf ("retry attempts exceeded limit: %d." , tbwr .Retries )
183+ }
184+ case * pb.RetryConfig_MaxBackoff :
185+ {
186+ tbwr .Message = fmt .Sprintf ("retry attempts exceeded backoff duration." )
192187 }
193- } else {
194- tbwr .Message = fmt .Sprint ("retry attempts exceeded limit: 1." )
195188 }
189+ } else {
190+ tbwr .Message = fmt .Sprint ("retry attempts exceeded limit: 1." )
191+ }
196192
197- if len (ops ) > 0 {
198- tbwr .Message = tbwr .Message + fmt .Sprintf (" Launched operations %s" , operationIDs )
199- fields = append (fields , zap .String ("OperationIDs" , operationIDs ))
200- }
193+ if len (ops ) > 0 {
194+ tbwr .Message = tbwr .Message + fmt .Sprintf (" Launched operations %s" , operationIDs )
195+ fields = append (fields , zap .String ("OperationIDs" , operationIDs ))
201196 }
197+
202198 xlog .Error (ctx , tbwr .Message , fields ... )
203199}
204200
@@ -287,7 +283,7 @@ func TBWROperationHandler(
287283 return nil
288284 case Error :
289285 {
290- setErrorToRetryOperation (ctx , tbwr , ops , clock , false )
286+ setErrorToRetryOperation (ctx , tbwr , ops , clock )
291287 return db .ExecuteUpsert (ctx , queryBuilderFactory ().WithUpdateOperation (tbwr ))
292288 }
293289 case RunNewTb :
@@ -302,22 +298,35 @@ func TBWROperationHandler(
302298 types .OperationCreatorName ,
303299 clock ,
304300 )
301+
302+ tbwr .IncRetries ()
303+
305304 if err != nil {
306305 var empty * backup_operations.EmptyDatabaseError
307306
308307 if errors .As (err , & empty ) {
309- setErrorToRetryOperation (ctx , tbwr , ops , clock , true )
310- metrics .GlobalMetricsRegistry .ReportEmptyDatabase (tbwr )
311- return db .ExecuteUpsert (ctx , queryBuilderFactory ().WithUpdateOperation (tbwr ))
308+ backup , tb = backup_operations .CreateEmptyBackup (
309+ backup_operations .FromTBWROperation (tbwr ),
310+ clock ,
311+ )
312+ xlog .Debug (
313+ ctx ,
314+ "Created empty backup instance for empty db" ,
315+ zap .String ("BackupID" , backup .ID ),
316+ zap .String ("TBOperationID" , tb .ID ),
317+ )
318+ tbwr .State = types .OperationStateDone
319+ tbwr .Message = "Success"
320+ now := clock .Now ()
321+ tbwr .UpdatedAt = timestamppb .New (now )
322+ tbwr .Audit .CompletedAt = timestamppb .New (now )
323+ return db .ExecuteUpsert (ctx , queryBuilderFactory ().WithCreateBackup (* backup ).WithCreateOperation (tb ).WithUpdateOperation (tbwr ))
312324 } else {
313- tbwr .IncRetries ()
314- metrics .GlobalMetricsRegistry .ResetEmptyDatabase (tbwr )
325+ //increment retries
315326 return db .ExecuteUpsert (ctx , queryBuilderFactory ().WithUpdateOperation (tbwr ))
316327 }
317328 } else {
318- metrics .GlobalMetricsRegistry .ResetEmptyDatabase (tbwr )
319329 xlog .Debug (ctx , "running new TB" , zap .String ("TBOperationID" , tb .ID ))
320- tbwr .IncRetries ()
321330 return db .ExecuteUpsert (ctx , queryBuilderFactory ().WithCreateBackup (* backup ).WithCreateOperation (tb ).WithUpdateOperation (tbwr ))
322331 }
323332 }
0 commit comments