mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Fix wrong byte size in WAL base ref
This commit is contained in:
parent
5fb01d41aa
commit
343dd9d94c
9
db.go
9
db.go
|
@ -58,15 +58,6 @@ type Appender interface {
|
|||
Rollback() error
|
||||
}
|
||||
|
||||
type hashedSample struct {
|
||||
hash uint64
|
||||
labels labels.Labels
|
||||
ref uint32
|
||||
|
||||
t int64
|
||||
v float64
|
||||
}
|
||||
|
||||
const sep = '\xff'
|
||||
|
||||
// DB handles reads and writes of time series falling into
|
||||
|
|
32
head.go
32
head.go
|
@ -65,10 +65,7 @@ func openHeadBlock(dir string, l log.Logger) (*headBlock, error) {
|
|||
b.stats.SeriesCount++
|
||||
},
|
||||
sample: func(s refdSample) {
|
||||
si := s.ref
|
||||
|
||||
cd := b.series[si]
|
||||
cd.append(s.t, s.v)
|
||||
b.series[s.ref].append(s.t, s.v)
|
||||
|
||||
if s.t > b.stats.MaxTime {
|
||||
b.stats.MaxTime = s.t
|
||||
|
@ -177,11 +174,11 @@ func (a *headAppender) setSeries(hash uint64, lset labels.Labels) (uint64, error
|
|||
func (a *headAppender) Add(ref uint64, t int64, v float64) error {
|
||||
// We only own the first 5 bytes of the reference. Anything before is
|
||||
// used by higher-order appenders. We erase it to avoid issues.
|
||||
ref = (ref << 31) >> 31
|
||||
ref = (ref << 24) >> 24
|
||||
|
||||
// Distinguish between existing series and series created in
|
||||
// this transaction.
|
||||
if ref&(1<<32) > 0 {
|
||||
if ref&(1<<32) != 0 {
|
||||
if _, ok := a.newSeries[ref]; !ok {
|
||||
return ErrNotFound
|
||||
}
|
||||
|
@ -189,14 +186,7 @@ func (a *headAppender) Add(ref uint64, t int64, v float64) error {
|
|||
// sample sequence is valid.
|
||||
// We also have to revalidate it as we switch locks an create
|
||||
// the new series.
|
||||
a.samples = append(a.samples, refdSample{
|
||||
ref: ref,
|
||||
t: t,
|
||||
v: v,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
} else {
|
||||
ms := a.series[int(ref)]
|
||||
if ms == nil {
|
||||
return ErrNotFound
|
||||
|
@ -211,6 +201,7 @@ func (a *headAppender) Add(ref uint64, t int64, v float64) error {
|
|||
if c.maxTime == t && ms.lastValue != v {
|
||||
return ErrAmendSample
|
||||
}
|
||||
}
|
||||
|
||||
a.samples = append(a.samples, refdSample{
|
||||
ref: ref,
|
||||
|
@ -254,12 +245,6 @@ func (a *headAppender) createSeries() {
|
|||
|
||||
func (a *headAppender) Commit() error {
|
||||
defer putHeadAppendBuffer(a.samples)
|
||||
// Write all new series and samples to the WAL and add it to the
|
||||
// in-mem database on success.
|
||||
if err := a.wal.Log(a.newLabels, a.samples); err != nil {
|
||||
a.mtx.RUnlock()
|
||||
return err
|
||||
}
|
||||
|
||||
a.createSeries()
|
||||
|
||||
|
@ -279,8 +264,15 @@ func (a *headAppender) Commit() error {
|
|||
total--
|
||||
}
|
||||
}
|
||||
|
||||
a.mtx.RUnlock()
|
||||
|
||||
// Write all new series and samples to the WAL and add it to the
|
||||
// in-mem database on success.
|
||||
if err := a.wal.Log(a.newLabels, a.samples); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
a.stats.mtx.Lock()
|
||||
defer a.stats.mtx.Unlock()
|
||||
|
||||
|
|
8
wal.go
8
wal.go
|
@ -285,7 +285,7 @@ func (e *walEncoder) encodeSamples(samples []refdSample) error {
|
|||
first := samples[0]
|
||||
|
||||
binary.BigEndian.PutUint64(b, first.ref)
|
||||
buf = append(buf, b[:4]...)
|
||||
buf = append(buf, b[:8]...)
|
||||
binary.BigEndian.PutUint64(b, uint64(first.t))
|
||||
buf = append(buf, b[:8]...)
|
||||
|
||||
|
@ -349,14 +349,14 @@ func (d *walDecoder) decodeSeries(flag byte, b []byte) error {
|
|||
}
|
||||
|
||||
func (d *walDecoder) decodeSamples(flag byte, b []byte) error {
|
||||
if len(b) < 12 {
|
||||
if len(b) < 16 {
|
||||
return errors.Wrap(errInvalidSize, "header length")
|
||||
}
|
||||
var (
|
||||
baseRef = binary.BigEndian.Uint64(b)
|
||||
baseTime = int64(binary.BigEndian.Uint64(b[4:]))
|
||||
baseTime = int64(binary.BigEndian.Uint64(b[8:]))
|
||||
)
|
||||
b = b[12:]
|
||||
b = b[16:]
|
||||
|
||||
for len(b) > 0 {
|
||||
var smpl refdSample
|
||||
|
|
Loading…
Reference in a new issue