List:Internals« Previous MessageNext Message »
From:mikael Date:December 5 2005 3:59pm
Subject:bk commit into 5.1 tree (mikron:1.1982)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of mikron. When mikron 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.1982 05/12/05 16:59:19 mikron@stripped +2 -0
  WL 2747: Fix-up ndb_restore for user partitioned NDB tables
  Moved code to enable proper BackupPrinter behaviour
  Added code to handle calculation of number of partitions
  and set-up node groups by default

  storage/ndb/tools/restore/consumer_restore.cpp
    1.24 05/12/05 16:58:56 mikron@stripped +140 -10
    Moved code to enable proper BackupPrinter behaviour
    Added code to handle calculation of number of partitions
    and set-up node groups by default

  storage/ndb/tools/restore/Restore.cpp
    1.34 05/12/05 16:58:56 mikron@stripped +0 -77
    Moved code to enable proper BackupPrinter behaviour

# 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:	mikron
# Host:	mikael-ronstr-ms-dator.local
# Root:	/Users/mikron/wl2747

--- 1.33/storage/ndb/tools/restore/Restore.cpp	2005-12-05 17:03:28 +01:00
+++ 1.34/storage/ndb/tools/restore/Restore.cpp	2005-12-05 16:58:56 +01:00
@@ -212,37 +212,6 @@
     delete allAttributesDesc[i];
 }
 
-static bool default_nodegroups(NdbTableImpl *tableImpl)
-{
-  Uint16 *node_groups = (Uint16*)tableImpl->getFragmentData();
-  Uint32 no_ngs = tableImpl->getFragmentDataLen() >> 1;
-  Uint32 i;
-
-  if (node_groups[0] != 0)
-    return false; 
-  for (i = 1; i < no_ngs; i++) 
-  {
-    if (node_groups[i] != UNDEF_NODEGROUP)
-      return false;
-  }
-  return true;
-}
-
-
-static bool is_nodegroups_ok(NdbTableImpl *tableImpl)
-{
-  Uint16 *node_groups = (Uint16*)tableImpl->getFragmentData();
-  Uint32 no_ngs = tableImpl->getFragmentDataLen() >> 1;
-  Uint32 i;
-  Uint32 no_ngs_in_cluster;
-
-  do
-  {
-    if (node_groups[i] > no_ngs_in_cluster)
-      return false;
-  } while (++i < no_ngs);
-  return true;
-}
 
 // Parse dictTabInfo buffer and pushback to to vector storage 
 bool
@@ -259,52 +228,6 @@
     return false;
 
   debug << "parseTableInfo " << tableImpl->getName() << " done" << endl;
-  if (tableImpl->m_default_no_part_flag)
-  {
-    /*
-      Table was defined with default number of partitions. We can restore
-      it with whatever is the default in this cluster.
-      We use the max_rows parameter in calculating the default number.
-    */
-  }
-  else
-  {
-    /*
-      Table was defined with specific number of partitions. It should be
-      restored with the same number of partitions. If possible it should
-      be restored in the same node groups as the backup was created in.
-      If this is not possible we check a program parameter to see if the
-      user has requested us to override this error. In any case we will
-      generate a warning message about it.
-    */
-    if (default_nodegroups(tableImpl))
-    {
-      /*
-        We use default node groups and so we don't need to do anything.
-      */
-      ;
-    }
-    else if (is_nodegroups_ok(tableImpl))
-    {
-      /*
-        The node groups in the array are ok to restore on this cluster.
-        Simply proceed
-      */
-      ;
-    }
-    else
-    {
-      /*
-        The user on the cluster where the backup was created had specified
-        specific node groups for partitions. Some of these node groups
-        didn't exist on this cluster. We will warn the user of this and
-        only if the user has set a flag to override this will we continue
-        restoring the table.
-      */
-    }
-  }
-  tableImpl->m_fd.clear();
-  tableImpl->m_fragmentType = NdbDictionary::Object::FragAllSmall;
   TableS * table = new TableS(m_fileHeader.NdbVersion, tableImpl);
   if(table == NULL) {
     return false;

--- 1.23/storage/ndb/tools/restore/consumer_restore.cpp	2005-12-05 17:03:29 +01:00
+++ 1.24/storage/ndb/tools/restore/consumer_restore.cpp	2005-12-05 16:58:56 +01:00
@@ -152,6 +152,56 @@
   return ret;
 }
 
+
+static bool default_nodegroups(NdbDictionary::Table *table)
+{
+  Uint16 *node_groups = (Uint16*)table->getFragmentData();
+  Uint32 no_parts = table->getFragmentDataLen() >> 1;
+  Uint32 i;
+
+  if (node_groups[0] != 0)
+    return false; 
+  for (i = 1; i < no_parts; i++) 
+  {
+    if (node_groups[i] != UNDEF_NODEGROUP)
+      return false;
+  }
+  return true;
+}
+
+
+static Uint32 get_no_fragments(Uint64 max_rows, Uint32 no_nodes;)
+{
+  Uint32 acc_row_size = 27;
+  Uint32 acc_fragment_size = 512*1024*1024;
+  Uint32 no_parts= (max_rows*acc_row_size)/acc_fragment_size + 1;
+  Uint32 reported_parts = no_nodes; 
+  while (reported_parts < no_parts && ++i < 4 &&
+         (reported_parts + no_parts) < MAX_PARTITIONS)
+    reported_parts+= no_nodes;
+  if (reported_parts < no_parts)
+  {
+    err << "Table will be restored but will not be able to handle the maximum";
+    err << " amount of rows as requested" << endl;
+  }
+  return reported_parts;
+}
+
+
+static void set_default_nodegroups(NdbDictionary::Table *table)
+{
+  Uint32 no_parts = table->getFragmentCount();
+  Uint16 node_group[MAX_PARTITIONS];
+
+  node_group[0] = 0;
+  for (i = 1; i < no_parts; i++)
+  {
+    node_group[i] = UNDEF_NODEGROUP;
+  }
+  table->setFragmentData((const void*)node_group, 2 * node_parts);
+}
+
+
 bool
 BackupRestore::table(const TableS & table){
   if (!m_restore && !m_restore_meta)
@@ -182,18 +232,98 @@
   m_ndb->setSchemaName(split[1].c_str());
   
   NdbDictionary::Dictionary* dict = m_ndb->getDictionary();
-  if(m_restore_meta){
-    NdbDictionary::Table copy(*table.m_dictTable);
+  if(m_restore_meta)
+  {
+    bool node_group_flag= false;
+    do
+    {
+      NdbDictionary::Table copy(*table.m_dictTable);
 
-    copy.setName(split[2].c_str());
+      copy.setName(split[2].c_str());
+      if (table->getDefaultNoPartitionsFlag())
+      {
+        /*
+          Table was defined with default number of partitions. We can restore
+          it with whatever is the default in this cluster.
+          We use the max_rows parameter in calculating the default number.
+        */
+        Uint32 no_nodes = m_cluster_connection->no_db_nodes();
+        table->setFragmentCount(get_no_fragments(table->getMaxRows(),
+                                no_nodes));
+        set_default_nodegroups(table);
+      }
+      else
+      {
+        /*
+          Table was defined with specific number of partitions. It should be
+          restored with the same number of partitions. If possible it should
+          be restored in the same node groups as the backup was created in.
+          If this is not possible we check a program parameter to see if the
+          user has requested us to override this error. In any case we will
+          generate a warning message about it.
+        */
+        if (default_nodegroups(table))
+        {
+          /*
+            We use default node groups and so we don't need to do anything.
+          */
+          ;
+        }
+        else if (node_group_change)
+        {
+          /*
+            We failed restoring with the original definition of the node
+            groups. We'll restore using the default set-up of node groups
+            instead. Set new fragmentation data on the table.
+          */
+          set_default_nodegroups(table);
+        }
+      }
 
-    if (dict->createTable(copy) == -1) 
-    {
-      err << "Create table " << table.getTableName() << " failed: "
-	  << dict->getNdbError() << endl;
-      return false;
-    }
-    info << "Successfully restored table " << table.getTableName()<< endl ;
+      if (dict->createTable(copy) == -1) 
+      {
+        err << "Create table " << table.getTableName() << " failed: "
+            << dict->getNdbError() << endl;
+        if (dict->getNdbError().code == 771)
+        {
+          /*
+            The user on the cluster where the backup was created had specified
+            specific node groups for partitions. Some of these node groups
+            didn't exist on this cluster. We will warn the user of this and
+            only if the user has set a flag to override this will we continue
+            restoring the table.
+          */
+          if (!node_group_change && parameter_retry_set)
+          {
+            err << "We will retry with default settings on node groups";
+            err << endl << "WARNING: This will create a mismatch between";
+            err << " the frm file and the table" << endl;
+            err << "Please perform an ALTER TABLE of this table after"
+            err << "restoring it" << endl;
+            node_group_change = true;
+            continue;
+          }
+          else (!node_group_change)
+          {
+            err << "Attempted to restore a user defined table to a smaller"
+            err << " cluster resulted in " << endl;
+            err << "trying to place partition in non-existing node group";
+            err << endl << "It is possible to use --restore-override to"
+            err << " restore with default node groups although this creates"
+            err << " inconsistency between frm file and table" << endl;
+            err << "thus requiring an ALTER TABLE immediately after restore";
+            err << "has completed" << endl;
+          }
+          return false;
+        }
+        else
+        {
+          return false;
+        }
+      }
+      info << "Successfully restored table " << table.getTableName()<< endl ;
+      break;
+    } while (true);
   }  
   
   const NdbDictionary::Table* tab = dict->getTable(split[2].c_str());
Thread
bk commit into 5.1 tree (mikron:1.1982)mikael7 Dec