Merge pull request #286 from mattbostock/rename_high_timestamp

head: Rename highTimestamp to maxt
This commit is contained in:
Goutham Veeramachaneni 2018-04-05 17:41:48 +05:30 committed by GitHub
commit 90d55672d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

25
head.go
View file

@ -449,10 +449,10 @@ func (h *Head) Appender() Appender {
func (h *Head) appender() *headAppender { func (h *Head) appender() *headAppender {
return &headAppender{ return &headAppender{
head: h, head: h,
mint: h.MaxTime() - h.chunkRange/2, mint: h.MaxTime() - h.chunkRange/2,
samples: h.getAppendBuffer(), maxt: math.MinInt64,
highTimestamp: math.MinInt64, samples: h.getAppendBuffer(),
} }
} }
@ -469,12 +469,11 @@ func (h *Head) putAppendBuffer(b []RefSample) {
} }
type headAppender struct { type headAppender struct {
head *Head head *Head
mint int64 mint, maxt int64
series []RefSeries series []RefSeries
samples []RefSample samples []RefSample
highTimestamp int64
} }
func (a *headAppender) Add(lset labels.Labels, t int64, v float64) (uint64, error) { func (a *headAppender) Add(lset labels.Labels, t int64, v float64) (uint64, error) {
@ -508,8 +507,8 @@ func (a *headAppender) AddFast(ref uint64, t int64, v float64) error {
if t < a.mint { if t < a.mint {
return ErrOutOfBounds return ErrOutOfBounds
} }
if t > a.highTimestamp { if t > a.maxt {
a.highTimestamp = t a.maxt = t
} }
a.samples = append(a.samples, RefSample{ a.samples = append(a.samples, RefSample{
@ -551,10 +550,10 @@ func (a *headAppender) Commit() error {
for { for {
ht := a.head.MaxTime() ht := a.head.MaxTime()
if a.highTimestamp <= ht { if a.maxt <= ht {
break break
} }
if atomic.CompareAndSwapInt64(&a.head.maxTime, ht, a.highTimestamp) { if atomic.CompareAndSwapInt64(&a.head.maxTime, ht, a.maxt) {
break break
} }
} }