Commit 313ce62f authored by unknown's avatar unknown

WL#1596 "make mysqldump --master-data --single-transaction able to do online...

WL#1596 "make mysqldump --master-data --single-transaction able to do online dump of InnoDB AND report reliable
binlog coordinates corresponding to the dump".
The good news is that now mysqldump can be used to get an online backup of InnoDB *which works for
point-in-time recovery and replication slave creation*. Formerly, mysqldump --master-data --single-transaction
used to call in fact mysqldump --master-data, so the dump was not an online dump (took big lock all time of dump).
The only lock which is now taken in this patch is at the beginning of the dump: mysqldump does:
FLUSH TABLES WITH READ LOCK; START TRANSACTION WITH CONSISTENT SNAPSHOT; SHOW MASTER STATUS; UNLOCK TABLES;
so the lock time is in fact the time FLUSH TABLES WITH READ LOCK takes to return (can be 0 or very long, if
a table is undergoing a huge update).
I have done some more minor changes listed in the paragraph of mysqldump.c.
WL#2237 "WITH CONSISTENT SNAPSHOT clause for START TRANSACTION":
it's a START TRANSACTION which additionally starts a consistent read on all
capable storage engine (i.e. InnoDB). So, can serve as a replacement for
BEGIN; SELECT * FROM some_innodb_table LIMIT 1; which starts a consistent read too. 


client/mysqldump.c:
  Main change: mysqldump --single-transaction --master-data is now able to, at the same time,
  take an online dump of InnoDB (using consistent read) AND get the binlog position corresponding to this dump
  (before, using the two options used to silently cancel --single-transaction).
  This uses the new START TRANSACTION WITH CONSISTENT SNAPSHOT syntax.
  Additional changes: 
  a) cleanup:
   - DBerror calls exit() so some code was unneeded
   - no need to call COMMIT at end, leave disconnection do the job
   - mysql_query_with_error_report()
  b) requirements I had heard from colleagues:
   - --master-data now requires an argument, to comment out ("--") the CHANGE MASTER or not
     (commenting had been asked for point-in-time recovery when replication is not necessary).
   - --first-slave is renamed to --lock-all-tables
  c) more sensible behaviours (has been discussed internally):
   - if used with --master-data, --flush-logs is probably intended to get a flush synchronous
     with the dump, not one random flush per dumped db.
   - disabled automatic reconnection as, at least, SQL_MODE would be lost (and also, depending
     on options, LOCK TABLES, BEGIN, FLUSH TABLES WITH READ LOCK).
include/mysqld_error.h:
  an error if START TRANSACTION WITH CONSISTENT SNAPSHOT is called and there is no consistent-read capable storage engine
  (idea ((C) PeterG) is that it's a bit like CREATE TABLE ENGINE=InnoDB when there is no support for InnoDB).
sql/handler.cc:
  new ha_start_consistent_snapshot(), which, inside an existing transaction, starts a consistent read
  (offers an alternative to SELECTing any InnoDB table). Does something only for InnoDB.
  Warning if no suitable engine supported.
sql/handler.h:
  declarations
sql/lex.h:
  symbols for lex
sql/share/czech/errmsg.txt:
  new message
sql/share/danish/errmsg.txt:
  new message
sql/share/dutch/errmsg.txt:
  new message
sql/share/english/errmsg.txt:
  new message
sql/share/estonian/errmsg.txt:
  new message
sql/share/french/errmsg.txt:
  new message
sql/share/german/errmsg.txt:
  new message
sql/share/greek/errmsg.txt:
  new message
sql/share/hungarian/errmsg.txt:
  new message
sql/share/italian/errmsg.txt:
  new message
sql/share/japanese/errmsg.txt:
  new message
sql/share/korean/errmsg.txt:
  new message
sql/share/norwegian-ny/errmsg.txt:
  new message
sql/share/norwegian/errmsg.txt:
  new message
sql/share/polish/errmsg.txt:
  new message
sql/share/portuguese/errmsg.txt:
  new message
sql/share/romanian/errmsg.txt:
  new message
sql/share/russian/errmsg.txt:
  new message
sql/share/serbian/errmsg.txt:
  new message
sql/share/slovak/errmsg.txt:
  new message
sql/share/spanish/errmsg.txt:
  new message
sql/share/swedish/errmsg.txt:
  new message
sql/share/ukrainian/errmsg.txt:
  new message
sql/sql_lex.h:
  new option in lex (transaction options)
sql/sql_parse.cc:
  warning comment (never make UNLOCK TABLES commit a transaction, please);
  support for starting consistent snapshot.
sql/sql_yacc.yy:
  new clause WITH CONSISTENT SNAPSHOT (syntax ok'd by PeterG) for START TRANSACTION.
parent c4d04e9e
This diff is collapsed.
......@@ -319,4 +319,5 @@
#define ER_INVALID_CHARACTER_STRING 1300
#define ER_WARN_ALLOWED_PACKET_OVERFLOWED 1301
#define ER_CONFLICTING_DECLARATIONS 1302
#define ER_ERROR_MESSAGES 303
#define ER_NO_CONS_READ_ENGINE 1303
#define ER_ERROR_MESSAGES 304
drop table if exists t1;
create table t1 (a int) engine=innodb;
start transaction with consistent snapshot;
insert into t1 values(1);
select * from t1;
a
commit;
delete from t1;
start transaction;
insert into t1 values(1);
select * from t1;
a
1
commit;
drop table t1;
-- source include/have_innodb.inc
--disable_warnings
drop table if exists t1;
--enable_warnings
connect (con1,localhost,root,,);
connect (con2,localhost,root,,);
### Test 1:
### - While a consistent snapshot transaction is executed,
### no external inserts should be visible to the transaction.
connection con1;
create table t1 (a int) engine=innodb;
start transaction with consistent snapshot;
connection con2;
insert into t1 values(1);
connection con1;
select * from t1; # if consistent snapshot was set as expected, we
# should see nothing.
commit;
### Test 2:
### - For any non-consistent snapshot transaction, external
### committed inserts should be visible to the transaction.
delete from t1;
start transaction; # Now we omit WITH CONSISTENT SNAPSHOT
connection con2;
insert into t1 values(1);
connection con1;
select * from t1; # if consistent snapshot was not set, as expected, we
# should see 1.
commit;
drop table t1;
......@@ -771,6 +771,24 @@ int ha_savepoint(THD *thd, char *savepoint_name)
DBUG_RETURN(error);
}
int ha_start_consistent_snapshot(THD *thd)
{
#ifdef HAVE_INNOBASE_DB
if ((have_innodb == SHOW_OPTION_YES) &&
!innobase_start_trx_and_assign_read_view(thd))
return 0;
#endif
/*
Same idea as when one wants to CREATE TABLE in one engine which does not
exist:
*/
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_NO_CONS_READ_ENGINE, ER(ER_NO_CONS_READ_ENGINE));
return 0;
}
bool ha_flush_logs()
{
bool result=0;
......
......@@ -138,6 +138,8 @@
#define HA_CACHE_TBL_ASKTRANSACT 2
#define HA_CACHE_TBL_TRANSACT 4
/* Options of START TRANSACTION statement (and later of SET TRANSACTION stmt) */
#define MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT 1
enum db_type
{
......@@ -567,5 +569,4 @@ int ha_discover(THD* thd, const char* dbname, const char* name,
int ha_find_files(THD *thd,const char *db,const char *path,
const char *wild, bool dir,List<char>* files);
int ha_table_exists(THD* thd, const char* db, const char* name);
int ha_start_consistent_snapshot(THD *thd);
......@@ -114,6 +114,7 @@ static SYMBOL symbols[] = {
{ "COMMITTED", SYM(COMMITTED_SYM)},
{ "COMPRESSED", SYM(COMPRESSED_SYM)},
{ "CONCURRENT", SYM(CONCURRENT)},
{ "CONSISTENT", SYM(CONSISTENT_SYM)},
{ "CONSTRAINT", SYM(CONSTRAINT)},
{ "CONVERT", SYM(CONVERT_SYM)},
{ "CREATE", SYM(CREATE)},
......@@ -382,6 +383,7 @@ static SYMBOL symbols[] = {
{ "SIGNED", SYM(SIGNED_SYM)},
{ "SIMPLE", SYM(SIMPLE_SYM)},
{ "SLAVE", SYM(SLAVE)},
{ "SNAPSHOT", SYM(SNAPSHOT_SYM)},
{ "SMALLINT", SYM(SMALLINT)},
{ "SOME", SYM(ANY_SYM)},
{ "SONAME", SYM(UDF_SONAME_SYM)},
......
......@@ -331,3 +331,4 @@ character-set=latin2
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -322,3 +322,4 @@ character-set=latin1
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -331,3 +331,4 @@ character-set=latin1
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -319,3 +319,4 @@ character-set=latin1
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -324,3 +324,4 @@ character-set=latin7
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -319,3 +319,4 @@ character-set=latin1
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -332,3 +332,4 @@ character-set=latin1
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -319,3 +319,4 @@ character-set=greek
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -324,3 +324,4 @@ character-set=latin2
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -319,3 +319,4 @@ character-set=latin1
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -323,3 +323,4 @@ character-set=ujis
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -319,3 +319,4 @@ character-set=euckr
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -321,3 +321,4 @@ character-set=latin1
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -321,3 +321,4 @@ character-set=latin1
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -324,3 +324,4 @@ character-set=latin2
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -321,3 +321,4 @@ character-set=latin1
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -324,3 +324,4 @@ character-set=latin2
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -324,3 +324,4 @@ character-set=koi8r
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -312,3 +312,4 @@ character-set=cp1250
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -327,3 +327,4 @@ character-set=latin2
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -323,3 +323,4 @@ character-set=latin1
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -319,3 +319,4 @@ character-set=latin1
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -325,3 +325,4 @@ character-set=koi8u
"Invalid %s character string: '%.64s'",
"Result of %s() was larger than max_allowed_packet (%ld) - truncated"
"Conflicting declarations: '%s%s' and '%s%s'"
"This MySQL server does not support any consistent-read capable storage engine"
......@@ -613,7 +613,7 @@ typedef struct st_lex
uint uint_geom_type;
uint grant, grant_tot_col, which_columns;
uint fk_delete_opt, fk_update_opt, fk_match_option;
uint slave_thd_opt;
uint slave_thd_opt, start_transaction_opt;
uint8 describe;
bool drop_if_exists, drop_temporary, local_file, one_shot_set;
bool in_comment, ignore_space, verbose, no_write_to_binlog;
......
......@@ -3076,6 +3076,12 @@ purposes internal to the MySQL server", MYF(0));
}
case SQLCOM_UNLOCK_TABLES:
/*
It is critical for mysqldump --single-transaction --master-data that
UNLOCK TABLES does not implicitely commit a connection which has only
done FLUSH TABLES WITH READ LOCK + BEGIN. If this assumption becomes
false, mysqldump will not work.
*/
unlock_locked_tables(thd);
if (thd->options & OPTION_TABLE_LOCK)
{
......@@ -3462,6 +3468,8 @@ purposes internal to the MySQL server", MYF(0));
thd->options= ((thd->options & (ulong) ~(OPTION_STATUS_NO_TRANS_UPDATE)) |
OPTION_BEGIN);
thd->server_status|= SERVER_STATUS_IN_TRANS;
if (!(lex->start_transaction_opt & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT) ||
!(res= ha_start_consistent_snapshot(thd)))
send_ok(thd);
}
break;
......
......@@ -131,6 +131,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token CLIENT_SYM
%token COMMENT_SYM
%token COMMIT_SYM
%token CONSISTENT_SYM
%token COUNT_SYM
%token CREATE
%token CROSS
......@@ -165,6 +166,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token SELECT_SYM
%token SHOW
%token SLAVE
%token SNAPSHOT_SYM
%token SQL_THREAD
%token START_SYM
%token STD_SYM
......@@ -618,6 +620,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
table_option opt_if_not_exists opt_no_write_to_binlog opt_var_type
opt_var_ident_type delete_option opt_temporary all_or_any opt_distinct
opt_ignore_leaves fulltext_options spatial_type union_option
start_transaction_opts
%type <ulong_num>
ULONG_NUM raid_types merge_insert_types
......@@ -2095,10 +2098,20 @@ slave:
start:
START_SYM TRANSACTION_SYM { Lex->sql_command = SQLCOM_BEGIN;}
{}
START_SYM TRANSACTION_SYM start_transaction_opts
{
Lex->sql_command = SQLCOM_BEGIN;
Lex->start_transaction_opt= $3;
}
;
start_transaction_opts:
/*empty*/ { $$ = 0; }
| WITH CONSISTENT_SYM SNAPSHOT_SYM
{
$$= MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT;
}
slave_thread_opts:
{ Lex->slave_thd_opt= 0; }
slave_thread_opt_list
......@@ -5122,6 +5135,7 @@ keyword:
| COMMIT_SYM {}
| COMPRESSED_SYM {}
| CONCURRENT {}
| CONSISTENT_SYM {}
| CUBE_SYM {}
| DATA_SYM {}
| DATETIME {}
......@@ -5262,6 +5276,7 @@ keyword:
| SHARE_SYM {}
| SHUTDOWN {}
| SLAVE {}
| SNAPSHOT_SYM {}
| SOUNDS_SYM {}
| SQL_CACHE_SYM {}
| SQL_BUFFER_RESULT {}
......@@ -5888,7 +5903,7 @@ grant_option:
;
begin:
BEGIN_SYM { Lex->sql_command = SQLCOM_BEGIN;} opt_work {}
BEGIN_SYM { Lex->sql_command = SQLCOM_BEGIN; Lex->start_transaction_opt= 0;} opt_work {}
;
opt_work:
......
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