Tomas, hej.
> can someone explain to me what master_bind does?
>
> T
>
It's a new parameter to `change master ... master_bind=a.b.c.d'
forcing the slave to connect to the master with the specified source
address (a.b.c.d).
Andrei
> On Thu, 2008-01-31 at 12:20 +0200, Andrei Elkin wrote:
>> Stewart, hello!
>>
>> I have couple of notes about the replication code part.
>>
>> After had thought over if `master_bind' is a meaningful collocation I
>> doubt it is one.
>> I think we are better to rename it to `slave_bind' as it's entirely
>> the slave's property.
>> Seeing MASTER_BIND a.b.c.d in show slave status' report confuses me.
>>
>>
>> > Add option to CHANGE MASTER TO MASTER_BIND
>> > Add Master_Bind to SHOW SLAVE STATUS
>> > Set OPT_BIND_ADDR for client connection in slave thread
>> > default bind of all interfaces
>> >
>> > ===== sql/lex.h 1.148 vs edited =====
>> > Index: telco/sql/lex.h
>> > ===================================================================
>> > --- telco.orig/sql/lex.h 2007-09-03 17:20:36.514574529 +1000
>> > +++ telco/sql/lex.h 2007-09-04 09:55:02.032475331 +1000
>> > @@ -302,6 +302,7 @@ static SYMBOL symbols[] = {
>> > { "MASTER", SYM(MASTER_SYM)},
>> > { "MASTER_CONNECT_RETRY", SYM(MASTER_CONNECT_RETRY_SYM)},
>> > { "MASTER_HOST", SYM(MASTER_HOST_SYM)},
>> > + { "MASTER_BIND", SYM(MASTER_BIND_SYM)},
>> > { "MASTER_LOG_FILE", SYM(MASTER_LOG_FILE_SYM)},
>> > { "MASTER_LOG_POS", SYM(MASTER_LOG_POS_SYM)},
>> > { "MASTER_PASSWORD", SYM(MASTER_PASSWORD_SYM)},
>> > Index: telco/sql/log_event.h
>> > ===================================================================
>> > --- telco.orig/sql/log_event.h 2007-09-03 17:20:36.574577307 +1000
>> > +++ telco/sql/log_event.h 2007-09-04 09:55:02.136480248 +1000
>> > @@ -1132,6 +1132,7 @@ public:
>> > int master_host_len;
>> > int master_log_len;
>> > uint16 master_port;
>>
>> > + /* TODO add mysql_bind_addr here ? */
>>
>> I think the bind info is not necessary to be stored in a member of a
>> replication event class.
>> Please remove this TODO.
>>
>>
>> >
>> > #ifndef MYSQL_CLIENT
>> > Slave_log_event(THD* thd_arg, RELAY_LOG_INFO* rli);
>> > Index: telco/sql/repl_failsafe.cc
>> > ===================================================================
>> > --- telco.orig/sql/repl_failsafe.cc 2007-09-03 17:20:36.582577677 +1000
>> > +++ telco/sql/repl_failsafe.cc 2007-09-04 09:55:02.328489325 +1000
>> > @@ -691,6 +691,12 @@ int connect_to_master(THD *thd, MYSQL* m
>> > mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *)
> &slave_net_timeout);
>> > mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (char *)
> &slave_net_timeout);
>> >
>> > + if (mi->bind_addr && !strcmp(mi->bind_addr,"0.0.0.0"))
>> > + {
>> > + DBUG_PRINT("info",("rpl failsafe BIND ADDR: %s",mi->bind_addr));
>> > + mysql_options(mysql, MYSQL_OPT_BIND, mi->bind_addr);
>> > + }
>> > +
>> > #ifdef HAVE_OPENSSL
>> > if (mi->ssl)
>> > {
>> > Index: telco/sql/slave.cc
>> > ===================================================================
>> > --- telco.orig/sql/slave.cc 2007-09-03 17:21:59.574420274 +1000
>> > +++ telco/sql/slave.cc 2007-09-04 09:55:02.644504266 +1000
>> > @@ -1304,7 +1304,8 @@ bool show_master_info(THD* thd, MASTER_I
>> > field_list.push_back(new Item_empty_string("Last_IO_Error", 20));
>> > field_list.push_back(new Item_return_int("Last_SQL_Errno", 4,
> MYSQL_TYPE_LONG));
>> > field_list.push_back(new Item_empty_string("Last_SQL_Error", 20));
>> > -
>> > + field_list.push_back(new Item_empty_string("Master_Bind",
>> > + sizeof(mi->bind_addr)));
>> > if (protocol->send_fields(&field_list,
>> > Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
>> > DBUG_RETURN(TRUE);
>> > @@ -1423,6 +1424,8 @@ bool show_master_info(THD* thd, MASTER_I
>> > // Last_SQL_Error
>> > protocol->store(mi->rli.last_error().message,
> &my_charset_bin);
>> >
>> > + protocol->store(mi->bind_addr, &my_charset_bin);
>> > +
>> > pthread_mutex_unlock(&mi->rli.data_lock);
>> > pthread_mutex_unlock(&mi->data_lock);
>> >
>> > @@ -3271,6 +3274,12 @@ static int connect_to_master(THD* thd, M
>> > mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *)
> &slave_net_timeout);
>> > mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (char *)
> &slave_net_timeout);
>> >
>> > + if (mi->bind_addr[0])
>> > + {
>> > + DBUG_PRINT("info",("BIND ADDR: %s",mi->bind_addr));
>> > + mysql_options(mysql, MYSQL_OPT_BIND, mi->bind_addr);
>> > + }
>> > +
>> > #ifdef HAVE_OPENSSL
>> > if (mi->ssl)
>> > {
>> > Index: telco/sql/sql_lex.h
>> > ===================================================================
>> > --- telco.orig/sql/sql_lex.h 2007-09-03 17:20:36.810588232 +1000
>> > +++ telco/sql/sql_lex.h 2007-09-04 09:55:02.828512965 +1000
>> > @@ -185,7 +185,7 @@ typedef struct st_lex_server_options
>> >
>> > typedef struct st_lex_master_info
>> > {
>> > - char *host, *user, *password, *log_file_name;
>> > + char *host, *user, *password, *log_file_name, *bind_addr;
>> > uint port, connect_retry;
>> > ulonglong pos;
>> > ulong server_id;
>> > Index: telco/sql/sql_repl.cc
>> > ===================================================================
>> > --- telco.orig/sql/sql_repl.cc 2007-09-03 17:20:36.814588417 +1000
>> > +++ telco/sql/sql_repl.cc 2007-09-04 09:55:02.992520719 +1000
>> > @@ -1122,6 +1122,8 @@ bool change_master(THD* thd, MASTER_INFO
>> >
>> > if (lex_mi->host)
>> > strmake(mi->host, lex_mi->host, sizeof(mi->host)-1);
>> > + if (lex_mi->bind_addr)
>> > + strmake(mi->bind_addr, lex_mi->bind_addr,
> sizeof(mi->bind_addr)-1);
>> > if (lex_mi->user)
>> > strmake(mi->user, lex_mi->user, sizeof(mi->user)-1);
>> > if (lex_mi->password)
>> > Index: telco/sql/sql_yacc.yy
>> > ===================================================================
>> > --- telco.orig/sql/sql_yacc.yy 2007-09-03 17:20:36.822588788 +1000
>> > +++ telco/sql/sql_yacc.yy 2007-09-04 09:55:03.140527716 +1000
>> > @@ -773,6 +773,7 @@ bool my_yyoverflow(short **a, YYSTYPE **
>> > %token LT /* OPERATOR */
>> > %token MASTER_CONNECT_RETRY_SYM
>> > %token MASTER_HOST_SYM
>> > +%token MASTER_BIND_SYM
>> > %token MASTER_LOG_FILE_SYM
>> > %token MASTER_LOG_POS_SYM
>> > %token MASTER_PASSWORD_SYM
>> > @@ -1483,6 +1484,11 @@ master_def:
>> > Lex->mi.host = $3.str;
>> > }
>> > |
>> > + MASTER_BIND_SYM EQ TEXT_STRING_sys
>> > + {
>> > + Lex->mi.bind_addr = $3.str;
>> > + }
>> > + |
>> > MASTER_USER_SYM EQ TEXT_STRING_sys
>> > {
>> > Lex->mi.user = $3.str;
>> > Index: telco/sql/rpl_mi.cc
>> > ===================================================================
>> > --- telco.orig/sql/rpl_mi.cc 2007-09-03 17:20:36.862590639 +1000
>> > +++ telco/sql/rpl_mi.cc 2007-09-04 09:55:03.320536227 +1000
>> > @@ -33,7 +33,7 @@ MASTER_INFO::MASTER_INFO()
>> > abort_slave(0),slave_running(0),
>> > ssl_verify_server_cert(0), slave_run_id(0)
>> > {
>> > - host[0] = 0; user[0] = 0; password[0] = 0;
>> > + host[0] = 0; user[0] = 0; password[0] = 0; bind_addr[0] = 0;
>> > ssl_ca[0]= 0; ssl_capath[0]= 0; ssl_cert[0]= 0;
>> > ssl_cipher[0]= 0; ssl_key[0]= 0;
>> >
>> > @@ -62,6 +62,8 @@ void init_master_info_with_options(MASTE
>> > mi->master_log_name[0] = 0;
>> > mi->master_log_pos = BIN_LOG_HEADER_SIZE; // skip magic
> number
>> >
>> > + strmake(mi->bind_addr, "0.0.0.0", sizeof(mi->bind_addr));
>> > +
>> > if (master_host)
>> > strmake(mi->host, master_host, sizeof(mi->host) - 1);
>> > if (master_user)
>> > @@ -94,8 +96,10 @@ enum {
>> > /* 5.1.16 added value of master_ssl_verify_server_cert */
>> > LINE_FOR_MASTER_SSL_VERIFY_SERVER_CERT= 15,
>> >
>> > + LINES_IN_MASTER_INFO_WITH_SSL_AND_BIND_ADDR= 16,
>> > +
>> > /* Number of lines currently used when saving master info file */
>> > - LINES_IN_MASTER_INFO= LINE_FOR_MASTER_SSL_VERIFY_SERVER_CERT
>> > + LINES_IN_MASTER_INFO= LINES_IN_MASTER_INFO_WITH_SSL_AND_BIND_ADDR
>> > };
>> >
>> > int init_master_info(MASTER_INFO* mi, const char* master_info_fname,
>>
>> > @@ -282,6 +286,11 @@ file '%s')", fname);
>> > init_intvar_from_file(&ssl_verify_server_cert,
> &mi->file, 0))
>> > goto errwithmsg;
>> >
>> > + if (lines >= LINES_IN_MASTER_INFO_WITH_SSL_AND_BIND_ADDR
> &&
>> > + init_strvar_from_file(mi->bind_addr,
> sizeof(mi->bind_addr),
>> > + &mi->file, ""))
>> > + goto errwithmsg;
>> > +
>> > }
>> >
>> > #ifndef HAVE_OPENSSL
>> > @@ -290,7 +299,6 @@ file '%s')", fname);
>> > "('%s') are ignored because this MySQL slave was
> compiled "
>> > "without SSL support.", fname);
>> > #endif /* HAVE_OPENSSL */
>> > -
>> > /*
>> > This has to be handled here as init_intvar_from_file can't handle
>> > my_off_t types
>> > Index: telco/sql/rpl_mi.h
>> > ===================================================================
>> > --- telco.orig/sql/rpl_mi.h 2007-09-03 17:20:36.942594343 +1000
>> > +++ telco/sql/rpl_mi.h 2007-09-04 09:55:03.592549087 +1000
>> > @@ -64,6 +64,7 @@ class MASTER_INFO : public Slave_reporti
>> > /* the variables below are needed because we can change masters on the
> fly */
>> > char master_log_name[FN_REFLEN];
>> > char host[HOSTNAME_LENGTH+1];
>> > + char bind_addr[HOSTNAME_LENGTH+1];
>> > char user[USERNAME_LENGTH+1];
>> > char password[MAX_PASSWORD_LENGTH+1];
>> > my_bool ssl; // enables use of SSL connection if true
>> >
>> > --
>> > Stewart Smith
>>
>> cheers,
>>
>> Andrei