List:Commits« Previous MessageNext Message »
From:Martin Skold Date:October 8 2009 9:48am
Subject:bzr commit into mysql-5.1-telco-6.2 branch (Martin.Skold:3016) Bug#47865
View as plain text  
#At file:///home/marty/MySQL/mysql-5.1-telco-6.2/

 3016 Martin Skold	2009-10-08
      Bug#47865  SHOW CREATE TABLE does not show the current auto_increment number for ndb tables: reading auto_increment value in ha_ndbcluster::update_create_info
      modified:
        mysql-test/suite/ndb/r/ndb_alter_table_backup.result
        sql/ha_ndbcluster.cc

=== modified file 'mysql-test/suite/ndb/r/ndb_alter_table_backup.result'
--- a/mysql-test/suite/ndb/r/ndb_alter_table_backup.result	2007-11-07 03:48:11 +0000
+++ b/mysql-test/suite/ndb/r/ndb_alter_table_backup.result	2009-10-08 09:48:07 +0000
@@ -17,7 +17,7 @@ t1	CREATE TABLE `t1` (
   `f` datetime DEFAULT NULL,
   `g` binary(4) DEFAULT NULL,
   PRIMARY KEY (`a`)
-) ENGINE=ndbcluster DEFAULT CHARSET=latin1
+) ENGINE=ndbcluster AUTO_INCREMENT=31 DEFAULT CHARSET=latin1
 SELECT * FROM t1 WHERE a = 1 or a = 10 or a = 20 or a = 30 ORDER BY a;
 a	b	c	d	e	f	g
 1	5	3.40282e+38	1.2686868689898e+308	666.66	2007-10-23 23:23:23	1111
@@ -42,7 +42,7 @@ t1	CREATE TABLE `t1` (
   `f` datetime DEFAULT NULL,
   `g` binary(4) DEFAULT NULL,
   PRIMARY KEY (`a`)
-) ENGINE=ndbcluster DEFAULT CHARSET=latin1
+) ENGINE=ndbcluster AUTO_INCREMENT=31 DEFAULT CHARSET=latin1
 SELECT * FROM t1 WHERE a = 1 or a = 10 or a = 20 or a = 30 ORDER BY a;
 a	b	c	d	e	f	g
 1	5	3.40282e+38	1.2686868689898e+308	666.66	2007-10-23 23:23:23	1111

=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2009-10-07 15:53:06 +0000
+++ b/sql/ha_ndbcluster.cc	2009-10-08 09:48:07 +0000
@@ -5412,7 +5412,48 @@ static int create_ndb_column(THD *thd,
 void ha_ndbcluster::update_create_info(HA_CREATE_INFO *create_info)
 {
   DBUG_ENTER("update_create_info");
+  THD *thd= current_thd;
   TABLE_SHARE *share= table->s;
+  const NDBTAB *ndbtab= m_table;
+  Ndb *ndb= check_ndb_in_thd(thd);
+
+  /*
+    Find any initial auto_increment value
+   */
+  for (uint i= 0; i < table->s->fields; i++) 
+  {
+    Field *field= table->field[i];
+    if (field->flags & AUTO_INCREMENT_FLAG)
+    {
+      ulonglong auto_value;
+      uint retries= NDB_AUTO_INCREMENT_RETRIES;
+      int retry_sleep= 30; /* 30 milliseconds, transaction */
+      for (;;)
+      {
+        Ndb_tuple_id_range_guard g(m_share);
+        if (ndb->readAutoIncrementValue(ndbtab, g.range, auto_value))
+        {
+          if (--retries && !thd->killed &&
+              ndb->getNdbError().status == NdbError::TemporaryError)
+          {
+            do_retry_sleep(retry_sleep);
+            continue;
+          }
+          const NdbError err= ndb->getNdbError();
+          sql_print_error("Error %lu in ::update_create_info(): %s",
+                          (ulong) err.code, err.message);
+          DBUG_VOID_RETURN;
+        }
+        break;
+      }
+      if (auto_value > 1)
+      {
+        create_info->auto_increment_value= auto_value;
+      }
+      break;
+    }
+  }
+
   if (share->mysql_version < MYSQL_VERSION_TABLESPACE_IN_FRM)
   {
      DBUG_PRINT("info", ("Restored an old table %s, pre-frm_version 7", 
@@ -5420,13 +5461,10 @@ void ha_ndbcluster::update_create_info(H
      if (!create_info->tablespace && !share->tablespace)
      {
        DBUG_PRINT("info", ("Checking for tablespace in ndb"));
-       THD *thd= current_thd;
-       Ndb *ndb= check_ndb_in_thd(thd);
        NDBDICT *ndbdict= ndb->getDictionary();
        NdbError ndberr;
        Uint32 id;
        ndb->setDatabaseName(m_dbname);
-       const NDBTAB *ndbtab= m_table;
        DBUG_ASSERT(ndbtab != NULL);
        if (!ndbtab->getTablespace(&id))
        {

Thread
bzr commit into mysql-5.1-telco-6.2 branch (Martin.Skold:3016) Bug#47865Martin Skold8 Oct