mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
fixed the empty dirs not being removed (#15573)
* fixed the empty dirs not being removed * update list empty dirs first --------- Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com> Co-authored-by: kasey <489222+kasey@users.noreply.github.com>
This commit is contained in:
@@ -116,19 +116,43 @@ func (l *periodicEpochLayout) pruneBefore(before primitives.Epoch) (*pruneSummar
|
||||
}
|
||||
// Roll up summaries and clean up per-epoch directories.
|
||||
rollup := &pruneSummary{}
|
||||
|
||||
// Track which period directories might be empty after epoch removal
|
||||
periodsToCheck := make(map[string]struct{})
|
||||
|
||||
for epoch, sum := range sums {
|
||||
rollup.blobsPruned += sum.blobsPruned
|
||||
rollup.failedRemovals = append(rollup.failedRemovals, sum.failedRemovals...)
|
||||
rmdir := l.epochDir(epoch)
|
||||
periodDir := l.periodDir(epoch)
|
||||
|
||||
if len(sum.failedRemovals) == 0 {
|
||||
if err := l.fs.Remove(rmdir); err != nil {
|
||||
log.WithField("dir", rmdir).WithError(err).Error("Failed to remove epoch directory while pruning")
|
||||
} else {
|
||||
periodsToCheck[periodDir] = struct{}{}
|
||||
}
|
||||
} else {
|
||||
log.WithField("dir", rmdir).WithField("numFailed", len(sum.failedRemovals)).WithError(err).Error("Unable to remove epoch directory due to pruning failures")
|
||||
}
|
||||
}
|
||||
|
||||
//Clean up empty period directories
|
||||
for periodDir := range periodsToCheck {
|
||||
entries, err := afero.ReadDir(l.fs, periodDir)
|
||||
if err != nil {
|
||||
log.WithField("dir", periodDir).WithError(err).Debug("Failed to read period directory contents")
|
||||
continue
|
||||
}
|
||||
|
||||
// Only attempt to remove if directory is empty
|
||||
if len(entries) == 0 {
|
||||
if err := l.fs.Remove(periodDir); err != nil {
|
||||
log.WithField("dir", periodDir).WithError(err).Error("Failed to remove empty period directory")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rollup, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/binary"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/OffchainLabs/prysm/v6/beacon-chain/verification"
|
||||
"github.com/OffchainLabs/prysm/v6/config/params"
|
||||
@@ -195,3 +196,48 @@ func TestLayoutPruneBefore(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLayoutByEpochPruneBefore(t *testing.T) {
|
||||
roots := testRoots(10)
|
||||
cases := []struct {
|
||||
name string
|
||||
pruned []testIdent
|
||||
remain []testIdent
|
||||
err error
|
||||
sum pruneSummary
|
||||
}{
|
||||
{
|
||||
name: "single epoch period cleanup",
|
||||
pruned: []testIdent{
|
||||
{offset: 0, blobIdent: blobIdent{root: roots[0], epoch: 367076, index: 0}},
|
||||
},
|
||||
remain: []testIdent{
|
||||
{offset: 0, blobIdent: blobIdent{root: roots[1], epoch: 371176, index: 0}}, // Different period
|
||||
},
|
||||
sum: pruneSummary{blobsPruned: 1},
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
fs, bs := NewEphemeralBlobStorageAndFs(t, WithLayout(LayoutNameByEpoch))
|
||||
pruned := testSetupBlobIdentPaths(t, fs, bs, c.pruned)
|
||||
remain := testSetupBlobIdentPaths(t, fs, bs, c.remain)
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
for _, id := range pruned {
|
||||
_, err := fs.Stat(bs.layout.sszPath(id))
|
||||
require.Equal(t, true, os.IsNotExist(err))
|
||||
|
||||
dirs := bs.layout.blockParentDirs(id)
|
||||
for i := len(dirs) - 1; i > 0; i-- {
|
||||
_, err = fs.Stat(dirs[i])
|
||||
require.Equal(t, true, os.IsNotExist(err))
|
||||
}
|
||||
}
|
||||
for _, id := range remain {
|
||||
_, err := fs.Stat(bs.layout.sszPath(id))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
3
changelog/muzry_fix_unremove_empty_dir.md
Normal file
3
changelog/muzry_fix_unremove_empty_dir.md
Normal file
@@ -0,0 +1,3 @@
|
||||
### Fixed
|
||||
|
||||
- Fixed the issue of empty dirs not being deleted when using –blob-storage-layout=by-epoch
|
||||
Reference in New Issue
Block a user