Beispiel #1
0
void
CDBShmPair::switch_shm()
{
    // 1st: reset standby. standby is readonly, no need to lock for reset
    memset(_standby->_data_addr, 0, _standby->_data_size);
    delete _standby->_ca;
    _standby->_ca = new CacheAccess();
    int ret = _standby->_ca->open((char*)_standby->_data_addr, _standby->_data_size, true,
                                  _shm_conf->_node_total, _shm_conf->_bucket_size, _shm_conf->_n_chunks, _shm_conf->_chunk_size);
    if (ret != 0) {
        // TOFIX: Fatal error, must exit!
        sql_print_error("CDB: CDBShmPair::switch_shm failed with %d", ret);
    }

    // 2nd: lock _current and _standby, wait for outstand write
    pthread_mutex_lock(_current->_lock);
    pthread_mutex_lock(_standby->_lock);

    // 3rd: switch pointers
    CDBShm* tmp = _current;
    _current = _standby;
    _standby = tmp;

    // 4th: release locks
    pthread_mutex_unlock(_standby->_lock);
    pthread_mutex_unlock(_current->_lock);
}
bool servers_reload(THD *thd)
{
  TABLE_LIST tables[1];
  bool return_val= TRUE;
  DBUG_ENTER("servers_reload");

  if (thd->locked_tables)
  {					// Can't have locked tables here
    thd->lock=thd->locked_tables;
    thd->locked_tables=0;
    close_thread_tables(thd);
  }

  DBUG_PRINT("info", ("locking servers_cache"));
  rw_wrlock(&THR_LOCK_servers);

  bzero((char*) tables, sizeof(tables));
  tables[0].alias= tables[0].table_name= (char*) "servers";
  tables[0].db= (char*) "mysql";
  tables[0].lock_type= TL_READ;

  if (simple_open_n_lock_tables(thd, tables))
  {
    /*
      Execution might have been interrupted; only print the error message
      if an error condition has been raised.
    */
    if (thd->main_da.is_error())
      sql_print_error("Can't open and lock privilege tables: %s",
                      thd->main_da.message());
    return_val= FALSE;
    goto end;
  }

  if ((return_val= servers_load(thd, tables)))
  {					// Error. Revert to old list
    /* blast, for now, we have no servers, discuss later way to preserve */

    DBUG_PRINT("error",("Reverting to old privileges"));
    servers_free();
  }

end:
  close_thread_tables(thd);
  DBUG_PRINT("info", ("unlocking servers_cache"));
  rw_unlock(&THR_LOCK_servers);
  DBUG_RETURN(return_val);
}
int init_relay_log_info(Relay_log_info* rli,
			const char* info_fname)
{
  char fname[FN_REFLEN+128];
  int info_fd;
  const char* msg = 0;
  int error = 0;
  DBUG_ENTER("init_relay_log_info");
  DBUG_ASSERT(!rli->no_storage);         // Don't init if there is no storage

  if (rli->inited)                       // Set if this function called
    DBUG_RETURN(0);
  fn_format(fname, info_fname, mysql_data_home, "", 4+32);
  pthread_mutex_lock(&rli->data_lock);
  info_fd = rli->info_fd;
  rli->cur_log_fd = -1;
  rli->slave_skip_counter=0;
  rli->abort_pos_wait=0;
  rli->log_space_limit= relay_log_space_limit;
  rli->log_space_total= 0;
  rli->tables_to_lock= 0;
  rli->tables_to_lock_count= 0;

  char pattern[FN_REFLEN];
  (void) my_realpath(pattern, slave_load_tmpdir, 0);
  if (fn_format(pattern, PREFIX_SQL_LOAD, pattern, "",
            MY_SAFE_PATH | MY_RETURN_REAL_PATH) == NullS)
  {
    pthread_mutex_unlock(&rli->data_lock);
    sql_print_error("Unable to use slave's temporary directory %s",
                    slave_load_tmpdir);
    DBUG_RETURN(1);
  }
  unpack_filename(rli->slave_patternload_file, pattern);
  rli->slave_patternload_file_size= strlen(rli->slave_patternload_file);

  /*
    The relay log will now be opened, as a SEQ_READ_APPEND IO_CACHE.
    Note that the I/O thread flushes it to disk after writing every
    event, in flush_master_info(mi, 1, ?).
  */

  /*
    For the maximum log size, we choose max_relay_log_size if it is
    non-zero, max_binlog_size otherwise. If later the user does SET
    GLOBAL on one of these variables, fix_max_binlog_size and
    fix_max_relay_log_size will reconsider the choice (for example
    if the user changes max_relay_log_size to zero, we have to
    switch to using max_binlog_size for the relay log) and update
    rli->relay_log.max_size (and mysql_bin_log.max_size).
  */
  {
    /* Reports an error and returns, if the --relay-log's path 
       is a directory.*/
    if (opt_relay_logname && 
        opt_relay_logname[strlen(opt_relay_logname) - 1] == FN_LIBCHAR)
    {
      pthread_mutex_unlock(&rli->data_lock);
      sql_print_error("Path '%s' is a directory name, please specify \
a file name for --relay-log option", opt_relay_logname);
      DBUG_RETURN(1);
    }

    /* Reports an error and returns, if the --relay-log-index's path 
       is a directory.*/
    if (opt_relaylog_index_name && 
        opt_relaylog_index_name[strlen(opt_relaylog_index_name) - 1] 
        == FN_LIBCHAR)
    {
      pthread_mutex_unlock(&rli->data_lock);
      sql_print_error("Path '%s' is a directory name, please specify \
a file name for --relay-log-index option", opt_relaylog_index_name);
      DBUG_RETURN(1);
    }