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)
SET(WITHOUT_DYNAMIC_PLUGINS 1)
ENDIF()
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)
IF(UNIX)
OPTION(WITH_VALGRIND "Valgrind instrumentation" OFF)
......
......@@ -260,7 +260,9 @@ void Json_writer::add_str(const String &str)
add_str(str.ptr(), str.length());
}
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
thread_local std::vector<bool> Json_writer_struct::named_items_expectation;
#endif
Json_writer_temp_disable::Json_writer_temp_disable(THD *thd_arg)
{
......
......@@ -312,7 +312,9 @@ class Json_value_helper
/* A common base for Json_writer_object and Json_writer_array */
class Json_writer_struct
{
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
static thread_local std::vector<bool> named_items_expectation;
#endif
protected:
Json_writer* my_writer;
Json_value_helper context;
......@@ -327,12 +329,16 @@ class Json_writer_struct
my_writer= thd->opt_trace.get_current_json();
context.init(my_writer);
closed= false;
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
named_items_expectation.push_back(expect_named_children);
#endif
}
virtual ~Json_writer_struct()
{
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
named_items_expectation.pop_back();
#endif
}
bool trace_started() const
......@@ -340,11 +346,13 @@ class Json_writer_struct
return my_writer != 0;
}
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
bool named_item_expected() const
{
return named_items_expectation.size() > 1
&& *(named_items_expectation.rbegin() + 1);
}
#endif
};
......@@ -367,7 +375,9 @@ class Json_writer_object : public Json_writer_struct
explicit Json_writer_object(THD *thd)
: Json_writer_struct(thd, true)
{
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
DBUG_ASSERT(!named_item_expected());
#endif
if (unlikely(my_writer))
my_writer->start_object();
}
......@@ -375,7 +385,9 @@ class Json_writer_object : public Json_writer_struct
explicit Json_writer_object(THD* thd, const char *str)
: Json_writer_struct(thd, true)
{
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
DBUG_ASSERT(named_item_expected());
#endif
if (unlikely(my_writer))
my_writer->add_member(str).start_object();
}
......@@ -542,7 +554,9 @@ class Json_writer_array : public Json_writer_struct
Json_writer_array(THD *thd)
: Json_writer_struct(thd, false)
{
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
DBUG_ASSERT(!named_item_expected());
#endif
if (unlikely(my_writer))
my_writer->start_array();
}
......@@ -550,7 +564,9 @@ class Json_writer_array : public Json_writer_struct
Json_writer_array(THD *thd, const char *str)
: Json_writer_struct(thd, false)
{
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
DBUG_ASSERT(named_item_expected());
#endif
if (unlikely(my_writer))
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