Configure the timeout value for the transaction lifetime.
If the transaction runs longer than this time, the transaction may throw DatabaseException.
This is the question that where does the transaction lifetime begin, and where is the end?
Code:
/* Begin our transaction. */
ret = envp->txn_begin(envp, NULL, &txn, 0);
//write transaction timeout 5 second
ret = txn->set_timeout(txn, 5000000, DB_SET_TXN_TIMEOUT);
for (j = 0; j < 10; j++) {
... ... ... ...
/* Perform the database put. */
switch (ret = dbp->put(dbp, txn, &key, &value, 0)) {
case 0:
break;
case DB_KEYEXIST:
printf("Got keyexists.\n");
break;
case DB_LOCK_DEADLOCK:
(void)txn->abort(txn);
if (retry_count < max_retries) {
retry_count++;
goto retry;
}
return (EXIT_FAILURE);
default:
envp->err(envp, ret, "db put failed");
ret = txn->abort(txn);
if (ret != 0)
envp->err(envp, ret, "txn abort failed");
return (EXIT_FAILURE);
} /** End case statement **/
} /** End for loop **/
ret = txn->commit(txn, 0);