fix windows tests

Signed-off-by: Krasi Georgiev <kgeorgie@redhat.com>
This commit is contained in:
Krasi Georgiev 2019-01-30 11:40:40 +02:00
parent 1603222bbc
commit 315de4c782
2 changed files with 24 additions and 2 deletions

View file

@ -269,7 +269,7 @@ type Block struct {
// OpenBlock opens the block in the directory. It can be passed a chunk pool, which is used // OpenBlock opens the block in the directory. It can be passed a chunk pool, which is used
// to instantiate chunk structs. // to instantiate chunk structs.
func OpenBlock(logger log.Logger, dir string, pool chunkenc.Pool) (*Block, error) { func OpenBlock(logger log.Logger, dir string, pool chunkenc.Pool) (pb *Block, err error) {
if logger == nil { if logger == nil {
logger = log.NewNopLogger() logger = log.NewNopLogger()
} }
@ -282,15 +282,31 @@ func OpenBlock(logger log.Logger, dir string, pool chunkenc.Pool) (*Block, error
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer func() {
if err != nil {
cr.Close()
}
}()
ir, err := index.NewFileReader(filepath.Join(dir, indexFilename)) ir, err := index.NewFileReader(filepath.Join(dir, indexFilename))
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer func() {
if err != nil {
ir.Close()
}
}()
tr, tsr, err := readTombstones(dir) tr, tsr, err := readTombstones(dir)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer func() {
if err != nil {
tr.Close()
}
}()
// TODO refactor to set this at block creation time as // TODO refactor to set this at block creation time as
// that would be the logical place for a block size to be calculated. // that would be the logical place for a block size to be calculated.
@ -301,7 +317,7 @@ func OpenBlock(logger log.Logger, dir string, pool chunkenc.Pool) (*Block, error
level.Warn(logger).Log("msg", "couldn't write the meta file for the block size", "block", dir, "err", err) level.Warn(logger).Log("msg", "couldn't write the meta file for the block size", "block", dir, "err", err)
} }
pb := &Block{ pb = &Block{
dir: dir, dir: dir,
meta: *meta, meta: *meta,
chunkr: cr, chunkr: cr,

6
db.go
View file

@ -512,6 +512,12 @@ func (db *DB) reload() (err error) {
} }
} }
if len(corrupted) > 0 { if len(corrupted) > 0 {
// Close all new blocks to release the lock for windows.
for _, block := range loadable {
if _, loaded := db.getBlock(block.Meta().ULID); !loaded {
block.Close()
}
}
return fmt.Errorf("unexpected corrupted block:%v", corrupted) return fmt.Errorf("unexpected corrupted block:%v", corrupted)
} }