From 60c0441f9ba3196eaabe38935333d17f1aff88f8 Mon Sep 17 00:00:00 2001 From: David Storch Date: Wed, 20 Mar 2019 17:18:56 -0400 Subject: SERVER-40267 Clean up debug string generation for MatchExpression. --- .../expression_internal_schema_all_elem_match_from_index.cpp | 6 +++--- .../schema/expression_internal_schema_all_elem_match_from_index.h | 2 +- .../schema/expression_internal_schema_allowed_properties.cpp | 4 ++-- .../matcher/schema/expression_internal_schema_allowed_properties.h | 2 +- src/mongo/db/matcher/schema/expression_internal_schema_eq.cpp | 5 +++-- src/mongo/db/matcher/schema/expression_internal_schema_eq.h | 2 +- src/mongo/db/matcher/schema/expression_internal_schema_fmod.cpp | 5 +++-- src/mongo/db/matcher/schema/expression_internal_schema_fmod.h | 2 +- .../schema/expression_internal_schema_match_array_index.cpp | 4 ++-- .../matcher/schema/expression_internal_schema_match_array_index.h | 2 +- .../matcher/schema/expression_internal_schema_num_array_items.cpp | 4 ++-- .../db/matcher/schema/expression_internal_schema_num_array_items.h | 2 +- .../matcher/schema/expression_internal_schema_num_properties.cpp | 4 ++-- .../db/matcher/schema/expression_internal_schema_num_properties.h | 2 +- .../db/matcher/schema/expression_internal_schema_object_match.cpp | 7 ++++--- .../db/matcher/schema/expression_internal_schema_object_match.h | 2 +- .../db/matcher/schema/expression_internal_schema_root_doc_eq.cpp | 5 +++-- .../db/matcher/schema/expression_internal_schema_root_doc_eq.h | 2 +- .../db/matcher/schema/expression_internal_schema_str_length.cpp | 5 +++-- .../db/matcher/schema/expression_internal_schema_str_length.h | 2 +- .../db/matcher/schema/expression_internal_schema_unique_items.cpp | 5 +++-- .../db/matcher/schema/expression_internal_schema_unique_items.h | 2 +- src/mongo/db/matcher/schema/expression_internal_schema_xor.cpp | 7 ++++--- src/mongo/db/matcher/schema/expression_internal_schema_xor.h | 2 +- src/mongo/db/matcher/schema/json_schema_parser.cpp | 3 ++- 25 files changed, 48 insertions(+), 40 deletions(-) (limited to 'src/mongo/db/matcher/schema') diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.cpp index 2b8d2a7b76d..7c2d67425b0 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.cpp +++ b/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.cpp @@ -66,11 +66,11 @@ bool InternalSchemaAllElemMatchFromIndexMatchExpression::equivalent( } void InternalSchemaAllElemMatchFromIndexMatchExpression::debugString(StringBuilder& debug, - int level) const { - _debugAddSpace(debug, level); + int indentationLevel) const { + _debugAddSpace(debug, indentationLevel); debug << kName << "\n"; debug << " index: " << _index << ", query:\n"; - _expression->getFilter()->debugString(debug, level + 1); + _expression->getFilter()->debugString(debug, indentationLevel + 1); } BSONObj InternalSchemaAllElemMatchFromIndexMatchExpression::getSerializedRightHandSide() const { diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.h b/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.h index c56884b96bb..dab875cb80d 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.h @@ -61,7 +61,7 @@ public: return true; } - void debugString(StringBuilder& debug, int level) const final; + void debugString(StringBuilder& debug, int indentationLevel) const final; BSONObj getSerializedRightHandSide() const final; diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties.cpp index 733a60c5771..c656840e247 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties.cpp +++ b/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties.cpp @@ -54,8 +54,8 @@ InternalSchemaAllowedPropertiesMatchExpression::InternalSchemaAllowedPropertiesM } void InternalSchemaAllowedPropertiesMatchExpression::debugString(StringBuilder& debug, - int level) const { - _debugAddSpace(debug, level); + int indentationLevel) const { + _debugAddSpace(debug, indentationLevel); BSONObjBuilder builder; serialize(&builder); diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties.h b/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties.h index 5779c4950b8..29042a38aae 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties.h @@ -115,7 +115,7 @@ public: std::vector patternProperties, std::unique_ptr otherwise); - void debugString(StringBuilder& debug, int level) const final; + void debugString(StringBuilder& debug, int indentationLevel) const final; bool equivalent(const MatchExpression* expr) const final; diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_eq.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_eq.cpp index 9f7db2244dd..c28eb69e4fb 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_eq.cpp +++ b/src/mongo/db/matcher/schema/expression_internal_schema_eq.cpp @@ -53,8 +53,9 @@ bool InternalSchemaEqMatchExpression::matchesSingleElement(const BSONElement& el return _eltCmp.evaluate(_rhsElem == elem); } -void InternalSchemaEqMatchExpression::debugString(StringBuilder& debug, int level) const { - _debugAddSpace(debug, level); +void InternalSchemaEqMatchExpression::debugString(StringBuilder& debug, + int indentationLevel) const { + _debugAddSpace(debug, indentationLevel); debug << path() << " " << kName << " " << _rhsElem.toString(false); auto td = getTag(); diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_eq.h b/src/mongo/db/matcher/schema/expression_internal_schema_eq.h index 7d6406da36c..c2495d991ba 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_eq.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_eq.h @@ -52,7 +52,7 @@ public: bool matchesSingleElement(const BSONElement&, MatchDetails*) const final; - void debugString(StringBuilder& debug, int level) const final; + void debugString(StringBuilder& debug, int indentationLevel) const final; BSONObj getSerializedRightHandSide() const final; diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_fmod.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_fmod.cpp index 71e954a930f..6362c3e8d41 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_fmod.cpp +++ b/src/mongo/db/matcher/schema/expression_internal_schema_fmod.cpp @@ -61,8 +61,9 @@ bool InternalSchemaFmodMatchExpression::matchesSingleElement(const BSONElement& return false; } -void InternalSchemaFmodMatchExpression::debugString(StringBuilder& debug, int level) const { - _debugAddSpace(debug, level); +void InternalSchemaFmodMatchExpression::debugString(StringBuilder& debug, + int indentationLevel) const { + _debugAddSpace(debug, indentationLevel); debug << path() << " fmod: divisor: " << _divisor.toString() << " remainder: " << _remainder.toString(); MatchExpression::TagData* td = getTag(); diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_fmod.h b/src/mongo/db/matcher/schema/expression_internal_schema_fmod.h index 76fb8670c17..201ec23f70e 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_fmod.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_fmod.h @@ -52,7 +52,7 @@ public: bool matchesSingleElement(const BSONElement& e, MatchDetails* details = nullptr) const final; - void debugString(StringBuilder& debug, int level) const final; + void debugString(StringBuilder& debug, int indentationLevel) const final; BSONObj getSerializedRightHandSide() const final; diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index.cpp index 7c929a08910..f4264c5d1ef 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index.cpp +++ b/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index.cpp @@ -43,8 +43,8 @@ InternalSchemaMatchArrayIndexMatchExpression::InternalSchemaMatchArrayIndexMatch } void InternalSchemaMatchArrayIndexMatchExpression::debugString(StringBuilder& debug, - int level) const { - _debugAddSpace(debug, level); + int indentationLevel) const { + _debugAddSpace(debug, indentationLevel); BSONObjBuilder builder; serialize(&builder); diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index.h b/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index.h index 89958d3fb82..9a0bb8675b7 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index.h @@ -45,7 +45,7 @@ public: InternalSchemaMatchArrayIndexMatchExpression( StringData path, long long index, std::unique_ptr expression); - void debugString(StringBuilder& debug, int level) const final; + void debugString(StringBuilder& debug, int indentationLevel) const final; bool equivalent(const MatchExpression* expr) const final; diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_num_array_items.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_num_array_items.cpp index dd4281890d7..c6aa1cf0cca 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_num_array_items.cpp +++ b/src/mongo/db/matcher/schema/expression_internal_schema_num_array_items.cpp @@ -38,8 +38,8 @@ InternalSchemaNumArrayItemsMatchExpression::InternalSchemaNumArrayItemsMatchExpr : ArrayMatchingMatchExpression(type, path), _name(name), _numItems(numItems) {} void InternalSchemaNumArrayItemsMatchExpression::debugString(StringBuilder& debug, - int level) const { - _debugAddSpace(debug, level); + int indentationLevel) const { + _debugAddSpace(debug, indentationLevel); debug << path() << " " << _name << " " << _numItems << "\n"; MatchExpression::TagData* td = getTag(); diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_num_array_items.h b/src/mongo/db/matcher/schema/expression_internal_schema_num_array_items.h index 930369c6241..249de09c030 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_num_array_items.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_num_array_items.h @@ -46,7 +46,7 @@ public: virtual ~InternalSchemaNumArrayItemsMatchExpression() {} - void debugString(StringBuilder& debug, int level) const final; + void debugString(StringBuilder& debug, int indentationLevel) const final; BSONObj getSerializedRightHandSide() const final; diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_num_properties.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_num_properties.cpp index b62d0a6e889..d8895fc7adb 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_num_properties.cpp +++ b/src/mongo/db/matcher/schema/expression_internal_schema_num_properties.cpp @@ -34,8 +34,8 @@ namespace mongo { void InternalSchemaNumPropertiesMatchExpression::debugString(StringBuilder& debug, - int level) const { - _debugAddSpace(debug, level); + int indentationLevel) const { + _debugAddSpace(debug, indentationLevel); BSONObjBuilder builder; serialize(&builder); debug << builder.obj().toString() << "\n"; diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_num_properties.h b/src/mongo/db/matcher/schema/expression_internal_schema_num_properties.h index aad612ec2b4..415ed946145 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_num_properties.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_num_properties.h @@ -59,7 +59,7 @@ public: return nullptr; } - void debugString(StringBuilder& debug, int level) const final; + void debugString(StringBuilder& debug, int indentationLevel) const final; void serialize(BSONObjBuilder* out) const final; diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_object_match.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_object_match.cpp index ab36f871ef3..36a921a4380 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_object_match.cpp +++ b/src/mongo/db/matcher/schema/expression_internal_schema_object_match.cpp @@ -51,10 +51,11 @@ bool InternalSchemaObjectMatchExpression::matchesSingleElement(const BSONElement return _sub->matchesBSON(elem.Obj()); } -void InternalSchemaObjectMatchExpression::debugString(StringBuilder& debug, int level) const { - _debugAddSpace(debug, level); +void InternalSchemaObjectMatchExpression::debugString(StringBuilder& debug, + int indentationLevel) const { + _debugAddSpace(debug, indentationLevel); debug << kName << "\n"; - _sub->debugString(debug, level + 1); + _sub->debugString(debug, indentationLevel + 1); } BSONObj InternalSchemaObjectMatchExpression::getSerializedRightHandSide() const { diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_object_match.h b/src/mongo/db/matcher/schema/expression_internal_schema_object_match.h index 86d80870a97..407c6680057 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_object_match.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_object_match.h @@ -43,7 +43,7 @@ public: std::unique_ptr shallowClone() const final; - void debugString(StringBuilder& debug, int level = 0) const final; + void debugString(StringBuilder& debug, int indentationLevel = 0) const final; BSONObj getSerializedRightHandSide() const final; diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_root_doc_eq.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_root_doc_eq.cpp index bea30b7657b..1b1fc6ae29f 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_root_doc_eq.cpp +++ b/src/mongo/db/matcher/schema/expression_internal_schema_root_doc_eq.cpp @@ -40,8 +40,9 @@ bool InternalSchemaRootDocEqMatchExpression::matches(const MatchableDocument* do return _objCmp.evaluate(doc->toBSON() == _rhsObj); } -void InternalSchemaRootDocEqMatchExpression::debugString(StringBuilder& debug, int level) const { - _debugAddSpace(debug, level); +void InternalSchemaRootDocEqMatchExpression::debugString(StringBuilder& debug, + int indentationLevel) const { + _debugAddSpace(debug, indentationLevel); debug << kName << " " << _rhsObj.toString(); auto td = getTag(); diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_root_doc_eq.h b/src/mongo/db/matcher/schema/expression_internal_schema_root_doc_eq.h index ea2f411c51a..062d358939d 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_root_doc_eq.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_root_doc_eq.h @@ -65,7 +65,7 @@ public: std::unique_ptr shallowClone() const final; - void debugString(StringBuilder& debug, int level = 0) const final; + void debugString(StringBuilder& debug, int indentationLevel = 0) const final; void serialize(BSONObjBuilder* out) const final; diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_str_length.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_str_length.cpp index 0bf8e45caf7..d8f961ce35b 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_str_length.cpp +++ b/src/mongo/db/matcher/schema/expression_internal_schema_str_length.cpp @@ -41,8 +41,9 @@ InternalSchemaStrLengthMatchExpression::InternalSchemaStrLengthMatchExpression(M StringData name) : LeafMatchExpression(type, path), _name(name), _strLen(strLen) {} -void InternalSchemaStrLengthMatchExpression::debugString(StringBuilder& debug, int level) const { - _debugAddSpace(debug, level); +void InternalSchemaStrLengthMatchExpression::debugString(StringBuilder& debug, + int indentationLevel) const { + _debugAddSpace(debug, indentationLevel); debug << path() << " " << _name << " " << _strLen << "\n"; MatchExpression::TagData* td = getTag(); diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_str_length.h b/src/mongo/db/matcher/schema/expression_internal_schema_str_length.h index 3fbdd83c1dd..12ade1d8fc0 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_str_length.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_str_length.h @@ -58,7 +58,7 @@ public: return getComparator()(len); }; - void debugString(StringBuilder& debug, int level) const final; + void debugString(StringBuilder& debug, int indentationLevel) const final; BSONObj getSerializedRightHandSide() const final; diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_unique_items.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_unique_items.cpp index 2854d58c5d5..afb0a39cbe4 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_unique_items.cpp +++ b/src/mongo/db/matcher/schema/expression_internal_schema_unique_items.cpp @@ -34,8 +34,9 @@ namespace mongo { constexpr StringData InternalSchemaUniqueItemsMatchExpression::kName; -void InternalSchemaUniqueItemsMatchExpression::debugString(StringBuilder& debug, int level) const { - _debugAddSpace(debug, level); +void InternalSchemaUniqueItemsMatchExpression::debugString(StringBuilder& debug, + int indentationLevel) const { + _debugAddSpace(debug, indentationLevel); BSONObjBuilder builder; serialize(&builder); diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_unique_items.h b/src/mongo/db/matcher/schema/expression_internal_schema_unique_items.h index f9e9527e6f1..9b47e32682f 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_unique_items.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_unique_items.h @@ -71,7 +71,7 @@ public: return true; } - void debugString(StringBuilder& builder, int level) const final; + void debugString(StringBuilder& builder, int indentationLevel) const final; bool equivalent(const MatchExpression* other) const final; diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_xor.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_xor.cpp index a876792060a..c920e38f827 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_xor.cpp +++ b/src/mongo/db/matcher/schema/expression_internal_schema_xor.cpp @@ -66,10 +66,11 @@ bool InternalSchemaXorMatchExpression::matchesSingleElement(const BSONElement& e return found; } -void InternalSchemaXorMatchExpression::debugString(StringBuilder& debug, int level) const { - _debugAddSpace(debug, level); +void InternalSchemaXorMatchExpression::debugString(StringBuilder& debug, + int indentationLevel) const { + _debugAddSpace(debug, indentationLevel); debug << kName + "\n"; - _debugList(debug, level); + _debugList(debug, indentationLevel); } void InternalSchemaXorMatchExpression::serialize(BSONObjBuilder* out) const { diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_xor.h b/src/mongo/db/matcher/schema/expression_internal_schema_xor.h index 580524ebe6b..b11d1641a33 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_xor.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_xor.h @@ -58,7 +58,7 @@ public: return std::move(xorCopy); } - void debugString(StringBuilder& debug, int level = 0) const final; + void debugString(StringBuilder& debug, int indentationLevel = 0) const final; void serialize(BSONObjBuilder* out) const final; }; diff --git a/src/mongo/db/matcher/schema/json_schema_parser.cpp b/src/mongo/db/matcher/schema/json_schema_parser.cpp index 2b35d8e34b5..f46196df71f 100644 --- a/src/mongo/db/matcher/schema/json_schema_parser.cpp +++ b/src/mongo/db/matcher/schema/json_schema_parser.cpp @@ -1583,7 +1583,8 @@ StatusWithMatchExpression JSONSchemaParser::parse(BSONObj schema, bool ignoreUnk try { auto translation = _parse(""_sd, schema, ignoreUnknownKeywords); if (shouldLog(logger::LogSeverity::Debug(5)) && translation.isOK()) { - LOG(5) << "Translated schema match expression: " << translation.getValue()->toString(); + LOG(5) << "Translated schema match expression: " + << translation.getValue()->debugString(); } return translation; } catch (const DBException& ex) { -- cgit v1.2.1