Browse Source

Close Head in DBReadOnly.FlushWAL (#7022)

Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
pull/7037/head
Ganesh Vernekar 5 years ago committed by GitHub
parent
commit
e64a149984
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      tsdb/db.go
  2. 5
      tsdb/wal/wal.go

8
tsdb/db.go

@ -294,7 +294,7 @@ func OpenDBReadOnly(dir string, l log.Logger) (*DBReadOnly, error) {
// Samples that are in existing blocks will not be written to the new block.
// Note that if the read only database is running concurrently with a
// writable database then writing the WAL to the database directory can race.
func (db *DBReadOnly) FlushWAL(dir string) error {
func (db *DBReadOnly) FlushWAL(dir string) (returnErr error) {
blockReaders, err := db.Blocks()
if err != nil {
return errors.Wrap(err, "read blocks")
@ -311,6 +311,12 @@ func (db *DBReadOnly) FlushWAL(dir string) error {
if err != nil {
return err
}
defer func() {
var merr tsdb_errors.MultiError
merr.Add(returnErr)
merr.Add(errors.Wrap(head.Close(), "closing Head"))
returnErr = merr.Err()
}()
// Set the min valid time for the ingested wal samples
// to be no lower than the maxt of the last block.
if err := head.Init(maxBlockTime); err != nil {

5
tsdb/wal/wal.go

@ -730,6 +730,11 @@ func (w *WAL) Close() (err error) {
return errors.New("wal already closed")
}
if w.segment == nil {
w.closed = true
return nil
}
// Flush the last page and zero out all its remaining size.
// We must not flush an empty page as it would falsely signal
// the segment is done if we start writing to it again after opening.

Loading…
Cancel
Save