~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/rpl_mi.cc

  • Committer: Toru Maesaka
  • Date: 2008-07-17 05:59:20 UTC
  • mto: (202.1.1 toru)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: dev@torum.net-20080717055920-10okif50x6nh7b1d
forgot to bzr-add new files in the previous push

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include <drizzled/server_includes.h>
 
16
#include <my_global.h> // For HAVE_REPLICATION
 
17
#include "mysql_priv.h"
 
18
#include <my_dir.h>
 
19
 
17
20
#include "rpl_mi.h"
18
21
 
 
22
#ifdef HAVE_REPLICATION
 
23
 
19
24
#define DEFAULT_CONNECT_RETRY 60
20
25
 
21
26
// Defined in slave.cc
26
31
 
27
32
Master_info::Master_info()
28
33
  :Slave_reporting_capability("I/O"),
29
 
   ssl(0), ssl_verify_server_cert(0), fd(-1),  io_thd(0), port(DRIZZLE_PORT),
 
34
   ssl(0), ssl_verify_server_cert(0), fd(-1),  io_thd(0), port(MYSQL_PORT),
30
35
   connect_retry(DEFAULT_CONNECT_RETRY), heartbeat_period(0),
31
36
   received_heartbeats(0), inited(0),
32
37
   abort_slave(0), slave_running(0), slave_run_id(0)
35
40
  ssl_ca[0]= 0; ssl_capath[0]= 0; ssl_cert[0]= 0;
36
41
  ssl_cipher[0]= 0; ssl_key[0]= 0;
37
42
 
38
 
  memset(&file, 0, sizeof(file));
 
43
  bzero((char*) &file, sizeof(file));
39
44
  pthread_mutex_init(&run_lock, MY_MUTEX_INIT_FAST);
40
45
  pthread_mutex_init(&data_lock, MY_MUTEX_INIT_FAST);
41
46
  pthread_cond_init(&data_cond, NULL);
63
68
    if CHANGE MASTER did not specify it.  (no data loss in conversion
64
69
    as hb period has a max)
65
70
  */
66
 
  mi->heartbeat_period= (float) cmin((double)SLAVE_MAX_HEARTBEAT_PERIOD,
 
71
  mi->heartbeat_period= (float) min(SLAVE_MAX_HEARTBEAT_PERIOD,
67
72
                                    (slave_net_timeout/2.0));
68
73
  assert(mi->heartbeat_period > (float) 0.001
69
74
              || mi->heartbeat_period == 0);
114
119
    return(0);
115
120
  }
116
121
 
117
 
  mi->drizzle=0;
 
122
  mi->mysql=0;
118
123
  mi->file_id=1;
119
124
  fn_format(fname, master_info_fname, mysql_data_home, "", 4+32);
120
125
 
143
148
      my_close(fd, MYF(MY_WME));
144
149
    if ((fd = my_open(fname, O_CREAT|O_RDWR|O_BINARY, MYF(MY_WME))) < 0 )
145
150
    {
146
 
      sql_print_error(_("Failed to create a new master info file (file '%s', errno %d)"), fname, my_errno);
 
151
      sql_print_error("Failed to create a new master info file (file '%s', errno %d)", fname, my_errno);
147
152
      goto err;
148
153
    }
149
154
    if (init_io_cache(&mi->file, fd, IO_SIZE*2, READ_CACHE, 0L,0,
150
155
                      MYF(MY_WME)))
151
156
    {
152
 
      sql_print_error(_("Failed to create a cache on master info file (file '%s')"), fname);
 
157
      sql_print_error("Failed to create a cache on master info file (file '%s')", fname);
153
158
      goto err;
154
159
    }
155
160
 
165
170
    {
166
171
      if ((fd = my_open(fname, O_RDWR|O_BINARY, MYF(MY_WME))) < 0 )
167
172
      {
168
 
        sql_print_error(_("Failed to open the existing master info file (file '%s', errno %d)"), fname, my_errno);
 
173
        sql_print_error("Failed to open the existing master info file (file '%s', errno %d)", fname, my_errno);
169
174
        goto err;
170
175
      }
171
176
      if (init_io_cache(&mi->file, fd, IO_SIZE*2, READ_CACHE, 0L,
172
177
                        0, MYF(MY_WME)))
173
178
      {
174
 
        sql_print_error(_("Failed to create a cache on master info file (file '%s')"), fname);
 
179
        sql_print_error("Failed to create a cache on master info file (file '%s')", fname);
175
180
        goto err;
176
181
      }
177
182
    }
229
234
        init_strvar_from_file(mi->user, sizeof(mi->user), &mi->file, "test") ||
230
235
        init_strvar_from_file(mi->password, SCRAMBLED_PASSWORD_CHAR_LENGTH+1,
231
236
                              &mi->file, 0 ) ||
232
 
        init_intvar_from_file(&port, &mi->file, DRIZZLE_PORT) ||
 
237
        init_intvar_from_file(&port, &mi->file, MYSQL_PORT) ||
233
238
        init_intvar_from_file(&connect_retry, &mi->file, DEFAULT_CONNECT_RETRY))
234
239
      goto errwithmsg;
235
240
 
271
276
    }
272
277
 
273
278
    if (ssl)
274
 
      sql_print_warning(_("SSL information in the master info file "
275
 
                          "('%s') are ignored because this MySQL slave was "
276
 
                          "compiled without SSL support."), fname);
 
279
      sql_print_warning("SSL information in the master info file "
 
280
                      "('%s') are ignored because this MySQL slave was "
 
281
                      "compiled without SSL support.", fname);
277
282
 
278
283
    /*
279
284
      This has to be handled here as init_intvar_from_file can't handle
295
300
  // now change cache READ -> WRITE - must do this before flush_master_info
296
301
  reinit_io_cache(&mi->file, WRITE_CACHE, 0L, 0, 1);
297
302
  if ((error=test(flush_master_info(mi, 1))))
298
 
    sql_print_error(_("Failed to flush master info file"));
 
303
    sql_print_error("Failed to flush master info file");
299
304
  pthread_mutex_unlock(&mi->data_lock);
300
305
  return(error);
301
306
 
302
307
errwithmsg:
303
 
  sql_print_error(_("Error reading master configuration"));
 
308
  sql_print_error("Error reading master configuration");
304
309
 
305
310
err:
306
311
  if (fd >= 0)
358
363
     of file we don't care about this garbage.
359
364
  */
360
365
  char heartbeat_buf[sizeof(mi->heartbeat_period) * 4]; // buffer to suffice always
361
 
  sprintf(heartbeat_buf, "%.3f", mi->heartbeat_period);
 
366
  my_sprintf(heartbeat_buf, (heartbeat_buf, "%.3f", mi->heartbeat_period));
362
367
  my_b_seek(file, 0L);
363
368
  my_b_printf(file,
364
369
              "%u\n%s\n%s\n%s\n%s\n%s\n%d\n%d\n%d\n%s\n%s\n%s\n%s\n%s\n%d\n%s\n",
388
393
 
389
394
  return;
390
395
}
 
396
 
 
397
 
 
398
#endif /* HAVE_REPLICATION */