~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/handler/ha_innodb.cc

  • Committer: Mark Atwood
  • Date: 2011-08-11 03:05:03 UTC
  • mfrom: (2385.1.12 refactor4)
  • Revision ID: me@mark.atwood.name-20110811030503-rp9xjihc5x3y0x4q
mergeĀ lp:~olafvdspek/drizzle/refactor4

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    in Windows?
39
39
*/
40
40
 
41
 
#include "config.h"
 
41
#include <config.h>
42
42
 
43
43
#include <limits.h>
44
44
#include <fcntl.h>
45
45
 
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"
68
 
 
 
46
#include <drizzled/error.h>
 
47
#include <drizzled/errmsg_print.h>
 
48
#include <drizzled/internal/m_string.h>
 
49
#include <drizzled/internal/my_sys.h>
 
50
#include <drizzled/plugin.h>
 
51
#include <drizzled/show.h>
 
52
#include <drizzled/data_home.h>
 
53
#include <drizzled/error.h>
 
54
#include <drizzled/field.h>
 
55
#include <drizzled/charset.h>
 
56
#include <drizzled/session.h>
 
57
#include <drizzled/current_session.h>
 
58
#include <drizzled/table.h>
 
59
#include <drizzled/field/blob.h>
 
60
#include <drizzled/field/varstring.h>
 
61
#include <drizzled/plugin/xa_storage_engine.h>
 
62
#include <drizzled/plugin/daemon.h>
 
63
#include <drizzled/memory/multi_malloc.h>
 
64
#include <drizzled/pthread_globals.h>
 
65
#include <drizzled/named_savepoint.h>
 
66
#include <drizzled/session/table_messages.h>
69
67
#include <drizzled/transaction_services.h>
70
 
#include "drizzled/message/statement_transform.h"
 
68
#include <drizzled/message/statement_transform.h>
 
69
#include <drizzled/cached_directory.h>
 
70
#include <drizzled/statistics_variables.h>
 
71
#include <drizzled/system_variables.h>
 
72
#include <drizzled/session/times.h>
 
73
#include <drizzled/session/transactions.h>
 
74
#include <drizzled/typelib.h>
71
75
 
72
76
#include <boost/algorithm/string.hpp>
73
77
#include <boost/program_options.hpp>
125
129
#include <sstream>
126
130
#include <string>
127
131
 
128
 
#include "plugin/innobase/handler/status_function.h"
129
 
#include "plugin/innobase/handler/replication_log.h"
 
132
#include <plugin/innobase/handler/status_function.h>
 
133
#include <plugin/innobase/handler/replication_log.h>
130
134
 
131
135
#include <google/protobuf/io/zero_copy_stream.h>
132
136
#include <google/protobuf/io/zero_copy_stream_impl.h>
175
179
static additional_mem_pool_constraint innobase_additional_mem_pool_size;
176
180
typedef constrained_check<unsigned int, 1000, 1> autoextend_constraint;
177
181
static autoextend_constraint innodb_auto_extend_increment;
178
 
typedef constrained_check<size_t, SIZE_MAX, 5242880, 1048576> buffer_pool_constraint;
 
182
typedef constrained_check<size_t, SIZE_MAX, 33554432, 1048576> buffer_pool_constraint;
179
183
static buffer_pool_constraint innobase_buffer_pool_size;
180
184
typedef constrained_check<uint32_t, MAX_BUFFER_POOLS, 1> buffer_pool_instances_constraint;
181
185
static buffer_pool_instances_constraint innobase_buffer_pool_instances;
 
186
typedef constrained_check<uint32_t,
 
187
                          (1 << UNIV_PAGE_SIZE_SHIFT_MAX),
 
188
                                (1 << 12)> page_size_constraint;
 
189
static page_size_constraint innobase_page_size;
 
190
typedef constrained_check<uint32_t,
 
191
                          (1 << UNIV_PAGE_SIZE_SHIFT_MAX),
 
192
                                (1 << 9)> log_block_size_constraint;
 
193
static log_block_size_constraint innobase_log_block_size;
182
194
typedef constrained_check<uint32_t, UINT32_MAX, 100> io_capacity_constraint;
183
195
static io_capacity_constraint innodb_io_capacity;
184
196
typedef constrained_check<uint32_t, 5000, 1> purge_batch_constraint;
205
217
 
206
218
static uint64_constraint innodb_replication_delay;
207
219
 
 
220
static uint32_constraint buffer_pool_restore_at_startup;
 
221
 
208
222
/** Percentage of the buffer pool to reserve for 'old' blocks.
209
223
Connected to buf_LRU_old_ratio. */
210
224
typedef constrained_check<uint32_t, 95, 5> old_blocks_constraint;
217
231
typedef constrained_check<uint32_t, 64, 0> read_ahead_threshold_constraint;
218
232
static read_ahead_threshold_constraint innodb_read_ahead_threshold;
219
233
 
 
234
static uint64_constraint ibuf_max_size;
 
235
 
 
236
typedef constrained_check<uint32_t, 1, 0> binary_constraint;
 
237
static binary_constraint ibuf_active_contract;
 
238
 
 
239
typedef constrained_check<uint32_t, 999999999, 100> ibuf_accel_rate_constraint;
 
240
static ibuf_accel_rate_constraint ibuf_accel_rate;
 
241
static uint32_constraint checkpoint_age_target;
 
242
static binary_constraint flush_neighbor_pages;
 
243
 
220
244
/* The default values for the following char* start-up parameters
221
245
are determined in innobase_init below: */
222
246
 
226
250
static string innobase_file_format_name;
227
251
static string innobase_change_buffering;
228
252
 
 
253
static string read_ahead;
 
254
static string adaptive_flushing_method;
 
255
 
229
256
/* The highest file format being used in the database. The value can be
230
257
set by user, however, it will be adjusted to the newer file format if
231
258
a table of such format is created/opened. */
234
261
/* Below we have boolean-valued start-up parameters, and their default
235
262
values */
236
263
 
237
 
typedef constrained_check<uint32_t, 2, 0> trinary_constraint;
238
264
static trinary_constraint innobase_fast_shutdown;
239
265
 
240
266
/* "innobase_file_format_check" decides whether we would continue
286
312
  "all"         /* IBUF_USE_ALL */
287
313
};
288
314
 
 
315
/** Allowed values of read_ahead */
 
316
static const char* read_ahead_names[] = {
 
317
  "none",       /* 0 */
 
318
  "random",
 
319
  "linear",
 
320
  "both",       /* 3 */
 
321
  /* For compatibility with the older Percona patch */
 
322
  "0",          /* 4 ("none" + 4) */
 
323
  "1",
 
324
  "2",
 
325
  "3",          /* 7 ("both" + 4) */
 
326
  NULL
 
327
};
 
328
 
 
329
static TYPELIB read_ahead_typelib = {
 
330
  array_elements(read_ahead_names) - 1, "read_ahead_typelib",
 
331
  read_ahead_names, NULL
 
332
};
 
333
 
 
334
/** Allowed values of adaptive_flushing_method */
 
335
static const char* adaptive_flushing_method_names[] = {
 
336
    "native",           /* 0 */
 
337
    "estimate",         /* 1 */
 
338
    "keep_average",     /* 2 */
 
339
    /* For compatibility with the older Percona patch */
 
340
    "0",                /* 3 ("native" + 3) */
 
341
    "1",                /* 4 ("estimate" + 3) */
 
342
    "2",                /* 5 ("keep_average" + 3) */
 
343
    NULL
 
344
};
 
345
 
 
346
static TYPELIB adaptive_flushing_method_typelib = {
 
347
  array_elements(adaptive_flushing_method_names) - 1,
 
348
  "adaptive_flushing_method_typelib",
 
349
  adaptive_flushing_method_names, NULL
 
350
};
 
351
 
289
352
/* "GEN_CLUST_INDEX" is the name reserved for Innodb default
290
353
system primary index. */
291
354
static const char innobase_index_reserve_name[]= "GEN_CLUST_INDEX";
321
384
 
322
385
  virtual ~InnobaseEngine()
323
386
  {
324
 
    int err= 0;
325
387
    if (innodb_inited) {
326
388
      srv_fast_shutdown = (ulint) innobase_fast_shutdown;
327
389
      innodb_inited = 0;
328
390
      hash_table_free(innobase_open_tables);
329
391
      innobase_open_tables = NULL;
330
392
      if (innobase_shutdown_for_mysql() != DB_SUCCESS) {
331
 
        err = 1;
 
393
        // Throw here?
332
394
      }
333
395
      srv_free_paths_and_sizes();
334
 
      if (internal_innobase_data_file_path)
335
 
        free(internal_innobase_data_file_path);
 
396
      free(internal_innobase_data_file_path);
336
397
    }
337
398
    
338
399
    /* These get strdup'd from vm variables */
462
523
  UNIV_INTERN int doCreateTable(Session &session,
463
524
                                Table &form,
464
525
                                const identifier::Table &identifier,
465
 
                                message::Table&);
 
526
                                const message::Table&);
466
527
  UNIV_INTERN int doRenameTable(Session&, const identifier::Table &from, const identifier::Table &to);
467
528
  UNIV_INTERN int doDropTable(Session &session, const identifier::Table &identifier);
468
529
 
490
551
 
491
552
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
492
553
                             const drizzled::identifier::Schema &schema_identifier,
493
 
                             drizzled::identifier::Table::vector &set_of_identifiers);
 
554
                             drizzled::identifier::table::vector &set_of_identifiers);
494
555
  bool validateCreateTableOption(const std::string &key, const std::string &state);
495
556
  void dropTemporarySchema();
496
557
 
519
580
 
520
581
void InnobaseEngine::doGetTableIdentifiers(drizzled::CachedDirectory &directory,
521
582
                                           const drizzled::identifier::Schema &schema_identifier,
522
 
                                           drizzled::identifier::Table::vector &set_of_identifiers)
 
583
                                           drizzled::identifier::table::vector &set_of_identifiers)
523
584
{
524
585
  CachedDirectory::Entries entries= directory.getEntries();
525
586
 
934
995
        ulint   value)  /*!< in: time waited for the lock */
935
996
{
936
997
  if (in_session)
937
 
    in_session->utime_after_lock+= value;
 
998
    in_session->times.utime_after_lock+= value;
938
999
}
939
1000
 
940
1001
/********************************************************************//**
964
1025
  uint64_t end_timestamp= message.transaction_context().end_timestamp();
965
1026
  bool is_end_segment= message.end_segment();
966
1027
  trx->log_commit_id= TRUE;
 
1028
 
 
1029
  string server_uuid= session.getServerUUID();
 
1030
  string originating_server_uuid= session.getOriginatingServerUUID();
 
1031
  uint64_t originating_commit_id= session.getOriginatingCommitID();
 
1032
  bool use_originating_server_uuid= session.isOriginatingServerUUIDSet();
 
1033
 
967
1034
  ulint error= insert_replication_message(data, message.ByteSize(), trx, trx_id,
968
 
               end_timestamp, is_end_segment, seg_id);
 
1035
               end_timestamp, is_end_segment, seg_id, server_uuid.c_str(),
 
1036
               use_originating_server_uuid, originating_server_uuid.c_str(),
 
1037
               originating_commit_id);
 
1038
 
969
1039
  (void)error;
970
1040
 
971
1041
  delete[] data;
1175
1245
  uint  )   /*!< in: max query length to print, or 0 to
1176
1246
           use the default max length */
1177
1247
{
1178
 
  drizzled::identifier::User::const_shared_ptr user_identifier(in_session->user());
 
1248
  drizzled::identifier::user::ptr user_identifier(in_session->user());
1179
1249
 
1180
1250
  fprintf(f,
1181
1251
          "Drizzle thread %"PRIu64", query id %"PRIu64", %s, %s, %s ",
1182
1252
          static_cast<uint64_t>(in_session->getSessionId()),
1183
1253
          static_cast<uint64_t>(in_session->getQueryId()),
1184
 
          glob_hostname,
 
1254
          getServerHostname().c_str(),
1185
1255
          user_identifier->address().c_str(),
1186
1256
          user_identifier->username().c_str()
1187
1257
  );
1199
1269
  ulint*  mbminlen, /*!< out: minimum length of a char (in bytes) */
1200
1270
  ulint*  mbmaxlen) /*!< out: maximum length of a char (in bytes) */
1201
1271
{
1202
 
  CHARSET_INFO* cs;
 
1272
  charset_info_st* cs;
1203
1273
  ut_ad(cset < 256);
1204
1274
  ut_ad(mbminlen);
1205
1275
  ut_ad(mbmaxlen);
1274
1344
  const void *cs,
1275
1345
  char char_to_test)
1276
1346
{
1277
 
  return my_isspace(static_cast<const CHARSET_INFO *>(cs), char_to_test);
 
1347
  return my_isspace(static_cast<const charset_info_st *>(cs), char_to_test);
1278
1348
}
1279
1349
 
1280
1350
#if defined (__WIN__) && defined (MYSQL_DYNAMIC_PLUGIN)
1866
1936
  srv_read_ahead_threshold= innodb_read_ahead_threshold.get();
1867
1937
}
1868
1938
 
 
1939
static void auto_lru_dump_update(Session *, sql_var_t)
 
1940
{
 
1941
  srv_auto_lru_dump= buffer_pool_restore_at_startup.get();
 
1942
}
 
1943
 
 
1944
static void ibuf_active_contract_update(Session *, sql_var_t)
 
1945
{
 
1946
  srv_ibuf_active_contract= ibuf_active_contract.get();
 
1947
}
 
1948
 
 
1949
static void ibuf_accel_rate_update(Session *, sql_var_t)
 
1950
{
 
1951
  srv_ibuf_accel_rate= ibuf_accel_rate.get();
 
1952
}
 
1953
 
 
1954
static void checkpoint_age_target_update(Session *, sql_var_t)
 
1955
{
 
1956
  srv_checkpoint_age_target= checkpoint_age_target.get();
 
1957
}
 
1958
 
 
1959
static void flush_neighbor_pages_update(Session *, sql_var_t)
 
1960
{
 
1961
  srv_flush_neighbor_pages= flush_neighbor_pages.get();
 
1962
}
1869
1963
 
1870
1964
static int innodb_commit_concurrency_validate(Session *session, set_var *var)
1871
1965
{
2003
2097
  return(1);
2004
2098
}
2005
2099
 
 
2100
/*********************************************************************//**
 
2101
Check if argument is a valid value for srv_read_ahead and set it.  This
 
2102
function is registered as a callback with MySQL.
 
2103
@return 0 for valid read_ahead value */
 
2104
static
 
2105
int
 
2106
read_ahead_validate(
 
2107
/*================*/
 
2108
  Session*,             /*!< in: thread handle */
 
2109
  set_var*    var)
 
2110
{
 
2111
  const char *read_ahead_input = var->value->str_value.ptr();
 
2112
  int res = read_ahead_typelib.find_type(read_ahead_input, TYPELIB::e_none); // e_none is wrong
 
2113
 
 
2114
  if (res > 0) {
 
2115
    srv_read_ahead = res - 1;
 
2116
    return 0;
 
2117
  }
 
2118
 
 
2119
  return 1;
 
2120
}
 
2121
 
 
2122
/*********************************************************************//**
 
2123
Check if argument is a valid value for srv_adaptive_flushing_method and
 
2124
set it.  This function is registered as a callback with MySQL.
 
2125
@return 0 for valid read_ahead value */
 
2126
static
 
2127
int
 
2128
adaptive_flushing_method_validate(
 
2129
/*==============================*/
 
2130
  Session*,             /*!< in: thread handle */
 
2131
  set_var*    var)
 
2132
{
 
2133
  const char *adaptive_flushing_method_input = var->value->str_value.ptr();
 
2134
  int res = adaptive_flushing_method_typelib.find_type(adaptive_flushing_method_input, TYPELIB::e_none); // e_none is wrong
 
2135
 
 
2136
  if (res > 0) {
 
2137
    srv_adaptive_flushing_method = res - 1;
 
2138
    return 0;
 
2139
  }
 
2140
  return 1;
 
2141
}
 
2142
 
2006
2143
 
2007
2144
/*********************************************************************//**
2008
2145
Opens an InnoDB database.
2034
2171
  srv_spin_wait_delay= innodb_spin_wait_delay.get();
2035
2172
  srv_thread_sleep_delay= innodb_thread_sleep_delay.get();
2036
2173
  srv_read_ahead_threshold= innodb_read_ahead_threshold.get();
 
2174
  srv_auto_lru_dump= buffer_pool_restore_at_startup.get();
 
2175
  srv_ibuf_max_size= ibuf_max_size.get();
 
2176
  srv_ibuf_active_contract= ibuf_active_contract.get();
 
2177
  srv_ibuf_accel_rate= ibuf_accel_rate.get();
 
2178
  srv_checkpoint_age_target= checkpoint_age_target.get();
 
2179
  srv_flush_neighbor_pages= flush_neighbor_pages.get();
 
2180
 
 
2181
  srv_read_ahead = read_ahead_typelib.find_type_or_exit(vm["read-ahead"].as<string>().c_str(),
 
2182
                                                        "read_ahead_typelib") + 1;
 
2183
 
 
2184
  srv_adaptive_flushing_method = adaptive_flushing_method_typelib.find_type_or_exit(vm["adaptive-flushing-method"].as<string>().c_str(),
 
2185
                                                                                    "adaptive_flushing_method_typelib") + 1;
2037
2186
 
2038
2187
  /* Inverted Booleans */
2039
2188
 
2040
 
  innobase_use_checksums= (vm.count("disable-checksums")) ? false : true;
2041
 
  innobase_use_doublewrite= (vm.count("disable-doublewrite")) ? false : true;
2042
 
  srv_adaptive_flushing= (vm.count("disable-adaptive-flushing")) ? false : true;
2043
 
  srv_use_sys_malloc= (vm.count("use-internal-malloc")) ? false : true;
2044
 
  srv_use_native_aio= (vm.count("disable-native-aio")) ? false : true;
2045
 
  support_xa= (vm.count("disable-xa")) ? false : true;
2046
 
  btr_search_enabled= (vm.count("disable-adaptive-hash-index")) ? false : true;
2047
 
 
 
2189
  innobase_use_checksums= not vm.count("disable-checksums");
 
2190
  innobase_use_doublewrite= not vm.count("disable-doublewrite");
 
2191
  srv_adaptive_flushing= not vm.count("disable-adaptive-flushing");
 
2192
  srv_use_sys_malloc= not vm.count("use-internal-malloc");
 
2193
  srv_use_native_aio= not vm.count("disable-native-aio");
 
2194
  support_xa= not vm.count("disable-xa");
 
2195
  btr_search_enabled= not vm.count("disable-adaptive-hash-index");
2048
2196
 
2049
2197
  /* Hafta do this here because we need to late-bind the default value */
2050
 
  if (vm.count("data-home-dir"))
2051
 
  {
2052
 
    innobase_data_home_dir= vm["data-home-dir"].as<string>();
2053
 
  }
2054
 
  else
2055
 
  {
2056
 
    innobase_data_home_dir= getDataHome().file_string();
2057
 
  }
2058
 
 
 
2198
  innobase_data_home_dir= vm.count("data-home-dir") ? vm["data-home-dir"].as<string>() : getDataHome().file_string();
2059
2199
 
2060
2200
  if (vm.count("data-file-path"))
2061
2201
  {
2086
2226
  }
2087
2227
#endif /* UNIV_DEBUG */
2088
2228
 
 
2229
  srv_page_size = 0;
 
2230
  srv_page_size_shift = 0;
 
2231
 
 
2232
  uint32_t page_size = innobase_page_size.get();
 
2233
  uint32_t log_block_size = innobase_log_block_size.get();
 
2234
 
 
2235
  if (innobase_page_size != (1 << 14)) {
 
2236
    uint n_shift;
 
2237
 
 
2238
    errmsg_printf(error::WARN,
 
2239
                  "InnoDB: Warning: innodb_page_size has been changed from default value 16384. (###EXPERIMENTAL### operation)\n");
 
2240
    for (n_shift = 12; n_shift <= UNIV_PAGE_SIZE_SHIFT_MAX; n_shift++) {
 
2241
      if (innobase_page_size == (1UL << n_shift)) {
 
2242
        srv_page_size_shift = n_shift;
 
2243
        srv_page_size = (1 << srv_page_size_shift);
 
2244
        errmsg_printf(error::WARN,
 
2245
                      "InnoDB: The universal page size of the database is set to %lu.\n",
 
2246
                      srv_page_size);
 
2247
        break;
 
2248
      }
 
2249
    }
 
2250
  } else {
 
2251
    srv_page_size_shift = 14;
 
2252
    srv_page_size = (1 << srv_page_size_shift);
 
2253
  }
 
2254
 
 
2255
  if (!srv_page_size_shift) {
 
2256
    errmsg_printf(error::ERROR,
 
2257
                  "InnoDB: Error: %"PRIu32" is not a valid value for innodb_page_size.\n"
 
2258
                  "InnoDB: Error: Valid values are 4096, 8192, and 16384 (default=16384).\n",
 
2259
                  page_size);
 
2260
    goto error;
 
2261
  }
 
2262
 
 
2263
  srv_log_block_size = 0;
 
2264
  if (log_block_size != (1 << 9)) { /*!=512*/
 
2265
    uint        n_shift;
 
2266
 
 
2267
    errmsg_printf(error::WARN,
 
2268
                  "InnoDB: Warning: innodb_log_block_size has been changed from default value 512. (###EXPERIMENTAL### operation)\n");
 
2269
    for (n_shift = 9; n_shift <= UNIV_PAGE_SIZE_SHIFT_MAX; n_shift++) {
 
2270
      if (log_block_size == (1UL << n_shift)) {
 
2271
        srv_log_block_size = (1 << n_shift);
 
2272
        errmsg_printf(error::WARN, "InnoDB: The log block size is set to %"PRIu32".\n",
 
2273
                      srv_log_block_size);
 
2274
        break;
 
2275
      }
 
2276
    }
 
2277
  } else {
 
2278
    srv_log_block_size = 512;
 
2279
  }
 
2280
 
 
2281
  if (!srv_log_block_size) {
 
2282
    errmsg_printf(error::ERROR,
 
2283
                  "InnoDB: Error: %"PRIu32" is not a valid value for innodb_log_block_size.\n"
 
2284
                  "InnoDB: Error: A valid value for innodb_log_block_size is\n"
 
2285
                  "InnoDB: Error: a power of 2 from 512 to 16384.\n",
 
2286
                  log_block_size);
 
2287
    goto error;
 
2288
  }
 
2289
 
2089
2290
  os_innodb_umask = (ulint)internal::my_umask;
2090
2291
 
2091
2292
 
2119
2320
 
2120
2321
mem_free_and_error:
2121
2322
    srv_free_paths_and_sizes();
2122
 
    if (internal_innobase_data_file_path)
2123
 
      free(internal_innobase_data_file_path);
 
2323
    free(internal_innobase_data_file_path);
2124
2324
    goto error;
2125
2325
  }
2126
2326
 
2236
2436
  srv_n_read_io_threads = (ulint) innobase_read_io_threads;
2237
2437
  srv_n_write_io_threads = (ulint) innobase_write_io_threads;
2238
2438
 
 
2439
  srv_read_ahead &= 3;
 
2440
  srv_adaptive_flushing_method %= 3;
 
2441
 
2239
2442
  srv_force_recovery = (ulint) innobase_force_recovery;
2240
2443
 
2241
2444
  srv_use_doublewrite_buf = (ibool) innobase_use_doublewrite;
2289
2492
  actuall_engine_ptr->dropTemporarySchema();
2290
2493
 
2291
2494
  context.add(new InnodbStatusTool);
2292
 
 
2293
2495
  context.add(innodb_engine_ptr);
2294
 
 
2295
 
  context.add(new(std::nothrow)CmpTool(false));
2296
 
 
2297
 
  context.add(new(std::nothrow)CmpTool(true));
2298
 
 
2299
 
  context.add(new(std::nothrow)CmpmemTool(false));
2300
 
 
2301
 
  context.add(new(std::nothrow)CmpmemTool(true));
2302
 
 
2303
 
  context.add(new(std::nothrow)InnodbTrxTool("INNODB_TRX"));
2304
 
 
2305
 
  context.add(new(std::nothrow)InnodbTrxTool("INNODB_LOCKS"));
2306
 
 
2307
 
  context.add(new(std::nothrow)InnodbTrxTool("INNODB_LOCK_WAITS"));
2308
 
 
2309
 
  context.add(new(std::nothrow)InnodbSysTablesTool());
2310
 
 
2311
 
  context.add(new(std::nothrow)InnodbSysTableStatsTool());
2312
 
 
2313
 
  context.add(new(std::nothrow)InnodbSysIndexesTool());
2314
 
 
2315
 
  context.add(new(std::nothrow)InnodbSysColumnsTool());
2316
 
 
2317
 
  context.add(new(std::nothrow)InnodbSysFieldsTool());
2318
 
 
2319
 
  context.add(new(std::nothrow)InnodbSysForeignTool());
2320
 
 
2321
 
  context.add(new(std::nothrow)InnodbSysForeignColsTool());
2322
 
 
2323
 
  context.add(new(std::nothrow)InnodbInternalTables());
2324
 
  context.add(new(std::nothrow)InnodbReplicationTable());
 
2496
  context.add(new CmpTool(false));
 
2497
  context.add(new CmpTool(true));
 
2498
  context.add(new CmpmemTool(false));
 
2499
  context.add(new CmpmemTool(true));
 
2500
  context.add(new InnodbTrxTool("INNODB_TRX"));
 
2501
  context.add(new InnodbTrxTool("INNODB_LOCKS"));
 
2502
  context.add(new InnodbTrxTool("INNODB_LOCK_WAITS"));
 
2503
  context.add(new InnodbSysTablesTool());
 
2504
  context.add(new InnodbSysTableStatsTool());
 
2505
  context.add(new InnodbSysIndexesTool());
 
2506
  context.add(new InnodbSysColumnsTool());
 
2507
  context.add(new InnodbSysFieldsTool());
 
2508
  context.add(new InnodbSysForeignTool());
 
2509
  context.add(new InnodbSysForeignColsTool());
 
2510
  context.add(new InnodbInternalTables());
 
2511
  context.add(new InnodbReplicationTable());
2325
2512
 
2326
2513
  if (innobase_use_replication_log)
2327
2514
  {
2328
 
    ReplicationLog *replication_logger= new(std::nothrow)ReplicationLog();
 
2515
    ReplicationLog *replication_logger= new ReplicationLog();
2329
2516
    context.add(replication_logger);
2330
2517
    ReplicationLog::setup(replication_logger);
2331
2518
  }
2377
2564
                                                  innodb_file_format_max_validate));
2378
2565
  context.registerVariable(new sys_var_constrained_value_readonly<size_t>("buffer_pool_size", innobase_buffer_pool_size));
2379
2566
  context.registerVariable(new sys_var_constrained_value_readonly<int64_t>("log_file_size", innobase_log_file_size));
 
2567
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("page_size", innobase_page_size));
 
2568
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("log_block_size", innobase_log_block_size));
2380
2569
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("flush_log_at_trx_commit",
2381
2570
                                                  innodb_flush_log_at_trx_commit));
2382
2571
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("max_dirty_pages_pct",
2411
2600
  context.registerVariable(new sys_var_constrained_value<uint32_t>("read_ahead_threshold",
2412
2601
                                                                   innodb_read_ahead_threshold,
2413
2602
                                                                   innodb_read_ahead_threshold_update));
 
2603
  context.registerVariable(new sys_var_constrained_value<uint32_t>("auto_lru_dump",
 
2604
                                                                   buffer_pool_restore_at_startup,
 
2605
                                                                   auto_lru_dump_update));
 
2606
  context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("ibuf_max_size",
 
2607
                                                                            ibuf_max_size));
 
2608
  context.registerVariable(new sys_var_constrained_value<uint32_t>("ibuf_active_contract",
 
2609
                                                                   ibuf_active_contract,
 
2610
                                                                   ibuf_active_contract_update));
 
2611
  context.registerVariable(new sys_var_constrained_value<uint32_t>("ibuf_accel_rate",
 
2612
                                                                   ibuf_accel_rate,
 
2613
                                                                   ibuf_accel_rate_update));
 
2614
  context.registerVariable(new sys_var_constrained_value<uint32_t>("checkpoint_age_target",
 
2615
                                                                   checkpoint_age_target,
 
2616
                                                                   checkpoint_age_target_update));
 
2617
  context.registerVariable(new sys_var_constrained_value<uint32_t>("flush_neighbor_pages",
 
2618
                                                                   flush_neighbor_pages,
 
2619
                                                                   flush_neighbor_pages_update));
 
2620
  context.registerVariable(new sys_var_std_string("read_ahead",
 
2621
                                                  read_ahead,
 
2622
                                                  read_ahead_validate));
 
2623
  context.registerVariable(new sys_var_std_string("adaptive_flushing_method",
 
2624
                                                  adaptive_flushing_method,
 
2625
                                                  adaptive_flushing_method_validate));
2414
2626
  /* Get the current high water mark format. */
2415
2627
  innobase_file_format_max = trx_sys_file_format_max_get();
2416
2628
  btr_search_fully_disabled = (!btr_search_enabled);
3639
3851
  const unsigned char* b,   /* in: data field */
3640
3852
  unsigned int  b_length) /* in: data field length, not UNIV_SQL_NULL */
3641
3853
{
3642
 
  const CHARSET_INFO* charset;
 
3854
  const charset_info_st* charset;
3643
3855
  enum_field_types  mysql_tp;
3644
3856
  int     ret;
3645
3857
 
3872
4084
      const byte* data;
3873
4085
      ulint   key_len;
3874
4086
      ulint   true_len;
3875
 
      const CHARSET_INFO* cs;
 
4087
      const charset_info_st* cs;
3876
4088
      int   error=0;
3877
4089
 
3878
4090
      key_len = key_part->length;
3931
4143
 
3932
4144
    } else if (mysql_type == DRIZZLE_TYPE_BLOB) {
3933
4145
 
3934
 
      const CHARSET_INFO* cs;
 
4146
      const charset_info_st* cs;
3935
4147
      ulint   key_len;
3936
4148
      ulint   true_len;
3937
4149
      int   error=0;
4003
4215
      ulint     true_len;
4004
4216
      ulint     key_len;
4005
4217
      const unsigned char*    src_start;
4006
 
      enum_field_types  real_type;
4007
 
      const CHARSET_INFO* cs= field->charset();
 
4218
      const charset_info_st* cs= field->charset();
4008
4219
 
4009
4220
      key_len = key_part->length;
4010
4221
 
4015
4226
      }
4016
4227
 
4017
4228
      src_start = record + key_part->offset;
4018
 
      real_type = field->real_type();
4019
4229
      true_len = key_len;
4020
4230
 
4021
4231
      /* Character set for the field is defined only
6020
6230
UNIV_INTERN
6021
6231
int
6022
6232
InnobaseEngine::doCreateTable(
6023
 
/*================*/
6024
 
  Session         &session, /*!< in: Session */
6025
 
  Table&    form,   /*!< in: information on table columns and indexes */
6026
 
        const identifier::Table &identifier,
6027
 
        message::Table& create_proto)
 
6233
                              /*================*/
 
6234
                              Session         &session, /*!< in: Session */
 
6235
                              Table&    form,   /*!< in: information on table columns and indexes */
 
6236
                              const identifier::Table &identifier,
 
6237
                              const message::Table& create_proto)
6028
6238
{
6029
6239
  int   error;
6030
6240
  dict_table_t* innobase_table;
6130
6340
      | DICT_TF_COMPACT
6131
6341
      | DICT_TF_FORMAT_ZIP
6132
6342
      << DICT_TF_FORMAT_SHIFT;
6133
 
#if DICT_TF_ZSSIZE_MAX < 1
6134
 
# error "DICT_TF_ZSSIZE_MAX < 1"
6135
 
#endif
6136
6343
 
6137
6344
    if (strict_mode)
6138
6345
    {
6566
6773
  innobase_commit_low(trx);
6567
6774
  trx_free_for_mysql(trx);
6568
6775
 
 
6776
  if (error) {
 
6777
    // What do we do here?
 
6778
  }
 
6779
 
6569
6780
  return false; // We are just a listener since we lack control over DDL, so we give no positive acknowledgement. 
6570
6781
}
6571
6782
 
7652
7863
  while (foreign != NULL) {
7653
7864
 
7654
7865
    uint i;
7655
 
    LEX_STRING *name = 0;
 
7866
    lex_string_t *name = 0;
7656
7867
    uint ulen;
7657
7868
    char uname[NAME_LEN + 1];           /* Unencoded name */
7658
7869
    char db_name[NAME_LEN + 1];
7664
7875
    while (tmp_buff[i] != '/')
7665
7876
      i++;
7666
7877
    tmp_buff += i + 1;
7667
 
    LEX_STRING *tmp_foreign_id = session->make_lex_string(NULL, tmp_buff, strlen(tmp_buff), true);
 
7878
    lex_string_t *tmp_foreign_id = session->make_lex_string(NULL, tmp_buff, strlen(tmp_buff), true);
7668
7879
 
7669
7880
    /* Database name */
7670
7881
    tmp_buff = foreign->referenced_table_name;
7677
7888
    }
7678
7889
    db_name[i] = 0;
7679
7890
    ulen= identifier::Table::filename_to_tablename(db_name, uname, sizeof(uname));
7680
 
    LEX_STRING *tmp_referenced_db = session->make_lex_string(NULL, uname, ulen, true);
 
7891
    lex_string_t *tmp_referenced_db = session->make_lex_string(NULL, uname, ulen, true);
7681
7892
 
7682
7893
    /* Table name */
7683
7894
    tmp_buff += i + 1;
7684
7895
    ulen= identifier::Table::filename_to_tablename(tmp_buff, uname, sizeof(uname));
7685
 
    LEX_STRING *tmp_referenced_table = session->make_lex_string(NULL, uname, ulen, true);
 
7896
    lex_string_t *tmp_referenced_table = session->make_lex_string(NULL, uname, ulen, true);
7686
7897
 
7687
7898
    /** Foreign Fields **/
7688
 
    List<LEX_STRING> tmp_foreign_fields;
7689
 
    List<LEX_STRING> tmp_referenced_fields;
 
7899
    List<lex_string_t> tmp_foreign_fields;
 
7900
    List<lex_string_t> tmp_referenced_fields;
7690
7901
    for (i= 0;;) {
7691
7902
      tmp_buff= foreign->foreign_col_names[i];
7692
7903
      name = session->make_lex_string(name, tmp_buff, strlen(tmp_buff), true);
7719
7930
      length=8;
7720
7931
      tmp_buff= "RESTRICT";
7721
7932
    }
7722
 
    LEX_STRING *tmp_delete_method = session->make_lex_string(NULL, tmp_buff, length, true);
 
7933
    lex_string_t *tmp_delete_method = session->make_lex_string(NULL, tmp_buff, length, true);
7723
7934
 
7724
7935
 
7725
7936
    if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE)
7742
7953
      length=8;
7743
7954
      tmp_buff= "RESTRICT";
7744
7955
    }
7745
 
    LEX_STRING *tmp_update_method = session->make_lex_string(NULL, tmp_buff, length, true);
 
7956
    lex_string_t *tmp_update_method = session->make_lex_string(NULL, tmp_buff, length, true);
7746
7957
 
7747
 
    LEX_STRING *tmp_referenced_key_name = NULL;
 
7958
    lex_string_t *tmp_referenced_key_name = NULL;
7748
7959
 
7749
7960
    if (foreign->referenced_index &&
7750
7961
        foreign->referenced_index->name)
7758
7969
                              tmp_update_method, tmp_delete_method, tmp_referenced_key_name,
7759
7970
                              tmp_foreign_fields, tmp_referenced_fields);
7760
7971
 
7761
 
    ForeignKeyInfo *pf_key_info = (ForeignKeyInfo *)
7762
 
      session->getMemRoot()->duplicate(&f_key_info, sizeof(ForeignKeyInfo));
 
7972
    ForeignKeyInfo *pf_key_info = (ForeignKeyInfo*)session->mem.memdup(&f_key_info, sizeof(ForeignKeyInfo));
7763
7973
    f_key_list->push_back(pf_key_info);
7764
7974
    foreign = UT_LIST_GET_NEXT(foreign_list, foreign);
7765
7975
  }
7824
8034
/*======================================*/
7825
8035
  char* str)  /*!< in, own: create info string to free */
7826
8036
{
7827
 
  if (str) {
7828
 
    free(str);
7829
 
  }
 
8037
  free(str);
7830
8038
}
7831
8039
 
7832
8040
/*******************************************************************//**
8787
8995
finds charset information and returns length of prefix_len characters in the
8788
8996
index field in bytes.
8789
8997
@return number of bytes occupied by the first n characters */
8790
 
UNIV_INTERN
8791
 
ulint
8792
 
innobase_get_at_most_n_mbchars(
8793
 
/*===========================*/
8794
 
  ulint charset_id, /*!< in: character set id */
8795
 
  ulint prefix_len, /*!< in: prefix length in bytes of the index
8796
 
        (this has to be divided by mbmaxlen to get the
8797
 
        number of CHARACTERS n in the prefix) */
8798
 
  ulint data_len,   /*!< in: length of the string in bytes */
8799
 
  const char* str); /*!< in: character string */
8800
8998
 
8801
8999
ulint
8802
9000
innobase_get_at_most_n_mbchars(
8810
9008
{
8811
9009
  ulint char_length;    /*!< character length in bytes */
8812
9010
  ulint n_chars;      /*!< number of characters in prefix */
8813
 
  const CHARSET_INFO* charset;  /*!< charset used in the field */
 
9011
  const charset_info_st* charset;  /*!< charset used in the field */
8814
9012
 
8815
9013
  charset = get_charset((uint) charset_id);
8816
9014
 
8923
9121
    return(0);
8924
9122
  }
8925
9123
 
8926
 
  session->get_xid(reinterpret_cast<DRIZZLE_XID*>(&trx->xid));
 
9124
  session->get_xid(reinterpret_cast<DrizzleXid*>(&trx->xid));
8927
9125
 
8928
9126
  /* Release a possible FIFO ticket and search latch. Since we will
8929
9127
  reserve the kernel mutex, we have to release the search system latch
9144
9342
          "Number of UNDO logs to purge in one batch from the history list. "
9145
9343
          "Default is 20.");
9146
9344
  context("purge-threads",
9147
 
          po::value<purge_threads_constraint>(&innodb_n_purge_threads)->default_value(0),
9148
 
          "Purge threads can be either 0 or 1. Defalut is 0.");
 
9345
          po::value<purge_threads_constraint>(&innodb_n_purge_threads)->default_value(1),
 
9346
          "Purge threads can be either 0 or 1. Default is 1.");
9149
9347
  context("file-per-table",
9150
9348
          po::value<bool>(&srv_file_per_table)->default_value(false)->zero_tokens(),
9151
9349
           "Stores each InnoDB table to an .ibd file in the database dir.");
9222
9420
  context("log-file-size",
9223
9421
          po::value<log_file_constraint>(&innobase_log_file_size)->default_value(20*1024*1024L),
9224
9422
          "The size of the buffer which InnoDB uses to write log to the log files on disk.");
 
9423
  context("page-size",
 
9424
          po::value<page_size_constraint>(&innobase_page_size)->default_value(1 << 14),
 
9425
          "###EXPERIMENTAL###: The universal page size of the database. Changing for created database is not supported. Use on your own risk!");
 
9426
  context("log-block-size",
 
9427
          po::value<log_block_size_constraint>(&innobase_log_block_size)->default_value(1 << 9),
 
9428
          "###EXPERIMENTAL###: The log block size of the transaction log file. Changing for created log file is not supported. Use on your own risk!");
9225
9429
  context("log-files-in-group",
9226
9430
          po::value<log_files_in_group_constraint>(&innobase_log_files_in_group)->default_value(2),
9227
9431
          "Number of log files in the log group. InnoDB writes to the files in a circular fashion.");
9259
9463
  context("read-ahead-threshold",
9260
9464
          po::value<read_ahead_threshold_constraint>(&innodb_read_ahead_threshold)->default_value(56),
9261
9465
          "Number of pages that must be accessed sequentially for InnoDB to trigger a readahead.");
 
9466
  context("auto-lru-dump",
 
9467
          po::value<uint32_constraint>(&buffer_pool_restore_at_startup)->default_value(0),
 
9468
          "Time in seconds between automatic buffer pool dumps. "
 
9469
          "0 (the default) disables automatic dumps.");
 
9470
  context("ibuf-max-size",
 
9471
          po::value<uint64_constraint>(&ibuf_max_size)->default_value(UINT64_MAX),
 
9472
          "The maximum size of the insert buffer (in bytes).");
 
9473
  context("ibuf-active-contract",
 
9474
          po::value<binary_constraint>(&ibuf_active_contract)->default_value(1),
 
9475
          "Enable/Disable active_contract of insert buffer. 0:disable 1:enable");
 
9476
  context("ibuf-accel-rate",
 
9477
          po::value<ibuf_accel_rate_constraint>(&ibuf_accel_rate)->default_value(100),
 
9478
          "Tunes amount of insert buffer processing of background, in addition to innodb_io_capacity. (in percentage)");
 
9479
  context("checkpoint-age-target",
 
9480
          po::value<uint32_constraint>(&checkpoint_age_target)->default_value(0),
 
9481
          "Control soft limit of checkpoint age. (0 : not control)");
 
9482
  context("flush-neighbor-pages",
 
9483
          po::value<binary_constraint>(&flush_neighbor_pages)->default_value(1),
 
9484
          "Enable/Disable flushing also neighbor pages. 0:disable 1:enable");
 
9485
  context("read-ahead",
 
9486
          po::value<string>(&read_ahead)->default_value("linear"),
 
9487
          "Control read ahead activity (none, random, [linear], both). [from 1.0.5: random read ahead is ignored]");
 
9488
  context("adaptive-flushing-method",
 
9489
          po::value<string>(&adaptive_flushing_method)->default_value("estimate"),
 
9490
          "Choose method of innodb_adaptive_flushing. (native, [estimate], keep_average)");
9262
9491
  context("disable-xa",
9263
9492
          "Disable InnoDB support for the XA two-phase commit");
9264
9493
  context("disable-table-locks",
9267
9496
          po::value<bool>(&strict_mode)->default_value(false)->zero_tokens(),
9268
9497
          "Use strict mode when evaluating create options.");
9269
9498
  context("replication-log",
9270
 
          po::value<bool>(&innobase_use_replication_log)->default_value(false),
 
9499
          po::value<bool>(&innobase_use_replication_log)->default_value(false)->zero_tokens(),
9271
9500
          _("Enable internal replication log."));
9272
9501
  context("lock-wait-timeout",
9273
9502
          po::value<lock_wait_constraint>(&lock_wait_timeout)->default_value(50),