|
23 | 23 | namespace { |
24 | 24 | inline const char *b2s(bool val) { return val ? "1" : "0"; } |
25 | 25 |
|
| 26 | +/* |
| 27 | + mysql.session user is mostly enough, but it lacks the following privileges: |
| 28 | +
|
| 29 | + 1. REPLICATION SLAVE |
| 30 | + 2. REPLICATION CLIENT |
| 31 | + 3. SELECT on mysql.component |
| 32 | + 4. SELECT on performance_schema.replication_group_members |
| 33 | +
|
| 34 | + These privileges are added at server startup in setup_percona_telemetry() |
| 35 | + if Percona telemetry is enabled. |
| 36 | +*/ |
| 37 | +constexpr const char default_command_user_name[] = "mysql.session"; |
| 38 | +constexpr const char default_command_host_name[] = "localhost"; |
| 39 | + |
26 | 40 | namespace JSONKey { |
27 | 41 | const char *pillar_version = "pillar_version"; |
28 | 42 | const char *db_instance_id = "db_instance_id"; |
@@ -120,25 +134,29 @@ bool DataProvider::do_query(const std::string &query, QueryResult *result, |
120 | 134 | } |
121 | 135 | result->clear(); |
122 | 136 |
|
| 137 | + /* command_factory_service_.init() allocates memory for mysql_h |
| 138 | + We need to call close() always. |
| 139 | + Even if init() fails, becaues it doesn't allocate anything, calling close() |
| 140 | + is safe, because internally it checks if provided pointer is valid |
| 141 | + */ |
| 142 | + std::shared_ptr<MYSQL_H> mysql_h_close_guard( |
| 143 | + &mysql_h, [&srv = command_factory_service_](MYSQL_H *ptr) { |
| 144 | + srv.close(*ptr); |
| 145 | + }); |
| 146 | + |
123 | 147 | mysql_service_status_t sstatus = command_factory_service_.init(&mysql_h); |
| 148 | + |
124 | 149 | if (!sstatus) |
125 | 150 | sstatus |= |
126 | 151 | command_options_service_.set(mysql_h, MYSQL_COMMAND_PROTOCOL, nullptr); |
127 | 152 | if (!sstatus) |
128 | | - sstatus |= |
129 | | - command_options_service_.set(mysql_h, MYSQL_COMMAND_USER_NAME, "root"); |
| 153 | + sstatus |= command_options_service_.set(mysql_h, MYSQL_COMMAND_USER_NAME, |
| 154 | + default_command_user_name); |
130 | 155 | if (!sstatus) |
131 | | - sstatus |= |
132 | | - command_options_service_.set(mysql_h, MYSQL_COMMAND_HOST_NAME, nullptr); |
| 156 | + sstatus |= command_options_service_.set(mysql_h, MYSQL_COMMAND_HOST_NAME, |
| 157 | + default_command_host_name); |
133 | 158 | if (!sstatus) sstatus |= command_factory_service_.connect(mysql_h); |
134 | 159 |
|
135 | | - // starting from this point, if the above succeeded we need to close mysql_h. |
136 | | - std::shared_ptr<void> mysql_h_close_guard( |
137 | | - mysql_h, |
138 | | - [&srv = command_factory_service_, do_close = !sstatus](void *ptr) { |
139 | | - if (do_close && ptr) srv.close(static_cast<MYSQL_H>(ptr)); |
140 | | - }); |
141 | | - |
142 | 160 | // if any of the above failed, just exit |
143 | 161 | if (sstatus) { |
144 | 162 | goto err; |
@@ -212,7 +230,7 @@ bool DataProvider::collect_db_instance_id_info(rapidjson::Document *document) { |
212 | 230 | so the SQL query failed. It will recover next time. |
213 | 231 | 2. Some other reason that caused selecting server_id to fail. */ |
214 | 232 | if (id.length() == 0) { |
215 | | - logger_.warning( |
| 233 | + logger_.info( |
216 | 234 | "Collecting db_instance_id failed. It may be caused by server still " |
217 | 235 | "initializing."); |
218 | 236 | return true; |
@@ -346,7 +364,7 @@ bool DataProvider::collect_se_usage_info(rapidjson::Document *document) { |
346 | 364 | QueryResult result; |
347 | 365 | if (do_query("SELECT DISTINCT ENGINE FROM information_schema.tables WHERE " |
348 | 366 | "table_schema NOT IN('mysql', 'information_schema', " |
349 | | - "'performance_schema', 'sys');", |
| 367 | + "'performance_schema', 'sys')", |
350 | 368 | &result)) { |
351 | 369 | return true; |
352 | 370 | } |
|
0 commit comments