diff --git a/internal/op/storage.go b/internal/op/storage.go index d7871c64ad0..8c0c6c1206f 100644 --- a/internal/op/storage.go +++ b/internal/op/storage.go @@ -94,19 +94,14 @@ func EnableStorage(ctx context.Context, id uint) error { if !storage.Disabled { return errors.Errorf("this storage have enabled") } - err = LoadStorage(ctx, *storage) - if err != nil { - return errors.WithMessage(err, "failed load storage") - } - // re-get storage from db, because it maybe hava updated - storage, err = db.GetStorageById(id) - if err != nil { - return errors.WithMessage(err, "failed re-get storage again") - } storage.Disabled = false err = db.UpdateStorage(storage) if err != nil { - return errors.WithMessage(err, "failed update storage in db, but have load in memory. you can try restart") + return errors.WithMessage(err, "failed update storage in db") + } + err = LoadStorage(ctx, *storage) + if err != nil { + return errors.WithMessage(err, "failed load storage") } return nil } @@ -128,12 +123,12 @@ func DisableStorage(ctx context.Context, id uint) error { return errors.Wrapf(err, "failed drop storage") } // delete the storage in the memory - storagesMap.Delete(storage.MountPath) storage.Disabled = true err = db.UpdateStorage(storage) if err != nil { - return errors.WithMessage(err, "failed update storage in db, but have drop in memory. you can try restart") + return errors.WithMessage(err, "failed update storage in db") } + storagesMap.Delete(storage.MountPath) return nil } diff --git a/pkg/cron/cron.go b/pkg/cron/cron.go index 77d94c74153..3a3e978cfa0 100644 --- a/pkg/cron/cron.go +++ b/pkg/cron/cron.go @@ -30,6 +30,10 @@ func (c *Cron) Do(f func()) { } func (c *Cron) Stop() { - c.ch <- struct{}{} - close(c.ch) + select { + case _, _ = <-c.ch: + default: + c.ch <- struct{}{} + close(c.ch) + } } diff --git a/pkg/cron/cron_test.go b/pkg/cron/cron_test.go index 6e718762e03..1bd7cf2dfa3 100644 --- a/pkg/cron/cron_test.go +++ b/pkg/cron/cron_test.go @@ -10,6 +10,7 @@ func TestCron(t *testing.T) { c.Do(func() { t.Logf("cron log") }) - time.Sleep(time.Second * 5) + time.Sleep(time.Second * 3) + c.Stop() c.Stop() }