35 #include "innodb_utility.h" 
   54         char*   s = (
char*) malloc(len + 1);
 
   62         return((
char*) memcpy(s, str, len));
 
  103 innodb_config_parse_value_col(
 
  109         static const char*      sep = 
" ;,|\n";
 
  113         char*                   my_str = my_strdupl(str, len);
 
  116         for (column_str = strtok_r(my_str, sep, &last);
 
  118              column_str = strtok_r(NULL, sep, &last)) {
 
  135                 for (column_str = strtok_r(my_str, sep, &last);
 
  137                      column_str = strtok_r(NULL, sep, &last)) {
 
  162 innodb_read_cache_policy(
 
  179                                MCI_CFG_CACHE_POLICIES, NULL, ib_trx,
 
  182         if (err != DB_SUCCESS) {
 
  183                 fprintf(stderr, 
" InnoDB_Memcached: Cannot open config table" 
  184                                 "'%s' in database '%s'. Error %d\n",
 
  185                         MCI_CFG_CACHE_POLICIES, MCI_CFG_DB_NAME,
 
  197         if (err != DB_SUCCESS) {
 
  198                 fprintf(stderr, 
" InnoDB_Memcached: failed to locate entry in" 
  199                                 " config table '%s' in database '%s' \n",
 
  200                         MCI_CFG_CACHE_POLICIES, MCI_CFG_DB_NAME);
 
  233                         fprintf(stderr, 
" InnoDB_Memcached: Invalid Cache" 
  234                                         " Policy %d. Reset to innodb_only\n",
 
  269         return(err == DB_SUCCESS || err == DB_END_OF_INDEX);
 
  278 innodb_read_config_option(
 
  291         int                     current_option = -1;
 
  295                                MCI_CFG_CONFIG_OPTIONS, NULL, ib_trx,
 
  298         if (err != DB_SUCCESS) {
 
  299                 fprintf(stderr, 
" InnoDB_Memcached: Cannot open config table" 
  300                                 "'%s' in database '%s'\n",
 
  301                         MCI_CFG_CONFIG_OPTIONS, MCI_CFG_DB_NAME);
 
  310         if (err != DB_SUCCESS) {
 
  311                 fprintf(stderr, 
" InnoDB_Memcached: failed to locate entry in" 
  312                                 " config table '%s' in database '%s' \n",
 
  313                         MCI_CFG_CONFIG_OPTIONS, MCI_CFG_DB_NAME);
 
  322                 if (err != DB_SUCCESS) {
 
  323                         fprintf(stderr, 
" InnoDB_Memcached: failed to read" 
  324                                         " row from config table '%s' in" 
  326                                 MCI_CFG_CONFIG_OPTIONS, MCI_CFG_DB_NAME);
 
  353                                                 config_option_names[j].
name)
 
  356                                                         config_option_names[j].
id;
 
  371                                 memcpy(item->
options[current_option].value,
 
  375                                 item->
options[current_option].value[max_len]
 
  378                                 item->
options[current_option].value_len
 
  383                 err = ib_cb_cursor_next(crsr);
 
  385         } 
while (err == DB_SUCCESS);
 
  399         return(err == DB_SUCCESS || err == DB_END_OF_INDEX);
 
  410 innodb_config_add_item(
 
  428                 fprintf(stderr, 
" InnoDB_Memcached: config table '%s' in" 
  429                                 " database '%s' has only %d column(s)," 
  430                                 " server is expecting %d columns\n",
 
  431                         MCI_CFG_CONTAINER_TABLE, MCI_CFG_DB_NAME,
 
  437         item = malloc(
sizeof(*item));
 
  439         memset(item, 0, 
sizeof(*item));
 
  447                         fprintf(stderr, 
" InnoDB_Memcached: column %d in" 
  448                                         " the entry for config table '%s' in" 
  449                                         " database '%s' has an invalid" 
  451                                 i, MCI_CFG_CONTAINER_TABLE, MCI_CFG_DB_NAME);
 
  465                         innodb_config_parse_value_col(
 
  474                 fprintf(stderr, 
" InnoDB_Memcached: There must be a unique" 
  475                                 " index on memcached table's key column\n");
 
  492         if (err != DB_SUCCESS && item) {
 
  518                                MCI_CFG_CONTAINER_TABLE, NULL, ib_trx,
 
  521         if (err != DB_SUCCESS) {
 
  522                 fprintf(stderr, 
" InnoDB_Memcached: Please create config table" 
  523                                 "'%s' in database '%s' by running" 
  524                                 " 'scripts/innodb_config.sql. error %d'\n",
 
  525                         MCI_CFG_CONTAINER_TABLE, MCI_CFG_DB_NAME,
 
  536         while (err == DB_SUCCESS) {
 
  541                 if (err != DB_SUCCESS) {
 
  542                         fprintf(stderr, 
" InnoDB_Memcached: failed to read row" 
  543                                         " from config table '%s' in database" 
  545                                 MCI_CFG_CONTAINER_TABLE, MCI_CFG_DB_NAME);
 
  550                 item = innodb_config_add_item(tpl, meta_hash);
 
  557                 if (default_item == NULL
 
  563                 err = ib_cb_cursor_next(crsr);
 
  566         if (err == DB_END_OF_INDEX) {
 
  570         if (err != DB_SUCCESS) {
 
  571                 fprintf(stderr, 
" InnoDB_Memcached: failed to locate entry in" 
  572                                 " config table '%s' in database '%s' \n",
 
  573                         MCI_CFG_CONTAINER_TABLE, MCI_CFG_DB_NAME);
 
  589         return(default_item);
 
  598 innodb_config_container(
 
  621                 fold = ut_fold_string(name);
 
  634                                MCI_CFG_CONTAINER_TABLE, NULL, ib_trx,
 
  637         if (err != DB_SUCCESS) {
 
  638                 fprintf(stderr, 
" InnoDB_Memcached: Please create config table" 
  639                                 "'%s' in database '%s' by running" 
  640                                 " 'scripts/innodb_config.sql. error %d'\n",
 
  641                         MCI_CFG_CONTAINER_TABLE, MCI_CFG_DB_NAME,
 
  654                 tpl = ib_cb_search_tuple_create(crsr);
 
  656                 err = ib_cb_col_set_value(tpl, 0, name, name_len, 
true);
 
  659                 err = ib_cb_moveto(crsr, tpl, 
IB_CUR_GE);
 
  662         if (err != DB_SUCCESS) {
 
  663                 fprintf(stderr, 
" InnoDB_Memcached: failed to locate entry in" 
  664                                 " config table '%s' in database '%s' \n",
 
  665                         MCI_CFG_CONTAINER_TABLE, MCI_CFG_DB_NAME);
 
  674                 read_tpl = ib_cb_read_tuple_create(crsr);
 
  676                 err = ib_cb_read_row(crsr, read_tpl);
 
  679         if (err != DB_SUCCESS) {
 
  680                 fprintf(stderr, 
" InnoDB_Memcached: failed to read row from" 
  681                                 " config table '%s' in database '%s' \n",
 
  682                         MCI_CFG_CONTAINER_TABLE, MCI_CFG_DB_NAME);
 
  689         if (n_cols < CONTAINER_NUM_COLS) {
 
  690                 fprintf(stderr, 
" InnoDB_Memcached: config table '%s' in" 
  691                                 " database '%s' has only %d column(s)," 
  692                                 " server is expecting %d columns\n",
 
  693                         MCI_CFG_CONTAINER_TABLE, MCI_CFG_DB_NAME,
 
  694                         n_cols, CONTAINER_NUM_COLS);
 
  699         item = malloc(
sizeof(*item));
 
  700         memset(item, 0, 
sizeof(*item));
 
  708                         fprintf(stderr, 
" InnoDB_Memcached: column %d in" 
  709                                         " the entry for config table '%s' in" 
  710                                         " database '%s' has an invalid" 
  712                                 i, MCI_CFG_CONTAINER_TABLE, MCI_CFG_DB_NAME);
 
  728                         innodb_config_parse_value_col(
 
  737                 fprintf(stderr, 
" InnoDB_Memcached: There must be a unique" 
  738                                 " index on memcached table's key column\n");
 
  744                                                 read_tpl, i), data_len);
 
  762         if (err != DB_SUCCESS) {
 
  782 innodb_config_value_col_verify(
 
  799         sprintf(table_name, 
"%s\%s", dbname, tname);
 
  801         snprintf(table_name, 
sizeof(table_name), 
"%s/%s", dbname, tname);
 
  816                                         " InnoDB_Memcached: the value" 
  817                                         " column %s in table %s" 
  818                                         " should be INTEGER, CHAR or" 
  842                                                 " InnoDB_Memcached: the value" 
  843                                                 " column %s in table %s" 
  844                                                 " should be INTEGER, CHAR or" 
  888         bool            is_key_col = 
false;
 
  889         bool            is_value_col = 
false;
 
  890         bool            is_flag_col = 
false;
 
  891         bool            is_cas_col = 
false;
 
  892         bool            is_exp_col = 
false;
 
  894         ib_id_u64_t     index_id;
 
  921         sprintf(table_name, 
"%s\%s", dbname, tname);
 
  923         snprintf(table_name, 
sizeof(table_name), 
"%s/%s", dbname, tname);
 
  929         for (i = 0; i < n_cols; i++) {
 
  935                 result = innodb_config_value_col_verify(
 
  936                         name, info, &col_meta, i, col_verify);
 
  938                 if (result == DB_SUCCESS) {
 
  954                                         " InnoDB_Memcached: the key" 
  955                                         " column %s in table %s should" 
  956                                         " be INTEGER, CHAR or VARCHAR.\n",
 
  967                                 fprintf(stderr, 
" InnoDB_Memcached: the flag" 
  968                                                 " column %s in table %s should" 
  978                 } 
else if (strcmp(name, cinfo[
CONTAINER_CAS].col_name) == 0) {
 
  981                                 fprintf(stderr, 
" InnoDB_Memcached: the cas" 
  982                                                 " column %s in table %s should" 
  992                 } 
else if (strcmp(name, cinfo[
CONTAINER_EXP].col_name) == 0) {
 
  995                                 fprintf(stderr, 
" InnoDB_Memcached: the expire" 
  996                                                 " column %s in table %s should" 
 1010         if (!is_key_col || !is_value_col) {
 
 1011                 fprintf(stderr, 
" InnoDB_Memcached: failed to locate key" 
 1012                                 " column or value column in table" 
 1013                                 " as specified by config table \n");
 
 1022                 col_check = (runtime && col_verify)
 
 1027                         if (col_check[i].field_id < 0) {
 
 1028                                 fprintf(stderr, 
" InnoDB_Memcached: failed to" 
 1029                                                 " locate value column %s" 
 1030                                                 " as specified by config" 
 1040                 fprintf(stderr, 
" InnoDB_Memcached: failed to locate flag" 
 1041                                 " column as specified by config table \n");
 
 1047                 fprintf(stderr, 
" InnoDB_Memcached: failed to locate cas" 
 1048                                 " column as specified by config table \n");
 
 1054                 fprintf(stderr, 
" InnoDB_Memcached: failed to locate exp" 
 1055                                 " column as specified by config table \n");
 
 1062                                                &idx_crsr, &index_type,
 
 1067         } 
else if (!idx_crsr || !(index_type & 
IB_UNIQUE)) {
 
 1068                 fprintf(stderr, 
" InnoDB_Memcached: Index on key column" 
 1069                                 " must be a Unique index\n");
 
 1079                 if (index_type & IB_CLUSTERED) {
 
 1082                         idx_tpl = ib_cb_search_tuple_create(idx_crsr);
 
 1085                 n_cols = ib_cb_get_n_user_cols(idx_tpl);
 
 1087                 name = ib_cb_get_idx_field_name(idx_crsr, 0);
 
 1090                         fprintf(stderr, 
" InnoDB_Memcached: Index used" 
 1091                                         " must be on key column only\n");
 
 1095                 if (!(index_type & IB_CLUSTERED) && n_cols > 1) {
 
 1096                         fprintf(stderr, 
" InnoDB_Memcached: Index used" 
 1097                                         " must be on key column only\n");
 
 1106         if (runtime && col_verify) {
 
 1139         sprintf(table_name, 
"%s\%s", dbname, name);
 
 1141         snprintf(table_name, 
sizeof(table_name), 
"%s/%s", dbname, name);
 
 1147         if (err != DB_SUCCESS) {
 
 1148                 fprintf(stderr, 
" InnoDB_Memcached: failed to open table" 
 1149                                 " '%s' \n", table_name);
 
 1160         return(err == DB_SUCCESS);
 
 1184         if (*meta_hash == NULL) {
 
 1185                 *meta_hash = hash_create(100);
 
 1193                 fold = ut_fold_string(name);
 
 1203                 item = innodb_config_container(name, name_len, *meta_hash);
 
 1212         success = innodb_read_cache_policy(item);
 
 1218         success = innodb_read_config_option(item);