From c004d8b9078d7cf34454013a9236635f862149b0 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Mon, 18 Apr 2022 12:26:20 +0500 Subject: [PATCH] avoid no such cpd or cpx file https://github.com/chrislusf/seaweedfs/issues/2928 --- weed/storage/volume_vacuum.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/weed/storage/volume_vacuum.go b/weed/storage/volume_vacuum.go index 06de181b5..c729d31e5 100644 --- a/weed/storage/volume_vacuum.go +++ b/weed/storage/volume_vacuum.go @@ -135,11 +135,18 @@ func (v *Volume) CommitCompact() error { } } var e error - if e = os.Rename(v.FileName(".cpd"), v.FileName(".dat")); e != nil { - return fmt.Errorf("rename %s: %v", v.FileName(".cpd"), e) + cpdFile := v.FileName(".cpd") + if _, err := os.Stat(cpdFile); err == nil { + if e = os.Rename(cpdFile, v.FileName(".dat")); e != nil { + return fmt.Errorf("rename %s: %v", v.FileName(".cpd"), e) + } + } - if e = os.Rename(v.FileName(".cpx"), v.FileName(".idx")); e != nil { - return fmt.Errorf("rename %s: %v", v.FileName(".cpx"), e) + cpxFile := v.FileName(".cpx") + if _, err := os.Stat(cpdFile); err == nil { + if e = os.Rename(cpxFile, v.FileName(".idx")); e != nil { + return fmt.Errorf("rename %s: %v", v.FileName(".cpx"), e) + } } }