aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-03-14 07:17:37 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-03-14 07:17:37 +0000
commite5a98270a180231b8055ec786565f31f9ba12445 (patch)
tree96be7dd30f4082eec22af497cd521906439dba18 /searchlib
parent957abff308a91e135c20732d50c58fc7291f9e86 (diff)
Use a hash map to avoid a presize vector.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/docstore/logdatastore.cpp22
-rw-r--r--searchlib/src/vespa/searchlib/docstore/logdatastore.h2
3 files changed, 18 insertions, 12 deletions
diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp
index ba7508f9b60..71712623a1d 100644
--- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp
+++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp
@@ -1013,9 +1013,9 @@ TEST_F("require that lid space can be increased after being compacted and then s
TEST_F("require that there is control of static memory usage", Fixture)
{
vespalib::MemoryUsage usage = f.store.getMemoryUsage();
- EXPECT_EQUAL(584u, sizeof(LogDataStore));
- EXPECT_EQUAL(2892160u, usage.allocatedBytes());
- EXPECT_EQUAL(262536u, usage.usedBytes());
+ EXPECT_EQUAL(624u, sizeof(LogDataStore));
+ EXPECT_EQUAL(2630020u, usage.allocatedBytes());
+ EXPECT_EQUAL(392u, usage.usedBytes());
}
TEST_F("require that lid space can be shrunk only after read guards are deleted", Fixture)
diff --git a/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp b/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp
index 74c21423e2b..91ced8a66c5 100644
--- a/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp
@@ -83,7 +83,6 @@ LogDataStore::LogDataStore(vespalib::Executor &executor, const vespalib::string
{
// Reserve space for 1TB summary in order to avoid locking.
_fileChunks.reserve(LidInfo::getFileIdLimit());
- _holdFileChunks.resize(LidInfo::getFileIdLimit());
preload();
updateLidMap(getLastFileChunkDocIdLimit());
@@ -1129,9 +1128,13 @@ std::unique_ptr<LogDataStore::FileChunkHolder>
LogDataStore::holdFileChunk(const MonitorGuard & guard, FileId fileId)
{
assert(guard.owns_lock());
- assert(fileId.getId() < _holdFileChunks.size());
- assert(_holdFileChunks[fileId.getId()] < 2000u);
- ++_holdFileChunks[fileId.getId()];
+ auto found = _holdFileChunks.find(fileId.getId());
+ if (found == _holdFileChunks.end()) {
+ _holdFileChunks[fileId.getId()] = 1;
+ } else {
+ assert(found->second < 2000u);
+ found->second++;
+ }
return std::make_unique<FileChunkHolder>(*this, fileId);
}
@@ -1139,15 +1142,18 @@ void
LogDataStore::unholdFileChunk(FileId fileId)
{
MonitorGuard guard(_updateLock);
- assert(fileId.getId() < _holdFileChunks.size());
- assert(_holdFileChunks[fileId.getId()] > 0u);
- --_holdFileChunks[fileId.getId()];
+ auto found = _holdFileChunks.find(fileId.getId());
+ assert(found != _holdFileChunks.end());
+ assert(found->second > 0u);
+ if (--found->second == 0u) {
+ _holdFileChunks.erase(found);
+ }
// No signalling, compactWorst() sleeps and retries
}
bool LogDataStore::canFileChunkBeDropped(const MonitorGuard & guard, FileId fileId) const {
assert(guard.owns_lock());
- return _holdFileChunks[fileId.getId()] == 0u;
+ return ! _holdFileChunks.contains(fileId.getId());
}
DataStoreStorageStats
diff --git a/searchlib/src/vespa/searchlib/docstore/logdatastore.h b/searchlib/src/vespa/searchlib/docstore/logdatastore.h
index 95605b87aaa..ef2cbf93215 100644
--- a/searchlib/src/vespa/searchlib/docstore/logdatastore.h
+++ b/searchlib/src/vespa/searchlib/docstore/logdatastore.h
@@ -254,7 +254,7 @@ private:
mutable vespalib::GenerationHandler _genHandler;
LidInfoVector _lidInfo;
FileChunkVector _fileChunks;
- std::vector<uint32_t> _holdFileChunks;
+ vespalib::hash_map<uint32_t, uint32_t> _holdFileChunks;
FileId _active;
FileId _prevActive;
mutable std::mutex _updateLock;