mrproliu commented on code in PR #1181:
URL: 
https://github.com/apache/skywalking-banyandb/pull/1181#discussion_r3427195479


##########
banyand/backup/backup.go:
##########
@@ -94,7 +104,19 @@ func NewBackupCommand() *cobra.Command {
                        schedLogger.Info().Msgf("backup to %s will run with 
schedule: %s", backupOpts.dest, backupOpts.schedule)
                        clockInstance := clock.New()
                        sch := timestamp.NewScheduler(schedLogger, 
clockInstance)
+                       // A full backup may legitimately run longer than the 
schedule interval.
+                       // The scheduler abandons (but does not cancel) an 
action that exceeds its
+                       // internal timeout, so without this guard a slow run 
would overlap with the
+                       // next scheduled run, stacking concurrent uploads 
until the process is
+                       // OOM-killed. backupInFlight ensures only one backup 
runs at a time: a tick
+                       // that fires while the previous run is still in 
progress is skipped.
+                       var backupInFlight atomic.Bool
                        err := sch.Register(cmd.Context(), "backup", 
cron.Descriptor, backupOpts.schedule, func(ctx context.Context, _ time.Time, l 
*logger.Logger) bool {
+                               if !backupInFlight.CompareAndSwap(false, true) {
+                                       l.Warn().Msg("previous backup is still 
running; skipping this scheduled run")
+                                       return true
+                               }
+                               defer backupInFlight.Store(false)

Review Comment:
   No need to be fixed, the `defer` could be handle with `panic`. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to