summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-04-29 11:26:08 +0200
committerTor Egge <Tor.Egge@online.no>2022-04-29 11:26:08 +0200
commit218211218323f19817464e2499bc75ed1883c03a (patch)
tree422442b1c21f1bedcadbb35bb8717aeac324932e /searchlib
parent2d10e45e1aca4122739d62a48dfddb43207f4607 (diff)
Extend use of search::Chunk::_lock to close more races.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/docstore/chunk.cpp13
-rw-r--r--searchlib/src/vespa/searchlib/docstore/chunk.h2
-rw-r--r--searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp25
-rw-r--r--searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h1
4 files changed, 30 insertions, 11 deletions
diff --git a/searchlib/src/vespa/searchlib/docstore/chunk.cpp b/searchlib/src/vespa/searchlib/docstore/chunk.cpp
index d7d390d5db8..2c0e47301d9 100644
--- a/searchlib/src/vespa/searchlib/docstore/chunk.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/chunk.cpp
@@ -30,6 +30,18 @@ Chunk::read(uint32_t lid, vespalib::DataBuffer & buffer) const
return buf.size();
}
+std::pair<size_t, vespalib::alloc::Alloc>
+Chunk::read(uint32_t lid) const
+{
+ std::lock_guard guard(_lock);
+ vespalib::ConstBufferRef buf = getLid(lid);
+ auto copy = vespalib::alloc::Alloc::alloc(buf.size());
+ if (buf.size() != 0) {
+ memcpy(copy.get(), buf.data(), buf.size());
+ }
+ return std::make_pair(buf.size(), std::move(copy));
+}
+
bool
Chunk::hasRoom(size_t len) const
{
@@ -108,6 +120,7 @@ Chunk::getLid(uint32_t lid) const
size_t
Chunk::size() const {
+ std::lock_guard guard(_lock);
return getData().size();
}
diff --git a/searchlib/src/vespa/searchlib/docstore/chunk.h b/searchlib/src/vespa/searchlib/docstore/chunk.h
index bd82315a7d8..40600663106 100644
--- a/searchlib/src/vespa/searchlib/docstore/chunk.h
+++ b/searchlib/src/vespa/searchlib/docstore/chunk.h
@@ -13,6 +13,7 @@ namespace vespalib {
class nbostream;
class DataBuffer;
}
+namespace vespalib::alloc { class Alloc; }
namespace search {
@@ -90,6 +91,7 @@ public:
~Chunk();
LidMeta append(uint32_t lid, const void * buffer, size_t len);
ssize_t read(uint32_t lid, vespalib::DataBuffer & buffer) const;
+ std::pair<size_t, vespalib::alloc::Alloc> read(uint32_t lid) const;
size_t count() const { return _lids.size(); }
bool empty() const { return count() == 0; }
size_t size() const;
diff --git a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp
index 2f6d570dbb7..20b7fd02dbe 100644
--- a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp
@@ -219,6 +219,18 @@ struct LidAndBuffer {
}
+const Chunk&
+WriteableFileChunk::get_chunk(uint32_t chunk) const
+{
+ auto found = _chunkMap.find(chunk);
+ if (found != _chunkMap.end()) {
+ return *found->second;
+ } else {
+ assert(chunk == _active->getId());
+ return *_active;
+ }
+}
+
void
WriteableFileChunk::read(LidInfoWithLidV::const_iterator begin, size_t count, IBufferVisitor & visitor) const
{
@@ -232,17 +244,8 @@ WriteableFileChunk::read(LidInfoWithLidV::const_iterator begin, size_t count, IB
const LidInfoWithLid & li = *(begin + i);
uint32_t chunk = li.getChunkId();
if ((chunk >= _chunkInfo.size()) || !_chunkInfo[chunk].valid()) {
- auto found = _chunkMap.find(chunk);
- vespalib::ConstBufferRef buffer;
- if (found != _chunkMap.end()) {
- buffer = found->second->getLid(li.getLid());
- } else {
- assert(chunk == _active->getId());
- buffer = _active->getLid(li.getLid());
- }
- auto copy = vespalib::alloc::Alloc::alloc(buffer.size());
- memcpy(copy.get(), buffer.data(), buffer.size());
- buffers.emplace_back(li.getLid(), buffer.size(), std::move(copy));
+ auto copy = get_chunk(chunk).read(li.getLid());
+ buffers.emplace_back(li.getLid(), copy.first, std::move(copy.second));
} else {
chunksOnFile[chunk] = _chunkInfo[chunk];
}
diff --git a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h
index 0b9ab0ce5f4..5e1479ed13c 100644
--- a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h
+++ b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h
@@ -104,6 +104,7 @@ private:
void updateCurrentDiskFootprint();
size_t getDiskFootprint(const unique_lock & guard) const;
std::unique_ptr<FastOS_FileInterface> openIdx();
+ const Chunk& get_chunk(uint32_t chunk) const;
Config _config;
SerialNum _serialNum;