Close Head in DBReadOnly.FlushWAL (#7022)

Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
This commit is contained in:
Ganesh Vernekar 2020-03-23 14:49:44 +05:30 committed by GitHub
parent e813f60fd6
commit e64a149984
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -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 {

View file

@ -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.