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

Function can_execute_sql_query_now

db/sqlinterfaces.c:4656–4749  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4654}
4655
4656static int can_execute_sql_query_now(
4657 struct sqlthdstate *thd,
4658 struct sqlclntstate *clnt,
4659 int *pRuleNo,
4660 int *pbRejected,
4661 int *pbTryAgain
4662){
4663 struct ruleset_item_criteria context = {0};
4664 struct ruleset_result result = {0};
4665 clnt->pPool = NULL; /* NOTE: By default, start with the "default" pool. */
4666 clnt_to_ruleset_item_criteria(clnt, &context);
4667 size_t count = comdb2_evaluate_ruleset(NULL, gbl_ruleset, &context, &result);
4668 comdb2_ruleset_result_to_str(
4669 &result, clnt->work.zRuleRes, sizeof(clnt->work.zRuleRes)
4670 );
4671 if (gbl_verbose_prioritize_queries) {
4672 logmsg(LOGMSG_INFO, "%s: PRE count=%d, sql={%s}, %s\n",
4673 __func__, (int)count, clnt->sql, clnt->work.zRuleRes);
4674 }
4675 *pRuleNo = -1; /* no rule was specifically responsible */
4676 *pbRejected = 0; /* initially, SQL work item is always allowed */
4677 /* BEGIN FAULT INJECTION TEST CODE */
4678 if ((result.action != RULESET_A_REJECT) && /* skip already adverse actions */
4679 (result.action != RULESET_A_REJECT_ALL)) {
4680 if (gbl_random_sql_work_rejected &&
4681 !(rand() % gbl_random_sql_work_rejected)) {
4682 logmsg(LOGMSG_WARN,
4683 "%s: POST forcing random SQL work item {%s} reject\n",
4684 __func__, clnt->sql);
4685 *pbRejected = 1;
4686 *pbTryAgain = 0;
4687 return 0;
4688 } else if (gbl_random_sql_work_delayed &&
4689 !(rand() % gbl_random_sql_work_delayed)) {
4690 logmsg(LOGMSG_WARN,
4691 "%s: POST forcing random SQL work item {%s} delay\n",
4692 __func__, clnt->sql);
4693 return 0;
4694 }
4695 }
4696 /* END FAULT INJECTION TEST CODE */
4697 struct thdpool *pool = get_sql_pool(clnt);
4698 switch (result.action) {
4699 case RULESET_A_NONE: {
4700 /* do nothing */
4701 break;
4702 }
4703 case RULESET_A_REJECT: {
4704 *pRuleNo = result.ruleNo;
4705 *pbRejected = 1;
4706 *pbTryAgain = 1;
4707 return 0;
4708 }
4709 case RULESET_A_REJECT_ALL: {
4710 *pRuleNo = result.ruleNo;
4711 *pbRejected = 1;
4712 *pbTryAgain = 0;
4713 return 0;

Callers 1

Calls 7

comdb2_evaluate_rulesetFunction · 0.85
get_sql_poolFunction · 0.85
get_named_sql_poolFunction · 0.85
thdpool_get_nameFunction · 0.85
logmsgFunction · 0.50

Tested by

no test coverage detected