List:Commits« Previous MessageNext Message »
From:Jonas Oreland Date:May 11 2011 11:03am
Subject:bzr commit into mysql-5.1-telco-7.0 branch (jonas:4367) Bug#60484
View as plain text  
#At file:///home/jonas/src/telco-7.0/ based on revid:jonas@stripped

 4367 Jonas Oreland	2011-05-11
      ndb - bug#60484 - also rename blob tables when changing db/schema

    modified:
      mysql-test/suite/ndb/r/ndb_rename.result
      mysql-test/suite/ndb/t/ndb_rename.test
      storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp
      storage/ndb/src/kernel/blocks/dbdict/Dbdict.hpp
      storage/ndb/src/ndbapi/DictCache.cpp
      storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp
      storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp
=== modified file 'mysql-test/suite/ndb/r/ndb_rename.result'
--- a/mysql-test/suite/ndb/r/ndb_rename.result	2007-06-27 12:28:02 +0000
+++ b/mysql-test/suite/ndb/r/ndb_rename.result	2011-05-11 11:03:10 +0000
@@ -21,4 +21,10 @@ SELECT * FROM ndbtest.t2 WHERE attr1 = 1
 pk1	attr1	attr2	attr3
 1	1	1	one
 drop table ndbtest.t2;
+create table t1 (
+pk1 INT NOT NULL PRIMARY KEY,
+b blob
+) engine = ndbcluster;
+alter table t1 rename ndbtest.t1;
+drop table ndbtest.t1;
 drop database ndbtest;

=== modified file 'mysql-test/suite/ndb/t/ndb_rename.test'
--- a/mysql-test/suite/ndb/t/ndb_rename.test	2007-11-29 10:29:35 +0000
+++ b/mysql-test/suite/ndb/t/ndb_rename.test	2011-05-11 11:03:10 +0000
@@ -30,6 +30,15 @@ alter table t2 rename ndbtest.t2;
 SELECT * FROM ndbtest.t2 WHERE attr1 = 1;
 
 drop table ndbtest.t2;
+
+create table t1 (
+  pk1 INT NOT NULL PRIMARY KEY,
+  b blob
+) engine = ndbcluster;
+
+alter table t1 rename ndbtest.t1;
+drop table ndbtest.t1;
+
 drop database ndbtest;
 
 # End of 4.1 tests

=== modified file 'storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp'
--- a/storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp	2011-04-11 13:36:12 +0000
+++ b/storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp	2011-05-11 11:03:10 +0000
@@ -8028,9 +8028,23 @@ Dbdict::alterTable_parse(Signal* signal,
 
     // the new temporary table record seized from pool
     newTablePtr = parseRecord.tablePtr;
+    alterTabPtr.p->m_newTable_realObjectId = newTablePtr.p->tableId;
     newTablePtr.p->tableId = impl_req->tableId; // set correct table id...(not the temporary)
   }
 
+
+  {
+    /**
+     * Mark SchemaObject as in-use so that it's won't be found by other op
+     *   choose a state that will be automatically cleaned incase we crash
+     */
+    SchemaFile::TableEntry * objEntry =
+      objEntry = getTableEntry(alterTabPtr.p->m_newTable_realObjectId);
+    objEntry->m_tableType = DictTabInfo::SchemaTransaction;
+    objEntry->m_tableState = SchemaFile::SF_STARTED;
+    objEntry->m_transId = trans_ptr.p->m_transId + 1;
+  }
+
   // set the new version now
   impl_req->newTableVersion =
     newTablePtr.p->tableVersion =
@@ -9469,6 +9483,15 @@ Dbdict::alterTable_fromCommitComplete(Si
 	       JBB, ptr, 1);
   }
 
+  {
+    // Remark object as free
+    SchemaFile::TableEntry * objEntry =
+      objEntry = getTableEntry(alterTabPtr.p->m_newTable_realObjectId);
+    objEntry->m_tableType = DictTabInfo::SchemaTransaction;
+    objEntry->m_tableState = SchemaFile::SF_UNUSED;
+    objEntry->m_transId = 0;
+  }
+
   releaseTableObject(alterTabPtr.p->m_newTablePtr.i, false);
   sendTransConf(signal, op_ptr);
 }
@@ -9551,6 +9574,16 @@ Dbdict::alterTable_abortParse(Signal* si
   if (!newTablePtr.isNull()) {
     jam();
     // release the temporary work table
+
+    {
+      // Remark object as free
+      SchemaFile::TableEntry * objEntry =
+        objEntry = getTableEntry(alterTabPtr.p->m_newTable_realObjectId);
+      objEntry->m_tableType = DictTabInfo::SchemaTransaction;
+      objEntry->m_tableState = SchemaFile::SF_UNUSED;
+      objEntry->m_transId = 0;
+    }
+
     releaseTableObject(newTablePtr.i, false);
     newTablePtr.setNull();
   }

=== modified file 'storage/ndb/src/kernel/blocks/dbdict/Dbdict.hpp'
--- a/storage/ndb/src/kernel/blocks/dbdict/Dbdict.hpp	2011-02-16 14:53:53 +0000
+++ b/storage/ndb/src/kernel/blocks/dbdict/Dbdict.hpp	2011-05-11 11:03:10 +0000
@@ -2365,6 +2365,7 @@ private:
     // current and new temporary work table
     TableRecordPtr m_tablePtr;
     TableRecordPtr m_newTablePtr;
+    Uint32 m_newTable_realObjectId;
 
     // before image
     RopeHandle m_oldTableName;

=== modified file 'storage/ndb/src/ndbapi/DictCache.cpp'
--- a/storage/ndb/src/ndbapi/DictCache.cpp	2011-02-01 23:27:25 +0000
+++ b/storage/ndb/src/ndbapi/DictCache.cpp	2011-05-11 11:03:10 +0000
@@ -457,7 +457,6 @@ GlobalDictCache::alter_table_rep(const c
 				 bool altered)
 {
   DBUG_ENTER("GlobalDictCache::alter_table_rep");
-  assert(! is_ndb_blob_table(name));
   const Uint32 len = (Uint32)strlen(name);
   Vector<TableVersion> * vers = 
     m_tableHash.getData(name, len);
@@ -467,6 +466,7 @@ GlobalDictCache::alter_table_rep(const c
     DBUG_VOID_RETURN;
   }
 
+  assert(! is_ndb_blob_table(name));
   const Uint32 sz = vers->size();
   if(sz == 0)
   {

=== modified file 'storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp'
--- a/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp	2011-02-23 12:15:04 +0000
+++ b/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp	2011-05-11 11:03:10 +0000
@@ -938,6 +938,72 @@ NdbTableImpl::getName() const
   return m_externalName.c_str();
 }
 
+int
+NdbTableImpl::getDbName(char buf[], size_t len) const
+{
+  if (len == 0)
+    return -1;
+
+  // db/schema/table
+  const char *ptr = m_internalName.c_str();
+
+  int pos = 0;
+  while (ptr[pos] && ptr[pos] != table_name_separator)
+  {
+    buf[pos] = ptr[pos];
+    pos++;
+
+    if (pos == len)
+      return -1;
+  }
+  buf[pos] = 0;
+  return 0;
+}
+
+int
+NdbTableImpl::getSchemaName(char buf[], size_t len) const
+{
+  if (len == 0)
+    return -1;
+
+  // db/schema/table
+  const char *ptr = m_internalName.c_str();
+
+  // skip over "db"
+  while (*ptr && *ptr != table_name_separator)
+    ptr++;
+
+  buf[0] = 0;
+  if (*ptr == table_name_separator)
+  {
+    ptr++;
+    int pos = 0;
+    while (ptr[pos] && ptr[pos] != table_name_separator)
+    {
+      buf[pos] = ptr[pos];
+      pos++;
+
+      if (pos == len)
+        return -1;
+    }
+    buf[pos] = 0;
+  }
+
+  return 0;
+}
+
+void
+NdbTableImpl::setDbSchema(const char * db, const char * schema)
+{
+  m_internalName.assfmt("%s%c%s%c%s",
+                        db,
+                        table_name_separator,
+                        schema,
+                        table_name_separator,
+                        m_externalName.c_str());
+  updateMysqlName();
+}
+
 void
 NdbTableImpl::computeAggregates()
 {
@@ -3090,7 +3156,8 @@ int NdbDictionaryImpl::alterTableGlobal(
 {
   DBUG_ENTER("NdbDictionaryImpl::alterTableGlobal");
   // Alter the table
-  int ret = m_receiver.alterTable(m_ndb, old_impl, impl);
+  Uint32 changeMask = 0;
+  int ret = m_receiver.alterTable(m_ndb, old_impl, impl, changeMask);
 #if ndb_bug41905
   old_impl.m_status = NdbDictionary::Object::Invalid;
 #endif
@@ -3107,18 +3174,96 @@ int NdbDictionaryImpl::alterTableGlobal(
     m_globalHash->unlock();
     if (ret != 0)
       m_error.code = 723;
+
+    printf("ret: %u AlterTableReq::getNameFlag(changeMask): %u\n",
+           ret, AlterTableReq::getNameFlag(changeMask));
+    fflush(stdout);
+    if (ret == 0 && AlterTableReq::getNameFlag(changeMask) != 0)
+    {
+      char db0[MAX_TAB_NAME_SIZE];
+      char db1[MAX_TAB_NAME_SIZE];
+      if (old_impl.getDbName(db0, sizeof(db0)) != 0)
+      {
+        m_error.code = 705;
+        DBUG_RETURN(-1);
+      }
+      if (impl.getDbName(db1, sizeof(db0)) != 0)
+      {
+        m_error.code = 705;
+        DBUG_RETURN(-1);
+      }
+
+      bool db_change = strcmp(db0, db1) != 0;
+      if (old_impl.getSchemaName(db0, sizeof(db0)) != 0)
+      {
+        m_error.code = 705;
+        DBUG_RETURN(-1);
+      }
+      if (impl.getSchemaName(db1, sizeof(db0)) != 0)
+      {
+        m_error.code = 705;
+        DBUG_RETURN(-1);
+      }
+
+      bool schema_change = strcmp(db0, db1) != 0;
+      if (db_change || schema_change)
+      {
+        if (renameBlobTables(old_impl, impl) != 0)
+        {
+          DBUG_RETURN(-1);
+        }
+      }
+    }
     DBUG_RETURN(ret);
   }
   ERR_RETURN(getNdbError(), ret);
 }
 
 int
+NdbDictionaryImpl::renameBlobTables(const NdbTableImpl & old_tab,
+                                    const NdbTableImpl & new_tab)
+{
+  if (old_tab.m_noOfBlobs == 0)
+    return 0;
+
+  char db[MAX_TAB_NAME_SIZE];
+  char schema[MAX_TAB_NAME_SIZE];
+  new_tab.getDbName(db, sizeof(db));
+  new_tab.getSchemaName(schema, sizeof(schema));
+
+  for (unsigned i = 0; i < old_tab.m_columns.size(); i++)
+  {
+    NdbColumnImpl & c = *old_tab.m_columns[i];
+    if (! c.getBlobType() || c.getPartSize() == 0)
+      continue;
+    NdbTableImpl* _bt = c.m_blobTable;
+    if (_bt == NULL)
+    {
+      continue; // "force" mode on
+    }
+
+    NdbDictionary::Table& bt = * _bt->m_facade;
+    NdbDictionary::Table new_bt(bt);
+    new_bt.m_impl.setDbSchema(db, schema);
+
+    Uint32 changeMask = 0;
+    int ret = m_receiver.alterTable(m_ndb, bt.m_impl, new_bt.m_impl,changeMask);
+    if (ret != 0)
+    {
+      return ret;
+    }
+    assert(AlterTableReq::getNameFlag(changeMask) != 0);
+  }
+  return 0;
+}
+
+int
 NdbDictInterface::alterTable(Ndb & ndb,
                              const NdbTableImpl &old_impl,
-                             NdbTableImpl &impl)
+                             NdbTableImpl &impl,
+                             Uint32 & change_mask)
 {
   int ret;
-  Uint32 change_mask;
 
   DBUG_ENTER("NdbDictInterface::alterTable");
 
@@ -3168,8 +3313,9 @@ NdbDictInterface::compChangeMask(const N
                       impl.m_internalName.c_str()));
   if(impl.m_internalName != old_impl.m_internalName)
   {
-    if (unlikely(is_ndb_blob_table(old_impl.m_externalName.c_str()) ||
-                 is_ndb_blob_table(impl.m_externalName.c_str())))
+    bool old_blob = is_ndb_blob_table(old_impl.m_externalName.c_str());
+    bool new_blob = is_ndb_blob_table(impl.m_externalName.c_str());
+    if (unlikely(old_blob != new_blob))
     {
       /* Attempt to alter to/from Blob part table name */
       DBUG_PRINT("info", ("Attempt to alter to/from Blob part table name"));
@@ -3260,7 +3406,9 @@ NdbDictInterface::compChangeMask(const N
          col->m_autoIncrement ||                   // ToDo: allow this?
 	 (col->getBlobType() && col->getPartSize())
          )
+      {
         goto invalid_alter_table;
+      }
     }
     AlterTableReq::setAddAttrFlag(change_mask, true);
   }

=== modified file 'storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp'
--- a/storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp	2011-02-23 12:15:04 +0000
+++ b/storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp	2011-05-11 11:03:10 +0000
@@ -185,14 +185,18 @@ public:
   int validate(NdbError& error);
 
   Uint32 m_primaryTableId;
-  BaseString m_internalName;
-  BaseString m_externalName;
-  BaseString m_mysqlName;
+  BaseString m_internalName; // db/schema/table
+  BaseString m_externalName; //           table
+  BaseString m_mysqlName;    //        db/table
   UtilBuffer m_frm; 
   Vector<Uint32> m_fd;
   Vector<Int32> m_range;
   NdbDictionary::Object::FragmentType m_fragmentType;
 
+  int getDbName(char * buf, size_t len) const;
+  int getSchemaName(char * buf, size_t len) const;
+  void setDbSchema(const char * db, const char * schema);
+
   /**
    * 
    */
@@ -617,7 +621,7 @@ public:
   int createTable(class Ndb & ndb, NdbTableImpl &);
   bool supportedAlterTable(const NdbTableImpl &,
 			   NdbTableImpl &);
-  int alterTable(class Ndb & ndb, const NdbTableImpl &, NdbTableImpl &);
+  int alterTable(class Ndb & ndb, const NdbTableImpl &, NdbTableImpl&, Uint32&);
   void syncInternalName(Ndb & ndb, NdbTableImpl &impl);
   int compChangeMask(const NdbTableImpl &old_impl,
                      const NdbTableImpl &impl,
@@ -828,6 +832,7 @@ public:
   int dropTable(const char * name);
   int dropTable(NdbTableImpl &);
   int dropBlobTables(NdbTableImpl &);
+  int renameBlobTables(const NdbTableImpl &old_impl, const NdbTableImpl &impl);
   int invalidateObject(NdbTableImpl &);
   int removeCachedObject(NdbTableImpl &);
 


Attachment: [text/bzr-bundle] bzr/jonas@mysql.com-20110511110310-p70s70sk5c6h1fyd.bundle
Thread
bzr commit into mysql-5.1-telco-7.0 branch (jonas:4367) Bug#60484Jonas Oreland11 May