Skip to content

Don't close chunks on GC thread, close chunk on flush #115

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

Merged
merged 2 commits into from
Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions ingester/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,26 +506,18 @@ func (i *Ingester) flushUser(userID string, immediate bool) {
}

func (i *Ingester) flushSeries(u *userState, fp model.Fingerprint, series *memorySeries, immediate bool) {
u.fpLocker.Lock(fp)

// Decide what chunks to flush
// Enqueue this series flushing if the oldest chunk is older than the threshold

u.fpLocker.Lock(fp)
firstTime := series.head().FirstTime()
if immediate || model.Now().Sub(firstTime) > i.cfg.MaxChunkAge {
series.headChunkClosed = true
series.head().MaybePopulateLastTime()
}
chunks := len(series.chunkDescs)
if !series.headChunkClosed {
chunks--
}
flush := immediate || model.Now().Sub(firstTime) > i.cfg.MaxChunkAge
u.fpLocker.Unlock(fp)

if chunks == 0 {
return
if flush {
flushQueueIndex := int(uint64(fp) % uint64(i.cfg.ConcurrentFlushes))
i.flushQueues[flushQueueIndex].Enqueue(&flushOp{firstTime, u.userID, fp, immediate})
}

flushQueueIndex := int(uint64(fp) % uint64(i.cfg.ConcurrentFlushes))
i.flushQueues[flushQueueIndex].Enqueue(&flushOp{firstTime, u.userID, fp, immediate})
}

func (i *Ingester) flushLoop(j int) {
Expand Down Expand Up @@ -557,8 +549,14 @@ func (i *Ingester) flushLoop(j int) {
}

userState.fpLocker.Lock(op.fp)

// Assume we're going to flush everything
chunks := series.chunkDescs
if !series.headChunkClosed {

// If the head chunk is old enough, close it
if op.immediate || model.Now().Sub(series.head().FirstTime()) > i.cfg.MaxChunkAge {
series.closeHead()
} else {
chunks = chunks[:len(chunks)-1]
}
userState.fpLocker.Unlock(op.fp)
Expand Down
5 changes: 5 additions & 0 deletions ingester/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ func (s *memorySeries) add(v model.SamplePair) (int, error) {
return len(chunks) - 1, nil
}

func (s *memorySeries) closeHead() {
s.headChunkClosed = true
s.head().MaybePopulateLastTime()
}

// head returns a pointer to the head chunk descriptor. The caller must have
// locked the fingerprint of the memorySeries. This method will panic if this
// series has no chunk descriptors.
Expand Down