Skip to content

Commit

Permalink
fix bug in spill file name allocation (#1391)
Browse files Browse the repository at this point in the history
The recent refactor of the spill code into its own module introduced
a bug where the file names could collide because they were named
after their position in the spill table, which grows and shrinks.
This caused distinct spills to have the same file name.  The fix is
to track the total number of spills and name the file after this.
  • Loading branch information
mccanne authored Sep 29, 2020
1 parent 0ecc775 commit aac5d89
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions proc/spill/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
// disk a chunk at a time, then read back and merged in sorted order, effectively
// implementing an external merge sort.
type MergeSort struct {
nspill int
runs []*peeker
compareFn expr.CompareFn
tempDir string
Expand Down Expand Up @@ -60,12 +61,12 @@ func (r *MergeSort) Cleanup() {
// the chunks sequentially.
func (r *MergeSort) Spill(recs []*zng.Record) error {
expr.SortStable(recs, r.compareFn)
index := len(r.runs)
filename := filepath.Join(r.tempDir, strconv.Itoa(index))
runFile, err := newPeeker(filename, index, recs, r.zctx)
filename := filepath.Join(r.tempDir, strconv.Itoa(r.nspill))
runFile, err := newPeeker(filename, r.nspill, recs, r.zctx)
if err != nil {
return err
}
r.nspill++
heap.Push(r, runFile)
return nil
}
Expand Down

0 comments on commit aac5d89

Please sign in to comment.