Commit 2481db06 authored by Sergei Golubchik's avatar Sergei Golubchik

move writing of the frm into init_from_binary_frm_image()

parent 07b25239
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "sql_select.h" #include "sql_select.h"
#include "sql_derived.h" #include "sql_derived.h"
#include "sql_statistics.h" #include "sql_statistics.h"
#include "discover.h"
#include "mdl.h" // MDL_wait_for_graph_visitor #include "mdl.h" // MDL_wait_for_graph_visitor
/* INFORMATION_SCHEMA name */ /* INFORMATION_SCHEMA name */
...@@ -613,7 +614,6 @@ enum open_frm_error open_table_def(THD *thd, TABLE_SHARE *share, uint flags) ...@@ -613,7 +614,6 @@ enum open_frm_error open_table_def(THD *thd, TABLE_SHARE *share, uint flags)
uchar *buf; uchar *buf;
uchar head[64]; uchar head[64];
char path[FN_REFLEN]; char path[FN_REFLEN];
MEM_ROOT **root_ptr, *old_root;
DBUG_ENTER("open_table_def"); DBUG_ENTER("open_table_def");
DBUG_PRINT("enter", ("table: '%s'.'%s' path: '%s'", share->db.str, DBUG_PRINT("enter", ("table: '%s'.'%s' path: '%s'", share->db.str,
share->table_name.str, share->normalized_path.str)); share->table_name.str, share->normalized_path.str));
...@@ -708,12 +708,8 @@ enum open_frm_error open_table_def(THD *thd, TABLE_SHARE *share, uint flags) ...@@ -708,12 +708,8 @@ enum open_frm_error open_table_def(THD *thd, TABLE_SHARE *share, uint flags)
} }
mysql_file_close(file, MYF(MY_WME)); mysql_file_close(file, MYF(MY_WME));
root_ptr= my_pthread_getspecific_ptr(MEM_ROOT**, THR_MALLOC); share->init_from_binary_frm_image(thd, NULL, buf, stats.st_size);
old_root= *root_ptr;
*root_ptr= &share->mem_root;
share->init_from_binary_frm_image(thd, buf);
error_given= true; error_given= true;
*root_ptr= old_root;
my_free(buf); my_free(buf);
if (!share->error) if (!share->error)
...@@ -745,9 +741,12 @@ err_not_open: ...@@ -745,9 +741,12 @@ err_not_open:
28..29 (used to be key_info_length) 28..29 (used to be key_info_length)
They're still set, for compatibility reasons, but never read. They're still set, for compatibility reasons, but never read.
TODO verify that we never read data from beyond frm_length!
*/ */
bool TABLE_SHARE::init_from_binary_frm_image(THD *thd, const uchar *frm_image) bool TABLE_SHARE::init_from_binary_frm_image(THD *thd, const char *path,
const uchar *frm_image, size_t frm_length)
{ {
TABLE_SHARE *share= this; TABLE_SHARE *share= this;
uint new_frm_ver, field_pack_length, new_field_pack_flag; uint new_frm_ver, field_pack_length, new_field_pack_flag;
...@@ -782,8 +781,16 @@ bool TABLE_SHARE::init_from_binary_frm_image(THD *thd, const uchar *frm_image) ...@@ -782,8 +781,16 @@ bool TABLE_SHARE::init_from_binary_frm_image(THD *thd, const uchar *frm_image)
uint first_key_parts= 0; uint first_key_parts= 0;
keyinfo= &first_keyinfo; keyinfo= &first_keyinfo;
share->ext_key_parts= 0; share->ext_key_parts= 0;
MEM_ROOT **root_ptr, *old_root;
DBUG_ENTER("open_binary_frm"); DBUG_ENTER("open_binary_frm");
root_ptr= my_pthread_getspecific_ptr(MEM_ROOT**, THR_MALLOC);
old_root= *root_ptr;
*root_ptr= &share->mem_root;
if (path && writefrm(path, frm_image, frm_length))
goto err;
new_field_pack_flag= frm_image[27]; new_field_pack_flag= frm_image[27];
new_frm_ver= (frm_image[2] - FRM_VER); new_frm_ver= (frm_image[2] - FRM_VER);
field_pack_length= new_frm_ver < 2 ? 11 : 17; field_pack_length= new_frm_ver < 2 ? 11 : 17;
...@@ -1922,6 +1929,7 @@ bool TABLE_SHARE::init_from_binary_frm_image(THD *thd, const uchar *frm_image) ...@@ -1922,6 +1929,7 @@ bool TABLE_SHARE::init_from_binary_frm_image(THD *thd, const uchar *frm_image)
#endif #endif
share->error= OPEN_FRM_OK; share->error= OPEN_FRM_OK;
*root_ptr= old_root;
DBUG_RETURN(0); DBUG_RETURN(0);
err: err:
...@@ -1945,6 +1953,7 @@ bool TABLE_SHARE::init_from_binary_frm_image(THD *thd, const uchar *frm_image) ...@@ -1945,6 +1953,7 @@ bool TABLE_SHARE::init_from_binary_frm_image(THD *thd, const uchar *frm_image)
if (!thd->is_error()) if (!thd->is_error())
open_table_error(share, OPEN_FRM_CORRUPTED, share->open_errno); open_table_error(share, OPEN_FRM_CORRUPTED, share->open_errno);
*root_ptr= old_root;
DBUG_RETURN(1); DBUG_RETURN(1);
} /* open_binary_frm */ } /* open_binary_frm */
......
...@@ -988,7 +988,8 @@ struct TABLE_SHARE ...@@ -988,7 +988,8 @@ struct TABLE_SHARE
uint actual_n_key_parts(THD *thd); uint actual_n_key_parts(THD *thd);
bool init_from_binary_frm_image(THD *thd, const uchar *frm_image); bool init_from_binary_frm_image(THD *thd, const char *path,
const uchar *frm_image, size_t frm_length);
}; };
......
...@@ -281,7 +281,7 @@ int archive_discover(handlerton *hton, THD* thd, TABLE_SHARE *share) ...@@ -281,7 +281,7 @@ int archive_discover(handlerton *hton, THD* thd, TABLE_SHARE *share)
strxmov(az_file, share->normalized_path.str, ARZ, NullS); strxmov(az_file, share->normalized_path.str, ARZ, NullS);
if (!(mysql_file_stat(/* arch_key_file_data */ 0, az_file, &file_stat, MYF(0)))) if (!(mysql_file_stat(/* arch_key_file_data */ 0, az_file, &file_stat, MYF(0))))
goto err; DBUG_RETURN(HA_ERR_NO_SUCH_TABLE);
if (!(azopen(&frm_stream, az_file, O_RDONLY|O_BINARY))) if (!(azopen(&frm_stream, az_file, O_RDONLY|O_BINARY)))
{ {
...@@ -293,21 +293,23 @@ int archive_discover(handlerton *hton, THD* thd, TABLE_SHARE *share) ...@@ -293,21 +293,23 @@ int archive_discover(handlerton *hton, THD* thd, TABLE_SHARE *share)
if (frm_stream.frm_length == 0) if (frm_stream.frm_length == 0)
DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
frm_ptr= (uchar *)my_malloc(sizeof(char) * frm_stream.frm_length, MYF(0)); frm_ptr= (uchar *)my_malloc(sizeof(char) * frm_stream.frm_length,
azread_frm(&frm_stream, frm_ptr); MYF(MY_THREAD_SPECIFIC | MY_WME));
azclose(&frm_stream); if (!frm_ptr)
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
// don't go through the discovery again if (azread_frm(&frm_stream, frm_ptr))
if (writefrm(share->normalized_path.str, frm_ptr, frm_stream.frm_length)) goto ret;
DBUG_RETURN(my_errno);
share->init_from_binary_frm_image(thd, frm_ptr); azclose(&frm_stream);
my_free(frm_ptr); if (!share->init_from_binary_frm_image(thd, share->normalized_path.str,
frm_ptr, frm_stream.frm_length))
my_errno= 0;
DBUG_RETURN(0); ret:
err: my_free(frm_ptr);
DBUG_RETURN(HA_ERR_NO_SUCH_TABLE); DBUG_RETURN(my_errno);
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment