replaces os.Rename calls w api calls to fs.RenameFile. tests now are failing

pull/14280/head
Max U 2019-07-03 13:14:43 -04:00
parent 9fcf27a25b
commit fe748128e3
9 changed files with 33 additions and 25 deletions

View File

@ -11,6 +11,7 @@ import re
import logging
import argparse
import json
import fs
################
#### Chronograf Variables
@ -697,7 +698,7 @@ def package(build_output, pkg_name, version, nightly=False, iteration=1, static=
# logging.debug("Changing package output version from {} to {} for RPM.".format(version, package_version))
# Strip nightly version from package name
new_outfile = outfile.replace("{}-{}".format(package_version, package_iteration), "nightly")
os.rename(outfile, new_outfile)
fs.RenameFile(outfile, new_outfile)
outfile = new_outfile
else:
if package_type == 'rpm':
@ -705,7 +706,7 @@ def package(build_output, pkg_name, version, nightly=False, iteration=1, static=
package_version = package_version.replace("-", "_")
logging.debug("Changing package output version from {} to {} for RPM.".format(version, package_version))
new_outfile = outfile.replace("{}-{}".format(package_version, package_iteration), package_version)
os.rename(outfile, new_outfile)
fs.RenameFile(outfile, new_outfile)
outfile = new_outfile
outfiles.append(os.path.join(os.getcwd(), outfile))
logging.debug("Produced package files: {}".format(outfiles))

View File

@ -16,6 +16,7 @@ import (
"github.com/influxdata/influxdb/logger"
"github.com/influxdata/influxdb/models"
"github.com/influxdata/influxdb/pkg/fs"
"github.com/influxdata/influxdb/storage"
"github.com/influxdata/influxdb/storage/wal"
"github.com/influxdata/influxdb/toml"
@ -327,7 +328,7 @@ func IndexShard(sfile *tsdb.SeriesFile, dataDir, walDir string, maxLogFileSize i
// Rename TSI to standard path.
log.Info("Moving tsi to permanent location")
return os.Rename(tmpPath, indexPath)
return fs.RenameFile(tmpPath, indexPath)
}
func IndexTSMFile(index *tsi1.Index, path string, batchSize int, log *zap.Logger, verboseLogging bool) error {

View File

@ -12,6 +12,7 @@ import (
"github.com/influxdata/influxdb/logger"
"github.com/influxdata/influxdb/models"
"github.com/influxdata/influxdb/pkg/fs"
"github.com/influxdata/influxdb/pkg/rhh"
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"
@ -727,7 +728,7 @@ func (c *SeriesPartitionCompactor) Compact(p *SeriesPartition) (time.Duration, e
// Reopen index with new file.
if err := p.index.Close(); err != nil {
return err
} else if err := os.Rename(indexPath, index.path); err != nil {
} else if err := fs.RenameFile(indexPath, index.path); err != nil {
return err
} else if err := p.index.Open(); err != nil {
return err

View File

@ -11,6 +11,7 @@ import (
"regexp"
"strconv"
"github.com/influxdata/influxdb/pkg/fs"
"github.com/influxdata/influxdb/pkg/mmap"
)
@ -75,7 +76,7 @@ func CreateSeriesSegment(id uint16, path string) (*SeriesSegment, error) {
}
// Swap with target path.
if err := os.Rename(f.Name(), path); err != nil {
if err := fs.RenameFile(f.Name(), path); err != nil {
return nil, err
}

View File

@ -17,6 +17,7 @@ import (
"github.com/influxdata/influxdb/logger"
"github.com/influxdata/influxdb/pkg/bytesutil"
"github.com/influxdata/influxdb/pkg/fs"
"github.com/influxdata/influxdb/tsdb"
"github.com/influxdata/influxql"
"github.com/prometheus/client_golang/prometheus"
@ -1285,7 +1286,7 @@ func (p *Partition) writeStatsFile() error {
if err := f.Close(); err != nil {
return err
} else if err := os.Rename(tmpPath, p.StatsPath()); err != nil {
} else if err := fs.RenameFile(tmpPath, p.StatsPath()); err != nil {
return err
}

View File

@ -11,6 +11,7 @@ import (
"time"
"github.com/google/go-cmp/cmp"
"github.com/influxdata/influxdb/pkg/fs"
"github.com/influxdata/influxdb/tsdb/cursors"
"github.com/influxdata/influxdb/tsdb/tsm1"
)
@ -2916,7 +2917,7 @@ func MustTSMWriter(dir string, gen int) (tsm1.TSMWriter, string) {
}
newName := filepath.Join(filepath.Dir(oldName), tsm1.DefaultFormatFileName(gen, 1)+".tsm")
if err := os.Rename(oldName, newName); err != nil {
if err := fs.RenameFile(oldName, newName); err != nil {
panic(fmt.Sprintf("create tsm file: %v", err))
}

View File

@ -598,7 +598,7 @@ func (f *FileStore) Open() error {
// the file, and continue loading the shard without it.
if err != nil {
f.logger.Error("Cannot read corrupt tsm file, renaming", zap.String("path", file.Name()), zap.Int("id", idx), zap.Error(err))
if e := os.Rename(file.Name(), file.Name()+"."+BadTSMFileExtension); e != nil {
if e := fs.RenameFile(file.Name(), file.Name()+"."+BadTSMFileExtension); e != nil {
f.logger.Error("Cannot rename corrupt tsm file", zap.String("path", file.Name()), zap.Int("id", idx), zap.Error(e))
readerC <- &res{r: df, err: fmt.Errorf("cannot rename corrupt file %s: %v", file.Name(), e)}
return
@ -797,7 +797,7 @@ func (f *FileStore) replace(oldFiles, newFiles []string, updatedFn func(r []TSMF
if strings.HasSuffix(file, tsmTmpExt) {
// The new TSM files have a tmp extension. First rename them.
newName = file[:len(file)-4]
if err := os.Rename(file, newName); err != nil {
if err := fs.RenameFile(file, newName); err != nil {
return err
}
}

View File

@ -13,6 +13,7 @@ import (
"time"
"github.com/influxdata/influxdb/logger"
"github.com/influxdata/influxdb/pkg/fs"
"github.com/influxdata/influxdb/tsdb/tsm1"
)
@ -2439,7 +2440,7 @@ func TestFileStore_Replace(t *testing.T) {
// Replace requires assumes new files have a .tmp extension
replacement := fmt.Sprintf("%s.%s", files[2], tsm1.TmpTSMFileExtension)
os.Rename(files[2], replacement)
fs.RenameFile(files[2], replacement)
fs := tsm1.NewFileStore(dir)
if err := fs.Open(); err != nil {
@ -2639,25 +2640,25 @@ func TestFileStore_Stats(t *testing.T) {
fatal(t, "creating test files", err)
}
fs := tsm1.NewFileStore(dir)
if err := fs.Open(); err != nil {
filestore := tsm1.NewFileStore(dir)
if err := filestore.Open(); err != nil {
fatal(t, "opening file store", err)
}
defer fs.Close()
defer filestore.Close()
stats := fs.Stats()
stats := filestore.Stats()
if got, exp := len(stats), 3; got != exp {
t.Fatalf("file count mismatch: got %v, exp %v", got, exp)
}
// Another call should result in the same stats being returned.
if got, exp := fs.Stats(), stats; !reflect.DeepEqual(got, exp) {
if got, exp := filestore.Stats(), stats; !reflect.DeepEqual(got, exp) {
t.Fatalf("got %v, exp %v", got, exp)
}
// Removing one of the files should invalidate the cache.
fs.Replace(files[0:1], nil)
if got, exp := len(fs.Stats()), 2; got != exp {
filestore.Replace(files[0:1], nil)
if got, exp := len(filestore.Stats()), 2; got != exp {
t.Fatalf("file count mismatch: got %v, exp %v", got, exp)
}
@ -2667,16 +2668,16 @@ func TestFileStore_Stats(t *testing.T) {
})
replacement := fmt.Sprintf("%s.%s.%s", files[2], tsm1.TmpTSMFileExtension, tsm1.TSMFileExtension) // Assumes new files have a .tmp extension
if err := os.Rename(newFile, replacement); err != nil {
if err := fs.RenameFile(newFile, replacement); err != nil {
t.Fatalf("rename: %v", err)
}
// Replace 3 w/ 1
if err := fs.Replace(files, []string{replacement}); err != nil {
if err := filestore.Replace(files, []string{replacement}); err != nil {
t.Fatalf("replace: %v", err)
}
var found bool
stats = fs.Stats()
stats = filestore.Stats()
for _, stat := range stats {
if strings.HasSuffix(stat.Path, fmt.Sprintf("%s.%s.%s", tsm1.TSMFileExtension, tsm1.TmpTSMFileExtension, tsm1.TSMFileExtension)) {
found = true
@ -2692,8 +2693,8 @@ func TestFileStore_Stats(t *testing.T) {
})
// Adding some files should invalidate the cache.
fs.Replace(nil, []string{newFile})
if got, exp := len(fs.Stats()), 2; got != exp {
filestore.Replace(nil, []string{newFile})
if got, exp := len(filestore.Stats()), 2; got != exp {
t.Fatalf("file count mismatch: got %v, exp %v", got, exp)
}
}
@ -2879,7 +2880,7 @@ func newFileDir(dir string, values ...keyValues) ([]string, error) {
return nil, err
}
newName := filepath.Join(filepath.Dir(f.Name()), tsm1.DefaultFormatFileName(id, 1)+".tsm")
if err := os.Rename(f.Name(), newName); err != nil {
if err := fs.RenameFile(f.Name(), newName); err != nil {
return nil, err
}
id++
@ -2914,7 +2915,7 @@ func newFiles(dir string, values ...keyValues) ([]string, error) {
}
newName := filepath.Join(filepath.Dir(f.Name()), tsm1.DefaultFormatFileName(id, 1)+".tsm")
if err := os.Rename(f.Name(), newName); err != nil {
if err := fs.RenameFile(f.Name(), newName); err != nil {
return nil, err
}
id++

View File

@ -12,6 +12,7 @@ import (
"time"
"github.com/google/go-cmp/cmp"
"github.com/influxdata/influxdb/pkg/fs"
"github.com/influxdata/influxdb/tsdb/tsm1"
)
@ -455,7 +456,7 @@ func TestTombstoner_Existing(t *testing.T) {
}
name := f.Name() + ".tombstone"
if err := os.Rename(f.Name(), name); err != nil {
if err := fs.RenameFile(f.Name(), name); err != nil {
panic(err)
}