~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/rpl_rli.cc

Removed dead variable, sorted authors file.

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>
17
 
 
18
 
#if TIME_WITH_SYS_TIME
19
 
# include <sys/time.h>
20
 
# include <time.h>
21
 
#else
22
 
# if HAVE_SYS_TIME_H
23
 
#  include <sys/time.h>
24
 
# else
25
 
#  include <time.h>
26
 
# endif
27
 
#endif
28
 
 
 
16
#include "mysql_priv.h"
29
17
 
30
18
#include "rpl_mi.h"
31
19
#include "rpl_rli.h"
 
20
#include <my_dir.h>
32
21
#include "sql_repl.h"  // For check_binlog_magic
33
22
#include "rpl_utility.h"
34
23
 
35
 
#include <libdrizzle/gettext.h>
36
 
 
37
24
static int32_t count_relay_log_space(Relay_log_info* rli);
38
25
 
39
26
// Defined in slave.cc
61
48
  group_relay_log_name[0]= event_relay_log_name[0]=
62
49
    group_master_log_name[0]= 0;
63
50
  until_log_name[0]= ign_master_log_name_end[0]= 0;
64
 
  memset(&info_file, 0, sizeof(info_file));
65
 
  memset(&cache_buf, 0, sizeof(cache_buf));
 
51
  bzero((char*) &info_file, sizeof(info_file));
 
52
  bzero((char*) &cache_buf, sizeof(cache_buf));
 
53
  cached_charset_invalidate();
66
54
  pthread_mutex_init(&run_lock, MY_MUTEX_INIT_FAST);
67
55
  pthread_mutex_init(&data_lock, MY_MUTEX_INIT_FAST);
68
56
  pthread_mutex_init(&log_space_lock, MY_MUTEX_INIT_FAST);
142
130
        instead require a name. But as we don't want to break many existing
143
131
        setups, we only give warning, not error.
144
132
      */
145
 
      sql_print_warning(_("Neither --relay-log nor --relay-log-index were used;"
 
133
      sql_print_warning("Neither --relay-log nor --relay-log-index were used;"
146
134
                        " so replication "
147
135
                        "may break when this MySQL server acts as a "
148
136
                        "slave and has his hostname changed!! Please "
149
 
                        "use '--relay-log=%s' to avoid this problem."), ln);
 
137
                        "use '--relay-log=%s' to avoid this problem.", ln);
150
138
      name_warning_sent= 1;
151
139
    }
152
140
    /*
159
147
                            max_binlog_size), 1))
160
148
    {
161
149
      pthread_mutex_unlock(&rli->data_lock);
162
 
      sql_print_error(_("Failed in open_log() called from "
163
 
                        "init_relay_log_info()"));
 
150
      sql_print_error("Failed in open_log() called from init_relay_log_info()");
164
151
      return(1);
165
152
    }
166
153
  }
168
155
  /* if file does not exist */
169
156
  if (access(fname,F_OK))
170
157
  {
171
 
    /* Create a new file */
 
158
    /*
 
159
      If someone removed the file from underneath our feet, just close
 
160
      the old descriptor and re-create the old file
 
161
    */
 
162
    if (info_fd >= 0)
 
163
      my_close(info_fd, MYF(MY_WME));
 
164
    if ((info_fd = my_open(fname, O_CREAT|O_RDWR|O_BINARY, MYF(MY_WME))) < 0)
 
165
    {
 
166
      sql_print_error("Failed to create a new relay log info file (\
 
167
file '%s', errno %d)", fname, my_errno);
 
168
      msg= current_thd->main_da.message();
 
169
      goto err;
 
170
    }
 
171
    if (init_io_cache(&rli->info_file, info_fd, IO_SIZE*2, READ_CACHE, 0L,0,
 
172
                      MYF(MY_WME)))
 
173
    {
 
174
      sql_print_error("Failed to create a cache on relay log info file '%s'",
 
175
                      fname);
 
176
      msg= current_thd->main_da.message();
 
177
      goto err;
 
178
    }
 
179
 
 
180
    /* Init relay log with first entry in the relay index file */
 
181
    if (init_relay_log_pos(rli,NullS,BIN_LOG_HEADER_SIZE,0 /* no data lock */,
 
182
                           &msg, 0))
 
183
    {
 
184
      sql_print_error("Failed to open the relay log 'FIRST' (relay_log_pos 4)");
 
185
      goto err;
 
186
    }
 
187
    rli->group_master_log_name[0]= 0;
 
188
    rli->group_master_log_pos= 0;
 
189
    rli->info_fd= info_fd;
172
190
  }
173
191
  else // file exists
174
192
  {
175
 
    /* Open up fname here and pull out the relay.info data */
 
193
    if (info_fd >= 0)
 
194
      reinit_io_cache(&rli->info_file, READ_CACHE, 0L,0,0);
 
195
    else
 
196
    {
 
197
      int32_t error=0;
 
198
      if ((info_fd = my_open(fname, O_RDWR|O_BINARY, MYF(MY_WME))) < 0)
 
199
      {
 
200
        sql_print_error("\
 
201
Failed to open the existing relay log info file '%s' (errno %d)",
 
202
                        fname, my_errno);
 
203
        error= 1;
 
204
      }
 
205
      else if (init_io_cache(&rli->info_file, info_fd,
 
206
                             IO_SIZE*2, READ_CACHE, 0L, 0, MYF(MY_WME)))
 
207
      {
 
208
        sql_print_error("Failed to create a cache on relay log info file '%s'",
 
209
                        fname);
 
210
        error= 1;
 
211
      }
 
212
      if (error)
 
213
      {
 
214
        if (info_fd >= 0)
 
215
          my_close(info_fd, MYF(0));
 
216
        rli->info_fd= -1;
 
217
        rli->relay_log.close(LOG_CLOSE_INDEX | LOG_CLOSE_STOP_EVENT);
 
218
        pthread_mutex_unlock(&rli->data_lock);
 
219
        return(1);
 
220
      }
 
221
    }
 
222
 
 
223
    rli->info_fd = info_fd;
 
224
    int32_t relay_log_pos, master_log_pos;
 
225
    if (init_strvar_from_file(rli->group_relay_log_name,
 
226
                              sizeof(rli->group_relay_log_name),
 
227
                              &rli->info_file, "") ||
 
228
       init_intvar_from_file(&relay_log_pos,
 
229
                             &rli->info_file, BIN_LOG_HEADER_SIZE) ||
 
230
       init_strvar_from_file(rli->group_master_log_name,
 
231
                             sizeof(rli->group_master_log_name),
 
232
                             &rli->info_file, "") ||
 
233
       init_intvar_from_file(&master_log_pos, &rli->info_file, 0))
 
234
    {
 
235
      msg="Error reading slave log configuration";
 
236
      goto err;
 
237
    }
 
238
    strmake(rli->event_relay_log_name,rli->group_relay_log_name,
 
239
            sizeof(rli->event_relay_log_name)-1);
 
240
    rli->group_relay_log_pos= rli->event_relay_log_pos= relay_log_pos;
 
241
    rli->group_master_log_pos= master_log_pos;
 
242
 
 
243
    if (init_relay_log_pos(rli,
 
244
                           rli->group_relay_log_name,
 
245
                           rli->group_relay_log_pos,
 
246
                           0 /* no data lock*/,
 
247
                           &msg, 0))
 
248
    {
 
249
      char llbuf[22];
 
250
      sql_print_error("Failed to open the relay log '%s' (relay_log_pos %s)",
 
251
                      rli->group_relay_log_name,
 
252
                      llstr(rli->group_relay_log_pos, llbuf));
 
253
      goto err;
 
254
    }
176
255
  }
 
256
  assert(rli->event_relay_log_pos >= BIN_LOG_HEADER_SIZE);
 
257
  assert(my_b_tell(rli->cur_log) == rli->event_relay_log_pos);
177
258
 
178
259
  /*
179
260
    Now change the cache from READ to WRITE - must do this
181
262
  */
182
263
  reinit_io_cache(&rli->info_file, WRITE_CACHE,0L,0,1);
183
264
  if ((error= flush_relay_log_info(rli)))
184
 
    sql_print_error(_("Failed to flush relay log info file"));
 
265
    sql_print_error("Failed to flush relay log info file");
185
266
  if (count_relay_log_space(rli))
186
267
  {
187
 
    msg=_("Error counting relay log space");
 
268
    msg="Error counting relay log space";
188
269
    goto err;
189
270
  }
190
271
  rli->inited= 1;
208
289
  struct stat s;
209
290
  if (stat(linfo->log_file_name,&s))
210
291
  {
211
 
    sql_print_error(_("log %s listed in the index, but failed to stat"),
 
292
    sql_print_error("log %s listed in the index, but failed to stat",
212
293
                    linfo->log_file_name);
213
294
    return(1);
214
295
  }
221
302
{
222
303
  LOG_INFO linfo;
223
304
  rli->log_space_total= 0;
224
 
  if (rli->relay_log.find_log_pos(&linfo, NULL, 1))
 
305
  if (rli->relay_log.find_log_pos(&linfo, NullS, 1))
225
306
  {
226
 
    sql_print_error(_("Could not find first log while counting relay "
227
 
                      "log space"));
 
307
    sql_print_error("Could not find first log while counting relay log space");
228
308
    return(1);
229
309
  }
230
310
  do
336
416
    Test to see if the previous run was with the skip of purging
337
417
    If yes, we do not purge when we restart
338
418
  */
339
 
  if (rli->relay_log.find_log_pos(&rli->linfo, NULL, 1))
 
419
  if (rli->relay_log.find_log_pos(&rli->linfo, NullS, 1))
340
420
  {
341
421
    *errmsg="Could not find first log during relay log initialization";
342
422
    goto err;
347
427
    *errmsg="Could not find target log during relay log initialization";
348
428
    goto err;
349
429
  }
350
 
 
351
 
  rli->group_relay_log_name.assign(rli->linfo.log_file_name);
352
 
  rli->event_relay_log_name.assign(rli->linfo.log_file_name);
353
 
 
 
430
  strmake(rli->group_relay_log_name,rli->linfo.log_file_name,
 
431
          sizeof(rli->group_relay_log_name)-1);
 
432
  strmake(rli->event_relay_log_name,rli->linfo.log_file_name,
 
433
          sizeof(rli->event_relay_log_name)-1);
354
434
  if (rli->relay_log.is_active(rli->linfo.log_file_name))
355
435
  {
356
436
    /*
525
605
  uint32_t log_name_extension;
526
606
  char log_name_tmp[FN_REFLEN]; //make a char[] from String
527
607
 
528
 
  strmake(log_name_tmp, log_name->ptr(), cmin(log_name->length(), (uint32_t)FN_REFLEN-1));
 
608
  strmake(log_name_tmp, log_name->ptr(), min(log_name->length(), FN_REFLEN-1));
529
609
 
530
610
  char *p= fn_ext(log_name_tmp);
531
611
  char *p_end;
535
615
    goto err;
536
616
  }
537
617
  // Convert 0-3 to 4
538
 
  log_pos= cmax(log_pos, (int64_t)BIN_LOG_HEADER_SIZE);
 
618
  log_pos= max(log_pos, BIN_LOG_HEADER_SIZE);
539
619
  /* p points to '.' */
540
620
  log_name_extension= strtoul(++p, &p_end, 10);
541
621
  /*
570
650
      configuration which does nothing), then group_master_log_pos
571
651
      will grow and group_master_log_name will stay "".
572
652
    */
573
 
    if (group_master_log_name.length())
 
653
    if (*group_master_log_name)
574
654
    {
575
 
      const char *basename= (group_master_log_name.c_str() +
576
 
                             dirname_length(group_master_log_name.c_str()));
 
655
      char *basename= (group_master_log_name +
 
656
                       dirname_length(group_master_log_name));
577
657
      /*
578
658
        First compare the parts before the extension.
579
659
        Find the dot in the master's log basename,
650
730
    pthread_mutex_lock(&data_lock);
651
731
  inc_event_relay_log_pos();
652
732
  group_relay_log_pos= event_relay_log_pos;
653
 
  group_relay_log_name.assign(event_relay_log_name);
 
733
  strmake(group_relay_log_name,event_relay_log_name,
 
734
          sizeof(group_relay_log_name)-1);
654
735
 
655
736
  notify_group_relay_log_name_update();
656
737
 
697
778
 
698
779
void Relay_log_info::close_temporary_tables()
699
780
{
700
 
  Table *table,*next;
 
781
  TABLE *table,*next;
701
782
 
702
783
  for (table=save_temporary_tables ; table ; table=next)
703
784
  {
777
858
    goto err;
778
859
  }
779
860
  /* Save name of used relay log file */
780
 
  rli->group_relay_log_name.assign(rli->relay_log.get_log_fname());
781
 
  rli->event_relay_log_name.assign(rli->relay_log.get_log_fname());
 
861
  strmake(rli->group_relay_log_name, rli->relay_log.get_log_fname(),
 
862
          sizeof(rli->group_relay_log_name)-1);
 
863
  strmake(rli->event_relay_log_name, rli->relay_log.get_log_fname(),
 
864
          sizeof(rli->event_relay_log_name)-1);
782
865
  rli->group_relay_log_pos= rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE;
783
866
  if (count_relay_log_space(rli))
784
867
  {
786
869
    goto err;
787
870
  }
788
871
  if (!just_reset)
789
 
    error= init_relay_log_pos(rli, rli->group_relay_log_name.c_str(),
 
872
    error= init_relay_log_pos(rli, rli->group_relay_log_name,
790
873
                              rli->group_relay_log_pos,
791
874
                              0 /* do not need data lock */, errmsg, 0);
792
875
 
838
921
 
839
922
  if (until_condition == UNTIL_MASTER_POS)
840
923
  {
841
 
    log_name= group_master_log_name.c_str();
 
924
    log_name= group_master_log_name;
842
925
    log_pos= master_beg_pos;
843
926
  }
844
927
  else
845
928
  { /* until_condition == UNTIL_RELAY_POS */
846
 
    log_name= group_relay_log_name.c_str();
 
929
    log_name= group_relay_log_name;
847
930
    log_pos= group_relay_log_pos;
848
931
  }
849
932
 
877
960
      else
878
961
      {
879
962
        /* Probably error so we aborting */
880
 
        sql_print_error(_("Slave SQL thread is stopped because UNTIL "
881
 
                          "condition is bad."));
 
963
        sql_print_error("Slave SQL thread is stopped because UNTIL "
 
964
                        "condition is bad.");
882
965
        return(true);
883
966
      }
884
967
    }
892
975
}
893
976
 
894
977
 
 
978
void Relay_log_info::cached_charset_invalidate()
 
979
{
 
980
  /* Full of zeroes means uninitialized. */
 
981
  bzero(cached_charset, sizeof(cached_charset));
 
982
  return;
 
983
}
 
984
 
 
985
 
 
986
bool Relay_log_info::cached_charset_compare(char *charset) const
 
987
{
 
988
  if (bcmp((uchar*) cached_charset, (uchar*) charset,
 
989
           sizeof(cached_charset)))
 
990
  {
 
991
    memcpy(const_cast<char*>(cached_charset), charset, sizeof(cached_charset));
 
992
    return(1);
 
993
  }
 
994
  return(0);
 
995
}
 
996
 
 
997
 
895
998
void Relay_log_info::stmt_done(my_off_t event_master_log_pos,
896
999
                                  time_t event_creation_time)
897
1000
{
940
1043
  }
941
1044
}
942
1045
 
 
1046
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
943
1047
void Relay_log_info::cleanup_context(THD *thd, bool error)
944
1048
{
945
1049
  assert(sql_thd == thd);
977
1081
{
978
1082
  while (tables_to_lock)
979
1083
  {
980
 
    unsigned char* to_free= reinterpret_cast<unsigned char*>(tables_to_lock);
 
1084
    uchar* to_free= reinterpret_cast<uchar*>(tables_to_lock);
981
1085
    if (tables_to_lock->m_tabledef_valid)
982
1086
    {
983
1087
      tables_to_lock->m_tabledef.table_def::~table_def();
984
1088
      tables_to_lock->m_tabledef_valid= false;
985
1089
    }
986
1090
    tables_to_lock=
987
 
      static_cast<RPL_TableList*>(tables_to_lock->next_global);
 
1091
      static_cast<RPL_TABLE_LIST*>(tables_to_lock->next_global);
988
1092
    tables_to_lock_count--;
989
 
    free(to_free);
 
1093
    my_free(to_free, MYF(MY_WME));
990
1094
  }
991
1095
  assert(tables_to_lock == NULL && tables_to_lock_count == 0);
992
1096
}
 
1097
 
 
1098
#endif