43
43
#include <limits.h>
46
#include "drizzled/error.h"
47
#include "drizzled/errmsg_print.h"
48
#include "drizzled/charset_info.h"
49
#include "drizzled/internal/m_string.h"
50
#include "drizzled/internal/my_sys.h"
51
#include "drizzled/my_hash.h"
52
#include "drizzled/plugin.h"
53
#include "drizzled/show.h"
54
#include "drizzled/data_home.h"
55
#include "drizzled/error.h"
56
#include "drizzled/field.h"
57
#include "drizzled/charset.h"
58
#include "drizzled/session.h"
59
#include "drizzled/current_session.h"
60
#include "drizzled/table.h"
61
#include "drizzled/field/blob.h"
62
#include "drizzled/field/varstring.h"
63
#include "drizzled/field/timestamp.h"
64
#include "drizzled/plugin/xa_storage_engine.h"
65
#include "drizzled/plugin/daemon.h"
66
#include "drizzled/memory/multi_malloc.h"
67
#include "drizzled/pthread_globals.h"
68
#include "drizzled/named_savepoint.h"
46
#include <drizzled/error.h>
47
#include <drizzled/errmsg_print.h>
48
#include <drizzled/charset_info.h>
49
#include <drizzled/internal/m_string.h>
50
#include <drizzled/internal/my_sys.h>
51
#include <drizzled/plugin.h>
52
#include <drizzled/show.h>
53
#include <drizzled/data_home.h>
54
#include <drizzled/error.h>
55
#include <drizzled/field.h>
56
#include <drizzled/charset.h>
57
#include <drizzled/session.h>
58
#include <drizzled/current_session.h>
59
#include <drizzled/table.h>
60
#include <drizzled/field/blob.h>
61
#include <drizzled/field/varstring.h>
62
#include <drizzled/plugin/xa_storage_engine.h>
63
#include <drizzled/plugin/daemon.h>
64
#include <drizzled/memory/multi_malloc.h>
65
#include <drizzled/pthread_globals.h>
66
#include <drizzled/named_savepoint.h>
67
#include <drizzled/session/table_messages.h>
70
68
#include <drizzled/transaction_services.h>
71
#include "drizzled/message/statement_transform.h"
69
#include <drizzled/message/statement_transform.h>
70
#include <drizzled/cached_directory.h>
71
#include <drizzled/statistics_variables.h>
72
#include <drizzled/system_variables.h>
73
#include <drizzled/session/transactions.h>
73
75
#include <boost/algorithm/string.hpp>
74
76
#include <boost/program_options.hpp>
77
#include <boost/scoped_array.hpp>
75
78
#include <boost/filesystem.hpp>
76
79
#include <drizzled/module/option_map.h>
77
80
#include <iostream>
128
128
#include <sstream>
129
129
#include <string>
131
#include "plugin/innobase/handler/status_function.h"
132
#include "plugin/innobase/handler/replication_log.h"
131
#include <plugin/innobase/handler/status_function.h>
132
#include <plugin/innobase/handler/replication_log.h>
134
134
#include <google/protobuf/io/zero_copy_stream.h>
135
135
#include <google/protobuf/io/zero_copy_stream_impl.h>
136
136
#include <google/protobuf/io/coded_stream.h>
137
137
#include <google/protobuf/text_format.h>
139
#include <boost/thread/mutex.hpp>
139
141
using namespace std;
140
142
using namespace drizzled;
142
144
/** to protect innobase_open_files */
143
static pthread_mutex_t innobase_share_mutex;
145
static boost::mutex innobase_share_mutex;
144
147
/** to force correct commit order in binlog */
145
static pthread_mutex_t prepare_commit_mutex;
146
148
static ulong commit_threads = 0;
147
static pthread_mutex_t commit_threads_m;
148
static pthread_cond_t commit_cond;
149
static pthread_mutex_t commit_cond_m;
149
static boost::condition_variable commit_cond;
150
static boost::mutex commit_cond_m;
150
151
static bool innodb_inited = 0;
152
153
#define INSIDE_HA_INNOBASE_CC
162
163
#endif /* MYSQL_DYNAMIC_PLUGIN && __WIN__ */
164
165
static plugin::XaStorageEngine* innodb_engine_ptr= NULL;
165
static plugin::TableFunction* status_table_function_ptr= NULL;
166
static plugin::TableFunction* cmp_tool= NULL;
167
static plugin::TableFunction* cmp_reset_tool= NULL;
168
static plugin::TableFunction* cmp_mem_tool= NULL;
169
static plugin::TableFunction* cmp_mem_reset_tool= NULL;
170
static plugin::TableFunction* innodb_trx_tool= NULL;
171
static plugin::TableFunction* innodb_locks_tool= NULL;
172
static plugin::TableFunction* innodb_lock_waits_tool= NULL;
173
static plugin::TableFunction* innodb_sys_tables_tool= NULL;
174
static plugin::TableFunction* innodb_sys_tablestats_tool= NULL;
176
static plugin::TableFunction* innodb_sys_indexes_tool= NULL;
177
static plugin::TableFunction* innodb_sys_columns_tool= NULL;
178
static plugin::TableFunction* innodb_sys_fields_tool= NULL;
179
static plugin::TableFunction* innodb_sys_foreign_tool= NULL;
180
static plugin::TableFunction* innodb_sys_foreign_cols_tool= NULL;
182
static ReplicationLog *replication_logger= NULL;
183
167
typedef constrained_check<uint32_t, UINT32_MAX, 10> open_files_constraint;
184
168
static open_files_constraint innobase_open_files;
185
169
typedef constrained_check<uint32_t, 10, 1> mirrored_log_groups_constraint;
204
188
static purge_batch_constraint innodb_purge_batch_size;
205
189
typedef constrained_check<uint32_t, 1, 0> purge_threads_constraint;
206
190
static purge_threads_constraint innodb_n_purge_threads;
207
typedef constrained_check<uint16_t, 2, 0> trinary_constraint;
191
typedef constrained_check<uint32_t, 2, 0> trinary_constraint;
208
192
static trinary_constraint innodb_flush_log_at_trx_commit;
209
193
typedef constrained_check<unsigned int, 99, 0> max_dirty_pages_constraint;
210
194
static max_dirty_pages_constraint innodb_max_dirty_pages_pct;
341
325
virtual ~InnobaseEngine()
344
327
if (innodb_inited) {
345
328
srv_fast_shutdown = (ulint) innobase_fast_shutdown;
346
329
innodb_inited = 0;
347
330
hash_table_free(innobase_open_tables);
348
331
innobase_open_tables = NULL;
349
332
if (innobase_shutdown_for_mysql() != DB_SUCCESS) {
352
335
srv_free_paths_and_sizes();
353
336
if (internal_innobase_data_file_path)
354
337
free(internal_innobase_data_file_path);
355
pthread_mutex_destroy(&innobase_share_mutex);
356
pthread_mutex_destroy(&prepare_commit_mutex);
357
pthread_mutex_destroy(&commit_threads_m);
358
pthread_mutex_destroy(&commit_cond_m);
359
pthread_cond_destroy(&commit_cond);
362
340
/* These get strdup'd from vm variables */
486
464
UNIV_INTERN int doCreateTable(Session &session,
488
const TableIdentifier &identifier,
490
UNIV_INTERN int doRenameTable(Session&, const TableIdentifier &from, const TableIdentifier &to);
491
UNIV_INTERN int doDropTable(Session &session, const TableIdentifier &identifier);
466
const identifier::Table &identifier,
467
const message::Table&);
468
UNIV_INTERN int doRenameTable(Session&, const identifier::Table &from, const identifier::Table &to);
469
UNIV_INTERN int doDropTable(Session &session, const identifier::Table &identifier);
493
UNIV_INTERN virtual bool get_error_message(int error, String *buf);
471
UNIV_INTERN virtual bool get_error_message(int error, String *buf) const;
495
473
UNIV_INTERN uint32_t max_supported_keys() const;
496
474
UNIV_INTERN uint32_t max_supported_key_length() const;
509
487
int doGetTableDefinition(drizzled::Session& session,
510
const TableIdentifier &identifier,
488
const identifier::Table &identifier,
511
489
drizzled::message::Table &table_proto);
513
bool doDoesTableExist(drizzled::Session& session, const TableIdentifier &identifier);
491
bool doDoesTableExist(drizzled::Session& session, const identifier::Table &identifier);
515
493
void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
516
const drizzled::SchemaIdentifier &schema_identifier,
517
drizzled::TableIdentifier::vector &set_of_identifiers);
494
const drizzled::identifier::Schema &schema_identifier,
495
drizzled::identifier::table::vector &set_of_identifiers);
518
496
bool validateCreateTableOption(const std::string &key, const std::string &state);
519
497
void dropTemporarySchema();
544
522
void InnobaseEngine::doGetTableIdentifiers(drizzled::CachedDirectory &directory,
545
const drizzled::SchemaIdentifier &schema_identifier,
546
drizzled::TableIdentifier::vector &set_of_identifiers)
523
const drizzled::identifier::Schema &schema_identifier,
524
drizzled::identifier::table::vector &set_of_identifiers)
548
526
CachedDirectory::Entries entries= directory.getEntries();
528
std::string search_string(schema_identifier.getSchemaName());
530
boost::algorithm::to_lower(search_string);
532
if (search_string.compare("data_dictionary") == 0)
534
set_of_identifiers.push_back(identifier::Table(schema_identifier.getSchemaName(), "SYS_REPLICATION_LOG"));
550
537
for (CachedDirectory::Entries::iterator entry_iter= entries.begin();
551
538
entry_iter != entries.end(); ++entry_iter)
574
561
Using schema_identifier here to stop unused warning, could use
575
562
definition.schema() instead
577
TableIdentifier identifier(schema_identifier.getSchemaName(), definition.name());
564
identifier::Table identifier(schema_identifier.getSchemaName(), definition.name());
578
565
set_of_identifiers.push_back(identifier);
584
bool InnobaseEngine::doDoesTableExist(Session &session, const TableIdentifier &identifier)
571
bool InnobaseEngine::doDoesTableExist(Session &session, const identifier::Table &identifier)
586
573
string proto_path(identifier.getPath());
587
574
proto_path.append(DEFAULT_FILE_EXTENSION);
878
874
DRIZZLE: Note, we didn't change this name to avoid more ifdef forking
879
875
in non-Cursor code.
880
876
@return true if non-transactional tables have been edited */
881
extern "C" UNIV_INTERN
883
879
thd_has_edited_nontrans_tables(
884
880
/*===========================*/
885
void* session) /*!< in: thread handle (Session*) */
881
drizzled::Session *session) /*!< in: thread handle (Session*) */
887
return((ibool)((Session *)session)->transaction.all.hasModifiedNonTransData());
883
return((ibool)session->transaction.all.hasModifiedNonTransData());
890
886
/******************************************************************//**
891
887
Returns true if the thread is executing a SELECT statement.
892
888
@return true if session is executing SELECT */
893
extern "C" UNIV_INTERN
897
const void* session) /*!< in: thread handle (Session*) */
893
const drizzled::Session *session) /*!< in: thread handle (Session*) */
899
return(session_sql_command((const Session*) session) == SQLCOM_SELECT);
895
return(session->getSqlCommand() == SQLCOM_SELECT);
902
898
/******************************************************************//**
903
899
Returns true if the thread supports XA,
904
900
global value of innodb_supports_xa if session is NULL.
905
901
@return true if session has XA support */
906
extern "C" UNIV_INTERN
910
void* ) /*!< in: thread handle (Session*), or NULL to query
906
drizzled::Session* ) /*!< in: thread handle (Session*), or NULL to query
911
907
the global innodb_supports_xa */
913
909
/* TODO: Add support here for per-session value */
967
962
trx_t *trx= session_to_trx(&session);
969
964
uint64_t trx_id= message.transaction_context().transaction_id();
970
ulint error= insert_replication_message(data, message.ByteSize(), trx, trx_id);
965
uint32_t seg_id= message.segment_id();
966
uint64_t end_timestamp= message.transaction_context().end_timestamp();
967
bool is_end_segment= message.end_segment();
968
trx->log_commit_id= TRUE;
969
ulint error= insert_replication_message(data, message.ByteSize(), trx, trx_id,
970
end_timestamp, is_end_segment, seg_id);
1168
1169
/*************************************************************//**
1169
1170
Prints info of a Session object (== user session thread) to the given file. */
1170
extern "C" UNIV_INTERN
1172
1173
innobase_mysql_print_thd(
1173
1174
/*=====================*/
1174
1175
FILE* f, /*!< in: output stream */
1175
void * in_session, /*!< in: pointer to a Drizzle Session object */
1176
drizzled::Session *in_session, /*!< in: pointer to a Drizzle Session object */
1176
1177
uint ) /*!< in: max query length to print, or 0 to
1177
1178
use the default max length */
1179
Session *session= reinterpret_cast<Session *>(in_session);
1180
drizzled::identifier::User::const_shared_ptr user_identifier(session->user());
1180
drizzled::identifier::user::ptr user_identifier(in_session->user());
1183
1183
"Drizzle thread %"PRIu64", query id %"PRIu64", %s, %s, %s ",
1184
static_cast<uint64_t>(session->getSessionId()),
1185
static_cast<uint64_t>(session->getQueryId()),
1184
static_cast<uint64_t>(in_session->getSessionId()),
1185
static_cast<uint64_t>(in_session->getQueryId()),
1186
getServerHostname().c_str(),
1187
1187
user_identifier->address().c_str(),
1188
1188
user_identifier->username().c_str()
1190
fprintf(f, "\n%s", session->getQueryString()->c_str());
1190
fprintf(f, "\n%s", in_session->getQueryString()->c_str());
1194
1194
/******************************************************************//**
1195
1195
Get the variable length bounds of the given character set. */
1196
extern "C" UNIV_INTERN
1198
1198
innobase_get_cset_width(
1199
1199
/*====================*/
1270
1270
my_casedn_str(system_charset_info, a);
1273
/**********************************************************************//**
1274
Determines the connection character set.
1275
@return connection character set */
1276
extern "C" UNIV_INTERN
1278
innobase_get_charset(
1279
/*=================*/
1280
void* mysql_session) /*!< in: MySQL thread handle */
1282
return static_cast<Session*>(mysql_session)->charset();
1285
extern "C" UNIV_INTERN
1287
1275
innobase_isspace(
1288
1276
const void *cs,
1289
1277
char char_to_test)
1291
return my_isspace(static_cast<const CHARSET_INFO *>(cs), char_to_test);
1296
innobase_fast_mutex_init(
1297
os_fast_mutex_t* fast_mutex)
1299
return pthread_mutex_init(fast_mutex, MY_MUTEX_INIT_FAST);
1302
/**********************************************************************//**
1303
Determines the current SQL statement.
1304
@return SQL statement string */
1305
extern "C" UNIV_INTERN
1309
void* session, /*!< in: MySQL thread handle */
1310
size_t* length) /*!< out: length of the SQL statement */
1312
return static_cast<Session*>(session)->getQueryStringCopy(*length);
1279
return my_isspace(static_cast<const charset_info_st *>(cs), char_to_test);
1315
1282
#if defined (__WIN__) && defined (MYSQL_DYNAMIC_PLUGIN)
1316
1283
/*******************************************************************//**
1317
1284
Map an OS error to an errno value. The OS error number is stored in
1318
1285
_doserrno and the mapped value is stored in errno) */
1322
1288
unsigned long); /*!< in: OS error value */
1404
1370
/*********************************************************************//**
1405
1371
Creates a temporary file.
1406
1372
@return temporary file descriptor, or < 0 on error */
1407
extern "C" UNIV_INTERN
1409
1375
innobase_mysql_tmpfile(void)
1410
1376
/*========================*/
1413
int fd = mysql_tmpfile("ib");
1379
int fd = ::drizzled::tmpfile("ib");
1415
1381
/* Copy the file descriptor, so that the additional resources
1416
1382
allocated by create_temp_file() can be freed by invoking
1667
1633
ulint buflen, /*!< in: length of buf, in bytes */
1668
1634
const char* id, /*!< in: identifier to convert */
1669
1635
ulint idlen, /*!< in: length of id, in bytes */
1670
void* session,/*!< in: MySQL connection thread, or NULL */
1636
drizzled::Session *session,/*!< in: MySQL connection thread, or NULL */
1671
1637
ibool file_id)/*!< in: TRUE=id is a table or database name;
1672
1638
FALSE=id is an UTF-8 string */
1674
1640
char nz[NAME_LEN + 1];
1675
char nz2[NAME_LEN + 1 + sizeof srv_mysql50_table_name_prefix];
1641
const size_t nz2_size= NAME_LEN + 1 + srv_mysql50_table_name_prefix.size();
1642
boost::scoped_array<char> nz2(new char[nz2_size]);
1677
1644
const char* s = id;
1752
1719
ulint buflen, /*!< in: length of buf, in bytes */
1753
1720
const char* id, /*!< in: identifier to convert */
1754
1721
ulint idlen, /*!< in: length of id, in bytes */
1755
void* session,/*!< in: MySQL connection thread, or NULL */
1722
drizzled::Session *session,/*!< in: MySQL connection thread, or NULL */
1756
1723
ibool table_id)/*!< in: TRUE=id is a table or database name;
1757
1724
FALSE=id is an index name */
1800
1767
/**********************************************************************//**
1801
1768
Determines if the currently running transaction has been interrupted.
1802
1769
@return TRUE if interrupted */
1803
extern "C" UNIV_INTERN
1805
1772
trx_is_interrupted(
1806
1773
/*===============*/
1807
1774
trx_t* trx) /*!< in: transaction */
1809
return(trx && trx->mysql_thd && static_cast<Session*>(trx->mysql_thd)->getKilled());
1776
return(trx && trx->mysql_thd && trx->mysql_thd->getKilled());
1812
1779
/**********************************************************************//**
1813
1780
Determines if the currently running transaction is in strict mode.
1814
1781
@return TRUE if strict */
1815
extern "C" UNIV_INTERN
2010
1977
if (format_id >= 0) {
2011
innobase_file_format_max=
2012
trx_sys_file_format_id_to_name((uint)format_id);
1978
innobase_file_format_max.assign(
1979
trx_sys_file_format_id_to_name((uint)format_id));
2014
1981
/* Update the max format id in the system tablespace. */
2015
char name_buff[100];
2016
strcpy(name_buff, innobase_file_format_max.c_str());
2017
if (trx_sys_file_format_max_set(format_id, (const char **)&name_buff))
1982
const char *name_buff;
1984
if (trx_sys_file_format_max_set(format_id, &name_buff))
2019
errmsg_printf(ERRMSG_LVL_WARN,
1986
errmsg_printf(error::WARN,
2020
1987
" [Info] InnoDB: the file format in the system "
2021
1988
"tablespace is now set to %s.\n", name_buff);
2022
1989
innobase_file_format_max= name_buff;
2104
2072
#ifdef UNIV_DEBUG
2105
2073
static const char test_filename[] = "-@";
2106
char test_tablename[sizeof test_filename
2107
+ sizeof srv_mysql50_table_name_prefix];
2108
if ((sizeof test_tablename) - 1
2109
!= filename_to_tablename(test_filename, test_tablename,
2110
sizeof test_tablename)
2111
|| strncmp(test_tablename,
2112
srv_mysql50_table_name_prefix,
2113
sizeof srv_mysql50_table_name_prefix)
2114
|| strcmp(test_tablename
2115
+ sizeof srv_mysql50_table_name_prefix,
2074
const size_t test_tablename_size= sizeof test_filename
2075
+ srv_mysql50_table_name_prefix.size();
2076
boost::scoped_array test_tablename(new char[test_tablename_size]);
2077
if ((test_tablename_size) - 1
2078
!= filename_to_tablename(test_filename, test_tablename.get(),
2079
test_tablename_size)
2080
|| strncmp(test_tablename.get(),
2081
srv_mysql50_table_name_prefix.c_str(),
2082
srv_mysql50_table_name_prefix.size())
2083
|| strcmp(test_tablename.get()
2084
+ srv_mysql50_table_name_prefix.size(),
2116
2085
test_filename)) {
2117
errmsg_printf(ERRMSG_LVL_ERROR, "tablename encoding has been changed");
2086
errmsg_printf(error::ERROR, "tablename encoding has been changed");
2120
2089
#endif /* UNIV_DEBUG */
2219
2187
srv_max_file_format_at_startup */
2220
2188
if (innobase_file_format_validate_and_set(innobase_file_format_max.c_str()) < 0)
2222
errmsg_printf(ERRMSG_LVL_ERROR, _("InnoDB: invalid "
2223
"innodb_file_format_max value: "
2224
"should be any value up to %s or its "
2225
"equivalent numeric id"),
2226
trx_sys_file_format_id_to_name(DICT_TF_FORMAT_MAX));
2190
errmsg_printf(error::ERROR, _("InnoDB: invalid innodb_file_format_max value: "
2191
"should be any value up to %s or its equivalent numeric id"),
2192
trx_sys_file_format_id_to_name(DICT_TF_FORMAT_MAX));
2227
2193
goto mem_free_and_error;
2324
2288
innobase_open_tables = hash_create(200);
2325
pthread_mutex_init(&innobase_share_mutex, MY_MUTEX_INIT_FAST);
2326
pthread_mutex_init(&prepare_commit_mutex, MY_MUTEX_INIT_FAST);
2327
pthread_mutex_init(&commit_threads_m, MY_MUTEX_INIT_FAST);
2328
pthread_mutex_init(&commit_cond_m, MY_MUTEX_INIT_FAST);
2329
pthread_cond_init(&commit_cond, NULL);
2330
2289
innodb_inited= 1;
2332
2291
actuall_engine_ptr->dropTemporarySchema();
2334
status_table_function_ptr= new InnodbStatusTool;
2293
context.add(new InnodbStatusTool);
2336
2294
context.add(innodb_engine_ptr);
2338
context.add(status_table_function_ptr);
2340
cmp_tool= new(std::nothrow)CmpTool(false);
2341
context.add(cmp_tool);
2343
cmp_reset_tool= new(std::nothrow)CmpTool(true);
2344
context.add(cmp_reset_tool);
2346
cmp_mem_tool= new(std::nothrow)CmpmemTool(false);
2347
context.add(cmp_mem_tool);
2349
cmp_mem_reset_tool= new(std::nothrow)CmpmemTool(true);
2350
context.add(cmp_mem_reset_tool);
2352
innodb_trx_tool= new(std::nothrow)InnodbTrxTool("INNODB_TRX");
2353
context.add(innodb_trx_tool);
2355
innodb_locks_tool= new(std::nothrow)InnodbTrxTool("INNODB_LOCKS");
2356
context.add(innodb_locks_tool);
2358
innodb_lock_waits_tool= new(std::nothrow)InnodbTrxTool("INNODB_LOCK_WAITS");
2359
context.add(innodb_lock_waits_tool);
2361
innodb_sys_tables_tool= new(std::nothrow)InnodbSysTablesTool();
2362
context.add(innodb_sys_tables_tool);
2364
innodb_sys_tablestats_tool= new(std::nothrow)InnodbSysTableStatsTool();
2365
context.add(innodb_sys_tablestats_tool);
2367
innodb_sys_indexes_tool= new(std::nothrow)InnodbSysIndexesTool();
2368
context.add(innodb_sys_indexes_tool);
2370
innodb_sys_columns_tool= new(std::nothrow)InnodbSysColumnsTool();
2371
context.add(innodb_sys_columns_tool);
2373
innodb_sys_fields_tool= new(std::nothrow)InnodbSysFieldsTool();
2374
context.add(innodb_sys_fields_tool);
2376
innodb_sys_foreign_tool= new(std::nothrow)InnodbSysForeignTool();
2377
context.add(innodb_sys_foreign_tool);
2379
innodb_sys_foreign_cols_tool= new(std::nothrow)InnodbSysForeignColsTool();
2380
context.add(innodb_sys_foreign_cols_tool);
2382
context.add(new(std::nothrow)InnodbInternalTables());
2383
context.add(new(std::nothrow)InnodbReplicationTable());
2295
context.add(new CmpTool(false));
2296
context.add(new CmpTool(true));
2297
context.add(new CmpmemTool(false));
2298
context.add(new CmpmemTool(true));
2299
context.add(new InnodbTrxTool("INNODB_TRX"));
2300
context.add(new InnodbTrxTool("INNODB_LOCKS"));
2301
context.add(new InnodbTrxTool("INNODB_LOCK_WAITS"));
2302
context.add(new InnodbSysTablesTool());
2303
context.add(new InnodbSysTableStatsTool());
2304
context.add(new InnodbSysIndexesTool());
2305
context.add(new InnodbSysColumnsTool());
2306
context.add(new InnodbSysFieldsTool());
2307
context.add(new InnodbSysForeignTool());
2308
context.add(new InnodbSysForeignColsTool());
2309
context.add(new InnodbInternalTables());
2310
context.add(new InnodbReplicationTable());
2385
2312
if (innobase_use_replication_log)
2387
replication_logger= new(std::nothrow)ReplicationLog();
2314
ReplicationLog *replication_logger= new ReplicationLog();
2388
2315
context.add(replication_logger);
2389
2316
ReplicationLog::setup(replication_logger);
2436
2363
innodb_file_format_max_validate));
2437
2364
context.registerVariable(new sys_var_constrained_value_readonly<size_t>("buffer_pool_size", innobase_buffer_pool_size));
2438
2365
context.registerVariable(new sys_var_constrained_value_readonly<int64_t>("log_file_size", innobase_log_file_size));
2439
context.registerVariable(new sys_var_constrained_value_readonly<uint16_t>("flush_log_at_trx_commit",
2366
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("flush_log_at_trx_commit",
2440
2367
innodb_flush_log_at_trx_commit));
2441
2368
context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("max_dirty_pages_pct",
2442
2369
innodb_max_dirty_pages_pct));
2571
2499
trx_search_latch_release_if_reserved(trx);
2575
|| (!session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
2577
2504
/* We were instructed to commit the whole transaction, or
2578
2505
this is an SQL statement end and autocommit is on */
2580
2507
/* We need current binlog position for ibbackup to work.
2581
2508
Note, the position is current because of
2582
2509
prepare_commit_mutex */
2584
if (innobase_commit_concurrency.get() > 0) {
2585
pthread_mutex_lock(&commit_cond_m);
2588
if (commit_threads > innobase_commit_concurrency.get()) {
2510
const uint32_t commit_concurrency= innobase_commit_concurrency.get();
2511
if (commit_concurrency)
2515
boost::mutex::scoped_lock scopedLock(commit_cond_m);
2518
if (commit_threads <= commit_concurrency)
2589
2521
commit_threads--;
2590
pthread_cond_wait(&commit_cond,
2592
pthread_mutex_unlock(&commit_cond_m);
2596
pthread_mutex_unlock(&commit_cond_m);
2522
commit_cond.wait(scopedLock);
2600
/* Store transaction point for binlog
2601
Later logic tests that this is set to _something_. We need
2602
that logic to fire, even though we do not have a real name. */
2603
trx->mysql_log_file_name = "UNUSED";
2526
trx->mysql_log_file_name = NULL;
2604
2527
trx->mysql_log_offset = 0;
2606
2529
/* Don't do write + flush right now. For group commit
2943
/*****************************************************************//**
2944
Normalizes a table name string. A normalized name consists of the
2945
database name catenated to '/' and table name. An example:
2946
test/mytable. On Windows normalization puts both the database name and the
2947
table name always to lower case. */
2950
normalize_table_name(
2951
/*=================*/
2952
char* norm_name, /*!< out: normalized name as a
2953
null-terminated string */
2954
const char* name) /*!< in: table name string */
2956
const char* name_ptr;
2960
/* Scan name from the end */
2962
ptr = strchr(name, '\0')-1;
2964
while (ptr >= name && *ptr != '\\' && *ptr != '/') {
2974
while (ptr >= name && *ptr != '\\' && *ptr != '/') {
2980
memcpy(norm_name, db_ptr, strlen(name) + 1 - (db_ptr - name));
2982
norm_name[name_ptr - db_ptr - 1] = '/';
2985
innobase_casedn_str(norm_name);
2989
2865
/********************************************************************//**
2990
2866
Get the upper limit of the MySQL integral and floating-point type.
2991
2867
@return maximum allowed value for the field */
3152
3028
if (!index_mapping) {
3153
3029
/* Report an error if index_mapping continues to be
3154
3030
NULL and mysql_num_index is a non-zero value */
3155
errmsg_printf(ERRMSG_LVL_ERROR,
3156
"InnoDB: fail to allocate memory for "
3157
"index translation table. Number of "
3158
"Index:%lu, array size:%lu",
3031
errmsg_printf(error::ERROR, "InnoDB: fail to allocate memory for "
3032
"index translation table. Number of Index:%lu, array size:%lu",
3159
3033
mysql_num_index,
3160
3034
share->idx_trans_tbl.array_size);
3176
3050
ib_table, table->key_info[count].name);
3178
3052
if (!index_mapping[count]) {
3179
errmsg_printf(ERRMSG_LVL_ERROR, "Cannot find index %s in InnoDB "
3180
"index dictionary.",
3181
table->key_info[count].name);
3053
errmsg_printf(error::ERROR, "Cannot find index %s in InnoDB index dictionary.",
3054
table->key_info[count].name);
3183
3056
goto func_exit;
3186
3059
/* Double check fetched index has the same
3187
3060
column info as those in mysql key_info. */
3188
if (!innobase_match_index_columns(&table->key_info[count],
3189
index_mapping[count])) {
3190
errmsg_printf(ERRMSG_LVL_ERROR, "Found index %s whose column info "
3191
"does not match that of MySQL.",
3192
table->key_info[count].name);
3061
if (!innobase_match_index_columns(&table->key_info[count], index_mapping[count])) {
3062
errmsg_printf(error::ERROR, "Found index %s whose column info does not match that of MySQL.",
3063
table->key_info[count].name);
3313
3183
case DB_RECORD_NOT_FOUND:
3314
3184
ut_print_timestamp(stderr);
3315
fprintf(stderr, " InnoDB: MySQL and InnoDB data "
3316
"dictionaries are out of sync.\n"
3317
"InnoDB: Unable to find the AUTOINC column "
3318
"%s in the InnoDB table %s.\n"
3319
"InnoDB: We set the next AUTOINC column "
3321
"InnoDB: in effect disabling the AUTOINC "
3322
"next value generation.\n"
3323
"InnoDB: You can either set the next "
3324
"AUTOINC value explicitly using ALTER TABLE\n"
3325
"InnoDB: or fix the data dictionary by "
3326
"recreating the table.\n",
3327
col_name, index->table->name);
3185
errmsg_printf(error::ERROR, "InnoDB: MySQL and InnoDB data dictionaries are out of sync.\n"
3186
"InnoDB: Unable to find the AUTOINC column %s in the InnoDB table %s.\n"
3187
"InnoDB: We set the next AUTOINC column value to 0,\n"
3188
"InnoDB: in effect disabling the AUTOINC next value generation.\n"
3189
"InnoDB: You can either set the next AUTOINC value explicitly using ALTER TABLE\n"
3190
"InnoDB: or fix the data dictionary by recreating the table.\n",
3191
col_name, index->table->name);
3329
3193
/* This will disable the AUTOINC generation. */
3370
3233
getTransactionalEngine()->releaseTemporaryLatches(session);
3373
normalize_table_name(norm_name, identifier.getPath().c_str());
3375
3236
user_session = NULL;
3377
if (!(share=get_share(identifier.getPath().c_str()))) {
3238
std::string search_string(identifier.getSchemaName());
3239
boost::algorithm::to_lower(search_string);
3241
if (search_string.compare("data_dictionary") == 0)
3243
std::string table_name(identifier.getTableName());
3244
boost::algorithm::to_upper(table_name);
3245
if (!(share=get_share(table_name.c_str())))
3252
if (!(share=get_share(identifier.getKeyPath().c_str())))
3382
3258
/* Create buffers for packing the fields of a record. Why
3405
3281
/* Get pointer to a table object in InnoDB dictionary cache */
3406
ib_table = dict_table_get(norm_name, TRUE);
3282
if (search_string.compare("data_dictionary") == 0)
3284
std::string table_name(identifier.getTableName());
3285
boost::algorithm::to_upper(table_name);
3286
ib_table = dict_table_get(table_name.c_str(), TRUE);
3290
ib_table = dict_table_get(identifier.getKeyPath().c_str(), TRUE);
3408
3293
if (NULL == ib_table) {
3409
errmsg_printf(ERRMSG_LVL_ERROR, "Cannot find or open table %s from\n"
3294
errmsg_printf(error::ERROR, "Cannot find or open table %s from\n"
3410
3295
"the internal data dictionary of InnoDB "
3411
3296
"though the .frm file for the\n"
3412
3297
"table exists. Maybe you have deleted and "
3429
3314
return(HA_ERR_NO_SUCH_TABLE);
3432
if (ib_table->ibd_file_missing && !session_tablespace_op(session)) {
3433
errmsg_printf(ERRMSG_LVL_ERROR, "MySQL is trying to open a table handle but "
3317
if (ib_table->ibd_file_missing && ! session->doing_tablespace_operation()) {
3318
errmsg_printf(error::ERROR, "MySQL is trying to open a table handle but "
3434
3319
"the .ibd file for\ntable %s does not exist.\n"
3435
3320
"Have you deleted the .ibd file from the "
3436
3321
"database directory under\nthe MySQL datadir, "
3437
3322
"or have you used DISCARD TABLESPACE?\n"
3438
3323
"See " REFMAN "innodb-troubleshooting.html\n"
3439
3324
"how you can resolve the problem.\n",
3325
identifier.getKeyPath().c_str());
3441
3326
free_share(share);
3442
3327
upd_buff.resize(0);
3443
3328
key_val_buff.resize(0);
3459
3344
key_used_on_scan = primary_key;
3461
3346
if (!innobase_build_index_translation(getTable(), ib_table, share)) {
3462
errmsg_printf(ERRMSG_LVL_ERROR, "Build InnoDB index translation table for"
3463
" Table %s failed", identifier.getPath().c_str());
3347
errmsg_printf(error::ERROR, "Build InnoDB index translation table for"
3348
" Table %s failed", identifier.getKeyPath().c_str());
3466
3351
/* Allocate a buffer for a 'row reference'. A row reference is
4288
4173
n_requested_fields++;
4290
4175
templ->col_no = i;
4176
templ->clust_rec_field_no = dict_col_get_clust_pos(col, clust_index);
4177
ut_ad(templ->clust_rec_field_no != ULINT_UNDEFINED);
4292
4179
if (index == clust_index) {
4293
templ->rec_field_no = dict_col_get_clust_pos(col, index);
4180
templ->rec_field_no = templ->clust_rec_field_no;
4295
4182
templ->rec_field_no = dict_index_get_nth_col_pos(
4299
if (templ->rec_field_no == ULINT_UNDEFINED) {
4300
prebuilt->need_to_access_clustered = TRUE;
4184
if (templ->rec_field_no == ULINT_UNDEFINED) {
4185
prebuilt->need_to_access_clustered = TRUE;
4303
4189
if (field->null_ptr) {
6122
6006
InnobaseEngine::doCreateTable(
6123
/*================*/
6124
Session &session, /*!< in: Session */
6125
Table& form, /*!< in: information on table columns and indexes */
6126
const TableIdentifier &identifier,
6127
message::Table& create_proto)
6007
/*================*/
6008
Session &session, /*!< in: Session */
6009
Table& form, /*!< in: information on table columns and indexes */
6010
const identifier::Table &identifier,
6011
const message::Table& create_proto)
6130
6014
dict_table_t* innobase_table;
6277
6161
if (lex_identified_temp_table)
6278
6162
iflags |= DICT_TF2_TEMPORARY << DICT_TF2_SHIFT;
6280
error= create_table_def(trx, &form, norm_name,
6281
lex_identified_temp_table ? name2 : NULL,
6164
error= create_table_def(trx, &form, identifier.getKeyPath().c_str(),
6165
lex_identified_temp_table ? identifier.getKeyPath().c_str() : NULL,
6284
6168
session.setXaId(trx->id);
6311
6195
for (i = 0; i < form.getShare()->sizeKeys(); i++) {
6312
6196
if (i != (uint) primary_key_no) {
6314
if ((error = create_index(trx, &form, iflags, norm_name,
6198
if ((error = create_index(trx, &form, iflags, identifier.getKeyPath().c_str(),
6321
stmt = innobase_get_stmt(&session, &stmt_len);
6205
stmt= session.getQueryStringCopy(stmt_len);
6324
6208
string generated_create_table;
6325
6209
const char *query= stmt;
6327
if (session_sql_command(&session) == SQLCOM_CREATE_TABLE)
6211
if (session.getSqlCommand() == SQLCOM_CREATE_TABLE)
6329
6213
message::transformTableDefinitionToSql(create_proto,
6330
6214
generated_create_table,
6335
6219
error = row_table_add_foreign_constraints(trx,
6336
6220
query, strlen(query),
6221
identifier.getKeyPath().c_str(),
6338
6222
lex_identified_temp_table);
6225
case DB_PARENT_NO_INDEX:
6226
push_warning_printf(
6227
&session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
6228
HA_ERR_CANNOT_ADD_FOREIGN,
6229
"Create table '%s' with foreign key constraint"
6230
" failed. There is no index in the referenced"
6231
" table where the referenced columns appear"
6232
" as the first columns.\n", identifier.getKeyPath().c_str());
6235
case DB_CHILD_NO_INDEX:
6236
push_warning_printf(
6237
&session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
6238
HA_ERR_CANNOT_ADD_FOREIGN,
6239
"Create table '%s' with foreign key constraint"
6240
" failed. There is no index in the referencing"
6241
" table where referencing columns appear"
6242
" as the first columns.\n", identifier.getKeyPath().c_str());
6340
6246
error = convert_error_code_to_mysql(error, iflags, NULL);
6505
6411
InnobaseEngine::doDropTable(
6506
6412
/*======================*/
6507
6413
Session &session,
6508
const TableIdentifier &identifier)
6414
const identifier::Table &identifier)
6511
6417
trx_t* parent_trx;
6513
char norm_name[1000];
6515
6420
ut_a(identifier.getPath().length() < 1000);
6517
/* Strangely, MySQL passes the table name without the '.frm'
6518
extension, in contrast to ::create */
6519
normalize_table_name(norm_name, identifier.getPath().c_str());
6422
std::string search_string(identifier.getSchemaName());
6423
boost::algorithm::to_lower(search_string);
6425
if (search_string.compare("data_dictionary") == 0)
6427
return HA_ERR_TABLE_READONLY;
6521
6430
/* Get the transaction associated with the current session, or create one
6522
6431
if not yet created */
6683
6596
innobase_rename_table(
6684
6597
/*==================*/
6685
6598
trx_t* trx, /*!< in: transaction */
6686
const char* from, /*!< in: old name of the table */
6687
const char* to, /*!< in: new name of the table */
6599
const identifier::Table &from,
6600
const identifier::Table &to,
6688
6601
ibool lock_and_commit)
6689
6602
/*!< in: TRUE=lock data dictionary and commit */
6692
char norm_to[FN_REFLEN];
6693
char norm_from[FN_REFLEN];
6695
6606
srv_lower_case_table_names = TRUE;
6697
normalize_table_name(norm_to, to);
6698
normalize_table_name(norm_from, from);
6700
6608
/* Serialize data dictionary operations with dictionary mutex:
6701
6609
no deadlocks can occur then in these operations */
6704
6612
row_mysql_lock_data_dictionary(trx);
6707
error = row_rename_table_for_mysql(
6708
norm_from, norm_to, trx, lock_and_commit);
6615
error = row_rename_table_for_mysql(from.getKeyPath().c_str(), to.getKeyPath().c_str(), trx, lock_and_commit);
6710
6617
if (error != DB_SUCCESS) {
6711
6618
FILE* ef = dict_foreign_err_file;
6713
6620
fputs("InnoDB: Renaming table ", ef);
6714
ut_print_name(ef, trx, TRUE, norm_from);
6621
ut_print_name(ef, trx, TRUE, from.getKeyPath().c_str());
6715
6622
fputs(" to ", ef);
6716
ut_print_name(ef, trx, TRUE, norm_to);
6623
ut_print_name(ef, trx, TRUE, to.getKeyPath().c_str());
6717
6624
fputs(" failed!\n", ef);
7241
7159
innodb_crash_recovery is set to a high value. */
7242
7160
stats.delete_length = 0;
7244
/* lock the data dictionary to avoid races with
7245
ibd_file_missing and tablespace_discarded */
7246
row_mysql_lock_data_dictionary(prebuilt->trx);
7248
/* ib_table->space must be an existent tablespace */
7249
if (!ib_table->ibd_file_missing
7250
&& !ib_table->tablespace_discarded) {
7252
stats.delete_length =
7253
fsp_get_available_space_in_free_extents(
7254
ib_table->space) * 1024;
7164
avail_space = fsp_get_available_space_in_free_extents(ib_table->space);
7166
if (avail_space == ULLINT_UNDEFINED) {
7257
7167
Session* session;
7259
7169
session= getTable()->in_use;
7758
7666
db_name[i] = 0;
7759
ulen= TableIdentifier::filename_to_tablename(db_name, uname, sizeof(uname));
7667
ulen= identifier::Table::filename_to_tablename(db_name, uname, sizeof(uname));
7760
7668
LEX_STRING *tmp_referenced_db = session->make_lex_string(NULL, uname, ulen, true);
7762
7670
/* Table name */
7763
7671
tmp_buff += i + 1;
7764
ulen= TableIdentifier::filename_to_tablename(tmp_buff, uname, sizeof(uname));
7672
ulen= identifier::Table::filename_to_tablename(tmp_buff, uname, sizeof(uname));
7765
7673
LEX_STRING *tmp_referenced_table = session->make_lex_string(NULL, uname, ulen, true);
7767
7675
/** Foreign Fields **/
8871
8775
finds charset information and returns length of prefix_len characters in the
8872
8776
index field in bytes.
8873
8777
@return number of bytes occupied by the first n characters */
8874
extern "C" UNIV_INTERN
8876
innobase_get_at_most_n_mbchars(
8877
/*===========================*/
8878
ulint charset_id, /*!< in: character set id */
8879
ulint prefix_len, /*!< in: prefix length in bytes of the index
8880
(this has to be divided by mbmaxlen to get the
8881
number of CHARACTERS n in the prefix) */
8882
ulint data_len, /*!< in: length of the string in bytes */
8883
const char* str); /*!< in: character string */
8886
8780
innobase_get_at_most_n_mbchars(
9232
9126
"Purge threads can be either 0 or 1. Defalut is 0.");
9233
9127
context("file-per-table",
9234
9128
po::value<bool>(&srv_file_per_table)->default_value(false)->zero_tokens(),
9235
"Stores each InnoDB table to an .ibd file in the database dir.");
9236
context("file-format",
9237
po::value<string>(&innobase_file_format_name)->default_value("Antelope"),
9238
"File format to use for new tables in .ibd files.");
9129
"Stores each InnoDB table to an .ibd file in the database dir.");
9239
9130
context("file-format-max",
9240
9131
po::value<string>(&innobase_file_format_max)->default_value("Antelope"),
9241
9132
"The highest file format in the tablespace.");
9242
9133
context("file-format-check",
9243
9134
po::value<bool>(&innobase_file_format_check)->default_value(true)->zero_tokens(),
9244
9135
"Whether to perform system file format check.");
9136
context("file-format",
9137
po::value<string>(&innobase_file_format_name)->default_value("Antelope"),
9138
"File format to use for new tables in .ibd files.");
9245
9139
context("flush-log-at-trx-commit",
9246
9140
po::value<trinary_constraint>(&innodb_flush_log_at_trx_commit)->default_value(1),
9247
9141
"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).");
9276
9170
po::value<additional_mem_pool_constraint>(&innobase_additional_mem_pool_size)->default_value(8*1024*1024L),
9277
9171
"Size of a memory pool InnoDB uses to store data dictionary information and other internal data structures.");
9278
9172
context("autoextend-increment",
9279
po::value<autoextend_constraint>(&innodb_auto_extend_increment)->default_value(8L),
9173
po::value<autoextend_constraint>(&innodb_auto_extend_increment)->default_value(64L),
9280
9174
"Data file autoextend increment in megabytes");
9281
9175
context("buffer-pool-size",
9282
9176
po::value<buffer_pool_constraint>(&innobase_buffer_pool_size)->default_value(128*1024*1024L),
9335
9229
"InnoDB version");
9336
9230
context("use-internal-malloc",
9337
9231
"Use InnoDB's internal memory allocator instal of the OS memory allocator.");
9232
context("disable-native-aio",
9233
_("Do not use Native AIO library for IO, even if available"));
9338
9234
context("change-buffering",
9339
9235
po::value<string>(&innobase_change_buffering),
9340
9236
"Buffer changes to reduce random access: OFF, ON, inserting, deleting, changing, or purging.");
9349
9245
po::value<bool>(&strict_mode)->default_value(false)->zero_tokens(),
9350
9246
"Use strict mode when evaluating create options.");
9351
9247
context("replication-log",
9352
po::value<bool>(&innobase_use_replication_log)->default_value(false),
9248
po::value<bool>(&innobase_use_replication_log)->default_value(false)->zero_tokens(),
9353
9249
_("Enable internal replication log."));
9354
9250
context("lock-wait-timeout",
9355
9251
po::value<lock_wait_constraint>(&lock_wait_timeout)->default_value(50),