aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-05-20 13:30:07 +0200
committerTor Egge <Tor.Egge@online.no>2022-05-20 13:30:07 +0200
commite28d123621518fec965940f98f84b3fbc680fb47 (patch)
tree32534899cc6f59a2284e293246d8764d2953e654 /searchlib/src/vespa
parentc735cf68e73e7a4bb9130d24ea1509a86ae51ddf (diff)
Avoid wraparound when calculating compacted size.
Always flush active filechunk even when not compacting to it to ensure that lastSyncToken() >= sync token for any remove that affected the compaction.
Diffstat (limited to 'searchlib/src/vespa')
-rw-r--r--searchlib/src/vespa/searchlib/docstore/logdatastore.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp b/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp
index b991773c50f..51a4d392839 100644
--- a/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp
@@ -450,7 +450,10 @@ void LogDataStore::compactFile(FileId fileId)
IWriteData::UP compacter;
FileId destinationFileId = FileId::active();
if (_bucketizer) {
- if ( ! shouldCompactToActiveFile(fc->getDiskFootprint() - fc->getDiskBloat())) {
+ size_t disk_footprint = fc->getDiskFootprint();
+ size_t disk_bloat = fc->getDiskBloat();
+ size_t compacted_size = (disk_footprint <= disk_bloat) ? 0u : (disk_footprint - disk_bloat);
+ if ( ! shouldCompactToActiveFile(compacted_size)) {
MonitorGuard guard(_updateLock);
destinationFileId = allocateFileId(guard);
setNewFileChunk(guard, createWritableFile(destinationFileId, fc->getLastPersistedSerialNum(), fc->getNameId().next()));
@@ -464,9 +467,8 @@ void LogDataStore::compactFile(FileId fileId)
fc->appendTo(_executor, *this, *compacter, fc->getNumChunks(), nullptr, CpuCategory::COMPACT);
- if (destinationFileId.isActive()) {
- flushActiveAndWait(0);
- } else {
+ flushActiveAndWait(0);
+ if (!destinationFileId.isActive()) {
MonitorGuard guard(_updateLock);
auto & compactTo = dynamic_cast<WriteableFileChunk &>(*_fileChunks[destinationFileId.getId()]);
flushFileAndWait(std::move(guard), compactTo, 0);