diff --git a/tsdb/engine/tsm1/reader.go b/tsdb/engine/tsm1/reader.go index a3e5ddf3e7d..023292fec01 100644 --- a/tsdb/engine/tsm1/reader.go +++ b/tsdb/engine/tsm1/reader.go @@ -1309,7 +1309,7 @@ func (d *indirectIndex) Close() error { // blockaccessor abstracts a method of accessing blocks from a // TSM file through the accessor. type blockAccessor interface { - length() int + length() int64 read(int64, int64) []byte free() error advise(bool) error @@ -1338,8 +1338,8 @@ func NewMMapAccessor(f *os.File) (*mmapAccessor, error) { return t, nil } -func (m *mmapAccessor) length() int { - return len(m.b) +func (m *mmapAccessor) length() int64 { + return int64(len(m.b)) } func (m *mmapAccessor) read(start int64, stop int64) []byte { @@ -1360,7 +1360,7 @@ func (m *mmapAccessor) advise(need bool) error { type seekAccessor struct { f *os.File - l int + l int64 } func NewSeekAccessor(f *os.File) (*seekAccessor, error) { @@ -1372,11 +1372,11 @@ func NewSeekAccessor(f *os.File) (*seekAccessor, error) { } t.f = f // TSM files are immutable so their size won't change - t.l = int(stat.Size()) + t.l = stat.Size() return t, nil } -func (m *seekAccessor) length() int { +func (m *seekAccessor) length() int64 { return m.l } @@ -1403,8 +1403,8 @@ func (m *seekAccessor) advise(need bool) error { // Access is mmap based block accessor. It access blocks through an // MMAP or seek/read file interface, depending on the type of blockAccessor type accessor struct { - accessCount uint64 // Counter incremented everytime the accessor is accessed - freeCount uint64 // Counter to determine whether the accessor can free its resources + accessCount *uint64 // Counter incremented everytime the accessor is accessed + freeCount *uint64 // Counter to determine whether the accessor can free its resources mmapWillNeed bool // If true then mmap advise value MADV_WILLNEED will be provided the kernel for b. useSeek bool // If true, use seekAccessor instead of mmapAccessor @@ -1424,6 +1424,9 @@ func (m *accessor) init() (*indirectIndex, error) { return nil, err } + m.freeCount = new(uint64) + m.accessCount = new(uint64) + var err error if (m.useSeek) { m.b, err = NewSeekAccessor(m.f) @@ -1461,14 +1464,14 @@ func (m *accessor) init() (*indirectIndex, error) { // Allow resources to be freed immediately if requested m.incAccess() - atomic.StoreUint64(&m.freeCount, 1) + atomic.StoreUint64(m.freeCount, 1) return m.index, nil } func (m *accessor) free() error { - accessCount := atomic.LoadUint64(&m.accessCount) - freeCount := atomic.LoadUint64(&m.freeCount) + accessCount := atomic.LoadUint64(m.accessCount) + freeCount := atomic.LoadUint64(m.freeCount) // Already freed everything. if freeCount == 0 && accessCount == 0 { @@ -1479,13 +1482,13 @@ func (m *accessor) free() error { // If so, don't free anything and record the access count that we // see now for the next check. if accessCount != freeCount { - atomic.StoreUint64(&m.freeCount, accessCount) + atomic.StoreUint64(m.freeCount, accessCount) return nil } // Reset both counters to zero to indicate that we have freed everything. - atomic.StoreUint64(&m.accessCount, 0) - atomic.StoreUint64(&m.freeCount, 0) + atomic.StoreUint64(m.accessCount, 0) + atomic.StoreUint64(m.freeCount, 0) m.mu.RLock() defer m.mu.RUnlock() @@ -1494,7 +1497,7 @@ func (m *accessor) free() error { } func (m *accessor) incAccess() { - atomic.AddUint64(&m.accessCount, 1) + atomic.AddUint64(m.accessCount, 1) } func (m *accessor) rename(path string) error {