aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorHÃ¥vard Pettersen <3535158+havardpe@users.noreply.github.com>2022-04-27 17:10:06 +0200
committerGitHub <noreply@github.com>2022-04-27 17:10:06 +0200
commit5205caa25887e48e272241866a50eb125a4477be (patch)
treea49355a4b1b0bd87593e6c73eed2a4c6a778c88f /searchcore
parenta11f93a5efb0eef8d5b7f91663c7c601f633a2d8 (diff)
parent60b0de3e295dd51e044f602c45d42709bf57d2ef (diff)
Merge pull request #22318 from vespa-engine/toregge/use-atomic-variables-for-raw-document-meta-data
Use atomic variables in proton::RawDocumentMetaData.
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/vespa/searchcore/proton/documentmetastore/raw_document_meta_data.h57
1 files changed, 33 insertions, 24 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/raw_document_meta_data.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/raw_document_meta_data.h
index e5f7dcc7192..b5e512fcd9e 100644
--- a/searchcore/src/vespa/searchcore/proton/documentmetastore/raw_document_meta_data.h
+++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/raw_document_meta_data.h
@@ -5,6 +5,8 @@
#include <vespa/document/base/globalid.h>
#include <vespa/document/bucket/bucketid.h>
#include <persistence/spi/types.h>
+#include <algorithm>
+#include <atomic>
#include <cassert>
namespace proton {
@@ -18,35 +20,41 @@ struct RawDocumentMetaData
using BucketId = document::BucketId;
using Timestamp = storage::spi::Timestamp;
GlobalId _gid;
- uint8_t _bucketUsedBits;
- uint8_t _docSizeLow;
- uint16_t _docSizeHigh;
- Timestamp _timestamp;
+ std::atomic<uint32_t> _bucket_used_bits_and_doc_size;
+ std::atomic<uint64_t> _timestamp;
+
+ static uint32_t capped_doc_size(uint32_t doc_size) { return std::min(0xffffffu, doc_size); }
RawDocumentMetaData() noexcept
: _gid(),
- _bucketUsedBits(BucketId::minNumBits),
- _docSizeLow(0),
- _docSizeHigh(0),
- _timestamp()
+ _bucket_used_bits_and_doc_size(BucketId::minNumBits),
+ _timestamp(0)
{ }
RawDocumentMetaData(const GlobalId &gid, const BucketId &bucketId, const Timestamp &timestamp, uint32_t docSize) noexcept
: _gid(gid),
- _bucketUsedBits(bucketId.getUsedBits()),
- _docSizeLow(docSize),
- _docSizeHigh(docSize >> 8),
+ _bucket_used_bits_and_doc_size(bucketId.getUsedBits() | (capped_doc_size(docSize) << 8)),
_timestamp(timestamp)
{
assert(bucketId.valid());
BucketId verId(gid.convertToBucketId());
- verId.setUsedBits(_bucketUsedBits);
+ verId.setUsedBits(bucketId.getUsedBits());
assert(bucketId.getRawId() == verId.getRawId() ||
bucketId.getRawId() == verId.getId());
- if (docSize >= (1u << 24)) {
- _docSizeLow = 0xff;
- _docSizeHigh = 0xffff;
- }
+ }
+
+ RawDocumentMetaData(const RawDocumentMetaData& rhs)
+ : _gid(rhs._gid),
+ _bucket_used_bits_and_doc_size(rhs._bucket_used_bits_and_doc_size.load(std::memory_order_relaxed)),
+ _timestamp(rhs._timestamp.load(std::memory_order_relaxed))
+ {
+ }
+
+ RawDocumentMetaData& operator=(const RawDocumentMetaData& rhs) {
+ _gid = rhs._gid;
+ _bucket_used_bits_and_doc_size.store(rhs._bucket_used_bits_and_doc_size.load(std::memory_order_relaxed), std::memory_order_relaxed);
+ _timestamp.store(rhs._timestamp.load(std::memory_order_relaxed), std::memory_order_relaxed);
+ return *this;
}
bool operator<(const GlobalId &rhs) const noexcept { return _gid < rhs; }
@@ -57,17 +65,17 @@ struct RawDocumentMetaData
const GlobalId &getGid() const { return _gid; }
GlobalId &getGid() { return _gid; }
void setGid(const GlobalId &rhs) { _gid = rhs; }
- uint8_t getBucketUsedBits() const { return _bucketUsedBits; }
+ uint8_t getBucketUsedBits() const { return _bucket_used_bits_and_doc_size.load(std::memory_order_relaxed) & 0xffu; }
BucketId getBucketId() const {
BucketId ret(_gid.convertToBucketId());
- ret.setUsedBits(_bucketUsedBits);
+ ret.setUsedBits(getBucketUsedBits());
return ret;
}
void setBucketUsedBits(uint8_t bucketUsedBits) {
assert(BucketId::validUsedBits(bucketUsedBits));
- _bucketUsedBits = bucketUsedBits;
+ _bucket_used_bits_and_doc_size.store((_bucket_used_bits_and_doc_size.load(std::memory_order_relaxed) & ~0xffu) | bucketUsedBits, std::memory_order_relaxed);
}
void setBucketId(const BucketId &bucketId) {
@@ -77,15 +85,16 @@ struct RawDocumentMetaData
verId.setUsedBits(bucketUsedBits);
assert(bucketId.getRawId() == verId.getRawId() ||
bucketId.getRawId() == verId.getId());
- _bucketUsedBits = bucketUsedBits;
+ setBucketUsedBits(bucketUsedBits);
}
- Timestamp getTimestamp() const { return _timestamp; }
+ Timestamp getTimestamp() const { return Timestamp(_timestamp.load(std::memory_order_relaxed)); }
+
+ void setTimestamp(const Timestamp &timestamp) { _timestamp.store(timestamp.getValue(), std::memory_order_relaxed); }
- void setTimestamp(const Timestamp &timestamp) { _timestamp = timestamp; }
+ uint32_t getDocSize() const { return _bucket_used_bits_and_doc_size.load(std::memory_order_relaxed) >> 8; }
+ void setDocSize(uint32_t docSize) { _bucket_used_bits_and_doc_size.store((_bucket_used_bits_and_doc_size.load(std::memory_order_relaxed) & 0xffu) | (capped_doc_size(docSize) << 8), std::memory_order_relaxed); }
- uint32_t getDocSize() const { return _docSizeLow + (static_cast<uint32_t>(_docSizeHigh) << 8); }
- void setDocSize(uint32_t docSize) { _docSizeLow = docSize; _docSizeHigh = docSize >> 8; }
};
} // namespace proton