mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-10 07:34:04 -08:00
Merge pull request #282 from codesome/goroutine-stack-overflow
Change recursion into iteration for removedPostings.Next()
This commit is contained in:
commit
cc673dc167
|
@ -445,32 +445,31 @@ func (rp *removedPostings) Next() bool {
|
|||
rp.rok = rp.remove.Next()
|
||||
rp.initialized = true
|
||||
}
|
||||
for {
|
||||
if !rp.fok {
|
||||
return false
|
||||
}
|
||||
|
||||
if !rp.fok {
|
||||
return false
|
||||
if !rp.rok {
|
||||
rp.cur = rp.full.At()
|
||||
rp.fok = rp.full.Next()
|
||||
return true
|
||||
}
|
||||
|
||||
fcur, rcur := rp.full.At(), rp.remove.At()
|
||||
if fcur < rcur {
|
||||
rp.cur = fcur
|
||||
rp.fok = rp.full.Next()
|
||||
|
||||
return true
|
||||
} else if rcur < fcur {
|
||||
// Forward the remove postings to the right position.
|
||||
rp.rok = rp.remove.Seek(fcur)
|
||||
} else {
|
||||
// Skip the current posting.
|
||||
rp.fok = rp.full.Next()
|
||||
}
|
||||
}
|
||||
|
||||
if !rp.rok {
|
||||
rp.cur = rp.full.At()
|
||||
rp.fok = rp.full.Next()
|
||||
return true
|
||||
}
|
||||
|
||||
fcur, rcur := rp.full.At(), rp.remove.At()
|
||||
if fcur < rcur {
|
||||
rp.cur = fcur
|
||||
rp.fok = rp.full.Next()
|
||||
|
||||
return true
|
||||
} else if rcur < fcur {
|
||||
// Forward the remove postings to the right position.
|
||||
rp.rok = rp.remove.Seek(fcur)
|
||||
} else {
|
||||
// Skip the current posting.
|
||||
rp.fok = rp.full.Next()
|
||||
}
|
||||
|
||||
return rp.Next()
|
||||
}
|
||||
|
||||
func (rp *removedPostings) Seek(id uint64) bool {
|
||||
|
|
|
@ -354,6 +354,28 @@ func TestRemovedPostings(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func TestRemovedNextStackoverflow(t *testing.T) {
|
||||
var full []uint64
|
||||
var remove []uint64
|
||||
|
||||
var i uint64
|
||||
for i = 0; i < 1e7; i++ {
|
||||
full = append(full, i)
|
||||
remove = append(remove, i)
|
||||
}
|
||||
|
||||
flp := newListPostings(full)
|
||||
rlp := newListPostings(remove)
|
||||
rp := newRemovedPostings(flp, rlp)
|
||||
gotElem := false
|
||||
for rp.Next() {
|
||||
gotElem = true
|
||||
}
|
||||
|
||||
testutil.Ok(t, rp.Err())
|
||||
testutil.Assert(t, !gotElem, "")
|
||||
}
|
||||
|
||||
func TestRemovedPostingsSeek(t *testing.T) {
|
||||
var cases = []struct {
|
||||
a, b []uint64
|
||||
|
|
Loading…
Reference in a new issue