code review sugestions applied

pull/10541/head
Grzegorz Pomykala 2019-02-06 09:10:51 +01:00
parent be97f36e66
commit fb3c837de9
1 changed files with 6 additions and 9 deletions

View File

@ -65,11 +65,11 @@ func (f *SeriesFile) Open() error {
p := NewSeriesPartition(i, f.SeriesPartitionPath(i)) p := NewSeriesPartition(i, f.SeriesPartitionPath(i))
p.Logger = f.Logger.With(zap.Int("partition", p.ID())) p.Logger = f.Logger.With(zap.Int("partition", p.ID()))
if err := p.Open(); err != nil { if err := p.Open(); err != nil {
f.Logger.Error("Unable to open time series data", f.Logger.Error("Unable to open series file",
zap.String("path", f.path), zap.String("path", f.path),
zap.Int("partition", p.ID()), zap.Int("partition", p.ID()),
zap.Error(err)) zap.Error(err))
f.doClose(false) f.close(false)
return err return err
} }
f.partitions = append(f.partitions, p) f.partitions = append(f.partitions, p)
@ -78,12 +78,7 @@ func (f *SeriesFile) Open() error {
return nil return nil
} }
func (f *SeriesFile) doClose(withLock bool) (err error) { func (f *SeriesFile) close() (err error) {
if withLock {
// Wait for all references to be released and prevent new ones from being acquired.
f.refs.Lock()
defer f.refs.Unlock()
}
for _, p := range f.partitions { for _, p := range f.partitions {
if e := p.Close(); e != nil && err == nil { if e := p.Close(); e != nil && err == nil {
err = e err = e
@ -95,7 +90,9 @@ func (f *SeriesFile) doClose(withLock bool) (err error) {
// Close unmaps the data file. // Close unmaps the data file.
func (f *SeriesFile) Close() (err error) { func (f *SeriesFile) Close() (err error) {
return f.doClose(true) f.refs.Lock()
defer f.refs.Unlock()
return f.close()
} }
// Path returns the path to the file. // Path returns the path to the file.