null+****@clear*****
null+****@clear*****
2011年 6月 10日 (金) 00:02:01 JST
Kentoku 2011-06-09 15:02:01 +0000 (Thu, 09 Jun 2011) New Revision: 12cd502dcda735357423085c4cd761429a7d0ab6 Log: fixes #985 add wrapper_open() and wrapper_close() Modified files: ha_mroonga.cc ha_mroonga.h Modified: ha_mroonga.cc (+105 -5) =================================================================== --- ha_mroonga.cc 2011-06-09 10:08:37 +0000 (3a899ba) +++ ha_mroonga.cc 2011-06-09 15:02:01 +0000 (bc706be) @@ -1333,12 +1333,52 @@ int ha_mroonga::create(const char *name, TABLE *table, HA_CREATE_INFO *info) DBUG_RETURN(error); } -int ha_mroonga::open(const char *name, int mode, uint test_if_locked) +int ha_mroonga::wrapper_open(const char *name, int mode, uint test_if_locked) { + int error; MRN_DBUG_ENTER_METHOD(); - thr_lock_init(&thr_lock); - thr_lock_data_init(&thr_lock, &thr_lock_data, NULL); + wrap_key_info = mrn_create_key_info_for_table(share, table, &error); + if (error) + DBUG_RETURN(error); + base_key_info = table->key_info; + + MRN_SET_WRAP_SHARE_KEY(share, table->s); + MRN_SET_WRAP_TABLE_KEY(this, table); + if (!(wrap_handler = + share->hton->create(share->hton, table->s, + current_thd->mem_root))) + { + MRN_SET_BASE_SHARE_KEY(share, table->s); + MRN_SET_BASE_TABLE_KEY(this, table); + if (wrap_key_info) + { + my_free(wrap_key_info, MYF(0)); + wrap_key_info = NULL; + } + base_key_info = NULL; + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + error = wrap_handler->ha_open(table, name, mode, test_if_locked); + MRN_SET_BASE_SHARE_KEY(share, table->s); + MRN_SET_BASE_TABLE_KEY(this, table); + if (error) + { + delete wrap_handler; + wrap_handler = NULL; + if (wrap_key_info) + { + my_free(wrap_key_info, MYF(0)); + wrap_key_info = NULL; + } + base_key_info = NULL; + } + DBUG_RETURN(error); +} + +int ha_mroonga::default_open(const char *name, int mode, uint test_if_locked) +{ + MRN_DBUG_ENTER_METHOD(); /* First, we must check if database is alreadly opened */ char db_name[MRN_MAX_PATH_SIZE]; char db_path[MRN_MAX_PATH_SIZE]; @@ -1442,11 +1482,54 @@ int ha_mroonga::open(const char *name, int mode, uint test_if_locked) DBUG_RETURN(0); } -int ha_mroonga::close() +int ha_mroonga::open(const char *name, int mode, uint test_if_locked) { + int error; MRN_DBUG_ENTER_METHOD(); - thr_lock_delete(&thr_lock); + thr_lock_init(&thr_lock); + thr_lock_data_init(&thr_lock, &thr_lock_data, NULL); + if (!(share = mrn_get_share(name, table, &error))) + DBUG_RETURN(error); + + if (share->wrapper_mode) + { + error = wrapper_open(name, mode, test_if_locked); + } else { + error = default_open(name, mode, test_if_locked); + } + + if (error) + { + mrn_free_share(share); + share = NULL; + } + DBUG_RETURN(error); +} + +int ha_mroonga::wrapper_close() +{ + int error; + MRN_DBUG_ENTER_METHOD(); + MRN_SET_WRAP_SHARE_KEY(share, table->s); + MRN_SET_WRAP_TABLE_KEY(this, table); + error = wrap_handler->close(); + MRN_SET_BASE_SHARE_KEY(share, table->s); + MRN_SET_BASE_TABLE_KEY(this, table); + delete wrap_handler; + wrap_handler = NULL; + if (wrap_key_info) + { + my_free(wrap_key_info, MYF(0)); + wrap_key_info = NULL; + } + base_key_info = NULL; + DBUG_RETURN(error); +} + +int ha_mroonga::default_close() +{ + MRN_DBUG_ENTER_METHOD(); int i; uint n_keys = table->s->keys; uint pkeynr = table->s->primary_key; @@ -1471,6 +1554,23 @@ int ha_mroonga::close() DBUG_RETURN(0); } +int ha_mroonga::close() +{ + int error; + MRN_DBUG_ENTER_METHOD(); + if (share->wrapper_mode) + { + error = wrapper_close(); + } else { + error = default_close(); + } + + mrn_free_share(share); + share = NULL; + thr_lock_delete(&thr_lock); + DBUG_RETURN(0); +} + int ha_mroonga::wrapper_delete_table(const char *name, MRN_SHARE *tmp_share) { int error; Modified: ha_mroonga.h (+5 -0) =================================================================== --- ha_mroonga.h 2011-06-09 10:08:37 +0000 (fc14bf9) +++ ha_mroonga.h 2011-06-09 15:02:01 +0000 (0e23694) @@ -61,6 +61,7 @@ class ha_mroonga: public handler MRN_SHARE *share; KEY *wrap_key_info; KEY *base_key_info; + handler *wrap_handler; grn_ctx *ctx; @@ -210,6 +211,10 @@ private: int wrapper_delete_table(const char *name, MRN_SHARE *tmp_share); int default_delete_table(const char *name, MRN_SHARE *tmp_share, const char *tbl_name); + int wrapper_open(const char *name, int mode, uint test_if_locked); + int default_open(const char *name, int mode, uint test_if_locked); + int wrapper_close(); + int default_close(); }; #ifdef __cplusplus