From 6b458905a952c8c2443548b4b8e93f46a497d282 Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Fri, 9 Nov 2018 12:56:20 +0000 Subject: do reserialization in more cases * only re-use cached serialized chunks if we have the right amount of chunks compared to what we wanted. This covers even the case where (mode != COMPLETE) but some fields have been reconfigured. --- .../serialization/vespadocumentserializer.cpp | 41 ++++++++++------------ 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'document') diff --git a/document/src/vespa/document/serialization/vespadocumentserializer.cpp b/document/src/vespa/document/serialization/vespadocumentserializer.cpp index f5059c233bd..ae03bcc0d3c 100644 --- a/document/src/vespa/document/serialization/vespadocumentserializer.cpp +++ b/document/src/vespa/document/serialization/vespadocumentserializer.cpp @@ -91,6 +91,13 @@ VespaDocumentSerializer::getContentCode(bool hasHeader, bool hasBody) const return content; } +static inline size_t wantChunks(bool hasHeader, bool hasBody) { + size_t res = 0; + if (hasHeader) ++res; + if (hasBody) ++res; + return res; +} + void VespaDocumentSerializer::write(const Document &value, DocSerializationMode mode) { nbostream doc_stream; @@ -101,12 +108,6 @@ void VespaDocumentSerializer::write(const Document &value, bool hasBody = false; const StructFieldValue::Chunks & chunks = value.getFields().getChunks(); - if (chunks.size() == 2) { - // we must assume both types of fields if the original serialization - // had that, even if config has changed since then. - hasHeader = true; - hasBody = true; - } for (const Field & field : value.getFields()) { if (field.isHeaderField()) { @@ -114,35 +115,29 @@ void VespaDocumentSerializer::write(const Document &value, } else { hasBody = true; } - if (hasHeader && hasBody) { break; } } - if (mode != COMPLETE) { hasBody = false; } - doc_stream << getContentCode(hasHeader, hasBody); doc_serializer.write(value.getType()); - if (!structNeedsReserialization(value.getFields())) { - // FIXME(vekterli): - // Currently assume legacy serialization; a chunk will only ever contain fields - // _either_ for the header _or_ for the body, never a mixture! - // This is to avoid horrible breakage whilst ripping out old guts. - - if (hasHeader) { + if (chunks.size() == wantChunks(hasHeader, hasBody) && + !structNeedsReserialization(value.getFields())) + { + // here we assume the receiver can handle whatever serialization the + // chunks contain, so we just send them as-is, even if some fields + // may have moved from header to body or vice versa. + if (hasHeader || hasBody) { assert(chunks.size() >= 1); doc_serializer.writeUnchanged(chunks[0]); - if (hasBody) { - assert(chunks.size() == 2); - doc_serializer.writeUnchanged(chunks[1]); - } - } else if (hasBody) { - assert(chunks.size() == 1); - doc_serializer.writeUnchanged(chunks[0]); + } + if (hasHeader && hasBody) { + assert(chunks.size() == 2); + doc_serializer.writeUnchanged(chunks[1]); } } else { if (hasHeader) { -- cgit v1.2.3