~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/rpl_rli.cc

  • Committer: Brian Aker
  • Date: 2008-10-08 02:16:25 UTC
  • Revision ID: brian@tangent.org-20081008021625-3756823nqs1phvsn
More effort around master.info (and relay.info)

Show diffs side-by-side

added added

removed removed

Lines of Context:
168
168
  /* if file does not exist */
169
169
  if (access(fname,F_OK))
170
170
  {
171
 
    /*
172
 
      If someone removed the file from underneath our feet, just close
173
 
      the old descriptor and re-create the old file
174
 
    */
175
 
    if (info_fd >= 0)
176
 
      my_close(info_fd, MYF(MY_WME));
177
 
    if ((info_fd = my_open(fname, O_CREAT|O_RDWR|O_BINARY, MYF(MY_WME))) < 0)
178
 
    {
179
 
      sql_print_error(_("Failed to create a new relay log info file "
180
 
                        "( file '%s', errno %d)"), fname, my_errno);
181
 
      msg= current_thd->main_da.message();
182
 
      goto err;
183
 
    }
184
 
    if (init_io_cache(&rli->info_file, info_fd, IO_SIZE*2, READ_CACHE, 0L,0,
185
 
                      MYF(MY_WME)))
186
 
    {
187
 
      sql_print_error(_("Failed to create a cache on relay log info file '%s'"),
188
 
                      fname);
189
 
      msg= current_thd->main_da.message();
190
 
      goto err;
191
 
    }
192
 
 
193
 
    /* Init relay log with first entry in the relay index file */
194
 
    if (init_relay_log_pos(rli,NULL,BIN_LOG_HEADER_SIZE,0 /* no data lock */,
195
 
                           &msg, 0))
196
 
    {
197
 
      sql_print_error(_("Failed to open the relay log 'FIRST' (relay_log_pos 4)"));
198
 
      goto err;
199
 
    }
200
 
    rli->group_master_log_name[0]= 0;
201
 
    rli->group_master_log_pos= 0;
202
 
    rli->info_fd= info_fd;
 
171
    /* Create a new file */
203
172
  }
204
173
  else // file exists
205
174
  {
206
 
    if (info_fd >= 0)
207
 
      reinit_io_cache(&rli->info_file, READ_CACHE, 0L,0,0);
208
 
    else
209
 
    {
210
 
      int32_t error=0;
211
 
      if ((info_fd = my_open(fname, O_RDWR|O_BINARY, MYF(MY_WME))) < 0)
212
 
      {
213
 
        sql_print_error(_("Failed to open the existing relay log info "
214
 
                          "file '%s' (errno %d)"),
215
 
                        fname, my_errno);
216
 
        error= 1;
217
 
      }
218
 
      else if (init_io_cache(&rli->info_file, info_fd,
219
 
                             IO_SIZE*2, READ_CACHE, 0L, 0, MYF(MY_WME)))
220
 
      {
221
 
        sql_print_error(_("Failed to create a cache on relay log info "
222
 
                          "file '%s'"),
223
 
                        fname);
224
 
        error= 1;
225
 
      }
226
 
      if (error)
227
 
      {
228
 
        if (info_fd >= 0)
229
 
          my_close(info_fd, MYF(0));
230
 
        rli->info_fd= -1;
231
 
        rli->relay_log.close(LOG_CLOSE_INDEX | LOG_CLOSE_STOP_EVENT);
232
 
        pthread_mutex_unlock(&rli->data_lock);
233
 
        return(1);
234
 
      }
235
 
    }
236
 
 
237
 
    rli->info_fd = info_fd;
238
 
    int32_t relay_log_pos, master_log_pos;
239
 
    if (init_strvar_from_file(rli->group_relay_log_name,
240
 
                              sizeof(rli->group_relay_log_name),
241
 
                              &rli->info_file, "") ||
242
 
       init_intvar_from_file(&relay_log_pos,
243
 
                             &rli->info_file, BIN_LOG_HEADER_SIZE) ||
244
 
       init_strvar_from_file(rli->group_master_log_name,
245
 
                             sizeof(rli->group_master_log_name),
246
 
                             &rli->info_file, "") ||
247
 
       init_intvar_from_file(&master_log_pos, &rli->info_file, 0))
248
 
    {
249
 
      msg="Error reading slave log configuration";
250
 
      goto err;
251
 
    }
252
 
    strmake(rli->event_relay_log_name,rli->group_relay_log_name,
253
 
            sizeof(rli->event_relay_log_name)-1);
254
 
    rli->group_relay_log_pos= rli->event_relay_log_pos= relay_log_pos;
255
 
    rli->group_master_log_pos= master_log_pos;
256
 
 
257
 
    if (init_relay_log_pos(rli,
258
 
                           rli->group_relay_log_name,
259
 
                           rli->group_relay_log_pos,
260
 
                           0 /* no data lock*/,
261
 
                           &msg, 0))
262
 
    {
263
 
      char llbuf[22];
264
 
      sql_print_error(_("Failed to open the relay log '%s' (relay_log_pos %s)"),
265
 
                      rli->group_relay_log_name,
266
 
                      llstr(rli->group_relay_log_pos, llbuf));
267
 
      goto err;
268
 
    }
 
175
    /* Open up fname here and pull out the relay.info data */
269
176
  }
270
 
  assert(rli->event_relay_log_pos >= BIN_LOG_HEADER_SIZE);
271
 
  assert(my_b_tell(rli->cur_log) == rli->event_relay_log_pos);
272
177
 
273
178
  /*
274
179
    Now change the cache from READ to WRITE - must do this
442
347
    *errmsg="Could not find target log during relay log initialization";
443
348
    goto err;
444
349
  }
445
 
  strmake(rli->group_relay_log_name,rli->linfo.log_file_name,
446
 
          sizeof(rli->group_relay_log_name)-1);
447
 
  strmake(rli->event_relay_log_name,rli->linfo.log_file_name,
448
 
          sizeof(rli->event_relay_log_name)-1);
 
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
 
449
354
  if (rli->relay_log.is_active(rli->linfo.log_file_name))
450
355
  {
451
356
    /*
665
570
      configuration which does nothing), then group_master_log_pos
666
571
      will grow and group_master_log_name will stay "".
667
572
    */
668
 
    if (*group_master_log_name)
 
573
    if (group_master_log_name.length())
669
574
    {
670
 
      char *basename= (group_master_log_name +
671
 
                       dirname_length(group_master_log_name));
 
575
      const char *basename= (group_master_log_name.c_str() +
 
576
                             dirname_length(group_master_log_name.c_str()));
672
577
      /*
673
578
        First compare the parts before the extension.
674
579
        Find the dot in the master's log basename,
745
650
    pthread_mutex_lock(&data_lock);
746
651
  inc_event_relay_log_pos();
747
652
  group_relay_log_pos= event_relay_log_pos;
748
 
  strmake(group_relay_log_name,event_relay_log_name,
749
 
          sizeof(group_relay_log_name)-1);
 
653
  group_relay_log_name.assign(event_relay_log_name);
750
654
 
751
655
  notify_group_relay_log_name_update();
752
656
 
873
777
    goto err;
874
778
  }
875
779
  /* Save name of used relay log file */
876
 
  strmake(rli->group_relay_log_name, rli->relay_log.get_log_fname(),
877
 
          sizeof(rli->group_relay_log_name)-1);
878
 
  strmake(rli->event_relay_log_name, rli->relay_log.get_log_fname(),
879
 
          sizeof(rli->event_relay_log_name)-1);
 
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());
880
782
  rli->group_relay_log_pos= rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE;
881
783
  if (count_relay_log_space(rli))
882
784
  {
884
786
    goto err;
885
787
  }
886
788
  if (!just_reset)
887
 
    error= init_relay_log_pos(rli, rli->group_relay_log_name,
 
789
    error= init_relay_log_pos(rli, rli->group_relay_log_name.c_str(),
888
790
                              rli->group_relay_log_pos,
889
791
                              0 /* do not need data lock */, errmsg, 0);
890
792
 
936
838
 
937
839
  if (until_condition == UNTIL_MASTER_POS)
938
840
  {
939
 
    log_name= group_master_log_name;
 
841
    log_name= group_master_log_name.c_str();
940
842
    log_pos= master_beg_pos;
941
843
  }
942
844
  else
943
845
  { /* until_condition == UNTIL_RELAY_POS */
944
 
    log_name= group_relay_log_name;
 
846
    log_name= group_relay_log_name.c_str();
945
847
    log_pos= group_relay_log_pos;
946
848
  }
947
849