Correctly close querier on error, revendor tsdb

This commit is contained in:
Fabian Reinartz 2017-03-09 15:40:52 +01:00
parent 3abf54c660
commit b09b90a940
4 changed files with 16 additions and 9 deletions

View file

@ -345,10 +345,16 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) (
prepareTimer.Stop()
queryPrepareTime.Observe(prepareTimer.ElapsedTime().Seconds())
// XXX(fabxc): the querier returned by populateIterators might be instantiated
// we must not return without closing irrespective of the error.
// TODO: make this semantically saner.
if querier != nil {
defer querier.Close()
}
if err != nil {
return nil, err
}
defer querier.Close()
evalTimer := query.stats.GetTimer(stats.InnerEvalTime).Start()
// Instant evaluation.

7
vendor/github.com/fabxc/tsdb/db.go generated vendored
View file

@ -369,10 +369,7 @@ func (db *DB) reloadBlocks() error {
}
heads = append(heads, b.(*headBlock))
} else {
if ok && meta.ULID != b.Meta().ULID {
if err := b.Close(); err != nil {
return err
}
if !ok || meta.ULID != b.Meta().ULID {
b, err = newPersistedBlock(dirs[i])
if err != nil {
return errors.Wrapf(err, "open persisted block %s", dirs[i])
@ -385,7 +382,7 @@ func (db *DB) reloadBlocks() error {
}
for seq, b := range db.seqBlocks {
if _, ok := seqBlocks[seq]; !ok {
if nb, ok := seqBlocks[seq]; !ok || nb != b {
if err := b.Close(); err != nil {
return errors.Wrapf(err, "closing removed block %d", b.Meta().Sequence)
}

View file

@ -299,6 +299,8 @@ func (w *WAL) entry(et WALEntryType, flag byte, buf []byte) error {
sz = int64(6 + 4 + len(buf))
newsz = w.curN + sz
)
// XXX(fabxc): this currently cuts a new file whenever the WAL was newly opened.
// Probably fine in general but may yield a lot of short files in some cases.
if w.cur == nil || w.curN > w.segmentSize || newsz > w.segmentSize && sz <= w.segmentSize {
if err := w.cut(); err != nil {
return err
@ -431,6 +433,8 @@ func NewWALReader(rs ...io.ReadCloser) *WALReader {
}
// At returns the last decoded entry of labels or samples.
// The returned slices are only valid until the next call to Next(). Their elements
// have to be copied to preserve them.
func (r *WALReader) At() ([]labels.Labels, []refdSample) {
return r.labels, r.samples
}

6
vendor/vendor.json vendored
View file

@ -368,10 +368,10 @@
"revisionTime": "2016-09-30T00:14:02Z"
},
{
"checksumSHA1": "Aj4Cn1RClamxluIri/LQMnK/yB4=",
"checksumSHA1": "hnxY08GfzanNSvD8vjz/wSWnwmk=",
"path": "github.com/fabxc/tsdb",
"revision": "ca1bc920b795cfc670002e7643471b0277e79a9b",
"revisionTime": "2017-03-08T15:54:13Z"
"revision": "32c32013a6d2a8ee5fb231d3f3cb5538128650d2",
"revisionTime": "2017-03-09T14:40:13Z"
},
{
"checksumSHA1": "uVzWuLvF646YjiKomsc2CR1ua58=",