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);
1181
1181
"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(),
1185
user_identifier->address().c_str(),
1186
user_identifier->username().c_str()
1182
static_cast<uint64_t>(session->getSessionId()),
1183
static_cast<uint64_t>(session->getQueryId()),
1185
session->getSecurityContext().getIp().c_str(),
1186
session->getSecurityContext().getUser().c_str()
1188
fprintf(f, "\n%s", in_session->getQueryString()->c_str());
1188
fprintf(f, "\n%s", session->getQueryString()->c_str());
1192
1192
/******************************************************************//**
1193
1193
Get the variable length bounds of the given character set. */
1194
extern "C" UNIV_INTERN
1196
1196
innobase_get_cset_width(
1197
1197
/*====================*/
1277
1289
return my_isspace(static_cast<const CHARSET_INFO *>(cs), char_to_test);
1294
innobase_fast_mutex_init(
1295
os_fast_mutex_t* fast_mutex)
1297
return pthread_mutex_init(fast_mutex, MY_MUTEX_INIT_FAST);
1300
/**********************************************************************//**
1301
Determines the current SQL statement.
1302
@return SQL statement string */
1303
extern "C" UNIV_INTERN
1307
void* session, /*!< in: MySQL thread handle */
1308
size_t* length) /*!< out: length of the SQL statement */
1310
return static_cast<Session*>(session)->getQueryStringCopy(*length);
1280
1313
#if defined (__WIN__) && defined (MYSQL_DYNAMIC_PLUGIN)
1281
1314
/*******************************************************************//**
1282
1315
Map an OS error to an errno value. The OS error number is stored in
1283
1316
_doserrno and the mapped value is stored in errno) */
1286
1320
unsigned long); /*!< in: OS error value */
1368
1402
/*********************************************************************//**
1369
1403
Creates a temporary file.
1370
1404
@return temporary file descriptor, or < 0 on error */
1405
extern "C" UNIV_INTERN
1373
1407
innobase_mysql_tmpfile(void)
1374
1408
/*========================*/
1377
int fd = ::drizzled::tmpfile("ib");
1411
int fd = mysql_tmpfile("ib");
1379
1413
/* Copy the file descriptor, so that the additional resources
1380
1414
allocated by create_temp_file() can be freed by invoking
1631
1665
ulint buflen, /*!< in: length of buf, in bytes */
1632
1666
const char* id, /*!< in: identifier to convert */
1633
1667
ulint idlen, /*!< in: length of id, in bytes */
1634
drizzled::Session *session,/*!< in: MySQL connection thread, or NULL */
1668
void* session,/*!< in: MySQL connection thread, or NULL */
1635
1669
ibool file_id)/*!< in: TRUE=id is a table or database name;
1636
1670
FALSE=id is an UTF-8 string */
1638
1672
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]);
1673
char nz2[NAME_LEN + 1 + sizeof srv_mysql50_table_name_prefix];
1642
1675
const char* s = id;
1717
1750
ulint buflen, /*!< in: length of buf, in bytes */
1718
1751
const char* id, /*!< in: identifier to convert */
1719
1752
ulint idlen, /*!< in: length of id, in bytes */
1720
drizzled::Session *session,/*!< in: MySQL connection thread, or NULL */
1753
void* session,/*!< in: MySQL connection thread, or NULL */
1721
1754
ibool table_id)/*!< in: TRUE=id is a table or database name;
1722
1755
FALSE=id is an index name */
1765
1798
/**********************************************************************//**
1766
1799
Determines if the currently running transaction has been interrupted.
1767
1800
@return TRUE if interrupted */
1801
extern "C" UNIV_INTERN
1770
1803
trx_is_interrupted(
1771
1804
/*===============*/
1772
1805
trx_t* trx) /*!< in: transaction */
1774
return(trx && trx->mysql_thd && trx->mysql_thd->getKilled());
1807
return(trx && trx->mysql_thd && static_cast<Session*>(trx->mysql_thd)->getKilled());
1777
1810
/**********************************************************************//**
1778
1811
Determines if the currently running transaction is in strict mode.
1779
1812
@return TRUE if strict */
1813
extern "C" UNIV_INTERN
1975
2008
if (format_id >= 0) {
1976
innobase_file_format_max.assign(
1977
trx_sys_file_format_id_to_name((uint)format_id));
2009
innobase_file_format_max=
2010
trx_sys_file_format_id_to_name((uint)format_id);
1979
2012
/* 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))
2013
char name_buff[100];
2014
strcpy(name_buff, innobase_file_format_max.c_str());
2015
if (trx_sys_file_format_max_set(format_id, (const char **)&name_buff))
1984
errmsg_printf(error::WARN,
2017
errmsg_printf(ERRMSG_LVL_WARN,
1985
2018
" [Info] InnoDB: the file format in the system "
1986
2019
"tablespace is now set to %s.\n", name_buff);
1987
2020
innobase_file_format_max= name_buff;
2070
2102
#ifdef UNIV_DEBUG
2071
2103
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(),
2104
char test_tablename[sizeof test_filename
2105
+ sizeof srv_mysql50_table_name_prefix];
2106
if ((sizeof test_tablename) - 1
2107
!= filename_to_tablename(test_filename, test_tablename,
2108
sizeof test_tablename)
2109
|| strncmp(test_tablename,
2110
srv_mysql50_table_name_prefix,
2111
sizeof srv_mysql50_table_name_prefix)
2112
|| strcmp(test_tablename
2113
+ sizeof srv_mysql50_table_name_prefix,
2083
2114
test_filename)) {
2084
errmsg_printf(error::ERROR, "tablename encoding has been changed");
2115
errmsg_printf(ERRMSG_LVL_ERROR, "tablename encoding has been changed");
2087
2118
#endif /* UNIV_DEBUG */
2185
2217
srv_max_file_format_at_startup */
2186
2218
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));
2220
errmsg_printf(ERRMSG_LVL_ERROR, _("InnoDB: invalid "
2221
"innodb_file_format_max value: "
2222
"should be any value up to %s or its "
2223
"equivalent numeric id"),
2224
trx_sys_file_format_id_to_name(DICT_TF_FORMAT_MAX));
2191
2225
goto mem_free_and_error;
2286
2322
innobase_open_tables = hash_create(200);
2323
pthread_mutex_init(&innobase_share_mutex, MY_MUTEX_INIT_FAST);
2324
pthread_mutex_init(&prepare_commit_mutex, MY_MUTEX_INIT_FAST);
2325
pthread_mutex_init(&commit_threads_m, MY_MUTEX_INIT_FAST);
2326
pthread_mutex_init(&commit_cond_m, MY_MUTEX_INIT_FAST);
2327
pthread_cond_init(&commit_cond, NULL);
2287
2328
innodb_inited= 1;
2289
2330
actuall_engine_ptr->dropTemporarySchema();
2291
context.add(new InnodbStatusTool);
2332
status_table_function_ptr= new InnodbStatusTool;
2293
2334
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());
2336
context.add(status_table_function_ptr);
2338
cmp_tool= new(std::nothrow)CmpTool(false);
2339
context.add(cmp_tool);
2341
cmp_reset_tool= new(std::nothrow)CmpTool(true);
2342
context.add(cmp_reset_tool);
2344
cmp_mem_tool= new(std::nothrow)CmpmemTool(false);
2345
context.add(cmp_mem_tool);
2347
cmp_mem_reset_tool= new(std::nothrow)CmpmemTool(true);
2348
context.add(cmp_mem_reset_tool);
2350
innodb_trx_tool= new(std::nothrow)InnodbTrxTool("INNODB_TRX");
2351
context.add(innodb_trx_tool);
2353
innodb_locks_tool= new(std::nothrow)InnodbTrxTool("INNODB_LOCKS");
2354
context.add(innodb_locks_tool);
2356
innodb_lock_waits_tool= new(std::nothrow)InnodbTrxTool("INNODB_LOCK_WAITS");
2357
context.add(innodb_lock_waits_tool);
2359
innodb_sys_tables_tool= new(std::nothrow)InnodbSysTablesTool();
2360
context.add(innodb_sys_tables_tool);
2362
innodb_sys_tablestats_tool= new(std::nothrow)InnodbSysTableStatsTool();
2363
context.add(innodb_sys_tablestats_tool);
2365
innodb_sys_indexes_tool= new(std::nothrow)InnodbSysIndexesTool();
2366
context.add(innodb_sys_indexes_tool);
2368
innodb_sys_columns_tool= new(std::nothrow)InnodbSysColumnsTool();
2369
context.add(innodb_sys_columns_tool);
2371
innodb_sys_fields_tool= new(std::nothrow)InnodbSysFieldsTool();
2372
context.add(innodb_sys_fields_tool);
2374
innodb_sys_foreign_tool= new(std::nothrow)InnodbSysForeignTool();
2375
context.add(innodb_sys_foreign_tool);
2377
innodb_sys_foreign_cols_tool= new(std::nothrow)InnodbSysForeignColsTool();
2378
context.add(innodb_sys_foreign_cols_tool);
2323
2380
context.add(new(std::nothrow)InnodbInternalTables());
2324
2381
context.add(new(std::nothrow)InnodbReplicationTable());
2326
2383
if (innobase_use_replication_log)
2328
ReplicationLog *replication_logger= new(std::nothrow)ReplicationLog();
2385
replication_logger= new(std::nothrow)ReplicationLog();
2329
2386
context.add(replication_logger);
2330
2387
ReplicationLog::setup(replication_logger);
2377
2434
innodb_file_format_max_validate));
2378
2435
context.registerVariable(new sys_var_constrained_value_readonly<size_t>("buffer_pool_size", innobase_buffer_pool_size));
2379
2436
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",
2437
context.registerVariable(new sys_var_constrained_value_readonly<uint16_t>("flush_log_at_trx_commit",
2381
2438
innodb_flush_log_at_trx_commit));
2382
2439
context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("max_dirty_pages_pct",
2383
2440
innodb_max_dirty_pages_pct));
2513
2569
trx_search_latch_release_if_reserved(trx);
2573
|| (!session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
2518
2575
/* We were instructed to commit the whole transaction, or
2519
2576
this is an SQL statement end and autocommit is on */
2521
2578
/* We need current binlog position for ibbackup to work.
2522
2579
Note, the position is current because of
2523
2580
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)
2582
if (innobase_commit_concurrency.get() > 0) {
2583
pthread_mutex_lock(&commit_cond_m);
2586
if (commit_threads > innobase_commit_concurrency.get()) {
2535
2587
commit_threads--;
2536
commit_cond.wait(scopedLock);
2588
pthread_cond_wait(&commit_cond,
2590
pthread_mutex_unlock(&commit_cond_m);
2594
pthread_mutex_unlock(&commit_cond_m);
2540
trx->mysql_log_file_name = NULL;
2598
/* Store transaction point for binlog
2599
Later logic tests that this is set to _something_. We need
2600
that logic to fire, even though we do not have a real name. */
2601
trx->mysql_log_file_name = "UNUSED";
2541
2602
trx->mysql_log_offset = 0;
2543
2604
/* Don't do write + flush right now. For group commit
2941
/*****************************************************************//**
2942
Normalizes a table name string. A normalized name consists of the
2943
database name catenated to '/' and table name. An example:
2944
test/mytable. On Windows normalization puts both the database name and the
2945
table name always to lower case. */
2948
normalize_table_name(
2949
/*=================*/
2950
char* norm_name, /*!< out: normalized name as a
2951
null-terminated string */
2952
const char* name) /*!< in: table name string */
2954
const char* name_ptr;
2958
/* Scan name from the end */
2960
ptr = strchr(name, '\0')-1;
2962
while (ptr >= name && *ptr != '\\' && *ptr != '/') {
2972
while (ptr >= name && *ptr != '\\' && *ptr != '/') {
2978
memcpy(norm_name, db_ptr, strlen(name) + 1 - (db_ptr - name));
2980
norm_name[name_ptr - db_ptr - 1] = '/';
2983
innobase_casedn_str(norm_name);
2879
2987
/********************************************************************//**
2880
2988
Get the upper limit of the MySQL integral and floating-point type.
2881
2989
@return maximum allowed value for the field */
3042
3150
if (!index_mapping) {
3043
3151
/* Report an error if index_mapping continues to be
3044
3152
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",
3153
errmsg_printf(ERRMSG_LVL_ERROR,
3154
"InnoDB: fail to allocate memory for "
3155
"index translation table. Number of "
3156
"Index:%lu, array size:%lu",
3047
3157
mysql_num_index,
3048
3158
share->idx_trans_tbl.array_size);
3064
3174
ib_table, table->key_info[count].name);
3066
3176
if (!index_mapping[count]) {
3067
errmsg_printf(error::ERROR, "Cannot find index %s in InnoDB index dictionary.",
3068
table->key_info[count].name);
3177
errmsg_printf(ERRMSG_LVL_ERROR, "Cannot find index %s in InnoDB "
3178
"index dictionary.",
3179
table->key_info[count].name);
3070
3181
goto func_exit;
3073
3184
/* Double check fetched index has the same
3074
3185
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);
3186
if (!innobase_match_index_columns(&table->key_info[count],
3187
index_mapping[count])) {
3188
errmsg_printf(ERRMSG_LVL_ERROR, "Found index %s whose column info "
3189
"does not match that of MySQL.",
3190
table->key_info[count].name);
3197
3311
case DB_RECORD_NOT_FOUND:
3198
3312
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);
3313
fprintf(stderr, " InnoDB: MySQL and InnoDB data "
3314
"dictionaries are out of sync.\n"
3315
"InnoDB: Unable to find the AUTOINC column "
3316
"%s in the InnoDB table %s.\n"
3317
"InnoDB: We set the next AUTOINC column "
3319
"InnoDB: in effect disabling the AUTOINC "
3320
"next value generation.\n"
3321
"InnoDB: You can either set the next "
3322
"AUTOINC value explicitly using ALTER TABLE\n"
3323
"InnoDB: or fix the data dictionary by "
3324
"recreating the table.\n",
3325
col_name, index->table->name);
3207
3327
/* This will disable the AUTOINC generation. */
3247
3368
getTransactionalEngine()->releaseTemporaryLatches(session);
3371
normalize_table_name(norm_name, identifier.getPath().c_str());
3250
3373
user_session = NULL;
3252
std::string search_string(identifier.getSchemaName());
3253
boost::algorithm::to_lower(search_string);
3375
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
3380
/* Create buffers for packing the fields of a record. Why
3295
3403
/* 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);
3404
ib_table = dict_table_get(norm_name, TRUE);
3307
3406
if (NULL == ib_table) {
3308
errmsg_printf(error::ERROR, "Cannot find or open table %s from\n"
3407
errmsg_printf(ERRMSG_LVL_ERROR, "Cannot find or open table %s from\n"
3309
3408
"the internal data dictionary of InnoDB "
3310
3409
"though the .frm file for the\n"
3311
3410
"table exists. Maybe you have deleted and "
3328
3427
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 "
3430
if (ib_table->ibd_file_missing && !session_tablespace_op(session)) {
3431
errmsg_printf(ERRMSG_LVL_ERROR, "MySQL is trying to open a table handle but "
3333
3432
"the .ibd file for\ntable %s does not exist.\n"
3334
3433
"Have you deleted the .ibd file from the "
3335
3434
"database directory under\nthe MySQL datadir, "
3336
3435
"or have you used DISCARD TABLESPACE?\n"
3337
3436
"See " REFMAN "innodb-troubleshooting.html\n"
3338
3437
"how you can resolve the problem.\n",
3339
identifier.getKeyPath().c_str());
3340
3439
free_share(share);
3341
3440
upd_buff.resize(0);
3342
3441
key_val_buff.resize(0);
3358
3457
key_used_on_scan = primary_key;
3360
3459
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());
3460
errmsg_printf(ERRMSG_LVL_ERROR, "Build InnoDB index translation table for"
3461
" Table %s failed", identifier.getPath().c_str());
3365
3464
/* Allocate a buffer for a 'row reference'. A row reference is
4189
4283
n_requested_fields++;
4191
4285
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
4287
if (index == clust_index) {
4196
templ->rec_field_no = templ->clust_rec_field_no;
4288
templ->rec_field_no = dict_col_get_clust_pos(col, index);
4198
4290
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;
4294
if (templ->rec_field_no == ULINT_UNDEFINED) {
4295
prebuilt->need_to_access_clustered = TRUE;
4205
4298
if (field->null_ptr) {
6177
6272
if (lex_identified_temp_table)
6178
6273
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,
6275
error= create_table_def(trx, &form, norm_name,
6276
lex_identified_temp_table ? name2 : NULL,
6184
6279
session.setXaId(trx->id);
6211
6306
for (i = 0; i < form.getShare()->sizeKeys(); i++) {
6212
6307
if (i != (uint) primary_key_no) {
6214
if ((error = create_index(trx, &form, iflags, identifier.getKeyPath().c_str(),
6309
if ((error = create_index(trx, &form, iflags, norm_name,
6221
stmt= session.getQueryStringCopy(stmt_len);
6316
stmt = innobase_get_stmt(&session, &stmt_len);
6224
6319
string generated_create_table;
6225
6320
const char *query= stmt;
6227
if (session.getSqlCommand() == SQLCOM_CREATE_TABLE)
6322
if (session_sql_command(&session) == SQLCOM_CREATE_TABLE)
6229
6324
message::transformTableDefinitionToSql(create_proto,
6230
6325
generated_create_table,
6235
6330
error = row_table_add_foreign_constraints(trx,
6236
6331
query, strlen(query),
6237
identifier.getKeyPath().c_str(),
6238
6333
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
6335
error = convert_error_code_to_mysql(error, iflags, NULL);
6427
6500
InnobaseEngine::doDropTable(
6428
6501
/*======================*/
6429
6502
Session &session,
6430
const identifier::Table &identifier)
6503
const TableIdentifier &identifier)
6433
6506
trx_t* parent_trx;
6508
char norm_name[1000];
6436
6510
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;
6512
/* Strangely, MySQL passes the table name without the '.frm'
6513
extension, in contrast to ::create */
6514
normalize_table_name(norm_name, identifier.getPath().c_str());
6446
6516
/* Get the transaction associated with the current session, or create one
6447
6517
if not yet created */
6608
6678
innobase_rename_table(
6609
6679
/*==================*/
6610
6680
trx_t* trx, /*!< in: transaction */
6611
const identifier::Table &from,
6612
const identifier::Table &to,
6681
const char* from, /*!< in: old name of the table */
6682
const char* to, /*!< in: new name of the table */
6613
6683
ibool lock_and_commit)
6614
6684
/*!< in: TRUE=lock data dictionary and commit */
6687
char norm_to[FN_REFLEN];
6688
char norm_from[FN_REFLEN];
6618
6690
srv_lower_case_table_names = TRUE;
6692
normalize_table_name(norm_to, to);
6693
normalize_table_name(norm_from, from);
6620
6695
/* Serialize data dictionary operations with dictionary mutex:
6621
6696
no deadlocks can occur then in these operations */
6624
6699
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);
6702
error = row_rename_table_for_mysql(
6703
norm_from, norm_to, trx, lock_and_commit);
6629
6705
if (error != DB_SUCCESS) {
6630
6706
FILE* ef = dict_foreign_err_file;
6632
6708
fputs("InnoDB: Renaming table ", ef);
6633
ut_print_name(ef, trx, TRUE, from.getKeyPath().c_str());
6709
ut_print_name(ef, trx, TRUE, norm_from);
6634
6710
fputs(" to ", ef);
6635
ut_print_name(ef, trx, TRUE, to.getKeyPath().c_str());
6711
ut_print_name(ef, trx, TRUE, norm_to);
6636
6712
fputs(" failed!\n", ef);
7171
7236
innodb_crash_recovery is set to a high value. */
7172
7237
stats.delete_length = 0;
7176
avail_space = fsp_get_available_space_in_free_extents(ib_table->space);
7178
if (avail_space == ULLINT_UNDEFINED) {
7239
/* lock the data dictionary to avoid races with
7240
ibd_file_missing and tablespace_discarded */
7241
row_mysql_lock_data_dictionary(prebuilt->trx);
7243
/* ib_table->space must be an existent tablespace */
7244
if (!ib_table->ibd_file_missing
7245
&& !ib_table->tablespace_discarded) {
7247
stats.delete_length =
7248
fsp_get_available_space_in_free_extents(
7249
ib_table->space) * 1024;
7179
7252
Session* session;
7181
7254
session= getTable()->in_use;
7678
7753
db_name[i] = 0;
7679
ulen= identifier::Table::filename_to_tablename(db_name, uname, sizeof(uname));
7754
ulen= TableIdentifier::filename_to_tablename(db_name, uname, sizeof(uname));
7680
7755
LEX_STRING *tmp_referenced_db = session->make_lex_string(NULL, uname, ulen, true);
7682
7757
/* Table name */
7683
7758
tmp_buff += i + 1;
7684
ulen= identifier::Table::filename_to_tablename(tmp_buff, uname, sizeof(uname));
7759
ulen= TableIdentifier::filename_to_tablename(tmp_buff, uname, sizeof(uname));
7685
7760
LEX_STRING *tmp_referenced_table = session->make_lex_string(NULL, uname, ulen, true);
7687
7762
/** Foreign Fields **/
8787
8866
finds charset information and returns length of prefix_len characters in the
8788
8867
index field in bytes.
8789
8868
@return number of bytes occupied by the first n characters */
8869
extern "C" UNIV_INTERN
8871
innobase_get_at_most_n_mbchars(
8872
/*===========================*/
8873
ulint charset_id, /*!< in: character set id */
8874
ulint prefix_len, /*!< in: prefix length in bytes of the index
8875
(this has to be divided by mbmaxlen to get the
8876
number of CHARACTERS n in the prefix) */
8877
ulint data_len, /*!< in: length of the string in bytes */
8878
const char* str); /*!< in: character string */
8792
8881
innobase_get_at_most_n_mbchars(
9138
9227
"Purge threads can be either 0 or 1. Defalut is 0.");
9139
9228
context("file-per-table",
9140
9229
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.");
9230
"Stores each InnoDB table to an .ibd file in the database dir.");
9231
context("file-format",
9232
po::value<string>(&innobase_file_format_name)->default_value("Antelope"),
9233
"File format to use for new tables in .ibd files.");
9142
9234
context("file-format-max",
9143
9235
po::value<string>(&innobase_file_format_max)->default_value("Antelope"),
9144
9236
"The highest file format in the tablespace.");
9145
9237
context("file-format-check",
9146
9238
po::value<bool>(&innobase_file_format_check)->default_value(true)->zero_tokens(),
9147
9239
"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
9240
context("flush-log-at-trx-commit",
9152
9241
po::value<trinary_constraint>(&innodb_flush_log_at_trx_commit)->default_value(1),
9153
9242
"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
9271
po::value<additional_mem_pool_constraint>(&innobase_additional_mem_pool_size)->default_value(8*1024*1024L),
9183
9272
"Size of a memory pool InnoDB uses to store data dictionary information and other internal data structures.");
9184
9273
context("autoextend-increment",
9185
po::value<autoextend_constraint>(&innodb_auto_extend_increment)->default_value(64L),
9274
po::value<autoextend_constraint>(&innodb_auto_extend_increment)->default_value(8L),
9186
9275
"Data file autoextend increment in megabytes");
9187
9276
context("buffer-pool-size",
9188
9277
po::value<buffer_pool_constraint>(&innobase_buffer_pool_size)->default_value(128*1024*1024L),
9241
9330
"InnoDB version");
9242
9331
context("use-internal-malloc",
9243
9332
"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
9333
context("change-buffering",
9247
9334
po::value<string>(&innobase_change_buffering),
9248
9335
"Buffer changes to reduce random access: OFF, ON, inserting, deleting, changing, or purging.");