Skip to content

Commit

Permalink
e2: don't reopen files when new created (#12514)
Browse files Browse the repository at this point in the history
Cherry pick #12375 into `release/2.60`

Co-authored-by: Alex Sharov <AskAlexSharov@gmail.com>
  • Loading branch information
yperbasis and AskAlexSharov authored Oct 29, 2024
1 parent 501a53b commit 13e8803
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions turbo/snapshotsync/freezeblocks/block_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ func (s Segment) FileInfo(dir string) snaptype.FileInfo {
}

func (s *Segment) reopenSeg(dir string) (err error) {
s.closeSeg()
if s.Decompressor != nil {
return nil
}
s.Decompressor, err = seg.NewDecompressor(filepath.Join(dir, s.FileName()))
if err != nil {
return fmt.Errorf("%w, fileName: %s", err, s.FileName())
Expand Down Expand Up @@ -160,12 +162,7 @@ func (s *Segment) openFiles() []string {
}

func (s *Segment) reopenIdxIfNeed(dir string, optimistic bool) (err error) {
if len(s.Type().IdxFileNames(s.version, s.from, s.to)) == 0 {
return nil
}

err = s.reopenIdx(dir)

if err != nil {
if !errors.Is(err, os.ErrNotExist) {
if optimistic {
Expand All @@ -180,19 +177,25 @@ func (s *Segment) reopenIdxIfNeed(dir string, optimistic bool) (err error) {
}

func (s *Segment) reopenIdx(dir string) (err error) {
s.closeIdx()
if s.Decompressor == nil {
return nil
}
for len(s.indexes) < len(s.Type().Indexes()) {
s.indexes = append(s.indexes, nil)
}

for i, fileName := range s.Type().IdxFileNames(s.version, s.from, s.to) {
if s.indexes[i] != nil {
continue
}

for _, fileName := range s.Type().IdxFileNames(s.version, s.from, s.to) {
index, err := recsplit.OpenIndex(filepath.Join(dir, fileName))

if err != nil {
return fmt.Errorf("%w, fileName: %s", err, fileName)
}

s.indexes = append(s.indexes, index)
s.indexes[i] = index
}

return nil
Expand Down Expand Up @@ -2152,6 +2155,7 @@ func (v *View) HeadersSegment(blockNum uint64) (*Segment, bool) {
func (v *View) BodiesSegment(blockNum uint64) (*Segment, bool) {
return v.Segment(coresnaptype.Bodies, blockNum)
}

func (v *View) TxsSegment(blockNum uint64) (*Segment, bool) {
return v.Segment(coresnaptype.Transactions, blockNum)
}
Expand Down

0 comments on commit 13e8803

Please sign in to comment.