Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:when the shard is created, disk iops is high, causing http write … #24584

Open
wants to merge 1 commit into
base: master-1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 28 additions & 3 deletions tsdb/index/tsi1/log_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"hash/crc32"
"io"
"math/rand"
"os"
"sort"
"sync"
Expand Down Expand Up @@ -215,6 +216,22 @@ func (f *LogFile) FlushAndSync() error {
return f.file.Sync()
}

// FlushAndSync flushes buffered data to disk
// If the LogFile has disabled flushing and syncing then FlushAndSync is a no-op.
func (f *LogFile) Flush() error {
if f.nosync {
return nil
}

if f.w != nil {
if err := f.w.Flush(); err != nil {
return err
}
}

return nil
}

// ID returns the file sequence identifier.
func (f *LogFile) ID() int { return f.id }

Expand Down Expand Up @@ -565,10 +582,18 @@ func (f *LogFile) AddSeriesList(seriesSet *tsdb.SeriesIDSet, names [][]byte, tag
seriesSet.AddNoLock(entry.SeriesID)
}

// Flush buffer and sync to disk.
if err := f.FlushAndSync(); err != nil {
return nil, err
if rand.Intn(100) < 10 {
// Flush buffer and sync to disk.
if err := f.FlushAndSync(); err != nil {
return nil, err
}
} else {
// Flush buffer.
if err := f.Flush(); err != nil {
return nil, err
}
}

return seriesIDs, nil
}

Expand Down