Commit 69a2345c authored by vasil's avatar vasil

Implement INFORMATION_SCHEMA tables innodb_trx, innodb_locks,

innodb_lock_waits. See
https://svn.innodb.com/innobase/InformationSchema/TransactionsAndLocks
for design notes.

Things that need to be resolved before this goes live:
* MySQL must add thd_get_thread_id() function to their code
  http://bugs.mysql.com/30930
* Allocate memory from mem_heap instead of using mem_alloc()
* Copy table name and index name into the cache because they may be
  freed later which will result in referencing freed memory

Approved by:	Marko
parent 4a1d105a
...@@ -104,6 +104,7 @@ noinst_HEADERS = include/btr0btr.h include/btr0btr.ic \ ...@@ -104,6 +104,7 @@ noinst_HEADERS = include/btr0btr.h include/btr0btr.ic \
include/sync0rw.ic include/sync0sync.h \ include/sync0rw.ic include/sync0sync.h \
include/sync0sync.ic include/sync0types.h \ include/sync0sync.ic include/sync0types.h \
include/thr0loc.h include/thr0loc.ic \ include/thr0loc.h include/thr0loc.ic \
include/trx0i_s.h \
include/trx0purge.h include/trx0purge.ic \ include/trx0purge.h include/trx0purge.ic \
include/trx0rec.h include/trx0rec.ic \ include/trx0rec.h include/trx0rec.ic \
include/trx0roll.h include/trx0roll.ic \ include/trx0roll.h include/trx0roll.ic \
...@@ -123,7 +124,8 @@ noinst_HEADERS = include/btr0btr.h include/btr0btr.ic \ ...@@ -123,7 +124,8 @@ noinst_HEADERS = include/btr0btr.h include/btr0btr.ic \
include/ut0vec.ic include/ut0list.h \ include/ut0vec.ic include/ut0list.h \
include/ut0list.ic include/ut0wqueue.h \ include/ut0list.ic include/ut0wqueue.h \
include/ha_prototypes.h handler/ha_innodb.h \ include/ha_prototypes.h handler/ha_innodb.h \
include/handler0alter.h include/handler0alter.h \
handler/i_s.h
EXTRA_LIBRARIES = libinnobase.a EXTRA_LIBRARIES = libinnobase.a
noinst_LIBRARIES = @plugin_innobase_static_target@ noinst_LIBRARIES = @plugin_innobase_static_target@
...@@ -154,13 +156,16 @@ libinnobase_a_SOURCES = btr/btr0btr.c btr/btr0cur.c btr/btr0pcur.c \ ...@@ -154,13 +156,16 @@ libinnobase_a_SOURCES = btr/btr0btr.c btr/btr0cur.c btr/btr0pcur.c \
row/row0undo.c row/row0upd.c row/row0vers.c \ row/row0undo.c row/row0upd.c row/row0vers.c \
srv/srv0que.c srv/srv0srv.c srv/srv0start.c \ srv/srv0que.c srv/srv0srv.c srv/srv0start.c \
sync/sync0arr.c sync/sync0rw.c \ sync/sync0arr.c sync/sync0rw.c \
sync/sync0sync.c thr/thr0loc.c trx/trx0purge.c \ sync/sync0sync.c thr/thr0loc.c \
trx/trx0i_s.c \
trx/trx0purge.c \
trx/trx0rec.c trx/trx0roll.c trx/trx0rseg.c \ trx/trx0rec.c trx/trx0roll.c trx/trx0rseg.c \
trx/trx0sys.c trx/trx0trx.c trx/trx0undo.c \ trx/trx0sys.c trx/trx0trx.c trx/trx0undo.c \
usr/usr0sess.c ut/ut0byte.c ut/ut0dbg.c \ usr/usr0sess.c ut/ut0byte.c ut/ut0dbg.c \
ut/ut0list.c ut/ut0mem.c ut/ut0rnd.c \ ut/ut0list.c ut/ut0mem.c ut/ut0rnd.c \
ut/ut0ut.c ut/ut0vec.c ut/ut0wqueue.c \ ut/ut0ut.c ut/ut0vec.c ut/ut0wqueue.c \
handler/ha_innodb.cc handler/handler0alter.cc handler/ha_innodb.cc handler/handler0alter.cc \
handler/i_s.cc
libinnobase_a_CXXFLAGS= $(AM_CFLAGS) libinnobase_a_CXXFLAGS= $(AM_CFLAGS)
libinnobase_a_CFLAGS = $(AM_CFLAGS) libinnobase_a_CFLAGS = $(AM_CFLAGS)
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <mysys_err.h> #include <mysys_err.h>
#include <my_sys.h> #include <my_sys.h>
#include "ha_innodb.h" #include "ha_innodb.h"
#include "i_s.h"
#include <mysql/plugin.h> #include <mysql/plugin.h>
#ifndef MYSQL_SERVER #ifndef MYSQL_SERVER
...@@ -8388,5 +8389,8 @@ mysql_declare_plugin(innobase) ...@@ -8388,5 +8389,8 @@ mysql_declare_plugin(innobase)
innobase_stat_zip_deinit, innobase_stat_zip_deinit,
0x0100 /* 1.0 */, 0x0100 /* 1.0 */,
NULL, NULL, NULL NULL, NULL, NULL
} },
i_s_innodb_trx,
i_s_innodb_locks,
i_s_innodb_lock_waits
mysql_declare_plugin_end; mysql_declare_plugin_end;
This diff is collapsed.
/******************************************************
InnoDB INFORMATION SCHEMA tables interface to MySQL.
(c) 2007 Innobase Oy
Created July 18, 2007 Vasil Dimov
*******************************************************/
#ifndef i_s_h
#define i_s_h
extern struct st_mysql_plugin i_s_innodb_trx;
extern struct st_mysql_plugin i_s_innodb_locks;
extern struct st_mysql_plugin i_s_innodb_lock_waits;
#endif /* i_s_h */
...@@ -383,6 +383,9 @@ or row lock! */ ...@@ -383,6 +383,9 @@ or row lock! */
their level set after the page is their level set after the page is
locked; see e.g. locked; see e.g.
ibuf_bitmap_get_map_page(). */ ibuf_bitmap_get_map_page(). */
#define SYNC_INFORMATION_SCHEMA 1900 /* Used when latching
INFORMATION SCHEMA internal
structures. */
#define SYNC_DICT_OPERATION 1001 /* table create, drop, etc. reserve #define SYNC_DICT_OPERATION 1001 /* table create, drop, etc. reserve
this in X-mode, implicit or backround this in X-mode, implicit or backround
operations purge, rollback, foreign operations purge, rollback, foreign
......
/******************************************************
INFORMATION SCHEMA innodb_trx, innodb_locks and
innodb_lock_waits tables cache structures and public
functions.
(c) 2007 Innobase Oy
Created July 17, 2007 Vasil Dimov
*******************************************************/
#ifndef trx0i_s_h
#define trx0i_s_h
#include "univ.i"
#include "ut0ut.h"
typedef struct i_s_locks_row_struct i_s_locks_row_t;
typedef struct i_s_hash_chain_struct i_s_hash_chain_t;
/* Objects of this type are added to the hash table
trx_i_s_cache_t::locks_hash */
struct i_s_hash_chain_struct {
i_s_locks_row_t* value;
i_s_hash_chain_t* next;
};
/* This structure represents INFORMATION_SCHEMA.innodb_locks row */
struct i_s_locks_row_struct {
ullint lock_trx_id;
const char* lock_mode;
const char* lock_type;
const char* lock_table;
const char* lock_index;
ulint lock_space;
ulint lock_page;
ulint lock_rec;
/* The following are auxiliary and not included in the table */
ullint lock_table_id;
i_s_hash_chain_t hash_chain; /* this object is added to the hash
table
trx_i_s_cache_t::locks_hash */
};
/* This structure represents INFORMATION_SCHEMA.innodb_trx row */
typedef struct i_s_trx_row_struct {
ullint trx_id;
const char* trx_state;
ib_time_t trx_started;
const i_s_locks_row_t* wait_lock_row;
ib_time_t trx_wait_started;
ulint trx_mysql_thread_id;
} i_s_trx_row_t;
/* This structure represents INFORMATION_SCHEMA.innodb_lock_waits row */
typedef struct i_s_lock_waits_row_struct {
const i_s_locks_row_t* wait_lock_row;
const i_s_locks_row_t* waited_lock_row;
} i_s_lock_waits_row_t;
/* This type is opaque and is defined in trx/trx0i_s.c */
typedef struct trx_i_s_cache_struct trx_i_s_cache_t;
/* Auxiliary enum used by functions that need to select one of the
INFORMATION_SCHEMA tables */
enum i_s_table {
I_S_INNODB_TRX,
I_S_INNODB_LOCKS,
I_S_INNODB_LOCK_WAITS
};
/* This is the intermediate buffer where data needed to fill the
INFORMATION SCHEMA tables is fetched and later retrieved by the C++
code in handler/i_s.cc. */
extern trx_i_s_cache_t* trx_i_s_cache;
/***********************************************************************
Initialize INFORMATION SCHEMA trx related cache. */
void
trx_i_s_cache_init(
/*===============*/
trx_i_s_cache_t* cache); /* out: cache to init */
/***********************************************************************
Issue a shared/read lock on the tables cache. */
void
trx_i_s_cache_start_read(
/*=====================*/
trx_i_s_cache_t* cache); /* in: cache */
/***********************************************************************
Release a shared/read lock on the tables cache. */
void
trx_i_s_cache_end_read(
/*===================*/
trx_i_s_cache_t* cache); /* in: cache */
/***********************************************************************
Issue an exclusive/write lock on the tables cache. */
void
trx_i_s_cache_start_write(
/*======================*/
trx_i_s_cache_t* cache); /* in: cache */
/***********************************************************************
Release an exclusive/write lock on the tables cache. */
void
trx_i_s_cache_end_write(
/*====================*/
trx_i_s_cache_t* cache); /* in: cache */
/***********************************************************************
Retrieves the number of used rows in the cache for a given
INFORMATION SCHEMA table. */
ullint
trx_i_s_cache_get_rows_used(
/*========================*/
/* out: number of rows */
trx_i_s_cache_t* cache, /* in: cache */
enum i_s_table table); /* in: which table */
/***********************************************************************
Retrieves the nth row in the cache for a given INFORMATION SCHEMA
table. */
void*
trx_i_s_cache_get_nth_row(
/*======================*/
/* out: row */
trx_i_s_cache_t* cache, /* in: cache */
enum i_s_table table, /* in: which table */
ulint n); /* in: row number */
/***********************************************************************
Update the transactions cache if it has not been read for some time. */
int
trx_i_s_possibly_fetch_data_into_cache(
/*===================================*/
/* out: 0 - fetched, 1 - not */
trx_i_s_cache_t* cache); /* in/out: cache */
/* The maximum length that may be required by lock_id_sz in
trx_i_s_create_lock_id(). "%llu:%lu:%lu:%lu" -> 84 chars */
#define TRX_I_S_LOCK_ID_MAX_LEN 84
/***********************************************************************
Crafts a lock id string from a i_s_locks_row_t object. Returns its
second argument. This function aborts if there is not enough space in
lock_id. Be sure to provide at least TRX_I_S_LOCK_ID_MAX_LEN if you want
to be 100% sure that it will not abort. */
char*
trx_i_s_create_lock_id(
/*===================*/
/* out: resulting lock id */
const i_s_locks_row_t* row, /* in: innodb_locks row */
char* lock_id,/* out: resulting lock_id */
ulint lock_id_size);/* in: size of the lock id
buffer */
#endif /* trx0i_s_h */
...@@ -49,6 +49,7 @@ Created 10/8/1995 Heikki Tuuri ...@@ -49,6 +49,7 @@ Created 10/8/1995 Heikki Tuuri
#include "srv0start.h" #include "srv0start.h"
#include "row0mysql.h" #include "row0mysql.h"
#include "ha_prototypes.h" #include "ha_prototypes.h"
#include "trx0i_s.h"
/* This is set to TRUE if the MySQL user has set it in MySQL; currently /* This is set to TRUE if the MySQL user has set it in MySQL; currently
affects only FOREIGN KEY definition parsing */ affects only FOREIGN KEY definition parsing */
...@@ -938,6 +939,9 @@ srv_init(void) ...@@ -938,6 +939,9 @@ srv_init(void)
conc_slot->event = os_event_create(NULL); conc_slot->event = os_event_create(NULL);
ut_a(conc_slot->event); ut_a(conc_slot->event);
} }
/* Initialize some INFORMATION SCHEMA internal structures */
trx_i_s_cache_init(trx_i_s_cache);
} }
/************************************************************************* /*************************************************************************
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment