Commit d50af8ae authored by unknown's avatar unknown
Browse files

Review of new pushed code (XA & other)

Portability fixes and cleanups
Fixed setting of 'res' in mysql_execute_command()


sql/handler.cc:
  delete_table() will not return error for not found files if one handler file was found and deleted
sql/handler.h:
  Incremented MAX_HA so that ndb works again
  Don't convert char pointer to (my_xid*) as we don't know if the address is aligned on 8
sql/log.cc:
  Indentation fixes
  Simplified loop to find next log
  Fixed race condition in reset_logs that caused mix_innodb_myisam_binlog to fail
sql/log_event.cc:
  Don't convert char pointer to (my_xid*) as we don't know if the address is aligned on 8
sql/sql_acl.cc:
  Convert db name directly to avoid extra strmov
sql/sql_base.cc:
  Added comment
  Removed not needed code
sql/sql_db.cc:
  Added comment
  Remove not needed code
sql/sql_parse.cc:
  Always call mysql_rm_db() with lower case db name
  Ensure that 'res' is set correctly in mysql_execute_command()
  (One don't have to set res if one calls my_error() and res should be = 0 for correct commands)
sql/sql_repl.cc:
  Indentation fixes
  use packet->ptr() instead of packet->c_ptr()
sql/sql_table.cc:
  Join similar code when table didn't exist in engine
parent da4604f9
Loading
Loading
Loading
Loading
+24 −2
Original line number Diff line number Diff line
@@ -1494,16 +1494,38 @@ uint handler::get_dup_key(int error)
}


/*
  Delete all files with extension from bas_ext()

  SYNOPSIS
    delete_table()
    name		Base name of table

  NOTES
    We assume that the handler may return more extensions than
    was actually used for the file.

  RETURN
    0   If we successfully deleted at least one file from base_ext and
	didn't get any other errors than ENOENT    
    #   Error from delete_file()
*/

int handler::delete_table(const char *name)
{
  int error= 0;
  int enoent_or_zero= ENOENT;                   // Error if no file was deleted

  for (const char **ext=bas_ext(); *ext ; ext++)
  {
    if (delete_file(name,*ext,2))
    {
      if ((error=errno) != ENOENT)
      if ((error= my_errno) != ENOENT)
	break;
    }
    else
      enoent_or_zero= 0;
    error= enoent_or_zero;
  }
  return error;
}
+9 −5
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@
  Note: the following includes binlog and closing 0.
  so: innodb+bdb+ndb+binlog+0
*/
#define MAX_HA 5
#define MAX_HA 6

/*
  Bits in index_ddl_flags(KEY *wanted_index)
@@ -217,11 +217,13 @@ struct xid_t {
  bool eq(long g, long b, const char *d)
  { return g == gtrid_length && b == bqual_length && !memcmp(d, data, g+b); }
  void set(LEX_STRING *l) { set(l->length, 0, l->str); }
  void set(ulonglong l)
  void set(ulonglong xid)
  {
    my_xid tmp;
    set(MYSQL_XID_PREFIX_LEN, 0, MYSQL_XID_PREFIX);
    *(ulong*)(data+MYSQL_XID_PREFIX_LEN)=server_id;
    *(my_xid*)(data+MYSQL_XID_OFFSET)=l;
    memcpy(data+MYSQL_XID_PREFIX_LEN, &server_id, sizeof(server_id));
    tmp= xid;
    memcpy(data+MYSQL_XID_OFFSET, &tmp, sizeof(tmp));
    gtrid_length=MYSQL_XID_GTRID_LEN;
  }
  void set(long g, long b, const char *d)
@@ -235,7 +237,9 @@ struct xid_t {
  void null() { formatID= -1; }
  my_xid quick_get_my_xid()
  {
    return *(my_xid*)(data+MYSQL_XID_OFFSET);
    my_xid tmp;
    memcpy(&tmp, data+MYSQL_XID_OFFSET, sizeof(tmp));
    return tmp;
  }
  my_xid get_my_xid()
  {
+41 −31
Original line number Diff line number Diff line
@@ -919,6 +919,13 @@ bool MYSQL_LOG::reset_logs(THD* thd)
  */
  pthread_mutex_lock(&LOCK_log);
  pthread_mutex_lock(&LOCK_index);
  /*
    The following mutex is needed to ensure that no threads call
    'delete thd' as we would then risk missing a 'rollback' from this
    thread. If the transaction involved MyISAM tables, it should go
    into binlog even on rollback.
  */
  (void) pthread_mutex_lock(&LOCK_thread_count);

  /* Save variables so that we can reopen the log */
  save_name=name;
@@ -952,6 +959,7 @@ bool MYSQL_LOG::reset_logs(THD* thd)
  my_free((gptr) save_name, MYF(0));

err:
  (void) pthread_mutex_unlock(&LOCK_thread_count);
  pthread_mutex_unlock(&LOCK_index);
  pthread_mutex_unlock(&LOCK_log);
  DBUG_RETURN(error);
@@ -1600,7 +1608,8 @@ bool MYSQL_LOG::write(Log_event* event_info)
        {
          thd->ha_data[binlog_hton.slot]= trans_log= (IO_CACHE *)
            my_malloc(sizeof(IO_CACHE), MYF(MY_ZEROFILL));
          if (!trans_log || open_cached_file(trans_log, mysql_tmpdir, LOG_PREFIX,
          if (!trans_log || open_cached_file(trans_log, mysql_tmpdir,
                                             LOG_PREFIX,
                                             binlog_cache_size, MYF(MY_WME)))
          {
            my_free((gptr)trans_log, MYF(MY_ALLOW_ZERO_PTR));
@@ -1609,12 +1618,14 @@ bool MYSQL_LOG::write(Log_event* event_info)
          }
          trans_log->end_of_file= max_binlog_cache_size;
          trans_register_ha(thd,
              thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN),
                            thd->options & (OPTION_NOT_AUTOCOMMIT |
                                            OPTION_BEGIN),
                            &binlog_hton);
        }
        else if (!my_b_tell(trans_log))
          trans_register_ha(thd,
              thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN),
                            thd->options & (OPTION_NOT_AUTOCOMMIT |
                                            OPTION_BEGIN),
                            &binlog_hton);
        file= trans_log;
      }
@@ -1803,9 +1814,9 @@ uint MYSQL_LOG::next_file_id()
  IMPLEMENTATION
    - To support transaction over replication, we wrap the transaction
      with BEGIN/COMMIT or BEGIN/ROLLBACK in the binary log.
      We want to write a BEGIN/ROLLBACK block when a non-transactional table was
      updated in a transaction which was rolled back. This is to ensure that the
      same updates are run on the slave.
      We want to write a BEGIN/ROLLBACK block when a non-transactional table
      was updated in a transaction which was rolled back. This is to ensure
      that the same updates are run on the slave.
*/

bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache)
@@ -2481,15 +2492,13 @@ int TC_LOG_MMAP::open(const char *opt_name)
#endif

  fn_format(logname,opt_name,mysql_data_home,"",MY_UNPACK_FILENAME);
  fd= my_open(logname, O_RDWR, MYF(0));
  if (fd == -1)
  if ((fd= my_open(logname, O_RDWR, MYF(0))) < 0)
  {
    if (my_errno != ENOENT)
      goto err;
    if (using_heuristic_recover())
      return 1;
    fd= my_create(logname, O_RDWR, 0, MYF(MY_WME));
    if (fd == -1)
    if ((fd= my_create(logname, O_RDWR, 0, MYF(MY_WME))) < 0)
      goto err;
    inited=1;
    file_length= opt_tc_log_size;
@@ -2827,7 +2836,7 @@ int TC_LOG_MMAP::recover()
  */
  if (data[sizeof(tc_log_magic)] != total_ha_2pc)
  {
    sql_print_error("Recovery failed! You must have enabled "
    sql_print_error("Recovery failed! You must enable "
                    "exactly %d storage engines that support "
                    "two-phase commit protocol",
                    data[sizeof(tc_log_magic)]);
@@ -2931,15 +2940,16 @@ int TC_LOG_BINLOG::open(const char *opt_name)
    if (! fdle.is_valid())
      goto err;

    for (error= 0; !error ;)
    do
    {
      strnmov(log_name, log_info.log_file_name, sizeof(log_name));
      if ((error= find_next_log(&log_info, 1)) != LOG_INFO_EOF)
      strmake(log_name, log_info.log_file_name, sizeof(log_name)-1);
    } while (!(error= find_next_log(&log_info, 1)));

    if (error !=  LOG_INFO_EOF)
    {
      sql_print_error("find_log_pos() failed (error: %d)", error);
      goto err;
    }
    }

    if ((file= open_binlog(&log, log_name, &errmsg)) < 0)
    {
+5 −3
Original line number Diff line number Diff line
@@ -3099,12 +3099,14 @@ void Xid_log_event::pack_info(Protocol *protocol)
  we don't care about actual values of xids as long as
  identical numbers compare identically
*/
Xid_log_event::Xid_log_event(const char* buf,

Xid_log_event::
Xid_log_event(const char* buf,
              const Format_description_log_event *description_event)
  :Log_event(buf, description_event)
{
  buf+= description_event->common_header_len;
  xid=*((my_xid *)buf);
  memcpy((char*) &xid, buf, sizeof(xid));
}


+7 −13
Original line number Diff line number Diff line
@@ -204,20 +204,16 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables)
    if (lower_case_table_names)
    {
      /*
       We make a temporary copy of the database, force it to lower case,
       and then copy it back over the original name. We can't just update
       the host.db pointer, because tmp_name is allocated on the stack.
        convert db to lower case and give a warning if the db wasn't
        already in lower case
      */
      (void) strmov(tmp_name, host.db);
      my_casedn_str(files_charset_info, tmp_name);
      my_casedn_str(files_charset_info, host.db);
      if (strcmp(host.db, tmp_name) != 0)
      {
        sql_print_warning("'host' entry '%s|%s' had database in mixed "
                          "case that has been forced to lowercase because "
                          "lower_case_table_names is set.",
                          host.host.hostname, host.db);
        (void)strmov(host.db, tmp_name);
      }
    }
    host.access= get_access(table,2);
    host.access= fix_rights_for_db(host.access);
@@ -432,19 +428,17 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables)
    if (lower_case_table_names)
    {
      /*
       We make a temporary copy of the database, force it to lower case,
       and then copy it back over the original name. We can't just update
       the db.db pointer, because tmp_name is allocated on the stack.
        convert db to lower case and give a warning if the db wasn't
        already in lower case
      */
      (void)strmov(tmp_name, db.db);
      my_casedn_str(files_charset_info, tmp_name);
      my_casedn_str(files_charset_info, db.db);
      if (strcmp(db.db, tmp_name) != 0)
      {
        sql_print_warning("'db' entry '%s %s@%s' had database in mixed "
                          "case that has been forced to lowercase because "
                          "lower_case_table_names is set.",
		          db.db, db.user, db.host.hostname, db.host.hostname);
        (void)strmov(db.db, tmp_name);
      }
    }
    db.sort=get_sort(3,db.host.hostname,db.db,db.user);
Loading