diff options
author | Håvard Pettersen <havardpe@oath.com> | 2022-03-16 15:06:27 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2022-03-16 15:06:27 +0000 |
commit | 1e7cf62d5fb8ce0a705f05e9d5e19b3dd7a36c7a (patch) | |
tree | 609782e45bec559c5b6d8cc0b18ebdab12ceaa23 /searchlib | |
parent | 4f2475fd0ed916562f113d4ccc9821e600c05619 (diff) |
use atomics for disk footprint to avoid tsan warnings
Diffstat (limited to 'searchlib')
4 files changed, 10 insertions, 10 deletions
diff --git a/searchlib/src/vespa/searchlib/docstore/filechunk.cpp b/searchlib/src/vespa/searchlib/docstore/filechunk.cpp index a56360d0b53..c6a657d78b1 100644 --- a/searchlib/src/vespa/searchlib/docstore/filechunk.cpp +++ b/searchlib/src/vespa/searchlib/docstore/filechunk.cpp @@ -93,13 +93,13 @@ FileChunk::FileChunk(FileId fileId, NameId nameId, const vespalib::string & base if (!dataFile.Sync()) { throw SummaryException("Failed syncing dat file", dataFile, VESPA_STRLOC); } - _diskFootprint += dataFile.GetSize(); + _diskFootprint.fetch_add(dataFile.GetSize(), std::memory_order_relaxed); FastOS_File idxFile(_idxFileName.c_str()); if (idxFile.OpenReadOnly()) { if (!idxFile.Sync()) { throw SummaryException("Failed syncing idx file", idxFile, VESPA_STRLOC); } - _diskFootprint += idxFile.GetSize(); + _diskFootprint.fetch_add(idxFile.GetSize(), std::memory_order_relaxed); _modificationTime = FileKit::getModificationTime(_idxFileName); } else { throw SummaryException("Failed opening idx file", idxFile, VESPA_STRLOC); @@ -488,7 +488,7 @@ FileChunk::verify(bool reportOnly) const (void) reportOnly; LOG(info, "Verifying file '%s' with fileid '%u'. erased-count='%zu' and erased-bytes='%zu'. diskFootprint='%zu'", - _name.c_str(), _fileId.getId(), _erasedCount, _erasedBytes, _diskFootprint); + _name.c_str(), _fileId.getId(), _erasedCount, _erasedBytes, _diskFootprint.load(std::memory_order_relaxed)); uint64_t lastSerial(0); size_t chunkId(0); bool errorInPrev(false); diff --git a/searchlib/src/vespa/searchlib/docstore/filechunk.h b/searchlib/src/vespa/searchlib/docstore/filechunk.h index e57fba712fd..c83974047e8 100644 --- a/searchlib/src/vespa/searchlib/docstore/filechunk.h +++ b/searchlib/src/vespa/searchlib/docstore/filechunk.h @@ -115,7 +115,7 @@ public: virtual ssize_t read(uint32_t lid, SubChunkId chunk, vespalib::DataBuffer & buffer) const; virtual void read(LidInfoWithLidV::const_iterator begin, size_t count, IBufferVisitor & visitor) const; void remove(uint32_t lid, uint32_t size); - virtual size_t getDiskFootprint() const { return _diskFootprint; } + virtual size_t getDiskFootprint() const { return _diskFootprint.load(std::memory_order_relaxed); } virtual size_t getMemoryFootprint() const; virtual size_t getMemoryMetaFootprint() const; virtual vespalib::MemoryUsage getMemoryUsage() const; @@ -210,13 +210,13 @@ private: const bool _skipCrcOnRead; size_t _erasedCount; size_t _erasedBytes; - size_t _diskFootprint; + std::atomic<size_t> _diskFootprint; size_t _sumNumBuckets; size_t _numChunksWithBuckets; size_t _numUniqueBuckets; File _file; protected: - void setDiskFootprint(size_t sz) { _diskFootprint = sz; } + void setDiskFootprint(size_t sz) { _diskFootprint.store(sz, std::memory_order_relaxed); } static size_t adjustSize(size_t sz); class ChunkInfo diff --git a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp index 78b247ffd46..2f6d570dbb7 100644 --- a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp +++ b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp @@ -607,8 +607,8 @@ WriteableFileChunk::getDiskFootprint(const unique_lock & guard) const { assert(guard.mutex() == &_lock && guard.owns_lock()); return frozen() - ? FileChunk::getDiskFootprint() - : _currentDiskFootprint + FileChunk::getDiskFootprint(); + ? FileChunk::getDiskFootprint() + : _currentDiskFootprint.load(std::memory_order_relaxed) + FileChunk::getDiskFootprint(); } size_t @@ -859,7 +859,7 @@ WriteableFileChunk::needFlushPendingChunks(const unique_lock & guard, uint64_t s void WriteableFileChunk::updateCurrentDiskFootprint() { - _currentDiskFootprint = _idxFileSize + _dataFile.getSize(); + _currentDiskFootprint.store(_idxFileSize + _dataFile.getSize(), std::memory_order_relaxed); } /* diff --git a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h index 846a9a9035e..0b9ab0ce5f4 100644 --- a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h +++ b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h @@ -121,7 +121,7 @@ private: uint64_t _pendingIdx; uint64_t _pendingDat; uint64_t _idxFileSize; - uint64_t _currentDiskFootprint; + std::atomic<uint64_t> _currentDiskFootprint; uint32_t _nextChunkId; Chunk::UP _active; size_t _alignment; |