diff --git a/tsdb/head.go b/tsdb/head.go index 0ea2b8385..4a6e6ac73 100644 --- a/tsdb/head.go +++ b/tsdb/head.go @@ -2011,7 +2011,7 @@ func newMemSeries(lset labels.Labels, id chunks.HeadSeriesRef, isolationDisabled nextAt: math.MinInt64, } if !isolationDisabled { - s.txs = newTxRing(4) + s.txs = newTxRing(0) } return s } diff --git a/tsdb/isolation.go b/tsdb/isolation.go index 19eba9340..86330f36e 100644 --- a/tsdb/isolation.go +++ b/tsdb/isolation.go @@ -253,7 +253,11 @@ func newTxRing(capacity int) *txRing { func (txr *txRing) add(appendID uint64) { if int(txr.txIDCount) == len(txr.txIDs) { // Ring buffer is full, expand by doubling. - newRing := make([]uint64, txr.txIDCount*2) + newLen := txr.txIDCount * 2 + if newLen == 0 { + newLen = 4 + } + newRing := make([]uint64, newLen) idx := copy(newRing, txr.txIDs[txr.txIDFirst:]) copy(newRing[idx:], txr.txIDs[:txr.txIDFirst]) txr.txIDs = newRing @@ -265,6 +269,9 @@ func (txr *txRing) add(appendID uint64) { } func (txr *txRing) cleanupAppendIDsBelow(bound uint64) { + if len(txr.txIDs) == 0 { + return + } pos := int(txr.txIDFirst) for txr.txIDCount > 0 {