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

Function fdb_svc_trans_commit

db/fdb_bend_sql.c:365–459  ·  view source on GitHub ↗

* Commit a transaction * */

Source from the content-addressed store, hash-verified

363 *
364 */
365int fdb_svc_trans_commit(char *tid, enum transaction_level lvl,
366 struct sqlclntstate *clnt, int seq)
367{
368 int rc = 0, irc = 0;
369 int bdberr = 0;
370 uuidstr_t us;
371 comdb2uuidstr((unsigned char*)tid, us);
372
373 /* we have to wait for any potential cursor to go away */
374 Pthread_mutex_lock(&clnt->dtran_mtx);
375
376 /* we need to wait for not yet arrived cursors, before we wait for them
377 to finish!!!
378 */
379 fdb_sequence_request(clnt, clnt->dbtran.dtran->fdb_trans.top, seq);
380
381 while (clnt->dbtran.dtran->fdb_trans.top->cursors.top != NULL) {
382 Pthread_mutex_unlock(&clnt->dtran_mtx);
383 poll(NULL, 0, 10);
384 Pthread_mutex_lock(&clnt->dtran_mtx);
385 }
386 Pthread_mutex_unlock(&clnt->dtran_mtx);
387
388 if (clnt->dbtran.mode == TRANLEVEL_RECOM ||
389 clnt->dbtran.mode == TRANLEVEL_SNAPISOL ||
390 clnt->dbtran.mode == TRANLEVEL_SERIAL ||
391 clnt->dbtran.mode == TRANLEVEL_SOSQL) {
392 osql_shadtbl_begin_query(thedb->bdb_env, clnt);
393 }
394
395 switch (clnt->dbtran.mode) {
396 case TRANLEVEL_RECOM: {
397 /* here we handle the communication with bp */
398 rc = recom_commit(clnt, NULL, clnt->tzname, 1);
399 /* if a transaction exists
400 (it doesn't for empty begin/commit */
401 if (clnt->dbtran.shadow_tran) {
402 if (rc == SQLITE_OK) {
403 irc = trans_commit_shadow(clnt->dbtran.shadow_tran, &bdberr);
404 } else {
405 if (rc == SQLITE_ABORT) {
406 /* convert this to user code */
407 rc = blockproc2sql_error(clnt->osql.xerr.errval, __func__, __LINE__);
408 }
409 irc = trans_abort_shadow((void **)&clnt->dbtran.shadow_tran,
410 &bdberr);
411 }
412 if (irc) {
413 logmsg(LOGMSG_ERROR, "%s: failed %s rc=%d bdberr=%d\n", __func__,
414 (rc == SQLITE_OK) ? "commit" : "abort", irc, bdberr);
415 }
416 clnt->dbtran.shadow_tran = NULL;
417 }
418 }
419
420 break;
421
422 case TRANLEVEL_SOSQL:

Callers 1

fdb_bend_trans_commitFunction · 0.85

Calls 12

comdb2uuidstrFunction · 0.85
fdb_sequence_requestFunction · 0.85
osql_shadtbl_begin_queryFunction · 0.85
recom_commitFunction · 0.85
trans_commit_shadowFunction · 0.85
blockproc2sql_errorFunction · 0.85
trans_abort_shadowFunction · 0.85
osql_sock_commitFunction · 0.85
tran2reqFunction · 0.85
osql_shadtbl_done_queryFunction · 0.85
osql_unregister_sqlthrFunction · 0.85
logmsgFunction · 0.50

Tested by

no test coverage detected