diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-01-16 11:45:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-16 11:45:12 +0100 |
commit | b324c19e007a7a57ba731ed72a01d35cd6937ed7 (patch) | |
tree | fd27f6cd58d35168a17c0ed4b7e9765457b19e10 | |
parent | 99eb3b5fe51397ec2fb29e2388e97c24a28ffb69 (diff) | |
parent | 6b816198bd0d8a518465c8015e6dc9ee40399cd2 (diff) |
Merge pull request #11782 from vespa-engine/balder/bring-you-backing-buffer-along
Balder/bring your backing buffer along
24 files changed, 135 insertions, 215 deletions
diff --git a/document/src/tests/documentidtest.cpp b/document/src/tests/documentidtest.cpp index a6255cc148a..d3f6e8a8fcd 100644 --- a/document/src/tests/documentidtest.cpp +++ b/document/src/tests/documentidtest.cpp @@ -44,16 +44,8 @@ TEST(DocumentIdTest, generateJavaComplianceFile) TEST(DocumentIdTest, testOutput) { DocumentId id("id:ns:news::crawler:http://www.yahoo.com"); - - std::ostringstream ost; - ost << id; - std::string expected("id:ns:news::crawler:http://www.yahoo.com"); - EXPECT_EQ(expected, ost.str()); - - EXPECT_EQ(vespalib::string(expected), id.toString()); - - expected = "DocumentId(id = id:ns:news::crawler:http://www.yahoo.com, gid(0xa516a5abd7c7fa26944b72f7))"; - EXPECT_EQ(expected, static_cast<Printable&>(id).toString(true)); + vespalib::string expected("id:ns:news::crawler:http://www.yahoo.com"); + EXPECT_EQ(expected, id.toString()); } namespace { diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp index fa59358f6d3..b0128607ac5 100644 --- a/document/src/tests/documenttestcase.cpp +++ b/document/src/tests/documenttestcase.cpp @@ -28,7 +28,8 @@ using namespace fieldvalue; TEST(DocumentTest, testSizeOf) { - EXPECT_EQ(136ul, sizeof(Document)); + EXPECT_EQ(24ul, sizeof(DocumentId)); + EXPECT_EQ(128ul, sizeof(Document)); EXPECT_EQ(72ul, sizeof(StructFieldValue)); EXPECT_EQ(24ul, sizeof(StructuredFieldValue)); EXPECT_EQ(64ul, sizeof(SerializableArray)); diff --git a/document/src/tests/fieldvalue/referencefieldvalue_test.cpp b/document/src/tests/fieldvalue/referencefieldvalue_test.cpp index 17fb5ac74e6..b42e2d9cd7a 100644 --- a/document/src/tests/fieldvalue/referencefieldvalue_test.cpp +++ b/document/src/tests/fieldvalue/referencefieldvalue_test.cpp @@ -122,7 +122,7 @@ TEST_F("clone()ing creates new instance with same ID and type", Fixture) { ReferenceFieldValue src(f.refType, DocumentId("id:ns:foo::yoshi")); std::unique_ptr<ReferenceFieldValue> cloned(src.clone()); - ASSERT_TRUE(cloned.get() != nullptr); + ASSERT_TRUE(cloned); ASSERT_TRUE(cloned->hasValidDocumentId()); EXPECT_EQUAL(src.getDocumentId(), cloned->getDocumentId()); EXPECT_EQUAL(src.getDataType(), cloned->getDataType()); @@ -133,7 +133,7 @@ TEST_F("Can clone() value without document ID", Fixture) { ReferenceFieldValue src(f.refType); std::unique_ptr<ReferenceFieldValue> cloned(src.clone()); - ASSERT_TRUE(cloned.get() != nullptr); + ASSERT_TRUE(cloned); EXPECT_FALSE(cloned->hasValidDocumentId()); EXPECT_EQUAL(src.getDataType(), cloned->getDataType()); EXPECT_TRUE(cloned->hasChanged()); diff --git a/document/src/vespa/document/base/documentid.cpp b/document/src/vespa/document/base/documentid.cpp index c3ba8fea29d..5c240922e6d 100644 --- a/document/src/vespa/document/base/documentid.cpp +++ b/document/src/vespa/document/base/documentid.cpp @@ -9,68 +9,45 @@ using vespalib::nbostream; namespace document { DocumentId::DocumentId() - : Printable(), - _globalId(), + : _globalId(), _id(new NullIdString()) { } DocumentId::DocumentId(vespalib::stringref id) - : Printable(), - _globalId(), + : _globalId(), _id(IdString::createIdString(id.data(), id.size()).release()) { } DocumentId::DocumentId(vespalib::nbostream & is) - : Printable(), - _globalId(), + : _globalId(), _id(IdString::createIdString(is.peek(), strlen(is.peek())).release()) { is.adjustReadPos(strlen(is.peek()) + 1); } -DocumentId::DocumentId(const IdString& id) - : Printable(), - _globalId(), - _id(id.clone()) -{ -} +DocumentId::DocumentId(const DocumentId & rhs) = default; +DocumentId & DocumentId::operator = (const DocumentId & rhs) = default; +DocumentId::~DocumentId() = default; vespalib::string DocumentId::toString() const { return _id->toString(); } -void DocumentId::set(vespalib::stringref id) { +void +DocumentId::set(vespalib::stringref id) { _id.reset(IdString::createIdString(id).release()); _globalId.first = false; } -void -DocumentId::print(std::ostream& out, bool verbose, const std::string& indent) const -{ - (void) indent; - if (verbose) { - out << "DocumentId(id = "; - } - out << _id->toString().c_str(); - if (verbose) { - out << ", " << getGlobalId().toString() << ")"; - } -} - size_t DocumentId::getSerializedSize() const { return _id->toString().size() + 1; } -void DocumentId::swap(DocumentId & rhs) { - _id.swap(rhs._id); - std::swap(_globalId, rhs._globalId); -} - void DocumentId::calculateGlobalId() const { @@ -86,5 +63,9 @@ DocumentId::calculateGlobalId() const _globalId.second.set(key); } +std::ostream & +operator << (std::ostream & os, const DocumentId & id) { + return os << id.toString(); +} } // document diff --git a/document/src/vespa/document/base/documentid.h b/document/src/vespa/document/base/documentid.h index a4b01cdad82..99ab63bd296 100644 --- a/document/src/vespa/document/base/documentid.h +++ b/document/src/vespa/document/base/documentid.h @@ -21,7 +21,6 @@ #include "idstring.h" #include "globalid.h" -#include <vespa/document/util/printable.h> namespace vespalib { class nbostream; } @@ -29,14 +28,18 @@ namespace document { class DocumentType; -class DocumentId : public Printable +class DocumentId { public: typedef std::unique_ptr<DocumentId> UP; DocumentId(); DocumentId(vespalib::nbostream & os); - explicit DocumentId(const IdString& id); + DocumentId(DocumentId && rhs) = default; + DocumentId & operator = (DocumentId && rhs) = default; + DocumentId(const DocumentId & rhs); + DocumentId & operator = (const DocumentId & rhs); + ~DocumentId(); /** * Parse the given document identifier given as string, and create an * identifier object from it. @@ -57,8 +60,6 @@ public: */ vespalib::string toString() const; - void print(std::ostream& out, bool verbose, const std::string& indent) const override; - bool operator==(const DocumentId& other) const { return *_id == *other._id; } bool operator!=(const DocumentId& other) const { return ! (*_id == *other._id); } @@ -71,9 +72,7 @@ public: return _globalId.second; } - DocumentId* clone() const { return new DocumentId(*this); } - virtual size_t getSerializedSize() const; - void swap(DocumentId & rhs); + size_t getSerializedSize() const; private: mutable std::pair<bool, GlobalId> _globalId; vespalib::CloneablePtr<IdString> _id; @@ -81,5 +80,7 @@ private: void calculateGlobalId() const; }; +std::ostream & operator << (std::ostream & os, const DocumentId & id); + } // document diff --git a/document/src/vespa/document/base/idstring.cpp b/document/src/vespa/document/base/idstring.cpp index 05dc52475b7..1dcc11aa891 100644 --- a/document/src/vespa/document/base/idstring.cpp +++ b/document/src/vespa/document/base/idstring.cpp @@ -5,7 +5,6 @@ #include <vespa/document/bucket/bucketid.h> #include <vespa/vespalib/util/md5.h> #include <vespa/vespalib/util/stringfmt.h> -#include <limits> #include <cerrno> using vespalib::string; @@ -31,12 +30,6 @@ IdString::getTypeName(Type t) return _G_typeName[t]; } -string -IdString::getSchemeName() const -{ - return getTypeName(getType()); -} - const string & IdString::toString() const { @@ -74,11 +67,6 @@ union FourByte { uint32_t as32; }; -union EightByte { - char asChar[8]; - uint64_t as64; -}; - const FourByte _G_null = {{'n', 'u', 'l', 'l'}}; const TwoByte _G_id = {{'i', 'd'}}; @@ -128,7 +116,7 @@ fmemchr(const char * s, const char * e) } s++; } - return NULL; + return nullptr; } } // namespace @@ -141,7 +129,7 @@ IdString::Offsets::Offsets(uint32_t maxComponents, uint32_t namespaceOffset, str const char * s(id.data() + namespaceOffset); const char * e(id.data() + id.size()); for(s=fmemchr(s, e); - (s != NULL) && (index < maxComponents); + (s != nullptr) && (index < maxComponents); s = fmemchr(s+1, e)) { _offsets[index++] = s - id.data() + 1; @@ -159,6 +147,8 @@ IdString::IdString(uint32_t maxComponents, uint32_t namespaceOffset, stringref r { } +IdString::~IdString() = default; + void IdString::validate() const { @@ -205,7 +195,7 @@ union LocationUnion { }; uint64_t parseNumber(stringref number) { - char* errPos = NULL; + char* errPos = nullptr; errno = 0; uint64_t n = strtoul(number.data(), &errPos, 10); if (*errPos) { diff --git a/document/src/vespa/document/base/idstring.h b/document/src/vespa/document/base/idstring.h index cddf6d036b1..8e8cf0057dc 100644 --- a/document/src/vespa/document/base/idstring.h +++ b/document/src/vespa/document/base/idstring.h @@ -28,7 +28,7 @@ public: static IdString::UP createIdString(const char *id, size_t sz); static LocationType makeLocation(vespalib::stringref s); - ~IdString() {} + ~IdString(); IdString* clone() const override = 0; virtual Type getType() const = 0; @@ -50,7 +50,6 @@ public: protected: IdString(uint32_t maxComponents, uint32_t namespaceOffset, vespalib::stringref rawId); - virtual vespalib::string getSchemeName() const; size_t offset(size_t index) const { return _offsets[index]; } size_t size(size_t index) const { return _offsets[index+1] - _offsets[index] - 1; } vespalib::stringref getComponent(size_t index) const { return vespalib::stringref(_rawId.c_str() + offset(index), size(index)); } diff --git a/document/src/vespa/document/fieldvalue/document.cpp b/document/src/vespa/document/fieldvalue/document.cpp index 1bcee490378..29414c901f8 100644 --- a/document/src/vespa/document/fieldvalue/document.cpp +++ b/document/src/vespa/document/fieldvalue/document.cpp @@ -3,7 +3,6 @@ #include "document.h" #include <vespa/document/datatype/documenttype.h> #include <vespa/vespalib/util/crc.h> -#include <vespa/document/repo/fixedtyperepo.h> #include <vespa/document/repo/documenttyperepo.h> #include <vespa/document/serialization/vespadocumentdeserializer.h> #include <vespa/document/serialization/vespadocumentserializer.h> @@ -43,7 +42,10 @@ void throwTypeMismatch(vespalib::stringref type, vespalib::stringref docidType) VESPA_STRLOC); } -const DataType &verifyDocumentType(const DataType *type) { +} // namespace + +const DataType & +Document::verifyDocumentType(const DataType *type) { if (!type) { documentTypeError("null"); } else if ( ! type->getClass().inherits(DocumentType::classId)) { @@ -51,7 +53,20 @@ const DataType &verifyDocumentType(const DataType *type) { } return *type; } -} // namespace + +void +Document::verifyIdAndType(const DocumentId & id, const DataType *type) { + verifyDocumentType(type); + if (id.hasDocType() && (id.getDocType() != type->getName())) { + throwTypeMismatch(type->getName(), id.getDocType()); + } +} + +void +Document::setType(const DataType & type) { + StructuredFieldValue::setType(type); + _fields.setType(getType().getFieldsType()); +} IMPLEMENT_IDENTIFIABLE_ABSTRACT(Document, StructuredFieldValue); @@ -64,38 +79,18 @@ Document::Document() _fields.setDocumentType(getType()); } -Document::Document(const Document& other) - : StructuredFieldValue(other), - _id(other._id), - _fields(other._fields), - _lastModified(other._lastModified) -{ -} - -Document::Document(const DataType &type, const DocumentId& documentId) - : StructuredFieldValue(verifyDocumentType(&type)), - _id(documentId), - _fields(getType().getFieldsType()), - _lastModified(0) -{ - _fields.setDocumentType(getType()); - if (documentId.hasDocType() && documentId.getDocType() != type.getName()) { - throwTypeMismatch(type.getName(), documentId.getDocType()); - } -} +Document::Document(const Document& other) = default; -Document::Document(const DataType &type, DocumentId& documentId, bool iWillAllowSwap) +Document::Document(const DataType &type, DocumentId documentId) : StructuredFieldValue(verifyDocumentType(&type)), - _id(), + _id(std::move(documentId)), _fields(getType().getFieldsType()), _lastModified(0) { - (void) iWillAllowSwap; _fields.setDocumentType(getType()); - if (documentId.hasDocType() && (documentId.getDocType() != type.getName())) { - throwTypeMismatch(type.getName(), documentId.getDocType()); + if (_id.hasDocType() && (_id.getDocType() != type.getName())) { + throwTypeMismatch(type.getName(), _id.getDocType()); } - _id.swap(documentId); } Document::Document(const DocumentTypeRepo& repo, ByteBuffer& buffer, const DataType *anticipatedType) @@ -148,31 +143,14 @@ Document::Document(const DocumentTypeRepo& repo, ByteBuffer& header, ByteBuffer& deserializeBody(repo, body); } -Document::~Document() { -} - -void -Document::swap(Document & rhs) -{ - StructuredFieldValue::swap(rhs); - _fields.swap(rhs._fields); - _id.swap(rhs._id); - std::swap(_lastModified, rhs._lastModified); -} +Document::~Document() = default; const DocumentType& Document::getType() const { return static_cast<const DocumentType &>(StructuredFieldValue::getType()); } -Document& Document::operator=(const Document& doc) -{ - StructuredFieldValue::operator=(doc); - _id = doc._id; - _fields = doc._fields; - _lastModified = doc._lastModified; - return *this; -} +Document& Document::operator=(const Document& doc) = default; void Document::clear() @@ -210,7 +188,7 @@ Document::getDocTypeFromSerialized(const DocumentTypeRepo& repo, ByteBuffer& buf int position = buf.getPos(); DocumentId retVal; - const DocumentType *docType(deserializeDocHeaderAndType(repo, buf, retVal, NULL)); + const DocumentType *docType(deserializeDocHeaderAndType(repo, buf, retVal, nullptr)); buf.setPos(position); return docType; @@ -221,7 +199,7 @@ Document::assign(const FieldValue& value) { /// \todo TODO (was warning): This type checking doesnt work with the way assign is used. // if (*value.getDataType() == *_type) { - const Document& other(dynamic_cast<const Document&>(value)); + auto & other(dynamic_cast<const Document&>(value)); return operator=(other); // } // return FieldValue::assign(value); // Generates exception @@ -234,7 +212,7 @@ Document::compare(const FieldValue& other) const if (diff != 0) { return diff; } - const Document& doc(static_cast<const Document&>(other)); + auto & doc(static_cast<const Document&>(other)); vespalib::string id1 = _id.toString(); vespalib::string id2 = doc._id.toString(); if (id1 != id2) { @@ -309,9 +287,9 @@ Document::deserializeDocHeaderAndType( int16_t docTypeVersion; // version not supported anymore buffer.getShortNetwork(docTypeVersion); } - const DocumentType *docTypeNew = 0; + const DocumentType *docTypeNew = nullptr; - if (! ((docType != NULL) && (docType->getName() == docTypeName))) { + if (! ((docType != nullptr) && (docType->getName() == docTypeName))) { docTypeNew = repo.getDocumentType(docTypeName); if (!docTypeNew) { throw DocumentTypeNotFoundException(docTypeName, VESPA_STRLOC); diff --git a/document/src/vespa/document/fieldvalue/document.h b/document/src/vespa/document/fieldvalue/document.h index ebbe01958b8..3e1ec0da3e6 100644 --- a/document/src/vespa/document/fieldvalue/document.h +++ b/document/src/vespa/document/fieldvalue/document.h @@ -36,30 +36,30 @@ public: typedef std::shared_ptr<Document> SP; static constexpr uint16_t getNewestSerializationVersion() { return 8; } + static const DataType & verifyDocumentType(const DataType *type); + static void verifyIdAndType(const DocumentId & id, const DataType *type); Document(); Document(const Document&); - Document(const DataType &, const DocumentId&); - Document(const DataType &, DocumentId &, bool iWillAllowSwap); - Document(const DocumentTypeRepo& repo, ByteBuffer& buffer, const DataType *anticipatedType = 0); - Document(const DocumentTypeRepo& repo, vespalib::nbostream& stream, const DataType *anticipatedType = 0); + Document(const DataType &, DocumentId id); + Document(const DocumentTypeRepo& repo, ByteBuffer& buffer, const DataType *anticipatedType = nullptr); + Document(const DocumentTypeRepo& repo, vespalib::nbostream& stream, const DataType *anticipatedType = nullptr); /** Constructor to deserialize only document and type from a buffer. Only relevant if includeContent is false. */ Document(const DocumentTypeRepo& repo, ByteBuffer& buffer, bool includeContent, const DataType *anticipatedType); - Document(const DocumentTypeRepo& repo, ByteBuffer& header, ByteBuffer& body, const DataType *anticipatedType = 0); - ~Document(); + Document(const DocumentTypeRepo& repo, ByteBuffer& header, ByteBuffer& body, const DataType *anticipatedType = nullptr); + ~Document() override; void setRepo(const DocumentTypeRepo & repo); const DocumentTypeRepo * getRepo() const { return _fields.getRepo(); } Document& operator=(const Document&); - void swap(Document & rhs); - void accept(FieldValueVisitor &visitor) override { visitor.visit(*this); } void accept(ConstFieldValueVisitor &visitor) const override { visitor.visit(*this); } + void setType(const DataType & type) override; const DocumentType& getType() const; const DocumentId& getId() const { return _id; } DocumentId & getId() { return _id; } @@ -126,7 +126,8 @@ public: size_t getSerializedSize() const; /** Undo fieldvalue's toXml override for document. */ - std::string toXml(const std::string& indent = "") const override; + std::string toXml() const { return toXml(""); } + std::string toXml(const std::string& indent) const override; bool empty() const override { return _fields.empty(); } @@ -142,10 +143,6 @@ private: FieldValue::UP getFieldValue(const Field& field) const override { return _fields.getValue(field); } bool getFieldValue(const Field& field, FieldValue& value) const override { return _fields.getValue(field, value); } - // Iterator implementation - class FieldIterator; - friend class FieldIterator; - StructuredIterator::UP getIterator(const Field* first) const override; static void deserializeDocHeader(ByteBuffer& buffer, DocumentId& id); diff --git a/document/src/vespa/document/fieldvalue/fieldvalue.h b/document/src/vespa/document/fieldvalue/fieldvalue.h index bfdc907e871..a152f74cc09 100644 --- a/document/src/vespa/document/fieldvalue/fieldvalue.h +++ b/document/src/vespa/document/fieldvalue/fieldvalue.h @@ -47,7 +47,7 @@ public: DECLARE_IDENTIFIABLE_ABSTRACT(FieldValue); - FieldValue() {} + FieldValue() = default; /** * Visit this fieldvalue for double dispatch. diff --git a/document/src/vespa/document/fieldvalue/referencefieldvalue.cpp b/document/src/vespa/document/fieldvalue/referencefieldvalue.cpp index 281161fccbf..6c046c1787b 100644 --- a/document/src/vespa/document/fieldvalue/referencefieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/referencefieldvalue.cpp @@ -37,8 +37,7 @@ ReferenceFieldValue::ReferenceFieldValue( requireIdOfMatchingType(_documentId, _dataType->getTargetType()); } -ReferenceFieldValue::~ReferenceFieldValue() { -} +ReferenceFieldValue::~ReferenceFieldValue() = default; void ReferenceFieldValue::requireIdOfMatchingType( const DocumentId& id, const DocumentType& type) @@ -105,9 +104,7 @@ int ReferenceFieldValue::compare(const FieldValue& rhs) const { void ReferenceFieldValue::print(std::ostream& os, bool verbose, const std::string& indent) const { (void) verbose; assert(_dataType != nullptr); - os << indent << "ReferenceFieldValue(" << *_dataType << ", DocumentId("; - _documentId.print(os, false, ""); - os << "))"; + os << indent << "ReferenceFieldValue(" << *_dataType << ", DocumentId(" << _documentId << "))"; } bool ReferenceFieldValue::hasChanged() const { diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp index 80b86997122..87c8d09648c 100644 --- a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp @@ -32,16 +32,19 @@ IMPLEMENT_IDENTIFIABLE_ABSTRACT(StructFieldValue, StructuredFieldValue); StructFieldValue::StructFieldValue(const DataType &type) : StructuredFieldValue(type), - _repo(NULL), - _doc_type(NULL), + _repo(nullptr), + _doc_type(nullptr), _version(Document::getNewestSerializationVersion()), _hasChanged(true) { } -StructFieldValue::~StructFieldValue() { } +StructFieldValue::StructFieldValue(const StructFieldValue & rhs) = default; +StructFieldValue & StructFieldValue::operator = (const StructFieldValue & rhs) = default; -StructFieldValue::Chunks::~Chunks() { } +StructFieldValue::~StructFieldValue() = default; + +StructFieldValue::Chunks::~Chunks() = default; void StructFieldValue::Chunks::push_back(SerializableArray::UP item) { @@ -56,24 +59,6 @@ StructFieldValue::Chunks::clear() { _sz = 0; } -void -StructFieldValue::Chunks::swap(Chunks & rhs) { - _chunks[0].swap(rhs._chunks[0]); - _chunks[1].swap(rhs._chunks[1]); - std::swap(_sz, rhs._sz); -} - -void -StructFieldValue::swap(StructFieldValue & rhs) -{ - StructuredFieldValue::swap(rhs); - std::swap(_chunks, rhs._chunks); - std::swap(_hasChanged, rhs._hasChanged); - std::swap(_repo, rhs._repo); - std::swap(_doc_type, rhs._doc_type); - std::swap(_version, _version); -} - const StructDataType & StructFieldValue::getStructType() const { return static_cast<const StructDataType &>(getType()); diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.h b/document/src/vespa/document/fieldvalue/structfieldvalue.h index 0a288aeb69d..b5b15e9dfce 100644 --- a/document/src/vespa/document/fieldvalue/structfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/structfieldvalue.h @@ -37,7 +37,6 @@ public: size_t size() const { return _sz; } bool empty() const { return _sz == 0; } VESPA_DLL_LOCAL void clear(); - VESPA_DLL_LOCAL void swap(Chunks & rhs); private: SerializableArray::CP _chunks[2]; size_t _sz; @@ -56,8 +55,9 @@ public: using CompressionConfig = vespalib::compression::CompressionConfig; StructFieldValue(const DataType &type); - ~StructFieldValue(); - void swap(StructFieldValue & rhs); + StructFieldValue(const StructFieldValue & rhs); + StructFieldValue & operator = (const StructFieldValue & rhs); + ~StructFieldValue() override; void setRepo(const DocumentTypeRepo & repo) { _repo = & repo; } const DocumentTypeRepo * getRepo() const { return _repo; } diff --git a/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp b/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp index 860151e4bb4..39af319bc8a 100644 --- a/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp @@ -41,12 +41,8 @@ StructuredFieldValue::StructuredFieldValue(const DataType &type) { } -StructuredFieldValue::~StructuredFieldValue() {} +StructuredFieldValue::~StructuredFieldValue() = default; -void StructuredFieldValue::setType(const DataType& type) -{ - _type = &type; -} StructuredFieldValue& StructuredFieldValue::operator=(const StructuredFieldValue& other) @@ -61,7 +57,8 @@ StructuredFieldValue::operator=(const StructuredFieldValue& other) return *this; } -void StructuredFieldValue::setFieldValue(const Field & field, const FieldValue & value) +void +StructuredFieldValue::setFieldValue(const Field & field, const FieldValue & value) { if (!field.getDataType().isValueType(value) && !value.getDataType()->isA(field.getDataType())) diff --git a/document/src/vespa/document/fieldvalue/structuredfieldvalue.h b/document/src/vespa/document/fieldvalue/structuredfieldvalue.h index 619c8cf7f06..b81dc8e3936 100644 --- a/document/src/vespa/document/fieldvalue/structuredfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/structuredfieldvalue.h @@ -44,13 +44,13 @@ class StructuredFieldValue : public FieldValue VESPA_DLL_LOCAL void returnValue(const Field & field, FieldValue::UP value) const; protected: - StructuredFieldValue(const DataType &type); + VESPA_DLL_LOCAL StructuredFieldValue(const DataType &type); StructuredFieldValue(const StructuredFieldValue&); StructuredFieldValue& operator=(const StructuredFieldValue&); - void swap(StructuredFieldValue & rhs) { std::swap(_type, rhs._type); } + ~StructuredFieldValue() override; /** Called from Document when deserializing alters type. */ - virtual void setType(const DataType& type); + virtual void setType(const DataType& type) { _type = &type; } const DataType &getType() const { return *_type; } struct StructuredIterator { @@ -77,10 +77,10 @@ protected: } bool operator==(const Iterator& other) const { - if (_field == 0 && other._field == 0) + if (_field == nullptr && other._field == nullptr) // both at end() return true; - if (_field == 0 || other._field == 0) + if (_field == nullptr || other._field == nullptr) // one at end() return false; return (*_field == *other._field); @@ -105,9 +105,8 @@ protected: onIterateNested(PathRange nested, fieldvalue::IteratorHandler & handler) const override; public: DECLARE_IDENTIFIABLE_ABSTRACT(StructuredFieldValue); - ~StructuredFieldValue(); - virtual StructuredFieldValue* clone() const override = 0; + StructuredFieldValue* clone() const override = 0; const DataType *getDataType() const override { return _type; } /** Wrapper for DataType's hasField() function. */ diff --git a/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp b/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp index a0eaa9d8154..4fe7cfc6d29 100644 --- a/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp +++ b/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp @@ -72,8 +72,10 @@ void VespaDocumentDeserializer::readDocument(Document &value) { LOG(spam, "content_code is %u", content_code); const DocumentType *type = readDocType(value.getType()); if (type) { - Document newDoc(*type, value.getId(), true); - value.swap(newDoc); + Document::verifyIdAndType(value.getId(), type); + value.setType(*type); + value.clear(); + value.setLastModified(0); } value.setRepo(_repo.getDocumentTypeRepo()); diff --git a/persistence/src/vespa/persistence/conformancetest/conformancetest.cpp b/persistence/src/vespa/persistence/conformancetest/conformancetest.cpp index 3ae13d6b21c..937431fb7dd 100644 --- a/persistence/src/vespa/persistence/conformancetest/conformancetest.cpp +++ b/persistence/src/vespa/persistence/conformancetest/conformancetest.cpp @@ -405,7 +405,7 @@ TEST_F(ConformanceTest, testBasics) timeDoc2 = result.getEntries()[i]->getTimestamp(); } } else { - FAIL() << "Unknown document " << did->toString(); + FAIL() << "Unknown document " << *did; } } diff --git a/persistence/src/vespa/persistence/spi/docentry.cpp b/persistence/src/vespa/persistence/spi/docentry.cpp index 8ddbe6d9a9d..dac3761c6d2 100644 --- a/persistence/src/vespa/persistence/spi/docentry.cpp +++ b/persistence/src/vespa/persistence/spi/docentry.cpp @@ -110,7 +110,7 @@ DocEntry::prettyPrint(std::ostream& out) const out << "DocEntry(Timestamp: " << _timestamp << ", size " << getPersistedDocumentSize() << ", "; - if (_documentId.get() != 0) { + if (_documentId) { out << *_documentId; } else if (_document.get()) { out << "Doc(" << _document->getId() << ")"; @@ -135,8 +135,8 @@ DocEntry::operator==(const DocEntry& entry) const { return false; } - if (_documentId.get()) { - if (!entry._documentId.get()) { + if (_documentId) { + if (!entry._documentId) { return false; } @@ -144,13 +144,13 @@ DocEntry::operator==(const DocEntry& entry) const { return false; } } else { - if (entry._documentId.get()) { + if (entry._documentId) { return false; } } - if (_document.get()) { - if (!entry._document.get()) { + if (_document) { + if (!entry._document) { return false; } @@ -158,7 +158,7 @@ DocEntry::operator==(const DocEntry& entry) const { return false; } } else { - if (entry._document.get()) { + if (entry._document) { return false; } } diff --git a/storage/src/tests/persistence/testandsettest.cpp b/storage/src/tests/persistence/testandsettest.cpp index fe10d346ba7..1507f0e8f0d 100644 --- a/storage/src/tests/persistence/testandsettest.cpp +++ b/storage/src/tests/persistence/testandsettest.cpp @@ -294,9 +294,9 @@ std::string TestAndSetTest::expectedDocEntryString( ss << "DocEntry(" << timestamp << ", " << removeFlag << ", "; if (removeFlag == spi::REMOVE_ENTRY) { - ss << docId.toString() << ")\n"; + ss << docId << ")\n"; } else { - ss << "Doc(" << docId.toString() << "))\n"; + ss << "Doc(" << docId << "))\n"; } return ss.str(); diff --git a/storage/src/vespa/storage/persistence/processallhandler.cpp b/storage/src/vespa/storage/persistence/processallhandler.cpp index 7cb373279a6..8c951a9f50d 100644 --- a/storage/src/vespa/storage/persistence/processallhandler.cpp +++ b/storage/src/vespa/storage/persistence/processallhandler.cpp @@ -56,11 +56,11 @@ public: void process(spi::DocEntry& e) override { ost << " Timestamp: " << e.getTimestamp() << ", "; - if (e.getDocument() != 0) { + if (e.getDocument() != nullptr) { ost << "Doc(" << e.getDocument()->getId() << ")" << ", " << e.getDocument()->getId().getGlobalId().toString() << ", size: " << e.getPersistedDocumentSize(); - } else if (e.getDocumentId() != 0) { + } else if (e.getDocumentId() != nullptr) { ost << *e.getDocumentId() << ", " << e.getDocumentId()->getGlobalId().toString(); } else { diff --git a/storage/src/vespa/storage/persistence/splitbitdetector.cpp b/storage/src/vespa/storage/persistence/splitbitdetector.cpp index 1133c470bb0..0208b220b79 100644 --- a/storage/src/vespa/storage/persistence/splitbitdetector.cpp +++ b/storage/src/vespa/storage/persistence/splitbitdetector.cpp @@ -109,7 +109,7 @@ BucketVisitor::BucketVisitor(const document::BucketIdFactory& factory) _splitMask = (_splitMask << 1) | 1; } } -BucketVisitor::~BucketVisitor() { } +BucketVisitor::~BucketVisitor() = default; bool smallerThanSizeLimit(uint32_t minCount, diff --git a/storage/src/vespa/storage/storageserver/opslogger.cpp b/storage/src/vespa/storage/storageserver/opslogger.cpp index feb48b97b5b..6fc9795993e 100644 --- a/storage/src/vespa/storage/storageserver/opslogger.cpp +++ b/storage/src/vespa/storage/storageserver/opslogger.cpp @@ -14,7 +14,7 @@ OpsLogger::OpsLogger(StorageComponentRegister& compReg, : StorageLink("Operations logger"), _lock(), _fileName(), - _targetFile(0), + _targetFile(nullptr), _component(compReg, "opslogger"), _configFetcher(configUri.getContext()) { @@ -46,9 +46,9 @@ OpsLogger::configure(std::unique_ptr<vespa::config::content::core::StorOpslogger // If no change in state, ignore if (config->targetfile == _fileName) return; // If a change we need to close old handle if open - if (_targetFile != 0) { + if (_targetFile != nullptr) { fclose(_targetFile); - _targetFile = 0; + _targetFile = nullptr; } // Set up the new operations log file _fileName = config->targetfile; @@ -73,14 +73,14 @@ OpsLogger::print(std::ostream& out, bool verbose, bool OpsLogger::onPutReply(const std::shared_ptr<api::PutReply>& msg) { - if (_targetFile == 0) return false; + if (_targetFile == nullptr) return false; std::ostringstream ost; ost << _component.getClock().getTimeInSeconds().getTime() << "\tPUT\t" << msg->getDocumentId() << "\t" << msg->getResult().toString() << "\n"; { vespalib::LockGuard lock(_lock); - if (_targetFile == 0) return false; + if (_targetFile == nullptr) return false; fwrite(ost.str().c_str(), ost.str().length(), 1, _targetFile); fflush(_targetFile); } @@ -90,14 +90,14 @@ OpsLogger::onPutReply(const std::shared_ptr<api::PutReply>& msg) bool OpsLogger::onUpdateReply(const std::shared_ptr<api::UpdateReply>& msg) { - if (_targetFile == 0) return false; + if (_targetFile == nullptr) return false; std::ostringstream ost; ost << _component.getClock().getTimeInSeconds().getTime() << "\tUPDATE\t" << msg->getDocumentId() << "\t" << msg->getResult().toString() << "\n"; { vespalib::LockGuard lock(_lock); - if (_targetFile == 0) return false; + if (_targetFile == nullptr) return false; fwrite(ost.str().c_str(), ost.str().length(), 1, _targetFile); fflush(_targetFile); } @@ -107,14 +107,14 @@ OpsLogger::onUpdateReply(const std::shared_ptr<api::UpdateReply>& msg) bool OpsLogger::onRemoveReply(const std::shared_ptr<api::RemoveReply>& msg) { - if (_targetFile == 0) return false; + if (_targetFile == nullptr) return false; std::ostringstream ost; ost << _component.getClock().getTimeInSeconds().getTime() << "\tREMOVE\t" << msg->getDocumentId() << "\t" << msg->getResult().toString() << "\n"; { vespalib::LockGuard lock(_lock); - if (_targetFile == 0) return false; + if (_targetFile == nullptr) return false; fwrite(ost.str().c_str(), ost.str().length(), 1, _targetFile); fflush(_targetFile); } @@ -124,14 +124,14 @@ OpsLogger::onRemoveReply(const std::shared_ptr<api::RemoveReply>& msg) bool OpsLogger::onGetReply(const std::shared_ptr<api::GetReply>& msg) { - if (_targetFile == 0) return false; + if (_targetFile == nullptr) return false; std::ostringstream ost; ost << _component.getClock().getTimeInSeconds().getTime() << "\tGET\t" << msg->getDocumentId() << "\t" << msg->getResult().toString() << "\n"; { vespalib::LockGuard lock(_lock); - if (_targetFile == 0) return false; + if (_targetFile == nullptr) return false; fwrite(ost.str().c_str(), ost.str().length(), 1, _targetFile); fflush(_targetFile); } diff --git a/storageapi/src/vespa/storageapi/message/persistence.cpp b/storageapi/src/vespa/storageapi/message/persistence.cpp index 8bd4f648f30..54df92546a5 100644 --- a/storageapi/src/vespa/storageapi/message/persistence.cpp +++ b/storageapi/src/vespa/storageapi/message/persistence.cpp @@ -31,7 +31,7 @@ PutCommand::PutCommand(const document::Bucket &bucket, const DocumentSP& doc, Ti _timestamp(time), _updateTimestamp(0) { - if (_doc.get() == 0) { + if ( !_doc ) { throw vespalib::IllegalArgumentException("Cannot put a null document", VESPA_STRLOC); } } @@ -85,7 +85,7 @@ void PutReply::print(std::ostream& out, bool verbose, const std::string& indent) const { - out << "PutReply(" << _docId.toString() << ", " << getBucketId() << ", timestamp " << _timestamp; + out << "PutReply(" << _docId << ", " << getBucketId() << ", timestamp " << _timestamp; if (hasBeenRemapped()) { out << " (was remapped)"; @@ -104,7 +104,7 @@ UpdateCommand::UpdateCommand(const document::Bucket &bucket, const document::Doc _timestamp(time), _oldTimestamp(0) { - if (_update.get() == 0) { + if ( ! _update) { throw vespalib::IllegalArgumentException("Cannot update a null update", VESPA_STRLOC); } } @@ -160,7 +160,7 @@ void UpdateReply::print(std::ostream& out, bool verbose, const std::string& indent) const { out << "UpdateReply(" - << _docId.toString() << ", " << getBucketId() << ", timestamp " + << _docId << ", " << getBucketId() << ", timestamp " << _timestamp << ", timestamp of updated doc: " << _oldTimestamp; if (_consistentNode != (uint16_t)-1) { @@ -300,8 +300,8 @@ RevertCommand::print(std::ostream& out, bool verbose, const std::string& indent) out << "Revert(" << getBucketId(); if (verbose) { out << ","; - for (uint32_t i=0; i<_tokens.size(); ++i) { - out << "\n" << indent << " " << _tokens[i]; + for (Timestamp token : _tokens) { + out << "\n" << indent << " " << token; } } out << ")"; diff --git a/vespalib/src/vespa/vespalib/util/alloc.cpp b/vespalib/src/vespa/vespalib/util/alloc.cpp index 01d0f91dfa3..6aa96992254 100644 --- a/vespalib/src/vespa/vespalib/util/alloc.cpp +++ b/vespalib/src/vespa/vespalib/util/alloc.cpp @@ -116,6 +116,7 @@ MMapLimitAndAlignment::MMapLimitAndAlignment(size_t mmapLimit, size_t alignment) } namespace alloc { +namespace { class HeapAllocator : public MemoryAllocator { public: @@ -179,8 +180,6 @@ private: }; -namespace { - struct MMapLimitAndAlignmentHash { std::size_t operator ()(MMapLimitAndAlignment key) const { return key.hash(); } }; @@ -239,8 +238,6 @@ alloc::AlignedHeapAllocator _G_1KalignedHeapAllocator(4096); alloc::AlignedHeapAllocator _G_512BalignedHeapAllocator(512); alloc::MMapAllocator _G_mmapAllocatorDefault; -} - MemoryAllocator & HeapAllocator::getDefault() { return _G_heapAllocatorDefault; @@ -270,7 +267,8 @@ AutoAllocator::getDefault() { return *_G_availableAutoAllocators.second; } -MemoryAllocator & AutoAllocator::getAllocator(size_t mmapLimit, size_t alignment) { +MemoryAllocator & +AutoAllocator::getAllocator(size_t mmapLimit, size_t alignment) { return getAutoAllocator(_G_availableAutoAllocators.first, mmapLimit, alignment); } @@ -451,6 +449,9 @@ AutoAllocator::free(PtrAndSize alloc) const { } } +} + + Alloc Alloc::allocHeap(size_t sz) { |