Skip to content

Commit

Permalink
revert changes in tsdb/index.go
Browse files Browse the repository at this point in the history
  • Loading branch information
korniltsev committed Aug 7, 2024
1 parent 2e24794 commit 2188cde
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
7 changes: 2 additions & 5 deletions pkg/experiment/querybackend/block/compaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,8 @@ func (rw *indexRewriter) rewriteRow(e ProfileEntry) error {
func (rw *indexRewriter) NumSeries() uint64 { return uint64(len(rw.series)) }

func (rw *indexRewriter) Flush() error {
w, err := index.NewWriterSize(context.Background(),
filepath.Join(rw.path, block.IndexFilename),
// There is no particular reason to use a buffer (bufio.Writer)
// larger than the default one when writing on disk
4<<10)
w, err := index.NewWriter(context.Background(),
filepath.Join(rw.path, block.IndexFilename))
if err != nil {
return err
}
Expand Down
21 changes: 8 additions & 13 deletions pkg/phlaredb/tsdb/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ func NewTOCFromByteSlice(bs ByteSlice) (*TOC, error) {

// NewWriter returns a new Writer to the given filename. It serializes data in format version 2.
func NewWriter(ctx context.Context, fn string) (*Writer, error) {
return NewWriterSize(ctx, fn, 4<<20)
}

func NewWriterSize(ctx context.Context, fn string, bufferSize int) (*Writer, error) {
dir := filepath.Dir(fn)

df, err := fileutil.OpenDir(dir)
Expand All @@ -225,17 +221,17 @@ func NewWriterSize(ctx context.Context, fn string, bufferSize int) (*Writer, err
}

// Main index file we are building.
f, err := NewFileWriter(fn, bufferSize)
f, err := NewFileWriter(fn)
if err != nil {
return nil, err
}
// Temporary file for postings.
fP, err := NewFileWriter(fn+"_tmp_p", bufferSize)
fP, err := NewFileWriter(fn + "_tmp_p")
if err != nil {
return nil, err
}
// Temporary file for posting offset table.
fPO, err := NewFileWriter(fn+"_tmp_po", bufferSize)
fPO, err := NewFileWriter(fn + "_tmp_po")
if err != nil {
return nil, err
}
Expand All @@ -251,8 +247,8 @@ func NewWriterSize(ctx context.Context, fn string, bufferSize int) (*Writer, err
stage: idxStageNone,

// Reusable memory.
buf1: encoding.EncWrap(tsdb_enc.Encbuf{B: make([]byte, 0, bufferSize)}),
buf2: encoding.EncWrap(tsdb_enc.Encbuf{B: make([]byte, 0, bufferSize)}),
buf1: encoding.EncWrap(tsdb_enc.Encbuf{B: make([]byte, 0, 1<<22)}),
buf2: encoding.EncWrap(tsdb_enc.Encbuf{B: make([]byte, 0, 1<<22)}),

symbolCache: make(map[string]symbolCacheEntry, 1<<8),
labelNames: make(map[string]uint64, 1<<8),
Expand Down Expand Up @@ -283,14 +279,14 @@ type FileWriter struct {
name string
}

func NewFileWriter(name string, bufferSize int) (*FileWriter, error) {
func NewFileWriter(name string) (*FileWriter, error) {
f, err := os.OpenFile(name, os.O_CREATE|os.O_RDWR, 0o666)
if err != nil {
return nil, err
}
return &FileWriter{
f: f,
fbuf: bufio.NewWriterSize(f, bufferSize),
fbuf: bufio.NewWriterSize(f, 1<<22),
pos: 0,
name: name,
}, nil
Expand Down Expand Up @@ -1080,8 +1076,7 @@ func (w *Writer) writePostings() error {
return err
}
// Don't need to calculate a checksum, so can copy directly.
buf := w.buf1.B[:cap(w.buf1.B)]
n, err := io.CopyBuffer(w.f.fbuf, w.fP.f, buf)
n, err := io.CopyBuffer(w.f.fbuf, w.fP.f, make([]byte, 1<<20))
if err != nil {
return err
}
Expand Down

0 comments on commit 2188cde

Please sign in to comment.