diff options
author | Monty <monty@mariadb.org> | 2021-03-30 17:06:55 +0300 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2021-05-19 22:54:13 +0200 |
commit | 83e529eced51aa965805e894349bbadd26881f3f (patch) | |
tree | 2f13b79cf5648498ee709424ea37105be730fcf3 /sql/datadict.cc | |
parent | 496a14e18714ac3f0b686ec5f57bf88e96512d2f (diff) | |
download | mariadb-git-83e529eced51aa965805e894349bbadd26881f3f.tar.gz |
MDEV-18465 Logging of DDL statements during backup
Many of the changes was needed to be able to collect and print engine
name and table version id's in the ddl log.
Diffstat (limited to 'sql/datadict.cc')
-rw-r--r-- | sql/datadict.cc | 85 |
1 files changed, 78 insertions, 7 deletions
diff --git a/sql/datadict.cc b/sql/datadict.cc index 1321bf9a3a7..716b4dc3025 100644 --- a/sql/datadict.cc +++ b/sql/datadict.cc @@ -55,10 +55,12 @@ static int read_string(File file, uchar**to, size_t length) @retval TABLE_TYPE_VIEW view */ -Table_type dd_frm_type(THD *thd, char *path, LEX_CSTRING *engine_name) +Table_type dd_frm_type(THD *thd, char *path, LEX_CSTRING *engine_name, + LEX_CSTRING *partition_engine_name, + LEX_CUSTRING *table_version) { File file; - uchar header[40]; //"TYPE=VIEW\n" it is 10 characters + uchar header[64+ MY_UUID_SIZE + 2]; // Header and uuid size_t error; Table_type type= TABLE_TYPE_UNKNOWN; uchar dbt; @@ -83,8 +85,18 @@ Table_type dd_frm_type(THD *thd, char *path, LEX_CSTRING *engine_name) engine_name->length= 0; ((char*) (engine_name->str))[0]= 0; } - - if (unlikely((error= mysql_file_read(file, (uchar*) header, sizeof(header), MYF(MY_NABP))))) + if (partition_engine_name) + { + partition_engine_name->length= 0; + partition_engine_name->str= 0; + } + if (table_version) + { + table_version->length= 0; + table_version->str= 0; // Allocated if needed + } + if (unlikely((error= mysql_file_read(file, (uchar*) header, sizeof(header), + MYF(MY_NABP))))) goto err; if (unlikely((!strncmp((char*) header, "TYPE=VIEW\n", 10)))) @@ -108,20 +120,41 @@ Table_type dd_frm_type(THD *thd, char *path, LEX_CSTRING *engine_name) type= TABLE_TYPE_SEQUENCE; } + if (table_version) + { + /* Read the table version (if it is a 'new' frm file) */ + if (header[64] == EXTRA2_TABLEDEF_VERSION && header[65] == MY_UUID_SIZE) + if ((table_version->str= (uchar*) thd->memdup(header + 66, MY_UUID_SIZE))) + table_version->length= MY_UUID_SIZE; + } + /* cannot use ha_resolve_by_legacy_type without a THD */ if (thd && dbt < DB_TYPE_FIRST_DYNAMIC) { - handlerton *ht= ha_resolve_by_legacy_type(thd, (enum legacy_db_type)dbt); + handlerton *ht= ha_resolve_by_legacy_type(thd, (legacy_db_type) dbt); if (ht) { *engine_name= hton2plugin[ht->slot]->name; +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (partition_engine_name && dbt == DB_TYPE_PARTITION_DB) + { + handlerton *p_ht; + legacy_db_type new_dbt= (legacy_db_type) header[61]; + if (new_dbt >= DB_TYPE_FIRST_DYNAMIC) + goto cont; + if (!(p_ht= ha_resolve_by_legacy_type(thd, new_dbt))) + goto err; + *partition_engine_name= *hton_name(p_ht); + } +#endif // WITH_PARTITION_STORAGE_ENGINE goto err; } } +cont: /* read the true engine name */ { - MY_STAT state; + MY_STAT state; uchar *frm_image= 0; uint n_length; @@ -134,7 +167,8 @@ Table_type dd_frm_type(THD *thd, char *path, LEX_CSTRING *engine_name) if (read_string(file, &frm_image, (size_t)state.st_size)) goto err; - if ((n_length= uint4korr(frm_image+55))) + /* The test for !engine_name->length is only true for partition engine */ + if (!engine_name->length && (n_length= uint4korr(frm_image+55))) { uint record_offset= uint2korr(frm_image+6)+ ((uint2korr(frm_image+14) == 0xffff ? @@ -160,6 +194,43 @@ Table_type dd_frm_type(THD *thd, char *path, LEX_CSTRING *engine_name) } } +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (partition_engine_name && dbt == DB_TYPE_PARTITION_DB) + { + uint len; + const uchar *extra2; + /* Length of the MariaDB extra2 segment in the form file. */ + len = uint2korr(frm_image+4); + extra2= frm_image + 64; + if (*extra2 != '/') // old frm had '/' there + { + const uchar *e2end= extra2 + len; + while (extra2 + 3 <= e2end) + { + uchar type= *extra2++; + size_t length= *extra2++; + if (!length) + { + if (extra2 + 2 >= e2end) + break; + length= uint2korr(extra2); + extra2+= 2; + if (length < 256) + break; + } + if (extra2 + length > e2end) + break; + if (type == EXTRA2_DEFAULT_PART_ENGINE) + { + partition_engine_name->str= thd->strmake((char*)extra2, length); + partition_engine_name->length= length; + break; + } + extra2+= length; + } + } + } +#endif // WITH_PARTITION_STORAGE_ENGINE my_free(frm_image); } |