Skip to content

Commit

Permalink
fix(store): use symlinks for empty blocks heighs (#3747)
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss committed Sep 18, 2024
1 parent 89e8781 commit 2c67306
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,12 @@ func (s *Store) linkHeight(datahash share.DataHash, height uint64) error {
// create hard link with height as name
pathOds := s.hashToPath(datahash, odsFileExt)
linktoOds := s.heightToPath(height, odsFileExt)
return link(pathOds, linktoOds)
if datahash.IsEmptyEDS() {
// empty EDS is always symlinked, because there is limited number of hardlinks
// for the same file in some filesystems (ext4)
return symlink(pathOds, linktoOds)
}
return hardLink(pathOds, linktoOds)
}

// populateEmptyFile writes fresh empty EDS file on disk.
Expand Down Expand Up @@ -407,14 +412,22 @@ func mkdir(path string) error {
return nil
}

func link(filepath, linkpath string) error {
func hardLink(filepath, linkpath string) error {
err := os.Link(filepath, linkpath)
if err != nil && !errors.Is(err, os.ErrExist) {
return fmt.Errorf("creating hardlink (%s -> %s): %w", filepath, linkpath, err)
}
return nil
}

func symlink(filepath, linkpath string) error {
err := os.Symlink(filepath, linkpath)
if err != nil && !errors.Is(err, os.ErrExist) {
return fmt.Errorf("creating symlink (%s -> %s): %w", filepath, linkpath, err)
}
return nil
}

func exists(path string) (bool, error) {
_, err := os.Stat(path)
switch {
Expand Down

0 comments on commit 2c67306

Please sign in to comment.