test: close temp sfile before running buildtsi compaction test (#22481)

pull/22486/head
Daniel Moran 2021-09-14 17:34:55 -04:00 committed by GitHub
parent b8a3b4ca5c
commit 140148edfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 11 deletions

View File

@ -259,7 +259,7 @@ func (buildTSICmd *buildTSI) compactSeriesFilePartition(path string) error {
src := dst + tmpExt
buildTSICmd.Logger.Debug("Renaming new segment", zap.String("prev", src), zap.String("new", dst))
if err = file.RenameFile(src, dst); err != nil && !os.IsNotExist(err) {
if err := file.RenameFile(src, dst); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("serious failure. Please rebuild index and series file: %w", err)
}
}
@ -267,7 +267,7 @@ func (buildTSICmd *buildTSI) compactSeriesFilePartition(path string) error {
// Remove index file so it will be rebuilt when reopened.
buildTSICmd.Logger.Debug("Removing index file", zap.String("path", indexPath))
if err = os.Remove(indexPath); err != nil && !os.IsNotExist(err) { // index won't exist for low cardinality
if err := os.Remove(indexPath); err != nil && !os.IsNotExist(err) { // index won't exist for low cardinality
return err
}

View File

@ -37,7 +37,7 @@ type cmdOuts struct {
expectErr bool
expectBuiltIndex bool
expectCompactSeries bool
sfile *tsdb.SeriesFile
sfilePath string
}
func Test_BuildTSI_ShardID_Without_BucketID(t *testing.T) {
@ -234,8 +234,7 @@ func Test_BuildTSI_Valid_Compact_Series(t *testing.T) {
// Create new series file
sfile := tsdb.NewSeriesFile(filepath.Join(tempDir, "data", "12345", "_series"))
err := sfile.Open()
require.NoError(t, err)
require.NoError(t, sfile.Open())
defer sfile.Close()
// Generate a bunch of keys.
@ -247,7 +246,7 @@ func Test_BuildTSI_Valid_Compact_Series(t *testing.T) {
}
// Add all to the series file.
_, err = sfile.CreateSeriesListIfNotExists(mms, tagSets)
_, err := sfile.CreateSeriesListIfNotExists(mms, tagSets)
require.NoError(t, err)
params := cmdParams{
@ -262,9 +261,10 @@ func Test_BuildTSI_Valid_Compact_Series(t *testing.T) {
outs := cmdOuts{
expectCompactSeries: true,
sfile: sfile,
sfilePath: sfile.Path(),
}
require.NoError(t, sfile.Close())
runCommand(t, params, outs)
}
@ -277,10 +277,10 @@ func initCommand(t *testing.T, params cmdParams) *cobra.Command {
// Set args
allArgs := make([]string, 0)
if params.dataPath != os.Getenv("HOME")+"/.influxdbv2/engine/data" {
if params.dataPath != filepath.Join(os.Getenv("HOME"), ".influxdbv2", "engine", "data") {
allArgs = append(allArgs, "--data-path", params.dataPath)
}
if params.walPath != os.Getenv("HOME")+"/.influxdbv2/engine/wal" {
if params.walPath != filepath.Join(os.Getenv("HOME"), ".influxdbv2", "engine", "wal") {
allArgs = append(allArgs, "--wal-path", params.walPath)
}
if params.bucketID != "" {
@ -356,9 +356,14 @@ func runCommand(t *testing.T, params cmdParams, outs cmdOuts) {
}
if outs.expectCompactSeries {
sfile := tsdb.NewSeriesFile(outs.sfilePath)
require.NoError(t, sfile.Open())
defer sfile.Close()
// Get size of all partitions before series compaction
beforeSize, err := outs.sfile.FileSize()
beforeSize, err := sfile.FileSize()
require.NoError(t, err)
require.NoError(t, sfile.Close())
// Run command with series compaction option chosen
require.NoError(t, cmd.Execute())
@ -367,7 +372,8 @@ func runCommand(t *testing.T, params cmdParams, outs cmdOuts) {
require.DirExists(t, filepath.Join(params.dataPath, "12345", "_series"))
// Get size of all partitions after series compaction
afterSize, err := outs.sfile.FileSize()
require.NoError(t, sfile.Open())
afterSize, err := sfile.FileSize()
require.NoError(t, err)
// Check that collective size of all series partitions has decreased after compaction