Commit 052dda61 authored by Sergei Krivonos's avatar Sergei Krivonos

Made optional Json_writer_object / Json_writer_array consistency check

parent cf8e78a4
...@@ -185,6 +185,10 @@ IF(DISABLE_SHARED) ...@@ -185,6 +185,10 @@ IF(DISABLE_SHARED)
SET(WITHOUT_DYNAMIC_PLUGINS 1) SET(WITHOUT_DYNAMIC_PLUGINS 1)
ENDIF() ENDIF()
OPTION(ENABLED_PROFILING "Enable profiling" ON) OPTION(ENABLED_PROFILING "Enable profiling" ON)
OPTION(ENABLED_JSON_WRITER_CONSISTENCY_CHECKS "Enable Json_writer_object / Json_writer_array checking to produce consistent JSON output" OFF)
IF(ENABLED_JSON_WRITER_CONSISTENCY_CHECKS)
ADD_DEFINITIONS(-DENABLED_JSON_WRITER_CONSISTENCY_CHECKS)
ENDIF()
OPTION(WITHOUT_SERVER "Build only the client library and clients" OFF) OPTION(WITHOUT_SERVER "Build only the client library and clients" OFF)
IF(UNIX) IF(UNIX)
OPTION(WITH_VALGRIND "Valgrind instrumentation" OFF) OPTION(WITH_VALGRIND "Valgrind instrumentation" OFF)
......
...@@ -260,7 +260,9 @@ void Json_writer::add_str(const String &str) ...@@ -260,7 +260,9 @@ void Json_writer::add_str(const String &str)
add_str(str.ptr(), str.length()); add_str(str.ptr(), str.length());
} }
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
thread_local std::vector<bool> Json_writer_struct::named_items_expectation; thread_local std::vector<bool> Json_writer_struct::named_items_expectation;
#endif
Json_writer_temp_disable::Json_writer_temp_disable(THD *thd_arg) Json_writer_temp_disable::Json_writer_temp_disable(THD *thd_arg)
{ {
......
...@@ -312,7 +312,9 @@ class Json_value_helper ...@@ -312,7 +312,9 @@ class Json_value_helper
/* A common base for Json_writer_object and Json_writer_array */ /* A common base for Json_writer_object and Json_writer_array */
class Json_writer_struct class Json_writer_struct
{ {
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
static thread_local std::vector<bool> named_items_expectation; static thread_local std::vector<bool> named_items_expectation;
#endif
protected: protected:
Json_writer* my_writer; Json_writer* my_writer;
Json_value_helper context; Json_value_helper context;
...@@ -327,12 +329,16 @@ class Json_writer_struct ...@@ -327,12 +329,16 @@ class Json_writer_struct
my_writer= thd->opt_trace.get_current_json(); my_writer= thd->opt_trace.get_current_json();
context.init(my_writer); context.init(my_writer);
closed= false; closed= false;
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
named_items_expectation.push_back(expect_named_children); named_items_expectation.push_back(expect_named_children);
#endif
} }
virtual ~Json_writer_struct() virtual ~Json_writer_struct()
{ {
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
named_items_expectation.pop_back(); named_items_expectation.pop_back();
#endif
} }
bool trace_started() const bool trace_started() const
...@@ -340,11 +346,13 @@ class Json_writer_struct ...@@ -340,11 +346,13 @@ class Json_writer_struct
return my_writer != 0; return my_writer != 0;
} }
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
bool named_item_expected() const bool named_item_expected() const
{ {
return named_items_expectation.size() > 1 return named_items_expectation.size() > 1
&& *(named_items_expectation.rbegin() + 1); && *(named_items_expectation.rbegin() + 1);
} }
#endif
}; };
...@@ -367,7 +375,9 @@ class Json_writer_object : public Json_writer_struct ...@@ -367,7 +375,9 @@ class Json_writer_object : public Json_writer_struct
explicit Json_writer_object(THD *thd) explicit Json_writer_object(THD *thd)
: Json_writer_struct(thd, true) : Json_writer_struct(thd, true)
{ {
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
DBUG_ASSERT(!named_item_expected()); DBUG_ASSERT(!named_item_expected());
#endif
if (unlikely(my_writer)) if (unlikely(my_writer))
my_writer->start_object(); my_writer->start_object();
} }
...@@ -375,7 +385,9 @@ class Json_writer_object : public Json_writer_struct ...@@ -375,7 +385,9 @@ class Json_writer_object : public Json_writer_struct
explicit Json_writer_object(THD* thd, const char *str) explicit Json_writer_object(THD* thd, const char *str)
: Json_writer_struct(thd, true) : Json_writer_struct(thd, true)
{ {
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
DBUG_ASSERT(named_item_expected()); DBUG_ASSERT(named_item_expected());
#endif
if (unlikely(my_writer)) if (unlikely(my_writer))
my_writer->add_member(str).start_object(); my_writer->add_member(str).start_object();
} }
...@@ -542,7 +554,9 @@ class Json_writer_array : public Json_writer_struct ...@@ -542,7 +554,9 @@ class Json_writer_array : public Json_writer_struct
Json_writer_array(THD *thd) Json_writer_array(THD *thd)
: Json_writer_struct(thd, false) : Json_writer_struct(thd, false)
{ {
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
DBUG_ASSERT(!named_item_expected()); DBUG_ASSERT(!named_item_expected());
#endif
if (unlikely(my_writer)) if (unlikely(my_writer))
my_writer->start_array(); my_writer->start_array();
} }
...@@ -550,7 +564,9 @@ class Json_writer_array : public Json_writer_struct ...@@ -550,7 +564,9 @@ class Json_writer_array : public Json_writer_struct
Json_writer_array(THD *thd, const char *str) Json_writer_array(THD *thd, const char *str)
: Json_writer_struct(thd, false) : Json_writer_struct(thd, false)
{ {
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
DBUG_ASSERT(named_item_expected()); DBUG_ASSERT(named_item_expected());
#endif
if (unlikely(my_writer)) if (unlikely(my_writer))
my_writer->add_member(str).start_array(); my_writer->add_member(str).start_array();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment