diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-30 19:42:02 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-30 19:43:20 +0100 |
commit | 2194cb59bfdf4f18630f3173b38301429539746e (patch) | |
tree | c11f9a53bbf24390e0d2a479c33fd7edfd786674 | |
parent | e689c3bb29f9fc135bf93e2d6e7d15671e76b1e9 (diff) |
Remove version from type id interfaces.
15 files changed, 53 insertions, 89 deletions
diff --git a/document/src/tests/documenttypetestcase.cpp b/document/src/tests/documenttypetestcase.cpp index 4d5f9fd2dc0..9f4ea13cef4 100644 --- a/document/src/tests/documenttypetestcase.cpp +++ b/document/src/tests/documenttypetestcase.cpp @@ -62,11 +62,11 @@ void DocumentTypeTest::testSetGet() { CPPUNIT_ASSERT(fetch1==fetch2); CPPUNIT_ASSERT(fetch1.getName() == "stringattr"); - const Field& fetch3 = docType.getField(3, Document::getNewestSerializationVersion()); + const Field& fetch3 = docType.getField(3); CPPUNIT_ASSERT(fetch1==fetch3); - const Field& fetch4=docType.getField(0, Document::getNewestSerializationVersion()); + const Field& fetch4=docType.getField(0); CPPUNIT_ASSERT(fetch4!=fetch1); } diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp index 7040d04efdc..6ed36527734 100644 --- a/document/src/tests/documentupdatetestcase.cpp +++ b/document/src/tests/documentupdatetestcase.cpp @@ -595,8 +595,7 @@ void DocumentUpdateTest::testReadSerializedFile() // Verify assign value update. FieldUpdate serField = upd[0]; - CPPUNIT_ASSERT_EQUAL(serField.getField().getId(Document::getNewestSerializationVersion()), - type->getField("intfield").getId(Document::getNewestSerializationVersion())); + CPPUNIT_ASSERT_EQUAL(serField.getField().getId(), type->getField("intfield").getId()); const ValueUpdate* serValue = &serField[0]; CPPUNIT_ASSERT_EQUAL(serValue->getType(), ValueUpdate::Assign); @@ -608,8 +607,7 @@ void DocumentUpdateTest::testReadSerializedFile() // Verify clear field update. serField = upd[1]; - CPPUNIT_ASSERT_EQUAL(serField.getField().getId(Document::getNewestSerializationVersion()), - type->getField("floatfield").getId(Document::getNewestSerializationVersion())); + CPPUNIT_ASSERT_EQUAL(serField.getField().getId(), type->getField("floatfield").getId()); serValue = &serField[0]; CPPUNIT_ASSERT_EQUAL(serValue->getType(), ValueUpdate::Clear); @@ -617,8 +615,7 @@ void DocumentUpdateTest::testReadSerializedFile() // Verify add value update. serField = upd[2]; - CPPUNIT_ASSERT_EQUAL(serField.getField().getId(Document::getNewestSerializationVersion()), - type->getField("arrayoffloatfield").getId(Document::getNewestSerializationVersion())); + CPPUNIT_ASSERT_EQUAL(serField.getField().getId(), type->getField("arrayoffloatfield").getId()); serValue = &serField[0]; CPPUNIT_ASSERT_EQUAL(serValue->getType(), ValueUpdate::Add); diff --git a/document/src/tests/serialization/vespadocumentserializer_test.cpp b/document/src/tests/serialization/vespadocumentserializer_test.cpp index 6b7af0c0a93..9ef9f80aaee 100644 --- a/document/src/tests/serialization/vespadocumentserializer_test.cpp +++ b/document/src/tests/serialization/vespadocumentserializer_test.cpp @@ -37,9 +37,6 @@ #include <vespa/eval/tensor/tensor.h> #include <vespa/eval/tensor/default_tensor.h> #include <vespa/eval/tensor/tensor_factory.h> -#include <stdlib.h> -#include <vespa/vespalib/data/slime/cursor.h> -#include <vespa/vespalib/data/slime/slime.h> #include <vespa/vespalib/io/fileutil.h> #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/testkit/testapp.h> @@ -476,9 +473,9 @@ void checkStructSerialization(const StructFieldValue &value, >> element2_id >> element2_size; EXPECT_EQUAL(comp_type, compression_type); EXPECT_EQUAL(2u, field_count); - EXPECT_EQUAL(field1.getId(8), element1_id & 0x7fffffff); + EXPECT_EQUAL(field1.getId(), element1_id & 0x7fffffff); EXPECT_EQUAL(4u, element1_size); - EXPECT_EQUAL(field2.getId(8), element2_id & 0x7fffffff); + EXPECT_EQUAL(field2.getId(), element2_id & 0x7fffffff); EXPECT_EQUAL(60u, element2_size); } diff --git a/document/src/vespa/document/base/field.cpp b/document/src/vespa/document/base/field.cpp index 4dcdf56bef0..d62623b64b9 100644 --- a/document/src/vespa/document/base/field.cpp +++ b/document/src/vespa/document/base/field.cpp @@ -50,7 +50,7 @@ Field::contains(const FieldSet& fields) const { switch (fields.getType()) { case FIELD: - return static_cast<const Field&>(fields).getId(7) == getId(7); + return static_cast<const Field&>(fields).getId() == getId(); case SET: { // Go through each. diff --git a/document/src/vespa/document/base/field.h b/document/src/vespa/document/base/field.h index 18c5b820243..0f852db6647 100644 --- a/document/src/vespa/document/base/field.h +++ b/document/src/vespa/document/base/field.h @@ -72,8 +72,7 @@ public: const DataType &getDataType() const { return *_dataType; } - int getId() const { return getId(7); } - int getId(int version) const { (void) version; return _fieldId; } + int getId() const { return _fieldId; } bool isHeaderField() const { return _isHeaderField; } vespalib::string toString(bool verbose=false) const; diff --git a/document/src/vespa/document/datatype/documenttype.cpp b/document/src/vespa/document/datatype/documenttype.cpp index bd5e02f030c..883c4df8f9b 100644 --- a/document/src/vespa/document/datatype/documenttype.cpp +++ b/document/src/vespa/document/datatype/documenttype.cpp @@ -97,17 +97,13 @@ void DocumentType::addField(const Field& field) { if (_fields->hasField(field.getName())) { - throw IllegalArgumentException( "A field already exists with name " + field.getName(), - VESPA_STRLOC); + throw IllegalArgumentException( "A field already exists with name " + field.getName(), VESPA_STRLOC); } else if (_fields->hasField(field)) { - throw IllegalArgumentException(make_string( - "A field already exists with id %i (or deprecated id %i).", - field.getId(7), field.getId(6)), VESPA_STRLOC); + throw IllegalArgumentException(make_string("A field already exists with id %i.", field.getId()), VESPA_STRLOC); } else if (!_ownedFields.get()) { throw vespalib::IllegalStateException(make_string( "Cannot add field %s to a DocumentType that does not " - "own its fields.", field.getName().c_str()), - VESPA_STRLOC); + "own its fields.", field.getName().c_str()), VESPA_STRLOC); } _ownedFields->addField(field); } @@ -210,10 +206,8 @@ DocumentType::operator==(const DataType& other) const if (o == 0) return false; if (*_fields != *o->_fields) return false; if (_inheritedTypes.size() != o->_inheritedTypes.size()) return false; - std::vector<const DocumentType *>::const_iterator it1( - _inheritedTypes.begin()); - std::vector<const DocumentType *>::const_iterator it2( - o->_inheritedTypes.begin()); + std::vector<const DocumentType *>::const_iterator it1(_inheritedTypes.begin()); + std::vector<const DocumentType *>::const_iterator it2(o->_inheritedTypes.begin()); while (it1 != _inheritedTypes.end()) { if (**it1 != **it2) return false; ++it1; @@ -229,17 +223,17 @@ DocumentType::getField(const stringref& name) const } const Field& -DocumentType::getField(int fieldId, int version) const +DocumentType::getField(int fieldId) const { - return _fields->getField(fieldId, version); + return _fields->getField(fieldId); } bool DocumentType::hasField(const stringref &name) const { return _fields->hasField(name); } -bool DocumentType::hasField(int fieldId, int version) const { - return _fields->hasField(fieldId, version); +bool DocumentType::hasField(int fieldId) const { + return _fields->hasField(fieldId); } Field::Set diff --git a/document/src/vespa/document/datatype/documenttype.h b/document/src/vespa/document/datatype/documenttype.h index 61f3448eec9..2b12e267eac 100644 --- a/document/src/vespa/document/datatype/documenttype.h +++ b/document/src/vespa/document/datatype/documenttype.h @@ -83,9 +83,9 @@ public: return _fields->getFieldCount(); } const Field & getField(const vespalib::stringref & name) const override; - const Field & getField(int fieldId, int version) const override; + const Field & getField(int fieldId) const override; bool hasField(const vespalib::stringref &name) const override; - bool hasField(int fieldId, int version) const override; + bool hasField(int fieldId) const override; Field::Set getFieldSet() const override; DocumentType* clone() const override; diff --git a/document/src/vespa/document/datatype/structdatatype.cpp b/document/src/vespa/document/datatype/structdatatype.cpp index 9670f7f680d..6cf9e18656b 100644 --- a/document/src/vespa/document/datatype/structdatatype.cpp +++ b/document/src/vespa/document/datatype/structdatatype.cpp @@ -89,7 +89,7 @@ StructDataType::addField(const Field& field) } std::shared_ptr<Field> newF(new Field(field)); _nameFieldMap[field.getName()] = newF; - _idFieldMap[field.getId(Document::getNewestSerializationVersion())] = newF; + _idFieldMap[field.getId()] = newF; } void @@ -110,7 +110,7 @@ StructDataType::addInheritedField(const Field& field) } std::shared_ptr<Field> newF(new Field(field)); _nameFieldMap[field.getName()] = newF; - _idFieldMap[field.getId(Document::getNewestSerializationVersion())] = newF; + _idFieldMap[field.getId()] = newF; } FieldValue::UP @@ -142,14 +142,11 @@ void throwFieldNotFound(int32_t fieldId, int version) } const Field& -StructDataType::getField(int32_t fieldId, int version) const +StructDataType::getField(int32_t fieldId) const { - if (version <= 6) { - throwFieldNotFound(fieldId, version); - } IntFieldMap::const_iterator it(_idFieldMap.find(fieldId)); if (__builtin_expect(it == _idFieldMap.end(), false)) { - throwFieldNotFound(fieldId, version); + throwFieldNotFound(fieldId, 7); } return *it->second; } @@ -158,10 +155,7 @@ bool StructDataType::hasField(const vespalib::stringref &name) const { return _nameFieldMap.find(name) != _nameFieldMap.end(); } -bool StructDataType::hasField(int32_t fieldId, int version) const { - if (version <= 6) { - throwFieldNotFound(fieldId, version); - } +bool StructDataType::hasField(int32_t fieldId) const { return _idFieldMap.find(fieldId) != _idFieldMap.end(); } @@ -179,7 +173,6 @@ namespace { // We cannot use Field::operator==(), since that only compares id. bool differs(const Field &field1, const Field &field2) { return field1.getId() != field2.getId() - || field1.getId(6) != field2.getId(6) || field1.getName() != field2.getName(); } } // namespace @@ -188,7 +181,7 @@ vespalib::string StructDataType::containsConflictingField(const Field& field) const { StringFieldMap::const_iterator it1( _nameFieldMap.find(field.getName())); - IntFieldMap::const_iterator it2(_idFieldMap.find(field.getId(Document::getNewestSerializationVersion()))); + IntFieldMap::const_iterator it2(_idFieldMap.find(field.getId())); if (it1 != _nameFieldMap.end() && differs(field, *it1->second)) { return make_string("Name in use by field with different id %s.", it1->second->toString().c_str()); diff --git a/document/src/vespa/document/datatype/structdatatype.h b/document/src/vespa/document/datatype/structdatatype.h index f6762c64d11..c66d20ed7c6 100644 --- a/document/src/vespa/document/datatype/structdatatype.h +++ b/document/src/vespa/document/datatype/structdatatype.h @@ -53,12 +53,12 @@ public: * Retrieves a field based on its ID. To determine which ID to use, we also * need the document serialization version. */ - const Field& getField(int32_t fieldId, int version) const override; + const Field& getField(int32_t fieldId) const override; bool hasField(const vespalib::stringref &name) const override; - bool hasField(int32_t fieldId, int version) const override; + bool hasField(int32_t fieldId) const override; bool hasField(const Field& f) const { - return hasField(f.getId(7), 7); + return hasField(f.getId()); } Field::Set getFieldSet() const override; diff --git a/document/src/vespa/document/datatype/structureddatatype.h b/document/src/vespa/document/datatype/structureddatatype.h index 12368c8a272..5e93c1da73d 100644 --- a/document/src/vespa/document/datatype/structureddatatype.h +++ b/document/src/vespa/document/datatype/structureddatatype.h @@ -31,10 +31,10 @@ public: virtual const Field& getField(const vespalib::stringref & name) const = 0; /** @throws FieldNotFoundException if field does not exist. */ - virtual const Field& getField(int fieldId, int version) const = 0; + virtual const Field& getField(int fieldId) const = 0; virtual bool hasField(const vespalib::stringref & name) const = 0; - virtual bool hasField(int32_t fieldId, int version) const = 0; + virtual bool hasField(int32_t fieldId) const = 0; virtual Field::Set getFieldSet() const = 0; diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp index 6c0903d44ee..bf8eb9e7eb5 100644 --- a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp @@ -5,7 +5,6 @@ #include "document.h" #include <vespa/document/repo/fixedtyperepo.h> #include <vespa/document/serialization/vespadocumentdeserializer.h> -#include <vespa/document/fieldset/fieldsets.h> #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/util/crc.h> #include <vespa/document/datatype/positiondatatype.h> @@ -19,6 +18,7 @@ LOG_SETUP(".document.structfieldvalue"); using std::vector; using vespalib::nbostream; using vespalib::nbostream_longlivedbuf; +using vespalib::make_string; namespace document { @@ -84,7 +84,7 @@ bool StructFieldValue::serializeField(int field_id, uint16_t version, return true; } try { - const Field &f = getStructType().getField(field_id, _version); + const Field &f = getStructType().getField(field_id); writer.writeFieldValue(*getFieldValue(f)); return true; } catch (FieldNotFoundException &) { @@ -93,13 +93,6 @@ bool StructFieldValue::serializeField(int field_id, uint16_t version, } } -int StructFieldValue::fieldIdFromRawId(int raw_id, uint16_t version) const { - if (version != _version) { - return getStructType().getField(raw_id, _version).getId(version); - } - return raw_id; -} - void StructFieldValue::getRawFieldIds(vector<int> &raw_ids) const { raw_ids.clear(); @@ -126,7 +119,7 @@ StructFieldValue::getRawFieldIds(vector<int> &raw_ids, for (uint32_t i = 0; i < _chunks.size(); ++i) { const SerializableArray::EntryMap & entries = _chunks[i].getEntries(); for (const SerializableArray::Entry & entry : entries) { - if (fieldSet.contains(getStructType().getField(entry.id(), _version))) { + if (fieldSet.contains(getStructType().getField(entry.id()))) { raw_ids.push_back(entry.id()); } } @@ -162,7 +155,7 @@ createFV(FieldValue & value, const DocumentTypeRepo & repo, nbostream & stream, FieldValue::UP StructFieldValue::getFieldValue(const Field& field) const { - int fieldId = field.getId(_version); + int fieldId = field.getId(); for (int i = _chunks.size() - 1; i >= 0; --i) { vespalib::ConstBufferRef buf = _chunks[i].get(fieldId); @@ -197,7 +190,7 @@ StructFieldValue::getRawField(uint32_t id) const bool StructFieldValue::getFieldValue(const Field& field, FieldValue& value) const { - int fieldId = field.getId(_version); + int fieldId = field.getId(); vespalib::ConstBufferRef buf = getRawField(fieldId); if (buf.size() > 0) { @@ -217,7 +210,7 @@ bool StructFieldValue::hasFieldValue(const Field& field) const { for (int i = _chunks.size() - 1; i >= 0; --i) { - if (_chunks[i].has(field.getId(_version))) { + if (_chunks[i].has(field.getId())) { return true; } } @@ -228,12 +221,10 @@ StructFieldValue::hasFieldValue(const Field& field) const void StructFieldValue::setFieldValue(const Field& field, FieldValue::UP value) { - int fieldId = field.getId(_version); + int fieldId = field.getId(); std::unique_ptr<ByteBuffer> serialized(value->serialize()); if (serialized->getLength() >= 0x4000000) { // Max 64 MB fields. - throw SerializeException(vespalib::make_string( - "Field value for field %i larger than 64 MB", - fieldId), VESPA_STRLOC); + throw SerializeException(make_string("Field value for field %i larger than 64 MB", fieldId), VESPA_STRLOC); } serialized->flip(); if (_chunks.empty()) { @@ -249,7 +240,7 @@ void StructFieldValue::removeFieldValue(const Field& field) { for (uint32_t i = 0; i < _chunks.size(); ++i) { - _chunks[i].clear(field.getId(_version)); + _chunks[i].clear(field.getId()); } _hasChanged = true; } @@ -321,7 +312,7 @@ StructFieldValue::printXml(XmlOutputStream& xos) const { double ns = getFieldValue(getField(PositionDataType::FIELD_Y))->getAsInt() / 1.0e6; double ew = getFieldValue(getField(PositionDataType::FIELD_X))->getAsInt() / 1.0e6; - vespalib::string buf = vespalib::make_vespa_string("%s%.6f;%s%.6f", + vespalib::string buf = make_string("%s%.6f;%s%.6f", (ns < 0 ? "S" : "N"), (ns < 0 ? (-ns) : ns), (ew < 0 ? "W" : "E"), @@ -376,13 +367,11 @@ struct StructFieldValue::FieldIterator : public StructuredIterator { const StructFieldValue& _struct; std::vector<int> _ids; std::vector<int>::iterator _cur; - int _version; - FieldIterator(const StructFieldValue& s, int version) + FieldIterator(const StructFieldValue& s) : _struct(s), _ids(), - _cur(_ids.begin()), - _version(version) + _cur(_ids.begin()) { s.getRawFieldIds(_ids); _cur = _ids.begin(); @@ -398,10 +387,10 @@ struct StructFieldValue::FieldIterator : public StructuredIterator { while (_cur != _ids.end()) { int id = *_cur++; try { - return &_struct.getStructType().getField(id, _version); + return &_struct.getStructType().getField(id); } catch (FieldNotFoundException& e) { // Should not get this exception until after we've moved the iterator. - LOG(debug, "exception for id %d version %d", id, _version); + LOG(debug, "exception for id %d", id); LOG(debug, "struct data type: %s", _struct.getType().toString(true).c_str()); } } @@ -414,11 +403,11 @@ StructFieldValue::getIterator(const Field* toFind) const { StructuredIterator::UP ret; - FieldIterator *fi = new FieldIterator(*this, _version); + FieldIterator *fi = new FieldIterator(*this); ret.reset(fi); if (toFind != NULL) { - fi->skipTo(toFind->getId(_version)); + fi->skipTo(toFind->getId()); } return ret; } diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.h b/document/src/vespa/document/fieldvalue/structfieldvalue.h index da29051b6a9..3bb32fc9690 100644 --- a/document/src/vespa/document/fieldvalue/structfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/structfieldvalue.h @@ -85,8 +85,6 @@ public: // returns false if the field could not be serialized. bool serializeField(int raw_field_id, uint16_t version, FieldValueWriter &writer) const; - int fieldIdFromRawId(int raw_field_id, uint16_t version) const; - uint16_t getVersion() const { return _version; } const Chunks & getChunks() const { return _chunks; } diff --git a/document/src/vespa/document/serialization/vespadocumentserializer.cpp b/document/src/vespa/document/serialization/vespadocumentserializer.cpp index baece7b004f..3a45fd49615 100644 --- a/document/src/vespa/document/serialization/vespadocumentserializer.cpp +++ b/document/src/vespa/document/serialization/vespadocumentserializer.cpp @@ -236,20 +236,17 @@ void serializeFields(const StructFieldValue &value, nbostream &stream, vector<pair<uint32_t, uint32_t> > &field_info, const FieldSet& fieldSet) { VespaDocumentSerializer serializer(stream); - for (StructuredFieldValue::const_iterator - it(value.begin()), e(value.end()); - it != e; ++it) - { + for (StructuredFieldValue::const_iterator it(value.begin()), e(value.end()); it != e; ++it) { if (!fieldSet.contains(it.field())) { continue; } size_t original_size = stream.size(); - int id = it.field().getId(value.getVersion()); + int id = it.field().getId(); if (!value.serializeField(id, VespaDocumentSerializer::getCurrentVersion(), serializer)) { continue; } size_t field_size = stream.size() - original_size; - field_info.push_back(make_pair(it.field().getId(VespaDocumentSerializer::getCurrentVersion()), field_size)); + field_info.push_back(make_pair(it.field().getId(), field_size)); } } @@ -444,7 +441,7 @@ void VespaDocumentSerializer::writeHEAD(const DocumentUpdate &value) void VespaDocumentSerializer::write(const FieldUpdate &value) { - _stream << static_cast<int32_t>(value.getField().getId(Document::getNewestSerializationVersion())); + _stream << static_cast<int32_t>(value.getField().getId()); _stream << static_cast<int32_t>(value.size()); for (size_t i(0), m(value.size()); i < m; i++) { write(value[i]); diff --git a/document/src/vespa/document/update/fieldupdate.cpp b/document/src/vespa/document/update/fieldupdate.cpp index 900dceec17f..e932d985056 100644 --- a/document/src/vespa/document/update/fieldupdate.cpp +++ b/document/src/vespa/document/update/fieldupdate.cpp @@ -93,7 +93,7 @@ FieldUpdate::deserialize(const DocumentTypeRepo& repo, { int fieldId; buffer.getIntNetwork(fieldId); - _field = docType.getField(fieldId, Document::getNewestSerializationVersion()); + _field = docType.getField(fieldId); const DataType& dataType = _field.getDataType(); int numUpdates = 0; diff --git a/searchlib/src/vespa/searchlib/index/doctypebuilder.cpp b/searchlib/src/vespa/searchlib/index/doctypebuilder.cpp index 18fc60b70b0..c9b90a21240 100644 --- a/searchlib/src/vespa/searchlib/index/doctypebuilder.cpp +++ b/searchlib/src/vespa/searchlib/index/doctypebuilder.cpp @@ -63,7 +63,7 @@ insertStructType(document::DocumenttypesConfig::Documenttype & cfg, DTC::Documenttype::Datatype::Sstruct::Field field; field.name = (*itr)->getName(); field.datatype = (*itr)->getDataType().getId(); - field.id = (*itr)->getId(Document::getNewestSerializationVersion()); + field.id = (*itr)->getId(); cfgStruct.field.push_back(field); } cfg.datatype.push_back(DTC::Documenttype::Datatype()); |