List:Commits« Previous MessageNext Message »
From:Elliot Murphy Date:June 25 2006 3:59pm
Subject:bk commit into 5.1 tree (elliot:1.2216)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of emurphy. When emurphy 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.2216 06/06/25 09:59:34 elliot@stripped +24 -0
  Merge mysql.com:/home/emurphy/src/bk-clean/tmp_merge
  into  mysql.com:/home/emurphy/src/bk-clean/mysql-5.1

  mysql-test/r/select.result
    1.131 06/06/25 09:59:29 elliot@stripped +0 -6
    manual merge

  mysql-test/r/func_time.result
    1.57 06/06/25 09:59:29 elliot@stripped +3 -10
    manual merge

  include/Makefile.am
    1.66 06/06/25 09:59:29 elliot@stripped +2 -2
    manual merge

  storage/ndb/src/ndbapi/ndberror.c
    1.65 06/06/25 09:58:07 elliot@scared.(none) +0 -0
    Auto merged

  storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp
    1.67 06/06/25 09:58:07 elliot@scared.(none) +0 -0
    Auto merged

  sql/sql_select.cc
    1.415 06/06/25 09:58:07 elliot@scared.(none) +1 -1
    Auto merged

  sql/slave.cc
    1.274 06/06/25 09:58:07 elliot@scared.(none) +0 -0
    Auto merged

  sql/opt_sum.cc
    1.53 06/06/25 09:58:06 elliot@scared.(none) +0 -0
    Auto merged

  sql/mysqld.cc
    1.565 06/06/25 09:58:06 elliot@scared.(none) +0 -0
    Auto merged

  sql/item_strfunc.h
    1.112 06/06/25 09:58:06 elliot@scared.(none) +0 -0
    Auto merged

  sql/item_strfunc.cc
    1.275 06/06/25 09:58:06 elliot@scared.(none) +0 -0
    Auto merged

  sql/item_cmpfunc.cc
    1.209 06/06/25 09:58:05 elliot@scared.(none) +0 -0
    Auto merged

  sql/ha_ndbcluster.cc
    1.335 06/06/25 09:58:05 elliot@scared.(none) +0 -0
    Auto merged

  sql/field.h
    1.188 06/06/25 09:58:05 elliot@scared.(none) +0 -0
    Auto merged

  sql/field.cc
    1.321 06/06/25 09:58:05 elliot@scared.(none) +0 -0
    Auto merged

  mysys/Makefile.am
    1.81 06/06/25 09:58:05 elliot@scared.(none) +0 -0
    Auto merged

  mysql-test/t/select.test
    1.105 06/06/25 09:58:05 elliot@scared.(none) +0 -0
    Auto merged

  mysql-test/t/myisam.test
    1.59 06/06/25 09:58:05 elliot@scared.(none) +0 -0
    Auto merged

  mysql-test/t/func_time.test
    1.46 06/06/25 09:58:05 elliot@scared.(none) +0 -0
    Auto merged

  mysql-test/r/myisam.result
    1.82 06/06/25 09:58:05 elliot@scared.(none) +0 -0
    Auto merged

  mysql-test/r/insert_select.result
    1.38 06/06/25 09:58:05 elliot@scared.(none) +0 -0
    Auto merged

  mysql-test/r/func_str.result
    1.118 06/06/25 09:58:05 elliot@scared.(none) +0 -0
    Auto merged

  storage/ndb/src/ndbapi/ndberror.c
    1.30.20.2 06/06/25 09:58:04 elliot@scared.(none) +0 -0
    Merge rename: ndb/src/ndbapi/ndberror.c -> storage/ndb/src/ndbapi/ndberror.c

  storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp
    1.24.30.2 06/06/25 09:58:04 elliot@scared.(none) +0 -0
    Merge rename: ndb/src/kernel/blocks/dbdih/DbdihMain.cpp ->
storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp

  mysql-test/valgrind.supp
    1.13 06/06/25 09:58:04 elliot@scared.(none) +0 -0
    Auto merged

  mysql-test/mysql-test-run.sh
    1.325 06/06/25 09:58:04 elliot@scared.(none) +0 -0
    Auto merged

# 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:	elliot
# Host:	scared.(none)
# Root:	/home/emurphy/src/bk-clean/mysql-5.1/RESYNC

--- 1.65/include/Makefile.am	2006-05-31 18:02:50 -04:00
+++ 1.66/include/Makefile.am	2006-06-25 09:59:29 -04:00
@@ -32,7 +32,8 @@ noinst_HEADERS =	config-win.h config-net
 			thr_lock.h t_ctype.h violite.h md5.h base64.h \
 			mysql_version.h.in my_handler.h my_time.h decimal.h \
 			my_vle.h my_user.h my_atomic.h atomic/nolock.h \
-			atomic/rwlock.h atomic/x86-gcc.h atomic/x86-msvc.h
+			atomic/rwlock.h atomic/x86-gcc.h atomic/x86-msvc.h \
+			my_libwrap.h
 
 # mysql_version.h are generated
 CLEANFILES =            mysql_version.h my_config.h readline openssl

--- 1.80/mysys/Makefile.am	2006-06-01 06:23:10 -04:00
+++ 1.81/mysys/Makefile.am	2006-06-25 09:58:05 -04:00
@@ -53,7 +53,7 @@ libmysys_a_SOURCES =    my_init.c my_get
 			my_gethostbyname.c rijndael.c my_aes.c sha1.c \
 			my_handler.c my_netware.c my_largepage.c \
 			my_memmem.c \
-			my_windac.c my_access.c base64.c
+			my_windac.c my_access.c base64.c my_libwrap.c
 EXTRA_DIST =		thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \
 			thr_mutex.c thr_rwlock.c \
 			CMakeLists.txt mf_soundex.c \

--- 1.320/sql/field.cc	2006-06-19 06:00:31 -04:00
+++ 1.321/sql/field.cc	2006-06-25 09:58:05 -04:00
@@ -4640,7 +4640,7 @@ int Field_timestamp::store(const char *f
   }
 
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
   {
     int4store(ptr,tmp);
   }
@@ -4707,7 +4707,7 @@ int Field_timestamp::store(longlong nr, 
                          nr, MYSQL_TIMESTAMP_DATETIME, 1);
 
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
   {
     int4store(ptr,timestamp);
   }
@@ -4733,7 +4733,7 @@ longlong Field_timestamp::val_int(void)
   THD  *thd= table ? table->in_use : current_thd;
 
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
     temp=uint4korr(ptr);
   else
 #endif
@@ -4764,7 +4764,7 @@ String *Field_timestamp::val_str(String 
   val_buffer->length(field_length);
 
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
     temp=uint4korr(ptr);
   else
 #endif
@@ -4829,7 +4829,7 @@ bool Field_timestamp::get_date(TIME *lti
   long temp;
   THD *thd= table ? table->in_use : current_thd;
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
     temp=uint4korr(ptr);
   else
 #endif
@@ -4866,7 +4866,7 @@ int Field_timestamp::cmp(const char *a_p
 {
   int32 a,b;
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
   {
     a=sint4korr(a_ptr);
     b=sint4korr(b_ptr);
@@ -4884,7 +4884,7 @@ int Field_timestamp::cmp(const char *a_p
 void Field_timestamp::sort_string(char *to,uint length __attribute__((unused)))
 {
 #ifdef WORDS_BIGENDIAN
-  if (!table->s->db_low_byte_first)
+  if (!table || !table->s->db_low_byte_first)
   {
     to[0] = ptr[0];
     to[1] = ptr[1];
@@ -4914,7 +4914,7 @@ void Field_timestamp::set_time()
   long tmp= (long) thd->query_start();
   set_notnull();
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
   {
     int4store(ptr,tmp);
   }
@@ -5326,7 +5326,7 @@ int Field_date::store(const char *from, 
                          from, len, MYSQL_TIMESTAMP_DATE, 1);
 
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
   {
     int4store(ptr,tmp);
   }
@@ -5388,7 +5388,7 @@ int Field_date::store(longlong nr, bool 
                          MYSQL_TIMESTAMP_DATETIME, 1);
 
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
   {
     int4store(ptr, nr);
   }
@@ -5415,7 +5415,7 @@ double Field_date::val_real(void)
   ASSERT_COLUMN_MARKED_FOR_READ;
   int32 j;
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
     j=sint4korr(ptr);
   else
 #endif
@@ -5429,7 +5429,7 @@ longlong Field_date::val_int(void)
   ASSERT_COLUMN_MARKED_FOR_READ;
   int32 j;
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
     j=sint4korr(ptr);
   else
 #endif
@@ -5446,7 +5446,7 @@ String *Field_date::val_str(String *val_
   val_buffer->alloc(field_length);
   int32 tmp;
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
     tmp=sint4korr(ptr);
   else
 #endif
@@ -5464,7 +5464,7 @@ int Field_date::cmp(const char *a_ptr, c
 {
   int32 a,b;
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
   {
     a=sint4korr(a_ptr);
     b=sint4korr(b_ptr);
@@ -5482,7 +5482,7 @@ int Field_date::cmp(const char *a_ptr, c
 void Field_date::sort_string(char *to,uint length __attribute__((unused)))
 {
 #ifdef WORDS_BIGENDIAN
-  if (!table->s->db_low_byte_first)
+  if (!table || !table->s->db_low_byte_first)
   {
     to[0] = ptr[0];
     to[1] = ptr[1];
@@ -5729,7 +5729,7 @@ int Field_datetime::store(const char *fr
                          from, len, MYSQL_TIMESTAMP_DATETIME, 1);
 
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
   {
     int8store(ptr,tmp);
   }
@@ -5783,7 +5783,7 @@ int Field_datetime::store(longlong nr, b
                          MYSQL_TIMESTAMP_DATETIME, 1);
 
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
   {
     int8store(ptr,nr);
   }
@@ -5813,7 +5813,7 @@ int Field_datetime::store_time(TIME *lti
     set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
   }
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
   {
     int8store(ptr,tmp);
   }
@@ -5841,7 +5841,7 @@ longlong Field_datetime::val_int(void)
   ASSERT_COLUMN_MARKED_FOR_READ;
   longlong j;
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
     j=sint8korr(ptr);
   else
 #endif
@@ -5862,7 +5862,7 @@ String *Field_datetime::val_str(String *
   int part3;
 
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
     tmp=sint8korr(ptr);
   else
 #endif
@@ -5927,7 +5927,7 @@ int Field_datetime::cmp(const char *a_pt
 {
   longlong a,b;
 #ifdef WORDS_BIGENDIAN
-  if (table->s->db_low_byte_first)
+  if (table && table->s->db_low_byte_first)
   {
     a=sint8korr(a_ptr);
     b=sint8korr(b_ptr);
@@ -5945,7 +5945,7 @@ int Field_datetime::cmp(const char *a_pt
 void Field_datetime::sort_string(char *to,uint length __attribute__((unused)))
 {
 #ifdef WORDS_BIGENDIAN
-  if (!table->s->db_low_byte_first)
+  if (!table || !table->s->db_low_byte_first)
   {
     to[0] = ptr[0];
     to[1] = ptr[1];

--- 1.187/sql/field.h	2006-06-18 06:56:31 -04:00
+++ 1.188/sql/field.h	2006-06-25 09:58:05 -04:00
@@ -822,7 +822,7 @@ public:
     if ((*null_value= is_null()))
       return 0;
 #ifdef WORDS_BIGENDIAN
-    if (table->s->db_low_byte_first)
+    if (table && table->s->db_low_byte_first)
       return sint4korr(ptr);
 #endif
     long tmp;

--- 1.208/sql/item_cmpfunc.cc	2006-06-23 17:24:11 -04:00
+++ 1.209/sql/item_cmpfunc.cc	2006-06-25 09:58:05 -04:00
@@ -138,7 +138,8 @@ static void agg_cmp_type(THD *thd, Item_
       }
       continue;
     }
-    if ((res= items[i]->real_item()->type()) == Item::FIELD_ITEM)
+    if ((res= items[i]->real_item()->type()) == Item::FIELD_ITEM &&
+        items[i]->result_type() != INT_RESULT)
     {
       field= ((Item_field *)items[i]->real_item())->field;
       break;

--- 1.564/sql/mysqld.cc	2006-06-23 09:05:09 -04:00
+++ 1.565/sql/mysqld.cc	2006-06-25 09:58:06 -04:00
@@ -116,16 +116,7 @@ extern "C" {					// Because of SCO 3.2V4
 #include <sys/utsname.h>
 #endif /* __WIN__ */
 
-#ifdef HAVE_LIBWRAP
-#include <tcpd.h>
-#include <syslog.h>
-#ifdef NEED_SYS_SYSLOG_H
-#include <sys/syslog.h>
-#endif /* NEED_SYS_SYSLOG_H */
-int allow_severity = LOG_INFO;
-int deny_severity = LOG_WARNING;
-
-#endif /* HAVE_LIBWRAP */
+#include <my_libwrap.h>
 
 #ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
@@ -687,6 +678,8 @@ static const char* default_dbug_option;
 #endif
 #ifdef HAVE_LIBWRAP
 const char *libwrapName= NULL;
+int allow_severity = LOG_INFO;
+int deny_severity = LOG_WARNING;
 #endif
 #ifdef HAVE_QUERY_CACHE
 static ulong query_cache_limit= 0;
@@ -4239,8 +4232,8 @@ pthread_handler_t handle_connections_soc
 	struct request_info req;
 	signal(SIGCHLD, SIG_DFL);
 	request_init(&req, RQ_DAEMON, libwrapName, RQ_FILE, new_sock, NULL);
-	fromhost(&req);
-	if (!hosts_access(&req))
+	my_fromhost(&req);
+	if (!my_hosts_access(&req))
 	{
 	  /*
 	    This may be stupid but refuse() includes an exit(0)
@@ -4248,7 +4241,7 @@ pthread_handler_t handle_connections_soc
 	    clean_exit() - same stupid thing ...
 	  */
 	  syslog(deny_severity, "refused connect from %s",
-		 eval_client(&req));
+		 my_eval_client(&req));
 
 	  /*
 	    C++ sucks (the gibberish in front just translates the supplied

--- 1.52/sql/opt_sum.cc	2006-06-18 06:20:27 -04:00
+++ 1.53/sql/opt_sum.cc	2006-06-25 09:58:06 -04:00
@@ -744,6 +744,12 @@ static bool find_key_for_maxmin(bool max
   {
     KEY_PART_INFO *part,*part_end;
     key_part_map key_part_to_use= 0;
+    /*
+      Perform a check if index is not disabled by ALTER TABLE
+      or IGNORE INDEX.
+    */
+    if (!table->keys_in_use_for_query.is_set(idx))
+      continue;
     uint jdx= 0;
     *prefix_len= 0;
     for (part= keyinfo->key_part, part_end= part+keyinfo->key_parts ;

--- 1.273/sql/slave.cc	2006-06-15 07:38:09 -04:00
+++ 1.274/sql/slave.cc	2006-06-25 09:58:07 -04:00
@@ -1419,6 +1419,15 @@ int fetch_master_table(THD *thd, const c
     if (connect_to_master(thd, mysql, mi))
     {
       my_error(ER_CONNECT_TO_MASTER, MYF(0), mysql_error(mysql));
+      /*
+        We need to clear the active VIO since, theoretically, somebody
+        might issue an awake() on this thread.  If we are then in the
+        middle of closing and destroying the VIO inside the
+        mysql_close(), we will have a problem.
+       */
+#ifdef SIGNAL_WITH_VIO_CLOSE
+      thd->clear_active_vio();
+#endif
       mysql_close(mysql);
       DBUG_RETURN(1);
     }
@@ -3507,6 +3516,17 @@ err:
   VOID(pthread_mutex_unlock(&LOCK_thread_count));
   if (mysql)
   {
+    /*
+      Here we need to clear the active VIO before closing the
+      connection with the master.  The reason is that THD::awake()
+      might be called from terminate_slave_thread() because somebody
+      issued a STOP SLAVE.  If that happends, the close_active_vio()
+      can be called in the middle of closing the VIO associated with
+      the 'mysql' object, causing a crash.
+    */
+#ifdef SIGNAL_WITH_VIO_CLOSE
+    thd->clear_active_vio();
+#endif
     mysql_close(mysql);
     mi->mysql=0;
   }

--- 1.414/sql/sql_select.cc	2006-06-20 06:20:28 -04:00
+++ 1.415/sql/sql_select.cc	2006-06-25 09:58:07 -04:00
@@ -1071,8 +1071,9 @@ JOIN::optimize()
 			   group_list ? 0 : select_distinct,
 			   group_list && simple_group,
 			   select_options,
-			   (order == 0 || skip_sort_order) ? select_limit :
-			   HA_POS_ERROR,
+			   (order == 0 || skip_sort_order || 
+                            test(select_options & OPTION_BUFFER_RESULT)) ? 
+                             select_limit : HA_POS_ERROR,
 			   (char *) "")))
       DBUG_RETURN(1);
 
@@ -8893,6 +8894,11 @@ create_tmp_table(THD *thd,TMP_TABLE_PARA
       }
       keyinfo->key_length+=  key_part_info->length;
     }
+  }
+  else
+  {
+    set_if_smaller(table->s->max_rows, rows_limit);
+    param->end_write_records= rows_limit;
   }
 
   if (distinct && field_count != param->hidden_field_count)

--- 1.24.30.1/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp	2006-06-20 13:25:30 -04:00
+++ 1.67/storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp	2006-06-25 09:58:07 -04:00
@@ -67,6 +67,8 @@
 #include <signaldata/CreateFragmentation.hpp>
 #include <signaldata/LqhFrag.hpp>
 #include <signaldata/FsOpenReq.hpp>
+#include <signaldata/DihFragCount.hpp>
+#include <signaldata/DictLock.hpp>
 #include <DebuggerNames.hpp>
 
 #include <EventLogger.hpp>
@@ -544,7 +546,7 @@ void Dbdih::execCONTINUEB(Signal* signal
     break;
   case DihContinueB::ZSTART_PERMREQ_AGAIN:
     jam();
-    nodeRestartPh2Lab(signal);
+    nodeRestartPh2Lab2(signal);
     return;
     break;
   case DihContinueB::SwitchReplica:
@@ -609,6 +611,14 @@ void Dbdih::execCONTINUEB(Signal* signal
     checkWaitDropTabFailedLqh(signal, nodeId, tableId);
     return;
   }
+  case DihContinueB::ZTO_START_FRAGMENTS:
+  {
+    TakeOverRecordPtr takeOverPtr;
+    takeOverPtr.i = signal->theData[1];
+    ptrCheckGuard(takeOverPtr, MAX_NDB_NODES, takeOverRecord);
+    nr_start_fragments(signal, takeOverPtr);
+    return;
+  }
   }//switch
   
   ndbrequire(false);
@@ -639,9 +649,11 @@ void Dbdih::execCOPY_GCIREQ(Signal* sign
     c_copyGCISlave.m_expectedNextWord += CopyGCIReq::DATA_SIZE;
     return;
   }//if
-  
+
+  Uint32 tmp= SYSFILE->m_restart_seq;
   memcpy(sysfileData, cdata, sizeof(sysfileData));
-  
+  SYSFILE->m_restart_seq = tmp;
+
   c_copyGCISlave.m_copyReason = reason;
   c_copyGCISlave.m_senderRef  = signal->senderBlockRef();
   c_copyGCISlave.m_senderData = copyGCI->anyData;
@@ -1052,7 +1064,7 @@ void Dbdih::execREAD_CONFIG_REQ(Signal* 
   jamEntry();
 
   const ndb_mgm_configuration_iterator * p = 
-    theConfiguration.getOwnConfigIterator();
+    m_ctx.m_config.getOwnConfigIterator();
   ndbrequireErr(p != 0, NDBD_EXIT_INVALID_CONFIG);
 
   initData();
@@ -1138,7 +1150,7 @@ void Dbdih::execDIH_RESTARTREQ(Signal* s
 {
   jamEntry();
   cntrlblockref = signal->theData[0];
-  if(theConfiguration.getInitialStart()){
+  if(m_ctx.m_config.getInitialStart()){
     sendSignal(cntrlblockref, GSN_DIH_RESTARTREF, signal, 1, JBB);
   } else {
     readGciFileLab(signal);
@@ -1284,6 +1296,7 @@ void Dbdih::execNDB_STTOR(Signal* signal
     case NodeState::ST_INITIAL_NODE_RESTART:
     case NodeState::ST_NODE_RESTART:
       jam();
+
       /***********************************************************************
        * When starting nodes while system is operational we must be controlled
        * by the master since only one node restart is allowed at a time. 
@@ -1294,7 +1307,7 @@ void Dbdih::execNDB_STTOR(Signal* signal
       req->startingRef = reference();
       req->startingVersion = 0; // Obsolete
       sendSignal(cmasterdihref, GSN_START_MEREQ, signal, 
-		 StartMeReq::SignalLength, JBB);
+                 StartMeReq::SignalLength, JBB);
       return;
     }
     ndbrequire(false);
@@ -1354,6 +1367,24 @@ void Dbdih::execNDB_STTOR(Signal* signal
     }
     ndbrequire(false);
     break;
+  case ZNDB_SPH7:
+    jam();
+    switch (typestart) {
+    case NodeState::ST_INITIAL_START:
+    case NodeState::ST_SYSTEM_RESTART:
+      jam();
+      ndbsttorry10Lab(signal, __LINE__);
+      return;
+    case NodeState::ST_NODE_RESTART:
+    case NodeState::ST_INITIAL_NODE_RESTART:
+      jam();
+      sendDictUnlockOrd(signal, c_dictLockSlavePtrI_nodeRestart);
+      c_dictLockSlavePtrI_nodeRestart = RNIL;
+      ndbsttorry10Lab(signal, __LINE__);
+      return;
+    }
+    ndbrequire(false);
+    break;
   default:
     jam();
     ndbsttorry10Lab(signal, __LINE__);
@@ -1564,6 +1595,34 @@ void Dbdih::execREAD_NODESCONF(Signal* s
 /*---------------------------------------------------------------------------*/
 void Dbdih::nodeRestartPh2Lab(Signal* signal) 
 {
+  /*
+   * Lock master DICT to avoid metadata operations during INR/NR.
+   * Done just before START_PERMREQ.
+   *
+   * It would be more elegant to do this just before START_MEREQ.
+   * The problem is, on INR we end up in massive invalidateNodeLCP
+   * which is not fully protected against metadata ops.
+   */
+  ndbrequire(c_dictLockSlavePtrI_nodeRestart == RNIL);
+
+  // check that we are not yet taking part in schema ops
+  CRASH_INSERTION(7174);
+
+  Uint32 lockType = DictLockReq::NodeRestartLock;
+  Callback c = { safe_cast(&Dbdih::recvDictLockConf_nodeRestart), 0 };
+  sendDictLockReq(signal, lockType, c);
+}
+
+void Dbdih::recvDictLockConf_nodeRestart(Signal* signal, Uint32 data, Uint32 ret)
+{
+  ndbrequire(c_dictLockSlavePtrI_nodeRestart == RNIL);
+  c_dictLockSlavePtrI_nodeRestart = data;
+
+  nodeRestartPh2Lab2(signal);
+}
+
+void Dbdih::nodeRestartPh2Lab2(Signal* signal)
+{
   /*------------------------------------------------------------------------*/
   // REQUEST FOR PERMISSION FROM MASTER TO START A NODE IN AN ALREADY
   // RUNNING SYSTEM.
@@ -1574,7 +1633,7 @@ void Dbdih::nodeRestartPh2Lab(Signal* si
   req->nodeId    = cownNodeId;
   req->startType = cstarttype;
   sendSignal(cmasterdihref, GSN_START_PERMREQ, signal, 3, JBB);
-}//Dbdih::nodeRestartPh2Lab()
+}
 
 void Dbdih::execSTART_PERMCONF(Signal* signal) 
 {
@@ -1656,12 +1715,15 @@ void Dbdih::execSTART_MECONF(Signal* sig
    *
    * But dont copy lastCompletedGCI:s
    */
+  Uint32 key = SYSFILE->m_restart_seq;
   Uint32 tempGCP[MAX_NDB_NODES];
   for(i = 0; i < MAX_NDB_NODES; i++)
     tempGCP[i] = SYSFILE->lastCompletedGCI[i];
 
   for(i = 0; i < Sysfile::SYSFILE_SIZE32; i++)
     sysfileData[i] = cdata[i];
+
+  SYSFILE->m_restart_seq = key;
   for(i = 0; i < MAX_NDB_NODES; i++)
     SYSFILE->lastCompletedGCI[i] = tempGCP[i];
 
@@ -1696,12 +1758,12 @@ void Dbdih::execSTART_PERMREQ(Signal* si
   const BlockReference retRef = req->blockRef;
   const Uint32 nodeId   = req->nodeId;
   const Uint32 typeStart = req->startType;
-  
   CRASH_INSERTION(7122);
   ndbrequire(isMaster());
   ndbrequire(refToNode(retRef) == nodeId);
   if ((c_nodeStartMaster.activeState) ||
-      (c_nodeStartMaster.wait != ZFALSE)) {
+      (c_nodeStartMaster.wait != ZFALSE) ||
+      ERROR_INSERTED_CLEAR(7175)) {
     jam();
     signal->theData[0] = nodeId;
     signal->theData[1] = StartPermRef::ZNODE_ALREADY_STARTING_ERROR;
@@ -1819,11 +1881,6 @@ void Dbdih::execSTART_MEREQ(Signal* sign
   ndbrequire(c_nodeStartMaster.startNode == Tnodeid);
   ndbrequire(getNodeStatus(Tnodeid) == NodeRecord::STARTING);
   
-  sendSTART_RECREQ(signal, Tnodeid);
-}//Dbdih::execSTART_MEREQ()
-
-void Dbdih::nodeRestartStartRecConfLab(Signal* signal) 
-{
   c_nodeStartMaster.blockLcp = true;
   if ((c_lcpState.lcpStatus != LCP_STATUS_IDLE) &&
       (c_lcpState.lcpStatus != LCP_TCGET)) {
@@ -2634,13 +2691,14 @@ void Dbdih::sendStartTo(Signal* signal, 
     return;
   }//if
   c_startToLock = takeOverPtrI;
+
+  takeOverPtr.p->toMasterStatus = TakeOverRecord::STARTING;
   StartToReq * const req = (StartToReq *)&signal->theData[0];
   req->userPtr = takeOverPtr.i;
   req->userRef = reference();
   req->startingNodeId = takeOverPtr.p->toStartingNode;
   req->nodeTakenOver = takeOverPtr.p->toFailedNode;
   req->nodeRestart = takeOverPtr.p->toNodeRestart;
-  takeOverPtr.p->toMasterStatus = TakeOverRecord::STARTING;
   sendLoopMacro(START_TOREQ, sendSTART_TOREQ);
 }//Dbdih::sendStartTo()
 
@@ -2684,9 +2742,153 @@ void Dbdih::execSTART_TOCONF(Signal* sig
   CRASH_INSERTION(7134);
   c_startToLock = RNIL;
 
+  if (takeOverPtr.p->toNodeRestart)
+  {
+    jam();
+    takeOverPtr.p->toMasterStatus = TakeOverRecord::STARTING_LOCAL_FRAGMENTS;
+    nr_start_fragments(signal, takeOverPtr);
+    return;
+  }
+
   startNextCopyFragment(signal, takeOverPtr.i);
 }//Dbdih::execSTART_TOCONF()
 
+void
+Dbdih::nr_start_fragments(Signal* signal, 
+			  TakeOverRecordPtr takeOverPtr)
+{
+  Uint32 loopCount = 0 ;
+  TabRecordPtr tabPtr;
+  while (loopCount++ < 100) {
+    tabPtr.i = takeOverPtr.p->toCurrentTabref;
+    if (tabPtr.i >= ctabFileSize) {
+      jam();
+      nr_run_redo(signal, takeOverPtr);
+      return;
+    }//if
+    ptrAss(tabPtr, tabRecord);
+    if (tabPtr.p->tabStatus != TabRecord::TS_ACTIVE){
+      jam();
+      takeOverPtr.p->toCurrentFragid = 0;
+      takeOverPtr.p->toCurrentTabref++;
+      continue;
+    }//if
+    Uint32 fragId = takeOverPtr.p->toCurrentFragid;
+    if (fragId >= tabPtr.p->totalfragments) {
+      jam();
+      takeOverPtr.p->toCurrentFragid = 0;
+      takeOverPtr.p->toCurrentTabref++;
+      continue;
+    }//if
+    FragmentstorePtr fragPtr;
+    getFragstore(tabPtr.p, fragId, fragPtr);
+    ReplicaRecordPtr loopReplicaPtr;
+    loopReplicaPtr.i = fragPtr.p->oldStoredReplicas;
+    while (loopReplicaPtr.i != RNIL) {
+      ptrCheckGuard(loopReplicaPtr, creplicaFileSize, replicaRecord);
+      if (loopReplicaPtr.p->procNode == takeOverPtr.p->toStartingNode) {
+        jam();
+	nr_start_fragment(signal, takeOverPtr, loopReplicaPtr);
+	break;
+      } else {
+        jam();
+        loopReplicaPtr.i = loopReplicaPtr.p->nextReplica;
+      }//if
+    }//while
+    takeOverPtr.p->toCurrentFragid++;
+  }//while
+  signal->theData[0] = DihContinueB::ZTO_START_FRAGMENTS;
+  signal->theData[1] = takeOverPtr.i;
+  sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
+}
+
+void
+Dbdih::nr_start_fragment(Signal* signal, 
+			 TakeOverRecordPtr takeOverPtr,
+			 ReplicaRecordPtr replicaPtr)
+{
+  Uint32 i, j = 0;
+  Uint32 maxLcpId = 0;
+  Uint32 maxLcpIndex = ~0;
+  
+  Uint32 restorableGCI = 0;
+  
+  ndbout_c("tab: %d frag: %d replicaP->nextLcp: %d",
+	   takeOverPtr.p->toCurrentTabref,
+	   takeOverPtr.p->toCurrentFragid,
+	   replicaPtr.p->nextLcp);
+  
+  Uint32 idx = replicaPtr.p->nextLcp;
+  for(i = 0; i<MAX_LCP_STORED; i++, idx = nextLcpNo(idx))
+  {
+    ndbout_c("scanning idx: %d lcpId: %d", idx, replicaPtr.p->lcpId[idx]);
+    if (replicaPtr.p->lcpStatus[idx] == ZVALID) 
+    {
+      ndbrequire(replicaPtr.p->lcpId[idx] > maxLcpId);
+      Uint32 startGci = replicaPtr.p->maxGciCompleted[idx];
+      Uint32 stopGci = replicaPtr.p->maxGciStarted[idx];
+      for (;j < replicaPtr.p->noCrashedReplicas; j++)
+      {
+	ndbout_c("crashed replica: %d(%d) replicaLastGci: %d",
+		 j, 
+		 replicaPtr.p->noCrashedReplicas,
+		 replicaPtr.p->replicaLastGci[j]);
+	if (replicaPtr.p->replicaLastGci[j] > stopGci)
+	{
+	  maxLcpId = replicaPtr.p->lcpId[idx];
+	  maxLcpIndex = idx;
+	  restorableGCI = replicaPtr.p->replicaLastGci[j];
+	  break;
+	}
+      }
+    }
+  }
+  
+  if (maxLcpIndex == ~0)
+  {
+    ndbout_c("Didnt find any LCP for node: %d tab: %d frag: %d",
+	     takeOverPtr.p->toStartingNode,
+	     takeOverPtr.p->toCurrentTabref,
+	     takeOverPtr.p->toCurrentFragid);
+    replicaPtr.p->lcpIdStarted = 0;
+  }
+  else
+  {
+    ndbout_c("Found LCP: %d(%d) maxGciStarted: %d maxGciCompleted: %d restorable: %d(%d)
newestRestorableGCI: %d",
+	     maxLcpId,
+	     maxLcpIndex,
+	     replicaPtr.p->maxGciStarted[maxLcpIndex],
+	     replicaPtr.p->maxGciCompleted[maxLcpIndex],	     
+	     restorableGCI,
+	     SYSFILE->lastCompletedGCI[takeOverPtr.p->toStartingNode],
+	     SYSFILE->newestRestorableGCI);
+
+    replicaPtr.p->lcpIdStarted = restorableGCI;
+    BlockReference ref = calcLqhBlockRef(takeOverPtr.p->toStartingNode);
+    StartFragReq *req = (StartFragReq *)signal->getDataPtrSend();
+    req->userPtr = 0;
+    req->userRef = reference();
+    req->lcpNo = maxLcpIndex;
+    req->lcpId = maxLcpId;
+    req->tableId = takeOverPtr.p->toCurrentTabref;
+    req->fragId = takeOverPtr.p->toCurrentFragid;
+    req->noOfLogNodes = 1;
+    req->lqhLogNode[0] = takeOverPtr.p->toStartingNode;
+    req->startGci[0] = replicaPtr.p->maxGciCompleted[maxLcpIndex];
+    req->lastGci[0] = restorableGCI;
+    sendSignal(ref, GSN_START_FRAGREQ, signal, 
+	       StartFragReq::SignalLength, JBB);
+  }
+}
+
+void
+Dbdih::nr_run_redo(Signal* signal, TakeOverRecordPtr takeOverPtr)
+{
+  takeOverPtr.p->toCurrentTabref = 0;
+  takeOverPtr.p->toCurrentFragid = 0;
+  sendSTART_RECREQ(signal, takeOverPtr.p->toStartingNode);
+}
+
 void Dbdih::initStartTakeOver(const StartToReq * req, 
 			      TakeOverRecordPtr takeOverPtr)
 {
@@ -3019,6 +3221,14 @@ void Dbdih::execCREATE_FRAGCONF(Signal* 
     /*---------------------------------------------------------------------- */
     FragmentstorePtr fragPtr;
     getFragstore(tabPtr.p, fragId, fragPtr);
+    Uint32 gci = 0;
+    if (takeOverPtr.p->toNodeRestart)
+    {
+      ReplicaRecordPtr replicaPtr;
+      findReplica(replicaPtr, fragPtr.p, takeOverPtr.p->toStartingNode, true);
+      gci = replicaPtr.p->lcpIdStarted;
+      replicaPtr.p->lcpIdStarted = 0;
+    }
     takeOverPtr.p->toMasterStatus = TakeOverRecord::COPY_FRAG;
     BlockReference ref = calcLqhBlockRef(takeOverPtr.p->toCopyNode);
     CopyFragReq * const copyFragReq = (CopyFragReq *)&signal->theData[0];
@@ -3029,6 +3239,7 @@ void Dbdih::execCREATE_FRAGCONF(Signal* 
     copyFragReq->nodeId = takeOverPtr.p->toStartingNode;
     copyFragReq->schemaVersion = tabPtr.p->schemaVersion;
     copyFragReq->distributionKey = fragPtr.p->distributionKey;
+    copyFragReq->gci = gci;
     sendSignal(ref, GSN_COPY_FRAGREQ, signal, CopyFragReq::SignalLength, JBB);
   } else {
     ndbrequire(takeOverPtr.p->toMasterStatus == TakeOverRecord::COMMIT_CREATE);
@@ -3550,6 +3761,7 @@ void Dbdih::readingGcpLab(Signal* signal
   /*     WE ALSO COPY TO OUR OWN NODE. TO ENABLE US TO DO THIS PROPERLY WE   */
   /*     START BY CLOSING THIS FILE.                                         */
   /* ----------------------------------------------------------------------- */
+  globalData.m_restart_seq = ++SYSFILE->m_restart_seq;
   closeFile(signal, filePtr);
   filePtr.p->reqStatus = FileRecord::CLOSING_GCP;
 }//Dbdih::readingGcpLab()
@@ -4068,6 +4280,8 @@ void Dbdih::checkTakeOverInMasterStartNo
 						  Uint32 takeOverPtrI)
 {
   jam();
+  ndbout_c("checkTakeOverInMasterStartNodeFailure %x",
+	   takeOverPtrI);
   if (takeOverPtrI == RNIL) {
     jam();
     return;
@@ -4081,6 +4295,9 @@ void Dbdih::checkTakeOverInMasterStartNo
   takeOverPtr.i = takeOverPtrI;
   ptrCheckGuard(takeOverPtr, MAX_NDB_NODES, takeOverRecord);
 
+  ndbout_c("takeOverPtr.p->toMasterStatus: %x", 
+	   takeOverPtr.p->toMasterStatus);
+  
   bool ok = false;
   switch (takeOverPtr.p->toMasterStatus) {
   case TakeOverRecord::IDLE:
@@ -4189,6 +4406,13 @@ void Dbdih::checkTakeOverInMasterStartNo
     //-----------------------------------------------------------------------
     endTakeOver(takeOverPtr.i);
     break;
+
+  case TakeOverRecord::STARTING_LOCAL_FRAGMENTS:
+    ok = true;
+    jam();
+    endTakeOver(takeOverPtr.i);
+    break;
+    
     /**
      * The following are states that it should not be possible to "be" in
      */
@@ -5607,11 +5831,9 @@ Dbdih::sendMASTER_LCPCONF(Signal * signa
 #endif
   }
 
-  bool ok = false;
   MasterLCPConf::State lcpState;
   switch (c_lcpState.lcpStatus) {
   case LCP_STATUS_IDLE:
-    ok = true;
     jam();
     /*------------------------------------------------*/
     /*       LOCAL CHECKPOINT IS CURRENTLY NOT ACTIVE */
@@ -5622,7 +5844,6 @@ Dbdih::sendMASTER_LCPCONF(Signal * signa
     lcpState = MasterLCPConf::LCP_STATUS_IDLE;
     break;
   case LCP_STATUS_ACTIVE:
-    ok = true;
     jam();
     /*--------------------------------------------------*/
     /*       COPY OF RESTART INFORMATION HAS BEEN       */
@@ -5631,7 +5852,6 @@ Dbdih::sendMASTER_LCPCONF(Signal * signa
     lcpState = MasterLCPConf::LCP_STATUS_ACTIVE;
     break;
   case LCP_TAB_COMPLETED:
-    ok = true;
     jam();
     /*--------------------------------------------------------*/
     /*       ALL LCP_REPORT'S HAVE BEEN COMPLETED FOR         */
@@ -5641,7 +5861,6 @@ Dbdih::sendMASTER_LCPCONF(Signal * signa
     lcpState = MasterLCPConf::LCP_TAB_COMPLETED;
     break;
   case LCP_TAB_SAVED:
-    ok = true;
     jam();
     /*--------------------------------------------------------*/
     /*       ALL LCP_REPORT'S HAVE BEEN COMPLETED FOR         */
@@ -5665,15 +5884,15 @@ Dbdih::sendMASTER_LCPCONF(Signal * signa
     break;
   case LCP_COPY_GCI:
   case LCP_INIT_TABLES:
-    ok = true;
     /**
      * These two states are handled by if statements above
      */
     ndbrequire(false);
     lcpState= MasterLCPConf::LCP_STATUS_IDLE; // remove warning
     break;
+  default:
+    ndbrequire(false);
   }//switch
-  ndbrequire(ok);
 
   Uint32 failedNodeId = c_lcpState.m_MASTER_LCPREQ_FailedNodeId;
   MasterLCPConf * const conf = (MasterLCPConf *)&signal->theData[0];
@@ -6271,96 +6490,146 @@ void Dbdih::execDIRELEASEREQ(Signal* sig
   3.7.1   A D D   T A B L E   M A I N L Y
   ***************************************
   */
-void Dbdih::execCREATE_FRAGMENTATION_REQ(Signal * signal){
+
+static inline void inc_node_or_group(Uint32 &node, Uint32 max_node)
+{
+  Uint32 next = node + 1;
+  node = (next == max_node ? 0 : next);
+}
+
+/*
+  Spread fragments in backwards compatible mode
+*/
+static void set_default_node_groups(Signal *signal, Uint32 noFrags)
+{
+  Uint16 *node_group_array = (Uint16*)&signal->theData[25];
+  Uint32 i;
+  node_group_array[0] = 0;
+  for (i = 1; i < noFrags; i++)
+    node_group_array[i] = UNDEF_NODEGROUP;
+}
+void Dbdih::execCREATE_FRAGMENTATION_REQ(Signal * signal)
+{
+  Uint16 node_group_id[MAX_NDB_PARTITIONS];
   jamEntry();
   CreateFragmentationReq * const req = 
     (CreateFragmentationReq*)signal->getDataPtr();
   
   const Uint32 senderRef = req->senderRef;
   const Uint32 senderData = req->senderData;
-  const Uint32 fragmentNode = req->fragmentNode;
-  const Uint32 fragmentType = req->fragmentationType;
-  //const Uint32 fragmentCount = req->noOfFragments;
+  Uint32 noOfFragments = req->noOfFragments;
+  const Uint32 fragType = req->fragmentationType;
   const Uint32 primaryTableId = req->primaryTableId;
 
   Uint32 err = 0;
   
   do {
-    Uint32 noOfFragments = 0;
-    Uint32 noOfReplicas = cnoReplicas;
-    switch(fragmentType){
-    case DictTabInfo::AllNodesSmallTable:
-      jam();
-      noOfFragments = csystemnodes;
-      break;
-    case DictTabInfo::AllNodesMediumTable:
-      jam();
-      noOfFragments = 2 * csystemnodes;
-      break;
-    case DictTabInfo::AllNodesLargeTable:
-      jam();
-      noOfFragments = 4 * csystemnodes;
-      break;
-    case DictTabInfo::SingleFragment:
-      jam();
-      noOfFragments = 1;
-      break;
-#if 0
-    case DictTabInfo::SpecifiedFragmentCount:
-      noOfFragments = (fragmentCount == 0 ? 1 : (fragmentCount + 1)/ 2);
-      break;
-#endif
-    default:
-      jam();
-      err = CreateFragmentationRef::InvalidFragmentationType;
-      break;
-    }
-    if(err)
-      break;
-   
     NodeGroupRecordPtr NGPtr;
     TabRecordPtr primTabPtr;
+    Uint32 count = 2;
+    Uint16 noOfReplicas = cnoReplicas;
+    Uint16 *fragments = (Uint16*)(signal->theData+25);
     if (primaryTableId == RNIL) {
-      if(fragmentNode == 0){
-        jam();
-        NGPtr.i = 0; 
-	if(noOfFragments < csystemnodes)
-	{
-	  NGPtr.i = c_nextNodeGroup; 
-	  c_nextNodeGroup = (NGPtr.i + 1 == cnoOfNodeGroups ? 0 : NGPtr.i + 1);
-	}
-      } else if(! (fragmentNode < MAX_NDB_NODES)) {
-        jam();
-        err = CreateFragmentationRef::InvalidNodeId;
-      } else {
-        jam();
-        const Uint32 stat = Sysfile::getNodeStatus(fragmentNode,
-                                                   SYSFILE->nodeStatus);
-        switch (stat) {
-        case Sysfile::NS_Active:
-        case Sysfile::NS_ActiveMissed_1:
-        case Sysfile::NS_ActiveMissed_2:
-        case Sysfile::NS_TakeOver:
+      jam();
+      switch ((DictTabInfo::FragmentType)fragType)
+      {
+        /*
+          Backward compatability and for all places in code not changed.
+        */
+        case DictTabInfo::AllNodesSmallTable:
+          jam();
+          noOfFragments = csystemnodes;
+          set_default_node_groups(signal, noOfFragments);
+          break;
+        case DictTabInfo::AllNodesMediumTable:
+          jam();
+          noOfFragments = 2 * csystemnodes;
+          set_default_node_groups(signal, noOfFragments);
+          break;
+        case DictTabInfo::AllNodesLargeTable:
           jam();
+          noOfFragments = 4 * csystemnodes;
+          set_default_node_groups(signal, noOfFragments);
           break;
-        case Sysfile::NS_NotActive_NotTakenOver:
+        case DictTabInfo::SingleFragment:
           jam();
+          noOfFragments = 1;
+          set_default_node_groups(signal, noOfFragments);
           break;
-        case Sysfile::NS_HotSpare:
+        case DictTabInfo::DistrKeyHash:
           jam();
-        case Sysfile::NS_NotDefined:
+        case DictTabInfo::DistrKeyLin:
           jam();
+          if (noOfFragments == 0)
+          {
+            jam();
+            noOfFragments = csystemnodes;
+            set_default_node_groups(signal, noOfFragments);
+          }
+          break;
         default:
           jam();
-          err = CreateFragmentationRef::InvalidNodeType;
+          if (noOfFragments == 0)
+          {
+            jam();
+            err = CreateFragmentationRef::InvalidFragmentationType;
+          }
           break;
+      }
+      if (err)
+        break;
+      /*
+        When we come here the the exact partition is specified
+        and there is an array of node groups sent along as well.
+      */
+      memcpy(&node_group_id[0], &signal->theData[25], 2 * noOfFragments);
+      Uint16 next_replica_node[MAX_NDB_NODES];
+      memset(next_replica_node,0,sizeof(next_replica_node));
+      Uint32 default_node_group= c_nextNodeGroup;
+      for(Uint32 fragNo = 0; fragNo < noOfFragments; fragNo++)
+      {
+        jam();
+        NGPtr.i = node_group_id[fragNo];
+        if (NGPtr.i == UNDEF_NODEGROUP)
+        {
+          jam();
+	  NGPtr.i = default_node_group; 
         }
-        if(err)
+        if (NGPtr.i > cnoOfNodeGroups)
+        {
+          jam();
+          err = CreateFragmentationRef::InvalidNodeGroup;
           break;
-        NGPtr.i = Sysfile::getNodeGroup(fragmentNode,
-                                        SYSFILE->nodeGroups);
+        }
+        ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
+        const Uint32 max = NGPtr.p->nodeCount;
+	
+	Uint32 tmp= next_replica_node[NGPtr.i];
+        for(Uint32 replicaNo = 0; replicaNo < noOfReplicas; replicaNo++)
+        {
+          jam();
+          const Uint16 nodeId = NGPtr.p->nodesInGroup[tmp];
+          fragments[count++]= nodeId;
+          inc_node_or_group(tmp, max);
+        }
+        inc_node_or_group(tmp, max);
+	next_replica_node[NGPtr.i]= tmp;
+	
+        /**
+         * Next node group for next fragment
+         */
+        inc_node_or_group(default_node_group, cnoOfNodeGroups);
+      }
+      if (err)
+      {
+        jam();
         break;
       }
+      else
+      {
+        jam();
+        c_nextNodeGroup = default_node_group;
+      }
     } else {
       if (primaryTableId >= ctabFileSize) {
         jam();
@@ -6374,49 +6643,14 @@ void Dbdih::execCREATE_FRAGMENTATION_REQ
         err = CreateFragmentationRef::InvalidPrimaryTable;
         break;
       }
-      if (noOfFragments != primTabPtr.p->totalfragments) {
-        jam();
-        err = CreateFragmentationRef::InvalidFragmentationType;
-        break;
-      }
-    }
-    
-    Uint32 count = 2;
-    Uint16 *fragments = (Uint16*)(signal->theData+25);
-    if (primaryTableId == RNIL) {
-      jam();
-      Uint8 next_replica_node[MAX_NDB_NODES];
-      memset(next_replica_node,0,sizeof(next_replica_node));
-      for(Uint32 fragNo = 0; fragNo<noOfFragments; fragNo++){
-        jam();
-        ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);      
-        const Uint32 max = NGPtr.p->nodeCount;
-	
-	Uint32 tmp= next_replica_node[NGPtr.i];
-        for(Uint32 replicaNo = 0; replicaNo<noOfReplicas; replicaNo++)
-        {
-          jam();
-          const Uint32 nodeId = NGPtr.p->nodesInGroup[tmp++];
-          fragments[count++] = nodeId;
-          tmp = (tmp >= max ? 0 : tmp);
-        }
-	tmp++;
-	next_replica_node[NGPtr.i]= (tmp >= max ? 0 : tmp);
-	
-        /**
-         * Next node group for next fragment
-         */
-        NGPtr.i++;
-        NGPtr.i = (NGPtr.i == cnoOfNodeGroups ? 0 : NGPtr.i);
-      }
-    } else {
+      noOfFragments= primTabPtr.p->totalfragments;
       for (Uint32 fragNo = 0;
-           fragNo < primTabPtr.p->totalfragments; fragNo++) {
+           fragNo < noOfFragments; fragNo++) {
         jam();
         FragmentstorePtr fragPtr;
         ReplicaRecordPtr replicaPtr;
         getFragstore(primTabPtr.p, fragNo, fragPtr);
-        fragments[count++] = fragPtr.p->preferredPrimary;
+        fragments[count++]= fragPtr.p->preferredPrimary;
         for (replicaPtr.i = fragPtr.p->storedReplicas;
              replicaPtr.i != RNIL;
              replicaPtr.i = replicaPtr.p->nextReplica) {
@@ -6424,9 +6658,9 @@ void Dbdih::execCREATE_FRAGMENTATION_REQ
           ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
           if (replicaPtr.p->procNode != fragPtr.p->preferredPrimary) {
             jam();
-            fragments[count++] = replicaPtr.p->procNode;
-          }//if
-        }//for
+            fragments[count++]= replicaPtr.p->procNode;
+          }
+        }
         for (replicaPtr.i = fragPtr.p->oldStoredReplicas;
              replicaPtr.i != RNIL;
              replicaPtr.i = replicaPtr.p->nextReplica) {
@@ -6434,25 +6668,26 @@ void Dbdih::execCREATE_FRAGMENTATION_REQ
           ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
           if (replicaPtr.p->procNode != fragPtr.p->preferredPrimary) {
             jam();
-            fragments[count++] = replicaPtr.p->procNode;
-          }//if
-        }//for
+            fragments[count++]= replicaPtr.p->procNode;
+          }
+        }
       }
     }
-    ndbrequire(count == (2 + noOfReplicas * noOfFragments)); 
+    ndbrequire(count == (2U + noOfReplicas * noOfFragments)); 
     
     CreateFragmentationConf * const conf = 
       (CreateFragmentationConf*)signal->getDataPtrSend();
     conf->senderRef = reference();
     conf->senderData = senderData;
-    conf->noOfReplicas = noOfReplicas;
-    conf->noOfFragments = noOfFragments;
+    conf->noOfReplicas = (Uint32)noOfReplicas;
+    conf->noOfFragments = (Uint32)noOfFragments;
 
-    fragments[0] = noOfReplicas;
-    fragments[1] = noOfFragments;
+    fragments[0]= noOfReplicas;
+    fragments[1]= noOfFragments;
     
     if(senderRef != 0)
     {
+      jam();
       LinearSectionPtr ptr[3];
       ptr[0].p = (Uint32*)&fragments[0];
       ptr[0].sz = (count + 1) / 2;
@@ -6464,33 +6699,17 @@ void Dbdih::execCREATE_FRAGMENTATION_REQ
 		 ptr,
 		 1);
     }
-    else
-    {
-      // Execute direct
-      signal->theData[0] = 0;
-    }
+    // Always ACK/NACK (here ACK)
+    signal->theData[0] = 0;
     return;
   } while(false);
-
-  if(senderRef != 0)
-  {
-    CreateFragmentationRef * const ref = 
-      (CreateFragmentationRef*)signal->getDataPtrSend();
-    ref->senderRef = reference();
-    ref->senderData = senderData;
-    ref->errorCode = err;
-    sendSignal(senderRef, GSN_CREATE_FRAGMENTATION_REF, signal, 
-	       CreateFragmentationRef::SignalLength, JBB);
-  }
-  else
-  {
-    // Execute direct
-    signal->theData[0] = err;
-  }
+  // Always ACK/NACK (here NACK)
+  signal->theData[0] = err;
 }
 
 void Dbdih::execDIADDTABREQ(Signal* signal) 
 {
+  Uint32 fragType;
   jamEntry();
 
   DiAddTabReq * const req = (DiAddTabReq*)signal->getDataPtr();
@@ -6515,6 +6734,7 @@ void Dbdih::execDIADDTABREQ(Signal* sign
   ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
   tabPtr.p->connectrec = connectPtr.i;
   tabPtr.p->tableType = req->tableType;
+  fragType= req->fragType;
   tabPtr.p->schemaVersion = req->schemaVersion;
   tabPtr.p->primaryTableId = req->primaryTableId;
 
@@ -6551,9 +6771,33 @@ void Dbdih::execDIADDTABREQ(Signal* sign
   /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
   tabPtr.p->tabStatus = TabRecord::TS_CREATING;
   tabPtr.p->storedTable = req->storedTable;
-  tabPtr.p->method = TabRecord::HASH;
   tabPtr.p->kvalue = req->kValue;
 
+  switch ((DictTabInfo::FragmentType)fragType)
+  {
+    case DictTabInfo::AllNodesSmallTable:
+    case DictTabInfo::AllNodesMediumTable:
+    case DictTabInfo::AllNodesLargeTable:
+    case DictTabInfo::SingleFragment:
+      jam();
+    case DictTabInfo::DistrKeyLin:
+      jam();
+      tabPtr.p->method= TabRecord::LINEAR_HASH;
+      break;
+    case DictTabInfo::DistrKeyHash:
+    case DictTabInfo::DistrKeyUniqueHashIndex:
+    case DictTabInfo::DistrKeyOrderedIndex:
+      jam();
+      tabPtr.p->method= TabRecord::NORMAL_HASH;
+      break;
+    case DictTabInfo::UserDefined:
+      jam();
+      tabPtr.p->method= TabRecord::USER_DEFINED;
+      break;
+    default:
+      ndbrequire(false);
+  }
+
   union {
     Uint16 fragments[2 + MAX_FRAG_PER_NODE*MAX_REPLICAS*MAX_NDB_NODES];
     Uint32 align;
@@ -6603,6 +6847,8 @@ void Dbdih::execDIADDTABREQ(Signal* sign
     Uint32 activeIndex = 0;
     getFragstore(tabPtr.p, fragId, fragPtr);
     fragPtr.p->preferredPrimary = fragments[index];
+    fragPtr.p->m_log_part_id = c_nextLogPart++;
+    
     for (Uint32 i = 0; i<noReplicas; i++) {
       const Uint32 nodeId = fragments[index++];
       ReplicaRecordPtr replicaPtr;
@@ -6647,9 +6893,9 @@ Dbdih::sendAddFragreq(Signal* signal, Co
   jam();
   const Uint32 fragCount = tabPtr.p->totalfragments;
   ReplicaRecordPtr replicaPtr; replicaPtr.i = RNIL;
+  FragmentstorePtr fragPtr;
   for(; fragId<fragCount; fragId++){
     jam();
-    FragmentstorePtr fragPtr;
     getFragstore(tabPtr.p, fragId, fragPtr);    
     
     replicaPtr.i = fragPtr.p->storedReplicas;
@@ -6707,6 +6953,7 @@ Dbdih::sendAddFragreq(Signal* signal, Co
     req->nodeId = getOwnNodeId();
     req->totalFragments = fragCount;
     req->startGci = SYSFILE->newestRestorableGCI;
+    req->logPartId = fragPtr.p->m_log_part_id;
     sendSignal(DBDICT_REF, GSN_ADD_FRAGREQ, signal, 
 	       AddFragReq::SignalLength, JBB);
     return;
@@ -6988,17 +7235,40 @@ void Dbdih::execDIGETNODESREQ(Signal* si
   tabPtr.i = req->tableId;
   Uint32 hashValue = req->hashValue;
   Uint32 ttabFileSize = ctabFileSize;
+  Uint32 fragId;
+  DiGetNodesConf * const conf = (DiGetNodesConf *)&signal->theData[0];
   TabRecord* regTabDesc = tabRecord;
   jamEntry();
   ptrCheckGuard(tabPtr, ttabFileSize, regTabDesc);
-  Uint32 fragId = hashValue & tabPtr.p->mask;
-  ndbrequire(tabPtr.p->tabStatus == TabRecord::TS_ACTIVE);
-  if (fragId < tabPtr.p->hashpointer) {
+  if (tabPtr.p->method == TabRecord::LINEAR_HASH)
+  {
     jam();
-    fragId = hashValue & ((tabPtr.p->mask << 1) + 1);
-  }//if
+    fragId = hashValue & tabPtr.p->mask;
+    ndbrequire(tabPtr.p->tabStatus == TabRecord::TS_ACTIVE);
+    if (fragId < tabPtr.p->hashpointer) {
+      jam();
+      fragId = hashValue & ((tabPtr.p->mask << 1) + 1);
+    }//if
+  }
+  else if (tabPtr.p->method == TabRecord::NORMAL_HASH)
+  {
+    jam();
+    fragId= hashValue % tabPtr.p->totalfragments;
+  }
+  else
+  {
+    jam();
+    ndbassert(tabPtr.p->method == TabRecord::USER_DEFINED);
+    fragId= hashValue;
+    if (fragId >= tabPtr.p->totalfragments)
+    {
+      jam();
+      conf->zero= 1; //Indicate error;
+      signal->theData[1]= ZUNDEFINED_FRAGMENT_ERROR;
+      return;
+    }
+  }
   getFragstore(tabPtr.p, fragId, fragPtr);
-  DiGetNodesConf * const conf = (DiGetNodesConf *)&signal->theData[0];
   Uint32 nodeCount = extractNodeInfo(fragPtr.p, conf->nodes);
   Uint32 sig2 = (nodeCount - 1) + 
     (fragPtr.p->distributionKey << 16);
@@ -7165,39 +7435,66 @@ void Dbdih::execDIVERIFYREQ(Signal* sign
 
 void Dbdih::execDI_FCOUNTREQ(Signal* signal) 
 {
+  DihFragCountReq * const req = (DihFragCountReq*)signal->getDataPtr();
   ConnectRecordPtr connectPtr;
   TabRecordPtr tabPtr;
+  const BlockReference senderRef = signal->senderBlockRef();
+  const Uint32 senderData = req->m_senderData;
   jamEntry();
-  connectPtr.i = signal->theData[0];
-  tabPtr.i = signal->theData[1];
+  connectPtr.i = req->m_connectionData;
+  tabPtr.i = req->m_tableRef;
   ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
 
-  ndbrequire(tabPtr.p->tabStatus == TabRecord::TS_ACTIVE);
+  if (tabPtr.p->tabStatus != TabRecord::TS_ACTIVE)
+  {
+    DihFragCountRef* ref = (DihFragCountRef*)signal->getDataPtrSend();
+    //connectPtr.i == RNIL -> question without connect record
+    if(connectPtr.i == RNIL)
+      ref->m_connectionData = RNIL;
+    else
+      ref->m_connectionData = connectPtr.p->userpointer;
+    ref->m_tableRef = tabPtr.i;
+    ref->m_senderData = senderData;
+    ref->m_error = DihFragCountRef::ErroneousTableState;
+    ref->m_tableStatus = tabPtr.p->tabStatus;
+    sendSignal(senderRef, GSN_DI_FCOUNTREF, signal, 
+               DihFragCountRef::SignalLength, JBB);
+    return;
+  }
 
   if(connectPtr.i != RNIL){
     ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
     if (connectPtr.p->connectState == ConnectRecord::INUSE) {
       jam();
-      signal->theData[0] = connectPtr.p->userpointer;
-      signal->theData[1] = tabPtr.p->totalfragments;
-      sendSignal(connectPtr.p->userblockref, GSN_DI_FCOUNTCONF, signal,2, JBB);
-      return;
-    }//if
-    signal->theData[0] = connectPtr.p->userpointer;
-    signal->theData[1] = ZERRONOUSSTATE;
-    sendSignal(connectPtr.p->userblockref, GSN_DI_FCOUNTREF, signal, 2, JBB);
+      DihFragCountConf* conf = (DihFragCountConf*)signal->getDataPtrSend();
+      conf->m_connectionData = connectPtr.p->userpointer;
+      conf->m_tableRef = tabPtr.i;
+      conf->m_senderData = senderData;
+      conf->m_fragmentCount = tabPtr.p->totalfragments;
+      conf->m_noOfBackups = tabPtr.p->noOfBackups;
+      sendSignal(connectPtr.p->userblockref, GSN_DI_FCOUNTCONF, signal,
+                 DihFragCountConf::SignalLength, JBB);
+      return;
+    }//if
+    DihFragCountRef* ref = (DihFragCountRef*)signal->getDataPtrSend();
+    ref->m_connectionData = connectPtr.p->userpointer;
+    ref->m_tableRef = tabPtr.i;
+    ref->m_senderData = senderData;
+    ref->m_error = DihFragCountRef::ErroneousTableState;
+    ref->m_tableStatus = tabPtr.p->tabStatus;
+    sendSignal(connectPtr.p->userblockref, GSN_DI_FCOUNTREF, signal, 
+               DihFragCountRef::SignalLength, JBB);
     return;
   }//if
-
+  DihFragCountConf* conf = (DihFragCountConf*)signal->getDataPtrSend();
   //connectPtr.i == RNIL -> question without connect record
-  const Uint32 senderData = signal->theData[2];
-  const BlockReference senderRef = signal->senderBlockRef();
-  signal->theData[0] = RNIL;
-  signal->theData[1] = tabPtr.p->totalfragments;
-  signal->theData[2] = tabPtr.i;
-  signal->theData[3] = senderData;
-  signal->theData[4] = tabPtr.p->noOfBackups;
-  sendSignal(senderRef, GSN_DI_FCOUNTCONF, signal, 5, JBB);
+  conf->m_connectionData = RNIL;
+  conf->m_tableRef = tabPtr.i;
+  conf->m_senderData = senderData;
+  conf->m_fragmentCount = tabPtr.p->totalfragments;
+  conf->m_noOfBackups = tabPtr.p->noOfBackups;
+  sendSignal(senderRef, GSN_DI_FCOUNTCONF, signal, 
+             DihFragCountConf::SignalLength, JBB);
 }//Dbdih::execDI_FCOUNTREQ()
 
 void Dbdih::execDIGETPRIMREQ(Signal* signal) 
@@ -7974,9 +8271,12 @@ void Dbdih::writingCopyGciLab(Signal* si
     
     SubGcpCompleteRep * const rep = (SubGcpCompleteRep*)signal->getDataPtr();
     rep->gci = coldgcp;
-    rep->senderData = 0;
     sendSignal(SUMA_REF, GSN_SUB_GCP_COMPLETE_REP, signal, 
 	       SubGcpCompleteRep::SignalLength, JBB);
+
+    EXECUTE_DIRECT(LGMAN, GSN_SUB_GCP_COMPLETE_REP, signal, 
+		   SubGcpCompleteRep::SignalLength);
+    jamEntry();
   }
   
   jam();
@@ -8543,8 +8843,7 @@ void Dbdih::readPagesIntoTableLab(Signal
   rf.rwfTabPtr.p->hashpointer = readPageWord(&rf);
   rf.rwfTabPtr.p->kvalue = readPageWord(&rf);
   rf.rwfTabPtr.p->mask = readPageWord(&rf);
-  ndbrequire(readPageWord(&rf) == TabRecord::HASH);
-  rf.rwfTabPtr.p->method = TabRecord::HASH;
+  rf.rwfTabPtr.p->method = (TabRecord::Method)readPageWord(&rf);
   /* ---------------------------------- */
   /* Type of table, 2 = temporary table */
   /* ---------------------------------- */
@@ -8638,7 +8937,7 @@ void Dbdih::packTableIntoPagesLab(Signal
   writePageWord(&wf, tabPtr.p->hashpointer);
   writePageWord(&wf, tabPtr.p->kvalue);
   writePageWord(&wf, tabPtr.p->mask);
-  writePageWord(&wf, TabRecord::HASH);
+  writePageWord(&wf, tabPtr.p->method);
   writePageWord(&wf, tabPtr.p->storedTable);
 
   signal->theData[0] = DihContinueB::ZPACK_FRAG_INTO_PAGES;
@@ -8739,6 +9038,80 @@ void Dbdih::packFragIntoPagesLab(Signal*
 /*****************************************************************************/
 /* **********     START FRAGMENT MODULE                          *************/
 /*****************************************************************************/
+void
+Dbdih::dump_replica_info()
+{
+  TabRecordPtr tabPtr;
+  FragmentstorePtr fragPtr;
+
+  for(tabPtr.i = 0; tabPtr.i < ctabFileSize; tabPtr.i++)
+  {
+    ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
+    if (tabPtr.p->tabStatus != TabRecord::TS_ACTIVE)
+      continue;
+    
+    for(Uint32 fid = 0; fid<tabPtr.p->totalfragments; fid++)
+    {
+      getFragstore(tabPtr.p, fid, fragPtr);
+      ndbout_c("tab: %d frag: %d gci: %d\n  -- storedReplicas:", 
+	       tabPtr.i, fid, SYSFILE->newestRestorableGCI);
+      
+      Uint32 i;
+      ReplicaRecordPtr replicaPtr;
+      replicaPtr.i = fragPtr.p->storedReplicas;
+      for(; replicaPtr.i != RNIL; replicaPtr.i = replicaPtr.p->nextReplica)
+      {
+	ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
+	ndbout_c("  node: %d initialGci: %d nextLcp: %d noCrashedReplicas: %d",
+		 replicaPtr.p->procNode,
+		 replicaPtr.p->initialGci,
+		 replicaPtr.p->nextLcp,
+		 replicaPtr.p->noCrashedReplicas);
+	for(i = 0; i<MAX_LCP_STORED; i++)
+	{
+	  ndbout_c("    i: %d %s : lcpId: %d maxGci Completed: %d Started: %d",
+		   i, 
+		   (replicaPtr.p->lcpStatus[i] == ZVALID ?"VALID":"INVALID"),
+		   replicaPtr.p->lcpId[i],
+		   replicaPtr.p->maxGciCompleted[i],
+		   replicaPtr.p->maxGciStarted[i]);
+	}
+	
+	for (i = 0; i < 8; i++)
+	{
+	  ndbout_c("    crashed replica: %d replicaLastGci: %d createGci: %d",
+		   i, 
+		   replicaPtr.p->replicaLastGci[i],
+		   replicaPtr.p->createGci[i]);
+	}
+      }
+      ndbout_c("  -- oldStoredReplicas");
+      replicaPtr.i = fragPtr.p->oldStoredReplicas;
+      for(; replicaPtr.i != RNIL; replicaPtr.i = replicaPtr.p->nextReplica)
+      {
+	ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
+	for(i = 0; i<MAX_LCP_STORED; i++)
+	{
+	  ndbout_c("    i: %d %s : lcpId: %d maxGci Completed: %d Started: %d",
+		   i, 
+		   (replicaPtr.p->lcpStatus[i] == ZVALID ?"VALID":"INVALID"),
+		   replicaPtr.p->lcpId[i],
+		   replicaPtr.p->maxGciCompleted[i],
+		   replicaPtr.p->maxGciStarted[i]);
+	}
+	
+	for (i = 0; i < 8; i++)
+	{
+	  ndbout_c("    crashed replica: %d replicaLastGci: %d createGci: %d",
+		   i, 
+		   replicaPtr.p->replicaLastGci[i],
+		   replicaPtr.p->createGci[i]);
+	}
+      }
+    }
+  }
+}
+
 void Dbdih::startFragment(Signal* signal, Uint32 tableId, Uint32 fragId) 
 {
   Uint32 TloopCount = 0;
@@ -8800,6 +9173,7 @@ void Dbdih::startFragment(Signal* signal
   /*     SEARCH FOR STORED REPLICAS THAT CAN BE USED TO RESTART THE SYSTEM.  */
   /* ----------------------------------------------------------------------- */
   searchStoredReplicas(fragPtr);
+
   if (cnoOfCreateReplicas == 0) {
     /* --------------------------------------------------------------------- */
     /*   THERE WERE NO STORED REPLICAS AVAILABLE THAT CAN SERVE AS REPLICA TO*/
@@ -8812,6 +9186,10 @@ void Dbdih::startFragment(Signal* signal
     char buf[64];
     BaseString::snprintf(buf, sizeof(buf), "table: %d fragment: %d gci: %d",
 			 tableId, fragId, SYSFILE->newestRestorableGCI);
+
+    ndbout_c(buf);
+    dump_replica_info();
+    
     progError(__LINE__, NDBD_EXIT_NO_RESTORABLE_REPLICA, buf);
     ndbrequire(false);
     return;
@@ -8888,8 +9266,8 @@ void Dbdih::execSTART_RECCONF(Signal* si
     // otherwise we have a problem.
     /* --------------------------------------------------------------------- */
     jam();
-    ndbrequire(senderNodeId == c_nodeStartMaster.startNode);
-    nodeRestartStartRecConfLab(signal);
+    ndbout_c("startNextCopyFragment");
+    startNextCopyFragment(signal, findTakeOver(senderNodeId));
     return;
   } else {
     /* --------------------------------------------------------------------- */
@@ -9907,9 +10285,11 @@ Dbdih::checkLcpAllTablesDoneInLqh(){
 }
 
 void Dbdih::findReplica(ReplicaRecordPtr& replicaPtr, 
-			Fragmentstore* fragPtrP, Uint32 nodeId)
+			Fragmentstore* fragPtrP, 
+			Uint32 nodeId,
+			bool old)
 {
-  replicaPtr.i = fragPtrP->storedReplicas;
+  replicaPtr.i = old ? fragPtrP->oldStoredReplicas : fragPtrP->storedReplicas;
   while(replicaPtr.i != RNIL){
     ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
     if (replicaPtr.p->procNode == nodeId) {
@@ -10448,6 +10828,10 @@ void Dbdih::crashSystemAtGcpStop(Signal*
 	     c_copyGCIMaster.m_copyReason,
 	     c_copyGCIMaster.m_waiting);
     break;
+  case GCP_READY: // shut up lint
+  case GCP_PREPARE_SENT:
+  case GCP_COMMIT_SENT:
+    break;
   }
   
   ndbout_c("c_copyGCISlave: sender{Data, Ref} %d %x reason: %d nextWord: %d",
@@ -11162,6 +11546,7 @@ void Dbdih::initCommonData()
   cnoHotSpare = 0;
   cnoOfActiveTables = 0;
   cnoOfNodeGroups = 0;
+  c_nextNodeGroup = 0;
   cnoReplicas = 0;
   coldgcp = 0;
   coldGcpId = 0;
@@ -11181,6 +11566,7 @@ void Dbdih::initCommonData()
   c_newest_restorable_gci = 0;
   cverifyQueueCounter = 0;
   cwaitLcpSr = false;
+  c_nextLogPart = 0;
 
   nodeResetStart();
   c_nodeStartMaster.wait = ZFALSE;
@@ -11188,7 +11574,7 @@ void Dbdih::initCommonData()
   memset(&sysfileData[0], 0, sizeof(sysfileData));
 
   const ndb_mgm_configuration_iterator * p = 
-    theConfiguration.getOwnConfigIterator();
+    m_ctx.m_config.getOwnConfigIterator();
   ndbrequire(p != 0);
   
   c_lcpState.clcpDelay = 20;
@@ -11267,6 +11653,8 @@ void Dbdih::initRestartInfo() 
     SYSFILE->takeOver[i] = 0;
   }//for
   Sysfile::setInitialStartOngoing(SYSFILE->systemRestartBits);
+  srand(time(0));
+  globalData.m_restart_seq = SYSFILE->m_restart_seq = 0;
 }//Dbdih::initRestartInfo()
 
 /*--------------------------------------------------------------------*/
@@ -12017,6 +12405,8 @@ void Dbdih::readFragment(RWFragment* rf,
     jam();
     fragPtr.p->distributionKey = TdistKey;
   }//if
+
+  fragPtr.p->m_log_part_id = readPageWord(rf);
 }//Dbdih::readFragment()
 
 Uint32 Dbdih::readPageWord(RWFragment* rf) 
@@ -13110,6 +13500,7 @@ void Dbdih::writeFragment(RWFragment* wf
   writePageWord(wf, fragPtr.p->noStoredReplicas);
   writePageWord(wf, fragPtr.p->noOldStoredReplicas);
   writePageWord(wf, fragPtr.p->distributionKey);
+  writePageWord(wf, fragPtr.p->m_log_part_id);
 }//Dbdih::writeFragment()
 
 void Dbdih::writePageWord(RWFragment* wf, Uint32 dataWord)
@@ -13176,7 +13567,7 @@ void Dbdih::writeTabfile(Signal* signal,
   signal->theData[0] = filePtr.p->fileRef;
   signal->theData[1] = reference();
   signal->theData[2] = filePtr.i;
-  signal->theData[3] = ZLIST_OF_PAIRS;
+  signal->theData[3] = ZLIST_OF_PAIRS_SYNCH;
   signal->theData[4] = ZVAR_NO_WORD;
   signal->theData[5] = tab->noPages;
   for (Uint32 i = 0; i < tab->noPages; i++) {
@@ -13539,7 +13930,7 @@ Dbdih::execDUMP_STATE_ORD(Signal* signal
     if (signal->getLength() == 1)
     {
       const ndb_mgm_configuration_iterator * p = 
-	theConfiguration.getOwnConfigIterator();
+	m_ctx.m_config.getOwnConfigIterator();
       ndbrequire(p != 0);
       ndb_mgm_get_int_parameter(p, CFG_DB_GCP_INTERVAL, &cgcpDelay);
     }
@@ -14638,4 +15029,123 @@ Dbdih::NodeRecord::NodeRecord(){
   useInTransactions = false;
   copyCompleted = false;
   allowNodeStart = true;
+}
+
+// DICT lock slave
+
+void
+Dbdih::sendDictLockReq(Signal* signal, Uint32 lockType, Callback c)
+{
+  DictLockReq* req = (DictLockReq*)&signal->theData[0];
+  DictLockSlavePtr lockPtr;
+
+  c_dictLockSlavePool.seize(lockPtr);
+  ndbrequire(lockPtr.i != RNIL);
+
+  req->userPtr = lockPtr.i;
+  req->lockType = lockType;
+  req->userRef = reference();
+
+  lockPtr.p->lockPtr = RNIL;
+  lockPtr.p->lockType = lockType;
+  lockPtr.p->locked = false;
+  lockPtr.p->callback = c;
+
+  // handle rolling upgrade
+  {
+    Uint32 masterVersion = getNodeInfo(cmasterNodeId).m_version;
+
+    const unsigned int get_major = getMajor(masterVersion);
+    const unsigned int get_minor = getMinor(masterVersion);
+    const unsigned int get_build = getBuild(masterVersion);
+    ndbrequire(get_major >= 4);
+
+    if (masterVersion < NDBD_DICT_LOCK_VERSION_5 ||
+        masterVersion < NDBD_DICT_LOCK_VERSION_5_1 &&
+          get_major == 5 && get_minor == 1 ||
+        ERROR_INSERTED(7176)) {
+      jam();
+
+      infoEvent("DIH: detect upgrade: master node %u old version %u.%u.%u",
+        (unsigned int)cmasterNodeId, get_major, get_minor, get_build);
+
+      DictLockConf* conf = (DictLockConf*)&signal->theData[0];
+      conf->userPtr = lockPtr.i;
+      conf->lockType = lockType;
+      conf->lockPtr = ZNIL;
+
+      sendSignal(reference(), GSN_DICT_LOCK_CONF, signal,
+          DictLockConf::SignalLength, JBB);
+      return;
+    }
+  }
+
+  BlockReference dictMasterRef = calcDictBlockRef(cmasterNodeId);
+  sendSignal(dictMasterRef, GSN_DICT_LOCK_REQ, signal,
+      DictLockReq::SignalLength, JBB);
+}
+
+void
+Dbdih::execDICT_LOCK_CONF(Signal* signal)
+{
+  jamEntry();
+  recvDictLockConf(signal);
+}
+
+void
+Dbdih::execDICT_LOCK_REF(Signal* signal)
+{
+  jamEntry();
+  ndbrequire(false);
+}
+
+void
+Dbdih::recvDictLockConf(Signal* signal)
+{
+  const DictLockConf* conf = (const DictLockConf*)&signal->theData[0];
+
+  DictLockSlavePtr lockPtr;
+  c_dictLockSlavePool.getPtr(lockPtr, conf->userPtr);
+  
+  lockPtr.p->lockPtr = conf->lockPtr;
+  ndbrequire(lockPtr.p->lockType == conf->lockType);
+  ndbrequire(lockPtr.p->locked == false);
+  lockPtr.p->locked = true;
+
+  lockPtr.p->callback.m_callbackData = lockPtr.i;
+  execute(signal, lockPtr.p->callback, 0);
+}
+
+void
+Dbdih::sendDictUnlockOrd(Signal* signal, Uint32 lockSlavePtrI)
+{
+  DictUnlockOrd* ord = (DictUnlockOrd*)&signal->theData[0];
+
+  DictLockSlavePtr lockPtr;
+  c_dictLockSlavePool.getPtr(lockPtr, lockSlavePtrI);
+
+  ord->lockPtr = lockPtr.p->lockPtr;
+  ord->lockType = lockPtr.p->lockType;
+
+  c_dictLockSlavePool.release(lockPtr);
+
+  // handle rolling upgrade
+  {
+    Uint32 masterVersion = getNodeInfo(cmasterNodeId).m_version;
+
+    const unsigned int get_major = getMajor(masterVersion);
+    const unsigned int get_minor = getMinor(masterVersion);
+    ndbrequire(get_major >= 4);
+
+    if (masterVersion < NDBD_DICT_LOCK_VERSION_5 ||
+        masterVersion < NDBD_DICT_LOCK_VERSION_5_1 &&
+          get_major == 5 && get_minor == 1 ||
+        ERROR_INSERTED(7176)) {
+      return;
+    }
+  }
+
+  BlockReference dictMasterRef = calcDictBlockRef(cmasterNodeId);
+  sendSignal(dictMasterRef, GSN_DICT_UNLOCK_ORD, signal,
+      DictUnlockOrd::SignalLength, JBB);
 }

--- 1.37/mysql-test/r/insert_select.result	2006-01-23 06:16:57 -05:00
+++ 1.38/mysql-test/r/insert_select.result	2006-06-25 09:58:05 -04:00
@@ -686,3 +686,7 @@ ERROR 42S22: Unknown column 'z' in 'fiel
 insert into t1(x,y) select x,z from t2 on duplicate key update x=values(t2.x);
 ERROR 42S22: Unknown column 't2.x' in 'field list'
 drop table t1,t2;
+CREATE TABLE t1 (a int PRIMARY KEY);
+INSERT INTO t1 values (1), (2);
+INSERT INTO t1 SELECT a + 2 FROM t1 LIMIT 1;
+DROP TABLE t1;

--- 1.45/mysql-test/t/func_time.test	2006-06-18 06:20:26 -04:00
+++ 1.46/mysql-test/t/func_time.test	2006-06-25 09:58:05 -04:00
@@ -392,8 +392,10 @@ drop table t1;
 # Bug #16546
 # 
 
-select now() - now() + 0, curtime() - curtime() + 0, 
-       sec_to_time(1) + 0, from_unixtime(1) + 0;
+create table t1 select now() - now(), curtime() - curtime(), 
+                       sec_to_time(1) + 0, from_unixtime(1) + 0;
+show create table t1;
+drop table t1;
 
 --echo End of 4.1 tests
 

--- 1.104/mysql-test/t/select.test	2006-06-18 06:20:26 -04:00
+++ 1.105/mysql-test/t/select.test	2006-06-25 09:58:05 -04:00
@@ -2285,6 +2285,25 @@ EXPLAIN SELECT * FROM t1 FORCE INDEX (a)
 
 DROP TABLE t1;
 
+#
+# Bug #18759 "Incorrect string to numeric conversion"
+#
+# This test is here so that the behavior will not be changed to 4.1
+# and not to 5.0 either. In 4.1 and 5.0 sending an integer as a string
+# will be converted internally to real (double) value and it is not
+# as accurate as bigint (longlong) for integers. Thus the results may
+# vary. In 5.1 internally it is decimal, which is a string type and
+# will be more accurate. Due to rather big changes needed to fix this
+# in 4.1 or 5.0 it is not desired to do it in the stable versions.
+#
+# This test is here only to make sure that behavior is not changed in
+# 4.1 and 5.0
+#
+CREATE TABLE t1 (i BIGINT UNSIGNED NOT NULL);
+INSERT INTO t1 VALUES (10);
+SELECT i='1e+01',i=1e+01, i in (1e+01,1e+01), i in ('1e+01','1e+01') FROM t1;
+DROP TABLE t1;
+
 # End of 4.1 tests
 
 #

--- 1.81/mysql-test/r/myisam.result	2006-06-20 07:38:56 -04:00
+++ 1.82/mysql-test/r/myisam.result	2006-06-25 09:58:05 -04:00
@@ -747,6 +747,19 @@ select count(id1) from t1 where id2 = 10
 count(id1)
 5
 drop table t1;
+CREATE TABLE t1(a TINYINT, KEY(a)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES(1);
+SELECT MAX(a) FROM t1 IGNORE INDEX(a);
+MAX(a)
+1
+ALTER TABLE t1 DISABLE KEYS;
+SELECT MAX(a) FROM t1;
+MAX(a)
+1
+SELECT MAX(a) FROM t1 IGNORE INDEX(a);
+MAX(a)
+1
+DROP TABLE t1;
 CREATE TABLE t1(a CHAR(9), b VARCHAR(7)) ENGINE=MyISAM;
 INSERT INTO t1(a) VALUES('xxxxxxxxx'),('xxxxxxxxx');
 UPDATE t1 AS ta1,t1 AS ta2 SET ta1.b='aaaaaa',ta2.b='bbbbbb';

--- 1.58/mysql-test/t/myisam.test	2006-06-20 07:45:45 -04:00
+++ 1.59/mysql-test/t/myisam.test	2006-06-25 09:58:05 -04:00
@@ -698,6 +698,18 @@ select count(id1) from t1 where id2 = 10
 drop table t1;
 
 #
+# BUG##20357 - Got error 124 from storage engine using MIN and MAX functions
+#              in queries
+#
+CREATE TABLE t1(a TINYINT, KEY(a)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES(1);
+SELECT MAX(a) FROM t1 IGNORE INDEX(a);
+ALTER TABLE t1 DISABLE KEYS;
+SELECT MAX(a) FROM t1;
+SELECT MAX(a) FROM t1 IGNORE INDEX(a);
+DROP TABLE t1;
+
+#
 # BUG#18036 - update of table joined to self reports table as crashed
 #
 CREATE TABLE t1(a CHAR(9), b VARCHAR(7)) ENGINE=MyISAM;

--- 1.12/mysql-test/valgrind.supp	2006-06-23 03:46:13 -04:00
+++ 1.13/mysql-test/valgrind.supp	2006-06-25 09:58:04 -04:00
@@ -249,6 +249,18 @@
 }
 
 #
+# Warning from my_thread_init becasue mysqld dies before kill thread exists
+#
+
+{
+   my_thread_init kill thread memory loss second
+   Memcheck:Leak
+   fun:calloc
+   fun:my_thread_init
+   fun:kill_server_thread
+}
+
+#
 # Leaks reported in _dl_* internal functions on Linux amd64 / glibc2.3.2.
 #
 

--- 1.30.20.1/ndb/src/ndbapi/ndberror.c	2006-06-20 13:29:08 -04:00
+++ 1.65/storage/ndb/src/ndbapi/ndberror.c	2006-06-25 09:58:07 -04:00
@@ -16,11 +16,13 @@
 
 
 #include <ndb_global.h>
+#include <my_base.h>
 #include <ndberror.h>
 #include <m_string.h>
 
 typedef struct ErrorBundle {
   int code;
+  int mysql_code;
   ndberror_classification classification;
   const char * message;
 } ErrorBundle;
@@ -57,6 +59,11 @@ typedef struct ErrorBundle {
 
 #define OE ndberror_cl_schema_object_already_exists
 
+#define IT ndberror_cl_internal_temporary
+
+/* default mysql error code for unmapped codes */
+#define DMEC -1
+
 static const char* empty_string = "";
 
 /*
@@ -71,6 +78,10 @@ static const char* empty_string = "";
  *  900 - TUX
  * 1200 - LQH
  * 1300 - BACKUP
+ * 1400 - SUMA
+ * 1500 - LGMAN
+ * 1600 - TSMAN
+ * 1700 - QMGR
  * 4000 - API
  * 4100 - ""
  * 4200 - ""
@@ -88,441 +99,516 @@ ErrorBundle ErrorCodes[] = {
   /**
    * No error
    */
-  { 0,    NE, "No error" },
+  { 0,    0, NE, "No error" },
   
   /**
    * NoDataFound
    */
-  { 626,  ND, "Tuple did not exist" },
+  { 626,  HA_ERR_KEY_NOT_FOUND, ND, "Tuple did not exist" },
 
   /**
    * ConstraintViolation 
    */
-  { 630,  CV, "Tuple already existed when attempting to insert" },
-  { 840,  CV, "Trying to set a NOT NULL attribute to NULL" },
-  { 893,  CV, "Constraint violation e.g. duplicate value in unique index" },
+  { 630,  HA_ERR_FOUND_DUPP_KEY, CV, "Tuple already existed when attempting to insert" },
+  { 839,  DMEC, CV, "Illegal null attribute" },
+  { 840,  DMEC, CV, "Trying to set a NOT NULL attribute to NULL" },
+  { 893,  HA_ERR_FOUND_DUPP_KEY, CV, "Constraint violation e.g. duplicate value in unique
index" },
 
   /**
    * Node recovery errors
    */
-  {  286, NR, "Node failure caused abort of transaction" }, 
-  {  250, NR, "Node where lock was held crashed, restart scan transaction" },
-  {  499, NR, "Scan take over error, restart scan transaction" },  
-  { 1204, NR, "Temporary failure, distribution changed" },
-  { 4002, NR, "Send to NDB failed" },
-  { 4010, NR, "Node failure caused abort of transaction" }, 
-  { 4025, NR, "Node failure caused abort of transaction" }, 
-  { 4027, NR, "Node failure caused abort of transaction" },
-  { 4028, NR, "Node failure caused abort of transaction" },
-  { 4029, NR, "Node failure caused abort of transaction" },
-  { 4031, NR, "Node failure caused abort of transaction" },
-  { 4033, NR, "Send to NDB failed" },
-  { 4115, NR, 
+  {  286, DMEC, NR, "Node failure caused abort of transaction" }, 
+  {  250, DMEC, NR, "Node where lock was held crashed, restart scan transaction" },
+  {  499, DMEC, NR, "Scan take over error, restart scan transaction" },  
+  { 1204, DMEC, NR, "Temporary failure, distribution changed" },
+  { 4002, DMEC, NR, "Send to NDB failed" },
+  { 4010, DMEC, NR, "Node failure caused abort of transaction" }, 
+  { 4025, DMEC, NR, "Node failure caused abort of transaction" }, 
+  { 4027, DMEC, NR, "Node failure caused abort of transaction" },
+  { 4028, DMEC, NR, "Node failure caused abort of transaction" },
+  { 4029, DMEC, NR, "Node failure caused abort of transaction" },
+  { 4031, DMEC, NR, "Node failure caused abort of transaction" },
+  { 4033, DMEC, NR, "Send to NDB failed" },
+  { 4115, DMEC, NR, 
     "Transaction was committed but all read information was not "
     "received due to node crash" },
-  { 4119, NR, "Simple/dirty read failed due to node failure" },
+  { 4119, DMEC, NR, "Simple/dirty read failed due to node failure" },
   
   /**
    * Node shutdown
    */
-  {  280, NS, "Transaction aborted due to node shutdown" },
+  {  280, DMEC, NS, "Transaction aborted due to node shutdown" },
   /* This scan trans had an active fragment scan in a LQH which have crashed */
-  {  270, NS, "Transaction aborted due to node shutdown" }, 
-  { 1223, NS, "Read operation aborted due to node shutdown" },
-  { 4023, NS, "Transaction aborted due to node shutdown" },
-  { 4030, NS, "Transaction aborted due to node shutdown" },
-  { 4034, NS, "Transaction aborted due to node shutdown" },
+  {  270, DMEC, NS, "Transaction aborted due to node shutdown" }, 
+  { 1223, DMEC, NS, "Read operation aborted due to node shutdown" },
+  { 4023, DMEC, NS, "Transaction aborted due to node shutdown" },
+  { 4030, DMEC, NS, "Transaction aborted due to node shutdown" },
+  { 4034, DMEC, NS, "Transaction aborted due to node shutdown" },
 
 
   
   /**
    * Unknown result
    */
-  { 4008, UR, "Receive from NDB failed" },
-  { 4009, UR, "Cluster Failure" },
-  { 4012, UR, 
+  { 4008, DMEC, UR, "Receive from NDB failed" },
+  { 4009, DMEC, UR, "Cluster Failure" },
+  { 4012, DMEC, UR, 
     "Request ndbd time-out, maybe due to high load or communication problems"}, 
-  { 4024, UR, 
+  { 4024, DMEC, UR, 
     "Time-out, most likely caused by simple read or cluster failure" }, 
   
   /**
    * TemporaryResourceError
    */
-  { 217,  TR, "217" },
-  { 218,  TR, "218" },
-  { 219,  TR, "219" },
-  { 233,  TR,
+  { 217,  DMEC, TR, "217" },
+  { 218,  DMEC, TR, "218" },
+  { 219,  DMEC, TR, "219" },
+  { 233,  DMEC, TR,
     "Out of operation records in transaction coordinator (increase
MaxNoOfConcurrentOperations)" },
-  { 275,  TR, "275" },
-  { 279,  TR, "Out of transaction markers in transaction coordinator" },
-  { 414,  TR, "414" },
-  { 418,  TR, "Out of transaction buffers in LQH" },
-  { 419,  TR, "419" },
-  { 245,  TR, "Too many active scans" },
-  { 488,  TR, "Too many active scans" },
-  { 490,  TR, "Too many active scans" },
-  { 805,  TR, "Out of attrinfo records in tuple manager" },
-  { 830,  TR, "Out of add fragment operation records" },
-  { 873,  TR, "Out of attrinfo records for scan in tuple manager" },
-  { 1217, TR, "Out of operation records in local data manager (increase
MaxNoOfLocalOperations)" },
-  { 1220, TR, "REDO log files overloaded, consult online manual (decrease
TimeBetweenLocalCheckpoints, and|or increase NoOfFragmentLogFiles)" },
-  { 1222, TR, "Out of transaction markers in LQH" },
-  { 1224, TR, "Out of Send Buffer space in LQH" },
-  { 4021, TR, "Out of Send Buffer space in NDB API" },
-  { 4022, TR, "Out of Send Buffer space in NDB API" },
-  { 4032, TR, "Out of Send Buffer space in NDB API" },
-  {  288, TR, "Out of index operations in transaction coordinator (increase
MaxNoOfConcurrentIndexOperations)" },
+  { 275,  DMEC, TR, "275" },
+  { 279,  DMEC, TR, "Out of transaction markers in transaction coordinator" },
+  { 414,  DMEC, TR, "414" },
+  { 418,  DMEC, TR, "Out of transaction buffers in LQH" },
+  { 419,  DMEC, TR, "419" },
+  { 245,  DMEC, TR, "Too many active scans" },
+  { 488,  DMEC, TR, "Too many active scans" },
+  { 490,  DMEC, TR, "Too many active scans" },
+  { 805,  DMEC, TR, "Out of attrinfo records in tuple manager" },
+  { 830,  DMEC, TR, "Out of add fragment operation records" },
+  { 873,  DMEC, TR, "Out of attrinfo records for scan in tuple manager" },
+  { 899,  DMEC, TR, "Rowid already allocated" },
+  { 1217, DMEC, TR, "Out of operation records in local data manager (increase
MaxNoOfLocalOperations)" },
+  { 1220, DMEC, TR, "REDO log files overloaded, consult online manual (decrease
TimeBetweenLocalCheckpoints, and|or increase NoOfFragmentLogFiles)" },
+  { 1222, DMEC, TR, "Out of transaction markers in LQH" },
+  { 4021, DMEC, TR, "Out of Send Buffer space in NDB API" },
+  { 4022, DMEC, TR, "Out of Send Buffer space in NDB API" },
+  { 4032, DMEC, TR, "Out of Send Buffer space in NDB API" },
+  { 1501, DMEC, TR, "Out of undo space" },
+  {  288, DMEC, TR, "Out of index operations in transaction coordinator (increase
MaxNoOfConcurrentIndexOperations)" },
+
   /**
    * InsufficientSpace
    */
-  { 623,  IS, "623" },
-  { 624,  IS, "624" },
-  { 625,  IS, "Out of memory in Ndb Kernel, hash index part (increase IndexMemory)" },
-  { 640,  IS, "Too many hash indexes (should not happen)" },
-  { 826,  IS, "Too many tables and attributes (increase MaxNoOfAttributes or
MaxNoOfTables)" },
-  { 827,  IS, "Out of memory in Ndb Kernel, table data (increase DataMemory)" },
-  { 902,  IS, "Out of memory in Ndb Kernel, ordered index data (increase DataMemory)" },
-  { 903,  IS, "Too many ordered indexes (increase MaxNoOfOrderedIndexes)" },
-  { 904,  IS, "Out of fragment records (increase MaxNoOfOrderedIndexes)" },
-  { 905,  IS, "Out of attribute records (increase MaxNoOfAttributes)" },
-
+  { 623,  HA_ERR_RECORD_FILE_FULL, IS, "623" },
+  { 624,  HA_ERR_RECORD_FILE_FULL, IS, "624" },
+  { 625,  HA_ERR_INDEX_FILE_FULL, IS, "Out of memory in Ndb Kernel, hash index part
(increase IndexMemory)" },
+  { 640,  DMEC, IS, "Too many hash indexes (should not happen)" },
+  { 826,  HA_ERR_RECORD_FILE_FULL, IS, "Too many tables and attributes (increase
MaxNoOfAttributes or MaxNoOfTables)" },
+  { 827,  HA_ERR_RECORD_FILE_FULL, IS, "Out of memory in Ndb Kernel, table data (increase
DataMemory)" },
+  { 902,  HA_ERR_RECORD_FILE_FULL, IS, "Out of memory in Ndb Kernel, ordered index data
(increase DataMemory)" },
+  { 903,  HA_ERR_INDEX_FILE_FULL, IS, "Too many ordered indexes (increase
MaxNoOfOrderedIndexes)" },
+  { 904,  HA_ERR_INDEX_FILE_FULL, IS, "Out of fragment records (increase
MaxNoOfOrderedIndexes)" },
+  { 905,  DMEC, IS, "Out of attribute records (increase MaxNoOfAttributes)" },
+  { 1601, HA_ERR_RECORD_FILE_FULL, IS, "Out extents, tablespace full" },
+  
   /**
    * TimeoutExpired 
    */
-  { 266,  TO, "Time-out in NDB, probably caused by deadlock" },
-  { 274,  TO, "Time-out in NDB, probably caused by deadlock" }, /* Scan trans timeout */
-  { 296,  TO, "Time-out in NDB, probably caused by deadlock" }, /* Scan trans timeout */
-  { 297,  TO, "Time-out in NDB, probably caused by deadlock" }, /* Scan trans timeout,
temporary!! */
-  { 237,  TO, "Transaction had timed out when trying to commit it" },
+  { 266,  HA_ERR_LOCK_WAIT_TIMEOUT, TO, "Time-out in NDB, probably caused by deadlock" },
+  { 274,  HA_ERR_LOCK_WAIT_TIMEOUT, TO, "Time-out in NDB, probably caused by deadlock" },
/* Scan trans timeout */
+  { 296,  HA_ERR_LOCK_WAIT_TIMEOUT, TO, "Time-out in NDB, probably caused by deadlock" },
/* Scan trans timeout */
+  { 297,  HA_ERR_LOCK_WAIT_TIMEOUT, TO, "Time-out in NDB, probably caused by deadlock" },
/* Scan trans timeout, temporary!! */
+  { 237,  HA_ERR_LOCK_WAIT_TIMEOUT, TO, "Transaction had timed out when trying to commit
it" },
   
   /**
    * OverloadError
    */
-  { 410,  OL, "REDO log files overloaded, consult online manual (decrease
TimeBetweenLocalCheckpoints, and|or increase NoOfFragmentLogFiles)" },
-  { 677,  OL, "Index UNDO buffers overloaded (increase UndoIndexBuffer)" },
-  { 891,  OL, "Data UNDO buffers overloaded (increase UndoDataBuffer)" },
-  { 1221, OL, "REDO buffers overloaded, consult online manual (increase RedoBuffer)" },
-  { 4006, OL, "Connect failure - out of connection objects (increase
MaxNoOfConcurrentTransactions)" }, 
+  { 701,  DMEC, OL, "System busy with other schema operation" },
+  { 711,  DMEC, OL, "System busy with node restart, schema operations not allowed" },
+  { 410,  DMEC, OL, "REDO log files overloaded, consult online manual (decrease
TimeBetweenLocalCheckpoints, and|or increase NoOfFragmentLogFiles)" },
+  { 677,  DMEC, OL, "Index UNDO buffers overloaded (increase UndoIndexBuffer)" },
+  { 891,  DMEC, OL, "Data UNDO buffers overloaded (increase UndoDataBuffer)" },
+  { 1221, DMEC, OL, "REDO buffers overloaded, consult online manual (increase
RedoBuffer)" },
+  { 4006, DMEC, OL, "Connect failure - out of connection objects (increase
MaxNoOfConcurrentTransactions)" }, 
 
 
+  /*
+   * Internal Temporary
+   */
+  { 702,  DMEC, IT, "Request to non-master" },
   
   /**
    * Internal errors
    */
-  { 892,  IE, "Inconsistent hash index. The index needs to be dropped and recreated" },
-  { 896,  IE, "Tuple corrupted - wrong checksum or column data in invalid format" },
-  { 901,  IE, "Inconsistent ordered index. The index needs to be dropped and recreated"
},
-  { 202,  IE, "202" },
-  { 203,  IE, "203" },
-  { 207,  IE, "207" },
-  { 208,  IE, "208" },
-  { 209,  IE, "Communication problem, signal error" },
-  { 220,  IE, "220" },
-  { 230,  IE, "230" },
-  { 232,  IE, "232" },
-  { 238,  IE, "238" },
-  { 271,  IE, "Simple Read transaction without any attributes to read" },
-  { 272,  IE, "Update operation without any attributes to update" },
-  { 276,  IE, "276" },
-  { 277,  IE, "277" },
-  { 278,  IE, "278" },
-  { 287,  IE, "Index corrupted" },
-  { 290,  IE, "Corrupt key in TC, unable to xfrm" },
-  { 631,  IE, "631" },
-  { 632,  IE, "632" },
-  { 702,  IE, "Request to non-master" },
-  { 706,  IE, "Inconsistency during table creation" },
-  { 809,  IE, "809" },
-  { 812,  IE, "812" },
-  { 829,  IE, "829" },
-  { 833,  IE, "833" },
-  { 839,  IE, "Illegal null attribute" },
-  { 871,  IE, "871" },
-  { 882,  IE, "882" },
-  { 883,  IE, "883" },
-  { 887,  IE, "887" },
-  { 888,  IE, "888" },
-  { 890,  IE, "890" },
-  { 4000, IE, "MEMORY ALLOCATION ERROR" },
-  { 4001, IE, "Signal Definition Error" },
-  { 4005, IE, "Internal Error in NdbApi" },
-  { 4011, IE, "Internal Error in NdbApi" }, 
-  { 4107, IE, "Simple Transaction and Not Start" },
-  { 4108, IE, "Faulty operation type" },
-  { 4109, IE, "Faulty primary key attribute length" },
-  { 4110, IE, "Faulty length in ATTRINFO signal" },
-  { 4111, IE, "Status Error in NdbConnection" },
-  { 4113, IE, "Too many operations received" },
-  { 4320, IE, "Cannot use the same object twice to create table" },
-  { 4321, IE, "Trying to start two schema transactions" },
-  { 4344, IE, "Only DBDICT and TRIX can send requests to TRIX" },
-  { 4345, IE, "TRIX block is not available yet, probably due to node failure" },
-  { 4346, IE, "Internal error at index create/build" },
-  { 4347, IE, "Bad state at alter index" },
-  { 4348, IE, "Inconsistency detected at alter index" },
-  { 4349, IE, "Inconsistency detected at index usage" },
-  { 4350, IE, "Transaction already aborted" },
+  { 892,  DMEC, IE, "Inconsistent hash index. The index needs to be dropped and
recreated" },
+  { 896,  DMEC, IE, "Tuple corrupted - wrong checksum or column data in invalid format"
},
+  { 901,  DMEC, IE, "Inconsistent ordered index. The index needs to be dropped and
recreated" },
+  { 202,  DMEC, IE, "202" },
+  { 203,  DMEC, IE, "203" },
+  { 207,  DMEC, IE, "207" },
+  { 208,  DMEC, IE, "208" },
+  { 209,  DMEC, IE, "Communication problem, signal error" },
+  { 220,  DMEC, IE, "220" },
+  { 230,  DMEC, IE, "230" },
+  { 232,  DMEC, IE, "232" },
+  { 238,  DMEC, IE, "238" },
+  { 271,  DMEC, IE, "Simple Read transaction without any attributes to read" },
+  { 272,  DMEC, IE, "Update operation without any attributes to update" },
+  { 276,  DMEC, IE, "276" },
+  { 277,  DMEC, IE, "277" },
+  { 278,  DMEC, IE, "278" },
+  { 287,  DMEC, IE, "Index corrupted" },
+  { 290,  DMEC, IE, "Corrupt key in TC, unable to xfrm" },
+  { 631,  DMEC, IE, "631" },
+  { 632,  DMEC, IE, "632" },
+  { 706,  DMEC, IE, "Inconsistency during table creation" },
+  { 809,  DMEC, IE, "809" },
+  { 812,  DMEC, IE, "812" },
+  { 829,  DMEC, IE, "829" },
+  { 833,  DMEC, IE, "833" },
+  { 871,  DMEC, IE, "871" },
+  { 882,  DMEC, IE, "882" },
+  { 883,  DMEC, IE, "883" },
+  { 887,  DMEC, IE, "887" },
+  { 888,  DMEC, IE, "888" },
+  { 890,  DMEC, IE, "890" },
+  { 4000, DMEC, IE, "MEMORY ALLOCATION ERROR" },
+  { 4001, DMEC, IE, "Signal Definition Error" },
+  { 4005, DMEC, IE, "Internal Error in NdbApi" },
+  { 4011, DMEC, IE, "Internal Error in NdbApi" }, 
+  { 4107, DMEC, IE, "Simple Transaction and Not Start" },
+  { 4108, DMEC, IE, "Faulty operation type" },
+  { 4109, DMEC, IE, "Faulty primary key attribute length" },
+  { 4110, DMEC, IE, "Faulty length in ATTRINFO signal" },
+  { 4111, DMEC, IE, "Status Error in NdbConnection" },
+  { 4113, DMEC, IE, "Too many operations received" },
+  { 4320, DMEC, IE, "Cannot use the same object twice to create table" },
+  { 4321, DMEC, IE, "Trying to start two schema transactions" },
+  { 4344, DMEC, IE, "Only DBDICT and TRIX can send requests to TRIX" },
+  { 4345, DMEC, IE, "TRIX block is not available yet, probably due to node failure" },
+  { 4346, DMEC, IE, "Internal error at index create/build" },
+  { 4347, DMEC, IE, "Bad state at alter index" },
+  { 4348, DMEC, IE, "Inconsistency detected at alter index" },
+  { 4349, DMEC, IE, "Inconsistency detected at index usage" },
+  { 4350, DMEC, IE, "Transaction already aborted" },
 
   /**
    * Application error
    */
-  { 763,  AE, "Alter table requires cluster nodes to have exact same version" },
-  { 823,  AE, "Too much attrinfo from application in tuple manager" },
-  { 831,  AE, "Too many nullable/bitfields in table definition" },
-  { 876,  AE, "876" },
-  { 877,  AE, "877" },
-  { 878,  AE, "878" },
-  { 879,  AE, "879" },
-  { 880,  AE, "Tried to read too much - too many getValue calls" },
-  { 884,  AE, "Stack overflow in interpreter" },
-  { 885,  AE, "Stack underflow in interpreter" },
-  { 886,  AE, "More than 65535 instructions executed in interpreter" },
-  { 897,  AE, "Update attempt of primary key via ndbcluster internal api (if this occurs
via the MySQL server it is a bug, please report)" },
-  { 4256, AE, "Must call Ndb::init() before this function" },
-  { 4257, AE, "Tried to read too much - too many getValue calls" },
-  
+  { 763,  DMEC, AE, "Alter table requires cluster nodes to have exact same version" },
+  { 823,  DMEC, AE, "Too much attrinfo from application in tuple manager" },
+  { 831,  DMEC, AE, "Too many nullable/bitfields in table definition" },
+  { 876,  DMEC, AE, "876" },
+  { 877,  DMEC, AE, "877" },
+  { 878,  DMEC, AE, "878" },
+  { 879,  DMEC, AE, "879" },
+  { 880,  DMEC, AE, "Tried to read too much - too many getValue calls" },
+  { 884,  DMEC, AE, "Stack overflow in interpreter" },
+  { 885,  DMEC, AE, "Stack underflow in interpreter" },
+  { 886,  DMEC, AE, "More than 65535 instructions executed in interpreter" },
+  { 897,  DMEC, AE, "Update attempt of primary key via ndbcluster internal api (if this
occurs via the MySQL server it is a bug, please report)" },
+  { 4256, DMEC, AE, "Must call Ndb::init() before this function" },
+  { 4257, DMEC, AE, "Tried to read too much - too many getValue calls" },
+
   /** 
    * Scan application errors
    */
-  { 242,  AE, "Zero concurrency in scan"},
-  { 244,  AE, "Too high concurrency in scan"},
-  { 269,  AE, "No condition and attributes to read in scan"},
-  { 4600, AE, "Transaction is already started"},
-  { 4601, AE, "Transaction is not started"},
-  { 4602, AE, "You must call getNdbOperation before executeScan" },
-  { 4603, AE, "There can only be ONE operation in a scan transaction" },
-  { 4604, AE, "takeOverScanOp, to take over a scanned row one must explicitly request
keyinfo in readTuples call" },
-  { 4605, AE, "You may only call openScanRead or openScanExclusive once for each
operation"},
-  { 4607, AE, "There may only be one operation in a scan transaction"},
-  { 4608, AE, "You can not takeOverScan unless you have used openScanExclusive"},
-  { 4609, AE, "You must call nextScanResult before trying to takeOverScan"},
-  { 4232, AE, "Parallelism can only be between 1 and 240" },
+  { 242,  DMEC, AE, "Zero concurrency in scan"},
+  { 244,  DMEC, AE, "Too high concurrency in scan"},
+  { 269,  DMEC, AE, "No condition and attributes to read in scan"},
+  { 4600, DMEC, AE, "Transaction is already started"},
+  { 4601, DMEC, AE, "Transaction is not started"},
+  { 4602, DMEC, AE, "You must call getNdbOperation before executeScan" },
+  { 4603, DMEC, AE, "There can only be ONE operation in a scan transaction" },
+  { 4604, DMEC, AE, "takeOverScanOp, to take over a scanned row one must explicitly
request keyinfo on readTuples call" },
+  { 4605, DMEC, AE, "You may only call openScanRead or openScanExclusive once for each
operation"},
+  { 4607, DMEC, AE, "There may only be one operation in a scan transaction"},
+  { 4608, DMEC, AE, "You can not takeOverScan unless you have used openScanExclusive"},
+  { 4609, DMEC, AE, "You must call nextScanResult before trying to takeOverScan"},
+  { 4232, DMEC, AE, "Parallelism can only be between 1 and 240" },
 
   /** 
    * Event schema errors
    */
 
-  { 4713,  SE, "Column defined in event does not exist in table"},
+  { 4713,  DMEC, SE, "Column defined in event does not exist in table"},
   
   /** 
    * Event application errors
    */
 
-  { 4707,  AE, "Too many event have been defined"},
-  { 4708,  AE, "Event name is too long"},
-  { 4709,  AE, "Can't accept more subscribers"},
-  {  746,  OE, "Event name already exists"},
-  { 4710,  AE, "Event not found"},
-  { 4711,  AE, "Creation of event failed"},
-  { 4712,  AE, "Stopped event operation does not exist. Already stopped?"},
+  { 4707,  DMEC, AE, "Too many event have been defined"},
+  { 4708,  DMEC, AE, "Event name is too long"},
+  { 4709,  DMEC, AE, "Can't accept more subscribers"},
+  {  746,  DMEC, OE, "Event name already exists"},
+  {  747,  DMEC, IS, "Out of event records"},
+  {  748,  DMEC, TR, "Busy during read of event table"},
+  { 4710,  DMEC, AE, "Event not found"},
+  { 4711,  DMEC, AE, "Creation of event failed"},
+  { 4712,  DMEC, AE, "Stopped event operation does not exist. Already stopped?"},
 
   /** 
    * Event internal errors
    */
 
-  { 4731,  IE, "Event not found"},
+  { 4731,  DMEC, IE, "Event not found"},
 
   /**
    * SchemaError
    */
-  { 701,  SE, "System busy with other schema operation" },
-  { 703,  SE, "Invalid table format" },
-  { 704,  SE, "Attribute name too long" },
-  { 705,  SE, "Table name too long" },
-  { 707,  SE, "No more table metadata records (increase MaxNoOfTables)" },  
-  { 708,  SE, "No more attribute metadata records (increase MaxNoOfAttributes)" },
-  { 709,  SE, "No such table existed" },
-  { 721,  OE, "Table or index with given name already exists" },
-  { 723,  SE, "No such table existed" },
-  { 736,  SE, "Unsupported array size" },
-  { 737,  SE, "Attribute array size too big" },
-  { 738,  SE, "Record too big" },
-  { 739,  SE, "Unsupported primary key length" },
-  { 740,  SE, "Nullable primary key not supported" },
-  { 741,  SE, "Unsupported alter table" },
-  { 743,  SE, "Unsupported character set in table or index" },
-  { 744,  SE, "Character string is invalid for given character set" },
-  { 745,  SE, "Distribution key not supported for char attribute (use binary attribute)"
},
-  { 761,  SE, "Unable to drop table as backup is in progress" },
-  { 762,  SE, "Unable to alter table as backup is in progress" },
-  { 241,  SE, "Invalid schema object version" },
-  { 283,  SE, "Table is being dropped" },
-  { 284,  SE, "Table not defined in transaction coordinator" },
-  { 285,  SE, "Unknown table error in transaction coordinator" },
-  { 881,  SE, "Unable to create table, out of data pages (increase DataMemory) " },
-  { 906,  SE, "Unsupported attribute type in index" },
-  { 907,  SE, "Unsupported character set in table or index" },
-  { 908,  IS, "Invalid ordered index tree node size" },
-  { 1225, SE, "Table not defined in local query handler" },
-  { 1226, SE, "Table is being dropped" },
-  { 1228, SE, "Cannot use drop table for drop index" },
-  { 1229, SE, "Too long frm data supplied" },
-  { 1231, SE, "Invalid table or index to scan" },
-  { 1232, SE, "Invalid table or index to scan" },
-
+  { 311,  DMEC, AE, "Undefined partition used in setPartitionId" },
+  { 703,  DMEC, SE, "Invalid table format" },
+  { 704,  DMEC, SE, "Attribute name too long" },
+  { 705,  DMEC, SE, "Table name too long" },
+  { 707,  DMEC, SE, "No more table metadata records (increase MaxNoOfTables)" },  
+  { 708,  DMEC, SE, "No more attribute metadata records (increase MaxNoOfAttributes)" },
+  { 709,  HA_ERR_NO_SUCH_TABLE, SE, "No such table existed" },
+  { 710,  DMEC, SE, "Internal: Get by table name not supported, use table id." },
+  { 721,  HA_ERR_TABLE_EXIST,   OE, "Table or index with given name already exists" },
+  { 723,  HA_ERR_NO_SUCH_TABLE, SE, "No such table existed" },
+  { 736,  DMEC, SE, "Unsupported array size" },
+  { 737,  HA_WRONG_CREATE_OPTION, SE, "Attribute array size too big" },
+  { 738,  HA_WRONG_CREATE_OPTION, SE, "Record too big" },
+  { 739,  HA_WRONG_CREATE_OPTION, SE, "Unsupported primary key length" },
+  { 740,  HA_WRONG_CREATE_OPTION, SE, "Nullable primary key not supported" },
+  { 741,  DMEC, SE, "Unsupported alter table" },
+  { 743,  HA_WRONG_CREATE_OPTION, SE, "Unsupported character set in table or index" },
+  { 744,  DMEC, SE, "Character string is invalid for given character set" },
+  { 745,  HA_WRONG_CREATE_OPTION, SE, "Distribution key not supported for char attribute
(use binary attribute)" },
+  { 771,  HA_WRONG_CREATE_OPTION, AE, "Given NODEGROUP doesn't exist in this cluster" },
+  { 772,  HA_WRONG_CREATE_OPTION, IE, "Given fragmentType doesn't exist" },
+  { 749,  HA_WRONG_CREATE_OPTION, IE, "Primary Table in wrong state" },
+  { 763,  HA_WRONG_CREATE_OPTION, SE, "Invalid undo buffer size" },
+  { 764,  HA_WRONG_CREATE_OPTION, SE, "Invalid extent size" },
+  { 765,  DMEC, SE, "Out of filegroup records" },
+  { 750,  IE, SE, "Invalid file type" },
+  { 751,  DMEC, SE, "Out of file records" },
+  { 752,  DMEC, SE, "Invalid file format" },
+  { 753,  IE, SE, "Invalid filegroup for file" },
+  { 754,  IE, SE, "Invalid filegroup version when creating file" },
+  { 755,  DMEC, SE, "Invalid tablespace" },
+  { 756,  DMEC, SE, "Index on disk column is not supported" },
+  { 757,  DMEC, SE, "Varsize bitfield not supported" },
+  { 758,  DMEC, SE, "Tablespace has changed" },
+  { 759,  DMEC, SE, "Invalid tablespace version " },
+  { 760,  DMEC, SE, "File already exists", },
+  { 761,  DMEC, SE, "Unable to drop table as backup is in progress" },
+  { 762,  DMEC, SE, "Unable to alter table as backup is in progress" },
+  { 766,  DMEC, SE, "Cant drop file, no such file" },
+  { 767,  DMEC, SE, "Cant drop filegroup, no such filegroup" },
+  { 768,  DMEC, SE, "Cant drop filegroup, filegroup is used" },
+  { 769,  DMEC, SE, "Drop undofile not supported, drop logfile group instead" },
+  { 770,  DMEC, SE, "Cant drop file, file is used" },
+  { 774,  DMEC, SE, "Invalid schema object for drop" },
+  { 241,  HA_ERR_TABLE_DEF_CHANGED, SE, "Invalid schema object version" },
+  { 283,  HA_ERR_NO_SUCH_TABLE, SE, "Table is being dropped" },
+  { 284,  HA_ERR_TABLE_DEF_CHANGED, SE, "Table not defined in transaction coordinator" },
+  { 285,  DMEC, SE, "Unknown table error in transaction coordinator" },
+  { 881,  DMEC, SE, "Unable to create table, out of data pages (increase DataMemory) " },
+  { 906,  DMEC, SE, "Unsupported attribute type in index" },
+  { 907,  DMEC, SE, "Unsupported character set in table or index" },
+  { 908,  DMEC, IS, "Invalid ordered index tree node size" },
+  { 1225, DMEC, SE, "Table not defined in local query handler" },
+  { 1226, DMEC, SE, "Table is being dropped" },
+  { 1228, DMEC, SE, "Cannot use drop table for drop index" },
+  { 1229, DMEC, SE, "Too long frm data supplied" },
+  { 1231, DMEC, SE, "Invalid table or index to scan" },
+  { 1232, DMEC, SE, "Invalid table or index to scan" },
+
+  { 1502, DMEC, IE, "Filegroup already exists" },
+  { 1503, DMEC, SE, "Out of filegroup records" },
+  { 1504, DMEC, SE, "Out of logbuffer memory" },
+  { 1505, DMEC, IE, "Invalid filegroup" },
+  { 1506, DMEC, IE, "Invalid filegroup version" },
+  { 1507, DMEC, IE, "File no already inuse" },
+  { 1508, DMEC, SE, "Out of file records" },
+  { 1509, DMEC, SE, "File system error, check if path,permissions etc" },
+  { 1510, DMEC, IE, "File meta data error" },
+  { 1511, DMEC, IE, "Out of memory" },
+  { 1512, DMEC, SE, "File read error" },
+  { 1513, DMEC, IE, "Filegroup not online" },
+  { 1514, DMEC, SE, "Currently there is a limit of one logfile group" },
+  
+  { 773,  DMEC, SE, "Out of string memory, please modify StringMemory config parameter"
},
+  
   /**
    * FunctionNotImplemented
    */
-  { 4003, NI, "Function not implemented yet" },
+  { 4003, DMEC, NI, "Function not implemented yet" },
 
   /**
    * Backup error codes
    */ 
 
-  { 1300, IE, "Undefined error" },
-  { 1301, IE, "Backup issued to not master (reissue command to master)" },
-  { 1302, IE, "Out of backup record" },
-  { 1303, IS, "Out of resources" },
-  { 1304, IE, "Sequence failure" },
-  { 1305, IE, "Backup definition not implemented" },
-  { 1306, AE, "Backup not supported in diskless mode (change Diskless)" },
-
-  { 1321, IE, "Backup aborted by application" },
-  { 1322, IE, "Backup already completed" },
-  { 1323, IE, "1323" },
-  { 1324, IE, "Backup log buffer full" },
-  { 1325, IE, "File or scan error" },
-  { 1326, IE, "Backup abortet due to node failure" },
-  { 1327, IE, "1327" },
-  
-  { 1340, IE, "Backup undefined error" },
-  { 1342, AE, "Backup failed to allocate buffers (check configuration)" },
-  { 1343, AE, "Backup failed to setup fs buffers (check configuration)" },
-  { 1344, AE, "Backup failed to allocate tables (check configuration)" },
-  { 1345, AE, "Backup failed to insert file header (check configuration)" },
-  { 1346, AE, "Backup failed to insert table list (check configuration)" },
-  { 1347, AE, "Backup failed to allocate table memory (check configuration)" },
-  { 1348, AE, "Backup failed to allocate file record (check configuration)" },
-  { 1349, AE, "Backup failed to allocate attribute record (check configuration)" },
-  { 1329, AE, "Backup during software upgrade not supported" },
+  { 1300, DMEC, IE, "Undefined error" },
+  { 1301, DMEC, IE, "Backup issued to not master (reissue command to master)" },
+  { 1302, DMEC, IE, "Out of backup record" },
+  { 1303, DMEC, IS, "Out of resources" },
+  { 1304, DMEC, IE, "Sequence failure" },
+  { 1305, DMEC, IE, "Backup definition not implemented" },
+  { 1306, DMEC, AE, "Backup not supported in diskless mode (change Diskless)" },
+
+  { 1321, DMEC, IE, "Backup aborted by application" },
+  { 1322, DMEC, IE, "Backup already completed" },
+  { 1323, DMEC, IE, "1323" },
+  { 1324, DMEC, IE, "Backup log buffer full" },
+  { 1325, DMEC, IE, "File or scan error" },
+  { 1326, DMEC, IE, "Backup abortet due to node failure" },
+  { 1327, DMEC, IE, "1327" },
+  
+  { 1340, DMEC, IE, "Backup undefined error" },
+  { 1342, DMEC, AE, "Backup failed to allocate buffers (check configuration)" },
+  { 1343, DMEC, AE, "Backup failed to setup fs buffers (check configuration)" },
+  { 1344, DMEC, AE, "Backup failed to allocate tables (check configuration)" },
+  { 1345, DMEC, AE, "Backup failed to insert file header (check configuration)" },
+  { 1346, DMEC, AE, "Backup failed to insert table list (check configuration)" },
+  { 1347, DMEC, AE, "Backup failed to allocate table memory (check configuration)" },
+  { 1348, DMEC, AE, "Backup failed to allocate file record (check configuration)" },
+  { 1349, DMEC, AE, "Backup failed to allocate attribute record (check configuration)" },
+  { 1329, DMEC, AE, "Backup during software upgrade not supported" },
+
+  /**
+   * Node id allocation error codes
+   */ 
+
+  { 1700, DMEC, IE, "Undefined error" },
+  { 1701, DMEC, AE, "Node already reserved" },
+  { 1702, DMEC, AE, "Node already connected" },
+  { 1703, DMEC, AE, "Node failure handling not completed" },
+  { 1704, DMEC, AE, "Node type mismatch" },
   
   /**
    * Still uncategorized
    */
-  { 720,  AE, "Attribute name reused in table definition" },
-  { 4004, AE, "Attribute name not found in the Table" },
-  
-  { 4100, AE, "Status Error in NDB" },
-  { 4101, AE, "No connections to NDB available and connect failed" },
-  { 4102, AE, "Type in NdbTamper not correct" },
-  { 4103, AE, "No schema connections to NDB available and connect failed" },
-  { 4104, AE, "Ndb Init in wrong state, destroy Ndb object and create a new" },
-  { 4105, AE, "Too many Ndb objects" },
-  { 4106, AE, "All Not NULL attribute have not been defined" },
-  { 4114, AE, "Transaction is already completed" },
-  { 4116, AE, "Operation was not defined correctly, probably missing a key" },
-  { 4117, AE, "Could not start transporter, configuration error"}, 
-  { 4118, AE, "Parameter error in API call" },
-  { 4300, AE, "Tuple Key Type not correct" },
-  { 4301, AE, "Fragment Type not correct" },
-  { 4302, AE, "Minimum Load Factor not correct" },
-  { 4303, AE, "Maximum Load Factor not correct" },
-  { 4304, AE, "Maximum Load Factor smaller than Minimum" },
-  { 4305, AE, "K value must currently be set to 6" },
-  { 4306, AE, "Memory Type not correct" },
-  { 4307, AE, "Invalid table name" },
-  { 4308, AE, "Attribute Size not correct" },
-  { 4309, AE, "Fixed array too large, maximum 64000 bytes" },
-  { 4310, AE, "Attribute Type not correct" },
-  { 4311, AE, "Storage Mode not correct" },
-  { 4312, AE, "Null Attribute Type not correct" },
-  { 4313, AE, "Index only storage for non-key attribute" },
-  { 4314, AE, "Storage Type of attribute not correct" },
-  { 4315, AE, "No more key attributes allowed after defining variable length key
attribute" },
-  { 4316, AE, "Key attributes are not allowed to be NULL attributes" },
-  { 4317, AE, "Too many primary keys defined in table" },
-  { 4318, AE, "Invalid attribute name" },
-  { 4319, AE, "createAttribute called at erroneus place" },
-  { 4322, AE, "Attempt to define distribution key when not prepared to" },
-  { 4323, AE, "Distribution Key set on table but not defined on first attribute" },
-  { 4324, AE, "Attempt to define distribution group when not prepared to" },
-  { 4325, AE, "Distribution Group set on table but not defined on first attribute" },
-  { 4326, AE, "Distribution Group with erroneus number of bits" },
-  { 4327, AE, "Distribution Group with 1 byte attribute is not allowed" },
-  { 4328, AE, "Disk memory attributes not yet supported" },
-  { 4329, AE, "Variable stored attributes not yet supported" },
-
-  { 4400, AE, "Status Error in NdbSchemaCon" },
-  { 4401, AE, "Only one schema operation per schema transaction" },
-  { 4402, AE, "No schema operation defined before calling execute" },
-
-  { 4501, AE, "Insert in hash table failed when getting table information from Ndb" },
-  { 4502, AE, "GetValue not allowed in Update operation" },
-  { 4503, AE, "GetValue not allowed in Insert operation" },
-  { 4504, AE, "SetValue not allowed in Read operation" },
-  { 4505, AE, "NULL value not allowed in primary key search" },
-  { 4506, AE, "Missing getValue/setValue when calling execute" },
-  { 4507, AE, "Missing operation request when calling execute" },
-
-  { 4200, AE, "Status Error when defining an operation" },
-  { 4201, AE, "Variable Arrays not yet supported" },
-  { 4202, AE, "Set value on tuple key attribute is not allowed" },
-  { 4203, AE, "Trying to set a NOT NULL attribute to NULL" },
-  { 4204, AE, "Set value and Read/Delete Tuple is incompatible" },
-  { 4205, AE, "No Key attribute used to define tuple" },
-  { 4206, AE, "Not allowed to equal key attribute twice" },
-  { 4207, AE, "Key size is limited to 4092 bytes" },
-  { 4208, AE, "Trying to read a non-stored attribute" },
-  { 4209, AE, "Length parameter in equal/setValue is incorrect" },
-  { 4210, AE, "Ndb sent more info than the length he specified" },
-  { 4211, AE, "Inconsistency in list of NdbRecAttr-objects" },
-  { 4212, AE, "Ndb reports NULL value on Not NULL attribute" },
-  { 4213, AE, "Not all data of an attribute has been received" },
-  { 4214, AE, "Not all attributes have been received" },
-  { 4215, AE, "More data received than reported in TCKEYCONF message" },
-  { 4216, AE, "More than 8052 bytes in setValue cannot be handled" },
-  { 4217, AE, "It is not allowed to increment any other than unsigned ints" },
-  { 4218, AE, "Currently not allowed to increment NULL-able attributes" },
-  { 4219, AE, "Maximum size of interpretative attributes are 64 bits" },
-  { 4220, AE, "Maximum size of interpretative attributes are 64 bits" },
-  { 4221, AE, "Trying to jump to a non-defined label" },
-  { 4222, AE, "Label was not found, internal error" },
-  { 4223, AE, "Not allowed to create jumps to yourself" },
-  { 4224, AE, "Not allowed to jump to a label in a different subroutine" },
-  { 4225, AE, "All primary keys defined, call setValue/getValue"},
-  { 4226, AE, "Bad number when defining a label" },
-  { 4227, AE, "Bad number when defining a subroutine" },
-  { 4228, AE, "Illegal interpreter function in scan definition" },
-  { 4229, AE, "Illegal register in interpreter function definition" },
-  { 4230, AE, "Illegal state when calling getValue, probably not a read" },
-  { 4231, AE, "Illegal state when calling interpreter routine" },
-  { 4233, AE, "Calling execute (synchronous) when already prepared asynchronous
transaction exists" },
-  { 4234, AE, "Illegal to call setValue in this state" },
-  { 4235, AE, "No callback from execute" },
-  { 4236, AE, "Trigger name too long" },
-  { 4237, AE, "Too many triggers" },
-  { 4238, AE, "Trigger not found" },
-  { 4239, AE, "Trigger with given name already exists"},
-  { 4240, AE, "Unsupported trigger type"},
-  { 4241, AE, "Index name too long" },
-  { 4242, AE, "Too many indexes" },
-  { 4243, AE, "Index not found" },
-  { 4244, OE, "Index or table with given name already exists" },
-  { 4247, AE, "Illegal index/trigger create/drop/alter request" },
-  { 4248, AE, "Trigger/index name invalid" },
-  { 4249, AE, "Invalid table" },
-  { 4250, AE, "Invalid index type or index logging option" },
-  { 4251, AE, "Cannot create unique index, duplicate keys found" },
-  { 4252, AE, "Failed to allocate space for index" },
-  { 4253, AE, "Failed to create index table" },
-  { 4254, AE, "Table not an index table" },
-  { 4255, AE, "Hash index attributes must be specified in same order as table attributes"
},
-  { 4258, AE, "Cannot create unique index, duplicate attributes found in definition" },
-  { 4259, AE, "Invalid set of range scan bounds" },
-  { 4260, UD, "NdbScanFilter: Operator is not defined in NdbScanFilter::Group"},
-  { 4261, UD, "NdbScanFilter: Column is NULL"},
-  { 4262, UD, "NdbScanFilter: Condition is out of bounds"},
-  { 4263, IE, "Invalid blob attributes or invalid blob parts table" },
-  { 4264, AE, "Invalid usage of blob attribute" },
-  { 4265, AE, "The blob method is not valid in current blob state" },
-  { 4266, AE, "Invalid blob seek position" },
-  { 4267, IE, "Corrupted blob value" },
-  { 4268, IE, "Error in blob head update forced rollback of transaction" },
-  { 4269, IE, "No connection to ndb management server" },
-  { 4270, IE, "Unknown blob error" },
-  { 4335, AE, "Only one autoincrement column allowed per table. Having a table without
primary key uses an autoincremented hidden key, i.e. a table without a primary key can
not have an autoincremented column" },
-  { 4271, AE, "Invalid index object, not retrieved via getIndex()" },
-  { 4275, AE, "The blob method is incompatible with operation type or lock mode" }
+  { 720,  DMEC, AE, "Attribute name reused in table definition" },
+  { 1405, DMEC, NR, "Subscriber manager busy with node recovery" },
+  { 1407, DMEC, SE, "Subscription not found in subscriber manager" },
+  { 1411, DMEC, TR, "Subscriber manager busy with adding/removing a subscriber" },
+  { 1412, DMEC, IS, "Can't accept more subscribers, out of space in pool" },
+  { 1413, DMEC, TR, "Subscriber manager busy with adding the subscription" },
+  { 1414, DMEC, TR, "Subscriber manager has subscribers on this subscription" },
+  { 1415, DMEC, SE, "Subscription not unique in subscriber manager" },
+  { 1416, DMEC, IS, "Can't accept more subscriptions, out of space in pool" },
+  { 1417, DMEC, SE, "Table in suscription not defined, probably dropped" },
+  { 1418, DMEC, SE, "Subscription dropped, no new subscribers allowed" },
+  { 1419, DMEC, SE, "Subscription already dropped" },
+
+  { 4004, DMEC, AE, "Attribute name not found in the Table" },
+  
+  { 4100, DMEC, AE, "Status Error in NDB" },
+  { 4101, DMEC, AE, "No connections to NDB available and connect failed" },
+  { 4102, DMEC, AE, "Type in NdbTamper not correct" },
+  { 4103, DMEC, AE, "No schema connections to NDB available and connect failed" },
+  { 4104, DMEC, AE, "Ndb Init in wrong state, destroy Ndb object and create a new" },
+  { 4105, DMEC, AE, "Too many Ndb objects" },
+  { 4106, DMEC, AE, "All Not NULL attribute have not been defined" },
+  { 4114, DMEC, AE, "Transaction is already completed" },
+  { 4116, DMEC, AE, "Operation was not defined correctly, probably missing a key" },
+  { 4117, DMEC, AE, "Could not start transporter, configuration error"}, 
+  { 4118, DMEC, AE, "Parameter error in API call" },
+  { 4300, DMEC, AE, "Tuple Key Type not correct" },
+  { 4301, DMEC, AE, "Fragment Type not correct" },
+  { 4302, DMEC, AE, "Minimum Load Factor not correct" },
+  { 4303, DMEC, AE, "Maximum Load Factor not correct" },
+  { 4304, DMEC, AE, "Maximum Load Factor smaller than Minimum" },
+  { 4305, DMEC, AE, "K value must currently be set to 6" },
+  { 4306, DMEC, AE, "Memory Type not correct" },
+  { 4307, DMEC, AE, "Invalid table name" },
+  { 4308, DMEC, AE, "Attribute Size not correct" },
+  { 4309, DMEC, AE, "Fixed array too large, maximum 64000 bytes" },
+  { 4310, DMEC, AE, "Attribute Type not correct" },
+  { 4311, DMEC, AE, "Storage Mode not correct" },
+  { 4312, DMEC, AE, "Null Attribute Type not correct" },
+  { 4313, DMEC, AE, "Index only storage for non-key attribute" },
+  { 4314, DMEC, AE, "Storage Type of attribute not correct" },
+  { 4315, DMEC, AE, "No more key attributes allowed after defining variable length key
attribute" },
+  { 4316, DMEC, AE, "Key attributes are not allowed to be NULL attributes" },
+  { 4317, DMEC, AE, "Too many primary keys defined in table" },
+  { 4318, DMEC, AE, "Invalid attribute name or number" },
+  { 4319, DMEC, AE, "createAttribute called at erroneus place" },
+  { 4322, DMEC, AE, "Attempt to define distribution key when not prepared to" },
+  { 4323, DMEC, AE, "Distribution Key set on table but not defined on first attribute" },
+  { 4324, DMEC, AE, "Attempt to define distribution group when not prepared to" },
+  { 4325, DMEC, AE, "Distribution Group set on table but not defined on first attribute"
},
+  { 4326, DMEC, AE, "Distribution Group with erroneus number of bits" },
+  { 4327, DMEC, AE, "Distribution Group with 1 byte attribute is not allowed" },
+  { 4328, DMEC, AE, "Disk memory attributes not yet supported" },
+  { 4329, DMEC, AE, "Variable stored attributes not yet supported" },
+
+  { 4400, DMEC, AE, "Status Error in NdbSchemaCon" },
+  { 4401, DMEC, AE, "Only one schema operation per schema transaction" },
+  { 4402, DMEC, AE, "No schema operation defined before calling execute" },
+
+  { 4501, DMEC, AE, "Insert in hash table failed when getting table information from Ndb"
},
+  { 4502, DMEC, AE, "GetValue not allowed in Update operation" },
+  { 4503, DMEC, AE, "GetValue not allowed in Insert operation" },
+  { 4504, DMEC, AE, "SetValue not allowed in Read operation" },
+  { 4505, DMEC, AE, "NULL value not allowed in primary key search" },
+  { 4506, DMEC, AE, "Missing getValue/setValue when calling execute" },
+  { 4507, DMEC, AE, "Missing operation request when calling execute" },
+
+  { 4200, DMEC, AE, "Status Error when defining an operation" },
+  { 4201, DMEC, AE, "Variable Arrays not yet supported" },
+  { 4202, DMEC, AE, "Set value on tuple key attribute is not allowed" },
+  { 4203, DMEC, AE, "Trying to set a NOT NULL attribute to NULL" },
+  { 4204, DMEC, AE, "Set value and Read/Delete Tuple is incompatible" },
+  { 4205, DMEC, AE, "No Key attribute used to define tuple" },
+  { 4206, DMEC, AE, "Not allowed to equal key attribute twice" },
+  { 4207, DMEC, AE, "Key size is limited to 4092 bytes" },
+  { 4208, DMEC, AE, "Trying to read a non-stored attribute" },
+  { 4209, DMEC, AE, "Length parameter in equal/setValue is incorrect" },
+  { 4210, DMEC, AE, "Ndb sent more info than the length he specified" },
+  { 4211, DMEC, AE, "Inconsistency in list of NdbRecAttr-objects" },
+  { 4212, DMEC, AE, "Ndb reports NULL value on Not NULL attribute" },
+  { 4213, DMEC, AE, "Not all data of an attribute has been received" },
+  { 4214, DMEC, AE, "Not all attributes have been received" },
+  { 4215, DMEC, AE, "More data received than reported in TCKEYCONF message" },
+  { 4216, DMEC, AE, "More than 8052 bytes in setValue cannot be handled" },
+  { 4217, DMEC, AE, "It is not allowed to increment any other than unsigned ints" },
+  { 4218, DMEC, AE, "Currently not allowed to increment NULL-able attributes" },
+  { 4219, DMEC, AE, "Maximum size of interpretative attributes are 64 bits" },
+  { 4220, DMEC, AE, "Maximum size of interpretative attributes are 64 bits" },
+  { 4221, DMEC, AE, "Trying to jump to a non-defined label" },
+  { 4222, DMEC, AE, "Label was not found, internal error" },
+  { 4223, DMEC, AE, "Not allowed to create jumps to yourself" },
+  { 4224, DMEC, AE, "Not allowed to jump to a label in a different subroutine" },
+  { 4225, DMEC, AE, "All primary keys defined, call setValue/getValue"},
+  { 4226, DMEC, AE, "Bad number when defining a label" },
+  { 4227, DMEC, AE, "Bad number when defining a subroutine" },
+  { 4228, DMEC, AE, "Illegal interpreter function in scan definition" },
+  { 4229, DMEC, AE, "Illegal register in interpreter function definition" },
+  { 4230, DMEC, AE, "Illegal state when calling getValue, probably not a read" },
+  { 4231, DMEC, AE, "Illegal state when calling interpreter routine" },
+  { 4233, DMEC, AE, "Calling execute (synchronous) when already prepared asynchronous
transaction exists" },
+  { 4234, DMEC, AE, "Illegal to call setValue in this state" },
+  { 4235, DMEC, AE, "No callback from execute" },
+  { 4236, DMEC, AE, "Trigger name too long" },
+  { 4237, DMEC, AE, "Too many triggers" },
+  { 4238, DMEC, AE, "Trigger not found" },
+  { 4239, DMEC, AE, "Trigger with given name already exists"},
+  { 4240, DMEC, AE, "Unsupported trigger type"},
+  { 4241, DMEC, AE, "Index name too long" },
+  { 4242, DMEC, AE, "Too many indexes" },
+  { 4243, DMEC, AE, "Index not found" },
+  { 4244, HA_ERR_TABLE_EXIST, OE, "Index or table with given name already exists" },
+  { 4247, DMEC, AE, "Illegal index/trigger create/drop/alter request" },
+  { 4248, DMEC, AE, "Trigger/index name invalid" },
+  { 4249, DMEC, AE, "Invalid table" },
+  { 4250, DMEC, AE, "Invalid index type or index logging option" },
+  { 4251, HA_ERR_FOUND_DUPP_UNIQUE, AE, "Cannot create unique index, duplicate keys
found" },
+  { 4252, DMEC, AE, "Failed to allocate space for index" },
+  { 4253, DMEC, AE, "Failed to create index table" },
+  { 4254, DMEC, AE, "Table not an index table" },
+  { 4255, DMEC, AE, "Hash index attributes must be specified in same order as table
attributes" },
+  { 4258, DMEC, AE, "Cannot create unique index, duplicate attributes found in
definition" },
+  { 4259, DMEC, AE, "Invalid set of range scan bounds" },
+  { 4260, DMEC, UD, "NdbScanFilter: Operator is not defined in NdbScanFilter::Group"},
+  { 4261, DMEC, UD, "NdbScanFilter: Column is NULL"},
+  { 4262, DMEC, UD, "NdbScanFilter: Condition is out of bounds"},
+  { 4263, DMEC, IE, "Invalid blob attributes or invalid blob parts table" },
+  { 4264, DMEC, AE, "Invalid usage of blob attribute" },
+  { 4265, DMEC, AE, "The method is not valid in current blob state" },
+  { 4266, DMEC, AE, "Invalid blob seek position" },
+  { 4267, DMEC, IE, "Corrupted blob value" },
+  { 4268, DMEC, IE, "Error in blob head update forced rollback of transaction" },
+  { 4269, DMEC, IE, "No connection to ndb management server" },
+  { 4270, DMEC, IE, "Unknown blob error" },
+  { 4335, DMEC, AE, "Only one autoincrement column allowed per table. Having a table
without primary key uses an autoincremented hidden key, i.e. a table without a primary
key can not have an autoincremented column" },
+  { 4271, DMEC, AE, "Invalid index object, not retrieved via getIndex()" },
+  { 4272, DMEC, AE, "Table definition has undefined column" },
+  { 4273, DMEC, IE, "No blob table in dict cache" },
+  { 4274, DMEC, IE, "Corrupted main table PK in blob operation" },
+  { 4275, DMEC, AE, "The blob method is incompatible with operation type or lock mode" }
 };
 
 static
@@ -573,6 +659,7 @@ ErrorStatusClassification StatusClassifi
   { ST_T, OL, "Overload error"},
   { ST_T, TO, "Timeout expired"},
   { ST_T, NS, "Node shutdown"},
+  { ST_T, IT, "Internal temporary"},
   
   { ST_U , UR, "Unknown result error"},
   { ST_U , UE, "Unknown error code"},
@@ -613,6 +700,7 @@ ndberror_update(ndberror_struct * error)
     if(ErrorCodes[i].code == error->code){
       error->classification = ErrorCodes[i].classification;
       error->message        = ErrorCodes[i].message;
+      error->mysql_code     = ErrorCodes[i].mysql_code;
       found = 1;
       break;
     }
@@ -621,6 +709,7 @@ ndberror_update(ndberror_struct * error)
   if(!found){
     error->classification = UE;
     error->message        = "Unknown error code";
+    error->mysql_code     = DMEC;
   }
 
   found = 0;
@@ -638,6 +727,7 @@ ndberror_update(ndberror_struct * error)
   error->details = 0;
 }
 
+#if CHECK_ERRORCODES
 int
 checkErrorCodes(){
   int i, j;
@@ -654,7 +744,6 @@ checkErrorCodes(){
 
 /*static const int a = checkErrorCodes();*/
 
-#if CHECK_ERRORCODES
 int main(void){
   checkErrorCodes();
   return 0;
Thread
bk commit into 5.1 tree (elliot:1.2216)Elliot Murphy25 Jun