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

Function luabb_trigger_register

lua/sp.c:400–444  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

398static pthread_mutex_t consumer_sqlthds_mutex = PTHREAD_MUTEX_INITIALIZER;
399
400static int luabb_trigger_register(Lua L, trigger_reg_t *reg, int register_timeoutms)
401{
402 int rc;
403 SP sp = getsp(L);
404 sp->num_instructions = 0;
405 int retry = round(register_timeoutms / 1000.0);
406 if (retry <= 0) {
407 retry = 1;
408 }
409
410 struct thdpool *pool = get_sql_pool(sp->clnt);
411 Pthread_mutex_lock(&consumer_sqlthds_mutex);
412 thdpool_add_waitthd(pool);
413 Pthread_mutex_unlock(&consumer_sqlthds_mutex);
414
415 while ((rc = trigger_register_req(reg)) != CDB2_TRIG_REQ_SUCCESS) {
416 /* trigger_register_req() can take up to 1 second. Tick up immediately
417 after this so that it's guaranteed that the appsock thread observes
418 a good query state for the next heartbeat. */
419 comdb2_sql_tick_no_recover_deadlock();
420 if (register_timeoutms) {
421 if (retry == 0) {
422 luabb_error(L, sp, "trigger:%s registration timeout %dms", reg->spname, register_timeoutms);
423 rc = -2;
424 goto out;
425 }
426 --retry;
427 }
428 if (check_retry_conditions(L, reg, 1) != 0) {
429 rc = luabb_error(L, sp, sp->error);
430 goto out;
431 }
432 if (rc != NET_SEND_FAIL_TIMEOUT) {
433 sleep(1);
434 comdb2_sql_tick_no_recover_deadlock();
435 }
436 }
437
438out:
439 Pthread_mutex_lock(&consumer_sqlthds_mutex);
440 thdpool_remove_waitthd(pool);
441 Pthread_mutex_unlock(&consumer_sqlthds_mutex);
442
443 return rc;
444}
445
446static void luabb_trigger_unregister(Lua L, dbconsumer_t *q)
447{

Callers 2

stop_waitingFunction · 0.85

Calls 7

get_sql_poolFunction · 0.85
thdpool_add_waitthdFunction · 0.85
trigger_register_reqFunction · 0.85
luabb_errorFunction · 0.85
check_retry_conditionsFunction · 0.85
thdpool_remove_waitthdFunction · 0.85

Tested by

no test coverage detected