aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-04-27 16:57:43 +0200
committerTor Egge <Tor.Egge@online.no>2022-04-27 16:57:43 +0200
commitb29b53dadc733242f94b32e0a44766af7f8b2c42 (patch)
tree8c5c075d0226faafbe2dc53cdb6ead16c0abbcaf /searchcore
parent984622d4a13315c1080f999ca513f7dc1c6dd425 (diff)
Use atomic variables in proton::RawDocumentMetaData.
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/vespa/searchcore/proton/documentmetastore/raw_document_meta_data.h55
1 files changed, 32 insertions, 23 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..edf60d2a3c3 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),
+ _bucket_used_bits_and_doc_size(BucketId::minNumBits),
_timestamp()
{ }
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); }
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