summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHåvard Pettersen <3535158+havardpe@users.noreply.github.com>2022-05-02 15:14:39 +0200
committerGitHub <noreply@github.com>2022-05-02 15:14:39 +0200
commita7c46fdf61ea4af911b174d855afb91b5759006d (patch)
treeec14e31da5f7f624189699680e69bfb468e30f02
parent99801cc7ef2673332e967c447c760d028a48bb43 (diff)
parentf2d7d7f9c6acfb9701dd20e79925407bb1bbd50c (diff)
Merge pull request #22383 from vespa-engine/toregge/more-atomic-member-variables-in-file-chunk-classes
Use more atomic member variables in search::FileChunk and search::Wri…
-rw-r--r--searchlib/src/vespa/searchlib/docstore/filechunk.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/docstore/filechunk.h2
-rw-r--r--searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp16
-rw-r--r--searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h6
4 files changed, 15 insertions, 15 deletions
diff --git a/searchlib/src/vespa/searchlib/docstore/filechunk.cpp b/searchlib/src/vespa/searchlib/docstore/filechunk.cpp
index c6a657d78b1..d3b84ed89ae 100644
--- a/searchlib/src/vespa/searchlib/docstore/filechunk.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/filechunk.cpp
@@ -240,8 +240,8 @@ FileChunk::updateLidMap(const unique_lock &guard, ISetLid &ds, uint64_t serialNu
serialNum = chunkMeta.getLastSerial();
addNumBuckets(bucketMap.getNumBuckets());
_chunkInfo.push_back(ChunkInfo(chunkMeta.getOffset(), chunkMeta.getSize(), chunkMeta.getLastSerial()));
- assert(serialNum >= _lastPersistedSerialNum);
- _lastPersistedSerialNum = serialNum;
+ assert(serialNum >= _lastPersistedSerialNum.load(std::memory_order_relaxed));
+ _lastPersistedSerialNum.store(serialNum, std::memory_order_relaxed);
}
_numUniqueBuckets = globalBucketMap.getNumBuckets();
}
@@ -294,7 +294,7 @@ FileChunk::remove(uint32_t lid, uint32_t size)
uint64_t
FileChunk::getLastPersistedSerialNum() const
{
- return _lastPersistedSerialNum;
+ return _lastPersistedSerialNum.load(std::memory_order_relaxed);
}
vespalib::system_time
diff --git a/searchlib/src/vespa/searchlib/docstore/filechunk.h b/searchlib/src/vespa/searchlib/docstore/filechunk.h
index c83974047e8..2a2cbb45c53 100644
--- a/searchlib/src/vespa/searchlib/docstore/filechunk.h
+++ b/searchlib/src/vespa/searchlib/docstore/filechunk.h
@@ -248,7 +248,7 @@ protected:
vespalib::string _dataFileName;
vespalib::string _idxFileName;
ChunkInfoVector _chunkInfo;
- uint64_t _lastPersistedSerialNum;
+ std::atomic<uint64_t> _lastPersistedSerialNum;
uint32_t _dataHeaderLen;
uint32_t _idxHeaderLen;
uint32_t _numLids;
diff --git a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp
index 20b7fd02dbe..c2dd760549c 100644
--- a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp
@@ -136,7 +136,7 @@ WriteableFileChunk(vespalib::Executor &executor,
if (_idxHeaderLen == 0) {
_idxHeaderLen = writeIdxHeader(fileHeaderContext, _docIdLimit, *idxFile);
}
- _idxFileSize = idxFile->GetSize();
+ _idxFileSize.store(idxFile->GetSize(), std::memory_order_relaxed);
if ( ! idxFile->Sync()) {
throw SummaryException("Failed syncing idx file", *idxFile, VESPA_STRLOC);
}
@@ -446,7 +446,7 @@ WriteableFileChunk::computeChunkMeta(ProcessedChunkQ & chunks, size_t startPos,
{
ChunkMetaV cmetaV;
cmetaV.reserve(chunks.size());
- uint64_t lastSerial(_lastPersistedSerialNum);
+ uint64_t lastSerial(_lastPersistedSerialNum.load(std::memory_order_relaxed));
std::unique_lock guard(_lock);
if (!_pendingChunks.empty()) {
@@ -585,7 +585,7 @@ WriteableFileChunk::freeze(CpuUsage::Category cpu_category)
{
std::unique_lock guard(_lock);
setDiskFootprint(getDiskFootprint(guard));
- _frozen = true;
+ _frozen.store(true, std::memory_order_release);
}
bool sync_and_close_ok = _dataFile.Sync() && _dataFile.Close();
assert(sync_and_close_ok);
@@ -862,7 +862,7 @@ WriteableFileChunk::needFlushPendingChunks(const unique_lock & guard, uint64_t s
void
WriteableFileChunk::updateCurrentDiskFootprint() {
- _currentDiskFootprint.store(_idxFileSize + _dataFile.getSize(), std::memory_order_relaxed);
+ _currentDiskFootprint.store(_idxFileSize.load(std::memory_order_relaxed) + _dataFile.getSize(), std::memory_order_relaxed);
}
/*
@@ -893,7 +893,7 @@ WriteableFileChunk::unconditionallyFlushPendingChunks(const unique_lock &flushGu
uint64_t lastSerial = 0;
{
std::unique_lock guard(_lock);
- lastSerial = _lastPersistedSerialNum;
+ lastSerial = _lastPersistedSerialNum.load(std::memory_order_relaxed);
for (;;) {
if (!needFlushPendingChunks(guard, serialNum, datFileLen))
break;
@@ -923,9 +923,9 @@ WriteableFileChunk::unconditionallyFlushPendingChunks(const unique_lock &flushGu
if ( ! idxFile->Sync()) {
throw SummaryException("Failed fsync of idx file", *idxFile, VESPA_STRLOC);
}
- _idxFileSize = idxFile->GetSize();
- if (_lastPersistedSerialNum < lastSerial) {
- _lastPersistedSerialNum = lastSerial;
+ _idxFileSize.store(idxFile->GetSize(), std::memory_order_relaxed);
+ if (_lastPersistedSerialNum.load(std::memory_order_relaxed) < lastSerial) {
+ _lastPersistedSerialNum.store(lastSerial, std::memory_order_relaxed);
}
return timeStamp;
}
diff --git a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h
index 5e1479ed13c..0cefe179304 100644
--- a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h
+++ b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h
@@ -77,7 +77,7 @@ private:
typedef std::vector<ProcessedChunkUP> ProcessedChunkQ;
- bool frozen() const override { return _frozen; }
+ bool frozen() const override { return _frozen.load(std::memory_order_acquire); }
void waitForChunkFlushedToDisk(uint32_t chunkId) const;
void waitForAllChunksFlushedToDisk() const;
void fileWriter(const uint32_t firstChunkId);
@@ -108,7 +108,7 @@ private:
Config _config;
SerialNum _serialNum;
- bool _frozen;
+ std::atomic<bool> _frozen;
// Lock order is _writeLock, _flushLock, _lock
mutable std::mutex _lock;
mutable std::condition_variable _cond;
@@ -121,7 +121,7 @@ private:
PendingChunks _pendingChunks;
uint64_t _pendingIdx;
uint64_t _pendingDat;
- uint64_t _idxFileSize;
+ std::atomic<uint64_t> _idxFileSize;
std::atomic<uint64_t> _currentDiskFootprint;
uint32_t _nextChunkId;
Chunk::UP _active;