use env vars for socket/port in connect in mysqltest

--local-master option in mysql-test-run
do not log CREATE TABLE when doing table dump
fix replication to slave off 3.23 master
parent f89418b4
...@@ -1280,6 +1280,7 @@ int do_connect(struct st_query* q) ...@@ -1280,6 +1280,7 @@ int do_connect(struct st_query* q)
char buff[FN_REFLEN]; char buff[FN_REFLEN];
int con_port; int con_port;
int con_error; int con_error;
int free_con_sock = 0;
DBUG_ENTER("do_connect"); DBUG_ENTER("do_connect");
DBUG_PRINT("enter",("connect: %s",p)); DBUG_PRINT("enter",("connect: %s",p));
...@@ -1299,10 +1300,29 @@ int do_connect(struct st_query* q) ...@@ -1299,10 +1300,29 @@ int do_connect(struct st_query* q)
} }
else else
{ {
VAR* var_port, *var_sock;
p = safe_get_param(p, &con_port_str, "missing connection port"); p = safe_get_param(p, &con_port_str, "missing connection port");
con_port=atoi(con_port_str); if (*con_port_str == '$')
{
if (!(var_port = var_get(con_port_str, 0, 0)))
die("Unknown variable '%s'", con_port_str+1);
con_port = var_port->int_val;
}
else
con_port=atoi(con_port_str);
p = safe_get_param(p, &con_sock, "missing connection socket"); p = safe_get_param(p, &con_sock, "missing connection socket");
if (*con_sock == '$')
{
if (!(var_sock = var_get(con_sock, 0, 0)))
die("Unknown variable '%s'", con_sock+1);
if (!(con_sock = (char*)my_malloc(var_sock->str_val_len+1, MYF(0))))
die("Out of memory");
free_con_sock = 1;
memcpy(con_sock, var_sock->str_val, var_sock->str_val_len);
con_sock[var_sock->str_val_len] = 0;
}
} }
if (next_con == cons_end) if (next_con == cons_end)
die("Connection limit exhausted - increase MAX_CONS in mysqltest.c"); die("Connection limit exhausted - increase MAX_CONS in mysqltest.c");
...@@ -1310,20 +1330,21 @@ int do_connect(struct st_query* q) ...@@ -1310,20 +1330,21 @@ int do_connect(struct st_query* q)
die("Failed on mysql_init()"); die("Failed on mysql_init()");
if (opt_compress) if (opt_compress)
mysql_options(&next_con->mysql,MYSQL_OPT_COMPRESS,NullS); mysql_options(&next_con->mysql,MYSQL_OPT_COMPRESS,NullS);
if (con_sock) if (con_sock && !free_con_sock && *con_sock && *con_sock != FN_LIBCHAR)
con_sock=fn_format(buff, con_sock, TMPDIR, "",0); con_sock=fn_format(buff, con_sock, TMPDIR, "",0);
if (!con_db[0]) if (!con_db[0])
con_db=db; con_db=db;
if((con_error = safe_connect(&next_con->mysql, con_host, if((con_error = safe_connect(&next_con->mysql, con_host,
con_user, con_pass, con_user, con_pass,
con_db, con_port, con_sock))) con_db, con_port, *con_sock ? con_sock: 0)))
die("Could not open connection '%s': %s", con_name, die("Could not open connection '%s': %s", con_name,
mysql_error(&next_con->mysql)); mysql_error(&next_con->mysql));
if (!(next_con->name = my_strdup(con_name, MYF(MY_WME)))) if (!(next_con->name = my_strdup(con_name, MYF(MY_WME))))
die(NullS); die(NullS);
cur_con = next_con++; cur_con = next_con++;
if (free_con_sock)
my_free(con_sock, MYF(MY_WME));
DBUG_RETURN(0); DBUG_RETURN(0);
} }
......
connect (master,localhost,root,,test,0,master.sock); connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,);
connect (master1,localhost,root,,test,0,master.sock); connect (master1,127.0.0.1,root,,test,$MASTER_MYPORT,);
connect (slave,localhost,root,,test,0,slave.sock); connect (slave,127.0.0.1,root,,test,$SLAVE_MYPORT,);
connect (slave1,localhost,root,,test,0,slave.sock); connect (slave1,127.0.0.1,root,,test,$SLAVE_MYPORT,);
connection slave; connection slave;
--error 0,1199 --error 0,1199
!slave stop; !slave stop;
......
...@@ -151,6 +151,11 @@ while test $# -gt 0; do ...@@ -151,6 +151,11 @@ while test $# -gt 0; do
--verbose-manager) MANAGER_QUIET_OPT="" ;; --verbose-manager) MANAGER_QUIET_OPT="" ;;
--local) USE_RUNNING_SERVER="" ;; --local) USE_RUNNING_SERVER="" ;;
--tmpdir=*) MYSQL_TMP_DIR=`$ECHO "$1" | $SED -e "s;--tmpdir=;;"` ;; --tmpdir=*) MYSQL_TMP_DIR=`$ECHO "$1" | $SED -e "s;--tmpdir=;;"` ;;
--local-master)
MASTER_MYPORT=3306;
EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT --host=127.0.0.1 \
--port=$MYSQL_MYPORT"
LOCAL_MASTER=1 ;;
--master_port=*) MASTER_MYPORT=`$ECHO "$1" | $SED -e "s;--master_port=;;"` ;; --master_port=*) MASTER_MYPORT=`$ECHO "$1" | $SED -e "s;--master_port=;;"` ;;
--slave_port=*) SLAVE_MYPORT=`$ECHO "$1" | $SED -e "s;--slave_port=;;"` ;; --slave_port=*) SLAVE_MYPORT=`$ECHO "$1" | $SED -e "s;--slave_port=;;"` ;;
--manager-port=*) MYSQL_MANAGER_PORT=`$ECHO "$1" | $SED -e "s;--manager_port=;;"` ;; --manager-port=*) MYSQL_MANAGER_PORT=`$ECHO "$1" | $SED -e "s;--manager_port=;;"` ;;
...@@ -639,7 +644,9 @@ EOF ...@@ -639,7 +644,9 @@ EOF
start_master() start_master()
{ {
[ x$MASTER_RUNNING = 1 ] && return if [ x$MASTER_RUNNING = x1 ] || [ x$LOCAL_MASTER = x1 ] ; then
return
fi
# Remove old berkeley db log files that can confuse the server # Remove old berkeley db log files that can confuse the server
$RM -f $MASTER_MYDDIR/log.* $RM -f $MASTER_MYDDIR/log.*
# Remove stale binary logs # Remove stale binary logs
......
...@@ -467,8 +467,10 @@ Log_event* Log_event::read_log_event(IO_CACHE* file, bool old_format) ...@@ -467,8 +467,10 @@ Log_event* Log_event::read_log_event(IO_CACHE* file, bool old_format)
#endif #endif
{ {
char head[LOG_EVENT_HEADER_LEN]; char head[LOG_EVENT_HEADER_LEN];
uint header_size = old_format ? OLD_HEADER_LEN :
LOG_EVENT_HEADER_LEN;
LOCK_MUTEX; LOCK_MUTEX;
if (my_b_read(file, (byte *) head, sizeof(head))) if (my_b_read(file, (byte *) head, header_size ))
{ {
UNLOCK_MUTEX; UNLOCK_MUTEX;
return 0; return 0;
...@@ -485,7 +487,7 @@ Log_event* Log_event::read_log_event(IO_CACHE* file, bool old_format) ...@@ -485,7 +487,7 @@ Log_event* Log_event::read_log_event(IO_CACHE* file, bool old_format)
goto err; goto err;
} }
if (data_len < LOG_EVENT_HEADER_LEN) if (data_len < header_size)
{ {
error = "Event too small"; error = "Event too small";
goto err; goto err;
...@@ -498,9 +500,9 @@ Log_event* Log_event::read_log_event(IO_CACHE* file, bool old_format) ...@@ -498,9 +500,9 @@ Log_event* Log_event::read_log_event(IO_CACHE* file, bool old_format)
goto err; goto err;
} }
buf[data_len] = 0; buf[data_len] = 0;
memcpy(buf, head, LOG_EVENT_HEADER_LEN); memcpy(buf, head, header_size);
if(my_b_read(file, (byte*) buf + LOG_EVENT_HEADER_LEN, if(my_b_read(file, (byte*) buf + header_size,
data_len - LOG_EVENT_HEADER_LEN)) data_len - header_size))
{ {
error = "read error"; error = "read error";
goto err; goto err;
...@@ -653,11 +655,11 @@ void Rotate_log_event::print(FILE* file, bool short_form, char* last_db) ...@@ -653,11 +655,11 @@ void Rotate_log_event::print(FILE* file, bool short_form, char* last_db)
Start_log_event::Start_log_event(const char* buf, Start_log_event::Start_log_event(const char* buf,
bool old_format) :Log_event(buf, old_format) bool old_format) :Log_event(buf, old_format)
{ {
binlog_version = uint2korr(buf + LOG_EVENT_HEADER_LEN + buf += (old_format) ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN;
ST_BINLOG_VER_OFFSET); binlog_version = uint2korr(buf+ST_BINLOG_VER_OFFSET);
memcpy(server_version, buf + ST_SERVER_VER_OFFSET + LOG_EVENT_HEADER_LEN, memcpy(server_version, buf+ST_SERVER_VER_OFFSET,
ST_SERVER_VER_LEN); ST_SERVER_VER_LEN);
created = uint4korr(buf + ST_CREATED_OFFSET + LOG_EVENT_HEADER_LEN); created = uint4korr(buf+ST_CREATED_OFFSET);
} }
int Start_log_event::write_data(IO_CACHE* file) int Start_log_event::write_data(IO_CACHE* file)
...@@ -675,13 +677,24 @@ Rotate_log_event::Rotate_log_event(const char* buf, int event_len, ...@@ -675,13 +677,24 @@ Rotate_log_event::Rotate_log_event(const char* buf, int event_len,
{ {
// the caller will ensure that event_len is what we have at // the caller will ensure that event_len is what we have at
// EVENT_LEN_OFFSET // EVENT_LEN_OFFSET
if(event_len < ROTATE_EVENT_OVERHEAD) int header_size = (old_format) ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN;
uint ident_offset;
if(event_len < header_size)
return; return;
buf += header_size;
pos = uint8korr(buf + R_POS_OFFSET + LOG_EVENT_HEADER_LEN); if (old_format)
ident_len = (uchar)(event_len - ROTATE_EVENT_OVERHEAD); {
if (!(new_log_ident = (char*) my_memdup((byte*) buf + R_IDENT_OFFSET ident_len = (uchar)(event_len - OLD_HEADER_LEN);
+ LOG_EVENT_HEADER_LEN, pos = 4;
ident_offset = 0;
}
else
{
ident_len = (uchar)(event_len - ROTATE_EVENT_OVERHEAD);
pos = uint8korr(buf + R_POS_OFFSET);
ident_offset = ROTATE_HEADER_LEN;
}
if (!(new_log_ident = (char*) my_memdup((byte*) buf + ident_offset,
(uint) ident_len, MYF(MY_WME)))) (uint) ident_len, MYF(MY_WME))))
return; return;
...@@ -717,22 +730,32 @@ Query_log_event::Query_log_event(const char* buf, int event_len, ...@@ -717,22 +730,32 @@ Query_log_event::Query_log_event(const char* buf, int event_len,
bool old_format): bool old_format):
Log_event(buf, old_format),data_buf(0), query(NULL), db(NULL) Log_event(buf, old_format),data_buf(0), query(NULL), db(NULL)
{ {
if ((uint)event_len < QUERY_EVENT_OVERHEAD)
return;
ulong data_len; ulong data_len;
data_len = event_len - QUERY_EVENT_OVERHEAD; if (old_format)
{
if ((uint)event_len < OLD_HEADER_LEN + QUERY_HEADER_LEN)
return;
data_len = event_len - (QUERY_HEADER_LEN + OLD_HEADER_LEN);
buf += OLD_HEADER_LEN;
}
else
{
if ((uint)event_len < QUERY_EVENT_OVERHEAD)
return;
data_len = event_len - QUERY_EVENT_OVERHEAD;
buf += LOG_EVENT_HEADER_LEN;
}
exec_time = uint4korr(buf + LOG_EVENT_HEADER_LEN + Q_EXEC_TIME_OFFSET); exec_time = uint4korr(buf + Q_EXEC_TIME_OFFSET);
error_code = uint2korr(buf + LOG_EVENT_HEADER_LEN + Q_ERR_CODE_OFFSET); error_code = uint2korr(buf + Q_ERR_CODE_OFFSET);
if (!(data_buf = (char*) my_malloc(data_len + 1, MYF(MY_WME)))) if (!(data_buf = (char*) my_malloc(data_len + 1, MYF(MY_WME))))
return; return;
memcpy(data_buf, buf + LOG_EVENT_HEADER_LEN + Q_DATA_OFFSET, data_len); memcpy(data_buf, buf + Q_DATA_OFFSET, data_len);
thread_id = uint4korr(buf + LOG_EVENT_HEADER_LEN + Q_THREAD_ID_OFFSET); thread_id = uint4korr(buf + Q_THREAD_ID_OFFSET);
db = data_buf; db = data_buf;
db_len = (uint)buf[LOG_EVENT_HEADER_LEN + Q_DB_LEN_OFFSET]; db_len = (uint)buf[Q_DB_LEN_OFFSET];
query=data_buf + db_len + 1; query=data_buf + db_len + 1;
q_len = data_len - 1 - db_len; q_len = data_len - 1 - db_len;
*((char*)query+q_len) = 0; *((char*)query+q_len) = 0;
...@@ -788,7 +811,7 @@ int Query_log_event::write_data(IO_CACHE* file) ...@@ -788,7 +811,7 @@ int Query_log_event::write_data(IO_CACHE* file)
Intvar_log_event::Intvar_log_event(const char* buf, bool old_format): Intvar_log_event::Intvar_log_event(const char* buf, bool old_format):
Log_event(buf, old_format) Log_event(buf, old_format)
{ {
buf += LOG_EVENT_HEADER_LEN; buf += (old_format) ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN;
type = buf[I_TYPE_OFFSET]; type = buf[I_TYPE_OFFSET];
val = uint8korr(buf+I_VAL_OFFSET); val = uint8korr(buf+I_VAL_OFFSET);
} }
...@@ -1031,19 +1054,22 @@ Load_log_event::Load_log_event(const char* buf, int event_len, ...@@ -1031,19 +1054,22 @@ Load_log_event::Load_log_event(const char* buf, int event_len,
{ {
if (!event_len) // derived class, will call copy_log_event() itself if (!event_len) // derived class, will call copy_log_event() itself
return; return;
copy_log_event(buf, event_len); copy_log_event(buf, event_len, old_format);
} }
int Load_log_event::copy_log_event(const char *buf, ulong event_len) int Load_log_event::copy_log_event(const char *buf, ulong event_len,
bool old_format)
{ {
uint data_len; uint data_len;
char* buf_end = (char*)buf + event_len; char* buf_end = (char*)buf + event_len;
thread_id = uint4korr(buf + L_THREAD_ID_OFFSET + LOG_EVENT_HEADER_LEN); const char* data_head = buf + ((old_format) ?
exec_time = uint4korr(buf + L_EXEC_TIME_OFFSET + LOG_EVENT_HEADER_LEN); OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN);
skip_lines = uint4korr(buf + L_SKIP_LINES_OFFSET + LOG_EVENT_HEADER_LEN); thread_id = uint4korr(data_head + L_THREAD_ID_OFFSET);
table_name_len = (uint)buf[L_TBL_LEN_OFFSET + LOG_EVENT_HEADER_LEN]; exec_time = uint4korr(data_head + L_EXEC_TIME_OFFSET);
db_len = (uint)buf[L_DB_LEN_OFFSET + LOG_EVENT_HEADER_LEN]; skip_lines = uint4korr(data_head + L_SKIP_LINES_OFFSET);
num_fields = uint4korr(buf + L_NUM_FIELDS_OFFSET + LOG_EVENT_HEADER_LEN); table_name_len = (uint)data_head[L_TBL_LEN_OFFSET];
db_len = (uint)data_head[L_DB_LEN_OFFSET];
num_fields = uint4korr(data_head + L_NUM_FIELDS_OFFSET);
int body_offset = get_data_body_offset(); int body_offset = get_data_body_offset();
if ((int) event_len < body_offset) if ((int) event_len < body_offset)
...@@ -1315,7 +1341,7 @@ Create_file_log_event::Create_file_log_event(const char* buf, int len): ...@@ -1315,7 +1341,7 @@ Create_file_log_event::Create_file_log_event(const char* buf, int len):
Load_log_event(buf,0,0),fake_base(0),block(0) Load_log_event(buf,0,0),fake_base(0),block(0)
{ {
int block_offset; int block_offset;
if (copy_log_event(buf,len)) if (copy_log_event(buf,len,0))
return; return;
file_id = uint4korr(buf + LOG_EVENT_HEADER_LEN + file_id = uint4korr(buf + LOG_EVENT_HEADER_LEN +
+ LOAD_HEADER_LEN + CF_FILE_ID_OFFSET); + LOAD_HEADER_LEN + CF_FILE_ID_OFFSET);
......
...@@ -105,6 +105,7 @@ struct sql_ex_info ...@@ -105,6 +105,7 @@ struct sql_ex_info
/* event-specific post-header sizes */ /* event-specific post-header sizes */
#define LOG_EVENT_HEADER_LEN 19 #define LOG_EVENT_HEADER_LEN 19
#define OLD_HEADER_LEN 13
#define QUERY_HEADER_LEN (4 + 4 + 1 + 2) #define QUERY_HEADER_LEN (4 + 4 + 1 + 2)
#define LOAD_HEADER_LEN (4 + 4 + 4 + 1 +1 + 4) #define LOAD_HEADER_LEN (4 + 4 + 4 + 1 +1 + 4)
#define START_HEADER_LEN (2 + ST_SERVER_VER_LEN + 4) #define START_HEADER_LEN (2 + ST_SERVER_VER_LEN + 4)
...@@ -378,7 +379,7 @@ public: ...@@ -378,7 +379,7 @@ public:
class Load_log_event: public Log_event class Load_log_event: public Log_event
{ {
protected: protected:
int copy_log_event(const char *buf, ulong event_len); int copy_log_event(const char *buf, ulong event_len, bool old_format);
public: public:
ulong thread_id; ulong thread_id;
......
...@@ -393,6 +393,7 @@ static int create_table_from_dump(THD* thd, NET* net, const char* db, ...@@ -393,6 +393,7 @@ static int create_table_from_dump(THD* thd, NET* net, const char* db,
TABLE_LIST tables; TABLE_LIST tables;
int error= 1; int error= 1;
handler *file; handler *file;
uint save_options;
if (packet_len == packet_error) if (packet_len == packet_error)
{ {
...@@ -418,12 +419,17 @@ static int create_table_from_dump(THD* thd, NET* net, const char* db, ...@@ -418,12 +419,17 @@ static int create_table_from_dump(THD* thd, NET* net, const char* db,
thd->current_tablenr = 0; thd->current_tablenr = 0;
thd->query_error = 0; thd->query_error = 0;
thd->net.no_send_ok = 1; thd->net.no_send_ok = 1;
/* we do not want to log create table statement */
save_options = thd->options;
thd->options &= ~OPTION_BIN_LOG;
thd->proc_info = "Creating table from master dump"; thd->proc_info = "Creating table from master dump";
// save old db in case we are creating in a different database // save old db in case we are creating in a different database
char* save_db = thd->db; char* save_db = thd->db;
thd->db = (char*)db; thd->db = (char*)db;
mysql_parse(thd, thd->query, packet_len); // run create table mysql_parse(thd, thd->query, packet_len); // run create table
thd->db = save_db; // leave things the way the were before thd->db = save_db; // leave things the way the were before
thd->options = save_options;
if (thd->query_error) if (thd->query_error)
goto err; // mysql_parse took care of the error send goto err; // mysql_parse took care of the error send
...@@ -1000,7 +1006,7 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len) ...@@ -1000,7 +1006,7 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
int type_code = ev->get_type_code(); int type_code = ev->get_type_code();
int exec_res; int exec_res;
if (ev->server_id == ::server_id || if (ev->server_id == ::server_id ||
(slave_skip_counter && ev->get_type_code() != ROTATE_EVENT)) (slave_skip_counter && type_code != ROTATE_EVENT))
{ {
if(type_code == LOAD_EVENT) if(type_code == LOAD_EVENT)
skip_load_data_infile(net); skip_load_data_infile(net);
......
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