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
Changes from 1 commit
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
31 changes: 15 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,15 @@ 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.headChunkClosed = true
series.head().MaybePopulateLastTime()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of surprised series doesn't have a method that does both of these together, since it seems like a vaguely atomic operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah its done under the lock, but could move the logic to series. Will do.

} else {
chunks = chunks[:len(chunks)-1]
}
userState.fpLocker.Unlock(op.fp)
Expand Down