@@ -26,7 +26,9 @@ Created 03/15/2011 Jimmy Yang
26
26
#define innodb_config_h
27
27
28
28
#include "api0api.h"
29
+ #include "innodb_utility.h"
29
30
31
+ typedef void * hash_node_t ;
30
32
31
33
/* Database name and table name for our metadata "system" tables for
32
34
InnoDB memcache. The table names are the same as those for the
@@ -52,7 +54,7 @@ There are 3 "system tables":
52
54
/** structure describes each column's basic info (name, field_id etc.) */
53
55
typedef struct meta_column {
54
56
char * col_name ; /*!< column name */
55
- int col_name_len ; /*!< column name length */
57
+ size_t col_name_len ; /*!< column name length */
56
58
int field_id ; /*!< column field id in
57
59
the table */
58
60
ib_col_meta_t col_meta ; /*!< column meta info */
@@ -138,6 +140,66 @@ typedef enum meta_cache_opt {
138
140
META_CACHE_NUM_OPT /*!< Number of options */
139
141
} meta_cache_opt_t ;
140
142
143
+ /** The "names" in the "config_option" table to identify possible
144
+ config options. Both are optional.
145
+ "COLUMN_SEPARATOR" is the delimiter that separates multiple columns and
146
+ "TABLE_MAP_SEPARATOR" is the delimiter that separates table map name
147
+ and key value */
148
+ #define COLUMN_SEPARATOR "separator"
149
+ #define TABLE_MAP_SEPARATOR "table_map_delimiter"
150
+
151
+ /* list of configure options we support */
152
+ typedef enum option_id {
153
+ OPTION_ID_COL_SEP , /*!< ID for character(s) separating
154
+ multiple column mapping */
155
+ OPTION_ID_TBL_MAP_SEP , /*!< ID for character(s) separating
156
+ table map name and key */
157
+ OPTION_ID_NUM_OPTIONS /*!< number of options */
158
+ } option_id_t ;
159
+
160
+ /** Maximum delimiter length */
161
+ #define MAX_DELIMITER_LEN 32
162
+
163
+ typedef struct option_value {
164
+ char value [MAX_DELIMITER_LEN + 1 ];
165
+ /* option value */
166
+ int value_len ; /* value length */
167
+ } option_value_t ;
168
+
169
+ /** structure to define some default "config_option" option settings */
170
+ typedef struct option {
171
+ option_id_t id ; /*!< option id as in enum option_id */
172
+ const char * name ; /*!< option name for above option ID,
173
+ currently they can be "COLUMN_SEPARATOR"
174
+ and "TABLE_MAP_SEPARATOR" */
175
+ option_value_t default_value ; /*!< default value */
176
+ } option_t ;
177
+
178
+ /** Configure options enum IDs, their "names" and their default value */
179
+ static option_t config_option_names [] =
180
+ {
181
+ {OPTION_ID_COL_SEP , COLUMN_SEPARATOR , {"|" , 1 }},
182
+ {OPTION_ID_TBL_MAP_SEP , TABLE_MAP_SEPARATOR , {"." , 1 }}
183
+ };
184
+
185
+ /** Get configure option value. If the value is not configured by
186
+ user, obtain its default value from "config_option_names"
187
+ @param meta_info metadata structure contains configure options
188
+ @param option option whose value to get
189
+ @param val value to fetch
190
+ @param val_len value length */
191
+ #define GET_OPTION (meta_info , option , val , val_len ) \
192
+ do { \
193
+ val_len = meta_info->options[option].value_len; \
194
+ \
195
+ if (val_len == 0) { \
196
+ val = config_option_names[option].default_value.value; \
197
+ val_len = config_option_names[option].default_value.value_len;\
198
+ } else { \
199
+ val = meta_info->options[option].value; \
200
+ } \
201
+ } while (0)
202
+
141
203
/** In memory structure contains most necessary metadata info
142
204
to configure an InnoDB Memcached engine */
143
205
typedef struct meta_cfg_info {
@@ -150,27 +212,34 @@ typedef struct meta_cfg_info {
150
212
bool flag_enabled ; /*!< whether flag is enabled */
151
213
bool cas_enabled ; /*!< whether cas is enabled */
152
214
bool exp_enabled ; /*!< whether exp is enabled */
153
- char * separator ; /*!< separator that separates
154
- incoming "value" string for
155
- multiple columns */
156
- int sep_len ; /*!< separator length */
215
+ option_value_t options [OPTION_ID_NUM_OPTIONS ];
216
+ /*!< configure options, mostly
217
+ are configured delimiters */
157
218
meta_cache_opt_t set_option ; /*!< cache option for "set" */
158
219
meta_cache_opt_t get_option ; /*!< cache option for "get" */
159
220
meta_cache_opt_t del_option ; /*!< cache option for
160
221
"delete" */
161
222
meta_cache_opt_t flush_option ; /*!< cache option for
162
223
"delete" */
224
+ hash_node_t name_hash ; /*!< name hash chain node */
163
225
} meta_cfg_info_t ;
164
226
227
+
165
228
/**********************************************************************/ /**
166
229
This function opens the default configuration table, and find the
167
230
table and column info that used for InnoDB Memcached, and set up
168
- InnoDB Memcached's meta_cfg_info_t structure
169
- @return true if everything works out fine */
170
- bool
231
+ InnoDB Memcached's meta_cfg_info_t structure. If the "name" parameter
232
+ is not NULL, it will find the specified setting in the "container" table.
233
+ If "name" field is NULL, it will then look for setting with the name of
234
+ "default". Otherwise, it returns the setting corresponding to the
235
+ first row of the configure table.
236
+ @return meta_cfg_info_t* structure if configure option found, otherwise NULL */
237
+ meta_cfg_info_t *
171
238
innodb_config (
172
239
/*==========*/
173
- meta_cfg_info_t * item ); /*!< out: meta info structure */
240
+ const char * name , /*!< in: config option name */
241
+ size_t name_len , /*!< in: option name length */
242
+ hash_table_t * * meta_hash ); /*!< in: engine hash table */
174
243
175
244
/**********************************************************************/ /**
176
245
This function verifies the table configuration information, and fills
@@ -189,4 +258,13 @@ innodb_config_free(
189
258
meta_cfg_info_t * item ); /*!< in/own: meta info
190
259
structure */
191
260
261
+ /**********************************************************************/ /**
262
+ This function opens the "containers" table, reads in all rows
263
+ and instantiates the metadata hash table.
264
+ @return the default configuration setting (whose mapping name is "default") */
265
+ meta_cfg_info_t *
266
+ innodb_config_meta_hash_init (
267
+ /*=========================*/
268
+ hash_table_t * meta_hash ); /*!< in/out: InnoDB Memcached
269
+ engine */
192
270
#endif
0 commit comments