diff --git a/src/observer/ob_server_event_history_table_operator.h b/src/observer/ob_server_event_history_table_operator.h index a44b6d0dc3..701d6d9379 100644 --- a/src/observer/ob_server_event_history_table_operator.h +++ b/src/observer/ob_server_event_history_table_operator.h @@ -38,7 +38,7 @@ private: #define SERVER_EVENT_INSTANCE (::oceanbase::observer::ObAllServerEventHistoryTableOperator::get_instance()) #define SERVER_EVENT_ADD(args...) \ - SERVER_EVENT_INSTANCE.add_event(args) + SERVER_EVENT_INSTANCE.add_event(args) #define SERVER_EVENT_SYNC_ADD(args...) \ SERVER_EVENT_INSTANCE.sync_add_event(args) #define SERVER_EVENT_ADD_WITH_RETRY(args...) \ diff --git a/src/rootserver/ob_root_service.cpp b/src/rootserver/ob_root_service.cpp index 9b1d05b27b..e394cbe92b 100755 --- a/src/rootserver/ob_root_service.cpp +++ b/src/rootserver/ob_root_service.cpp @@ -8126,7 +8126,10 @@ int ObRootService::admin_set_config(obrpc::ObAdminSetConfigArg &arg) } } } - ROOTSERVICE_EVENT_ADD("root_service", "admin_set_config", K(ret), K(arg)); + // Add event one by one if more than one parameters are set + for (int i = 0; i < arg.items_.count(); i++) { + ROOTSERVICE_EVENT_ADD_TRUNCATE("root_service", "admin_set_config", K(ret), "arg", arg.items_.at(i), "is_inner", arg.is_inner_); + } return ret; } diff --git a/src/rootserver/ob_rs_event_history_table_operator.h b/src/rootserver/ob_rs_event_history_table_operator.h index a7ebd3f309..a98a447f73 100644 --- a/src/rootserver/ob_rs_event_history_table_operator.h +++ b/src/rootserver/ob_rs_event_history_table_operator.h @@ -38,6 +38,7 @@ private: #define ROOTSERVICE_EVENT_INSTANCE (::oceanbase::rootserver::ObRsEventHistoryTableOperator::get_instance()) #define ROOTSERVICE_EVENT_ADD(args...) \ - ROOTSERVICE_EVENT_INSTANCE.add_event(args) - + ROOTSERVICE_EVENT_INSTANCE.add_event(args) +#define ROOTSERVICE_EVENT_ADD_TRUNCATE(args...) \ + ROOTSERVICE_EVENT_INSTANCE.add_event(args) #endif // OCEANBASE_ROOTSERVER_OB_RS_EVENT_HISTORY_TABLE_OPERATOR_H_ diff --git a/src/share/ob_event_history_table_operator.cpp b/src/share/ob_event_history_table_operator.cpp index ddf9d52574..179269af8b 100644 --- a/src/share/ob_event_history_table_operator.cpp +++ b/src/share/ob_event_history_table_operator.cpp @@ -233,35 +233,6 @@ void ObEventHistoryTableOperator::destroy() inited_ = false; } -int ObEventHistoryTableOperator::add_event(const char *module, const char *event) -{ - int ret = OB_SUCCESS; - if (!inited_) { - ret = OB_NOT_INIT; - LOG_WARN("not init", K(ret)); - } else if (NULL == module || NULL == event) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("neither module or event can be NULL", KP(module), KP(event), K(ret)); - } else { - const int64_t now = ObTimeUtility::current_time(); - ObDMLSqlSplicer dml; - if (OB_FAIL(dml.add_gmt_create(now)) - || OB_FAIL(dml.add_column("module", module)) - || OB_FAIL(dml.add_column("event", event))) { - LOG_WARN("add column failed", K(ret)); - } else { - ObSqlString sql; - if (OB_FAIL(dml.splice_insert_sql(event_table_name_, sql))) { - LOG_WARN("splice_insert_sql failed", - "table_name", event_table_name_, K(ret)); - } else if (OB_FAIL(add_task(sql))) { - LOG_WARN("add_task failed", K(sql), K(ret)); - } - } - } - return ret; -} - int ObEventHistoryTableOperator::gen_event_ts(int64_t &event_ts) { int ret = OB_SUCCESS; diff --git a/src/share/ob_event_history_table_operator.h b/src/share/ob_event_history_table_operator.h index aebd8e987d..255c118954 100644 --- a/src/share/ob_event_history_table_operator.h +++ b/src/share/ob_event_history_table_operator.h @@ -65,6 +65,8 @@ class ObEventHistoryTableOperator { public: static const int64_t EVENT_TABLE_CLEAR_INTERVAL = 2L * 3600L * 1000L * 1000L; // 2 Hours + template + struct ValueConverter {}; class ObEventTableUpdateTask : public common::IObDedupTask { public: @@ -99,37 +101,12 @@ public: void stop(); void wait(); void destroy(); - template - int add_event(const char *module, const char *event, const char *name1, const T1 &value1, - const char *name2, const T2 &value2, const char *name3, const T3 &value3, - const char *name4, const T4 &value4, const char *name5, const T5 &value5, - const char *name6, const T6 &value6, const T7 &extra_value); - template - int add_event(const char *module, const char *event, const char *name1, const T1 &value1, - const char *name2, const T2 &value2, const char *name3, const T3 &value3, - const char *name4, const T4 &value4, const char *name5, const T5 &value5, - const char *name6, const T6 &value6); - template - int add_event(const char *module, const char *event, const char *name1, const T1 &value1, - const char *name2, const T2 &value2, const char *name3, const T3 &value3, - const char *name4, const T4 &value4, const char *name5, const T5 &value5); - template - int add_event(const char *module, const char *event, const char *name1, const T1 &value1, - const char *name2, const T2 &value2, const char *name3, const T3 &value3, - const char *name4, const T4 &value4); - template - int add_event(const char *module, const char *event, const char *name1, const T1 &value1, - const char *name2, const T2 &value2, const char *name3, const T3 &value3); - template - int add_event(const char *module, const char *event, const char *name1, const T1 &value1, - const char *name2, const T2 &value2); - template - int add_event(const char *module, const char *event, const char *name1, const T1 &value1); - int add_event(const char *module, const char *event); - + // number of others should not less than 0, or more than 13 + // if number of others is not 13, should be even, every odd of them are name, every even of them are value + // If Truncate is true, then too long value will be truncated to fit in the field. + // Note: Only enable Truncate for rootservice_event_history! + template + int add_event(const char *module, const char *event, Rest &&...others); // number of others should not less than 0, or more than 13 // if number of others is not 13, should be even, every odd of them are name, every even of them are value template @@ -143,14 +120,14 @@ public: protected: virtual int default_async_delete(); // recursive begin - template - int sync_add_event_helper_(share::ObDMLSqlSplicer &dml, Name &&name, Value &&value, Rest &&...others); + template + int add_event_helper_(share::ObDMLSqlSplicer &dml, Name &&name, Value &&value, Rest &&...others); // recursive end if there is no extra_info - template - int sync_add_event_helper_(share::ObDMLSqlSplicer &dml); + template + int add_event_helper_(share::ObDMLSqlSplicer &dml); // recursive end if there is an extra_info - template - int sync_add_event_helper_(share::ObDMLSqlSplicer &dml, Value &&extro_info); + template + int add_event_helper_(share::ObDMLSqlSplicer &dml, Value &&extro_info); int add_event_to_timer_(const common::ObSqlString &sql); void set_addr(const common::ObAddr self_addr, bool is_rs_ev, @@ -196,14 +173,44 @@ private: DISALLOW_COPY_AND_ASSIGN(ObEventHistoryTableOperator); }; -template -int ObEventHistoryTableOperator::add_event(const char *module, const char *event, - const char *name1, const T1 &value1, const char *name2, const T2 &value2, - const char *name3, const T3 &value3, const char *name4, const T4 &value4, - const char *name5, const T5 &value5, const char *name6, const T6 &value6, - const T7 &extra_info_value) +template +struct ObEventHistoryTableOperator::ValueConverter { + const ObString & convert(const char *value) { + truncated_str_.assign_ptr(value, min(static_cast(STRLEN(value)), MAX_ROOTSERVICE_EVENT_VALUE_LENGTH)); + return truncated_str_; + } + + template::value, bool>::type = true> + const ObString & convert(const U &value) { + int64_t len = value.to_string(buffer_, sizeof(buffer_)); + truncated_str_.assign_ptr(buffer_, len); + return truncated_str_; + } + + template::value, bool>::type = true> + inline const U & convert(const U &value) { + return value; + } + + char buffer_[MAX_ROOTSERVICE_EVENT_VALUE_LENGTH + 1]; + ObString truncated_str_; +}; + +template +struct ObEventHistoryTableOperator::ValueConverter +{ + inline const T & convert(const T &value) { + return value; + } +}; + +template +int ObEventHistoryTableOperator::add_event(const char *module, const char *event, Rest &&...others) +{ + static_assert(sizeof...(others) >= 0 && sizeof...(others) <= 13 && + (sizeof...(others) == 13 || (sizeof...(others) % 2 == 0)), + "max support 6 pair of name-value args and 1 extra info, if number of others is not 13, should be even"); int ret = common::OB_SUCCESS; int64_t event_ts = 0; common::ObSqlString sql; @@ -222,43 +229,7 @@ int ObEventHistoryTableOperator::add_event(const char *module, const char *event || OB_FAIL(dml.add_column("module", module)) || OB_FAIL(dml.add_column("event", event))) { SHARE_LOG(WARN, "add column failed", K(ret)); - } - if (common::OB_SUCCESS == ret && NULL != name1) { - if (OB_FAIL(dml.add_column("name1", name1)) - || OB_FAIL(dml.add_column("value1", value1))) { - SHARE_LOG(WARN, "add column failed", K(ret)); - } - } - if (common::OB_SUCCESS == ret && NULL != name2) { - if (OB_FAIL(dml.add_column("name2", name2)) - || OB_FAIL(dml.add_column("value2", value2))) { - SHARE_LOG(WARN, "add column failed", K(ret)); - } - } - if (common::OB_SUCCESS == ret && NULL != name3) { - if (OB_FAIL(dml.add_column("name3", name3)) - || OB_FAIL(dml.add_column("value3", value3))) { - SHARE_LOG(WARN, "add column failed", K(ret)); - } - } - if (common::OB_SUCCESS == ret && NULL != name4) { - if (OB_FAIL(dml.add_column("name4", name4)) - || OB_FAIL(dml.add_column("value4", value4))) { - SHARE_LOG(WARN, "add column failed", K(ret)); - } - } - if (common::OB_SUCCESS == ret && NULL != name5) { - if (OB_FAIL(dml.add_column("name5", name5)) - || OB_FAIL(dml.add_column("value5", value5))) { - SHARE_LOG(WARN, "add column failed", K(ret)); - } - } - if (common::OB_SUCCESS == ret && NULL != name6) { - if (OB_FAIL(dml.add_column("name6", name6)) - || OB_FAIL(dml.add_column("value6", value6)) - || OB_FAIL(dml.add_column("extra_info", extra_info_value))) { - SHARE_LOG(WARN, "add column failed", K(ret)); - } + } else if (OB_FAIL((add_event_helper_<0, Truncate>(dml, std::forward(others)...)))) {// recursive call } char ip_buf[common::MAX_IP_ADDR_LENGTH]; if (common::OB_SUCCESS == ret && self_addr_.is_valid()) { @@ -291,137 +262,6 @@ int ObEventHistoryTableOperator::add_event(const char *module, const char *event return ret; } -template -int ObEventHistoryTableOperator::add_event(const char *module, const char *event, - const char *name1, const T1 &value1, const char *name2, const T2 &value2, - const char *name3, const T3 &value3, const char *name4, const T4 &value4, - const char *name5, const T5 &value5, const char *name6, const T6 &value6) -{ - int ret = common::OB_SUCCESS; - if (!inited_) { - ret = common::OB_NOT_INIT; - SHARE_LOG(WARN, "not init", K(ret)); - } else if (NULL == module || NULL == event || NULL == name1 || NULL == name2 - || NULL == name3 || NULL == name4 || NULL == name5 || NULL == name6) { - ret = common::OB_INVALID_ARGUMENT; - SHARE_LOG(WARN, "invalid argument", KP(module), KP(event), KP(name1), KP(name2), - KP(name3), KP(name4), KP(name5), KP(name6), K(ret)); - } else if (OB_FAIL(add_event(module, event, name1, value1, name2, value2, name3, value3, - name4, value4, name5, value5, name6, value6, ""))) { - SHARE_LOG(WARN, "add event failed", KP(module), KP(event), KP(name1), K(value1), - KP(name2), K(value2), KP(name3), K(value3), KP(name4), K(value4), - KP(name5), K(value5), KP(name6), K(value6), K(ret)); - } - return ret; -} - -template -int ObEventHistoryTableOperator::add_event(const char *module, const char *event, - const char *name1, const T1 &value1, const char *name2, const T2 &value2, - const char *name3, const T3 &value3, const char *name4, const T4 &value4, - const char *name5, const T5 &value5) -{ - int ret = common::OB_SUCCESS; - if (!inited_) { - ret = common::OB_NOT_INIT; - SHARE_LOG(WARN, "not init", K(ret)); - } else if (NULL == module || NULL == event || NULL == name1 || NULL == name2 - || NULL == name3 || NULL == name4 || NULL == name5) { - ret = common::OB_INVALID_ARGUMENT; - SHARE_LOG(WARN, "invalid argument", KP(module), KP(event), KP(name1), KP(name2), - KP(name3), KP(name4), KP(name5), K(ret)); - } else if (OB_FAIL(add_event(module, event, name1, value1, name2, value2, name3, value3, - name4, value4, name5, value5, NULL, "", ""))) { - SHARE_LOG(WARN, "add event failed", KP(module), KP(event), KP(name1), K(value1), - KP(name2), K(value2), KP(name3), K(value3), KP(name4), K(value4), - KP(name5), K(value5), K(ret)); - } - return ret; -} - -template -int ObEventHistoryTableOperator::add_event(const char *module, const char *event, - const char *name1, const T1 &value1, const char *name2, const T2 &value2, - const char *name3, const T3 &value3, const char *name4, const T4 &value4) -{ - int ret = common::OB_SUCCESS; - if (!inited_) { - ret = common::OB_NOT_INIT; - SHARE_LOG(WARN, "not init", K(ret)); - } else if (NULL == module || NULL == event || NULL == name1 || NULL == name2 - || NULL == name3 || NULL == name4) { - ret = common::OB_INVALID_ARGUMENT; - SHARE_LOG(WARN, "invalid argument", KP(module), KP(event), KP(name1), KP(name2), - KP(name3), KP(name4), K(ret)); - } else if (OB_FAIL(add_event(module, event, name1, value1, name2, value2, name3, value3, - name4, value4, NULL, "", NULL, "", ""))) { - SHARE_LOG(WARN, "add event failed", KP(module), KP(event), KP(name1), K(value1), - KP(name2), K(value2), KP(name3), K(value3), KP(name4), K(value4), K(ret)); - } - return ret; -} - -template -int ObEventHistoryTableOperator::add_event(const char *module, const char *event, - const char *name1, const T1 &value1, const char *name2, const T2 &value2, - const char *name3, const T3 &value3) -{ - int ret = common::OB_SUCCESS; - if (!inited_) { - ret = common::OB_NOT_INIT; - SHARE_LOG(WARN, "not init", K(ret)); - } else if (NULL == module || NULL == event || NULL == name1 || NULL == name2 - || NULL == name3) { - ret = common::OB_INVALID_ARGUMENT; - SHARE_LOG(WARN, "invalid argument", KP(module), KP(event), KP(name1), KP(name2), - KP(name3), K(ret)); - } else if (OB_FAIL(add_event(module, event, name1, value1, name2, value2, name3, value3, - NULL, "", NULL, "", NULL, "", ""))) { - SHARE_LOG(WARN, "add event failed", KP(module), KP(event), KP(name1), K(value1), - KP(name2), K(value2), KP(name3), K(value3), K(ret)); - } - return ret; -} - -template -int ObEventHistoryTableOperator::add_event(const char *module, const char *event, - const char *name1, const T1 &value1, const char *name2, const T2 &value2) -{ - int ret = common::OB_SUCCESS; - if (!inited_) { - ret = common::OB_NOT_INIT; - SHARE_LOG(WARN, "not init", K(ret)); - } else if (NULL == module || NULL == event || NULL == name1 || NULL == name2) { - ret = common::OB_INVALID_ARGUMENT; - SHARE_LOG(WARN, "invalid argument", KP(module), KP(event), KP(name1), KP(name2), K(ret)); - } else if (OB_FAIL(add_event(module, event, name1, value1, name2, value2, NULL, "", - NULL, "", NULL, "", NULL, "", ""))) { - SHARE_LOG(WARN, "add event failed", KP(module), KP(event), KP(name1), K(value1), - KP(name2), K(value2), K(ret)); - } - return ret; -} - -template -int ObEventHistoryTableOperator::add_event(const char *module, const char *event, - const char *name1, const T1 &value1) -{ - int ret = common::OB_SUCCESS; - if (!inited_) { - ret = common::OB_NOT_INIT; - SHARE_LOG(WARN, "not init", K(ret)); - } else if (NULL == module || NULL == event || NULL == name1) { - ret = common::OB_INVALID_ARGUMENT; - SHARE_LOG(WARN, "invalid argument", KP(module), KP(event), KP(name1), K(ret)); - } else if (OB_FAIL(add_event(module, event, name1, value1, NULL, "", NULL, "", - NULL, "", NULL, "", NULL, "", ""))) { - SHARE_LOG(WARN, "add event failed", KP(module), KP(event), KP(name1), K(value1), K(ret)); - } - return ret; -} - template int ObEventHistoryTableOperator::sync_add_event(const char *module, const char *event, Rest &&...others) { @@ -446,7 +286,7 @@ int ObEventHistoryTableOperator::sync_add_event(const char *module, const char * OB_FAIL(dml.add_column("module", module)) || OB_FAIL(dml.add_column("event", event))) { SHARE_LOG(WARN, "add column failed", K(ret)); - } else if (OB_FAIL(sync_add_event_helper_<0>(dml, std::forward(others)...))) {// recursive call + } else if (OB_FAIL((add_event_helper_<0, false>(dml, std::forward(others)...)))) {// recursive call } else if (common::OB_SUCCESS == ret && self_addr_.is_valid()) { if (is_rootservice_event_history_) { //Add rs_svr_ip, rs_svr_port to the __all_rootservice_event_history table @@ -507,7 +347,7 @@ int ObEventHistoryTableOperator::add_event_with_retry(const char *module, const CLICK_FAIL(dml.add_column("module", module)) || CLICK_FAIL(dml.add_column("event", event))) { SHARE_LOG(WARN, "add column failed", K(ret)); - } else if (CLICK_FAIL(sync_add_event_helper_<0>(dml, std::forward(others)...))) {// recursive call + } else if (CLICK_FAIL((add_event_helper_<0, false>(dml, std::forward(others)...)))) {// recursive call } else if (common::OB_SUCCESS == ret && self_addr_.is_valid()) { if (is_rootservice_event_history_) { //Add rs_svr_ip, rs_svr_port to the __all_rootservice_event_history table @@ -537,30 +377,48 @@ int ObEventHistoryTableOperator::add_event_with_retry(const char *module, const return ret; } // recursive begin -template -int ObEventHistoryTableOperator::sync_add_event_helper_(share::ObDMLSqlSplicer &dml, Name &&name, Value &&value, Rest &&...others) +template +int ObEventHistoryTableOperator::add_event_helper_(share::ObDMLSqlSplicer &dml, Name &&name, Value &&value, Rest &&...others) { int ret = OB_SUCCESS; common::ObSqlString sql; + ValueConverter converter; + #if Truncate + // Truncate can be true only for __all_rootservice_event_history + if (OB_UNLIKELY(OB_ALL_ROOTSERVICE_EVENT_HISTORY_TNAME != event_table_name_)) { + ret = OB_NOT_SUPPORTED; + SHARE_LOG(WARN, "Truncate event only available for __all_rootservice_event_history", + KR(ret), "actual_table", event_table_name_); + } else + #endif if (OB_FAIL(dml.add_column(names[Floor], name))) { SHARE_LOG(WARN, "add column failed", K(ret), K(Floor)); - } else if (OB_FAIL(dml.add_column(values[Floor], value))) { + } else if (OB_FAIL(dml.add_column(values[Floor], converter.convert(value)))) { SHARE_LOG(WARN, "add column failed", K(ret), K(Floor)); - } else if (OB_FAIL(sync_add_event_helper_(dml, std::forward(others)...))) { + } else if (OB_FAIL((add_event_helper_(dml, std::forward(others)...)))){ } return ret; } // recursive end if there is no extra_info -template -int ObEventHistoryTableOperator::sync_add_event_helper_(share::ObDMLSqlSplicer &) +// if not all columns are user-specified, set rest fields empty +template +int ObEventHistoryTableOperator::add_event_helper_(share::ObDMLSqlSplicer &dml) { - return OB_SUCCESS; + int ret = OB_SUCCESS; + if (Floor < 6) { + for (int64_t idx = Floor; OB_SUCCESS == ret && idx < 6; ++idx) { + if (OB_FAIL(dml.add_column(values[idx], ""))) { + SHARE_LOG(WARN, "add column failed", K(ret), K(idx)); + } + } + } + return ret; } // recursive end if there is an extra_info -template -int ObEventHistoryTableOperator::sync_add_event_helper_(share::ObDMLSqlSplicer &dml, Value &&extra_info) +template +int ObEventHistoryTableOperator::add_event_helper_(share::ObDMLSqlSplicer &dml, Value &&extra_info) { static_assert(Floor == 6, "if there is an extra_info column, it must be 13th args in this row, no more, no less"); int ret = OB_SUCCESS;