diff options
11 files changed, 40 insertions, 26 deletions
diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp index 6993596392c..fed4de67f28 100644 --- a/document/src/tests/documenttestcase.cpp +++ b/document/src/tests/documenttestcase.cpp @@ -36,7 +36,7 @@ TEST(DocumentTest, testSizeOf) EXPECT_EQ(32u, sizeof(vespalib::GrowableByteBuffer)); EXPECT_EQ(88ul, sizeof(IdString)); EXPECT_EQ(104ul, sizeof(DocumentId)); - EXPECT_EQ(232ul, sizeof(Document)); + EXPECT_EQ(240ul, sizeof(Document)); EXPECT_EQ(96ul, sizeof(StructFieldValue)); EXPECT_EQ(16ul, sizeof(StructuredFieldValue)); EXPECT_EQ(56ul, sizeof(SerializableArray)); diff --git a/document/src/vespa/document/datatype/structdatatype.cpp b/document/src/vespa/document/datatype/structdatatype.cpp index 7c308202e3b..ed17d22da59 100644 --- a/document/src/vespa/document/datatype/structdatatype.cpp +++ b/document/src/vespa/document/datatype/structdatatype.cpp @@ -118,7 +118,7 @@ StructDataType::addInheritedField(const Field& field) FieldValue::UP StructDataType::createFieldValue() const { - return FieldValue::UP(new StructFieldValue(*this)); + return std::make_unique<StructFieldValue>(*this); } const Field& diff --git a/document/src/vespa/document/fieldvalue/document.cpp b/document/src/vespa/document/fieldvalue/document.cpp index cc60234a093..fb79b516b90 100644 --- a/document/src/vespa/document/fieldvalue/document.cpp +++ b/document/src/vespa/document/fieldvalue/document.cpp @@ -11,6 +11,7 @@ #include <vespa/document/util/serializableexceptions.h> #include <vespa/document/fieldset/fieldsets.h> #include <vespa/document/util/bytebuffer.h> +#include <vespa/vespalib/data/databuffer.h> #include <vespa/vespalib/util/xmlstream.h> #include <vespa/vespalib/stllike/hash_map.hpp> #include <cassert> @@ -71,6 +72,7 @@ Document::Document() : StructuredFieldValue(*DataType::DOCUMENT), _id(), _fields(getType().getFieldsType()), + _backingBuffer(), _lastModified(0) { _fields.setDocumentType(getType()); @@ -80,6 +82,7 @@ Document::Document(const Document& rhs) : StructuredFieldValue(rhs), _id(rhs._id), _fields(rhs._fields), + _backingBuffer(), _lastModified(rhs._lastModified) {} @@ -87,6 +90,7 @@ Document::Document(const DataType &type, DocumentId documentId) : StructuredFieldValue(verifyDocumentType(&type)), _id(std::move(documentId)), _fields(getType().getFieldsType()), + _backingBuffer(), _lastModified(0) { _fields.setDocumentType(getType()); @@ -104,11 +108,29 @@ Document::Document(const DocumentTypeRepo& repo, vespalib::nbostream & is) : StructuredFieldValue(*DataType::DOCUMENT), _id(), _fields(static_cast<const DocumentType &>(getType()).getFieldsType()), + _backingBuffer(), _lastModified(0) { deserialize(repo, is); } +Document::Document(const DocumentTypeRepo& repo, vespalib::DataBuffer && backingBuffer) + : StructuredFieldValue(*DataType::DOCUMENT), + _id(), + _fields(static_cast<const DocumentType &>(getType()).getFieldsType()), + _backingBuffer(), + _lastModified(0) +{ + if (backingBuffer.referencesExternalData()) { + vespalib::nbostream is(backingBuffer.getData(), backingBuffer.getDataLen()); + deserialize(repo, is); + } else { + vespalib::nbostream_longlivedbuf is(backingBuffer.getData(), backingBuffer.getDataLen()); + deserialize(repo, is); + _backingBuffer = std::make_unique<vespalib::DataBuffer>(std::move(backingBuffer)); + } +} + Document::Document(Document &&) noexcept = default; Document::~Document() noexcept = default; @@ -117,6 +139,7 @@ Document::operator =(Document &&rhs) noexcept { assert( ! _cache && ! rhs._cache); _id = std::move(rhs._id); _fields = std::move(rhs._fields); + _backingBuffer = std::move(rhs._backingBuffer); _lastModified = rhs._lastModified; StructuredFieldValue::operator=(std::move(rhs)); return *this; @@ -124,15 +147,16 @@ Document::operator =(Document &&rhs) noexcept { Document & Document::operator =(const Document &rhs) { + if (this == &rhs) return *this; assert( ! _cache && ! rhs._cache); _id = rhs._id; _fields = rhs._fields; _lastModified = rhs._lastModified; StructuredFieldValue::operator=(rhs); + _backingBuffer.reset(); return *this; } - const DocumentType& Document::getType() const { return static_cast<const DocumentType &>(StructuredFieldValue::getType()); diff --git a/document/src/vespa/document/fieldvalue/document.h b/document/src/vespa/document/fieldvalue/document.h index b487aa067da..cb27ca5f338 100644 --- a/document/src/vespa/document/fieldvalue/document.h +++ b/document/src/vespa/document/fieldvalue/document.h @@ -19,6 +19,7 @@ #include <vespa/document/base/documentid.h> #include <vespa/document/base/field.h> +namespace vespalib { class DataBuffer; } namespace document { class TransactionGuard; @@ -29,6 +30,7 @@ private: DocumentId _id; StructFieldValue _fields; std::unique_ptr<StructuredCache> _cache; + std::unique_ptr<vespalib::DataBuffer> _backingBuffer; // To avoid having to return another container object out of docblocks // the meta data has been added to document. This will not be serialized @@ -50,6 +52,7 @@ public: Document & operator =(Document &&) noexcept; Document(const DataType &, DocumentId id); Document(const DocumentTypeRepo& repo, vespalib::nbostream& stream); + Document(const DocumentTypeRepo& repo, vespalib::DataBuffer && buffer); ~Document() noexcept override; void setRepo(const DocumentTypeRepo & repo); diff --git a/document/src/vespa/document/fieldvalue/serializablearray.cpp b/document/src/vespa/document/fieldvalue/serializablearray.cpp index be5001c6f5b..3664554ffcc 100644 --- a/document/src/vespa/document/fieldvalue/serializablearray.cpp +++ b/document/src/vespa/document/fieldvalue/serializablearray.cpp @@ -26,8 +26,6 @@ public: } -SerializableArray::SerializableArray() = default; - SerializableArray::SerializableArray(EntryMap entries, ByteBuffer buffer, CompressionConfig::Type comp_type, uint32_t uncompressed_length) : _entries(std::move(entries)), diff --git a/document/src/vespa/document/fieldvalue/serializablearray.h b/document/src/vespa/document/fieldvalue/serializablearray.h index 80edc8a810c..30777d7e337 100644 --- a/document/src/vespa/document/fieldvalue/serializablearray.h +++ b/document/src/vespa/document/fieldvalue/serializablearray.h @@ -84,7 +84,7 @@ public: using CompressionConfig = vespalib::compression::CompressionConfig; using CompressionInfo = vespalib::compression::CompressionInfo; - SerializableArray(); + SerializableArray() = default; SerializableArray(const SerializableArray&); SerializableArray& operator=(const SerializableArray&); SerializableArray(SerializableArray &&) noexcept; diff --git a/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp b/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp index 755186edd4c..2541a253c80 100644 --- a/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp @@ -30,12 +30,6 @@ StructuredFieldValue::Iterator::Iterator(const StructuredFieldValue& owner, cons { } -StructuredFieldValue::StructuredFieldValue(const DataType &type) - : FieldValue(), - _type(&type) -{ -} - void StructuredFieldValue::setFieldValue(const Field & field, const FieldValue & value) { diff --git a/document/src/vespa/document/fieldvalue/structuredfieldvalue.h b/document/src/vespa/document/fieldvalue/structuredfieldvalue.h index 55b964147be..867aabca537 100644 --- a/document/src/vespa/document/fieldvalue/structuredfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/structuredfieldvalue.h @@ -44,7 +44,7 @@ class StructuredFieldValue : public FieldValue virtual StructuredCache * getCache() const { return nullptr; } protected: - VESPA_DLL_LOCAL StructuredFieldValue(const DataType &type); + StructuredFieldValue(const DataType &type) : FieldValue(), _type(&type) {} /** Called from Document when deserializing alters type. */ virtual void setType(const DataType& type) { _type = &type; } diff --git a/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp b/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp index 039df466872..a28a65c3a3b 100644 --- a/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp +++ b/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp @@ -279,7 +279,8 @@ void readFieldInfo(nbostream& input, SerializableArray::EntryMap & field_info) { for (size_t i = 0; i < field_count; ++i) { const uint32_t id = getInt1_4Bytes(input); const uint32_t size = getInt2_4_8Bytes(input); - field_info.emplace_back(id, size, offset); + field_info.emplace_back(id, + size, offset); offset += size; } } diff --git a/searchcore/src/tests/proton/docsummary/docsummary.cpp b/searchcore/src/tests/proton/docsummary/docsummary.cpp index 3e86e703e1e..c15fd2ccfc1 100644 --- a/searchcore/src/tests/proton/docsummary/docsummary.cpp +++ b/searchcore/src/tests/proton/docsummary/docsummary.cpp @@ -197,9 +197,9 @@ public: _dummy(), _spec(TEST_PATH("")), _configMgr(_spec, getDocTypeName()), - _documenttypesConfig(new DocumenttypesConfig()), + _documenttypesConfig(std::make_shared<DocumenttypesConfig>()), _repo(repo), - _tuneFileDocumentDB(new TuneFileDocumentDB()), + _tuneFileDocumentDB(std::make_shared<TuneFileDocumentDB>()), _hwInfo(), _ddb(), _aw(), diff --git a/searchlib/src/vespa/searchlib/docstore/documentstore.cpp b/searchlib/src/vespa/searchlib/docstore/documentstore.cpp index 4c4405fabb0..6644533550f 100644 --- a/searchlib/src/vespa/searchlib/docstore/documentstore.cpp +++ b/searchlib/src/vespa/searchlib/docstore/documentstore.cpp @@ -42,12 +42,6 @@ DocumentVisitorAdapter::visit(uint32_t lid, vespalib::ConstBufferRef buf) { } } -document::Document::UP -deserializeDocument(const vespalib::DataBuffer & uncompressed, const DocumentTypeRepo &repo) { - vespalib::nbostream is(uncompressed.getData(), uncompressed.getDataLen()); - return std::make_unique<document::Document>(repo, is); -} - } using vespalib::nbostream; @@ -183,7 +177,7 @@ DocumentStore::read(DocumentIdT lid, const DocumentTypeRepo &repo) const } Value::Result result = value.decompressed(); if ( result.second ) { - return deserializeDocument(result.first, repo); + return std::make_unique<document::Document>(repo, std::move(result.first)); } else { LOG(warning, "Summary cache for lid %u is corrupt. Invalidating and reading directly from backing store", lid); _cache->invalidate(lid); @@ -195,7 +189,7 @@ DocumentStore::read(DocumentIdT lid, const DocumentTypeRepo &repo) const if ( ! value.empty() ) { Value::Result result = value.decompressed(); assert(result.second); - return deserializeDocument(result.first, repo); + return std::make_unique<document::Document>(repo, std::move(result.first)); } return std::unique_ptr<document::Document>(); } @@ -309,7 +303,7 @@ public: _visitorProgress.updateProgress(progress); } - WrapVisitorProgress(IDocumentStoreVisitorProgress &visitProgress) + explicit WrapVisitorProgress(IDocumentStoreVisitorProgress &visitProgress) : _visitorProgress(visitProgress) { } @@ -369,7 +363,7 @@ DocumentStore::WrapVisitor<Visitor>::visit(uint32_t lid, const void *buffer, siz value.set(std::move(buf), len); } if (! value.empty()) { - std::shared_ptr<document::Document> doc(deserializeDocument(value.decompressed().first, _repo)); + auto doc = std::make_shared<document::Document>(_repo, value.decompressed().first); _visitor.visit(lid, doc); rewrite(lid, *doc); } else { |