List:Commits« Previous MessageNext Message »
From:Mauritz Sundell Date:September 21 2012 1:58pm
Subject:bzr push into mysql-5.1-telco-7.0 branch (mauritz.sundell:4987 to 4989)
View as plain text  
 4989 Mauritz Sundell	2012-09-21
      ndb - regenerate result for test ndb.ndb_native_default_support

    modified:
      mysql-test/suite/ndb/r/ndb_native_default_support.result
 4988 Mauritz Sundell	2012-09-21
      ndb - backport vector changes from 7.2
      
      revision-id: ole.john.aske@stripped

    modified:
      storage/ndb/include/util/Vector.hpp
 4987 Mauritz Sundell	2012-09-21
      ndb - make online reorg change hashmap size if appropriate
      
      Bug #14645319ONLINE REORGANIZE CAN NOT USE BIGGER HASHMAP ON OLD TABLES
      
      before online reorg never changed hashmap size.
      
      now it either keeps the old size or use the hardcoded
      default hashmap size.
      
      changing hashmap size only occur if the number of
      fragments have increased and the old hashmap size
      is not a multiple of the new fragment count.
      also the bigger hashmap size must be a multiple of
      the old hashmap size to guarantee that data are moved
      from old fragments to new fragments only, therefore
      the old hashmap size is used if that is not true.
      
      this means that after an upgrade from a ndb version
      supporting a smaller hashmap size to a ndb version
      supporting a bigger hashmap size, will be downgradable
      as long as no new tables are created or an online
      reorg have been run after changing the number of
      fragments (implictly by adding nodes, or changing maxrows,
      or explicitly added partitions).
      
      NOTE: neither unique index nor blob tables are reorganized.

    added:
      storage/ndb/include/util/ndb_math.h
    modified:
      storage/ndb/include/ndbapi/NdbDictionary.hpp
      storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp
      storage/ndb/src/ndbapi/NdbDictionary.cpp
      storage/ndb/test/ndbapi/testDict.cpp
=== modified file 'mysql-test/suite/ndb/r/ndb_native_default_support.result'
--- a/mysql-test/suite/ndb/r/ndb_native_default_support.result	2012-09-21 12:25:04 +0000
+++ b/mysql-test/suite/ndb/r/ndb_native_default_support.result	2012-09-21 13:57:28 +0000
@@ -143,7 +143,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 i Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR
 j Int NULL AT=FIXED ST=MEMORY DEFAULT 6
@@ -182,7 +182,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 pk Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR
 b1 Bit(3) NULL AT=FIXED ST=MEMORY DEFAULT H'0x7
@@ -365,7 +365,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 i Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR
 j Int NULL AT=FIXED ST=MEMORY DEFAULT 6
@@ -456,7 +456,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 i Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR
 j Int NULL AT=FIXED ST=MEMORY DEFAULT 666
@@ -504,7 +504,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Int NULL AT=FIXED ST=MEMORY DEFAULT 12
@@ -546,7 +546,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Int NULL AT=FIXED ST=MEMORY DEFAULT 12
@@ -596,7 +596,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Binary(10) NULL AT=FIXED ST=MEMORY DEFAULT 0x4142430045464748494A
@@ -640,7 +640,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Timestamp NOT NULL AT=FIXED ST=MEMORY
@@ -683,7 +683,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Timestamp NOT NULL AT=FIXED ST=MEMORY
@@ -726,7 +726,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Timestamp NOT NULL AT=FIXED ST=MEMORY
@@ -771,7 +771,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Timestamp NOT NULL AT=FIXED ST=MEMORY
@@ -819,7 +819,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Timestamp NOT NULL AT=FIXED ST=MEMORY DEFAULT 0
@@ -862,7 +862,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Timestamp NOT NULL AT=FIXED ST=MEMORY DEFAULT 235861201
@@ -907,7 +907,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Timestamp NOT NULL AT=FIXED ST=MEMORY DEFAULT 235861201
@@ -953,7 +953,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Timestamp NOT NULL AT=FIXED ST=MEMORY DEFAULT 235861201
@@ -1003,7 +1003,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Timestamp NOT NULL AT=FIXED ST=MEMORY DEFAULT 235861201
@@ -1047,7 +1047,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Timestamp NULL AT=FIXED ST=MEMORY
@@ -1090,7 +1090,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Timestamp NULL AT=FIXED ST=MEMORY DEFAULT 0
@@ -1133,7 +1133,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Timestamp NULL AT=FIXED ST=MEMORY DEFAULT 235861201
@@ -1176,7 +1176,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Timestamp NULL AT=FIXED ST=MEMORY
@@ -1221,7 +1221,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Timestamp NULL AT=FIXED ST=MEMORY
@@ -1269,7 +1269,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Timestamp NULL AT=FIXED ST=MEMORY
@@ -1358,7 +1358,7 @@ FragmentCount: 2
 ExtraRowGciBits: 0
 ExtraRowAuthorBits: 0
 TableStatus: Retrieved
-HashMap: DEFAULT-HASHMAP-3840-2
+HashMap: DEFAULT-HASHMAP-240-2
 -- Attributes --
 i Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR
 j Bigint NOT NULL AT=FIXED ST=MEMORY DEFAULT 6006

=== modified file 'storage/ndb/include/util/Vector.hpp'
--- a/storage/ndb/include/util/Vector.hpp	2011-06-30 15:59:25 +0000
+++ b/storage/ndb/include/util/Vector.hpp	2012-09-21 13:51:42 +0000
@@ -24,7 +24,8 @@
 template<class T>
 class Vector {
 public:
-  Vector(int sz = 10);
+  Vector(unsigned sz = 10, unsigned inc_sz = 0);
+  int expand(unsigned sz);
   ~Vector();
 
   T& operator[](unsigned i);
@@ -32,7 +33,7 @@ public:
   unsigned size() const { return m_size; };
   
   int push_back(const T &);
-  void push(const T&, unsigned pos);
+  int push(const T&, unsigned pos);
   T& set(T&, unsigned pos, T& fill_obj);
   T& back();
   
@@ -63,40 +64,80 @@ private:
   unsigned m_arraySize;
 };
 
-template<class T>
-Vector<T>::Vector(int i){
-  m_items = new T[i];
+/**
+ * BEWARE: Constructing Vector with initial size > 0 is
+ * unsafe wrt. catching 'out of memory' errors.
+ * (C'tor doesn't return error code)
+ * Instead construct Vector with size==0, and then
+ * expand() it to the wanted initial size.
+ */
+template<class T>
+Vector<T>::Vector(unsigned sz, unsigned inc_sz):
+  m_items(NULL),
+  m_size(0),
+  m_incSize((inc_sz > 0) ? inc_sz : 50),
+  m_arraySize(0)
+{
+  if (sz == 0)
+    return;
+
+  m_items = new T[sz];
   if (m_items == NULL)
   {
     errno = ENOMEM;
-    m_size = 0;
-    m_arraySize = 0;
-    m_incSize = 0;
     return;
   }
-  m_size = 0;
-  m_arraySize = i;
-  m_incSize = 50;
+  m_arraySize = sz;
+}
+
+template<class T>
+int
+Vector<T>::expand(unsigned sz){
+  if (sz <= m_size)
+    return 0;
+
+  T * tmp = new T[sz];
+  if(tmp == NULL)
+  {
+    errno = ENOMEM;
+    return -1;
+  }
+  for (unsigned i = 0; i < m_size; i++)
+    tmp[i] = m_items[i];
+  delete[] m_items;
+  m_items = tmp;
+  m_arraySize = sz;
+  return 0;
 }
 
+/**
+ * BEWARE: Copy-constructing a Vector is
+ * unsafe wrt. catching 'out of memory' errors.
+ * (C'tor doesn't return error code)
+ * Instead construct empty Vector (size==0),
+ * and then assign() it the initial contents.
+ */
 template<class T>
 Vector<T>::Vector(const Vector& src):
-  m_items(new T[src.m_size]),
-  m_size(src.m_size),
+  m_items(NULL),
+  m_size(0),
   m_incSize(src.m_incSize),
-  m_arraySize(src.m_size)
-  
+  m_arraySize(0)
 {
+  const unsigned sz = src.m_size;
+  if (sz == 0)
+    return;
+
+  m_items = new T[sz];
   if (unlikely(m_items == NULL)){
     errno = ENOMEM;
-    m_size = 0;
-    m_arraySize = 0;
-    m_incSize = 0;
     return;
   }
-  for(unsigned i = 0; i < m_size; i++){
+  for(unsigned i = 0; i < sz; i++){
     m_items[i] = src.m_items[i];
   }
+  m_arraySize = sz;
+  m_size = sz;
 }
 
 template<class T>
@@ -127,6 +168,8 @@ Vector<T>::operator[](unsigned i) const
 template<class T>
 T &
 Vector<T>::back(){
+  if(m_size==0)
+    abort();
   return (* this)[m_size - 1];
 }
 
@@ -134,17 +177,9 @@ template<class T>
 int
 Vector<T>::push_back(const T & t){
   if(m_size == m_arraySize){
-    T * tmp = new T [m_arraySize + m_incSize];
-    if(tmp == NULL)
-    {
-      errno = ENOMEM;
-      return -1;
-    }
-    for (unsigned k = 0; k < m_size; k++)
-      tmp[k] = m_items[k];
-    delete[] m_items;
-    m_items = tmp;
-    m_arraySize = m_arraySize + m_incSize;
+    const int err = expand(m_arraySize + m_incSize);
+    if (unlikely(err))
+      return err;
   }
   m_items[m_size] = t;
   m_size++;
@@ -152,10 +187,12 @@ Vector<T>::push_back(const T & t){
 }
 
 template<class T>
-void
+int
 Vector<T>::push(const T & t, unsigned pos)
 {
-  push_back(t);
+  const int err = push_back(t);
+  if (unlikely(err))
+    return err;
   if (pos < m_size - 1)
   {
     for(unsigned i = m_size - 1; i > pos; i--)
@@ -164,13 +201,15 @@ Vector<T>::push(const T & t, unsigned po
     }
     m_items[pos] = t;
   }
+  return 0;
 }
 
 template<class T>
 T&
 Vector<T>::set(T & t, unsigned pos, T& fill_obj)
 {
-  fill(pos, fill_obj);
+  if (fill(pos, fill_obj))
+    abort();
   T& ret = m_items[pos];
   m_items[pos] = t;
   return ret;
@@ -196,19 +235,31 @@ Vector<T>::clear(){
 template<class T>
 int
 Vector<T>::fill(unsigned new_size, T & obj){
+  const int err = expand(new_size);
+  if (unlikely(err))
+    return err;
   while(m_size <= new_size)
     if (push_back(obj))
       return -1;
   return 0;
 }
 
+/**
+ * 'operator=' will 'abort()' on 'out of memory' errors.
+ *  You may prefer using ::assign()' which returns
+ *  an error code instead of aborting.
+ */
 template<class T>
 Vector<T>& 
 Vector<T>::operator=(const Vector<T>& obj){
   if(this != &obj){
     clear();
+    const int err = expand(obj.size());
+    if (unlikely(err))
+      abort();
     for(unsigned i = 0; i<obj.size(); i++){
-      push_back(obj[i]);
+      if (push_back(obj[i]))
+        abort();
     }
   }
   return * this;
@@ -218,12 +269,19 @@ template<class T>
 int
 Vector<T>::assign(const T* src, unsigned cnt)
 {
+  if (getBase() == src)
+    return 0;  // Self-assign is a NOOP
+
   clear();
+  const int err = expand(cnt);
+  if (unlikely(err))
+    return err;
+
   for (unsigned i = 0; i<cnt; i++)
   {
-    int ret;
-    if ((ret = push_back(src[i])))
-      return ret;
+    const int err = push_back(src[i]);
+    if (unlikely(err))
+      return err;
   }
   return 0;
 }
@@ -241,7 +299,8 @@ Vector<T>::equal(const Vector<T>& obj) c
 template<class T>
 class MutexVector : public NdbLockable {
 public:
-  MutexVector(int sz = 10);
+  MutexVector(unsigned sz = 10, unsigned inc_sz = 0);
+  int expand(unsigned sz);
   ~MutexVector();
 
   T& operator[](unsigned i);
@@ -260,26 +319,60 @@ public:
 
   int fill(unsigned new_size, T & obj);
 private:
+  // Don't allow copy and assignment of MutexVector
+  MutexVector(const MutexVector&); 
+  MutexVector<T>& operator=(const MutexVector<T>&);
+
   T * m_items;
   unsigned m_size;
   unsigned m_incSize;
   unsigned m_arraySize;
 };
 
-template<class T>
-MutexVector<T>::MutexVector(int i){
-  m_items = new T[i];
+/**
+ * BEWARE: Constructing MutexVector with initial size > 0 is
+ * unsafe wrt. catching 'out of memory' errors.
+ * (C'tor doesn't return error code)
+ * Instead construct MutexVector with size==0, and then
+ * expand() it to the wanted initial size.
+ */
+template<class T>
+MutexVector<T>::MutexVector(unsigned sz, unsigned inc_sz):
+  m_items(NULL),
+  m_size(0),
+  m_incSize((inc_sz > 0) ? inc_sz : 50),
+  m_arraySize(0)
+{
+  if (sz == 0)
+    return;
+
+  m_items = new T[sz];
   if (m_items == NULL)
   {
     errno = ENOMEM;
-    m_size = 0;
-    m_arraySize = 0;
-    m_incSize = 0;
     return;
   }
-  m_size = 0;
-  m_arraySize = i;
-  m_incSize = 50;
+  m_arraySize = sz;
+}
+
+template<class T>
+int
+MutexVector<T>::expand(unsigned sz){
+  if (sz <= m_size)
+    return 0;
+
+  T * tmp = new T[sz];
+  if(tmp == NULL)
+  {
+    errno = ENOMEM;
+    return -1;
+  }
+  for (unsigned i = 0; i < m_size; i++)
+    tmp[i] = m_items[i];
+  delete[] m_items;
+  m_items = tmp;
+  m_arraySize = sz;
+  return 0;
 }
 
 template<class T>
@@ -310,6 +403,8 @@ MutexVector<T>::operator[](unsigned i) c
 template<class T>
 T &
 MutexVector<T>::back(){
+  if(m_size==0)
+    abort();
   return (* this)[m_size - 1];
 }
 
@@ -318,18 +413,12 @@ int
 MutexVector<T>::push_back(const T & t){
   lock();
   if(m_size == m_arraySize){
-    T * tmp = new T [m_arraySize + m_incSize];
-    if (tmp == NULL)
+    const int err = expand(m_arraySize + m_incSize);
+    if (unlikely(err))
     {
-      errno = ENOMEM;
       unlock();
-      return -1;
+      return err;
     }
-    for (unsigned k = 0; k < m_size; k++)
-      tmp[k] = m_items[k];
-    delete[] m_items;
-    m_items = tmp;
-    m_arraySize = m_arraySize + m_incSize;
   }
   m_items[m_size] = t;
   m_size++;
@@ -343,19 +432,13 @@ MutexVector<T>::push_back(const T & t, b
   if(lockMutex) 
     lock();
   if(m_size == m_arraySize){
-    T * tmp = new T [m_arraySize + m_incSize];
-    if (tmp == NULL)
+    const int err = expand(m_arraySize + m_incSize);
+    if (unlikely(err))
     {
-      errno = ENOMEM;
       if(lockMutex) 
         unlock();
-      return -1;
+      return err;
     }
-    for (unsigned k = 0; k < m_size; k++)
-      tmp[k] = m_items[k];
-    delete[] m_items;
-    m_items = tmp;
-    m_arraySize = m_arraySize + m_incSize;
   }
   m_items[m_size] = t;
   m_size++;

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.1-telco-7.0 branch (mauritz.sundell:4987 to 4989) Mauritz Sundell21 Sep