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

Function create_master_entry_array

db/sqlmaster.c:60–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58int gbl_debug_create_master_entry = 0;
59
60master_entry_t *create_master_entry_array(struct dbtable **dbs, int num_dbs,
61 hash_t *view_hash, int *nents)
62{
63 int tblnum;
64 int tbl_idx;
65 int i;
66 int local_nentries = 0;
67
68 *nents = 0;
69 /* for each table, account for table and all its indices */
70 for (tblnum = 0; tblnum < num_dbs; tblnum++)
71 local_nentries += 1 + dbs[tblnum]->nsqlix;
72
73 if (view_hash) {
74 int view_count;
75 hash_info(view_hash, NULL, NULL, NULL, NULL, &view_count, NULL, NULL);
76 local_nentries += view_count;
77 }
78
79 master_entry_t *new_arr = calloc(local_nentries, sizeof(master_entry_t));
80 if (!new_arr) {
81 logmsg(LOGMSG_ERROR, "%s: MALLOC OOM\n", __func__);
82 return NULL;
83 }
84
85 for (i = 0, tblnum = 0; tblnum < num_dbs; tblnum++) {
86 if (gbl_debug_create_master_entry) {
87 poll(NULL, 0, 10);
88 }
89 master_entry_t *ent = &new_arr[i];
90 struct dbtable *tbl = dbs[tblnum];
91 ent->tblname = strdup(tbl->tablename);
92 ent->isstrdup = 1;
93 ent->ixnum = -1;
94 ent->rootpage = i + RTPAGE_START;
95 ent->entry =
96 create_master_row(dbs, num_dbs, ent->rootpage, tbl->csc2_schema,
97 tblnum, -1, &ent->entry_size);
98 tbl_idx = i;
99 i++;
100
101 for (int ixnum = 0; ixnum < tbl->nix; ixnum++) {
102 ent = &new_arr[i];
103 /* skip indexes that we aren't advertising to sqlite */
104 if (tbl->ixsql[ixnum] == NULL)
105 continue;
106 ent->isstrdup = 0;
107 assert(ent->tblname == NULL);
108 ent->tblname = new_arr[tbl_idx].tblname;
109 ent->ixnum = ixnum; /* comdb2 index number */
110 ent->rootpage = i + RTPAGE_START;
111 ent->entry = create_master_row(dbs, num_dbs, ent->rootpage, NULL,
112 tblnum, ixnum, &ent->entry_size);
113 i++;
114 }
115 }
116
117 if (view_hash) {

Callers 2

create_sqlite_masterFunction · 0.85
sql_syntax_checkFunction · 0.85

Calls 8

hash_infoFunction · 0.85
callocFunction · 0.85
create_master_rowFunction · 0.85
hash_firstFunction · 0.85
hash_nextFunction · 0.85
strdupFunction · 0.70
logmsgFunction · 0.50

Tested by

no test coverage detected