You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

668 lines
22 KiB

  1. #define MYSQL_SERVER 1
  2. #include "mysql_priv.h"
  3. extern "C" {
  4. #include "stdint.h"
  5. #if defined(_WIN32)
  6. #include "misc.h"
  7. #endif
  8. #include "toku_os.h"
  9. }
  10. /* We define DTRACE after mysql_priv.h in case it disabled dtrace in the main server */
  11. #ifdef HAVE_DTRACE
  12. #define _DTRACE_VERSION 1
  13. #else
  14. #endif
  15. #include <mysql/plugin.h>
  16. #include "hatoku_hton.h"
  17. #include "hatoku_defines.h"
  18. #include "ha_tokudb.h"
  19. #undef PACKAGE
  20. #undef VERSION
  21. #undef HAVE_DTRACE
  22. #undef _DTRACE_VERSION
  23. static inline void *thd_data_get(THD *thd, int slot) {
  24. #if MYSQL_VERSION_ID <= 50123
  25. return thd->ha_data[slot];
  26. #else
  27. return thd->ha_data[slot].ha_ptr;
  28. #endif
  29. }
  30. static inline void thd_data_set(THD *thd, int slot, void *data) {
  31. #if MYSQL_VERSION_ID <= 50123
  32. thd->ha_data[slot] = data;
  33. #else
  34. thd->ha_data[slot].ha_ptr = data;
  35. #endif
  36. }
  37. static uchar *tokudb_get_key(TOKUDB_SHARE * share, size_t * length, my_bool not_used __attribute__ ((unused))) {
  38. *length = share->table_name_length;
  39. return (uchar *) share->table_name;
  40. }
  41. static handler *tokudb_create_handler(handlerton * hton, TABLE_SHARE * table, MEM_ROOT * mem_root);
  42. static MYSQL_THDVAR_BOOL(commit_sync, PLUGIN_VAR_THDLOCAL, "sync on txn commit",
  43. /* check */ NULL, /* update */ NULL, /* default*/ TRUE);
  44. static void tokudb_print_error(const DB_ENV * db_env, const char *db_errpfx, const char *buffer);
  45. static void tokudb_cleanup_log_files(void);
  46. static int tokudb_end(handlerton * hton, ha_panic_function type);
  47. static bool tokudb_flush_logs(handlerton * hton);
  48. static bool tokudb_show_status(handlerton * hton, THD * thd, stat_print_fn * print, enum ha_stat_type);
  49. static int tokudb_close_connection(handlerton * hton, THD * thd);
  50. static int tokudb_commit(handlerton * hton, THD * thd, bool all);
  51. static int tokudb_rollback(handlerton * hton, THD * thd, bool all);
  52. static uint tokudb_alter_table_flags(uint flags);
  53. #if 0
  54. static int tokudb_rollback_to_savepoint(handlerton * hton, THD * thd, void *savepoint);
  55. static int tokudb_savepoint(handlerton * hton, THD * thd, void *savepoint);
  56. static int tokudb_release_savepoint(handlerton * hton, THD * thd, void *savepoint);
  57. #endif
  58. static bool tokudb_show_logs(THD * thd, stat_print_fn * stat_print);
  59. handlerton *tokudb_hton;
  60. const char *ha_tokudb_ext = ".tokudb";
  61. char *tokudb_data_dir;
  62. ulong tokudb_debug;
  63. DB_ENV *db_env;
  64. HASH tokudb_open_tables;
  65. pthread_mutex_t tokudb_mutex;
  66. //my_bool tokudb_shared_data = FALSE;
  67. static u_int32_t tokudb_init_flags =
  68. DB_CREATE | DB_THREAD | DB_PRIVATE |
  69. DB_INIT_LOCK |
  70. DB_INIT_MPOOL |
  71. DB_INIT_TXN |
  72. 0 | // disabled for 1.0.2 DB_INIT_LOG |
  73. DB_RECOVER;
  74. static u_int32_t tokudb_env_flags = DB_LOG_AUTOREMOVE;
  75. // static u_int32_t tokudb_lock_type = DB_LOCK_DEFAULT;
  76. // static ulong tokudb_log_buffer_size = 0;
  77. // static ulong tokudb_log_file_size = 0;
  78. static ulonglong tokudb_cache_size = 0;
  79. static char *tokudb_home;
  80. // static char *tokudb_tmpdir;
  81. static char *tokudb_log_dir;
  82. // static long tokudb_lock_scan_time = 0;
  83. // static ulong tokudb_region_size = 0;
  84. // static ulong tokudb_cache_parts = 1;
  85. static ulong tokudb_max_lock;
  86. static const char tokudb_hton_name[] = "TokuDB";
  87. static const int tokudb_hton_name_length = sizeof(tokudb_hton_name) - 1;
  88. static u_int32_t tokudb_checkpointing_period;
  89. #ifdef TOKUDB_VERSION
  90. char *tokudb_version = TOKUDB_VERSION;
  91. #else
  92. char *tokudb_version;
  93. #endif
  94. struct st_mysql_storage_engine storage_engine_structure = { MYSQL_HANDLERTON_INTERFACE_VERSION };
  95. extern "C" {
  96. #include "ydb.h"
  97. }
  98. static int tokudb_init_func(void *p) {
  99. TOKUDB_DBUG_ENTER("tokudb_init_func");
  100. int r;
  101. #if defined(_WIN32)
  102. r = toku_ydb_init();
  103. if (r) {
  104. goto error;
  105. }
  106. #endif
  107. tokudb_hton = (handlerton *) p;
  108. VOID(pthread_mutex_init(&tokudb_mutex, MY_MUTEX_INIT_FAST));
  109. (void) hash_init(&tokudb_open_tables, system_charset_info, 32, 0, 0, (hash_get_key) tokudb_get_key, 0, 0);
  110. tokudb_hton->state = SHOW_OPTION_YES;
  111. // tokudb_hton->flags= HTON_CAN_RECREATE; // QQQ this came from skeleton
  112. tokudb_hton->flags = HTON_CLOSE_CURSORS_AT_COMMIT | HTON_FLUSH_AFTER_RENAME;
  113. #ifdef DB_TYPE_TOKUDB
  114. tokudb_hton->db_type = DB_TYPE_TOKUDB;
  115. #else
  116. tokudb_hton->db_type = DB_TYPE_UNKNOWN;
  117. #endif
  118. tokudb_hton->create = tokudb_create_handler;
  119. tokudb_hton->close_connection = tokudb_close_connection;
  120. #if 0
  121. tokudb_hton->savepoint_offset = sizeof(DB_TXN *);
  122. tokudb_hton->savepoint_set = tokudb_savepoint;
  123. tokudb_hton->savepoint_rollback = tokudb_rollback_to_savepoint;
  124. tokudb_hton->savepoint_release = tokudb_release_savepoint;
  125. #endif
  126. tokudb_hton->commit = tokudb_commit;
  127. tokudb_hton->rollback = tokudb_rollback;
  128. tokudb_hton->panic = tokudb_end;
  129. tokudb_hton->flush_logs = tokudb_flush_logs;
  130. tokudb_hton->show_status = tokudb_show_status;
  131. tokudb_hton->alter_table_flags = tokudb_alter_table_flags;
  132. #if 0
  133. if (!tokudb_tmpdir)
  134. tokudb_tmpdir = mysql_tmpdir;
  135. DBUG_PRINT("info", ("tokudb_tmpdir: %s", tokudb_tmpdir));
  136. #endif
  137. if (!tokudb_home)
  138. tokudb_home = mysql_real_data_home;
  139. DBUG_PRINT("info", ("tokudb_home: %s", tokudb_home));
  140. #if 0
  141. if (!tokudb_log_buffer_size) { // QQQ
  142. tokudb_log_buffer_size = max(table_cache_size * 512, 32 * 1024);
  143. DBUG_PRINT("info", ("computing tokudb_log_buffer_size %ld\n", tokudb_log_buffer_size));
  144. }
  145. tokudb_log_file_size = tokudb_log_buffer_size * 4;
  146. tokudb_log_file_size = MY_ALIGN(tokudb_log_file_size, 1024 * 1024L);
  147. tokudb_log_file_size = max(tokudb_log_file_size, 10 * 1024 * 1024L);
  148. DBUG_PRINT("info", ("computing tokudb_log_file_size: %ld\n", tokudb_log_file_size));
  149. #endif
  150. if ((r = db_env_create(&db_env, 0))) {
  151. DBUG_PRINT("info", ("db_env_create %d\n", r));
  152. goto error;
  153. }
  154. DBUG_PRINT("info", ("tokudb_env_flags: 0x%x\n", tokudb_env_flags));
  155. r = db_env->set_flags(db_env, tokudb_env_flags, 1);
  156. if (r) { // QQQ
  157. if (tokudb_debug & TOKUDB_DEBUG_INIT)
  158. TOKUDB_TRACE("%s:WARNING: flags=%x r=%d\n", __FUNCTION__, tokudb_env_flags, r);
  159. // goto error;
  160. }
  161. // config error handling
  162. db_env->set_errcall(db_env, tokudb_print_error);
  163. db_env->set_errpfx(db_env, "TokuDB");
  164. //
  165. // set default comparison functions
  166. //
  167. r = db_env->set_default_bt_compare(db_env, tokudb_cmp_dbt_key);
  168. if (r) {
  169. DBUG_PRINT("info", ("set_default_bt_compare%d\n", r));
  170. goto error;
  171. }
  172. r = db_env->set_default_dup_compare(db_env, tokudb_cmp_dbt_data);
  173. if (r) {
  174. DBUG_PRINT("info", ("set_default_dup_compare%d\n", r));
  175. goto error;
  176. }
  177. // config directories
  178. #if 0
  179. DBUG_PRINT("info", ("tokudb_tmpdir: %s\n", tokudb_tmpdir));
  180. db_env->set_tmp_dir(db_env, tokudb_tmpdir);
  181. #endif
  182. {
  183. char *data_dir = tokudb_data_dir;
  184. if (data_dir == 0)
  185. data_dir = mysql_data_home;
  186. DBUG_PRINT("info", ("tokudb_data_dir: %s\n", data_dir));
  187. db_env->set_data_dir(db_env, data_dir);
  188. }
  189. if (tokudb_log_dir) {
  190. DBUG_PRINT("info", ("tokudb_log_dir: %s\n", tokudb_log_dir));
  191. db_env->set_lg_dir(db_env, tokudb_log_dir);
  192. }
  193. // config the cache table size to min(1/2 of physical memory, 1/8 of the process address space)
  194. if (tokudb_cache_size == 0) {
  195. uint64_t physmem, maxdata;
  196. physmem = toku_os_get_phys_memory_size();
  197. tokudb_cache_size = physmem / 2;
  198. r = toku_os_get_max_process_data_size(&maxdata);
  199. if (r == 0) {
  200. if (tokudb_cache_size > maxdata / 8)
  201. tokudb_cache_size = maxdata / 8;
  202. }
  203. }
  204. if (tokudb_cache_size) {
  205. DBUG_PRINT("info", ("tokudb_cache_size: %lld\n", tokudb_cache_size));
  206. r = db_env->set_cachesize(db_env, (u_int32_t)(tokudb_cache_size >> 30), (u_int32_t)(tokudb_cache_size % (1024L * 1024L * 1024L)), 1);
  207. if (r) {
  208. DBUG_PRINT("info", ("set_cachesize %d\n", r));
  209. goto error;
  210. }
  211. }
  212. u_int32_t gbytes, bytes; int parts;
  213. r = db_env->get_cachesize(db_env, &gbytes, &bytes, &parts);
  214. if (r == 0)
  215. if (tokudb_debug & TOKUDB_DEBUG_INIT)
  216. TOKUDB_TRACE("%s:tokudb_cache_size=%lld\n", __FUNCTION__, ((unsigned long long) gbytes << 30) + bytes);
  217. #if 0
  218. // QQQ config the logs
  219. DBUG_PRINT("info", ("tokudb_log_file_size: %ld\n", tokudb_log_file_size));
  220. db_env->set_lg_max(db_env, tokudb_log_file_size);
  221. DBUG_PRINT("info", ("tokudb_log_buffer_size: %ld\n", tokudb_log_buffer_size));
  222. db_env->set_lg_bsize(db_env, tokudb_log_buffer_size);
  223. // DBUG_PRINT("info",("tokudb_region_size: %ld\n", tokudb_region_size));
  224. // db_env->set_lg_regionmax(db_env, tokudb_region_size);
  225. #endif
  226. // config the locks
  227. #if 0 // QQQ no lock types yet
  228. DBUG_PRINT("info", ("tokudb_lock_type: 0x%lx\n", tokudb_lock_type));
  229. db_env->set_lk_detect(db_env, tokudb_lock_type);
  230. #endif
  231. if (tokudb_max_lock) {
  232. DBUG_PRINT("info",("tokudb_max_lock: %ld\n", tokudb_max_lock));
  233. r = db_env->set_lk_max_locks(db_env, tokudb_max_lock);
  234. if (r) {
  235. DBUG_PRINT("info", ("tokudb_set_max_locks %d\n", r));
  236. goto error;
  237. }
  238. }
  239. if (tokudb_debug & TOKUDB_DEBUG_INIT) TOKUDB_TRACE("%s:env open:flags=%x\n", __FUNCTION__, tokudb_init_flags);
  240. r = db_env->open(db_env, tokudb_home, tokudb_init_flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
  241. if (tokudb_debug & TOKUDB_DEBUG_INIT) TOKUDB_TRACE("%s:env opened:return=%d\n", __FUNCTION__, r);
  242. if (r) {
  243. DBUG_PRINT("info", ("env->open %d\n", r));
  244. goto error;
  245. }
  246. r = db_env->checkpointing_set_period(db_env, tokudb_checkpointing_period);
  247. assert(!r);
  248. DBUG_RETURN(FALSE);
  249. error:
  250. if (db_env) {
  251. db_env->close(db_env, 0);
  252. db_env = 0;
  253. }
  254. DBUG_RETURN(TRUE);
  255. }
  256. static int tokudb_done_func(void *p) {
  257. TOKUDB_DBUG_ENTER("tokudb_done_func");
  258. int error = 0;
  259. if (tokudb_open_tables.records)
  260. error = 1;
  261. hash_free(&tokudb_open_tables);
  262. pthread_mutex_destroy(&tokudb_mutex);
  263. #if defined(_WIN32)
  264. toku_ydb_destroy();
  265. #endif
  266. TOKUDB_DBUG_RETURN(0);
  267. }
  268. static handler *tokudb_create_handler(handlerton * hton, TABLE_SHARE * table, MEM_ROOT * mem_root) {
  269. return new(mem_root) ha_tokudb(hton, table);
  270. }
  271. int tokudb_end(handlerton * hton, ha_panic_function type) {
  272. TOKUDB_DBUG_ENTER("tokudb_end");
  273. int error = 0;
  274. if (db_env) {
  275. if (tokudb_init_flags & DB_INIT_LOG)
  276. tokudb_cleanup_log_files();
  277. error = db_env->close(db_env, 0); // Error is logged
  278. db_env = NULL;
  279. }
  280. TOKUDB_DBUG_RETURN(error);
  281. }
  282. static int tokudb_close_connection(handlerton * hton, THD * thd) {
  283. my_free(thd_data_get(thd, hton->slot), MYF(0));
  284. return 0;
  285. }
  286. bool tokudb_flush_logs(handlerton * hton) {
  287. TOKUDB_DBUG_ENTER("tokudb_flush_logs");
  288. int error;
  289. bool result = 0;
  290. u_int32_t curr_tokudb_checkpointing_period = 0;
  291. //
  292. // get the current checkpointing period
  293. //
  294. error = db_env->checkpointing_get_period(
  295. db_env,
  296. &curr_tokudb_checkpointing_period
  297. );
  298. if (error) {
  299. my_error(ER_ERROR_DURING_CHECKPOINT, MYF(0), error);
  300. result = 1;
  301. goto exit;
  302. }
  303. //
  304. // if the current period is not the same as the variable, that means
  305. // the user has changed the period and now we need to update it
  306. //
  307. if (tokudb_checkpointing_period != curr_tokudb_checkpointing_period) {
  308. error = db_env->checkpointing_set_period(
  309. db_env,
  310. tokudb_checkpointing_period
  311. );
  312. if (error) {
  313. my_error(ER_ERROR_DURING_CHECKPOINT, MYF(0), error);
  314. result = 1;
  315. goto exit;
  316. }
  317. }
  318. //
  319. // take the checkpoint
  320. //
  321. error = db_env->txn_checkpoint(db_env, 0, 0, 0);
  322. if (error) {
  323. my_error(ER_ERROR_DURING_CHECKPOINT, MYF(0), error);
  324. result = 1;
  325. goto exit;
  326. }
  327. result = 0;
  328. exit:
  329. TOKUDB_DBUG_RETURN(result);
  330. }
  331. static int tokudb_commit(handlerton * hton, THD * thd, bool all) {
  332. TOKUDB_DBUG_ENTER("tokudb_commit");
  333. DBUG_PRINT("trans", ("ending transaction %s", all ? "all" : "stmt"));
  334. u_int32_t syncflag = THDVAR(thd, commit_sync) ? 0 : DB_TXN_NOSYNC;
  335. tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, hton->slot);
  336. DB_TXN **txn = all ? &trx->all : &trx->stmt;
  337. int error = 0;
  338. if (*txn) {
  339. if (tokudb_debug & TOKUDB_DEBUG_TXN)
  340. TOKUDB_TRACE("commit:%d:%p\n", all, *txn);
  341. error = (*txn)->commit(*txn, syncflag);
  342. if (*txn == trx->sp_level)
  343. trx->sp_level = 0;
  344. *txn = 0;
  345. }
  346. else if (tokudb_debug & TOKUDB_DEBUG_TXN) {
  347. TOKUDB_TRACE("commit0\n");
  348. }
  349. if (all) {
  350. trx->iso_level = hatoku_iso_not_set;
  351. }
  352. TOKUDB_DBUG_RETURN(error);
  353. }
  354. static int tokudb_rollback(handlerton * hton, THD * thd, bool all) {
  355. TOKUDB_DBUG_ENTER("tokudb_rollback");
  356. DBUG_PRINT("trans", ("aborting transaction %s", all ? "all" : "stmt"));
  357. tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, hton->slot);
  358. DB_TXN **txn = all ? &trx->all : &trx->stmt;
  359. int error = 0;
  360. if (*txn) {
  361. if (tokudb_debug & TOKUDB_DEBUG_TXN)
  362. TOKUDB_TRACE("rollback:%p\n", *txn);
  363. error = (*txn)->abort(*txn);
  364. if (*txn == trx->sp_level)
  365. trx->sp_level = 0;
  366. *txn = 0;
  367. } else
  368. if (tokudb_debug & TOKUDB_DEBUG_TXN)
  369. TOKUDB_TRACE("abort0\n");
  370. TOKUDB_DBUG_RETURN(error);
  371. }
  372. #if 0
  373. static int tokudb_savepoint(handlerton * hton, THD * thd, void *savepoint) {
  374. TOKUDB_DBUG_ENTER("tokudb_savepoint");
  375. int error;
  376. DB_TXN **save_txn = (DB_TXN **) savepoint;
  377. tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, hton->slot);
  378. if (!(error = db_env->txn_begin(db_env, trx->sp_level, save_txn, 0))) {
  379. trx->sp_level = *save_txn;
  380. }
  381. TOKUDB_DBUG_RETURN(error);
  382. }
  383. static int tokudb_rollback_to_savepoint(handlerton * hton, THD * thd, void *savepoint) {
  384. TOKUDB_DBUG_ENTER("tokudb_rollback_to_savepoint");
  385. int error;
  386. DB_TXN *parent, **save_txn = (DB_TXN **) savepoint;
  387. tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, hton->slot);
  388. parent = (*save_txn)->parent;
  389. if (!(error = (*save_txn)->abort(*save_txn))) {
  390. trx->sp_level = parent;
  391. error = tokudb_savepoint(hton, thd, savepoint);
  392. }
  393. TOKUDB_DBUG_RETURN(error);
  394. }
  395. static int tokudb_release_savepoint(handlerton * hton, THD * thd, void *savepoint) {
  396. TOKUDB_DBUG_ENTER("tokudb_release_savepoint");
  397. int error;
  398. DB_TXN *parent, **save_txn = (DB_TXN **) savepoint;
  399. tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, hton->slot);
  400. parent = (*save_txn)->parent;
  401. if (!(error = (*save_txn)->commit(*save_txn, 0))) {
  402. trx->sp_level = parent;
  403. *save_txn = 0;
  404. }
  405. TOKUDB_DBUG_RETURN(error);
  406. }
  407. #endif
  408. static bool tokudb_show_logs(THD * thd, stat_print_fn * stat_print) {
  409. TOKUDB_DBUG_ENTER("tokudb_show_logs");
  410. char **all_logs, **free_logs, **a, **f;
  411. int error = 1;
  412. MEM_ROOT **root_ptr = my_pthread_getspecific_ptr(MEM_ROOT **, THR_MALLOC);
  413. MEM_ROOT show_logs_root, *old_mem_root = *root_ptr;
  414. init_sql_alloc(&show_logs_root, BDB_LOG_ALLOC_BLOCK_SIZE, BDB_LOG_ALLOC_BLOCK_SIZE);
  415. *root_ptr = &show_logs_root;
  416. all_logs = free_logs = 0;
  417. error = db_env->log_archive(db_env, &all_logs, 0);
  418. if (error) {
  419. DBUG_PRINT("error", ("log_archive failed (error %d)", error));
  420. db_env->err(db_env, error, "log_archive");
  421. if (error == DB_NOTFOUND)
  422. error = 0; // No log files
  423. goto err;
  424. }
  425. /* Error is 0 here */
  426. if (all_logs) {
  427. for (a = all_logs, f = free_logs; *a; ++a) {
  428. if (f && *f && strcmp(*a, *f) == 0) {
  429. f++;
  430. if ((error = stat_print(thd, tokudb_hton_name, tokudb_hton_name_length, *a, strlen(*a), STRING_WITH_LEN(SHOW_LOG_STATUS_FREE))))
  431. break;
  432. } else {
  433. if ((error = stat_print(thd, tokudb_hton_name, tokudb_hton_name_length, *a, strlen(*a), STRING_WITH_LEN(SHOW_LOG_STATUS_INUSE))))
  434. break;
  435. }
  436. }
  437. }
  438. err:
  439. if (all_logs)
  440. free(all_logs);
  441. if (free_logs)
  442. free(free_logs);
  443. free_root(&show_logs_root, MYF(0));
  444. *root_ptr = old_mem_root;
  445. TOKUDB_DBUG_RETURN(error);
  446. }
  447. bool tokudb_show_status(handlerton * hton, THD * thd, stat_print_fn * stat_print, enum ha_stat_type stat_type) {
  448. switch (stat_type) {
  449. case HA_ENGINE_LOGS:
  450. return tokudb_show_logs(thd, stat_print);
  451. default:
  452. return FALSE;
  453. }
  454. }
  455. static void tokudb_print_error(const DB_ENV * db_env, const char *db_errpfx, const char *buffer) {
  456. sql_print_error("%s: %s", db_errpfx, buffer);
  457. }
  458. void tokudb_cleanup_log_files(void) {
  459. TOKUDB_DBUG_ENTER("tokudb_cleanup_log_files");
  460. char **names;
  461. int error;
  462. if ((error = db_env->txn_checkpoint(db_env, 0, 0, 0)))
  463. my_error(ER_ERROR_DURING_CHECKPOINT, MYF(0), error);
  464. if ((error = db_env->log_archive(db_env, &names, 0)) != 0) {
  465. DBUG_PRINT("error", ("log_archive failed (error %d)", error));
  466. db_env->err(db_env, error, "log_archive");
  467. DBUG_VOID_RETURN;
  468. }
  469. if (names) {
  470. char **np;
  471. for (np = names; *np; ++np) {
  472. #if 1
  473. if (tokudb_debug)
  474. TOKUDB_TRACE("%s:cleanup:%s\n", __FUNCTION__, *np);
  475. #else
  476. my_delete(*np, MYF(MY_WME));
  477. #endif
  478. }
  479. free(names);
  480. }
  481. DBUG_VOID_RETURN;
  482. }
  483. //
  484. // *******NOTE*****
  485. // If the flags HA_ONLINE_DROP_INDEX and HA_ONLINE_DROP_UNIQUE_INDEX
  486. // are ever added, prepare_drop_index and final_drop_index will need to be modified
  487. // so that the actual deletion of DB's is done in final_drop_index and not prepare_drop_index
  488. //
  489. static uint tokudb_alter_table_flags(uint flags)
  490. {
  491. return (HA_ONLINE_ADD_INDEX_NO_WRITES| HA_ONLINE_DROP_INDEX_NO_WRITES |
  492. HA_ONLINE_ADD_UNIQUE_INDEX_NO_WRITES| HA_ONLINE_DROP_UNIQUE_INDEX_NO_WRITES);
  493. }
  494. // options flags
  495. // PLUGIN_VAR_THDLOCAL Variable is per-connection
  496. // PLUGIN_VAR_READONLY Server variable is read only
  497. // PLUGIN_VAR_NOSYSVAR Not a server variable
  498. // PLUGIN_VAR_NOCMDOPT Not a command line option
  499. // PLUGIN_VAR_NOCMDARG No argument for cmd line
  500. // PLUGIN_VAR_RQCMDARG Argument required for cmd line
  501. // PLUGIN_VAR_OPCMDARG Argument optional for cmd line
  502. // PLUGIN_VAR_MEMALLOC String needs memory allocated
  503. // system variables
  504. static MYSQL_SYSVAR_ULONGLONG(cache_size, tokudb_cache_size, PLUGIN_VAR_READONLY, "TokuDB cache table size", NULL, NULL, 0, 0, ~0LL, 0);
  505. static MYSQL_SYSVAR_ULONG(max_lock, tokudb_max_lock, PLUGIN_VAR_READONLY, "TokuDB Max Locks", NULL, NULL, 8 * 1024, 0, ~0L, 0);
  506. static MYSQL_SYSVAR_ULONG(debug, tokudb_debug, PLUGIN_VAR_READONLY, "TokuDB Debug", NULL, NULL, 0, 0, ~0L, 0);
  507. static MYSQL_SYSVAR_STR(log_dir, tokudb_log_dir, PLUGIN_VAR_READONLY, "TokuDB Log Directory", NULL, NULL, NULL);
  508. static MYSQL_SYSVAR_STR(data_dir, tokudb_data_dir, PLUGIN_VAR_READONLY, "TokuDB Data Directory", NULL, NULL, NULL);
  509. static MYSQL_SYSVAR_STR(version, tokudb_version, PLUGIN_VAR_READONLY, "TokuDB Version", NULL, NULL, NULL);
  510. static MYSQL_SYSVAR_UINT(init_flags, tokudb_init_flags, PLUGIN_VAR_READONLY, "Sets TokuDB DB_ENV->open flags", NULL, NULL, tokudb_init_flags, 0, ~0, 0);
  511. static MYSQL_SYSVAR_UINT(checkpointing_period, tokudb_checkpointing_period, 0, "TokuDB Checkpointing period", NULL, NULL, 60, 0, ~0L, 0);
  512. #if 0
  513. static MYSQL_SYSVAR_ULONG(cache_parts, tokudb_cache_parts, PLUGIN_VAR_READONLY, "Sets TokuDB set_cache_parts", NULL, NULL, 0, 0, ~0L, 0);
  514. // this is really a u_int32_t
  515. // ? use MYSQL_SYSVAR_SET
  516. static MYSQL_SYSVAR_UINT(env_flags, tokudb_env_flags, PLUGIN_VAR_READONLY, "Sets TokuDB env_flags", NULL, NULL, DB_LOG_AUTOREMOVE, 0, ~0, 0);
  517. static MYSQL_SYSVAR_STR(home, tokudb_home, PLUGIN_VAR_READONLY, "Sets TokuDB env->open home", NULL, NULL, NULL);
  518. // this is really a u_int32_t
  519. //? use MYSQL_SYSVAR_SET
  520. // this looks to be unused
  521. static MYSQL_SYSVAR_LONG(lock_scan_time, tokudb_lock_scan_time, PLUGIN_VAR_READONLY, "Tokudb Lock Scan Time (UNUSED)", NULL, NULL, 0, 0, ~0L, 0);
  522. // this is really a u_int32_t
  523. //? use MYSQL_SYSVAR_ENUM
  524. static MYSQL_SYSVAR_UINT(lock_type, tokudb_lock_type, PLUGIN_VAR_READONLY, "Sets set_lk_detect", NULL, NULL, DB_LOCK_DEFAULT, 0, ~0, 0);
  525. static MYSQL_SYSVAR_ULONG(log_buffer_size, tokudb_log_buffer_size, PLUGIN_VAR_READONLY, "Tokudb Log Buffer Size", NULL, NULL, 0, 0, ~0L, 0);
  526. static MYSQL_SYSVAR_ULONG(region_size, tokudb_region_size, PLUGIN_VAR_READONLY, "Tokudb Region Size", NULL, NULL, 128 * 1024, 0, ~0L, 0);
  527. static MYSQL_SYSVAR_BOOL(shared_data, tokudb_shared_data, PLUGIN_VAR_READONLY, "Tokudb Shared Data", NULL, NULL, FALSE);
  528. static MYSQL_SYSVAR_STR(tmpdir, tokudb_tmpdir, PLUGIN_VAR_READONLY, "Tokudb Tmp Dir", NULL, NULL, NULL);
  529. #endif
  530. static struct st_mysql_sys_var *tokudb_system_variables[] = {
  531. MYSQL_SYSVAR(cache_size),
  532. MYSQL_SYSVAR(max_lock),
  533. MYSQL_SYSVAR(data_dir),
  534. MYSQL_SYSVAR(log_dir),
  535. MYSQL_SYSVAR(debug),
  536. MYSQL_SYSVAR(commit_sync),
  537. MYSQL_SYSVAR(version),
  538. MYSQL_SYSVAR(init_flags),
  539. MYSQL_SYSVAR(checkpointing_period),
  540. #if 0
  541. MYSQL_SYSVAR(cache_parts),
  542. MYSQL_SYSVAR(env_flags),
  543. MYSQL_SYSVAR(home),
  544. MYSQL_SYSVAR(lock_scan_time),
  545. MYSQL_SYSVAR(lock_type),
  546. MYSQL_SYSVAR(log_buffer_size),
  547. MYSQL_SYSVAR(region_size),
  548. MYSQL_SYSVAR(shared_data),
  549. MYSQL_SYSVAR(tmpdir),
  550. #endif
  551. NULL
  552. };
  553. mysql_declare_plugin(tokudb) {
  554. MYSQL_STORAGE_ENGINE_PLUGIN,
  555. &storage_engine_structure,
  556. "TokuDB",
  557. "Tokutek Inc",
  558. "Tokutek TokuDB Storage Engine",
  559. PLUGIN_LICENSE_GPL,
  560. tokudb_init_func, /* plugin init */
  561. tokudb_done_func, /* plugin deinit */
  562. 0x0210, /* 2.1.0 */
  563. NULL, /* status variables */
  564. tokudb_system_variables, /* system variables */
  565. NULL /* config options */
  566. }
  567. mysql_declare_plugin_end;