summaryrefslogtreecommitdiff
path: root/sql/log_event.cc
diff options
context:
space:
mode:
authorunknown <gbichot@quadita2.mysql.com>2005-05-05 14:20:53 +0200
committerunknown <gbichot@quadita2.mysql.com>2005-05-05 14:20:53 +0200
commitaf12ff656852b528e64fef7e4894ee4a33698fd8 (patch)
tree1203ddb23b4b230f311e090d94091e8940da887c /sql/log_event.cc
parent2275c0486ca3e44c8dcfe62f9c92af5537efd504 (diff)
downloadmariadb-git-af12ff656852b528e64fef7e4894ee4a33698fd8.tar.gz
Approximative fixes for BUG#2610,2611,9100 i.e. WL#2146 binlogging/replication of routines (stored procs and functions).
Approximative, because it's using our binlogging way (what we call "query"-level) and this is not as good as record-level binlog (5.1) would be. It imposes several limitations to routines, and has caveats (which I'll document, and for which the server will try to issue errors but that is not always possible). Reason I don't propagate caller info to the binlog as planned is that on master and slave users may be different; even with that some caveats would remain. mysql-test/mysql-test-run.sh: In the testsuite we know what we do, we are not creating nasty routines, and breaking binlog is ok except in rpl_sp. mysql-test/r/blackhole.result: Updating results now that 4.1 has been merged mysql-test/valgrind.supp: Some suppressions for Valgrind (useful on my machine Suse 9.1); this is just adding to the already existing suppressions of pthread and dl. sql/item_func.cc: Don't binlog the substatements when executing a function. If the function is declared to modify data and does not complete, warning "broken binlog". Note that SELECT myfunc() will not be binlogged even if myfunc() updates data (will be documented); but INSERT INTO t VALUES(myfunc()) will be binlogged (what decides is if the caller gets binlogged; the function changes nothing to binlogging). sql/log_event.cc: Just making functions which can be re-used when we binlog more strings in status_vars in Query_log_event (e.g. one day "user", "host"). sql/log_event.h: comment sql/mysql_priv.h: --log-bin-trust-routine-creators sql/mysqld.cc: --log-bin-trust-routine-creators sql/set_var.cc: --log-bin-trust-routine-creators sql/share/errmsg.txt: error messages to warn about problems with routines and binlog sql/slave.cc: If in a routine, replication table inclusion/exclusion rules always answer "replicate!" (see comment in code). sql/sp.cc: If binlog is on: errors if one wants to create a non-deterministic update routine (repeatability problem - note that the test is not perfect for functions) or does not have SUPER (because routines can easily be made to destroy slave's data with just CREATE ROUTINE and EXECUTE priv on master). --log-bin-trust-routine-creators removes these errors. Binlogging of CREATE PROCEDURE|FUNCTION. sql/sql_acl.cc: No thd==0 in tables_ok(). sql/sql_parse.cc: Binlogging of CALL (and not of the substatements of the SP). If SP returns error, we don't binlog it (see comment); we push warning in this case. Binlogging of ALTER|DROP PROCEDURE|FUNCTION with safety messages.
Diffstat (limited to 'sql/log_event.cc')
-rw-r--r--sql/log_event.cc62
1 files changed, 39 insertions, 23 deletions
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 86d31a9c2e8..42134d2b990 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -955,6 +955,18 @@ void Query_log_event::pack_info(Protocol *protocol)
#ifndef MYSQL_CLIENT
+/* Utility function for the next method */
+static void write_str_with_code_and_len(char **dst, const char *src,
+ int len, uint code)
+{
+ DBUG_ASSERT(src);
+ *((*dst)++)= code;
+ *((*dst)++)= (uchar) len;
+ bmove(*dst, src, len);
+ (*dst)+= len;
+}
+
+
/*
Query_log_event::write()
@@ -1039,12 +1051,10 @@ bool Query_log_event::write(IO_CACHE* file)
int8store(start, (ulonglong)sql_mode);
start+= 8;
}
- if (catalog_len) // i.e. "catalog inited" (false for 4.0 events)
+ if (catalog_len) // i.e. this var is inited (false for 4.0 events)
{
- *start++= Q_CATALOG_NZ_CODE;
- *start++= (uchar) catalog_len;
- bmove(start, catalog, catalog_len);
- start+= catalog_len;
+ write_str_with_code_and_len((char **)(&start),
+ catalog, catalog_len, Q_CATALOG_NZ_CODE);
/*
In 5.0.x where x<4 masters we used to store the end zero here. This was
a waste of one byte so we don't do it in x>=4 masters. We change code to
@@ -1176,6 +1186,25 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
#endif /* MYSQL_CLIENT */
+/* 2 utility functions for the next method */
+
+static void get_str_len_and_pointer(const char **dst, const char **src, uint *len)
+{
+ if ((*len= **src))
+ *dst= *src + 1; // Will be copied later
+ (*src)+= *len+1;
+}
+
+
+static void copy_str_and_move(char **dst, const char **src, uint len)
+{
+ memcpy(*dst, *src, len);
+ *src= *dst;
+ (*dst)+= len;
+ *(*dst)++= 0;
+}
+
+
/*
Query_log_event::Query_log_event()
This is used by the SQL slave thread to prepare the event before execution.
@@ -1264,9 +1293,7 @@ Query_log_event::Query_log_event(const char* buf, uint event_len,
break;
}
case Q_CATALOG_NZ_CODE:
- if ((catalog_len= *pos))
- catalog= (char*) pos+1; // Will be copied later
- pos+= catalog_len+1;
+ get_str_len_and_pointer(&catalog, (const char **)(&pos), &catalog_len);
break;
case Q_AUTO_INCREMENT:
auto_increment_increment= uint2korr(pos);
@@ -1282,9 +1309,7 @@ Query_log_event::Query_log_event(const char* buf, uint event_len,
}
case Q_TIME_ZONE_CODE:
{
- if ((time_zone_len= *pos))
- time_zone_str= (char *)(pos+1);
- pos+= time_zone_len+1;
+ get_str_len_and_pointer(&time_zone_str, (const char **)(&pos), &time_zone_len);
break;
}
case Q_CATALOG_CODE: /* for 5.0.x where 0<=x<=3 masters */
@@ -1308,12 +1333,7 @@ Query_log_event::Query_log_event(const char* buf, uint event_len,
if (catalog_len) // If catalog is given
{
if (likely(catalog_nz)) // true except if event comes from 5.0.0|1|2|3.
- {
- memcpy(start, catalog, catalog_len);
- catalog= start;
- start+= catalog_len;
- *start++= 0;
- }
+ copy_str_and_move(&start, &catalog, catalog_len);
else
{
memcpy(start, catalog, catalog_len+1); // copy end 0
@@ -1322,12 +1342,8 @@ Query_log_event::Query_log_event(const char* buf, uint event_len,
}
}
if (time_zone_len)
- {
- memcpy(start, time_zone_str, time_zone_len);
- time_zone_str= start;
- start+= time_zone_len;
- *start++= 0;
- }
+ copy_str_and_move(&start, &time_zone_str, time_zone_len);
+
/* A 2nd variable part; this is common to all versions */
memcpy((char*) start, end, data_len); // Copy db and query
start[data_len]= '\0'; // End query with \0 (For safetly)