List:Internals« Previous MessageNext Message »
From:jonas.oreland Date:April 13 2005 8:11am
Subject:bk commit into 5.1-ndb tree (joreland:1.1842)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1-ndb repository of jonas. When jonas does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1842 05/04/13 10:10:58 joreland@stripped +30 -0
  merge

  sql/ha_ndbcluster.cc
    1.133 05/04/13 10:10:54 joreland@stripped +0 -0
    merge

  ndb/src/kernel/blocks/dbtup/DbtupRoutines.cpp
    1.35 05/04/13 10:10:54 joreland@stripped +2 -1
    merge

  mysql-test/r/ndb_alter_table.result
    1.27 05/04/13 10:10:54 joreland@stripped +1 -2
    merge

  mysql-test/Makefile.am
    1.49 05/04/13 10:10:54 joreland@stripped +0 -1
    merge

  configure.in
    1.257 05/04/13 10:10:54 joreland@stripped +0 -3
    merge

  sql/share/errmsg.txt
    1.25 05/04/13 10:03:26 joreland@stripped +0 -0
    Auto merged

  sql/sql_yacc.yy
    1.362 05/04/13 10:03:25 joreland@stripped +0 -0
    Auto merged

  sql/sql_table.cc
    1.221 05/04/13 10:03:25 joreland@stripped +0 -0
    Auto merged

  sql/sql_parse.cc
    1.419 05/04/13 10:03:25 joreland@stripped +0 -0
    Auto merged

  sql/sql_lex.h
    1.175 05/04/13 10:03:24 joreland@stripped +0 -0
    Auto merged

  sql/sql_class.h
    1.227 05/04/13 10:03:24 joreland@stripped +0 -0
    Auto merged

  sql/sql_class.cc
    1.173 05/04/13 10:03:24 joreland@stripped +0 -0
    Auto merged

  sql/mysql_priv.h
    1.289 05/04/13 10:03:24 joreland@stripped +0 -0
    Auto merged

  sql/log.cc
    1.154 05/04/13 10:03:24 joreland@stripped +0 -0
    Auto merged

  sql/item.cc
    1.110 05/04/13 10:03:24 joreland@stripped +0 -0
    Auto merged

  sql/handler.h
    1.137 05/04/13 10:03:24 joreland@stripped +0 -0
    Auto merged

  sql/handler.cc
    1.143 05/04/13 10:03:23 joreland@stripped +0 -0
    Auto merged

  ndb/src/ndbapi/NdbTransaction.cpp
    1.43 05/04/13 10:03:23 joreland@stripped +0 -0
    Auto merged

  ndb/src/ndbapi/NdbScanOperation.cpp
    1.55 05/04/13 10:03:23 joreland@stripped +0 -0
    Auto merged

  ndb/src/ndbapi/NdbOperationSearch.cpp
    1.21 05/04/13 10:03:23 joreland@stripped +0 -0
    Auto merged

  ndb/src/ndbapi/NdbOperationDefine.cpp
    1.21 05/04/13 10:03:23 joreland@stripped +0 -0
    Auto merged

  ndb/src/ndbapi/NdbIndexOperation.cpp
    1.20 05/04/13 10:03:23 joreland@stripped +0 -0
    Auto merged

  ndb/src/ndbapi/NdbDictionaryImpl.cpp
    1.75 05/04/13 10:03:23 joreland@stripped +0 -0
    Auto merged

  ndb/src/ndbapi/Ndb.cpp
    1.39 05/04/13 10:03:23 joreland@stripped +0 -0
    Auto merged

  ndb/src/kernel/blocks/dbacc/DbaccMain.cpp
    1.49 05/04/13 10:03:23 joreland@stripped +0 -0
    Auto merged

  ndb/include/ndbapi/NdbTransaction.hpp
    1.36 05/04/13 10:03:22 joreland@stripped +0 -0
    Auto merged

  mysql-test/t/ndb_alter_table.test
    1.20 05/04/13 10:03:22 joreland@stripped +0 -0
    Auto merged

  BitKeeper/triggers/post-commit
    1.37 05/04/13 10:03:22 joreland@stripped +0 -0
    Auto merged

  BitKeeper/etc/logging_ok
    1.292 05/04/13 10:03:04 joreland@stripped +0 -0
    auto-union

  BitKeeper/etc/ignore
    1.200 05/04/13 10:03:04 joreland@stripped +17 -17
    auto-union

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	joreland
# Host:	eel.ndb.mysql.com.ndb.mysql.com.ndb.mysql.com.ndb.mysql.com
# Root:	/home/jonas/src/mysql-5.1-ndb-dd/RESYNC

--- 1.256/configure.in	Mon Apr 11 14:37:56 2005
+++ 1.257/configure.in	Wed Apr 13 10:10:54 2005
@@ -5,8 +5,6 @@
 
 AC_INIT(sql/mysqld.cc)
 AC_CANONICAL_SYSTEM
-# The Docs Makefile.am parses this line!
-# remember to also change ndb version below and update version.c in ndb
 AM_INIT_AUTOMAKE(mysql, 5.1.0-ndb-devel)
 AM_CONFIG_HEADER(config.h)
 
@@ -42,7 +40,6 @@
 sinclude(config/ac-macros/ha_example.m4)
 sinclude(config/ac-macros/ha_federated.m4)
 sinclude(config/ac-macros/ha_innodb.m4)
-sinclude(config/ac-macros/ha_isam.m4)
 sinclude(config/ac-macros/ha_ndbcluster.m4)
 sinclude(config/ac-macros/ha_tina.m4)
 sinclude(config/ac-macros/large_file.m4)
@@ -353,6 +350,15 @@
   if echo $CXX | grep gcc > /dev/null 2>&1
   then
     GCC_VERSION=`gcc -v 2>&1 | grep version | sed -e 's/[[^0-9. ]]//g; s/^ *//g; s/ .*//g'`
+    case $SYSTEM_TYPE in
+      *freebsd*)
+        # The libsupc++ library on freebsd with gcc 3.4.2 is dependent on 
+        # libstdc++, disable it  since other solution works fine
+        GCC_VERSION="NOSUPCPP_$GCC_VERSION"
+      ;;
+      *) 
+      ;;
+    esac
     echo "Using gcc version '$GCC_VERSION'"
     case "$GCC_VERSION" in
       3.4.*|3.5.*)

--- 1.142/sql/handler.cc	Mon Apr 11 14:37:59 2005
+++ 1.143/sql/handler.cc	Wed Apr 13 10:03:23 2005
@@ -25,10 +25,6 @@
 #include "ha_heap.h"
 #include "ha_myisam.h"
 #include "ha_myisammrg.h"
-#ifdef HAVE_ISAM
-#include "ha_isam.h"
-#include "ha_isammrg.h"
-#endif
 #ifdef HAVE_BERKELEY_DB
 #include "ha_berkeley.h"
 #endif
@@ -308,6 +304,7 @@
   SETMSG(HA_ERR_NO_SUCH_TABLE,          "No such table: '%.64s'");
   SETMSG(HA_ERR_TABLE_EXIST,            ER(ER_TABLE_EXISTS_ERROR));
   SETMSG(HA_ERR_NO_CONNECTION,          "Could not connect to storage engine");
+  SETMSG(HA_ERR_TABLE_DEF_CHANGED,      ER(ER_TABLE_DEF_CHANGED));
 
   /* Register the error messages for use with my_error(). */
   return my_error_register(errmsgs, HA_ERR_FIRST, HA_ERR_LAST);
@@ -509,10 +506,16 @@
     "beginning of transaction" and "beginning of statement").
     Only storage engines registered for the transaction/statement
     will know when to commit/rollback it.
+
+  NOTE
+    trans_register_ha is idempotent - storage engine may register many
+    times per transaction.
+
 */
 void trans_register_ha(THD *thd, bool all, handlerton *ht_arg)
 {
   THD_TRANS *trans;
+  handlerton **ht;
   DBUG_ENTER("trans_register_ha");
   DBUG_PRINT("enter",("%s", all ? "all" : "stmt"));
 
@@ -524,15 +527,12 @@
   else
     trans= &thd->transaction.stmt;
 
-#ifndef DBUG_OFF
-  handlerton **ht=trans->ht;
-  while (*ht)
-  {
-    DBUG_ASSERT(*ht != ht_arg);
-    ht++;
-  }
-#endif
+  for (ht=trans->ht; *ht; ht++)
+    if (*ht == ht_arg)
+      DBUG_VOID_RETURN;  /* already registered, return */
+
   trans->ht[trans->nht++]=ht_arg;
+  DBUG_ASSERT(*ht == ht_arg);
   trans->no_2pc|=(ht_arg->prepare==0);
   if (thd->transaction.xid.is_null())
     thd->transaction.xid.set(thd->query_id);
@@ -587,6 +587,11 @@
 #ifdef USING_TRANSACTIONS
   if (trans->nht)
   {
+    if (is_real_trans && wait_if_global_read_lock(thd, 0, 0))
+    {
+      ha_rollback_trans(thd, all);
+      DBUG_RETURN(1);
+    }
     DBUG_EXECUTE_IF("crash_commit_before", abort(););
     if (!trans->no_2pc && trans->nht > 1)
     {
@@ -596,7 +601,7 @@
         if ((err= (*(*ht)->prepare)(thd, all)))
         {
           my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
-          error=1;
+          error= 1;
         }
         statistic_increment(thd->status_var.ha_prepare_count,&LOCK_status);
       }
@@ -605,20 +610,28 @@
                     (error= !(cookie= tc_log->log(thd, xid)))))
       {
         ha_rollback_trans(thd, all);
-        return 1;
+        error= 1;
+        goto end;
       }
-    DBUG_EXECUTE_IF("crash_commit_after_log", abort(););
+      DBUG_EXECUTE_IF("crash_commit_after_log", abort(););
     }
     error=ha_commit_one_phase(thd, all) ? cookie ? 2 : 1 : 0;
     DBUG_EXECUTE_IF("crash_commit_before_unlog", abort(););
     if (cookie)
       tc_log->unlog(cookie, xid);
     DBUG_EXECUTE_IF("crash_commit_after", abort(););
+end:
+    if (is_real_trans)
+      start_waiting_global_read_lock(thd);
   }
 #endif /* USING_TRANSACTIONS */
   DBUG_RETURN(error);
 }
 
+/*
+  NOTE - this function does not care about global read lock.
+  A caller should.
+*/
 int ha_commit_one_phase(THD *thd, bool all)
 {
   int error=0;
@@ -629,18 +642,6 @@
 #ifdef USING_TRANSACTIONS
   if (trans->nht)
   {
-    bool need_start_waiters= 0;
-    if (is_real_trans)
-    {
-      if ((error= wait_if_global_read_lock(thd, 0, 0)))
-      {
-        my_error(ER_ERROR_DURING_COMMIT, MYF(0), error);
-        error= 1;
-      }
-      else
-        need_start_waiters= 1;
-    }
-
     for (ht=trans->ht; *ht; ht++)
     {
       int err;
@@ -665,8 +666,6 @@
       thd->variables.tx_isolation=thd->session_tx_isolation;
       thd->transaction.cleanup();
     }
-    if (need_start_waiters)
-      start_waiting_global_read_lock(thd);
   }
 #endif /* USING_TRANSACTIONS */
   DBUG_RETURN(error);
@@ -750,17 +749,15 @@
   DBUG_RETURN(error);
 }
 
-int ha_commit_or_rollback_by_xid(LEX_STRING *ident, bool commit)
+int ha_commit_or_rollback_by_xid(XID *xid, bool commit)
 {
-  XID xid;
   handlerton **ht= handlertons, **end_ht=ht+total_ha;
   int res= 1;
 
-  xid.set(ident);
   for ( ; ht < end_ht ; ht++)
     if ((*ht)->recover)
       res= res &&
-        (*(commit ? (*ht)->commit_by_xid : (*ht)->rollback_by_xid))(&xid);
+        (*(commit ? (*ht)->commit_by_xid : (*ht)->rollback_by_xid))(xid);
   return res;
 }
 
@@ -1652,6 +1649,9 @@
   case HA_ERR_NO_REFERENCED_ROW:
     textno=ER_NO_REFERENCED_ROW;
     break;
+  case HA_ERR_TABLE_DEF_CHANGED:
+    textno=ER_TABLE_DEF_CHANGED;
+    break;
   case HA_ERR_NO_SUCH_TABLE:
   {
     /*
@@ -2366,10 +2366,9 @@
     const char **ext, *old_ext;
 
     known_extensions_id= mysys_usage_id;
-    found_exts.push_back((char*) ".db");
     found_exts.push_back((char*) triggers_file_ext);
     for (types= sys_table_types; types->type; types++)
-    {      
+    {
       if (*types->value == SHOW_OPTION_YES)
       {
 	handler *file= get_new_handler(0,(enum db_type) types->db_type);

--- 1.136/sql/handler.h	Mon Apr 11 12:08:58 2005
+++ 1.137/sql/handler.h	Wed Apr 13 10:03:24 2005
@@ -366,7 +366,7 @@
 typedef struct st_ha_create_information
 {
   CHARSET_INFO *table_charset, *default_table_charset;
-  const char *comment,*password;
+  const char *comment,*password, *tablespace;
   const char *data_file_name, *index_file_name;
   const char *alias;
   ulonglong max_rows,min_rows;
@@ -384,6 +384,7 @@
   bool table_existed;			/* 1 in create if table existed */
   bool frm_only;                        /* 1 if no ha_create_table() */
   bool varchar;                         /* 1 if table has a VARCHAR */
+  bool store_on_disk;                   /* 1 if table stored on disk */
 } HA_CREATE_INFO;
 
 
@@ -424,6 +425,73 @@
   byte *end_of_used_area;     /* End of area that was used by handler */
 } HANDLER_BUFFER;
 
+/*
+  These structures are used to pass information from a set of SQL commands
+  on add/drop/change tablespace definitions to the proper storage engine.
+*/
+#define UNDEF_NODEGROUP 65535
+enum ts_command_type
+{
+  TS_CMD_NOT_DEFINED = -1,
+  CREATE_TABLESPACE = 0,
+  ALTER_TABLESPACE = 1,
+  CREATE_LOGFILE_GROUP = 2,
+  ALTER_LOGFILE_GROUP = 3,
+  DROP_TABLESPACE = 4,
+  DROP_LOGFILE_GROUP = 5,
+  CHANGE_FILE_TABLESPACE = 6,
+  ALTER_ACCESS_MODE_TABLESPACE = 7
+};
+
+enum tablespace_access_mode
+{
+  TS_NOT_DEFINED= -1,
+  TS_READ_ONLY = 0,
+  TS_READ_WRITE = 1,
+  TS_NOT_ACCESSIBLE = 2
+};
+
+class st_alter_tablespace : public Sql_alloc
+{
+  public:
+  char *tablespace_name;
+  char *logfile_group_name;
+  enum ts_command_type ts_cmd_type;
+  char *data_file_name;
+  char *undo_file_name;
+  char *redo_file_name;
+  ulonglong extent_size;
+  ulonglong undo_buffer_size;
+  ulonglong redo_buffer_size;
+  ulonglong initial_size;
+  ulonglong autoextend_size;
+  ulonglong max_size;
+  uint nodegroup_id;
+  enum db_type storage_engine;
+  bool wait_until_completed;
+  char *ts_comment;
+  enum tablespace_access_mode ts_access_mode;
+  st_alter_tablespace()
+  {
+    tablespace_name= NULL;
+    logfile_group_name= "DEFAULT_LG"; //Default log file group
+    ts_cmd_type= TS_CMD_NOT_DEFINED;
+    data_file_name= NULL;
+    undo_file_name= NULL;
+    redo_file_name= NULL;
+    extent_size= 1024*1024;        //Default 1 MByte
+    undo_buffer_size= 8*1024*1024; //Default 8 MByte
+    redo_buffer_size= 8*1024*1024; //Default 8 MByte
+    initial_size= 128*1024*1024;   //Default 128 MByte
+    autoextend_size= 0;            //No autoextension as default
+    max_size= 0;                   //Max size == initial size => no extension
+    storage_engine= DB_TYPE_UNKNOWN;
+    nodegroup_id= UNDEF_NODEGROUP;
+    wait_until_completed= TRUE;
+    ts_comment= NULL;
+    ts_access_mode= TS_NOT_DEFINED;
+  }
+};
 
 class handler :public Sql_alloc
 {
@@ -653,6 +721,8 @@
   virtual int assign_to_keycache(THD* thd, HA_CHECK_OPT* check_opt)
   { return HA_ADMIN_NOT_IMPLEMENTED; }
   virtual int preload_keys(THD* thd, HA_CHECK_OPT* check_opt)
+  { return HA_ADMIN_NOT_IMPLEMENTED; }
+  virtual int alter_tablespace(st_alter_tablespace *alter_tablespace_info)
   { return HA_ADMIN_NOT_IMPLEMENTED; }
   /* end of the list of admin commands */
 

--- 1.153/sql/log.cc	Wed Mar 23 08:10:18 2005
+++ 1.154/sql/log.cc	Wed Apr 13 10:03:24 2005
@@ -1531,18 +1531,20 @@
   return 0;
 }
 
-
-inline bool sync_binlog(IO_CACHE *cache)
+bool MYSQL_LOG::flush_and_sync()
 {
-  if (sync_binlog_period == ++sync_binlog_counter && sync_binlog_period)
+  int err=0, fd=log_file.file;
+  safe_mutex_assert_owner(&LOCK_log);
+  if (flush_io_cache(&log_file))
+    return 1;
+  if (++sync_binlog_counter >= sync_binlog_period && sync_binlog_period)
   {
     sync_binlog_counter= 0;
-    return my_sync(cache->file, MYF(MY_WME));
+    err=my_sync(fd, MYF(MY_WME));
   }
-  return 0;
+  return err;
 }
 
-
 /*
   Write an event to the binary log
 */
@@ -1675,8 +1677,8 @@
       }
     }
 
-    /* 
-       Write the SQL command 
+    /*
+       Write the SQL command
      */
 
     if (event_info->write(file))
@@ -1684,8 +1686,10 @@
 
     if (file == &log_file) // we are writing to the real log (disk)
     {
-      if (flush_io_cache(file) || sync_binlog(file))
+      if (flush_and_sync())
 	goto err;
+      signal_update();
+      rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED);
     }
     error=0;
 
@@ -1698,15 +1702,9 @@
 	my_error(ER_ERROR_ON_WRITE, MYF(0), name, errno);
       write_error=1;
     }
-    if (file == &log_file)
-    {
-      signal_update();
-      rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED);
-    }
   }
 
   pthread_mutex_unlock(&LOCK_log);
-
   DBUG_RETURN(error);
 }
 
@@ -1813,7 +1811,7 @@
     if (commit_event->write(&log_file))
       goto err;
 DBUG_skip_commit:
-    if (flush_io_cache(&log_file) || sync_binlog(&log_file))
+    if (flush_and_sync())
       goto err;
     DBUG_EXECUTE_IF("half_binlogged_transaction", abort(););
     if (cache->error)				// Error on read
@@ -1983,26 +1981,26 @@
   SYNOPSIS
     wait_for_update()
     thd			Thread variable
-    master_or_slave     If 0, the caller is the Binlog_dump thread from master;
+    is_slave            If 0, the caller is the Binlog_dump thread from master;
                         if 1, the caller is the SQL thread from the slave. This
                         influences only thd->proc_info.
 
   NOTES
     One must have a lock on LOCK_log before calling this function.
-    This lock will be freed before return! That's required by
+    This lock will be released before return! That's required by
     THD::enter_cond() (see NOTES in sql_class.h).
 */
 
-void MYSQL_LOG::wait_for_update(THD* thd, bool master_or_slave)
+void MYSQL_LOG::wait_for_update(THD* thd, bool is_slave)
 {
   const char *old_msg;
   DBUG_ENTER("wait_for_update");
   old_msg= thd->enter_cond(&update_cond, &LOCK_log,
-                           master_or_slave ?
+                           is_slave ?
                            "Has read all relay log; waiting for the slave I/O "
-                           "thread to update it" : 
+                           "thread to update it" :
                            "Has sent all binlog to slave; waiting for binlog "
-                           "to be updated"); 
+                           "to be updated");
   pthread_cond_wait(&update_cond, &LOCK_log);
   thd->exit_cond(old_msg);
   DBUG_VOID_RETURN;
@@ -2051,7 +2049,12 @@
       my_pwrite(log_file.file, &flags, 1, offset, MYF(0));
     }
 
-    if (my_close(log_file.file,MYF(0)) < 0 && ! write_error)
+    if (my_sync(log_file.file,MYF(MY_WME)) && ! write_error)
+    {
+      write_error=1;
+      sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno);
+    }
+    if (my_close(log_file.file,MYF(MY_WME)) && ! write_error)
     {
       write_error=1;
       sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno);
@@ -2945,8 +2948,10 @@
 
 void TC_LOG_BINLOG::unlog(ulong cookie, my_xid xid)
 {
-  if (thread_safe_dec_and_test(prepared_xids, &LOCK_prep_xids))
+  pthread_mutex_lock(&LOCK_prep_xids);
+  if (--prepared_xids == 0)
     pthread_cond_signal(&COND_prep_xids);
+  pthread_mutex_unlock(&LOCK_prep_xids);
   rotate_and_purge(0);     // as ::write() did not rotate
 }
 

--- 1.288/sql/mysql_priv.h	Thu Apr  7 18:24:08 2005
+++ 1.289/sql/mysql_priv.h	Wed Apr 13 10:03:24 2005
@@ -615,6 +615,7 @@
 bool mysql_xa_recover(THD *thd);
 
 bool check_simple_select();
+int mysql_alter_tablespace(st_alter_tablespace *ts_info);
 
 SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length);
 int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,

--- 1.172/sql/sql_class.cc	Mon Apr 11 14:37:59 2005
+++ 1.173/sql/sql_class.cc	Wed Apr 13 10:03:24 2005
@@ -202,10 +202,11 @@
 #ifndef DBUG_OFF
   dbug_sentry=THD_SENTRY_MAGIC;
 #endif
-#ifndef EMBEDDED_LIBRARY  
+#ifndef EMBEDDED_LIBRARY
   net.vio=0;
 #endif
-  net.last_error[0]=0;				// If error on boot
+  net.last_error[0]=0;                          // If error on boot
+  net.query_cache_query=0;                      // If error on boot
   ull=0;
   system_thread= cleanup_done= abort_on_warning= no_warnings_for_error= 0;
   peer_port= 0;					// For SHOW PROCESSLIST
@@ -214,7 +215,7 @@
 #endif
 #ifdef SIGNAL_WITH_VIO_CLOSE
   active_vio = 0;
-#endif  
+#endif
   pthread_mutex_init(&LOCK_delete, MY_MUTEX_INIT_FAST);
 
   /* Variables with default values */
@@ -343,7 +344,10 @@
 void THD::cleanup(void)
 {
   DBUG_ENTER("THD::cleanup");
-  ha_rollback(this);
+#ifdef ENABLE_WHEN_BINLOG_WILL_BE_ABLE_TO_PREPARE
+  if (transaction.xa_state != XA_PREPARED)
+#endif
+    ha_rollback(this);
   if (locked_tables)
   {
     lock=locked_tables; locked_tables=0;
@@ -385,17 +389,17 @@
   add_to_status(&global_status_var, &status_var);
 
   /* Close connection */
-#ifndef EMBEDDED_LIBRARY  
+#ifndef EMBEDDED_LIBRARY
   if (net.vio)
   {
     vio_delete(net.vio);
-    net_end(&net); 
+    net_end(&net);
   }
 #endif
   if (!cleanup_done)
     cleanup();
 
-    ha_close_connection(this);
+  ha_close_connection(this);
 
   sp_cache_clear(&sp_proc_cache);
   sp_cache_clear(&sp_func_cache);

--- 1.226/sql/sql_class.h	Mon Apr 11 14:37:59 2005
+++ 1.227/sql/sql_class.h	Wed Apr 13 10:03:24 2005
@@ -327,6 +327,7 @@
   bool is_active(const char* log_file_name);
   int update_log_index(LOG_INFO* linfo, bool need_update_threads);
   void rotate_and_purge(uint flags);
+  bool flush_and_sync();
   int purge_logs(const char *to_log, bool included,
                  bool need_mutex, bool need_update_threads,
                  ulonglong *decrease_log_space);
@@ -1264,18 +1265,18 @@
     pthread_mutex_unlock(&LOCK_delete);
   }
   void close_active_vio();
-#endif  
+#endif
   void awake(THD::killed_state state_to_set);
   /*
     For enter_cond() / exit_cond() to work the mutex must be got before
-    enter_cond() (in 4.1 an assertion will soon ensure this); this mutex is
-    then released by exit_cond(). Use must be:
-    lock mutex; enter_cond(); your code; exit_cond().
+    enter_cond(); this mutex is then released by exit_cond().
+    Usage must be: lock mutex; enter_cond(); your code; exit_cond().
   */
   inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex,
 			  const char* msg)
   {
     const char* old_msg = proc_info;
+    safe_mutex_assert_owner(mutex);
     mysys_var->current_mutex = mutex;
     mysys_var->current_cond = cond;
     proc_info = msg;

--- 1.174/sql/sql_lex.h	Tue Apr  5 13:22:05 2005
+++ 1.175/sql/sql_lex.h	Wed Apr 13 10:03:24 2005
@@ -25,6 +25,7 @@
 class sp_name;
 class sp_instr;
 class sp_pcontext;
+class st_alter_tablespace;
 
 /*
   The following hack is needed because mysql_yacc.cc does not define
@@ -89,6 +90,7 @@
   SQLCOM_CREATE_TRIGGER, SQLCOM_DROP_TRIGGER,
   SQLCOM_XA_START, SQLCOM_XA_END, SQLCOM_XA_PREPARE,
   SQLCOM_XA_COMMIT, SQLCOM_XA_ROLLBACK, SQLCOM_XA_RECOVER,
+  SQLCOM_ALTER_TABLESPACE,
   /* This should be the last !!! */
 
   SQLCOM_END
@@ -817,6 +819,12 @@
     during replication ("LOCAL 'filename' REPLACE INTO" part).
   */
   uchar *fname_start, *fname_end;
+
+  /*
+    Reference to a struct that contains information in various commands
+    to add/create/drop/change table spaces.
+  */
+  st_alter_tablespace *alter_tablespace_info;
 
   st_lex() :result(0), sql_command(SQLCOM_END), query_tables_own_last(0)
   {

--- 1.418/sql/sql_parse.cc	Mon Apr 11 14:38:00 2005
+++ 1.419/sql/sql_parse.cc	Wed Apr 13 10:03:25 2005
@@ -1103,7 +1103,8 @@
     thd->proc_info=0;
     thd->set_time();
     thd->init_for_queries();
-    while (!net->error && net->vio != 0 && !(thd->killed == THD::KILL_CONNECTION))
+    while (!net->error && net->vio != 0 &&
+           !(thd->killed == THD::KILL_CONNECTION))
     {
       net->no_send_error= 0;
       if (do_command(thd))
@@ -1912,12 +1913,13 @@
 #endif
     ulong uptime = (ulong) (thd->start_time - start_time);
     sprintf((char*) buff,
-	    "Uptime: %ld  Threads: %d  Questions: %lu  Slow queries: %lu  Opens: %ld  Flush tables: %ld  Open tables: %u  Queries per second avg: %.3f",
+	    "Uptime: %lu  Threads: %d  Questions: %lu  Slow queries: %lu  Opens: %lu  Flush tables: %lu  Open tables: %u  Queries per second avg: %.3f",
 	    uptime,
 	    (int) thread_count, (ulong) thd->query_id,
             (ulong) thd->status_var.long_query_count,
 	    thd->status_var.opened_tables, refresh_version, cached_tables(),
-	    uptime ? (float)thd->query_id/(float)uptime : 0);
+	    (uptime ? (ulonglong2double(thd->query_id) / (double) uptime) :
+	     (double) 0));
 #ifdef SAFEMALLOC
     if (sf_malloc_cur_memory)				// Using SAFEMALLOC
       sprintf(strend(buff), "  Memory in use: %ldK  Max memory used: %ldK",
@@ -4126,7 +4128,15 @@
 	sp= sp_find_function(thd, lex->spname);
       mysql_reset_errors(thd, 0);
       if (! sp)
-	result= SP_KEY_NOT_FOUND;
+      {
+	if (lex->spname->m_db.str)
+	  result= SP_KEY_NOT_FOUND;
+	else
+	{
+	  my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
+	  goto error;
+	}
+      }
       else
       {
         if (check_procedure_access(thd, ALTER_PROC_ACL, sp->m_db.str, 
@@ -4205,7 +4215,13 @@
 	  }
 	}
 #endif
-	result= SP_KEY_NOT_FOUND;
+	if (lex->spname->m_db.str)
+	  result= SP_KEY_NOT_FOUND;
+	else
+	{
+	  my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
+	  goto error;
+	}
       }
       res= result;
       switch (result)
@@ -4317,7 +4333,7 @@
   case SQLCOM_XA_START:
     if (thd->transaction.xa_state == XA_IDLE && thd->lex->xa_opt == XA_RESUME)
     {
-      if (! thd->transaction.xid.eq(&thd->lex->ident))
+      if (! thd->transaction.xid.eq(thd->lex->xid))
       {
         my_error(ER_XAER_NOTA, MYF(0));
         break;
@@ -4326,7 +4342,7 @@
       send_ok(thd);
       break;
     }
-    if (thd->lex->ident.length > MAXGTRIDSIZE || thd->lex->xa_opt != XA_NONE)
+    if (thd->lex->xa_opt != XA_NONE)
     { // JOIN is not supported yet. TODO
       my_error(ER_XAER_INVAL, MYF(0));
       break;
@@ -4344,7 +4360,7 @@
     }
     DBUG_ASSERT(thd->transaction.xid.is_null());
     thd->transaction.xa_state=XA_ACTIVE;
-    thd->transaction.xid.set(&thd->lex->ident);
+    thd->transaction.xid.set(thd->lex->xid);
     thd->options= ((thd->options & (ulong) ~(OPTION_STATUS_NO_TRANS_UPDATE)) |
                    OPTION_BEGIN);
     thd->server_status|= SERVER_STATUS_IN_TRANS;
@@ -4363,7 +4379,7 @@
                xa_state_names[thd->transaction.xa_state]);
       break;
     }
-    if (!thd->transaction.xid.eq(&thd->lex->ident))
+    if (!thd->transaction.xid.eq(thd->lex->xid))
     {
       my_error(ER_XAER_NOTA, MYF(0));
       break;
@@ -4378,7 +4394,7 @@
                xa_state_names[thd->transaction.xa_state]);
       break;
     }
-    if (!thd->transaction.xid.eq(&thd->lex->ident))
+    if (!thd->transaction.xid.eq(thd->lex->xid))
     {
       my_error(ER_XAER_NOTA, MYF(0));
       break;
@@ -4393,9 +4409,9 @@
     send_ok(thd);
     break;
   case SQLCOM_XA_COMMIT:
-    if (!thd->transaction.xid.eq(&thd->lex->ident))
+    if (!thd->transaction.xid.eq(thd->lex->xid))
     {
-      if (!(res= !ha_commit_or_rollback_by_xid(&thd->lex->ident, 1)))
+      if (!(res= !ha_commit_or_rollback_by_xid(thd->lex->xid, 1)))
         my_error(ER_XAER_NOTA, MYF(0));
       else
         send_ok(thd);
@@ -4412,10 +4428,19 @@
     else
     if (thd->transaction.xa_state == XA_PREPARED && thd->lex->xa_opt == XA_NONE)
     {
-      if (ha_commit_one_phase(thd, 1))
+      if (wait_if_global_read_lock(thd, 0, 0))
+      {
+        ha_rollback(thd);
         my_error(ER_XAER_RMERR, MYF(0));
+      }
       else
-        send_ok(thd);
+      {
+        if (ha_commit_one_phase(thd, 1))
+          my_error(ER_XAER_RMERR, MYF(0));
+        else
+          send_ok(thd);
+        start_waiting_global_read_lock(thd);
+      }
     }
     else
     {
@@ -4428,9 +4453,9 @@
     thd->transaction.xa_state=XA_NOTR;
     break;
   case SQLCOM_XA_ROLLBACK:
-    if (!thd->transaction.xid.eq(&thd->lex->ident))
+    if (!thd->transaction.xid.eq(thd->lex->xid))
     {
-      if (!(res= !ha_commit_or_rollback_by_xid(&thd->lex->ident, 0)))
+      if (!(res= !ha_commit_or_rollback_by_xid(thd->lex->xid, 0)))
         my_error(ER_XAER_NOTA, MYF(0));
       else
         send_ok(thd);

--- 1.220/sql/sql_table.cc	Mon Apr 11 14:38:00 2005
+++ 1.221/sql/sql_table.cc	Wed Apr 13 10:03:25 2005
@@ -563,12 +563,9 @@
     sql_field->pack_flag=f_settype((uint) sql_field->sql_type);
     break;
   case FIELD_TYPE_BIT:
-    if (!(table_flags & HA_CAN_BIT_FIELD))
-    {
-      my_error(ER_CHECK_NOT_IMPLEMENTED, MYF(0), "BIT FIELD");
-      DBUG_RETURN(1);
-    }
-    sql_field->pack_flag= FIELDFLAG_NUMBER;
+    /* 
+      We have sql_field->pack_flag already set here, see mysql_prepare_table().
+    */
     break;
   case FIELD_TYPE_NEWDECIMAL:
     sql_field->pack_flag=(FIELDFLAG_NUMBER |
@@ -774,6 +771,15 @@
       set_if_smaller(sql_field->length, MAX_FIELD_WIDTH-1);
     }
 
+    if (sql_field->sql_type == FIELD_TYPE_BIT)
+    { 
+      sql_field->pack_flag= FIELDFLAG_NUMBER;
+      if (file->table_flags() & HA_CAN_BIT_FIELD)
+        total_uneven_bit_length+= sql_field->length & 7;
+      else
+        sql_field->pack_flag|= FIELDFLAG_TREAT_BIT_AS_CHAR;
+    }
+
     sql_field->create_length_to_internal_length();
     if (sql_field->length > MAX_FIELD_VARCHARLENGTH &&
         !(sql_field->flags & BLOB_FLAG))
@@ -810,9 +816,6 @@
     if (!(sql_field->flags & NOT_NULL_FLAG))
       null_fields++;
 
-    if (sql_field->sql_type == FIELD_TYPE_BIT)
-      total_uneven_bit_length+= sql_field->length & 7;
-
     if (check_column_name(sql_field->field_name))
     {
       my_error(ER_WRONG_COLUMN_NAME, MYF(0), sql_field->field_name);
@@ -2225,7 +2228,9 @@
       TABLE_LIST *save_next_local= table->next_local,
                  *save_next_global= table->next_global;
       table->next_local= table->next_global= 0;
+      tmp_disable_binlog(thd); // binlogging is done by caller if wanted
       result_code= mysql_recreate_table(thd, table, 0);
+      reenable_binlog(thd);
       close_thread_tables(thd);
       if (!result_code) // recreation went ok
       {
@@ -3302,6 +3307,10 @@
   /* Safety fix for innodb */
   if (lower_case_table_names)
     my_casedn_str(files_charset_info, tmp_name);
+  if (new_db_type != old_db_type && !table->file->can_switch_engines()) {
+    my_error(ER_ROW_IS_REFERENCED, MYF(0));
+    goto err;
+  }
   create_info->db_type=new_db_type;
   if (!create_info->comment)
     create_info->comment= table->s->comment;

--- 1.361/sql/sql_yacc.yy	Tue Apr 12 23:12:14 2005
+++ 1.362/sql/sql_yacc.yy	Wed Apr 13 10:03:25 2005
@@ -117,6 +117,7 @@
 %token  END_OF_INPUT
 
 %token  ABORT_SYM
+%token  ACCESSIBLE_SYM
 %token  ACTION
 %token  ADD
 %token  ADDDATE_SYM
@@ -136,6 +137,7 @@
 %token  ASENSITIVE_SYM
 %token  ATAN
 %token  AUTO_INC
+%token  AUTOEXTEND_SIZE_SYM
 %token  AVG_ROW_LENGTH
 %token  AVG_SYM
 %token  BACKUP_SYM
@@ -204,6 +206,7 @@
 %token  CURTIME
 %token  DATABASE
 %token  DATABASES
+%token  DATAFILE_SYM
 %token  DATA_SYM
 %token  DATETIME
 %token  DATE_ADD_INTERVAL
@@ -233,6 +236,7 @@
 %token  DIRECTORY_SYM
 %token  DISABLE_SYM
 %token  DISCARD
+%token  DISK_SYM
 %token  DISTINCT
 %token  DIV_SYM
 %token  DOUBLE_SYM
@@ -265,6 +269,7 @@
 %token  EXPANSION_SYM
 %token  EXPORT_SET
 %token  EXTENDED_SYM
+%token  EXTENT_SIZE_SYM
 %token  EXTRACT_SYM
 %token  FALSE_SYM
 %token  FAST_SYM
@@ -327,6 +332,7 @@
 %token  INDEXES
 %token  INDEX_SYM
 %token  INFILE
+%token  INITIAL_SIZE_SYM
 %token  INNER_SYM
 %token  INNOBASE_SYM
 %token  INOUT_SYM
@@ -369,6 +375,7 @@
 %token  LOCATOR_SYM
 %token  LOCKS_SYM
 %token  LOCK_SYM
+%token  LOGFILE_SYM
 %token  LOGS_SYM
 %token  LOG_SYM
 %token  LONGBLOB
@@ -399,6 +406,7 @@
 %token  MAX_CONNECTIONS_PER_HOUR
 %token  MAX_QUERIES_PER_HOUR
 %token  MAX_ROWS
+%token  MAX_SIZE_SYM
 %token  MAX_SYM
 %token  MAX_UPDATES_PER_HOUR
 %token  MAX_USER_CONNECTIONS_SYM
@@ -406,6 +414,7 @@
 %token  MEDIUMINT
 %token  MEDIUMTEXT
 %token  MEDIUM_SYM
+%token  MEMORY_SYM
 %token  MERGE_SYM
 %token  MICROSECOND_SYM
 %token  MIGRATE_SYM
@@ -436,11 +445,13 @@
 %token  NE
 %token  NEW_SYM
 %token  NEXT_SYM
+%token  NODEGROUP_SYM
 %token  NONE_SYM
 %token  NOT2_SYM
 %token  NOT_SYM
 %token  NOW_SYM
 %token  NO_SYM
+%token  NO_WAIT_SYM
 %token  NO_WRITE_TO_BINLOG
 %token  NULL_SYM
 %token  NUM
@@ -490,9 +501,13 @@
 %token  RAID_TYPE
 %token  RAND
 %token  READS_SYM
+%token  READ_ONLY_SYM
 %token  READ_SYM
+%token  READ_WRITE_SYM
 %token  REAL
 %token  RECOVER_SYM
+%token  REDO_BUFFER_SIZE_SYM
+%token  REDOFILE_SYM
 %token  REDUNDANT_SYM
 %token  REFERENCES
 %token  REGEXP
@@ -608,6 +623,8 @@
 %token  ULONGLONG_NUM
 %token  UNCOMMITTED_SYM
 %token  UNDEFINED_SYM
+%token  UNDO_BUFFER_SIZE_SYM
+%token  UNDOFILE_SYM
 %token  UNDERSCORE_CHARSET
 %token  UNDO_SYM
 %token  UNICODE_SYM
@@ -640,6 +657,7 @@
 %token  VARIANCE_SYM
 %token  VARYING
 %token  VIEW_SYM
+%token  WAIT_SYM
 %token  WARNINGS
 %token  WEEK_SYM
 %token  WHEN_SYM
@@ -704,7 +722,7 @@
 	ulong_num raid_types merge_insert_types
 
 %type <ulonglong_number>
-	ulonglong_num
+	ulonglong_num size_number
 
 %type <lock_type>
 	replace_lock_option opt_low_priority insert_lock_option load_data_lock
@@ -1246,6 +1264,16 @@
 	  }
 	  opt_view_list AS select_init check_option
 	  {}
+        | CREATE LOGFILE_SYM GROUP logfile_group_info 
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->ts_cmd_type= CREATE_LOGFILE_GROUP;
+          }
+        | CREATE TABLESPACE tablespace_info
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->ts_cmd_type= CREATE_TABLESPACE;
+          }
         | CREATE TRIGGER_SYM ident trg_action_time trg_event 
           ON table_ident FOR_SYM EACH_SYM ROW_SYM
           {
@@ -2490,6 +2518,368 @@
           | DELETE_SYM
             { Lex->trg_chistics.event= TRG_EVENT_DELETE; }
           ;
+/*
+  This part of the parser contains common code for all TABLESPACE
+  commands.
+  CREATE TABLESPACE name ...
+  ALTER TABLESPACE name CHANGE DATAFILE ...
+  ALTER TABLESPACE name ADD DATAFILE ...
+  ALTER TABLESPACE name access_mode
+  CREATE LOGFILE GROUP name ...
+  ALTER LOGFILE GROUP name ADD UNDOFILE ..
+  ALTER LOGFILE GROUP name ADD REDOFILE ..
+  DROP TABLESPACE name
+  DROP LOGFILE GROUP name
+*/
+change_tablespace_access:
+          tablespace_name
+          ts_access_mode
+          ;
+
+change_tablespace_info:
+          tablespace_name
+          CHANGE ts_datafile
+          change_ts_option_list
+          ;
+
+tablespace_info:
+          tablespace_name
+          ADD ts_datafile
+          opt_logfile_group_name
+          tablespace_option_list
+          ;
+
+opt_logfile_group_name:
+          /* empty */ {}
+          | USE_SYM LOGFILE_SYM GROUP ident
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->logfile_group_name= $4.str;
+          };
+
+alter_tablespace_info:
+          tablespace_name
+          ADD ts_datafile
+          alter_tablespace_option_list
+          ;
+
+logfile_group_info:
+          logfile_group_name
+          add_log_file
+          logfile_group_option_list
+          ;
+
+alter_logfile_group_info:
+          logfile_group_name
+          add_log_file
+          alter_logfile_group_option_list
+          ;
+
+add_log_file:
+          ADD lg_undofile
+          | ADD lg_redofile
+          ;
+
+change_ts_option_list:
+          /* empty */ {}
+          change_ts_options
+          ;
+
+change_ts_options:
+          change_ts_option
+          | change_ts_options change_ts_option
+          | change_ts_options ',' change_ts_option
+          ;
+
+change_ts_option:
+          opt_ts_initial_size
+          | opt_ts_autoextend_size
+          | opt_ts_max_size
+          ;
+
+tablespace_option_list:
+          /* empty */ {}
+          tablespace_options
+          ;
+
+tablespace_options:
+          tablespace_option
+          | tablespace_options tablespace_option
+          | tablespace_options ',' tablespace_option
+          ;
+
+tablespace_option:
+          opt_ts_initial_size
+          | opt_ts_autoextend_size
+          | opt_ts_max_size
+          | opt_ts_extent_size
+          | opt_ts_nodegroup
+          | opt_ts_engine
+          | opt_ts_wait
+          | opt_ts_comment
+          ;
+
+alter_tablespace_option_list:
+          /* empty */ {}
+          alter_tablespace_options
+          ;
+
+alter_tablespace_options:
+          alter_tablespace_option
+          | alter_tablespace_options alter_tablespace_option
+          | alter_tablespace_options ',' alter_tablespace_option
+          ;
+
+alter_tablespace_option:
+          opt_ts_initial_size
+          | opt_ts_autoextend_size
+          | opt_ts_max_size
+          | opt_ts_engine
+          | opt_ts_wait
+          ;
+
+logfile_group_option_list:
+          /* empty */ {}
+          logfile_group_options
+          ;
+
+logfile_group_options:
+          logfile_group_option
+          | logfile_group_options logfile_group_option
+          | logfile_group_options ',' logfile_group_option
+          ;
+
+logfile_group_option:
+          opt_ts_initial_size
+          | opt_ts_undo_buffer_size
+          | opt_ts_redo_buffer_size
+          | opt_ts_nodegroup
+          | opt_ts_engine
+          | opt_ts_wait
+          | opt_ts_comment
+          ;
+
+alter_logfile_group_option_list:
+          /* empty */ {}
+          alter_logfile_group_options
+          ;
+
+alter_logfile_group_options:
+          alter_logfile_group_option
+          | alter_logfile_group_options alter_logfile_group_option
+          | alter_logfile_group_options ',' alter_logfile_group_option
+          ;
+
+alter_logfile_group_option:
+          opt_ts_initial_size
+          | opt_ts_engine
+          | opt_ts_wait
+          ;
+
+
+ts_datafile:
+          DATAFILE_SYM TEXT_STRING_sys
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->data_file_name= $2.str;
+          };
+
+lg_undofile:
+          UNDOFILE_SYM TEXT_STRING_sys
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->undo_file_name= $2.str;
+          };
+
+lg_redofile:
+          REDOFILE_SYM TEXT_STRING_sys
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->redo_file_name= $2.str;
+          };
+
+tablespace_name:
+          ident
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info= new st_alter_tablespace();
+            lex->alter_tablespace_info->tablespace_name= $1.str;
+            lex->sql_command= SQLCOM_ALTER_TABLESPACE;
+          };
+
+logfile_group_name:
+          ident
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info= new st_alter_tablespace();
+            lex->alter_tablespace_info->logfile_group_name= $1.str;
+            lex->sql_command= SQLCOM_ALTER_TABLESPACE;
+          };
+
+ts_access_mode:
+          READ_ONLY_SYM
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->ts_access_mode= TS_READ_ONLY;
+          }
+          | READ_WRITE_SYM
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->ts_access_mode= TS_READ_WRITE;
+          }
+          | NOT_SYM ACCESSIBLE_SYM
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->ts_access_mode= TS_NOT_ACCESSIBLE;
+          };
+
+opt_ts_initial_size:
+          INITIAL_SIZE_SYM opt_equal size_number
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->initial_size= $3;
+          };
+
+opt_ts_autoextend_size:
+          AUTOEXTEND_SIZE_SYM opt_equal size_number
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->autoextend_size= $3;
+          };
+
+opt_ts_max_size:
+          MAX_SIZE_SYM opt_equal size_number
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->max_size= $3;
+          };
+
+opt_ts_extent_size:
+          EXTENT_SIZE_SYM opt_equal size_number
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->extent_size= $3;
+          };
+
+opt_ts_undo_buffer_size:
+          UNDO_BUFFER_SIZE_SYM opt_equal size_number
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->undo_buffer_size= $3;
+          };
+
+opt_ts_redo_buffer_size:
+          REDO_BUFFER_SIZE_SYM opt_equal size_number
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->redo_buffer_size= $3;
+          };
+
+opt_ts_nodegroup:
+          NODEGROUP_SYM opt_equal ULONG_NUM
+          {
+            LEX *lex= Lex;
+            if (lex->alter_tablespace_info->nodegroup_id != UNDEF_NODEGROUP)
+            {
+              my_error(ER_TABLESPACE_OPTION_ONLY_ONCE,MYF(0),"NODEGROUP");
+              YYABORT;
+            }
+            lex->alter_tablespace_info->nodegroup_id= $3;
+          };
+
+opt_ts_comment:
+          COMMENT_SYM opt_equal TEXT_STRING_sys
+          {
+            LEX *lex= Lex;
+            if (lex->alter_tablespace_info->ts_comment != NULL)
+            {
+              my_error(ER_TABLESPACE_OPTION_ONLY_ONCE,MYF(0),"COMMENT");
+              YYABORT;
+            }
+            lex->alter_tablespace_info->ts_comment= $3.str;
+          };
+
+opt_ts_engine:
+          opt_storage ENGINE_SYM opt_equal storage_engines
+          {
+            LEX *lex= Lex;
+            if (lex->alter_tablespace_info->storage_engine != DB_TYPE_UNKNOWN)
+            {
+              my_error(ER_TABLESPACE_OPTION_ONLY_ONCE,MYF(0),
+                       "STORAGE ENGINE");
+              YYABORT;
+            }
+            lex->alter_tablespace_info->storage_engine= $4;
+          };
+
+opt_ts_wait:
+          WAIT_SYM
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->wait_until_completed= TRUE;
+          }
+          | NO_WAIT_SYM
+          {
+            LEX *lex= Lex;
+            if (!(lex->alter_tablespace_info->wait_until_completed))
+            {
+              my_error(ER_TABLESPACE_OPTION_ONLY_ONCE,MYF(0),"NO_WAIT");
+              YYABORT;
+            }
+            lex->alter_tablespace_info->wait_until_completed= FALSE;
+          };
+
+size_number:
+          ULONG_NUM { $$= $1;}
+          | IDENT
+          {
+            ulonglong number, test_number;
+            uint text_shift_number= 0;
+            longlong prefix_number;
+            char *end_ptr;
+            char *start_ptr= $1.str;
+            uint str_len= strlen(start_ptr);
+            int error;
+            prefix_number= my_strtoll10(start_ptr, &end_ptr, &error);
+            if ((start_ptr + str_len - 1) == end_ptr)
+            {
+              switch (end_ptr[0])
+              {
+                case 'g':
+                case 'G':
+                  text_shift_number+=10;
+                case 'm':
+                case 'M':
+                  text_shift_number+=10;
+                case 'k':
+                case 'K':
+                  text_shift_number+=10;
+                  break;
+                default:
+                {
+                  my_error(ER_WRONG_SIZE_NUMBER, MYF(0));
+                  YYABORT;
+                }
+              }
+              if (prefix_number >> 31)
+              {
+                my_error(ER_SIZE_OVERFLOW_ERROR, MYF(0));
+                YYABORT;
+              }
+              number= prefix_number << text_shift_number;
+            }
+            else
+            {
+              my_error(ER_WRONG_SIZE_NUMBER, MYF(0));
+              YYABORT;
+            }
+            $$= number;
+          }
+          ;
+
+/*
+  End tablespace part
+*/
 
 create2:
         '(' create2a {}
@@ -2633,6 +3023,9 @@
 	| INSERT_METHOD opt_equal merge_insert_types   { Lex->create_info.merge_insert_method= $3; Lex->create_info.used_fields|= HA_CREATE_USED_INSERT_METHOD;}
 	| DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.data_file_name= $4.str; Lex->create_info.used_fields|= HA_CREATE_USED_DATADIR; }
 	| INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.index_file_name= $4.str;  Lex->create_info.used_fields|= HA_CREATE_USED_INDEXDIR; }
+        | TABLESPACE ident {Lex->create_info.tablespace= $2.str;}
+        | STORAGE_SYM DISK_SYM {Lex->create_info.store_on_disk= TRUE;}
+        | STORAGE_SYM MEMORY_SYM {Lex->create_info.store_on_disk= FALSE;}
         ;
 
 default_charset:
@@ -3339,6 +3732,26 @@
 	  }
 	  opt_view_list AS select_init check_option
 	  {}
+        | ALTER TABLESPACE alter_tablespace_info
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->ts_cmd_type= ALTER_TABLESPACE;
+          }
+        | ALTER LOGFILE_SYM GROUP alter_logfile_group_info 
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->ts_cmd_type= ALTER_LOGFILE_GROUP;
+          }
+        | ALTER TABLESPACE change_tablespace_info
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->ts_cmd_type= CHANGE_FILE_TABLESPACE;
+          }
+        | ALTER TABLESPACE change_tablespace_access 
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->ts_cmd_type= ALTER_ACCESS_MODE_TABLESPACE;
+          }
 	;
 
 ident_or_empty:
@@ -5772,6 +6185,16 @@
               YYABORT;
             lex->ident= $5;
           }
+        | DROP TABLESPACE tablespace_name opt_ts_engine opt_ts_wait
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->ts_cmd_type= DROP_TABLESPACE;
+          }
+        | DROP LOGFILE_SYM GROUP tablespace_name opt_ts_engine opt_ts_wait
+          {
+            LEX *lex= Lex;
+            lex->alter_tablespace_info->ts_cmd_type= DROP_LOGFILE_GROUP;
+          }
 	;
 
 table_list:
@@ -7150,6 +7573,7 @@
 	| ANY_SYM		{}
 	| ASCII_SYM		{}
 	| AUTO_INC		{}
+        | AUTOEXTEND_SIZE_SYM   {}
 	| AVG_ROW_LENGTH	{}
 	| AVG_SYM		{}
 	| BACKUP_SYM		{}
@@ -7182,6 +7606,7 @@
 	| CONTAINS_SYM          {}
 	| CUBE_SYM		{}
 	| DATA_SYM		{}
+        | DATAFILE_SYM          {}
 	| DATETIME		{}
 	| DATE_SYM		{}
 	| DAY_SYM		{}
@@ -7191,6 +7616,7 @@
 	| DES_KEY_FILE		{}
 	| DIRECTORY_SYM		{}
 	| DISCARD		{}
+        | DISK_SYM              {}
 	| DO_SYM		{}
 	| DUMPFILE		{}
 	| DUPLICATE_SYM		{}
@@ -7205,6 +7631,7 @@
 	| EXECUTE_SYM		{}
         | EXPANSION_SYM         {}
 	| EXTENDED_SYM		{}
+        | EXTENT_SIZE_SYM       {}
 	| FAST_SYM		{}
 	| FOUND_SYM		{}
 	| DISABLE_SYM		{}
@@ -7229,6 +7656,7 @@
 	| INVOKER_SYM		{}
 	| IMPORT		{}
 	| INDEXES		{}
+        | INITIAL_SIZE_SYM      {}
 	| ISOLATION		{}
 	| ISSUER_SYM		{}
 	| INNOBASE_SYM		{}
@@ -7242,6 +7670,7 @@
 	| LINESTRING		{}
 	| LOCAL_SYM		{}
 	| LOCKS_SYM		{}
+        | LOGFILE_SYM           {}
 	| LOGS_SYM		{}
 	| MAX_ROWS		{}
 	| MASTER_SYM		{}
@@ -7261,9 +7690,11 @@
 	| MASTER_SSL_KEY_SYM	{}
 	| MAX_CONNECTIONS_PER_HOUR	 {}
 	| MAX_QUERIES_PER_HOUR	{}
+        | MAX_SIZE_SYM          {}
 	| MAX_UPDATES_PER_HOUR	{}
 	| MAX_USER_CONNECTIONS_SYM {}
 	| MEDIUM_SYM		{}
+	| MEMORY_SYM		{}
 	| MERGE_SYM		{}
 	| MICROSECOND_SYM	{}
         | MIGRATE_SYM           {}
@@ -7284,6 +7715,8 @@
 	| NEXT_SYM		{}
 	| NEW_SYM		{}
 	| NO_SYM		{}
+        | NO_WAIT_SYM           {}
+        | NODEGROUP_SYM         {}
 	| NONE_SYM		{}
 	| NVARCHAR_SYM		{}
 	| OFFSET_SYM		{}
@@ -7311,6 +7744,8 @@
 	| RAID_STRIPED_SYM	{}
 	| RAID_TYPE		{}
         | RECOVER_SYM           {}
+	| REDO_BUFFER_SIZE_SYM	{}
+	| REDOFILE_SYM  	{}
         | REDUNDANT_SYM         {}
 	| RELAY_LOG_FILE_SYM	{}
 	| RELAY_LOG_POS_SYM	{}
@@ -7373,6 +7808,8 @@
 	| FUNCTION_SYM		{}
 	| UNCOMMITTED_SYM	{}
 	| UNDEFINED_SYM		{}
+	| UNDO_BUFFER_SIZE_SYM	{}
+	| UNDOFILE_SYM  	{}
 	| UNICODE_SYM		{}
 	| UNKNOWN_SYM		{}
 	| UNTIL_SYM		{}
@@ -7382,6 +7819,7 @@
 	| VIEW_SYM		{}
 	| VALUE_SYM		{}
 	| WARNINGS		{}
+        | WAIT_SYM              {}
 	| WEEK_SYM		{}
 	| WORK_SYM		{}
 	| X509_SYM		{}

--- 1.24/sql/share/errmsg.txt	Fri Apr  8 19:57:57 2005
+++ 1.25/sql/share/errmsg.txt	Wed Apr 13 10:03:26 2005
@@ -5332,6 +5332,18 @@
 	eng "%s: ready for connections.\nVersion: '%s'  socket: '%s'  port: %d  %s"
 ER_LOAD_FROM_FIXED_SIZE_ROWS_TO_VAR
         eng "Can't load value from file with fixed size rows to variable"
+ER_TABLESPACE_OPTION_ONLY_ONCE
+        eng "It is not allowed to specify %s more than once"
+ER_CREATE_TABLESPACE_FAILED
+        eng "Failed to create %s"
+ER_DROP_TABLESPACE_FAILED
+        eng "Failed to drop %s"
+ER_TABLESPACE_AUTO_EXTEND_ERROR
+        eng "The handler doesn't support autoextend of tablespaces"
+ER_WRONG_SIZE_NUMBER
+        eng "A size parameter was incorrectly specified, either number or on the form 10M"
+ER_SIZE_OVERFLOW_ERROR
+        eng "The size number was correct but we don't allow the digit part to be more than 2 billion"
 ER_CANT_CREATE_USER_WITH_GRANT 42000
 	eng "You are not allowed to create a user with GRANT"
 ER_WRONG_VALUE_FOR_TYPE  

--- 1.291/BitKeeper/etc/logging_ok	Mon Apr 11 14:37:42 2005
+++ 1.292/BitKeeper/etc/logging_ok	Wed Apr 13 10:03:04 2005
@@ -9,6 +9,7 @@
 WAX@stripped
 acurtis@stripped
 acurtis@stripped
+acurtis@stripped
 administrador@stripped
 ahlentz@stripped
 akishkin@stripped
@@ -59,6 +60,7 @@
 gluh@stripped
 gluh@gluh.(none)
 gluh@stripped
+gluh@stripped
 gordon@stripped
 greg@stripped
 greg@stripped

--- 1.26/mysql-test/r/ndb_alter_table.result	Wed Mar 30 16:37:58 2005
+++ 1.27/mysql-test/r/ndb_alter_table.result	Wed Apr 13 10:10:54 2005
@@ -40,7 +40,7 @@
 (0,4,3,5,"PENDING",1,7),(NULL,4,3,5,"PENDING",1,7),(31,4,3,5,"PENDING",1,7), (7,4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7), (100,4,3,5,"PENDING",1,7), (99,4,3,5,"PENDING",1,7), (8,4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7);
 show table status;
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-t1	ndbcluster	10	Dynamic	9	#	#	#	0	#	101	#	#	#	latin1_swedish_ci	NULL		#
+t1	ndbcluster	10	Dynamic	9	#	#	#	0	#	102	#	#	#	latin1_swedish_ci	NULL		#
 select * from t1 order by col1;
 col1	col2	col3	col4	col5	col6	to_be_deleted
 0	4	3	5	PENDING	1	7
@@ -179,7 +179,7 @@
 2	two	two
 alter table t1 drop index c;
 select * from t1 where b = 'two';
-ERROR 42S02: Table 'test.t1' doesn't exist
+ERROR HY000: Table definition has changed, please retry transaction
 select * from t1 where b = 'two';
 a	b	c
 2	two	two

--- 1.19/mysql-test/t/ndb_alter_table.test	Wed Mar 30 16:37:58 2005
+++ 1.20/mysql-test/t/ndb_alter_table.test	Wed Apr 13 10:03:22 2005
@@ -147,7 +147,7 @@
 connection server1;
 alter table t1 drop index c;
 connection server2;
---error 1146
+--error 1412
 select * from t1 where b = 'two';
 select * from t1 where b = 'two';
 connection server1;

--- 1.35/ndb/include/ndbapi/NdbTransaction.hpp	Wed Mar  9 12:06:43 2005
+++ 1.36/ndb/include/ndbapi/NdbTransaction.hpp	Wed Apr 13 10:03:22 2005
@@ -658,6 +658,7 @@
   // Release all cursor operations in connection
   void releaseOps(NdbOperation*);	
   void releaseScanOperations(NdbIndexScanOperation*);	
+  void releaseExecutedScanOperation(NdbIndexScanOperation*);
 
   // Set the transaction identity of the transaction
   void		setTransactionId(Uint64 aTransactionId);

--- 1.34/ndb/src/kernel/blocks/dbtup/DbtupRoutines.cpp	Tue Apr 12 11:36:24 2005
+++ 1.35/ndb/src/kernel/blocks/dbtup/DbtupRoutines.cpp	Wed Apr 13 10:10:54 2005
@@ -924,6 +924,7 @@
         ndbrequire(i < regTabPtr->noOfCharsets);
         // not const in MySQL
         CHARSET_INFO* cs = regTabPtr->charsetArray[i];
+        int not_used;
         const char* ssrc = (const char*)&inBuffer[indexBuf + 1];
         Uint32 lb, len;
         if (! NdbSqlUtil::get_var_length(typeId, ssrc, bytes, lb, len)) {
@@ -933,7 +934,7 @@
         }
 	// fast fix bug#7340
         if (typeId != NDB_TYPE_TEXT &&
-	    (*cs->cset->well_formed_len)(cs, ssrc + lb, ssrc + lb + len, ZNIL) != len) {
+	    (*cs->cset->well_formed_len)(cs, ssrc + lb, ssrc + lb + len, ZNIL, &not_used) != len) {
           ljam();
           terrorCode = ZINVALID_CHAR_FORMAT;
           return false;
@@ -1314,6 +1315,7 @@
         ndbrequire(i < regTabPtr->noOfCharsets);
         // not const in MySQL
         CHARSET_INFO* cs = regTabPtr->charsetArray[i];
+	int not_used;
         const char* ssrc = (const char*)&inBuffer[indexBuf + 1];
         Uint32 lb, len;
         if (! NdbSqlUtil::get_var_length(typeId, ssrc, bytes, lb, len)) {
@@ -1323,7 +1325,7 @@
         }
 	// fast fix bug#7340
         if (typeId != NDB_TYPE_TEXT &&
-	    (*cs->cset->well_formed_len)(cs, ssrc + lb, ssrc + lb + len, ZNIL) != len) {
+	    (*cs->cset->well_formed_len)(cs, ssrc + lb, ssrc + lb + len, ZNIL, &not_used) != len) {
           ljam();
           terrorCode = ZINVALID_CHAR_FORMAT;
           return false;

--- 1.38/ndb/src/ndbapi/Ndb.cpp	Mon Feb 21 07:28:15 2005
+++ 1.39/ndb/src/ndbapi/Ndb.cpp	Wed Apr 13 10:03:23 2005
@@ -756,26 +756,28 @@
 Uint64
 Ndb::getAutoIncrementValue(const char* aTableName, Uint32 cacheSize)
 {
-  DEBUG_TRACE("getAutoIncrementValue");
+  DBUG_ENTER("getAutoIncrementValue");
   const char * internalTableName = internalizeTableName(aTableName);
   Ndb_local_table_info *info=
     theDictionary->get_local_table_info(internalTableName, false);
   if (info == 0)
-    return ~0;
+    DBUG_RETURN(~0);
   const NdbTableImpl *table= info->m_table_impl;
   Uint64 tupleId = getTupleIdFromNdb(table->m_id, cacheSize);
-  return tupleId;
+  DBUG_PRINT("info", ("value %u", tupleId));
+  DBUG_RETURN(tupleId);
 }
 
 Uint64
 Ndb::getAutoIncrementValue(const NdbDictionary::Table * aTable, Uint32 cacheSize)
 {
-  DEBUG_TRACE("getAutoIncrementValue");
+  DBUG_ENTER("getAutoIncrementValue");
   if (aTable == 0)
-    return ~0;
+    DBUG_RETURN(~0);
   const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable);
   Uint64 tupleId = getTupleIdFromNdb(table->m_id, cacheSize);
-  return tupleId;
+  DBUG_PRINT("info", ("value %u", tupleId));
+  DBUG_RETURN(tupleId);
 }
 
 Uint64 
@@ -790,39 +792,45 @@
 Uint64
 Ndb::getTupleIdFromNdb(Uint32 aTableId, Uint32 cacheSize)
 {
+  DBUG_ENTER("getTupleIdFromNdb");
   if ( theFirstTupleId[aTableId] != theLastTupleId[aTableId] )
   {
     theFirstTupleId[aTableId]++;
-    return theFirstTupleId[aTableId];
+    DBUG_PRINT("info", ("next cached value %u", theFirstTupleId[aTableId]));
+    DBUG_RETURN(theFirstTupleId[aTableId]);
   }
   else // theFirstTupleId == theLastTupleId
   {
-    return opTupleIdOnNdb(aTableId, cacheSize, 0);
+    DBUG_PRINT("info",("reading %u values from database", 
+                       (cacheSize == 0) ? 1 : cacheSize));
+    DBUG_RETURN(opTupleIdOnNdb(aTableId, (cacheSize == 0) ? 1 : cacheSize, 0));
   }
 }
 
 Uint64
 Ndb::readAutoIncrementValue(const char* aTableName)
 {
-  DEBUG_TRACE("readtAutoIncrementValue");
+  DBUG_ENTER("readtAutoIncrementValue");
   const NdbTableImpl* table = theDictionary->getTable(aTableName);
   if (table == 0) {
     theError= theDictionary->getNdbError();
-    return ~0;
+    DBUG_RETURN(~0);
   }
   Uint64 tupleId = readTupleIdFromNdb(table->m_id);
-  return tupleId;
+  DBUG_PRINT("info", ("value %u", tupleId));
+  DBUG_RETURN(tupleId);
 }
 
 Uint64
 Ndb::readAutoIncrementValue(const NdbDictionary::Table * aTable)
 {
-  DEBUG_TRACE("readtAutoIncrementValue");
+  DBUG_ENTER("readtAutoIncrementValue");
   if (aTable == 0)
-    return ~0;
+    DBUG_RETURN(~0);
   const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable);
   Uint64 tupleId = readTupleIdFromNdb(table->m_id);
-  return tupleId;
+  DBUG_PRINT("info", ("value %u", tupleId));
+  DBUG_RETURN(tupleId);
 }
 
 Uint64

--- 1.42/ndb/src/ndbapi/NdbTransaction.cpp	Mon Apr 11 14:37:58 2005
+++ 1.43/ndb/src/ndbapi/NdbTransaction.cpp	Wed Apr 13 10:03:23 2005
@@ -949,6 +949,37 @@
 }//NdbTransaction::releaseScanOperations()
 
 /*****************************************************************************
+void releaseExecutedScanOperation();
+
+Remark:         Release scan op when hupp'ed trans closed (save memory)
+******************************************************************************/
+void 
+NdbTransaction::releaseExecutedScanOperation(NdbIndexScanOperation* cursorOp)
+{
+  DBUG_ENTER("NdbTransaction::releaseExecutedScanOperation");
+  DBUG_PRINT("enter", ("this=0x%x op=0x%x", (UintPtr)this, (UintPtr)cursorOp))
+
+  // here is one reason to make op lists doubly linked
+  if (m_firstExecutedScanOp == cursorOp) {
+    m_firstExecutedScanOp = (NdbIndexScanOperation*)cursorOp->theNext;
+    cursorOp->release();
+    theNdb->releaseScanOperation(cursorOp);
+  } else if (m_firstExecutedScanOp != NULL) {
+    NdbIndexScanOperation* tOp = m_firstExecutedScanOp;
+    while (tOp->theNext != NULL) {
+      if (tOp->theNext == cursorOp) {
+        tOp->theNext = cursorOp->theNext;
+        cursorOp->release();
+        theNdb->releaseScanOperation(cursorOp);
+        break;
+      }
+      tOp = (NdbIndexScanOperation*)tOp->theNext;
+    }
+  }
+  DBUG_VOID_RETURN;
+}//NdbTransaction::releaseExecutedScanOperation()
+
+/*****************************************************************************
 NdbOperation* getNdbOperation(const char* aTableName);
 
 Return Value    Return a pointer to a NdbOperation object if getNdbOperation 

--- 1.54/ndb/src/ndbapi/NdbScanOperation.cpp	Mon Apr 11 14:37:58 2005
+++ 1.55/ndb/src/ndbapi/NdbScanOperation.cpp	Wed Apr 13 10:03:23 2005
@@ -638,8 +638,14 @@
   return 0;
 }
 
-void NdbScanOperation::close(bool forceSend)
+void NdbScanOperation::close(bool forceSend, bool releaseOp)
 {
+  DBUG_ENTER("NdbScanOperation::close");
+  DBUG_PRINT("enter", ("this=%x tcon=%x con=%x force=%d release=%d",
+                       (UintPtr)this,
+                       (UintPtr)m_transConnection, (UintPtr)theNdbCon,
+                       forceSend, releaseOp));
+
   if(m_transConnection){
     if(DEBUG_NEXT_RESULT)
       ndbout_c("close() theError.code = %d "
@@ -655,13 +661,21 @@
     Guard guard(tp->theMutexPtr);
     close_impl(tp, forceSend);
     
-  } while(0);
-  
-  theNdbCon->theScanningOp = 0;
-  theNdb->closeTransaction(theNdbCon);
-  
-  theNdbCon = 0;
+  }
+
+  NdbConnection* tCon = theNdbCon;
+  NdbConnection* tTransCon = m_transConnection;
+  theNdbCon = NULL;
   m_transConnection = NULL;
+
+  if (releaseOp && tTransCon) {
+    NdbIndexScanOperation* tOp = (NdbIndexScanOperation*)this;
+    tTransCon->releaseExecutedScanOperation(tOp);
+  }
+  
+  tCon->theScanningOp = 0;
+  theNdb->closeTransaction(tCon);
+  DBUG_VOID_RETURN;
 }
 
 void

--- 1.132/sql/ha_ndbcluster.cc	Mon Apr 11 14:37:59 2005
+++ 1.133/sql/ha_ndbcluster.cc	Wed Apr 13 10:10:54 2005
@@ -180,7 +180,6 @@
 
   { 709, HA_ERR_NO_SUCH_TABLE, 0 },
   { 723, HA_ERR_NO_SUCH_TABLE, 0 },
-  { 284, HA_ERR_NO_SUCH_TABLE, 1 },
 
   { 266, HA_ERR_LOCK_WAIT_TIMEOUT, 1 },
   { 274, HA_ERR_LOCK_WAIT_TIMEOUT, 1 },
@@ -195,6 +194,8 @@
   { 827, HA_ERR_RECORD_FILE_FULL, 1 },
   { 832, HA_ERR_RECORD_FILE_FULL, 1 },
 
+  { 284, HA_ERR_TABLE_DEF_CHANGED, 0 },
+
   { 0, 1, 0 },
 
   { -1, -1, 1 }
@@ -450,13 +451,31 @@
 int ha_ndbcluster::ndb_err(NdbTransaction *trans)
 {
   int res;
-  const NdbError err= trans->getNdbError();
+  NdbError err= trans->getNdbError();
   DBUG_ENTER("ndb_err");
   
   ERR_PRINT(err);
   switch (err.classification) {
   case NdbError::SchemaError:
     invalidateDictionaryCache();
+
+    if (err.code==284)
+    {
+      /*
+         Check if the table is _really_ gone or if the table has
+         been alterend and thus changed table id
+       */
+      NDBDICT *dict= get_ndb()->getDictionary();
+      DBUG_PRINT("info", ("Check if table %s is really gone", m_tabname));
+      if (!(dict->getTable(m_tabname)))
+      {
+        err= dict->getNdbError();
+        DBUG_PRINT("info", ("Table not found, error: %d", err.code));
+        if (err.code != 709)
+          DBUG_RETURN(1);
+      }
+      DBUG_PRINT("info", ("Table exists but must have changed"));
+    }
     break;
   default:
     break;
@@ -1921,8 +1940,12 @@
 
     if (has_auto_increment) 
     {
+      THD *thd= table->in_use;
+
       m_skip_auto_increment= FALSE;
       update_auto_increment();
+      /* Ensure that handler is always called for auto_increment values */
+      thd->next_insert_id= 0;
       m_skip_auto_increment= !auto_increment_column_changed;
     }
 
@@ -2664,7 +2687,7 @@
     m_ops_pending= 0;
   }
   
-  cursor->close(m_force_send);
+  cursor->close(m_force_send, true);
   m_active_cursor= m_multi_cursor= NULL;
   DBUG_RETURN(0);
 }
@@ -2972,7 +2995,11 @@
   DBUG_PRINT("enter", ("rows: %d", (int)rows));
   
   m_rows_inserted= 0;
-  m_rows_to_insert= rows; 
+  if (rows == 0)
+    /* We don't know how many will be inserted, guess */
+    m_rows_to_insert= m_autoincrement_prefetch;
+  else
+    m_rows_to_insert= rows; 
 
   /* 
     Calculate how many rows that should be inserted
@@ -4103,6 +4130,10 @@
   DBUG_ENTER("get_auto_increment");
   DBUG_PRINT("enter", ("m_tabname: %s", m_tabname));
   Ndb *ndb= get_ndb();
+   
+  if (m_rows_inserted > m_rows_to_insert)
+    /* We guessed too low */
+    m_rows_to_insert+= m_autoincrement_prefetch;
   cache_size= 
     (m_rows_to_insert - m_rows_inserted < m_autoincrement_prefetch) ?
     m_rows_to_insert - m_rows_inserted 
@@ -5686,7 +5717,7 @@
 close_scan:
     if (res == 1)
     {
-      m_multi_cursor->close();
+      m_multi_cursor->close(false, true);
       m_active_cursor= m_multi_cursor= 0;
       DBUG_MULTI_RANGE(8);
       continue;
@@ -5826,6 +5857,7 @@
   {
     thd->cleanup();
     delete thd;
+    delete ndb;
     DBUG_RETURN(NULL);
   }
 
@@ -5944,6 +5976,7 @@
 
   thd->cleanup();
   delete thd;
+  delete ndb;
   DBUG_PRINT("exit", ("ndb_util_thread"));
   my_thread_end();
   pthread_exit(0);

--- 1.199/BitKeeper/etc/ignore	Wed Apr  6 17:33:57 2005
+++ 1.200/BitKeeper/etc/ignore	Wed Apr 13 10:03:04 2005
@@ -102,6 +102,7 @@
 Makefile.in'
 PENDING/*
 TAGS
+VC++Files/client/mysql_amd64.dsp
 ac_available_languages_fragment
 acinclude.m4
 aclocal.m4
@@ -274,6 +275,8 @@
 client/mysqlmanagerc
 client/mysqlshow
 client/mysqltest
+client/mysqltestmanager-pwgen
+client/mysqltestmanagerc
 client/mysys_priv.h
 client/select_test
 client/ssl_test
@@ -786,17 +789,22 @@
 ndb/src/common/util/libgeneral.dsp
 ndb/src/cw/cpcd/ndb_cpcd
 ndb/src/kernel/blocks/backup/libbackup.dsp
+ndb/src/kernel/blocks/backup/ndb_print_backup_file
 ndb/src/kernel/blocks/backup/restore/ndb_restore
 ndb/src/kernel/blocks/cmvmi/libcmvmi.dsp
 ndb/src/kernel/blocks/dbacc/libdbacc.dsp
 ndb/src/kernel/blocks/dbdict/libdbdict.dsp
+ndb/src/kernel/blocks/dbdict/ndb_print_schema_file
 ndb/src/kernel/blocks/dbdih/libdbdih.dsp
+ndb/src/kernel/blocks/dbdih/ndb_print_sys_file
 ndb/src/kernel/blocks/dblqh/libdblqh.dsp
 ndb/src/kernel/blocks/dbtc/libdbtc.dsp
 ndb/src/kernel/blocks/dbtup/libdbtup.dsp
+ndb/src/kernel/blocks/dbtup/test_varpage
 ndb/src/kernel/blocks/dbtux/libdbtux.dsp
 ndb/src/kernel/blocks/dbutil/libdbutil.dsp
 ndb/src/kernel/blocks/grep/libgrep.dsp
+ndb/src/kernel/blocks/ndb_print_file
 ndb/src/kernel/blocks/ndbcntr/libndbcntr.dsp
 ndb/src/kernel/blocks/ndbfs/libndbfs.dsp
 ndb/src/kernel/blocks/qmgr/libqmgr.dsp
@@ -815,6 +823,8 @@
 ndb/src/mgmsrv/ndb_mgmd
 ndb/src/mgmsrv/ndb_mgmd.dsp
 ndb/src/ndbapi/libndbapi.dsp
+ndb/test/ndbapi/DbAsyncGenerator
+ndb/test/ndbapi/DbCreate
 ndb/test/ndbapi/bank/bankCreator
 ndb/test/ndbapi/bank/bankMakeGL
 ndb/test/ndbapi/bank/bankSumAccounts
@@ -830,21 +840,26 @@
 ndb/test/ndbapi/flexBench.dsp
 ndb/test/ndbapi/flexHammer
 ndb/test/ndbapi/flexTT
+ndb/test/ndbapi/ndbapi_slow_select
 ndb/test/ndbapi/testBackup
 ndb/test/ndbapi/testBasic
 ndb/test/ndbapi/testBasic.dsp
 ndb/test/ndbapi/testBasicAsynch
+ndb/test/ndbapi/testBitfield
 ndb/test/ndbapi/testBlobs
 ndb/test/ndbapi/testBlobs.dsp
 ndb/test/ndbapi/testDataBuffers
 ndb/test/ndbapi/testDeadlock
 ndb/test/ndbapi/testDict
 ndb/test/ndbapi/testIndex
+ndb/test/ndbapi/testLcp
 ndb/test/ndbapi/testMgm
 ndb/test/ndbapi/testNdbApi
 ndb/test/ndbapi/testNodeRestart
 ndb/test/ndbapi/testOIBasic
 ndb/test/ndbapi/testOperations
+ndb/test/ndbapi/testPartitioning
+ndb/test/ndbapi/testReadPerf
 ndb/test/ndbapi/testRestartGci
 ndb/test/ndbapi/testScan
 ndb/test/ndbapi/testScan.dsp
@@ -854,6 +869,7 @@
 ndb/test/ndbapi/testTimeout
 ndb/test/ndbapi/testTransactions
 ndb/test/ndbapi/test_event
+ndb/test/ndbapi/test_event_multi_table
 ndb/test/run-test/atrt
 ndb/test/src/libNDBT.dsp
 ndb/test/tools/copy_tab
@@ -1100,13 +1116,10 @@
 tools/my_vsnprintf.c
 tools/mysqlmanager
 tools/mysqlmngd
+tools/mysqltestmanager
 tools/mysys_priv.h
 vi.h
 vio/test-ssl
 vio/test-sslclient
 vio/test-sslserver
 vio/viotest-ssl
-VC++Files/client/mysql_amd64.dsp
-client/mysqltestmanager-pwgen
-client/mysqltestmanagerc
-tools/mysqltestmanager

--- 1.36/BitKeeper/triggers/post-commit	Fri Feb 25 10:23:12 2005
+++ 1.37/BitKeeper/triggers/post-commit	Wed Apr 13 10:03:22 2005
@@ -27,6 +27,7 @@
 fi
 
 CHANGESET=`bk -R prs -r+ -h -d':P:::I:' ChangeSet`
+CSETKEY=`bk -R prs -r+ -h -d':KEY:' ChangeSet`
 BUG=`bk -R prs -r+ -h -d':C:' ChangeSet | sed -ne 's/^.*[Bb][Uu][Gg] *# *\([0-9][0-9]*\).*$/\1/p'`
 WL=`bk -R prs -r+ -h -d':C:' ChangeSet | sed -ne 's/^.*[Ww][Ll] *# *\([0-9][0-9]*\).*$/ WL#\1/p'`
 
@@ -52,6 +53,7 @@
 From: $FROM
 To: $TO
 Subject: bk commit - $VERSION tree ($CHANGESET)${BS}${WL}
+X-CSetKey: <$CSETKEY>
 $BH
 EOF
   bk changes -v -r+
@@ -68,6 +70,7 @@
 From: $FROM
 To: $INTERNALS
 Subject: bk commit into $VERSION tree ($CHANGESET)$BS
+X-CSetKey: <$CSETKEY>
 $BH
 Below is the list of changes that have just been committed into a local
 $VERSION repository of $USER. When $USER does a push these changes will
Thread
bk commit into 5.1-ndb tree (joreland:1.1842)jonas.oreland13 Apr