summaryrefslogtreecommitdiffstats
path: root/searchcorespi
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-05-05 14:04:46 +0200
committerTor Egge <Tor.Egge@online.no>2022-05-05 14:04:46 +0200
commit37d97d9455835b8741af6d2e55c0f44895ce299a (patch)
tree12a37b95626aad5188750c84fd34029d062aac7c /searchcorespi
parenta6f4bcefc08cb924b179cc1eadd9b2f95f2ffab1 (diff)
Use atomic searchcorespi::index::IndexMaintainer::_flush_serial_num.
Diffstat (limited to 'searchcorespi')
-rw-r--r--searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp14
-rw-r--r--searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.h14
2 files changed, 17 insertions, 11 deletions
diff --git a/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp b/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp
index e5bcf5291e5..af273bc5e45 100644
--- a/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp
+++ b/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp
@@ -655,7 +655,7 @@ IndexMaintainer::doneFlush(FlushArgs *args, IDiskIndex::SP *disk_index) {
if (args->_prunedSchema != memoryIndex.getPrunedSchema()) {
return false; // Must retry operation
}
- _flush_serial_num = std::max(_flush_serial_num, args->flush_serial_num);
+ set_flush_serial_num(std::max(flush_serial_num(), args->flush_serial_num));
vespalib::system_time timeStamp = search::FileKit::getModificationTime((*disk_index)->getIndexDir());
_lastFlushTime = timeStamp > _lastFlushTime ? timeStamp : _lastFlushTime;
const uint32_t old_id = args->old_absolute_id - _last_fusion_id;
@@ -919,13 +919,13 @@ IndexMaintainer::IndexMaintainer(const IndexMaintainerConfig &config,
? getFusionDir(_next_id - 1)
: getFlushDir(_next_id - 1);
- _flush_serial_num = IndexReadUtilities::readSerialNum(latest_index_dir);
+ set_flush_serial_num(IndexReadUtilities::readSerialNum(latest_index_dir));
_lastFlushTime = search::FileKit::getModificationTime(latest_index_dir);
- set_current_serial_num(_flush_serial_num);
+ set_current_serial_num(flush_serial_num());
const string selector = IndexDiskLayout::getSelectorFileName(latest_index_dir);
_selector = FixedSourceSelector::load(selector, _next_id - 1);
} else {
- _flush_serial_num = 0;
+ set_flush_serial_num(0);
_selector = std::make_shared<FixedSourceSelector>(0, "sourceselector", 1);
}
uint32_t baseId(_selector->getBaseId());
@@ -942,7 +942,7 @@ IndexMaintainer::IndexMaintainer(const IndexMaintainerConfig &config,
_selector->setDefaultSource(_current_index_id);
auto sourceList = loadDiskIndexes(spec, std::make_unique<IndexCollection>(_selector));
_current_index = operations.createMemoryIndex(_schema, *sourceList, current_serial_num());
- LOG(debug, "Index manager created with flushed serial num %" PRIu64, _flush_serial_num);
+ LOG(debug, "Index manager created with flushed serial num %" PRIu64, flush_serial_num());
sourceList->append(_current_index_id, _current_index);
sourceList->setCurrentIndex(_current_index_id);
_source_list = std::move(sourceList);
@@ -984,11 +984,11 @@ IndexMaintainer::initFlush(SerialNum serialNum, searchcorespi::FlushStats * stat
if (args._skippedEmptyLast && args._extraIndexes.empty()) {
// No memory index to flush, it was empty
LockGuard lock(_state_lock);
- _flush_serial_num = current_serial_num();
+ set_flush_serial_num(current_serial_num());
_lastFlushTime = vespalib::system_clock::now();
LOG(debug, "No memory index to flush. Update serial number and flush time to current: "
"flushSerialNum(%" PRIu64 "), lastFlushTime(%f)",
- _flush_serial_num, vespalib::to_s(_lastFlushTime.time_since_epoch()));
+ flush_serial_num(), vespalib::to_s(_lastFlushTime.time_since_epoch()));
return FlushTask::UP();
}
SerialNum realSerialNum = args.flush_serial_num;
diff --git a/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.h b/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.h
index dfae5b4d643..b3fb14e1c2e 100644
--- a/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.h
+++ b/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.h
@@ -93,8 +93,8 @@ class IndexMaintainer : public IIndexManager,
uint32_t _current_index_id; // Protected by SL + IUL
IMemoryIndex::SP _current_index; // Protected by SL + IUL
bool _flush_empty_current_index;
- std::atomic<SerialNum> _current_serial_num;// Protected by IUL
- SerialNum _flush_serial_num; // Protected by SL
+ std::atomic<SerialNum> _current_serial_num;// Writes protected by IUL
+ std::atomic<SerialNum> _flush_serial_num; // Writes protected by SL
vespalib::system_time _lastFlushTime; // Protected by SL
// Extra frozen memory indexes. This list is empty unless new
// memory index has been added by force (due to config change or
@@ -270,6 +270,12 @@ class IndexMaintainer : public IIndexManager,
void set_current_serial_num(SerialNum new_serial_num) noexcept {
_current_serial_num.store(new_serial_num, std::memory_order_relaxed);
}
+ [[nodiscard]] SerialNum flush_serial_num() const noexcept {
+ return _flush_serial_num.load(std::memory_order_relaxed);
+ }
+ void set_flush_serial_num(SerialNum new_serial_num) noexcept {
+ _flush_serial_num.store(new_serial_num, std::memory_order_relaxed);
+ }
public:
IndexMaintainer(const IndexMaintainer &) = delete;
@@ -340,11 +346,11 @@ public:
void compactLidSpace(uint32_t lidLimit, SerialNum serialNum) override;
SerialNum getCurrentSerialNum() const override {
- return _current_serial_num.load(std::memory_order_relaxed);
+ return current_serial_num();
}
SerialNum getFlushedSerialNum() const override {
- return _flush_serial_num;
+ return flush_serial_num();
}
IIndexCollection::SP getSourceCollection() const {