MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / enqueue_sql_query

Function enqueue_sql_query

db/sqlinterfaces.c:4902–5006  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4900 } while (0)
4901
4902static int enqueue_sql_query(struct sqlclntstate *clnt)
4903{
4904 char msg[1024];
4905 int rc;
4906 int fail_dispatch = 0;
4907 int q_depth_tag_and_sql;
4908
4909 struct thr_handle *self = thrman_self();
4910 if (self) {
4911 if (clnt->exec_lua_thread)
4912 thrman_set_subtype(self, THRSUBTYPE_LUA_SQL);
4913 else
4914 thrman_set_subtype(self, THRSUBTYPE_TOPLEVEL_SQL);
4915 }
4916
4917 bzero(&clnt->osql.timings, sizeof(osqltimings_t));
4918 bzero(&clnt->osql.fdbtimes, sizeof(fdbtimings_t));
4919 clnt->osql.timings.query_received = osql_log_time();
4920
4921 Pthread_mutex_lock(&clnt->wait_mutex);
4922 clnt->deadlock_recovered = 0;
4923
4924 Pthread_mutex_lock(&clnt_lk);
4925 /* Reset clnt->thd: there's no guarantee that this clnt is going to be
4926 dispatched to the same sql thread it previously ran under; Also, that
4927 thread may not even exist any more (eg aged out), causing
4928 reqlog_long_running_clnt() to segfault when reading clnt->thd, which is
4929 alloca'd on the stack by the sql thread */
4930 clnt->thd = NULL;
4931 clnt->done = 0;
4932 if (clnt->statement_timedout)
4933 fail_dispatch = 1;
4934 Pthread_mutex_unlock(&clnt_lk);
4935
4936 clnt->total_sql++;
4937 clnt->sql_since_reset++;
4938
4939 /* keep track so we can display it in stat thr */
4940 clnt->appsock_id = getarchtid();
4941 if (!clnt->sql_ref && clnt->sql) {
4942 clnt->sql_ref = create_string_ref(clnt->sql);
4943 }
4944
4945 Pthread_mutex_unlock(&clnt->wait_mutex);
4946
4947 if (fail_dispatch)
4948 return -1;
4949
4950 struct thdpool *pool = get_sql_pool(clnt);
4951 clnt->enque_timeus = comdb2_time_epochus();
4952
4953 if (gbl_verbose_normalized_queries) {
4954 snprintf(msg, sizeof(msg), "%s {%s} ==> pool {%s} at %llu",
4955 clnt->origin, clnt->sql, (pool != NULL) ? thdpool_get_name(pool) :
4956 "<null>", (long long unsigned int)clnt->enque_timeus);
4957
4958 logmsg(LOGMSG_DEBUG, "%s: %s\n", __func__, msg);
4959 }

Callers 1

dispatch_sql_query_intFunction · 0.85

Calls 15

thrman_selfFunction · 0.85
thrman_set_subtypeFunction · 0.85
osql_log_timeFunction · 0.85
getarchtidFunction · 0.85
get_sql_poolFunction · 0.85
comdb2_time_epochusFunction · 0.85
thdpool_get_nameFunction · 0.85
thd_queue_depthFunction · 0.85
thdpool_get_nbusythdsFunction · 0.85
thdpool_get_maxthdsFunction · 0.85
thdpool_get_queue_depthFunction · 0.85
time_metric_addFunction · 0.85

Tested by

no test coverage detected