* Commit a transaction * */
| 363 | * |
| 364 | */ |
| 365 | int 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: |
no test coverage detected