@brief create() is called to create a database. The variable name will have the name of the table. @details When create() is called you do not need to worry about opening the table. Also, the .frm file will have already been created so adjusting create_info is not necessary. You can overwrite the .frm file at this point if you wish to change the table definition, but there are no
| 1136 | ha_create_table() in handle.cc |
| 1137 | */ |
| 1138 | int ha_tera::create(const char *name, TABLE *table_arg, |
| 1139 | HA_CREATE_INFO *create_info) { |
| 1140 | DBUG_ENTER("ha_tera::create"); |
| 1141 | DBUG_PRINT("debug", ("ha_tera handler %p", this)); |
| 1142 | char dbname[FN_HEADLEN]; |
| 1143 | //char m_schemaname[FN_HEADLEN]; |
| 1144 | char tabname[FN_HEADLEN]; |
| 1145 | char tera_tabname[FN_HEADLEN * 2]; |
| 1146 | |
| 1147 | bool create_from_tera = (create_info->table_options & HA_OPTION_CREATE_FROM_ENGINE); |
| 1148 | ha_tera_util::path_to_dbname(name, dbname); |
| 1149 | ha_tera_util::path_to_tabname(name, tabname); |
| 1150 | ha_tera_util::name_to_tera_tabname(dbname, tabname, tera_tabname); |
| 1151 | DBUG_PRINT("info", ("create table: %s %s, from tera: %d", dbname, tabname, |
| 1152 | create_from_tera)); |
| 1153 | |
| 1154 | if (create_from_tera) { |
| 1155 | DBUG_RETURN(0); |
| 1156 | } |
| 1157 | |
| 1158 | // Save frm data for this table |
| 1159 | uchar* data = NULL; |
| 1160 | uchar* pack_data = NULL; |
| 1161 | size_t pack_length = 0, length = 0; |
| 1162 | if (readfrm(name, &data, &length)) { |
| 1163 | DBUG_RETURN(1); |
| 1164 | } |
| 1165 | if (packfrm(data, length, &pack_data, &pack_length)) { |
| 1166 | my_free((char*)data); |
| 1167 | DBUG_RETURN(2); |
| 1168 | } |
| 1169 | DBUG_PRINT("info", ("setFrm table: %s %s data: 0x%lx len: %lu", |
| 1170 | dbname, tabname, (long)pack_data, (ulong)pack_length)); |
| 1171 | std::string frm_data((char*)pack_data, pack_length); |
| 1172 | my_free((char*)data); |
| 1173 | my_free((char*)pack_data); |
| 1174 | |
| 1175 | tera::ErrorCode ec; |
| 1176 | tera::TableDescriptor table_desc(tera_tabname); |
| 1177 | table_desc.SetRawKey(tera::kGeneralKv); |
| 1178 | table_desc.AddLocalityGroup("default"); |
| 1179 | if (!tera_client->CreateTable(table_desc, &ec)) { |
| 1180 | DBUG_PRINT("TERA", ("create table %s %s on tera fail: %s", |
| 1181 | dbname, tabname, ec.GetReason().c_str())); |
| 1182 | DBUG_RETURN(3); |
| 1183 | } |
| 1184 | |
| 1185 | std::string frm_flag(8, '\0'); |
| 1186 | uint32 frm_version = 1; |
| 1187 | memcpy((char*)frm_flag.data(), &tera_frm_magic_num, 4); |
| 1188 | memcpy((char*)frm_flag.data() + 4, &frm_version, 4); |
| 1189 | tera::RowMutation* frm_mu = tera_frm_table->NewRowMutation(tera_tabname); |
| 1190 | frm_mu->Put(tera_frm_data_column, "", frm_data); |
| 1191 | frm_mu->Put(tera_frm_flag_column, "", frm_flag); |
| 1192 | tera_frm_table->ApplyMutation(frm_mu); |
| 1193 | ec = frm_mu->GetError(); |
| 1194 | delete frm_mu; |
| 1195 |
no test coverage detected