212
216
static INNOBASE_SHARE *get_share(const char *table_name);
213
217
static void free_share(INNOBASE_SHARE *share);
214
static int innobase_close_connection(handlerton *hton, Session* session);
215
static int innobase_commit(handlerton *hton, Session* session, bool all);
216
static int innobase_rollback(handlerton *hton, Session* session, bool all);
217
static int innobase_rollback_to_savepoint(handlerton *hton, Session* session,
219
static int innobase_savepoint(handlerton *hton, Session* session, void *savepoint);
220
static int innobase_release_savepoint(handlerton *hton, Session* session,
222
static handler *innobase_create_handler(handlerton *hton,
219
class InnobaseEngine : public StorageEngine
222
InnobaseEngine(string name_arg) : StorageEngine(name_arg) {}
227
/*======================*/
228
/* out: 0 or error number */
229
Session* session); /* in: handle to the MySQL thread of the user
230
whose resources should be free'd */
232
virtual int savepoint_set(Session* session,
234
virtual int savepoint_rollback(Session* session,
236
virtual int savepoint_release(Session* session,
238
virtual int commit(Session* session, bool all);
239
virtual int rollback(Session* session, bool all);
241
/***********************************************************************
242
This function is used to prepare X/Open XA distributed transaction */
247
/* out: 0 or error number */
248
Session* session, /* in: handle to the MySQL thread of the user
249
whose XA transaction should be prepared */
250
bool all); /* in: TRUE - commit transaction
251
FALSE - the current SQL statement ended */
252
/***********************************************************************
253
This function is used to recover X/Open XA distributed transactions */
258
/* out: number of prepared transactions
259
stored in xid_list */
260
XID* xid_list, /* in/out: prepared transactions */
261
uint len); /* in: number of slots in xid_list */
262
/***********************************************************************
263
This function is used to commit one X/Open XA distributed transaction
264
which is in the prepared state */
268
/*===================*/
269
/* out: 0 or error number */
270
XID* xid); /* in: X/Open XA transaction identification */
271
/***********************************************************************
272
This function is used to rollback one X/Open XA distributed transaction
273
which is in the prepared state */
277
/*=====================*/
278
/* out: 0 or error number */
279
XID *xid); /* in: X/Open XA transaction identification */
281
virtual handler *create(TABLE_SHARE *table,
284
return new (mem_root) ha_innobase(this, table);
287
/*********************************************************************
288
Removes all tables in the named database inside InnoDB. */
292
/*===================*/
293
/* out: error number */
294
char* path); /* in: database path; inside InnoDB the name
295
of the last directory in the path is used as
296
the database name: for example, in 'mysql/data/test'
297
the database name is 'test' */
299
/*********************************************************************
300
Creates an InnoDB transaction struct for the session if it does not yet have one.
301
Starts a new InnoDB transaction if a transaction is not yet started. And
302
assigns a new snapshot for a consistent read if the transaction does not yet
306
start_consistent_snapshot(
307
/*====================================*/
309
Session* session); /* in: MySQL thread handle of the user for whom
310
the transaction should be committed */
311
/********************************************************************
312
Flushes InnoDB logs to disk and makes a checkpoint. Really, a commit flushes
313
the logs, and the name of this function should be innobase_checkpoint. */
318
/* out: TRUE if error */
320
/****************************************************************************
321
Implements the SHOW INNODB STATUS command. Sends the output of the InnoDB
322
Monitor to the client. */
327
Session* session, /* in: the MySQL query thread of the caller */
328
stat_print_fn *stat_print,
329
enum ha_stat_type stat_type);
333
release_temporary_latches(
334
/*===============================*/
336
Session* session); /* in: MySQL thread */
226
340
/****************************************************************
227
341
Validate the file format name and return its corresponding id. */
274
389
NULL, NULL, 50, 1, 1024 * 1024 * 1024, 0);
277
static handler *innobase_create_handler(handlerton *hton,
281
return new (mem_root) ha_innobase(hton, table);
284
/***********************************************************************
285
This function is used to prepare X/Open XA distributed transaction */
290
/* out: 0 or error number */
292
Session* session, /* in: handle to the MySQL thread of the user
293
whose XA transaction should be prepared */
294
bool all); /* in: TRUE - commit transaction
295
FALSE - the current SQL statement ended */
296
/***********************************************************************
297
This function is used to recover X/Open XA distributed transactions */
302
/* out: number of prepared transactions
303
stored in xid_list */
305
XID* xid_list, /* in/out: prepared transactions */
306
uint len); /* in: number of slots in xid_list */
307
/***********************************************************************
308
This function is used to commit one X/Open XA distributed transaction
309
which is in the prepared state */
312
innobase_commit_by_xid(
313
/*===================*/
314
/* out: 0 or error number */
316
XID* xid); /* in: X/Open XA transaction identification */
317
/***********************************************************************
318
This function is used to rollback one X/Open XA distributed transaction
319
which is in the prepared state */
322
innobase_rollback_by_xid(
323
/*=====================*/
324
/* out: 0 or error number */
326
XID *xid); /* in: X/Open XA transaction identification */
327
/*********************************************************************
328
Removes all tables in the named database inside InnoDB. */
331
innobase_drop_database(
332
/*===================*/
333
/* out: error number */
334
handlerton* hton, /* in: handlerton of Innodb */
335
char* path); /* in: database path; inside InnoDB the name
336
of the last directory in the path is used as
337
the database name: for example, in 'mysql/data/test'
338
the database name is 'test' */
339
392
/***********************************************************************
340
393
Closes an InnoDB database. */
343
396
innobase_deinit(void *p);
345
/*********************************************************************
346
Creates an InnoDB transaction struct for the session if it does not yet have one.
347
Starts a new InnoDB transaction if a transaction is not yet started. And
348
assigns a new snapshot for a consistent read if the transaction does not yet
352
innobase_start_trx_and_assign_read_view(
353
/*====================================*/
355
handlerton* hton, /* in: Innodb handlerton */
356
Session* session); /* in: MySQL thread handle of the user for whom
357
the transaction should be committed */
358
/********************************************************************
359
Flushes InnoDB logs to disk and makes a checkpoint. Really, a commit flushes
360
the logs, and the name of this function should be innobase_checkpoint. */
365
/* out: TRUE if error */
366
handlerton* hton); /* in: InnoDB handlerton */
368
/****************************************************************************
369
Implements the SHOW INNODB STATUS command. Sends the output of the InnoDB
370
Monitor to the client. */
375
handlerton* hton, /* in: the innodb handlerton */
376
Session* session, /* in: the MySQL query thread of the caller */
377
stat_print_fn *stat_print);
379
bool innobase_show_status(handlerton *hton, Session* session,
380
stat_print_fn* stat_print,
381
enum ha_stat_type stat_type);
383
399
/*********************************************************************
384
400
Commits a transaction in an InnoDB database. */
630
646
/* out: reference to transaction pointer */
631
647
Session* session) /* in: MySQL thread */
633
return(*(trx_t**) session_ha_data(session, innodb_hton_ptr));
649
return(*(trx_t**) session_ha_data(session, innodb_engine_ptr));
636
652
/************************************************************************
637
653
Call this function when mysqld passes control to the client. That is to
638
654
avoid deadlocks on the adaptive hash S-latch possibly held by session. For more
639
655
documentation, see handler.cc. */
642
innobase_release_temporary_latches(
657
InnobaseEngine::release_temporary_latches(
643
658
/*===============================*/
645
handlerton *hton, /* in: handlerton */
646
660
Session* session) /* in: MySQL thread */
650
assert(hton == innodb_hton_ptr);
664
assert(this == innodb_engine_ptr);
652
666
if (!innodb_inited) {
1370
1384
innobase_register_trx_and_stmt(
1371
1385
/*===========================*/
1372
handlerton *hton, /* in: Innobase handlerton */
1386
StorageEngine *engine, /* in: Innobase StorageEngine */
1373
1387
Session* session) /* in: MySQL session (connection) object */
1375
1389
/* NOTE that actually innobase_register_stmt() registers also
1376
1390
the transaction in the AUTOCOMMIT=1 mode. */
1378
innobase_register_stmt(hton, session);
1392
innobase_register_stmt(engine, session);
1380
1394
if (session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
1382
1396
/* No autocommit mode, register for a transaction */
1383
trans_register_ha(session, TRUE, hton);
1397
trans_register_ha(session, TRUE, engine);
1825
1839
char *default_path;
1826
1840
uint format_id;
1828
handlerton *innobase_hton= (handlerton *)p;
1842
StorageEngine **engine= static_cast<StorageEngine **>(p);
1843
InnobaseEngine *innobase_engine= new InnobaseEngine(string(innobase_engine_name));
1830
1845
#ifdef DRIZZLE_DYNAMIC_PLUGIN
1831
1846
if (!innodb_plugin_init()) {
1832
1847
errmsg_printf(ERRMSG_LVL_ERROR, "InnoDB plugin init failed.");
1836
if (innodb_hton_ptr) {
1837
/* Patch the statically linked handlerton and variables */
1838
innobase_hton = innodb_hton_ptr;
1840
1850
#endif /* DRIZZLE_DYNAMIC_PLUGIN */
1842
innodb_hton_ptr = innobase_hton;
1852
innodb_engine_ptr = innobase_engine;
1844
innobase_hton->state = SHOW_OPTION_YES;
1845
innobase_hton->savepoint_offset=sizeof(trx_named_savept_t);
1846
innobase_hton->close_connection=innobase_close_connection;
1847
innobase_hton->savepoint_set=innobase_savepoint;
1848
innobase_hton->savepoint_rollback=innobase_rollback_to_savepoint;
1849
innobase_hton->savepoint_release=innobase_release_savepoint;
1850
innobase_hton->commit=innobase_commit;
1851
innobase_hton->rollback=innobase_rollback;
1852
innobase_hton->prepare=innobase_xa_prepare;
1853
innobase_hton->recover=innobase_xa_recover;
1854
innobase_hton->commit_by_xid=innobase_commit_by_xid;
1855
innobase_hton->rollback_by_xid=innobase_rollback_by_xid;
1856
innobase_hton->create=innobase_create_handler;
1857
innobase_hton->drop_database=innobase_drop_database;
1858
innobase_hton->start_consistent_snapshot=innobase_start_trx_and_assign_read_view;
1859
innobase_hton->flush_logs=innobase_flush_logs;
1860
innobase_hton->show_status=innobase_show_status;
1861
innobase_hton->flags=HTON_NO_FLAGS;
1862
innobase_hton->release_temporary_latches=innobase_release_temporary_latches;
1854
innobase_engine->state = SHOW_OPTION_YES;
1855
innobase_engine->savepoint_offset=sizeof(trx_named_savept_t);
1856
innobase_engine->flags=HTON_NO_FLAGS;
1864
1858
ut_a(DATA_MYSQL_TRUE_VARCHAR == (ulint)DRIZZLE_TYPE_VARCHAR);
2456
2439
/* TODO: use provided savepoint data area to store savepoint data */
2458
int64_t2str((ulint)savepoint, name, 36);
2441
int64_t2str((ulint)savepoint, sp_name, 36);
2460
error = (int) trx_rollback_to_savepoint_for_mysql(trx, name,
2443
error = (int) trx_rollback_to_savepoint_for_mysql(trx, sp_name,
2461
2444
&mysql_binlog_cache_pos);
2462
2445
return(convert_error_code_to_mysql(error, 0, NULL));
2465
2448
/*********************************************************************
2466
2449
Release transaction savepoint name. */
2469
innobase_release_savepoint(
2451
InnobaseEngine::savepoint_release(
2470
2452
/*=======================*/
2471
2453
/* out: 0 if success, HA_ERR_NO_SAVEPOINT if
2472
2454
no savepoint with the given name */
2473
handlerton* hton, /* in: handlerton for Innodb */
2474
2455
Session* session, /* in: handle to the MySQL thread of the user
2475
2456
whose transaction should be rolled back */
2476
2457
void* savepoint) /* in: savepoint data */
2482
assert(hton == innodb_hton_ptr);
2463
assert(this == innodb_engine_ptr);
2484
2465
trx = check_trx_exists(session);
2486
2467
/* TODO: use provided savepoint data area to store savepoint data */
2488
int64_t2str((ulint)savepoint, name, 36);
2469
int64_t2str((ulint)savepoint, sp_name, 36);
2490
error = (int) trx_release_savepoint_for_mysql(trx, name);
2471
error = (int) trx_release_savepoint_for_mysql(trx, sp_name);
2492
2473
return(convert_error_code_to_mysql(error, 0, NULL));
2495
2476
/*********************************************************************
2496
2477
Sets a transaction savepoint. */
2479
InnobaseEngine::savepoint_set(
2500
2480
/*===============*/
2501
2481
/* out: always 0, that is, always succeeds */
2502
handlerton* hton, /* in: handle to the Innodb handlerton */
2503
2482
Session* session, /* in: handle to the MySQL thread */
2504
2483
void* savepoint) /* in: savepoint data */
2509
assert(hton == innodb_hton_ptr);
2488
assert(this == innodb_engine_ptr);
2512
2491
In the autocommit mode there is no sense to set a savepoint
2526
2505
assert(trx->active_trans);
2528
2507
/* TODO: use provided savepoint data area to store savepoint data */
2530
int64_t2str((ulint)savepoint,name,36);
2509
int64_t2str((ulint)savepoint,sp_name,36);
2532
error = (int) trx_savepoint_for_mysql(trx, name, (ib_int64_t)0);
2511
error = (int) trx_savepoint_for_mysql(trx, sp_name, (ib_int64_t)0);
2534
2513
return(convert_error_code_to_mysql(error, 0, NULL));
2537
2516
/*********************************************************************
2538
2517
Frees a possible InnoDB trx object associated with the current Session. */
2541
innobase_close_connection(
2519
InnobaseEngine::close_connection(
2542
2520
/*======================*/
2543
2521
/* out: 0 or error number */
2544
handlerton* hton, /* in: innobase handlerton */
2545
2522
Session* session) /* in: handle to the MySQL thread of the user
2546
2523
whose resources should be free'd */
2550
assert(hton == innodb_hton_ptr);
2527
assert(this == innodb_engine_ptr);
2551
2528
trx = session_to_trx(session);
7967
bool innobase_show_status(handlerton *hton, Session* session,
7968
stat_print_fn* stat_print,
7969
enum ha_stat_type stat_type)
7941
bool InnobaseEngine::show_status(Session* session,
7942
stat_print_fn* stat_print,
7943
enum ha_stat_type stat_type)
7971
assert(hton == innodb_hton_ptr);
7945
assert(this == innodb_engine_ptr);
7973
7947
switch (stat_type) {
7974
7948
case HA_ENGINE_STATUS:
7975
return innodb_show_status(hton, session, stat_print);
7949
return innodb_show_status(this, session, stat_print);
7976
7950
case HA_ENGINE_MUTEX:
7977
return innodb_mutex_show_status(hton, session, stat_print);
7951
return innodb_mutex_show_status(this, session, stat_print);