Initial implementation of Delete on DB.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
This commit is contained in:
parent
d6bd64357b
commit
3dbb400bef
13
block.go
13
block.go
|
@ -218,10 +218,11 @@ func (pb *persistedBlock) String() string {
|
||||||
|
|
||||||
func (pb *persistedBlock) Querier(mint, maxt int64) Querier {
|
func (pb *persistedBlock) Querier(mint, maxt int64) Querier {
|
||||||
return &blockQuerier{
|
return &blockQuerier{
|
||||||
mint: mint,
|
mint: mint,
|
||||||
maxt: maxt,
|
maxt: maxt,
|
||||||
index: pb.Index(),
|
index: pb.Index(),
|
||||||
chunks: pb.Chunks(),
|
chunks: pb.Chunks(),
|
||||||
|
tombstones: pb.tombstones.Copy(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,10 +256,8 @@ Outer:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX(gouthamve): Adjust mint and maxt to match the time-range in the chunks?
|
|
||||||
for _, chk := range chunks {
|
for _, chk := range chunks {
|
||||||
if (mint <= chk.MinTime && maxt >= chk.MinTime) ||
|
if intervalOverlap(mint, maxt, chk.MinTime, chk.MaxTime) {
|
||||||
(mint > chk.MinTime && mint <= chk.MaxTime) {
|
|
||||||
vPostings = append(vPostings, p.At())
|
vPostings = append(vPostings, p.At())
|
||||||
continue Outer
|
continue Outer
|
||||||
}
|
}
|
||||||
|
|
|
@ -307,8 +307,7 @@ func (c *compactor) populate(blocks []Block, indexw IndexWriter, chunkw ChunkWri
|
||||||
if len(ranges) > 0 {
|
if len(ranges) > 0 {
|
||||||
// Re-encode the chunk to not have deleted values.
|
// Re-encode the chunk to not have deleted values.
|
||||||
for _, chk := range chks {
|
for _, chk := range chks {
|
||||||
// Checks Overlap: http://stackoverflow.com/questions/3269434/
|
if intervalOverlap(ranges[0].mint, ranges[len(ranges)-1].maxt, chk.MinTime, chk.MaxTime) {
|
||||||
if ranges[0].mint <= chk.MaxTime && chk.MinTime <= ranges[len(ranges)-1].maxt {
|
|
||||||
newChunk := chunks.NewXORChunk()
|
newChunk := chunks.NewXORChunk()
|
||||||
app, err := newChunk.Appender()
|
app, err := newChunk.Appender()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
32
db.go
32
db.go
|
@ -669,6 +669,32 @@ func (a *dbAppender) Rollback() error {
|
||||||
return g.Wait()
|
return g.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete implements deletion of metrics.
|
||||||
|
func (db *DB) Delete(mint, maxt int64, ms ...labels.Matcher) error {
|
||||||
|
s.mtx.RLock()
|
||||||
|
|
||||||
|
s.headmtx.RLock()
|
||||||
|
blocks := s.blocksForInterval(mint, maxt)
|
||||||
|
s.headmtx.RUnlock()
|
||||||
|
|
||||||
|
// TODO(gouthamve): Wait for pending compactions and stop compactions until
|
||||||
|
// delete finishes.
|
||||||
|
var g errgroup.Group
|
||||||
|
|
||||||
|
for _, b := range blocks {
|
||||||
|
f := func() error {
|
||||||
|
return b.Delete(mint, maxt, ms...)
|
||||||
|
}
|
||||||
|
g.Go(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.Wait(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return db.reloadBlocks()
|
||||||
|
}
|
||||||
|
|
||||||
// appendable returns a copy of a slice of HeadBlocks that can still be appended to.
|
// appendable returns a copy of a slice of HeadBlocks that can still be appended to.
|
||||||
func (db *DB) appendable() []headBlock {
|
func (db *DB) appendable() []headBlock {
|
||||||
var i int
|
var i int
|
||||||
|
@ -681,10 +707,8 @@ func (db *DB) appendable() []headBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
func intervalOverlap(amin, amax, bmin, bmax int64) bool {
|
func intervalOverlap(amin, amax, bmin, bmax int64) bool {
|
||||||
if bmin >= amin && bmin <= amax {
|
// Checks Overlap: http://stackoverflow.com/questions/3269434/
|
||||||
return true
|
if amin <= bmax && bmin <= amax {
|
||||||
}
|
|
||||||
if amin >= bmin && amin <= bmax {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in New Issue