Skip to content

Commit

Permalink
chore: improve some sync usages in index, log
Browse files Browse the repository at this point in the history
  • Loading branch information
DStrand1 committed Oct 19, 2021
1 parent 86e99df commit 318d580
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tsdb/index/tsi1/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func NewIndex(sfile *tsdb.SeriesFile, database string, options ...IndexOption) *
func (i *Index) Bytes() int {
var b int
i.mu.RLock()
defer i.mu.RUnlock()
b += 24 // mu RWMutex is 24 bytes
b += int(unsafe.Sizeof(i.partitions))
for _, p := range i.partitions {
Expand All @@ -215,7 +216,6 @@ func (i *Index) Bytes() int {
b += int(unsafe.Sizeof(i.database)) + len(i.database)
b += int(unsafe.Sizeof(i.version))
b += int(unsafe.Sizeof(i.PartitionN))
i.mu.RUnlock()
return b
}

Expand Down Expand Up @@ -886,10 +886,10 @@ func (i *Index) DropSeriesList(seriesIDs []uint64, keys [][]byte, _ bool) error

// Add sketch tombstone.
i.mu.Lock()
defer i.mu.Unlock()
for _, key := range keys {
i.sTSketch.Add(key)
}
i.mu.Unlock()

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions tsdb/index/tsi1/index_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func NewIndexFile(sfile *tsdb.SeriesFile) *IndexFile {
func (f *IndexFile) bytes() int {
var b int
f.wg.Add(1)
defer f.wg.Done()
b += 16 // wg WaitGroup is 16 bytes
b += int(unsafe.Sizeof(f.data))
// Do not count f.data contents because it is mmap'd
Expand All @@ -101,7 +102,6 @@ func (f *IndexFile) bytes() int {
b += 24 // mu RWMutex is 24 bytes
b += int(unsafe.Sizeof(f.compacting))
b += int(unsafe.Sizeof(f.path)) + len(f.path)
f.wg.Done()
return b
}

Expand Down Expand Up @@ -160,8 +160,8 @@ func (f *IndexFile) Size() int64 { return int64(len(f.data)) }
// Compacting returns true if the file is being compacted.
func (f *IndexFile) Compacting() bool {
f.mu.RLock()
defer f.mu.RUnlock()
v := f.compacting
f.mu.RUnlock()
return v
}

Expand Down
4 changes: 2 additions & 2 deletions tsdb/index/tsi1/log_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ func (f *LogFile) Release() { f.wg.Done() }
// Stat returns size and last modification time of the file.
func (f *LogFile) Stat() (int64, time.Time) {
f.mu.RLock()
defer f.mu.RUnlock()
size, modTime := f.size, f.modTime
f.mu.RUnlock()
return size, modTime
}

Expand All @@ -257,8 +257,8 @@ func (f *LogFile) TombstoneSeriesIDSet() (*tsdb.SeriesIDSet, error) {
// Size returns the size of the file, in bytes.
func (f *LogFile) Size() int64 {
f.mu.RLock()
defer f.mu.RUnlock()
v := f.size
f.mu.RUnlock()
return v
}

Expand Down

0 comments on commit 318d580

Please sign in to comment.