@ -5,10 +5,10 @@ import (
"testing"
"github.com/prometheus/tsdb/chunks"
"github.com/prometheus/tsdb/testutil"
"github.com/prometheus/tsdb/fileutil"
"github.com/prometheus/tsdb/index"
"github.com/prometheus/tsdb/labels"
"github.com/prometheus/tsdb/testutil"
)
func TestRepairBadIndexVersion ( t * testing . T ) {
@ -45,15 +45,20 @@ func TestRepairBadIndexVersion(t *testing.T) {
// panic(err)
// }
// }
const dbDir = "testdata/repair_index_version/01BZJ9WJQPWHGNC2W4J9TA62KC"
tmpDir := "testdata/repair_index_version/copy"
tmpDbDir := tmpDir + "/3MCNSQ8S31EHGJYWK5E1GPJWJZ"
// Check the current db.
// In its current state, lookups should fail with the fixed code.
const dir = "testdata/repair_index_version/01BZJ9WJQPWHGNC2W4J9TA62KC/"
meta , err := readMetaFile ( dir )
meta , err := readMetaFile ( dbDir )
testutil . NotOk ( t , err )
// Touch chunks dir in block.
os . MkdirAll ( dir + "chunks" , 0777 )
os . MkdirAll ( dbDir + "/chunks" , 0777 )
defer os . RemoveAll ( dbDir + "/chunks" )
r , err := index . NewFileReader ( d ir + " index")
r , err := index . NewFileReader ( d bD ir + " / index")
testutil . Ok ( t , err )
p , err := r . Postings ( "b" , "1" )
testutil . Ok ( t , err )
@ -66,12 +71,17 @@ func TestRepairBadIndexVersion(t *testing.T) {
testutil . Ok ( t , p . Err ( ) )
testutil . Ok ( t , r . Close ( ) )
// Create a copy DB to run test against.
if err = fileutil . CopyDirs ( dbDir , tmpDbDir ) ; err != nil {
t . Fatal ( err )
}
defer os . RemoveAll ( tmpDir )
// On DB opening all blocks in the base dir should be repaired.
db , err := Open ( "testdata/repair_index_version" , nil , nil , nil )
db , err := Open ( tmpDir , nil , nil , nil )
testutil . Ok ( t , err )
db . Close ( )
r , err = index . NewFileReader ( dir + " index")
r , err = index . NewFileReader ( tmpDbDir + "/ index")
testutil . Ok ( t , err )
p , err = r . Postings ( "b" , "1" )
testutil . Ok ( t , err )
@ -92,7 +102,7 @@ func TestRepairBadIndexVersion(t *testing.T) {
{ { "a" , "2" } , { "b" , "1" } } ,
} , res )
meta , err = readMetaFile ( d ir)
meta , err = readMetaFile ( tmpDbD ir)
testutil . Ok ( t , err )
testutil . Assert ( t , meta . Version == 1 , "unexpected meta version %d" , meta . Version )
}