~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/rpl_rli.cc

Removed some type checks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
#include <drizzled/server_includes.h>
17
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
 
 
29
 
 
30
18
#include "rpl_mi.h"
31
19
#include "rpl_rli.h"
32
20
#include "sql_repl.h"  // For check_binlog_magic
63
51
  until_log_name[0]= ign_master_log_name_end[0]= 0;
64
52
  memset(&info_file, 0, sizeof(info_file));
65
53
  memset(&cache_buf, 0, sizeof(cache_buf));
 
54
  cached_charset_invalidate();
66
55
  pthread_mutex_init(&run_lock, MY_MUTEX_INIT_FAST);
67
56
  pthread_mutex_init(&data_lock, MY_MUTEX_INIT_FAST);
68
57
  pthread_mutex_init(&log_space_lock, MY_MUTEX_INIT_FAST);
168
157
  /* if file does not exist */
169
158
  if (access(fname,F_OK))
170
159
  {
171
 
    /* Create a new file */
 
160
    /*
 
161
      If someone removed the file from underneath our feet, just close
 
162
      the old descriptor and re-create the old file
 
163
    */
 
164
    if (info_fd >= 0)
 
165
      my_close(info_fd, MYF(MY_WME));
 
166
    if ((info_fd = my_open(fname, O_CREAT|O_RDWR|O_BINARY, MYF(MY_WME))) < 0)
 
167
    {
 
168
      sql_print_error(_("Failed to create a new relay log info file "
 
169
                        "( file '%s', errno %d)"), fname, my_errno);
 
170
      msg= current_thd->main_da.message();
 
171
      goto err;
 
172
    }
 
173
    if (init_io_cache(&rli->info_file, info_fd, IO_SIZE*2, READ_CACHE, 0L,0,
 
174
                      MYF(MY_WME)))
 
175
    {
 
176
      sql_print_error(_("Failed to create a cache on relay log info file '%s'"),
 
177
                      fname);
 
178
      msg= current_thd->main_da.message();
 
179
      goto err;
 
180
    }
 
181
 
 
182
    /* Init relay log with first entry in the relay index file */
 
183
    if (init_relay_log_pos(rli,NULL,BIN_LOG_HEADER_SIZE,0 /* no data lock */,
 
184
                           &msg, 0))
 
185
    {
 
186
      sql_print_error(_("Failed to open the relay log 'FIRST' (relay_log_pos 4)"));
 
187
      goto err;
 
188
    }
 
189
    rli->group_master_log_name[0]= 0;
 
190
    rli->group_master_log_pos= 0;
 
191
    rli->info_fd= info_fd;
172
192
  }
173
193
  else // file exists
174
194
  {
175
 
    /* Open up fname here and pull out the relay.info data */
 
195
    if (info_fd >= 0)
 
196
      reinit_io_cache(&rli->info_file, READ_CACHE, 0L,0,0);
 
197
    else
 
198
    {
 
199
      int32_t error=0;
 
200
      if ((info_fd = my_open(fname, O_RDWR|O_BINARY, MYF(MY_WME))) < 0)
 
201
      {
 
202
        sql_print_error(_("Failed to open the existing relay log info "
 
203
                          "file '%s' (errno %d)"),
 
204
                        fname, my_errno);
 
205
        error= 1;
 
206
      }
 
207
      else if (init_io_cache(&rli->info_file, info_fd,
 
208
                             IO_SIZE*2, READ_CACHE, 0L, 0, MYF(MY_WME)))
 
209
      {
 
210
        sql_print_error(_("Failed to create a cache on relay log info "
 
211
                          "file '%s'"),
 
212
                        fname);
 
213
        error= 1;
 
214
      }
 
215
      if (error)
 
216
      {
 
217
        if (info_fd >= 0)
 
218
          my_close(info_fd, MYF(0));
 
219
        rli->info_fd= -1;
 
220
        rli->relay_log.close(LOG_CLOSE_INDEX | LOG_CLOSE_STOP_EVENT);
 
221
        pthread_mutex_unlock(&rli->data_lock);
 
222
        return(1);
 
223
      }
 
224
    }
 
225
 
 
226
    rli->info_fd = info_fd;
 
227
    int32_t relay_log_pos, master_log_pos;
 
228
    if (init_strvar_from_file(rli->group_relay_log_name,
 
229
                              sizeof(rli->group_relay_log_name),
 
230
                              &rli->info_file, "") ||
 
231
       init_intvar_from_file(&relay_log_pos,
 
232
                             &rli->info_file, BIN_LOG_HEADER_SIZE) ||
 
233
       init_strvar_from_file(rli->group_master_log_name,
 
234
                             sizeof(rli->group_master_log_name),
 
235
                             &rli->info_file, "") ||
 
236
       init_intvar_from_file(&master_log_pos, &rli->info_file, 0))
 
237
    {
 
238
      msg="Error reading slave log configuration";
 
239
      goto err;
 
240
    }
 
241
    strmake(rli->event_relay_log_name,rli->group_relay_log_name,
 
242
            sizeof(rli->event_relay_log_name)-1);
 
243
    rli->group_relay_log_pos= rli->event_relay_log_pos= relay_log_pos;
 
244
    rli->group_master_log_pos= master_log_pos;
 
245
 
 
246
    if (init_relay_log_pos(rli,
 
247
                           rli->group_relay_log_name,
 
248
                           rli->group_relay_log_pos,
 
249
                           0 /* no data lock*/,
 
250
                           &msg, 0))
 
251
    {
 
252
      char llbuf[22];
 
253
      sql_print_error(_("Failed to open the relay log '%s' (relay_log_pos %s)"),
 
254
                      rli->group_relay_log_name,
 
255
                      llstr(rli->group_relay_log_pos, llbuf));
 
256
      goto err;
 
257
    }
176
258
  }
 
259
  assert(rli->event_relay_log_pos >= BIN_LOG_HEADER_SIZE);
 
260
  assert(my_b_tell(rli->cur_log) == rli->event_relay_log_pos);
177
261
 
178
262
  /*
179
263
    Now change the cache from READ to WRITE - must do this
347
431
    *errmsg="Could not find target log during relay log initialization";
348
432
    goto err;
349
433
  }
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
 
 
 
434
  strmake(rli->group_relay_log_name,rli->linfo.log_file_name,
 
435
          sizeof(rli->group_relay_log_name)-1);
 
436
  strmake(rli->event_relay_log_name,rli->linfo.log_file_name,
 
437
          sizeof(rli->event_relay_log_name)-1);
354
438
  if (rli->relay_log.is_active(rli->linfo.log_file_name))
355
439
  {
356
440
    /*
570
654
      configuration which does nothing), then group_master_log_pos
571
655
      will grow and group_master_log_name will stay "".
572
656
    */
573
 
    if (group_master_log_name.length())
 
657
    if (*group_master_log_name)
574
658
    {
575
 
      const char *basename= (group_master_log_name.c_str() +
576
 
                             dirname_length(group_master_log_name.c_str()));
 
659
      char *basename= (group_master_log_name +
 
660
                       dirname_length(group_master_log_name));
577
661
      /*
578
662
        First compare the parts before the extension.
579
663
        Find the dot in the master's log basename,
650
734
    pthread_mutex_lock(&data_lock);
651
735
  inc_event_relay_log_pos();
652
736
  group_relay_log_pos= event_relay_log_pos;
653
 
  group_relay_log_name.assign(event_relay_log_name);
 
737
  strmake(group_relay_log_name,event_relay_log_name,
 
738
          sizeof(group_relay_log_name)-1);
654
739
 
655
740
  notify_group_relay_log_name_update();
656
741
 
777
862
    goto err;
778
863
  }
779
864
  /* 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());
 
865
  strmake(rli->group_relay_log_name, rli->relay_log.get_log_fname(),
 
866
          sizeof(rli->group_relay_log_name)-1);
 
867
  strmake(rli->event_relay_log_name, rli->relay_log.get_log_fname(),
 
868
          sizeof(rli->event_relay_log_name)-1);
782
869
  rli->group_relay_log_pos= rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE;
783
870
  if (count_relay_log_space(rli))
784
871
  {
786
873
    goto err;
787
874
  }
788
875
  if (!just_reset)
789
 
    error= init_relay_log_pos(rli, rli->group_relay_log_name.c_str(),
 
876
    error= init_relay_log_pos(rli, rli->group_relay_log_name,
790
877
                              rli->group_relay_log_pos,
791
878
                              0 /* do not need data lock */, errmsg, 0);
792
879
 
838
925
 
839
926
  if (until_condition == UNTIL_MASTER_POS)
840
927
  {
841
 
    log_name= group_master_log_name.c_str();
 
928
    log_name= group_master_log_name;
842
929
    log_pos= master_beg_pos;
843
930
  }
844
931
  else
845
932
  { /* until_condition == UNTIL_RELAY_POS */
846
 
    log_name= group_relay_log_name.c_str();
 
933
    log_name= group_relay_log_name;
847
934
    log_pos= group_relay_log_pos;
848
935
  }
849
936
 
892
979
}
893
980
 
894
981
 
 
982
void Relay_log_info::cached_charset_invalidate()
 
983
{
 
984
  /* Full of zeroes means uninitialized. */
 
985
  memset(cached_charset, 0, sizeof(cached_charset));
 
986
  return;
 
987
}
 
988
 
 
989
 
 
990
bool Relay_log_info::cached_charset_compare(char *charset) const
 
991
{
 
992
  if (memcmp(cached_charset, charset, sizeof(cached_charset)))
 
993
  {
 
994
    memcpy(const_cast<char*>(cached_charset), charset, sizeof(cached_charset));
 
995
    return(1);
 
996
  }
 
997
  return(0);
 
998
}
 
999
 
 
1000
 
895
1001
void Relay_log_info::stmt_done(my_off_t event_master_log_pos,
896
1002
                                  time_t event_creation_time)
897
1003
{