From: Mauritz Sundell Date: September 21 2012 2:02pm Subject: bzr push into mysql-5.1-telco-7.1 branch (mauritz.sundell:4614 to 4615) List-Archive: http://lists.mysql.com/commits/144850 Message-Id: <201209211402.q8LE2YSY003880@acsmt357.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 4615 Mauritz Sundell 2012-09-21 [merge] merge 7.0 -> 7.1 modified: mysql-test/suite/ndb/r/ndb_native_default_support.result storage/ndb/include/util/Vector.hpp 4614 Mauritz Sundell 2012-09-21 [merge] merge 7.0 -> 7.1 added: storage/ndb/include/util/ndb_math.h modified: mysql-test/suite/ndb/r/ndb_native_default_support.result storage/ndb/include/ndbapi/NdbDictionary.hpp storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp storage/ndb/src/ndbapi/NdbDictionary.cpp storage/ndb/test/include/NDBT_Table.hpp storage/ndb/test/ndbapi/testDict.cpp storage/ndb/test/run-test/daily-basic-tests.txt storage/ndb/test/src/NDBT_Table.cpp storage/ndb/tools/desc.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 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 -Vector::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 +Vector::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 +int +Vector::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 Vector::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 @@ -127,6 +168,8 @@ Vector::operator[](unsigned i) const template T & Vector::back(){ + if(m_size==0) + abort(); return (* this)[m_size - 1]; } @@ -134,17 +177,9 @@ template int Vector::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::push_back(const T & t){ } template -void +int Vector::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::push(const T & t, unsigned po } m_items[pos] = t; } + return 0; } template T& Vector::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::clear(){ template int Vector::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 Vector& Vector::operator=(const Vector& obj){ if(this != &obj){ clear(); + const int err = expand(obj.size()); + if (unlikely(err)) + abort(); for(unsigned i = 0; i int Vector::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::equal(const Vector& obj) c template 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& operator=(const MutexVector&); + T * m_items; unsigned m_size; unsigned m_incSize; unsigned m_arraySize; }; -template -MutexVector::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 +MutexVector::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 +int +MutexVector::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 @@ -310,6 +403,8 @@ MutexVector::operator[](unsigned i) c template T & MutexVector::back(){ + if(m_size==0) + abort(); return (* this)[m_size - 1]; } @@ -318,18 +413,12 @@ int MutexVector::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::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).