133
135
#include <google/protobuf/io/coded_stream.h>
134
136
#include <google/protobuf/text_format.h>
136
#include <boost/thread/mutex.hpp>
138
138
using namespace std;
139
139
using namespace drizzled;
141
141
/** to protect innobase_open_files */
142
static boost::mutex innobase_share_mutex;
142
static pthread_mutex_t innobase_share_mutex;
144
143
/** to force correct commit order in binlog */
144
static pthread_mutex_t prepare_commit_mutex;
145
145
static ulong commit_threads = 0;
146
static boost::condition_variable commit_cond;
147
static boost::mutex commit_cond_m;
146
static pthread_mutex_t commit_threads_m;
147
static pthread_cond_t commit_cond;
148
static pthread_mutex_t commit_cond_m;
148
149
static bool innodb_inited = 0;
150
151
#define INSIDE_HA_INNOBASE_CC
160
161
#endif /* MYSQL_DYNAMIC_PLUGIN && __WIN__ */
162
163
static plugin::XaStorageEngine* innodb_engine_ptr= NULL;
164
static plugin::TableFunction* status_table_function_ptr= NULL;
165
static plugin::TableFunction* cmp_tool= NULL;
166
static plugin::TableFunction* cmp_reset_tool= NULL;
167
static plugin::TableFunction* cmp_mem_tool= NULL;
168
static plugin::TableFunction* cmp_mem_reset_tool= NULL;
169
static plugin::TableFunction* innodb_trx_tool= NULL;
170
static plugin::TableFunction* innodb_locks_tool= NULL;
171
static plugin::TableFunction* innodb_lock_waits_tool= NULL;
172
static plugin::TableFunction* innodb_sys_tables_tool= NULL;
173
static plugin::TableFunction* innodb_sys_tablestats_tool= NULL;
175
static plugin::TableFunction* innodb_sys_indexes_tool= NULL;
176
static plugin::TableFunction* innodb_sys_columns_tool= NULL;
177
static plugin::TableFunction* innodb_sys_fields_tool= NULL;
178
static plugin::TableFunction* innodb_sys_foreign_tool= NULL;
179
static plugin::TableFunction* innodb_sys_foreign_cols_tool= NULL;
181
static ReplicationLog *replication_logger= NULL;
164
182
typedef constrained_check<uint32_t, UINT32_MAX, 10> open_files_constraint;
165
183
static open_files_constraint innobase_open_files;
166
184
typedef constrained_check<uint32_t, 10, 1> mirrored_log_groups_constraint;
185
203
static purge_batch_constraint innodb_purge_batch_size;
186
204
typedef constrained_check<uint32_t, 1, 0> purge_threads_constraint;
187
205
static purge_threads_constraint innodb_n_purge_threads;
188
typedef constrained_check<uint32_t, 2, 0> trinary_constraint;
206
typedef constrained_check<uint16_t, 2, 0> trinary_constraint;
189
207
static trinary_constraint innodb_flush_log_at_trx_commit;
190
208
typedef constrained_check<unsigned int, 99, 0> max_dirty_pages_constraint;
191
209
static max_dirty_pages_constraint innodb_max_dirty_pages_pct;
462
485
UNIV_INTERN int doCreateTable(Session &session,
464
const identifier::Table &identifier,
487
const TableIdentifier &identifier,
465
488
message::Table&);
466
UNIV_INTERN int doRenameTable(Session&, const identifier::Table &from, const identifier::Table &to);
467
UNIV_INTERN int doDropTable(Session &session, const identifier::Table &identifier);
489
UNIV_INTERN int doRenameTable(Session&, const TableIdentifier &from, const TableIdentifier &to);
490
UNIV_INTERN int doDropTable(Session &session, const TableIdentifier &identifier);
469
UNIV_INTERN virtual bool get_error_message(int error, String *buf) const;
492
UNIV_INTERN virtual bool get_error_message(int error, String *buf);
471
494
UNIV_INTERN uint32_t max_supported_keys() const;
472
495
UNIV_INTERN uint32_t max_supported_key_length() const;
485
508
int doGetTableDefinition(drizzled::Session& session,
486
const identifier::Table &identifier,
509
const TableIdentifier &identifier,
487
510
drizzled::message::Table &table_proto);
489
bool doDoesTableExist(drizzled::Session& session, const identifier::Table &identifier);
512
bool doDoesTableExist(drizzled::Session& session, const TableIdentifier &identifier);
491
514
void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
492
const drizzled::identifier::Schema &schema_identifier,
493
drizzled::identifier::Table::vector &set_of_identifiers);
515
const drizzled::SchemaIdentifier &schema_identifier,
516
drizzled::TableIdentifier::vector &set_of_identifiers);
494
517
bool validateCreateTableOption(const std::string &key, const std::string &state);
495
518
void dropTemporarySchema();
520
543
void InnobaseEngine::doGetTableIdentifiers(drizzled::CachedDirectory &directory,
521
const drizzled::identifier::Schema &schema_identifier,
522
drizzled::identifier::Table::vector &set_of_identifiers)
544
const drizzled::SchemaIdentifier &schema_identifier,
545
drizzled::TableIdentifier::vector &set_of_identifiers)
524
547
CachedDirectory::Entries entries= directory.getEntries();
526
std::string search_string(schema_identifier.getSchemaName());
528
boost::algorithm::to_lower(search_string);
530
if (search_string.compare("data_dictionary") == 0)
532
set_of_identifiers.push_back(identifier::Table(schema_identifier.getSchemaName(), "SYS_REPLICATION_LOG"));
535
549
for (CachedDirectory::Entries::iterator entry_iter= entries.begin();
536
550
entry_iter != entries.end(); ++entry_iter)
559
573
Using schema_identifier here to stop unused warning, could use
560
574
definition.schema() instead
562
identifier::Table identifier(schema_identifier.getSchemaName(), definition.name());
576
TableIdentifier identifier(schema_identifier.getSchemaName(), definition.name());
563
577
set_of_identifiers.push_back(identifier);
569
bool InnobaseEngine::doDoesTableExist(Session &session, const identifier::Table &identifier)
583
bool InnobaseEngine::doDoesTableExist(Session &session, const TableIdentifier &identifier)
571
585
string proto_path(identifier.getPath());
572
586
proto_path.append(DEFAULT_FILE_EXTENSION);
872
877
DRIZZLE: Note, we didn't change this name to avoid more ifdef forking
873
878
in non-Cursor code.
874
879
@return true if non-transactional tables have been edited */
880
extern "C" UNIV_INTERN
877
882
thd_has_edited_nontrans_tables(
878
883
/*===========================*/
879
drizzled::Session *session) /*!< in: thread handle (Session*) */
884
void* session) /*!< in: thread handle (Session*) */
881
return((ibool)session->transaction.all.hasModifiedNonTransData());
886
return((ibool)((Session *)session)->transaction.all.hasModifiedNonTransData());
884
889
/******************************************************************//**
885
890
Returns true if the thread is executing a SELECT statement.
886
891
@return true if session is executing SELECT */
892
extern "C" UNIV_INTERN
891
const drizzled::Session *session) /*!< in: thread handle (Session*) */
896
const void* session) /*!< in: thread handle (Session*) */
893
return(session->getSqlCommand() == SQLCOM_SELECT);
898
return(session_sql_command((const Session*) session) == SQLCOM_SELECT);
896
901
/******************************************************************//**
897
902
Returns true if the thread supports XA,
898
903
global value of innodb_supports_xa if session is NULL.
899
904
@return true if session has XA support */
905
extern "C" UNIV_INTERN
904
drizzled::Session* ) /*!< in: thread handle (Session*), or NULL to query
909
void* ) /*!< in: thread handle (Session*), or NULL to query
905
910
the global innodb_supports_xa */
907
912
/* TODO: Add support here for per-session value */
927
932
/******************************************************************//**
928
933
Set the time waited for the lock for the current query. */
934
extern "C" UNIV_INTERN
931
936
thd_set_lock_wait_time(
932
937
/*===================*/
933
drizzled::Session* in_session, /*!< in: thread handle (THD*) */
938
void* thd, /*!< in: thread handle (THD*) */
934
939
ulint value) /*!< in: time waited for the lock */
937
in_session->utime_after_lock+= value;
942
static_cast<Session*>(thd)->utime_after_lock+= value;
940
946
/********************************************************************//**
960
966
trx_t *trx= session_to_trx(&session);
962
968
uint64_t trx_id= message.transaction_context().transaction_id();
963
uint32_t seg_id= message.segment_id();
964
uint64_t end_timestamp= message.transaction_context().end_timestamp();
965
bool is_end_segment= message.end_segment();
966
trx->log_commit_id= TRUE;
967
ulint error= insert_replication_message(data, message.ByteSize(), trx, trx_id,
968
end_timestamp, is_end_segment, seg_id);
969
ulint error= insert_replication_message(data, message.ByteSize(), trx, trx_id);
1167
1169
/*************************************************************//**
1168
1170
Prints info of a Session object (== user session thread) to the given file. */
1171
extern "C" UNIV_INTERN
1171
1173
innobase_mysql_print_thd(
1172
1174
/*=====================*/
1173
1175
FILE* f, /*!< in: output stream */
1174
drizzled::Session *in_session, /*!< in: pointer to a Drizzle Session object */
1176
void * in_session, /*!< in: pointer to a Drizzle Session object */
1175
1177
uint ) /*!< in: max query length to print, or 0 to
1176
1178
use the default max length */
1178
drizzled::identifier::User::const_shared_ptr user_identifier(in_session->user());
1180
Session *session= reinterpret_cast<Session *>(in_session);
1181
drizzled::identifier::User::const_shared_ptr user_identifier(session->user());
1181
1184
"Drizzle thread %"PRIu64", query id %"PRIu64", %s, %s, %s ",
1182
static_cast<uint64_t>(in_session->getSessionId()),
1183
static_cast<uint64_t>(in_session->getQueryId()),
1185
static_cast<uint64_t>(session->getSessionId()),
1186
static_cast<uint64_t>(session->getQueryId()),
1185
1188
user_identifier->address().c_str(),
1186
1189
user_identifier->username().c_str()
1188
fprintf(f, "\n%s", in_session->getQueryString()->c_str());
1191
fprintf(f, "\n%s", session->getQueryString()->c_str());
1192
1195
/******************************************************************//**
1193
1196
Get the variable length bounds of the given character set. */
1197
extern "C" UNIV_INTERN
1196
1199
innobase_get_cset_width(
1197
1200
/*====================*/
1277
1292
return my_isspace(static_cast<const CHARSET_INFO *>(cs), char_to_test);
1297
innobase_fast_mutex_init(
1298
os_fast_mutex_t* fast_mutex)
1300
return pthread_mutex_init(fast_mutex, MY_MUTEX_INIT_FAST);
1303
/**********************************************************************//**
1304
Determines the current SQL statement.
1305
@return SQL statement string */
1306
extern "C" UNIV_INTERN
1310
void* session, /*!< in: MySQL thread handle */
1311
size_t* length) /*!< out: length of the SQL statement */
1313
return static_cast<Session*>(session)->getQueryStringCopy(*length);
1280
1316
#if defined (__WIN__) && defined (MYSQL_DYNAMIC_PLUGIN)
1281
1317
/*******************************************************************//**
1282
1318
Map an OS error to an errno value. The OS error number is stored in
1283
1319
_doserrno and the mapped value is stored in errno) */
1286
1323
unsigned long); /*!< in: OS error value */
1631
1668
ulint buflen, /*!< in: length of buf, in bytes */
1632
1669
const char* id, /*!< in: identifier to convert */
1633
1670
ulint idlen, /*!< in: length of id, in bytes */
1634
drizzled::Session *session,/*!< in: MySQL connection thread, or NULL */
1671
void* session,/*!< in: MySQL connection thread, or NULL */
1635
1672
ibool file_id)/*!< in: TRUE=id is a table or database name;
1636
1673
FALSE=id is an UTF-8 string */
1638
1675
char nz[NAME_LEN + 1];
1639
const size_t nz2_size= NAME_LEN + 1 + srv_mysql50_table_name_prefix.size();
1640
boost::scoped_array<char> nz2(new char[nz2_size]);
1676
char nz2[NAME_LEN + 1 + sizeof srv_mysql50_table_name_prefix];
1642
1678
const char* s = id;
1717
1753
ulint buflen, /*!< in: length of buf, in bytes */
1718
1754
const char* id, /*!< in: identifier to convert */
1719
1755
ulint idlen, /*!< in: length of id, in bytes */
1720
drizzled::Session *session,/*!< in: MySQL connection thread, or NULL */
1756
void* session,/*!< in: MySQL connection thread, or NULL */
1721
1757
ibool table_id)/*!< in: TRUE=id is a table or database name;
1722
1758
FALSE=id is an index name */
1765
1801
/**********************************************************************//**
1766
1802
Determines if the currently running transaction has been interrupted.
1767
1803
@return TRUE if interrupted */
1804
extern "C" UNIV_INTERN
1770
1806
trx_is_interrupted(
1771
1807
/*===============*/
1772
1808
trx_t* trx) /*!< in: transaction */
1774
return(trx && trx->mysql_thd && trx->mysql_thd->getKilled());
1810
return(trx && trx->mysql_thd && static_cast<Session*>(trx->mysql_thd)->getKilled());
1777
1813
/**********************************************************************//**
1778
1814
Determines if the currently running transaction is in strict mode.
1779
1815
@return TRUE if strict */
1816
extern "C" UNIV_INTERN
1975
2011
if (format_id >= 0) {
1976
innobase_file_format_max.assign(
1977
trx_sys_file_format_id_to_name((uint)format_id));
2012
innobase_file_format_max=
2013
trx_sys_file_format_id_to_name((uint)format_id);
1979
2015
/* Update the max format id in the system tablespace. */
1980
const char *name_buff;
1982
if (trx_sys_file_format_max_set(format_id, &name_buff))
2016
char name_buff[100];
2017
strcpy(name_buff, innobase_file_format_max.c_str());
2018
if (trx_sys_file_format_max_set(format_id, (const char **)&name_buff))
1984
errmsg_printf(error::WARN,
2020
errmsg_printf(ERRMSG_LVL_WARN,
1985
2021
" [Info] InnoDB: the file format in the system "
1986
2022
"tablespace is now set to %s.\n", name_buff);
1987
2023
innobase_file_format_max= name_buff;
2070
2105
#ifdef UNIV_DEBUG
2071
2106
static const char test_filename[] = "-@";
2072
const size_t test_tablename_size= sizeof test_filename
2073
+ srv_mysql50_table_name_prefix.size();
2074
boost::scoped_array test_tablename(new char[test_tablename_size]);
2075
if ((test_tablename_size) - 1
2076
!= filename_to_tablename(test_filename, test_tablename.get(),
2077
test_tablename_size)
2078
|| strncmp(test_tablename.get(),
2079
srv_mysql50_table_name_prefix.c_str(),
2080
srv_mysql50_table_name_prefix.size())
2081
|| strcmp(test_tablename.get()
2082
+ srv_mysql50_table_name_prefix.size(),
2107
char test_tablename[sizeof test_filename
2108
+ sizeof srv_mysql50_table_name_prefix];
2109
if ((sizeof test_tablename) - 1
2110
!= filename_to_tablename(test_filename, test_tablename,
2111
sizeof test_tablename)
2112
|| strncmp(test_tablename,
2113
srv_mysql50_table_name_prefix,
2114
sizeof srv_mysql50_table_name_prefix)
2115
|| strcmp(test_tablename
2116
+ sizeof srv_mysql50_table_name_prefix,
2083
2117
test_filename)) {
2084
errmsg_printf(error::ERROR, "tablename encoding has been changed");
2118
errmsg_printf(ERRMSG_LVL_ERROR, "tablename encoding has been changed");
2087
2121
#endif /* UNIV_DEBUG */
2185
2220
srv_max_file_format_at_startup */
2186
2221
if (innobase_file_format_validate_and_set(innobase_file_format_max.c_str()) < 0)
2188
errmsg_printf(error::ERROR, _("InnoDB: invalid innodb_file_format_max value: "
2189
"should be any value up to %s or its equivalent numeric id"),
2190
trx_sys_file_format_id_to_name(DICT_TF_FORMAT_MAX));
2223
errmsg_printf(ERRMSG_LVL_ERROR, _("InnoDB: invalid "
2224
"innodb_file_format_max value: "
2225
"should be any value up to %s or its "
2226
"equivalent numeric id"),
2227
trx_sys_file_format_id_to_name(DICT_TF_FORMAT_MAX));
2191
2228
goto mem_free_and_error;
2286
2325
innobase_open_tables = hash_create(200);
2326
pthread_mutex_init(&innobase_share_mutex, MY_MUTEX_INIT_FAST);
2327
pthread_mutex_init(&prepare_commit_mutex, MY_MUTEX_INIT_FAST);
2328
pthread_mutex_init(&commit_threads_m, MY_MUTEX_INIT_FAST);
2329
pthread_mutex_init(&commit_cond_m, MY_MUTEX_INIT_FAST);
2330
pthread_cond_init(&commit_cond, NULL);
2287
2331
innodb_inited= 1;
2289
2333
actuall_engine_ptr->dropTemporarySchema();
2291
context.add(new InnodbStatusTool);
2335
status_table_function_ptr= new InnodbStatusTool;
2293
2337
context.add(innodb_engine_ptr);
2295
context.add(new(std::nothrow)CmpTool(false));
2297
context.add(new(std::nothrow)CmpTool(true));
2299
context.add(new(std::nothrow)CmpmemTool(false));
2301
context.add(new(std::nothrow)CmpmemTool(true));
2303
context.add(new(std::nothrow)InnodbTrxTool("INNODB_TRX"));
2305
context.add(new(std::nothrow)InnodbTrxTool("INNODB_LOCKS"));
2307
context.add(new(std::nothrow)InnodbTrxTool("INNODB_LOCK_WAITS"));
2309
context.add(new(std::nothrow)InnodbSysTablesTool());
2311
context.add(new(std::nothrow)InnodbSysTableStatsTool());
2313
context.add(new(std::nothrow)InnodbSysIndexesTool());
2315
context.add(new(std::nothrow)InnodbSysColumnsTool());
2317
context.add(new(std::nothrow)InnodbSysFieldsTool());
2319
context.add(new(std::nothrow)InnodbSysForeignTool());
2321
context.add(new(std::nothrow)InnodbSysForeignColsTool());
2339
context.add(status_table_function_ptr);
2341
cmp_tool= new(std::nothrow)CmpTool(false);
2342
context.add(cmp_tool);
2344
cmp_reset_tool= new(std::nothrow)CmpTool(true);
2345
context.add(cmp_reset_tool);
2347
cmp_mem_tool= new(std::nothrow)CmpmemTool(false);
2348
context.add(cmp_mem_tool);
2350
cmp_mem_reset_tool= new(std::nothrow)CmpmemTool(true);
2351
context.add(cmp_mem_reset_tool);
2353
innodb_trx_tool= new(std::nothrow)InnodbTrxTool("INNODB_TRX");
2354
context.add(innodb_trx_tool);
2356
innodb_locks_tool= new(std::nothrow)InnodbTrxTool("INNODB_LOCKS");
2357
context.add(innodb_locks_tool);
2359
innodb_lock_waits_tool= new(std::nothrow)InnodbTrxTool("INNODB_LOCK_WAITS");
2360
context.add(innodb_lock_waits_tool);
2362
innodb_sys_tables_tool= new(std::nothrow)InnodbSysTablesTool();
2363
context.add(innodb_sys_tables_tool);
2365
innodb_sys_tablestats_tool= new(std::nothrow)InnodbSysTableStatsTool();
2366
context.add(innodb_sys_tablestats_tool);
2368
innodb_sys_indexes_tool= new(std::nothrow)InnodbSysIndexesTool();
2369
context.add(innodb_sys_indexes_tool);
2371
innodb_sys_columns_tool= new(std::nothrow)InnodbSysColumnsTool();
2372
context.add(innodb_sys_columns_tool);
2374
innodb_sys_fields_tool= new(std::nothrow)InnodbSysFieldsTool();
2375
context.add(innodb_sys_fields_tool);
2377
innodb_sys_foreign_tool= new(std::nothrow)InnodbSysForeignTool();
2378
context.add(innodb_sys_foreign_tool);
2380
innodb_sys_foreign_cols_tool= new(std::nothrow)InnodbSysForeignColsTool();
2381
context.add(innodb_sys_foreign_cols_tool);
2323
2383
context.add(new(std::nothrow)InnodbInternalTables());
2324
2384
context.add(new(std::nothrow)InnodbReplicationTable());
2326
2386
if (innobase_use_replication_log)
2328
ReplicationLog *replication_logger= new(std::nothrow)ReplicationLog();
2388
replication_logger= new(std::nothrow)ReplicationLog();
2329
2389
context.add(replication_logger);
2330
2390
ReplicationLog::setup(replication_logger);
2377
2437
innodb_file_format_max_validate));
2378
2438
context.registerVariable(new sys_var_constrained_value_readonly<size_t>("buffer_pool_size", innobase_buffer_pool_size));
2379
2439
context.registerVariable(new sys_var_constrained_value_readonly<int64_t>("log_file_size", innobase_log_file_size));
2380
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("flush_log_at_trx_commit",
2440
context.registerVariable(new sys_var_constrained_value_readonly<uint16_t>("flush_log_at_trx_commit",
2381
2441
innodb_flush_log_at_trx_commit));
2382
2442
context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("max_dirty_pages_pct",
2383
2443
innodb_max_dirty_pages_pct));
2513
2572
trx_search_latch_release_if_reserved(trx);
2576
|| (!session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
2518
2578
/* We were instructed to commit the whole transaction, or
2519
2579
this is an SQL statement end and autocommit is on */
2521
2581
/* We need current binlog position for ibbackup to work.
2522
2582
Note, the position is current because of
2523
2583
prepare_commit_mutex */
2524
const uint32_t commit_concurrency= innobase_commit_concurrency.get();
2525
if (commit_concurrency)
2529
boost::mutex::scoped_lock scopedLock(commit_cond_m);
2532
if (commit_threads <= commit_concurrency)
2585
if (innobase_commit_concurrency.get() > 0) {
2586
pthread_mutex_lock(&commit_cond_m);
2589
if (commit_threads > innobase_commit_concurrency.get()) {
2535
2590
commit_threads--;
2536
commit_cond.wait(scopedLock);
2591
pthread_cond_wait(&commit_cond,
2593
pthread_mutex_unlock(&commit_cond_m);
2597
pthread_mutex_unlock(&commit_cond_m);
2540
trx->mysql_log_file_name = NULL;
2601
/* Store transaction point for binlog
2602
Later logic tests that this is set to _something_. We need
2603
that logic to fire, even though we do not have a real name. */
2604
trx->mysql_log_file_name = "UNUSED";
2541
2605
trx->mysql_log_offset = 0;
2543
2607
/* Don't do write + flush right now. For group commit
2944
/*****************************************************************//**
2945
Normalizes a table name string. A normalized name consists of the
2946
database name catenated to '/' and table name. An example:
2947
test/mytable. On Windows normalization puts both the database name and the
2948
table name always to lower case. */
2951
normalize_table_name(
2952
/*=================*/
2953
char* norm_name, /*!< out: normalized name as a
2954
null-terminated string */
2955
const char* name) /*!< in: table name string */
2957
const char* name_ptr;
2961
/* Scan name from the end */
2963
ptr = strchr(name, '\0')-1;
2965
while (ptr >= name && *ptr != '\\' && *ptr != '/') {
2975
while (ptr >= name && *ptr != '\\' && *ptr != '/') {
2981
memcpy(norm_name, db_ptr, strlen(name) + 1 - (db_ptr - name));
2983
norm_name[name_ptr - db_ptr - 1] = '/';
2986
innobase_casedn_str(norm_name);
2879
2990
/********************************************************************//**
2880
2991
Get the upper limit of the MySQL integral and floating-point type.
2881
2992
@return maximum allowed value for the field */
3042
3153
if (!index_mapping) {
3043
3154
/* Report an error if index_mapping continues to be
3044
3155
NULL and mysql_num_index is a non-zero value */
3045
errmsg_printf(error::ERROR, "InnoDB: fail to allocate memory for "
3046
"index translation table. Number of Index:%lu, array size:%lu",
3156
errmsg_printf(ERRMSG_LVL_ERROR,
3157
"InnoDB: fail to allocate memory for "
3158
"index translation table. Number of "
3159
"Index:%lu, array size:%lu",
3047
3160
mysql_num_index,
3048
3161
share->idx_trans_tbl.array_size);
3064
3177
ib_table, table->key_info[count].name);
3066
3179
if (!index_mapping[count]) {
3067
errmsg_printf(error::ERROR, "Cannot find index %s in InnoDB index dictionary.",
3068
table->key_info[count].name);
3180
errmsg_printf(ERRMSG_LVL_ERROR, "Cannot find index %s in InnoDB "
3181
"index dictionary.",
3182
table->key_info[count].name);
3070
3184
goto func_exit;
3073
3187
/* Double check fetched index has the same
3074
3188
column info as those in mysql key_info. */
3075
if (!innobase_match_index_columns(&table->key_info[count], index_mapping[count])) {
3076
errmsg_printf(error::ERROR, "Found index %s whose column info does not match that of MySQL.",
3077
table->key_info[count].name);
3189
if (!innobase_match_index_columns(&table->key_info[count],
3190
index_mapping[count])) {
3191
errmsg_printf(ERRMSG_LVL_ERROR, "Found index %s whose column info "
3192
"does not match that of MySQL.",
3193
table->key_info[count].name);
3197
3314
case DB_RECORD_NOT_FOUND:
3198
3315
ut_print_timestamp(stderr);
3199
errmsg_printf(error::ERROR, "InnoDB: MySQL and InnoDB data dictionaries are out of sync.\n"
3200
"InnoDB: Unable to find the AUTOINC column %s in the InnoDB table %s.\n"
3201
"InnoDB: We set the next AUTOINC column value to 0,\n"
3202
"InnoDB: in effect disabling the AUTOINC next value generation.\n"
3203
"InnoDB: You can either set the next AUTOINC value explicitly using ALTER TABLE\n"
3204
"InnoDB: or fix the data dictionary by recreating the table.\n",
3205
col_name, index->table->name);
3316
fprintf(stderr, " InnoDB: MySQL and InnoDB data "
3317
"dictionaries are out of sync.\n"
3318
"InnoDB: Unable to find the AUTOINC column "
3319
"%s in the InnoDB table %s.\n"
3320
"InnoDB: We set the next AUTOINC column "
3322
"InnoDB: in effect disabling the AUTOINC "
3323
"next value generation.\n"
3324
"InnoDB: You can either set the next "
3325
"AUTOINC value explicitly using ALTER TABLE\n"
3326
"InnoDB: or fix the data dictionary by "
3327
"recreating the table.\n",
3328
col_name, index->table->name);
3207
3330
/* This will disable the AUTOINC generation. */
3247
3371
getTransactionalEngine()->releaseTemporaryLatches(session);
3374
normalize_table_name(norm_name, identifier.getPath().c_str());
3250
3376
user_session = NULL;
3252
std::string search_string(identifier.getSchemaName());
3253
boost::algorithm::to_lower(search_string);
3378
if (!(share=get_share(identifier.getPath().c_str()))) {
3255
if (search_string.compare("data_dictionary") == 0)
3257
std::string table_name(identifier.getTableName());
3258
boost::algorithm::to_upper(table_name);
3259
if (!(share=get_share(table_name.c_str())))
3266
if (!(share=get_share(identifier.getKeyPath().c_str())))
3272
3383
/* Create buffers for packing the fields of a record. Why
3295
3406
/* Get pointer to a table object in InnoDB dictionary cache */
3296
if (search_string.compare("data_dictionary") == 0)
3298
std::string table_name(identifier.getTableName());
3299
boost::algorithm::to_upper(table_name);
3300
ib_table = dict_table_get(table_name.c_str(), TRUE);
3304
ib_table = dict_table_get(identifier.getKeyPath().c_str(), TRUE);
3407
ib_table = dict_table_get(norm_name, TRUE);
3307
3409
if (NULL == ib_table) {
3308
errmsg_printf(error::ERROR, "Cannot find or open table %s from\n"
3410
errmsg_printf(ERRMSG_LVL_ERROR, "Cannot find or open table %s from\n"
3309
3411
"the internal data dictionary of InnoDB "
3310
3412
"though the .frm file for the\n"
3311
3413
"table exists. Maybe you have deleted and "
3328
3430
return(HA_ERR_NO_SUCH_TABLE);
3331
if (ib_table->ibd_file_missing && ! session->doing_tablespace_operation()) {
3332
errmsg_printf(error::ERROR, "MySQL is trying to open a table handle but "
3433
if (ib_table->ibd_file_missing && !session_tablespace_op(session)) {
3434
errmsg_printf(ERRMSG_LVL_ERROR, "MySQL is trying to open a table handle but "
3333
3435
"the .ibd file for\ntable %s does not exist.\n"
3334
3436
"Have you deleted the .ibd file from the "
3335
3437
"database directory under\nthe MySQL datadir, "
3336
3438
"or have you used DISCARD TABLESPACE?\n"
3337
3439
"See " REFMAN "innodb-troubleshooting.html\n"
3338
3440
"how you can resolve the problem.\n",
3339
identifier.getKeyPath().c_str());
3340
3442
free_share(share);
3341
3443
upd_buff.resize(0);
3342
3444
key_val_buff.resize(0);
3358
3460
key_used_on_scan = primary_key;
3360
3462
if (!innobase_build_index_translation(getTable(), ib_table, share)) {
3361
errmsg_printf(error::ERROR, "Build InnoDB index translation table for"
3362
" Table %s failed", identifier.getKeyPath().c_str());
3463
errmsg_printf(ERRMSG_LVL_ERROR, "Build InnoDB index translation table for"
3464
" Table %s failed", identifier.getPath().c_str());
3365
3467
/* Allocate a buffer for a 'row reference'. A row reference is
6177
6279
if (lex_identified_temp_table)
6178
6280
iflags |= DICT_TF2_TEMPORARY << DICT_TF2_SHIFT;
6180
error= create_table_def(trx, &form, identifier.getKeyPath().c_str(),
6181
lex_identified_temp_table ? identifier.getKeyPath().c_str() : NULL,
6282
error= create_table_def(trx, &form, norm_name,
6283
lex_identified_temp_table ? name2 : NULL,
6184
6286
session.setXaId(trx->id);
6211
6313
for (i = 0; i < form.getShare()->sizeKeys(); i++) {
6212
6314
if (i != (uint) primary_key_no) {
6214
if ((error = create_index(trx, &form, iflags, identifier.getKeyPath().c_str(),
6316
if ((error = create_index(trx, &form, iflags, norm_name,
6221
stmt= session.getQueryStringCopy(stmt_len);
6323
stmt = innobase_get_stmt(&session, &stmt_len);
6224
6326
string generated_create_table;
6225
6327
const char *query= stmt;
6227
if (session.getSqlCommand() == SQLCOM_CREATE_TABLE)
6329
if (session_sql_command(&session) == SQLCOM_CREATE_TABLE)
6229
6331
message::transformTableDefinitionToSql(create_proto,
6230
6332
generated_create_table,
6427
6529
InnobaseEngine::doDropTable(
6428
6530
/*======================*/
6429
6531
Session &session,
6430
const identifier::Table &identifier)
6532
const TableIdentifier &identifier)
6433
6535
trx_t* parent_trx;
6537
char norm_name[1000];
6436
6539
ut_a(identifier.getPath().length() < 1000);
6438
std::string search_string(identifier.getSchemaName());
6439
boost::algorithm::to_lower(search_string);
6441
if (search_string.compare("data_dictionary") == 0)
6443
return HA_ERR_TABLE_READONLY;
6541
/* Strangely, MySQL passes the table name without the '.frm'
6542
extension, in contrast to ::create */
6543
normalize_table_name(norm_name, identifier.getPath().c_str());
6446
6545
/* Get the transaction associated with the current session, or create one
6447
6546
if not yet created */
6608
6707
innobase_rename_table(
6609
6708
/*==================*/
6610
6709
trx_t* trx, /*!< in: transaction */
6611
const identifier::Table &from,
6612
const identifier::Table &to,
6710
const char* from, /*!< in: old name of the table */
6711
const char* to, /*!< in: new name of the table */
6613
6712
ibool lock_and_commit)
6614
6713
/*!< in: TRUE=lock data dictionary and commit */
6716
char norm_to[FN_REFLEN];
6717
char norm_from[FN_REFLEN];
6618
6719
srv_lower_case_table_names = TRUE;
6721
normalize_table_name(norm_to, to);
6722
normalize_table_name(norm_from, from);
6620
6724
/* Serialize data dictionary operations with dictionary mutex:
6621
6725
no deadlocks can occur then in these operations */
6624
6728
row_mysql_lock_data_dictionary(trx);
6627
error = row_rename_table_for_mysql(from.getKeyPath().c_str(), to.getKeyPath().c_str(), trx, lock_and_commit);
6731
error = row_rename_table_for_mysql(
6732
norm_from, norm_to, trx, lock_and_commit);
6629
6734
if (error != DB_SUCCESS) {
6630
6735
FILE* ef = dict_foreign_err_file;
6632
6737
fputs("InnoDB: Renaming table ", ef);
6633
ut_print_name(ef, trx, TRUE, from.getKeyPath().c_str());
6738
ut_print_name(ef, trx, TRUE, norm_from);
6634
6739
fputs(" to ", ef);
6635
ut_print_name(ef, trx, TRUE, to.getKeyPath().c_str());
6740
ut_print_name(ef, trx, TRUE, norm_to);
6636
6741
fputs(" failed!\n", ef);
7678
7783
db_name[i] = 0;
7679
ulen= identifier::Table::filename_to_tablename(db_name, uname, sizeof(uname));
7784
ulen= TableIdentifier::filename_to_tablename(db_name, uname, sizeof(uname));
7680
7785
LEX_STRING *tmp_referenced_db = session->make_lex_string(NULL, uname, ulen, true);
7682
7787
/* Table name */
7683
7788
tmp_buff += i + 1;
7684
ulen= identifier::Table::filename_to_tablename(tmp_buff, uname, sizeof(uname));
7789
ulen= TableIdentifier::filename_to_tablename(tmp_buff, uname, sizeof(uname));
7685
7790
LEX_STRING *tmp_referenced_table = session->make_lex_string(NULL, uname, ulen, true);
7687
7792
/** Foreign Fields **/
9148
9257
"Purge threads can be either 0 or 1. Defalut is 0.");
9149
9258
context("file-per-table",
9150
9259
po::value<bool>(&srv_file_per_table)->default_value(false)->zero_tokens(),
9151
"Stores each InnoDB table to an .ibd file in the database dir.");
9260
"Stores each InnoDB table to an .ibd file in the database dir.");
9261
context("file-format",
9262
po::value<string>(&innobase_file_format_name)->default_value("Antelope"),
9263
"File format to use for new tables in .ibd files.");
9152
9264
context("file-format-max",
9153
9265
po::value<string>(&innobase_file_format_max)->default_value("Antelope"),
9154
9266
"The highest file format in the tablespace.");
9155
9267
context("file-format-check",
9156
9268
po::value<bool>(&innobase_file_format_check)->default_value(true)->zero_tokens(),
9157
9269
"Whether to perform system file format check.");
9158
context("file-format",
9159
po::value<string>(&innobase_file_format_name)->default_value("Antelope"),
9160
"File format to use for new tables in .ibd files.");
9161
9270
context("flush-log-at-trx-commit",
9162
9271
po::value<trinary_constraint>(&innodb_flush_log_at_trx_commit)->default_value(1),
9163
9272
"Set to 0 (write and flush once per second), 1 (write and flush at each commit) or 2 (write at commit, flush once per second).");
9192
9301
po::value<additional_mem_pool_constraint>(&innobase_additional_mem_pool_size)->default_value(8*1024*1024L),
9193
9302
"Size of a memory pool InnoDB uses to store data dictionary information and other internal data structures.");
9194
9303
context("autoextend-increment",
9195
po::value<autoextend_constraint>(&innodb_auto_extend_increment)->default_value(64L),
9304
po::value<autoextend_constraint>(&innodb_auto_extend_increment)->default_value(8L),
9196
9305
"Data file autoextend increment in megabytes");
9197
9306
context("buffer-pool-size",
9198
9307
po::value<buffer_pool_constraint>(&innobase_buffer_pool_size)->default_value(128*1024*1024L),
9251
9360
"InnoDB version");
9252
9361
context("use-internal-malloc",
9253
9362
"Use InnoDB's internal memory allocator instal of the OS memory allocator.");
9254
context("disable-native-aio",
9255
_("Do not use Native AIO library for IO, even if available"));
9256
9363
context("change-buffering",
9257
9364
po::value<string>(&innobase_change_buffering),
9258
9365
"Buffer changes to reduce random access: OFF, ON, inserting, deleting, changing, or purging.");