|
41 | 41 | #include <sbuf2.h> |
42 | 42 | #include <bdb_api.h> |
43 | 43 | #include <bdb_int.h> |
| 44 | +#include <bdbglue.h> |
44 | 45 |
|
45 | 46 | #include "comdb2.h" |
46 | 47 | #include "types.h" |
@@ -183,6 +184,7 @@ int gbl_dump_history_on_too_many_verify_errors = 0; |
183 | 184 | int gbl_thdpool_queue_only = 0; |
184 | 185 | int gbl_random_sql_work_delayed = 0; |
185 | 186 | int gbl_random_sql_work_rejected = 0; |
| 187 | +int gbl_sleep_5s_after_caching_table_versions = 0; |
186 | 188 |
|
187 | 189 | int gbl_eventlog_fullhintsql = 1; |
188 | 190 |
|
@@ -1730,41 +1732,51 @@ int cache_table_versions(struct sqlclntstate *clnt) |
1730 | 1732 | return 0; |
1731 | 1733 | } |
1732 | 1734 |
|
1733 | | -int populate_modsnap_state(struct sqlclntstate *clnt) |
| 1735 | +static int populate_modsnap_state(struct sqlclntstate *clnt) |
1734 | 1736 | { |
| 1737 | + assert_no_schema_lk(); |
| 1738 | + |
| 1739 | + int rc = 0; |
1735 | 1740 | struct dbtable *db = &thedb->static_table; |
1736 | 1741 | assert(db->handle); |
1737 | 1742 |
|
| 1743 | + bdb_state_type *const bdb_state = thedb->bdb_env; |
| 1744 | + BDB_READLOCK(__func__); |
| 1745 | + rdlock_schema_lk(); |
| 1746 | + |
1738 | 1747 | if (clnt->is_hasql_retry) { |
1739 | 1748 | get_snapshot(clnt, (int *)&clnt->modsnap_start_lsn_file, (int *)&clnt->modsnap_start_lsn_offset); |
1740 | 1749 | } |
1741 | 1750 |
|
1742 | | - rdlock_schema_lk(); |
1743 | | - if (bdb_get_modsnap_start_state(db->handle, thedb->bdb_attr, clnt->is_hasql_retry, clnt->snapshot, |
1744 | | - &clnt->modsnap_start_lsn_file, &clnt->modsnap_start_lsn_offset, |
1745 | | - &clnt->last_checkpoint_lsn_file, &clnt->last_checkpoint_lsn_offset)) { |
1746 | | - unlock_schema_lk(); |
| 1751 | + rc = bdb_get_modsnap_start_state(db->handle, thedb->bdb_attr, clnt->is_hasql_retry, clnt->snapshot, |
| 1752 | + &clnt->modsnap_start_lsn_file, &clnt->modsnap_start_lsn_offset, |
| 1753 | + &clnt->last_checkpoint_lsn_file, &clnt->last_checkpoint_lsn_offset); |
| 1754 | + if (rc) { |
1747 | 1755 | logmsg(LOGMSG_ERROR, "%s: Failed to get modsnap txn start state\n", __func__); |
1748 | | - return 1; |
| 1756 | + goto done; |
1749 | 1757 | } |
1750 | 1758 |
|
1751 | 1759 | // TODO: Refactor cache_table_versions to not take in a clnt and then call it within bdb_get_modsnap_start_state |
1752 | 1760 | // so that we're holding the schema lock over less code. |
1753 | | - if (cache_table_versions(clnt)) { |
1754 | | - unlock_schema_lk(); |
| 1761 | + rc = cache_table_versions(clnt); |
| 1762 | + if (rc) { |
1755 | 1763 | logmsg(LOGMSG_ERROR, "%s: Failed to cache table versions\n", __func__); |
1756 | | - return 1; |
| 1764 | + goto done; |
1757 | 1765 | } |
1758 | | - unlock_schema_lk(); |
1759 | 1766 |
|
1760 | | - if (bdb_register_modsnap(db->handle, clnt->modsnap_start_lsn_file, clnt->modsnap_start_lsn_offset, |
1761 | | - clnt->last_checkpoint_lsn_file, clnt->last_checkpoint_lsn_offset, |
1762 | | - &clnt->modsnap_registration)) { |
| 1767 | + rc = bdb_register_modsnap(db->handle, clnt->modsnap_start_lsn_file, clnt->modsnap_start_lsn_offset, |
| 1768 | + clnt->last_checkpoint_lsn_file, clnt->last_checkpoint_lsn_offset, |
| 1769 | + &clnt->modsnap_registration); |
| 1770 | + if (rc) { |
1763 | 1771 | logmsg(LOGMSG_ERROR, "%s: Failed to register modsnap txn\n", __func__); |
1764 | | - return 1; |
| 1772 | + goto done; |
1765 | 1773 | } |
1766 | 1774 |
|
1767 | 1775 | clnt->modsnap_in_progress = 1; |
| 1776 | + |
| 1777 | +done: |
| 1778 | + unlock_schema_lk(); |
| 1779 | + BDB_RELLOCK(); |
1768 | 1780 | return 0; |
1769 | 1781 | } |
1770 | 1782 |
|
@@ -3355,6 +3367,12 @@ int get_prepared_stmt(struct sqlthdstate *thd, struct sqlclntstate *clnt, |
3355 | 3367 | /* sc-thread holds schema-lk in verify_dbstore */ |
3356 | 3368 | if (!clnt->verify_dbstore) { |
3357 | 3369 | curtran_assert_nolocks(); |
| 3370 | + if (clnt->dbtran.mode == TRANLEVEL_MODSNAP && !clnt->modsnap_in_progress && populate_modsnap_state(clnt)) { |
| 3371 | + return SQLITE_INTERNAL; |
| 3372 | + } |
| 3373 | + if (gbl_sleep_5s_after_caching_table_versions) { |
| 3374 | + sleep(5); |
| 3375 | + } |
3358 | 3376 | rdlock_schema_lk(); |
3359 | 3377 | } |
3360 | 3378 | int rc = get_prepared_stmt_int(thd, clnt, rec, err, |
|
0 commit comments