1
1
/*****************************************************************************
3
Copyright (C) 2000, 2010, MySQL AB & Innobase Oy. All Rights Reserved.
4
Copyright (C) 2008, 2009 Google Inc.
5
Copyright (C) 2009, Percona Inc.
3
Copyright (c) 2000, 2010, MySQL AB & Innobase Oy. All Rights Reserved.
4
Copyright (c) 2008, 2009 Google Inc.
5
Copyright (c) 2009, Percona Inc.
7
7
Portions of this file contain modifications contributed and copyrighted by
8
8
Google, Inc. Those modifications are gratefully acknowledged and are described
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/plugin/xa_storage_engine.h>
64
#include <drizzled/plugin/daemon.h>
65
#include <drizzled/memory/multi_malloc.h>
66
#include <drizzled/pthread_globals.h>
67
#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/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"
69
70
#include <drizzled/transaction_services.h>
70
#include <drizzled/message/statement_transform.h>
71
#include "drizzled/message/statement_transform.h"
72
73
#include <boost/algorithm/string.hpp>
73
74
#include <boost/program_options.hpp>
74
#include <boost/scoped_array.hpp>
75
75
#include <boost/filesystem.hpp>
76
76
#include <drizzled/module/option_map.h>
77
77
#include <iostream>
125
128
#include <sstream>
126
129
#include <string>
128
#include <plugin/innobase/handler/status_function.h>
129
#include <plugin/innobase/handler/replication_log.h>
131
#include "plugin/innobase/handler/status_function.h"
132
#include "plugin/innobase/handler/replication_log.h"
131
134
#include <google/protobuf/io/zero_copy_stream.h>
132
135
#include <google/protobuf/io/zero_copy_stream_impl.h>
133
136
#include <google/protobuf/io/coded_stream.h>
134
137
#include <google/protobuf/text_format.h>
136
#include <boost/thread/mutex.hpp>
138
139
using namespace std;
139
140
using namespace drizzled;
141
142
/** to protect innobase_open_files */
142
static boost::mutex innobase_share_mutex;
143
static pthread_mutex_t innobase_share_mutex;
144
144
/** to force correct commit order in binlog */
145
static pthread_mutex_t prepare_commit_mutex;
145
146
static ulong commit_threads = 0;
146
static boost::condition_variable commit_cond;
147
static boost::mutex commit_cond_m;
147
static pthread_mutex_t commit_threads_m;
148
static pthread_cond_t commit_cond;
149
static pthread_mutex_t commit_cond_m;
148
150
static bool innodb_inited = 0;
150
152
#define INSIDE_HA_INNOBASE_CC
160
162
#endif /* MYSQL_DYNAMIC_PLUGIN && __WIN__ */
162
164
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;
164
183
typedef constrained_check<uint32_t, UINT32_MAX, 10> open_files_constraint;
165
184
static open_files_constraint innobase_open_files;
166
185
typedef constrained_check<uint32_t, 10, 1> mirrored_log_groups_constraint;
185
204
static purge_batch_constraint innodb_purge_batch_size;
186
205
typedef constrained_check<uint32_t, 1, 0> purge_threads_constraint;
187
206
static purge_threads_constraint innodb_n_purge_threads;
188
typedef constrained_check<uint32_t, 2, 0> trinary_constraint;
207
typedef constrained_check<uint16_t, 2, 0> trinary_constraint;
189
208
static trinary_constraint innodb_flush_log_at_trx_commit;
190
209
typedef constrained_check<unsigned int, 99, 0> max_dirty_pages_constraint;
191
210
static max_dirty_pages_constraint innodb_max_dirty_pages_pct;
462
486
UNIV_INTERN int doCreateTable(Session &session,
464
const identifier::Table &identifier,
488
const TableIdentifier &identifier,
465
489
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);
490
UNIV_INTERN int doRenameTable(Session&, const TableIdentifier &from, const TableIdentifier &to);
491
UNIV_INTERN int doDropTable(Session &session, const TableIdentifier &identifier);
469
UNIV_INTERN virtual bool get_error_message(int error, String *buf) const;
493
UNIV_INTERN virtual bool get_error_message(int error, String *buf);
471
495
UNIV_INTERN uint32_t max_supported_keys() const;
472
496
UNIV_INTERN uint32_t max_supported_key_length() const;
485
509
int doGetTableDefinition(drizzled::Session& session,
486
const identifier::Table &identifier,
510
const TableIdentifier &identifier,
487
511
drizzled::message::Table &table_proto);
489
bool doDoesTableExist(drizzled::Session& session, const identifier::Table &identifier);
513
bool doDoesTableExist(drizzled::Session& session, const TableIdentifier &identifier);
491
515
void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
492
const drizzled::identifier::Schema &schema_identifier,
493
drizzled::identifier::Table::vector &set_of_identifiers);
516
const drizzled::SchemaIdentifier &schema_identifier,
517
drizzled::TableIdentifier::vector &set_of_identifiers);
494
518
bool validateCreateTableOption(const std::string &key, const std::string &state);
495
519
void dropTemporarySchema();
520
544
void InnobaseEngine::doGetTableIdentifiers(drizzled::CachedDirectory &directory,
521
const drizzled::identifier::Schema &schema_identifier,
522
drizzled::identifier::Table::vector &set_of_identifiers)
545
const drizzled::SchemaIdentifier &schema_identifier,
546
drizzled::TableIdentifier::vector &set_of_identifiers)
524
548
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
550
for (CachedDirectory::Entries::iterator entry_iter= entries.begin();
536
551
entry_iter != entries.end(); ++entry_iter)
559
574
Using schema_identifier here to stop unused warning, could use
560
575
definition.schema() instead
562
identifier::Table identifier(schema_identifier.getSchemaName(), definition.name());
577
TableIdentifier identifier(schema_identifier.getSchemaName(), definition.name());
563
578
set_of_identifiers.push_back(identifier);
569
bool InnobaseEngine::doDoesTableExist(Session &session, const identifier::Table &identifier)
584
bool InnobaseEngine::doDoesTableExist(Session &session, const TableIdentifier &identifier)
571
586
string proto_path(identifier.getPath());
572
587
proto_path.append(DEFAULT_FILE_EXTENSION);
872
878
DRIZZLE: Note, we didn't change this name to avoid more ifdef forking
873
879
in non-Cursor code.
874
880
@return true if non-transactional tables have been edited */
881
extern "C" UNIV_INTERN
877
883
thd_has_edited_nontrans_tables(
878
884
/*===========================*/
879
drizzled::Session *session) /*!< in: thread handle (Session*) */
885
void* session) /*!< in: thread handle (Session*) */
881
return((ibool)session->transaction.all.hasModifiedNonTransData());
887
return((ibool)((Session *)session)->transaction.all.hasModifiedNonTransData());
884
890
/******************************************************************//**
885
891
Returns true if the thread is executing a SELECT statement.
886
892
@return true if session is executing SELECT */
893
extern "C" UNIV_INTERN
891
const drizzled::Session *session) /*!< in: thread handle (Session*) */
897
const void* session) /*!< in: thread handle (Session*) */
893
return(session->getSqlCommand() == SQLCOM_SELECT);
899
return(session_sql_command((const Session*) session) == SQLCOM_SELECT);
896
902
/******************************************************************//**
897
903
Returns true if the thread supports XA,
898
904
global value of innodb_supports_xa if session is NULL.
899
905
@return true if session has XA support */
906
extern "C" UNIV_INTERN
904
drizzled::Session* ) /*!< in: thread handle (Session*), or NULL to query
910
void* ) /*!< in: thread handle (Session*), or NULL to query
905
911
the global innodb_supports_xa */
907
913
/* TODO: Add support here for per-session value */
927
933
/******************************************************************//**
928
934
Set the time waited for the lock for the current query. */
935
extern "C" UNIV_INTERN
931
937
thd_set_lock_wait_time(
932
938
/*===================*/
933
drizzled::Session* in_session, /*!< in: thread handle (THD*) */
939
void* thd, /*!< in: thread handle (THD*) */
934
940
ulint value) /*!< in: time waited for the lock */
937
in_session->utime_after_lock+= value;
943
static_cast<Session*>(thd)->utime_after_lock+= value;
940
947
/********************************************************************//**
960
967
trx_t *trx= session_to_trx(&session);
962
969
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);
970
ulint error= insert_replication_message(data, message.ByteSize(), trx, trx_id);
1167
1168
/*************************************************************//**
1168
1169
Prints info of a Session object (== user session thread) to the given file. */
1170
extern "C" UNIV_INTERN
1171
1172
innobase_mysql_print_thd(
1172
1173
/*=====================*/
1173
1174
FILE* f, /*!< in: output stream */
1174
drizzled::Session *in_session, /*!< in: pointer to a Drizzle Session object */
1175
void * in_session, /*!< in: pointer to a Drizzle Session object */
1175
1176
uint ) /*!< in: max query length to print, or 0 to
1176
1177
use the default max length */
1178
drizzled::identifier::User::const_shared_ptr user_identifier(in_session->user());
1179
Session *session= reinterpret_cast<Session *>(in_session);
1180
drizzled::identifier::User::const_shared_ptr user_identifier(session->user());
1181
1183
"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()),
1184
getServerHostname().c_str(),
1184
static_cast<uint64_t>(session->getSessionId()),
1185
static_cast<uint64_t>(session->getQueryId()),
1185
1187
user_identifier->address().c_str(),
1186
1188
user_identifier->username().c_str()
1188
fprintf(f, "\n%s", in_session->getQueryString()->c_str());
1190
fprintf(f, "\n%s", session->getQueryString()->c_str());
1192
1194
/******************************************************************//**
1193
1195
Get the variable length bounds of the given character set. */
1196
extern "C" UNIV_INTERN
1196
1198
innobase_get_cset_width(
1197
1199
/*====================*/
1277
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);
1280
1315
#if defined (__WIN__) && defined (MYSQL_DYNAMIC_PLUGIN)
1281
1316
/*******************************************************************//**
1282
1317
Map an OS error to an errno value. The OS error number is stored in
1283
1318
_doserrno and the mapped value is stored in errno) */
1286
1322
unsigned long); /*!< in: OS error value */
1368
1404
/*********************************************************************//**
1369
1405
Creates a temporary file.
1370
1406
@return temporary file descriptor, or < 0 on error */
1407
extern "C" UNIV_INTERN
1373
1409
innobase_mysql_tmpfile(void)
1374
1410
/*========================*/
1377
int fd = ::drizzled::tmpfile("ib");
1413
int fd = mysql_tmpfile("ib");
1379
1415
/* Copy the file descriptor, so that the additional resources
1380
1416
allocated by create_temp_file() can be freed by invoking
1631
1667
ulint buflen, /*!< in: length of buf, in bytes */
1632
1668
const char* id, /*!< in: identifier to convert */
1633
1669
ulint idlen, /*!< in: length of id, in bytes */
1634
drizzled::Session *session,/*!< in: MySQL connection thread, or NULL */
1670
void* session,/*!< in: MySQL connection thread, or NULL */
1635
1671
ibool file_id)/*!< in: TRUE=id is a table or database name;
1636
1672
FALSE=id is an UTF-8 string */
1638
1674
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]);
1675
char nz2[NAME_LEN + 1 + sizeof srv_mysql50_table_name_prefix];
1642
1677
const char* s = id;
1717
1752
ulint buflen, /*!< in: length of buf, in bytes */
1718
1753
const char* id, /*!< in: identifier to convert */
1719
1754
ulint idlen, /*!< in: length of id, in bytes */
1720
drizzled::Session *session,/*!< in: MySQL connection thread, or NULL */
1755
void* session,/*!< in: MySQL connection thread, or NULL */
1721
1756
ibool table_id)/*!< in: TRUE=id is a table or database name;
1722
1757
FALSE=id is an index name */
1765
1800
/**********************************************************************//**
1766
1801
Determines if the currently running transaction has been interrupted.
1767
1802
@return TRUE if interrupted */
1803
extern "C" UNIV_INTERN
1770
1805
trx_is_interrupted(
1771
1806
/*===============*/
1772
1807
trx_t* trx) /*!< in: transaction */
1774
return(trx && trx->mysql_thd && trx->mysql_thd->getKilled());
1809
return(trx && trx->mysql_thd && static_cast<Session*>(trx->mysql_thd)->getKilled());
1777
1812
/**********************************************************************//**
1778
1813
Determines if the currently running transaction is in strict mode.
1779
1814
@return TRUE if strict */
1815
extern "C" UNIV_INTERN
1975
2010
if (format_id >= 0) {
1976
innobase_file_format_max.assign(
1977
trx_sys_file_format_id_to_name((uint)format_id));
2011
innobase_file_format_max=
2012
trx_sys_file_format_id_to_name((uint)format_id);
1979
2014
/* 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))
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))
1984
errmsg_printf(error::WARN,
2019
errmsg_printf(ERRMSG_LVL_WARN,
1985
2020
" [Info] InnoDB: the file format in the system "
1986
2021
"tablespace is now set to %s.\n", name_buff);
1987
2022
innobase_file_format_max= name_buff;
2070
2104
#ifdef UNIV_DEBUG
2071
2105
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(),
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,
2083
2116
test_filename)) {
2084
errmsg_printf(error::ERROR, "tablename encoding has been changed");
2117
errmsg_printf(ERRMSG_LVL_ERROR, "tablename encoding has been changed");
2087
2120
#endif /* UNIV_DEBUG */
2185
2219
srv_max_file_format_at_startup */
2186
2220
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));
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));
2191
2227
goto mem_free_and_error;
2286
2324
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);
2287
2330
innodb_inited= 1;
2289
2332
actuall_engine_ptr->dropTemporarySchema();
2291
context.add(new InnodbStatusTool);
2334
status_table_function_ptr= new InnodbStatusTool;
2293
2336
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());
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);
2323
2382
context.add(new(std::nothrow)InnodbInternalTables());
2324
2383
context.add(new(std::nothrow)InnodbReplicationTable());
2326
2385
if (innobase_use_replication_log)
2328
ReplicationLog *replication_logger= new(std::nothrow)ReplicationLog();
2387
replication_logger= new(std::nothrow)ReplicationLog();
2329
2388
context.add(replication_logger);
2330
2389
ReplicationLog::setup(replication_logger);
2377
2436
innodb_file_format_max_validate));
2378
2437
context.registerVariable(new sys_var_constrained_value_readonly<size_t>("buffer_pool_size", innobase_buffer_pool_size));
2379
2438
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",
2439
context.registerVariable(new sys_var_constrained_value_readonly<uint16_t>("flush_log_at_trx_commit",
2381
2440
innodb_flush_log_at_trx_commit));
2382
2441
context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("max_dirty_pages_pct",
2383
2442
innodb_max_dirty_pages_pct));
2513
2571
trx_search_latch_release_if_reserved(trx);
2575
|| (!session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
2518
2577
/* We were instructed to commit the whole transaction, or
2519
2578
this is an SQL statement end and autocommit is on */
2521
2580
/* We need current binlog position for ibbackup to work.
2522
2581
Note, the position is current because of
2523
2582
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)
2584
if (innobase_commit_concurrency.get() > 0) {
2585
pthread_mutex_lock(&commit_cond_m);
2588
if (commit_threads > innobase_commit_concurrency.get()) {
2535
2589
commit_threads--;
2536
commit_cond.wait(scopedLock);
2590
pthread_cond_wait(&commit_cond,
2592
pthread_mutex_unlock(&commit_cond_m);
2596
pthread_mutex_unlock(&commit_cond_m);
2540
trx->mysql_log_file_name = NULL;
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";
2541
2604
trx->mysql_log_offset = 0;
2543
2606
/* 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);
2879
2989
/********************************************************************//**
2880
2990
Get the upper limit of the MySQL integral and floating-point type.
2881
2991
@return maximum allowed value for the field */
3042
3152
if (!index_mapping) {
3043
3153
/* Report an error if index_mapping continues to be
3044
3154
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",
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",
3047
3159
mysql_num_index,
3048
3160
share->idx_trans_tbl.array_size);
3064
3176
ib_table, table->key_info[count].name);
3066
3178
if (!index_mapping[count]) {
3067
errmsg_printf(error::ERROR, "Cannot find index %s in InnoDB index dictionary.",
3068
table->key_info[count].name);
3179
errmsg_printf(ERRMSG_LVL_ERROR, "Cannot find index %s in InnoDB "
3180
"index dictionary.",
3181
table->key_info[count].name);
3070
3183
goto func_exit;
3073
3186
/* Double check fetched index has the same
3074
3187
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);
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);
3197
3313
case DB_RECORD_NOT_FOUND:
3198
3314
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);
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);
3207
3329
/* This will disable the AUTOINC generation. */
3247
3370
getTransactionalEngine()->releaseTemporaryLatches(session);
3373
normalize_table_name(norm_name, identifier.getPath().c_str());
3250
3375
user_session = NULL;
3252
std::string search_string(identifier.getSchemaName());
3253
boost::algorithm::to_lower(search_string);
3377
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
3382
/* Create buffers for packing the fields of a record. Why
3295
3405
/* 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);
3406
ib_table = dict_table_get(norm_name, TRUE);
3307
3408
if (NULL == ib_table) {
3308
errmsg_printf(error::ERROR, "Cannot find or open table %s from\n"
3409
errmsg_printf(ERRMSG_LVL_ERROR, "Cannot find or open table %s from\n"
3309
3410
"the internal data dictionary of InnoDB "
3310
3411
"though the .frm file for the\n"
3311
3412
"table exists. Maybe you have deleted and "
3328
3429
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 "
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 "
3333
3434
"the .ibd file for\ntable %s does not exist.\n"
3334
3435
"Have you deleted the .ibd file from the "
3335
3436
"database directory under\nthe MySQL datadir, "
3336
3437
"or have you used DISCARD TABLESPACE?\n"
3337
3438
"See " REFMAN "innodb-troubleshooting.html\n"
3338
3439
"how you can resolve the problem.\n",
3339
identifier.getKeyPath().c_str());
3340
3441
free_share(share);
3341
3442
upd_buff.resize(0);
3342
3443
key_val_buff.resize(0);
3358
3459
key_used_on_scan = primary_key;
3360
3461
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());
3462
errmsg_printf(ERRMSG_LVL_ERROR, "Build InnoDB index translation table for"
3463
" Table %s failed", identifier.getPath().c_str());
3365
3466
/* Allocate a buffer for a 'row reference'. A row reference is
4189
4288
n_requested_fields++;
4191
4290
templ->col_no = i;
4192
templ->clust_rec_field_no = dict_col_get_clust_pos(col, clust_index);
4193
ut_ad(templ->clust_rec_field_no != ULINT_UNDEFINED);
4195
4292
if (index == clust_index) {
4196
templ->rec_field_no = templ->clust_rec_field_no;
4293
templ->rec_field_no = dict_col_get_clust_pos(col, index);
4198
4295
templ->rec_field_no = dict_index_get_nth_col_pos(
4200
if (templ->rec_field_no == ULINT_UNDEFINED) {
4201
prebuilt->need_to_access_clustered = TRUE;
4299
if (templ->rec_field_no == ULINT_UNDEFINED) {
4300
prebuilt->need_to_access_clustered = TRUE;
4205
4303
if (field->null_ptr) {
6177
6277
if (lex_identified_temp_table)
6178
6278
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,
6280
error= create_table_def(trx, &form, norm_name,
6281
lex_identified_temp_table ? name2 : NULL,
6184
6284
session.setXaId(trx->id);
6211
6311
for (i = 0; i < form.getShare()->sizeKeys(); i++) {
6212
6312
if (i != (uint) primary_key_no) {
6214
if ((error = create_index(trx, &form, iflags, identifier.getKeyPath().c_str(),
6314
if ((error = create_index(trx, &form, iflags, norm_name,
6221
stmt= session.getQueryStringCopy(stmt_len);
6321
stmt = innobase_get_stmt(&session, &stmt_len);
6224
6324
string generated_create_table;
6225
6325
const char *query= stmt;
6227
if (session.getSqlCommand() == SQLCOM_CREATE_TABLE)
6327
if (session_sql_command(&session) == SQLCOM_CREATE_TABLE)
6229
6329
message::transformTableDefinitionToSql(create_proto,
6230
6330
generated_create_table,
6235
6335
error = row_table_add_foreign_constraints(trx,
6236
6336
query, strlen(query),
6237
identifier.getKeyPath().c_str(),
6238
6338
lex_identified_temp_table);
6241
case DB_PARENT_NO_INDEX:
6242
push_warning_printf(
6243
&session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
6244
HA_ERR_CANNOT_ADD_FOREIGN,
6245
"Create table '%s' with foreign key constraint"
6246
" failed. There is no index in the referenced"
6247
" table where the referenced columns appear"
6248
" as the first columns.\n", identifier.getKeyPath().c_str());
6251
case DB_CHILD_NO_INDEX:
6252
push_warning_printf(
6253
&session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
6254
HA_ERR_CANNOT_ADD_FOREIGN,
6255
"Create table '%s' with foreign key constraint"
6256
" failed. There is no index in the referencing"
6257
" table where referencing columns appear"
6258
" as the first columns.\n", identifier.getKeyPath().c_str());
6262
6340
error = convert_error_code_to_mysql(error, iflags, NULL);
6427
6505
InnobaseEngine::doDropTable(
6428
6506
/*======================*/
6429
6507
Session &session,
6430
const identifier::Table &identifier)
6508
const TableIdentifier &identifier)
6433
6511
trx_t* parent_trx;
6513
char norm_name[1000];
6436
6515
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;
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());
6446
6521
/* Get the transaction associated with the current session, or create one
6447
6522
if not yet created */
6608
6683
innobase_rename_table(
6609
6684
/*==================*/
6610
6685
trx_t* trx, /*!< in: transaction */
6611
const identifier::Table &from,
6612
const identifier::Table &to,
6686
const char* from, /*!< in: old name of the table */
6687
const char* to, /*!< in: new name of the table */
6613
6688
ibool lock_and_commit)
6614
6689
/*!< in: TRUE=lock data dictionary and commit */
6692
char norm_to[FN_REFLEN];
6693
char norm_from[FN_REFLEN];
6618
6695
srv_lower_case_table_names = TRUE;
6697
normalize_table_name(norm_to, to);
6698
normalize_table_name(norm_from, from);
6620
6700
/* Serialize data dictionary operations with dictionary mutex:
6621
6701
no deadlocks can occur then in these operations */
6624
6704
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);
6707
error = row_rename_table_for_mysql(
6708
norm_from, norm_to, trx, lock_and_commit);
6629
6710
if (error != DB_SUCCESS) {
6630
6711
FILE* ef = dict_foreign_err_file;
6632
6713
fputs("InnoDB: Renaming table ", ef);
6633
ut_print_name(ef, trx, TRUE, from.getKeyPath().c_str());
6714
ut_print_name(ef, trx, TRUE, norm_from);
6634
6715
fputs(" to ", ef);
6635
ut_print_name(ef, trx, TRUE, to.getKeyPath().c_str());
6716
ut_print_name(ef, trx, TRUE, norm_to);
6636
6717
fputs(" failed!\n", ef);
7171
7241
innodb_crash_recovery is set to a high value. */
7172
7242
stats.delete_length = 0;
7176
avail_space = fsp_get_available_space_in_free_extents(ib_table->space);
7178
if (avail_space == ULLINT_UNDEFINED) {
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;
7179
7257
Session* session;
7181
7259
session= getTable()->in_use;
7678
7758
db_name[i] = 0;
7679
ulen= identifier::Table::filename_to_tablename(db_name, uname, sizeof(uname));
7759
ulen= TableIdentifier::filename_to_tablename(db_name, uname, sizeof(uname));
7680
7760
LEX_STRING *tmp_referenced_db = session->make_lex_string(NULL, uname, ulen, true);
7682
7762
/* Table name */
7683
7763
tmp_buff += i + 1;
7684
ulen= identifier::Table::filename_to_tablename(tmp_buff, uname, sizeof(uname));
7764
ulen= TableIdentifier::filename_to_tablename(tmp_buff, uname, sizeof(uname));
7685
7765
LEX_STRING *tmp_referenced_table = session->make_lex_string(NULL, uname, ulen, true);
7687
7767
/** Foreign Fields **/
8787
8871
finds charset information and returns length of prefix_len characters in the
8788
8872
index field in bytes.
8789
8873
@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 */
8792
8886
innobase_get_at_most_n_mbchars(
9138
9232
"Purge threads can be either 0 or 1. Defalut is 0.");
9139
9233
context("file-per-table",
9140
9234
po::value<bool>(&srv_file_per_table)->default_value(false)->zero_tokens(),
9141
"Stores each InnoDB table to an .ibd file in the database dir.");
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.");
9142
9239
context("file-format-max",
9143
9240
po::value<string>(&innobase_file_format_max)->default_value("Antelope"),
9144
9241
"The highest file format in the tablespace.");
9145
9242
context("file-format-check",
9146
9243
po::value<bool>(&innobase_file_format_check)->default_value(true)->zero_tokens(),
9147
9244
"Whether to perform system file format check.");
9148
context("file-format",
9149
po::value<string>(&innobase_file_format_name)->default_value("Antelope"),
9150
"File format to use for new tables in .ibd files.");
9151
9245
context("flush-log-at-trx-commit",
9152
9246
po::value<trinary_constraint>(&innodb_flush_log_at_trx_commit)->default_value(1),
9153
9247
"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).");
9182
9276
po::value<additional_mem_pool_constraint>(&innobase_additional_mem_pool_size)->default_value(8*1024*1024L),
9183
9277
"Size of a memory pool InnoDB uses to store data dictionary information and other internal data structures.");
9184
9278
context("autoextend-increment",
9185
po::value<autoextend_constraint>(&innodb_auto_extend_increment)->default_value(64L),
9279
po::value<autoextend_constraint>(&innodb_auto_extend_increment)->default_value(8L),
9186
9280
"Data file autoextend increment in megabytes");
9187
9281
context("buffer-pool-size",
9188
9282
po::value<buffer_pool_constraint>(&innobase_buffer_pool_size)->default_value(128*1024*1024L),
9241
9335
"InnoDB version");
9242
9336
context("use-internal-malloc",
9243
9337
"Use InnoDB's internal memory allocator instal of the OS memory allocator.");
9244
context("disable-native-aio",
9245
_("Do not use Native AIO library for IO, even if available"));
9246
9338
context("change-buffering",
9247
9339
po::value<string>(&innobase_change_buffering),
9248
9340
"Buffer changes to reduce random access: OFF, ON, inserting, deleting, changing, or purging.");