| 1288 | } |
| 1289 | |
| 1290 | void ImpalaServer::GetRuntimeProfile( |
| 1291 | TGetRuntimeProfileResp& return_val, const TGetRuntimeProfileReq& request) { |
| 1292 | TUniqueId session_id; |
| 1293 | TUniqueId secret; |
| 1294 | HS2_RETURN_IF_ERROR(return_val, THandleIdentifierToTUniqueId( |
| 1295 | request.sessionHandle.sessionId, &session_id, &secret), SQLSTATE_GENERAL_ERROR); |
| 1296 | ScopedSessionState session_handle(this); |
| 1297 | shared_ptr<SessionState> session; |
| 1298 | HS2_RETURN_IF_ERROR(return_val, |
| 1299 | session_handle.WithSession( |
| 1300 | session_id, SecretArg::Session(secret), &session), |
| 1301 | SQLSTATE_GENERAL_ERROR); |
| 1302 | if (session == NULL) { |
| 1303 | HS2_RETURN_ERROR(return_val, Substitute("Invalid session id: $0", |
| 1304 | PrintId(session_id)), SQLSTATE_GENERAL_ERROR); |
| 1305 | } |
| 1306 | |
| 1307 | TUniqueId query_id, op_secret; |
| 1308 | HS2_RETURN_IF_ERROR(return_val, THandleIdentifierToTUniqueId( |
| 1309 | request.operationHandle.operationId, &query_id, &op_secret), |
| 1310 | SQLSTATE_GENERAL_ERROR); |
| 1311 | |
| 1312 | VLOG_QUERY << "GetRuntimeProfile(): query_id=" << PrintId(query_id); |
| 1313 | |
| 1314 | // Make query id available to the following HS2_RETURN_IF_ERROR(). |
| 1315 | ScopedThreadContext scoped_tdi(GetThreadDebugInfo(), query_id); |
| 1316 | |
| 1317 | // Set the RuntimeProfileOutput for the retried query (e.g. the second attempt of a |
| 1318 | // query). If the query has been retried this will be the retried profile. If the |
| 1319 | // query has not been retried then all entries will be nullptr. |
| 1320 | RuntimeProfileOutput retried_profile; |
| 1321 | stringstream retried_ss; |
| 1322 | TRuntimeProfileTree retried_thrift_profile; |
| 1323 | rapidjson::Document retried_json_profile(rapidjson::kObjectType); |
| 1324 | retried_profile.string_output = &retried_ss; |
| 1325 | retried_profile.thrift_output = &retried_thrift_profile; |
| 1326 | retried_profile.json_output = &retried_json_profile; |
| 1327 | |
| 1328 | // Set the RuntimeProfileOutput for the original query (e.g. the first attempt of a |
| 1329 | // query). If the query has been retried this will be the original profile (the |
| 1330 | // profile of the original query attempt). If the query has not been retried then |
| 1331 | // this will be the normal runtime profile. |
| 1332 | RuntimeProfileOutput profile; |
| 1333 | stringstream ss; |
| 1334 | TRuntimeProfileTree thrift_profile; |
| 1335 | rapidjson::Document json_profile(rapidjson::kObjectType); |
| 1336 | profile.string_output = &ss; |
| 1337 | profile.thrift_output = &thrift_profile; |
| 1338 | profile.json_output = &json_profile; |
| 1339 | |
| 1340 | // Get the runtime profiles and load them into the given RuntimeProfileOutputs. |
| 1341 | bool was_retried = false; |
| 1342 | HS2_RETURN_IF_ERROR(return_val, |
| 1343 | GetRuntimeProfileOutput(query_id, GetEffectiveUser(*session), request.format, |
| 1344 | &profile, &retried_profile, &was_retried), |
| 1345 | SQLSTATE_GENERAL_ERROR); |
| 1346 | |
| 1347 | // Set the Thrift response in TGetRuntimeProfileResp. If the query was retried, then |