Skip to content

Commit 83c7445

Browse files
committed
Metrics requires 'comdb2_tables' & 'comdb2_queues'
Signed-off-by: Mark Hannum <mhannum@bloomberg.net>
1 parent 50a1182 commit 83c7445

26 files changed

+85
-49
lines changed

db/sqlinterfaces.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -745,20 +745,22 @@ void sqlinit(void)
745745
if (sqlite3_initialize()) abort();
746746
}
747747

748-
static char *vtable_lockname(sqlite3 *db, const char *vtable, int *is_system_table)
748+
static const char **vtable_locknames(sqlite3 *db, const char *vtable, int *is_system_table, int *lk_count)
749749
{
750750
*is_system_table = 0;
751751
if (vtable == NULL || db == NULL || db->aModule.count == 0)
752752
return NULL;
753753
struct Module *module;
754-
char *lockname = NULL;
754+
const char **locknames = NULL;
755+
*lk_count = 0;
755756
sqlite3_mutex_enter(db->mutex);
756757
if ((module = sqlite3HashFind(&db->aModule, vtable)) != NULL) {
757758
*is_system_table = 1;
758-
lockname = module->pModule->systable_lock;
759+
*lk_count = module->pModule->systable_lock_count;
760+
locknames = module->pModule->systable_locks;
759761
}
760762
sqlite3_mutex_leave(db->mutex);
761-
return lockname;
763+
return locknames;
762764
}
763765

764766
static int vtable_search(char **vtables, int ntables, const char *table)
@@ -773,12 +775,14 @@ static int vtable_search(char **vtables, int ntables, const char *table)
773775

774776
static void record_locked_vtable(struct sql_authorizer_state *pAuthState, const char *table)
775777
{
776-
int is_system_table;
777-
const char *vtable_lock = vtable_lockname(pAuthState->db, table, &is_system_table);
778-
if (vtable_lock && !vtable_search(pAuthState->vTableLocks, pAuthState->numVTableLocks, vtable_lock)) {
779-
pAuthState->vTableLocks =
780-
(char **)realloc(pAuthState->vTableLocks, sizeof(char *) * (pAuthState->numVTableLocks + 1));
781-
pAuthState->vTableLocks[pAuthState->numVTableLocks++] = strdup(vtable_lock);
778+
int is_system_table, lk_cnt;
779+
const char **vtable_locks = vtable_locknames(pAuthState->db, table, &is_system_table, &lk_cnt);
780+
for (int i = 0; i < lk_cnt; i++) {
781+
if (!vtable_search(pAuthState->vTableLocks, pAuthState->numVTableLocks, vtable_locks[i])) {
782+
pAuthState->vTableLocks =
783+
(char **)realloc(pAuthState->vTableLocks, sizeof(char *) * (pAuthState->numVTableLocks + 1));
784+
pAuthState->vTableLocks[pAuthState->numVTableLocks++] = strdup(vtable_locks[i]);
785+
}
782786
}
783787
if (is_system_table && !pAuthState->hasVTables)
784788
pAuthState->hasVTables = 1;

sqlite/ext/comdb2/api_history.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
sqlite3_module systblApiHistoryModule = {
2929
.access_flag = CDB2_ALLOW_ALL,
30-
.systable_lock = "comdb2_tables",
30+
.systable_lock_count = 1,
31+
.systable_locks = (const char *[]){ "comdb2_tables" }
3132
};
3233

3334
typedef struct systable_api_history {

sqlite/ext/comdb2/auto_analyze_tables.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ extern struct dbenv *thedb;
2727

2828
sqlite3_module systblAutoAnalyzeTablesModule = {
2929
.access_flag = CDB2_ALLOW_USER,
30-
.systable_lock = "comdb2_tables",
30+
.systable_lock_count = 1,
31+
.systable_locks = (const char *[]){ "comdb2_tables" }
3132
};
3233

3334
typedef struct systable_auto_analyze_tables {

sqlite/ext/comdb2/columns.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ static void free_columns(void *data, int n)
159159

160160
sqlite3_module systblColumnsModule = {
161161
.access_flag = CDB2_ALLOW_ALL,
162-
.systable_lock = "comdb2_tables"
162+
.systable_lock_count = 1,
163+
.systable_locks = (const char *[]){ "comdb2_tables" }
163164
};
164165

165166
int systblColumnsInit(sqlite3 *db)

sqlite/ext/comdb2/constraints.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ const sqlite3_module systblConstraintsModule = {
440440
0, /* xRollbackTo */
441441
0, /* xShadowName */
442442
.access_flag = CDB2_ALLOW_ALL,
443-
.systable_lock = "comdb2_tables",
443+
.systable_lock_count = 1,
444+
.systable_locks = (const char *[]){ "comdb2_tables" }
444445
};
445446

446447
#endif /* (!defined(SQLITE_CORE) || defined(SQLITE_BUILDING_FOR_COMDB2)) \

sqlite/ext/comdb2/dbinfo.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030

3131
static sqlite3_module systblDbInfoModule = {
3232
.access_flag = CDB2_ALLOW_ALL,
33-
.systable_lock = "comdb2_tables",
33+
.systable_lock_count = 1,
34+
.systable_locks = (const char *[]){ "comdb2_tables" }
3435
};
3536

3637
int systblDbInfoInit(sqlite3 *db) {

sqlite/ext/comdb2/indexuse.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929

3030
static sqlite3_module systblIndexUsageModule = {
3131
.access_flag = CDB2_ALLOW_USER,
32-
.systable_lock = "comdb2_tables"
32+
.systable_lock_count = 1,
33+
.systable_locks = (const char *[]){ "comdb2_tables" }
3334
};
3435

3536
struct index_usage {

sqlite/ext/comdb2/keycomponents.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ static void free_keycomponents(void *data, int n)
110110

111111
sqlite3_module systblKeyComponentsModule = {
112112
.access_flag = CDB2_ALLOW_ALL,
113-
.systable_lock = "comdb2_tables",
113+
.systable_lock_count = 1,
114+
.systable_locks = (const char *[]){ "comdb2_tables" }
114115
};
115116

116117
int systblKeyComponentsInit(sqlite3 *db)

sqlite/ext/comdb2/keys.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ static void free_keys(void *data, int n)
113113

114114
sqlite3_module systblKeysModule = {
115115
.access_flag = CDB2_ALLOW_ALL,
116-
.systable_lock = "comdb2_tables",
116+
.systable_lock_count = 1,
117+
.systable_locks = (const char *[]){ "comdb2_tables" }
117118
};
118119

119120
int systblKeysInit(sqlite3 *db)

sqlite/ext/comdb2/metrics.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ const sqlite3_module systblMetricsModule = {
197197
0, /* xShadowName */
198198
.access_flag = CDB2_ALLOW_USER,
199199
/* this system table calculates table sizes. grab the 'comdb2_table' lock */
200-
.systable_lock = "comdb2_tables"
200+
.systable_lock_count = 2,
201+
.systable_locks = (const char *[]){ "comdb2_tables", "comdb2_queues" }
201202
};
202203

203204
#endif /* (!defined(SQLITE_CORE) || defined(SQLITE_BUILDING_FOR_COMDB2)) \

0 commit comments

Comments
 (0)