Merge pull request #6899 from prometheus/beorn7/isolation

Do not attempt isolation for appendID == 0
This commit is contained in:
Björn Rabenstein 2020-03-01 16:21:39 +01:00 committed by GitHub
commit babadf13e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 4 deletions

View File

@ -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 // 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) { func (s *memSeries) append(t int64, v float64, appendID uint64) (success, chunkCreated bool) {
// Based on Gorilla white papers this offers near-optimal compression ratio // Based on Gorilla white papers this offers near-optimal compression ratio
// so anything bigger that this has diminishing returns and increases // 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[2] = s.sampleBuf[3]
s.sampleBuf[3] = sample{t: t, v: v} s.sampleBuf[3] = sample{t: t, v: v}
s.txs.add(appendID) if appendID > 0 {
s.txs.add(appendID)
}
return true, chunkCreated return true, chunkCreated
} }

View File

@ -1558,7 +1558,7 @@ func TestIsolationLowWatermarkMonotonous(t *testing.T) {
_, err = app1.Add(labels.FromStrings("foo", "bar"), 0, 0) _, err = app1.Add(labels.FromStrings("foo", "bar"), 0, 0)
testutil.Ok(t, err) testutil.Ok(t, err)
testutil.Ok(t, app1.Commit()) 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() app1 = hb.Appender()
_, err = app1.Add(labels.FromStrings("foo", "bar"), 1, 1) _, err = app1.Add(labels.FromStrings("foo", "bar"), 1, 1)
@ -1580,3 +1580,17 @@ func TestIsolationLowWatermarkMonotonous(t *testing.T) {
is.Close() is.Close()
testutil.Equals(t, uint64(3), hb.iso.lowWatermark(), "After read has finished (iso state closed), low watermark should jump to three.") 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.")
}

View File

@ -110,7 +110,8 @@ func (i *isolation) State() *isolationState {
return isoState 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 { func (i *isolation) newAppendID() uint64 {
i.appendMtx.Lock() i.appendMtx.Lock()
defer i.appendMtx.Unlock() defer i.appendMtx.Unlock()