Skip to content
This repository was archived by the owner on Aug 13, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,11 @@ func (db *DB) beyondSizeRetention(blocks []*Block) (deleteable map[ulid.ULID]*Bl
}

deleteable = make(map[ulid.ULID]*Block)
blocksSize := int64(0)
walSize, _ := db.Head().wal.Size()

// Initializing the size counter with the WAL size,
// as that is part of the retention strategy as well.
blocksSize := walSize
for i, block := range blocks {
blocksSize += block.Size()
if blocksSize > db.opts.MaxBytes {
Expand Down Expand Up @@ -774,13 +778,13 @@ func (o Overlaps) String() string {
m.ULID.String(),
m.MinTime,
m.MaxTime,
(time.Duration((m.MaxTime-m.MinTime)/1000)*time.Second).String(),
(time.Duration((m.MaxTime-m.MinTime)/1000) * time.Second).String(),
))
}
res = append(res, fmt.Sprintf(
"[mint: %d, maxt: %d, range: %s, blocks: %d]: %s",
r.Min, r.Max,
(time.Duration((r.Max-r.Min)/1000)*time.Second).String(),
(time.Duration((r.Max-r.Min)/1000) * time.Second).String(),
len(overlaps),
strings.Join(groups, ", ")),
)
Expand Down
14 changes: 14 additions & 0 deletions wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,3 +834,17 @@ func (r *segmentBufReader) Read(b []byte) (n int, err error) {
r.buf.Reset(r.segs[r.cur])
return n, nil
}

// Computing size of the WAL.
// We do this by counting the number of segments currently used by the WAL,
// and multiplying it by the size of a segment.
func (w *WAL) Size() (size int64, err error) {
first, last, err := w.Segments()
if err != nil {
return 0, err
}
if first == -1 || last == -1 {
return 0, fmt.Errorf("no segments found in WAL")
}
return int64((last - first + 1) * w.segmentSize), nil
}