|
|
|
|
@ -1,3 +1,7 @@
|
|
|
|
|
#include "../deps/json/json.hpp"
|
|
|
|
|
using json = nlohmann::json;
|
|
|
|
|
#define PROXYJSON
|
|
|
|
|
|
|
|
|
|
#include "PgSQL_HostGroups_Manager.h"
|
|
|
|
|
#include "proxysql.h"
|
|
|
|
|
#include "cpp.h"
|
|
|
|
|
@ -122,6 +126,49 @@ static int wait_for_pgsql(MYSQL *mysql, int status) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Helper function used to try to extract a value from the JSON field 'servers_defaults'.
|
|
|
|
|
*
|
|
|
|
|
* @param j JSON object constructed from 'servers_defaults' field.
|
|
|
|
|
* @param hid Hostgroup for which the 'servers_defaults' is defined in 'pgsql_hostgroup_attributes'. Used for
|
|
|
|
|
* error logging.
|
|
|
|
|
* @param key The key for the value to be extracted.
|
|
|
|
|
* @param val_check A validation function, checks if the value is within a expected range.
|
|
|
|
|
*
|
|
|
|
|
* @return The value extracted from the supplied JSON. In case of error '-1', and error cause is logged.
|
|
|
|
|
*/
|
|
|
|
|
template <typename T, typename std::enable_if<std::is_integral<T>::value, bool>::type = true>
|
|
|
|
|
T PgSQL_j_get_srv_default_int_val(
|
|
|
|
|
const json& j, uint32_t hid, const string& key, const function<bool(T)>& val_check
|
|
|
|
|
) {
|
|
|
|
|
if (j.find(key) != j.end()) {
|
|
|
|
|
const json::value_t val_type = j[key].type();
|
|
|
|
|
const char* type_name = j[key].type_name();
|
|
|
|
|
|
|
|
|
|
if (val_type == json::value_t::number_integer || val_type == json::value_t::number_unsigned) {
|
|
|
|
|
T val = j[key].get<T>();
|
|
|
|
|
|
|
|
|
|
if (val_check(val)) {
|
|
|
|
|
return val;
|
|
|
|
|
} else {
|
|
|
|
|
proxy_error(
|
|
|
|
|
"Invalid value %ld supplied for 'pgsql_hostgroup_attributes.servers_defaults.%s' for hostgroup %d."
|
|
|
|
|
" Value NOT UPDATED.\n",
|
|
|
|
|
static_cast<int64_t>(val), key.c_str(), hid
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
proxy_error(
|
|
|
|
|
"Invalid type '%s'(%hhu) supplied for 'pgsql_hostgroup_attributes.servers_defaults.%s' for hostgroup %d."
|
|
|
|
|
" Value NOT UPDATED.\n",
|
|
|
|
|
type_name, static_cast<std::uint8_t>(val_type), key.c_str(), hid
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return static_cast<T>(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
static void reader_cb(struct ev_loop *loop, struct ev_io *w, int revents) {
|
|
|
|
|
pthread_mutex_lock(&ev_loop_mutex);
|
|
|
|
|
@ -921,7 +968,10 @@ void PgSQL_HGC::reset_attributes() {
|
|
|
|
|
attributes.comment = NULL;
|
|
|
|
|
free(attributes.ignore_session_variables_text);
|
|
|
|
|
attributes.ignore_session_variables_text = NULL;
|
|
|
|
|
attributes.ignore_session_variables_json = json();
|
|
|
|
|
if (attributes.ignore_session_variables_json) {
|
|
|
|
|
delete attributes.ignore_session_variables_json;
|
|
|
|
|
attributes.ignore_session_variables_json = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PgSQL_HGC::~PgSQL_HGC() {
|
|
|
|
|
@ -7303,14 +7353,16 @@ void PgSQL_HostGroups_Manager::generate_pgsql_hostgroup_attributes_table() {
|
|
|
|
|
if (myhgc->attributes.ignore_session_variables_text == NULL) {
|
|
|
|
|
myhgc->attributes.ignore_session_variables_text = strdup(ignore_session_variables);
|
|
|
|
|
if (strlen(ignore_session_variables) != 0) { // only if there is a valid JSON
|
|
|
|
|
myhgc->attributes.ignore_session_variables_json = json::parse(ignore_session_variables);
|
|
|
|
|
if (myhgc->attributes.ignore_session_variables_json != nullptr) { delete myhgc->attributes.ignore_session_variables_json; }
|
|
|
|
|
myhgc->attributes.ignore_session_variables_json = new json(json::parse(ignore_session_variables));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (strcmp(myhgc->attributes.ignore_session_variables_text, ignore_session_variables) != 0) {
|
|
|
|
|
free(myhgc->attributes.ignore_session_variables_text);
|
|
|
|
|
myhgc->attributes.ignore_session_variables_text = strdup(ignore_session_variables);
|
|
|
|
|
if (strlen(ignore_session_variables) != 0) { // only if there is a valid JSON
|
|
|
|
|
myhgc->attributes.ignore_session_variables_json = json::parse(ignore_session_variables);
|
|
|
|
|
if (myhgc->attributes.ignore_session_variables_json != nullptr) { delete myhgc->attributes.ignore_session_variables_json; }
|
|
|
|
|
myhgc->attributes.ignore_session_variables_json = new json(json::parse(ignore_session_variables));
|
|
|
|
|
}
|
|
|
|
|
// TODO: assign the variables
|
|
|
|
|
}
|
|
|
|
|
|