92
92
extern size_t table_def_size;
94
/*****************************************************************************
95
Functions to handle table definition cach (TableShare)
96
*****************************************************************************/
99
Mark that we are not using table share anymore.
106
If ref_count goes to zero and (we have done a refresh or if we have
107
already too many open table shares) then delete the definition.
110
void TableShare::release(TableShare *share)
112
bool to_be_deleted= false;
113
safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle);
116
if (!--share->ref_count)
124
definition::Cache::singleton().erase(share->getCacheKey());
128
void TableShare::release(TableShare::shared_ptr &share)
130
bool to_be_deleted= false;
131
safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle);
134
if (!--share->ref_count)
142
definition::Cache::singleton().erase(share->getCacheKey());
146
void TableShare::release(const TableIdentifier &identifier)
148
TableShare::shared_ptr share= definition::Cache::singleton().find(identifier.getKey());
151
share->version= 0; // Mark for delete
152
if (share->ref_count == 0)
154
definition::Cache::singleton().erase(identifier.getKey());
160
static TableShare::shared_ptr foundTableShare(TableShare::shared_ptr share)
163
We found an existing table definition. Return it if we didn't get
164
an error when reading the table definition from file.
167
/* We must do a lock to ensure that the structure is initialized */
170
/* Table definition contained an error */
171
share->open_table_error(share->error, share->open_errno, share->errarg);
173
return TableShare::shared_ptr();
176
share->incrementTableCount();
182
Get TableShare for a table.
185
session Thread handle
186
table_list Table that should be opened
188
key_length Length of key
189
error out: Error code from open_table_def()
192
Get a table definition from the table definition cache.
193
If it doesn't exist, create a new from the table definition file.
196
We must have wrlock on table::Cache::singleton().mutex() when we come here
197
(To be changed later)
204
TableShare::shared_ptr TableShare::getShareCreate(Session *session,
205
const TableIdentifier &identifier,
208
TableShare::shared_ptr share;
212
/* Read table definition from cache */
213
if ((share= definition::Cache::singleton().find(identifier.getKey())))
214
return foundTableShare(share);
216
share.reset(new TableShare(message::Table::STANDARD, identifier));
218
if (share->open_table_def(*session, identifier))
220
in_error= share->error;
222
return TableShare::shared_ptr();
224
share->ref_count++; // Mark in use
226
plugin::EventObserver::registerTableEvents(*share);
228
bool ret= definition::Cache::singleton().insert(identifier.getKey(), share);
231
return TableShare::shared_ptr();
236
95
static enum_field_types proto_field_type_to_drizzle_type(const message::Table::Field &field)