Browse Source

Merge pull request #6899 from prometheus/beorn7/isolation

Do not attempt isolation for appendID == 0
pull/6913/head
Björn Rabenstein 5 years ago committed by GitHub
parent
commit
babadf13e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      tsdb/head.go
  2. 16
      tsdb/head_test.go
  3. 3
      tsdb/isolation.go

7
tsdb/head.go

@ -1847,7 +1847,8 @@ func (s *memSeries) truncateChunksBefore(mint int64) (removed int) {
}
// append adds the sample (t, v) to the series. The caller also has to provide
// the appendID for isolation.
// the appendID for isolation. (The appendID can be zero, which results in no
// isolation for this append.)
func (s *memSeries) append(t int64, v float64, appendID uint64) (success, chunkCreated bool) {
// Based on Gorilla white papers this offers near-optimal compression ratio
// so anything bigger that this has diminishing returns and increases
@ -1885,7 +1886,9 @@ func (s *memSeries) append(t int64, v float64, appendID uint64) (success, chunkC
s.sampleBuf[2] = s.sampleBuf[3]
s.sampleBuf[3] = sample{t: t, v: v}
s.txs.add(appendID)
if appendID > 0 {
s.txs.add(appendID)
}
return true, chunkCreated
}

16
tsdb/head_test.go

@ -1558,7 +1558,7 @@ func TestIsolationLowWatermarkMonotonous(t *testing.T) {
_, err = app1.Add(labels.FromStrings("foo", "bar"), 0, 0)
testutil.Ok(t, err)
testutil.Ok(t, app1.Commit())
testutil.Equals(t, uint64(1), hb.iso.lowWatermark())
testutil.Equals(t, uint64(1), hb.iso.lowWatermark(), "Low watermark should by 1 after 1st append.")
app1 = hb.Appender()
_, err = app1.Add(labels.FromStrings("foo", "bar"), 1, 1)
@ -1580,3 +1580,17 @@ func TestIsolationLowWatermarkMonotonous(t *testing.T) {
is.Close()
testutil.Equals(t, uint64(3), hb.iso.lowWatermark(), "After read has finished (iso state closed), low watermark should jump to three.")
}
func TestIsolationAppendIDZeroIsNoop(t *testing.T) {
h, err := NewHead(nil, nil, nil, 1000, DefaultStripeSize)
testutil.Ok(t, err)
defer h.Close()
h.initTime(0)
s, _ := h.getOrCreate(1, labels.FromStrings("a", "1"))
ok, _ := s.append(0, 0, 0)
testutil.Assert(t, ok, "Series append failed.")
testutil.Equals(t, 0, s.txs.txIDCount, "Series should not have an appendID after append with appendID=0.")
}

3
tsdb/isolation.go

@ -110,7 +110,8 @@ func (i *isolation) State() *isolationState {
return isoState
}
// newAppendID increments the transaction counter and returns a new transaction ID.
// newAppendID increments the transaction counter and returns a new transaction
// ID. The first ID returned is 1.
func (i *isolation) newAppendID() uint64 {
i.appendMtx.Lock()
defer i.appendMtx.Unlock()

Loading…
Cancel
Save