Commit 43ebae40 authored by unknown's avatar unknown
Browse files

BUG#9626 Several serious errors reported by Valgrind in latest 5.0 bk tree

 - Fix several valgrind warnings.


ndb/include/kernel/AttributeList.hpp:
  Include ndb_limits.h
ndb/include/ndbapi/Ndb.hpp:
  Add new function internalize_table_name
  Proper formatting
ndb/include/util/SimpleProperties.hpp:
  Add function "add" for adding strings/data to word buffers without reading after the string/data 
  Fix comment for UtilBufferWriter
ndb/src/common/util/SimpleProperties.cpp:
  Add function "add" for adding strings/data to word buffers without reading after the string/data
ndb/src/ndbapi/DictCache.cpp:
  Add DBUG printouts to all functions in GlobalDictCache
  Change ndbout_c to DBUG_PRINT
  Add function GlobalDictCache::printCache
ndb/src/ndbapi/DictCache.hpp:
  Add function GlobalDictCache::printCache
ndb/src/ndbapi/Ndb.cpp:
  Change DEBUG_TRACE to DBUG_PRINT, DBUG_ENTER
  Use new function internalize_table_name, and create internal tabname on stack
ndb/src/ndbapi/NdbDictionary.cpp:
  Add DBUG_ENTER calls
ndb/src/ndbapi/NdbDictionaryImpl.cpp:
  Pass BaseString as reference when passing internal table name to internal functions.
  Remove check for exceeding MAX_SECTION_SIZE.
  Remove pekkas fix that saves internalName in save_me variable, not needed when tablename is stack variable.
  NdbDictInterface::gettable(int tableid, ...) - Not used
ndb/src/ndbapi/NdbDictionaryImpl.hpp:
  Remove include of ndb_limits.h
  Use BaseString& for internal functions
  Remove m_namebuf, not needed, uses m_buffer
  Formatting
  NdbDictInterface::getTable(int tableId, ...) - Not used
ndb/src/ndbapi/NdbImpl.hpp:
  Remove buffer for m_internalname, placed on stack of caller.
  Moved impl of internalize_table_name and internalize_index_anme to Ndb::internalize_table_name and Ndb::internalize_index_name
ndb/src/ndbapi/NdbLinHash.hpp:
  Save also the terminating null character in chain->str to get nicer printouts.
ndb/src/ndbapi/NdbTransaction.cpp:
  Remove hardcoded buffer sizes.
  Remove include of ndb_limits.h
sql/ha_ndbcluster.cc:
  Fix "typo", use file_name var since that is the current files name,
parent 889fa8ae
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
#ifndef ATTRIBUTE_LIST_HPP
#define ATTRIBUTE_LIST_HPP

#include "ndb_limits.h"

/**
 * Masks and lists used by index and trigger.  Must be plain old Uint32 data.
 * XXX depends on other headers XXX move to some common file
+7 −5
Original line number Diff line number Diff line
@@ -1583,15 +1583,17 @@ private:
  void    abortTransactionsAfterNodeFailure(Uint16 aNodeId);

  static
  const char * externalizeTableName(const char * internalTableName, bool fullyQualifiedNames);
  const char * externalizeTableName(const char * internalTableName,
                                    bool fullyQualifiedNames);
  const char * externalizeTableName(const char * internalTableName);
  const char * internalizeTableName(const char * externalTableName);
  const BaseString internalize_table_name(const char * external_name) const;

  static
  const char * externalizeIndexName(const char * internalIndexName, bool fullyQualifiedNames);
  const char * externalizeIndexName(const char * internalIndexName,
                                    bool fullyQualifiedNames);
  const char * externalizeIndexName(const char * internalIndexName);
  const char * internalizeIndexName(const NdbTableImpl * table,
				    const char * externalIndexName);
  const BaseString internalize_index_name(const NdbTableImpl * table,
                                          const char * external_name) const;

  static
  const BaseString getDatabaseFromInternalName(const char * internalName);
+3 −1
Original line number Diff line number Diff line
@@ -172,6 +172,8 @@ public:
    virtual bool reset() = 0;
    virtual bool putWord(Uint32 val) = 0;
    virtual bool putWords(const Uint32 * src, Uint32 len) = 0;
  private:
    bool add(const char* value, int len);
  };
};

@@ -211,7 +213,7 @@ private:
};

/**
 * Writer for linear memory
 * Writer for UtilBuffer
 */
class UtilBufferWriter : public SimpleProperties::Writer {
public:
+28 −6
Original line number Diff line number Diff line
@@ -36,6 +36,28 @@ SimpleProperties::Writer::add(Uint16 key, Uint32 value){
  return putWord(htonl(value));
}

bool
SimpleProperties::Writer::add(const char * value, int len){
  const Uint32 valLen = (len + 3) / 4;

  if ((len % 4) == 0)
    return putWords((Uint32*)value, valLen);

  const Uint32 putLen= valLen - 1;
  if (!putWords((Uint32*)value, putLen))
    return false;

  // Special handling of last bytes
  union {
    Uint32 lastWord;
    char lastBytes[4];
  };
  memcpy(lastBytes,
         value + putLen*4,
         len - putLen*4);
  return putWord(lastWord);
}

bool
SimpleProperties::Writer::add(Uint16 key, const char * value){
  Uint32 head = StringValue;
@@ -47,8 +69,8 @@ SimpleProperties::Writer::add(Uint16 key, const char * value){
  if(!putWord(htonl(strLen)))
    return false;

  const Uint32 valLen = (strLen + 3) / 4;
  return putWords((Uint32*)value, valLen);
  return add(value, (int)strLen);

}

bool
@@ -61,8 +83,7 @@ SimpleProperties::Writer::add(Uint16 key, const void* value, int len){
  if(!putWord(htonl(len)))
    return false;

  const Uint32 valLen = (len + 3) / 4;
  return putWords((Uint32*)value, valLen);
  return add((const char*)value, len);
}

SimpleProperties::Reader::Reader(){
@@ -392,6 +413,7 @@ UtilBufferWriter::putWords(const Uint32 * src, Uint32 len){
  return (m_buf.append(src, 4 * len) == 0);
}


Uint32
UtilBufferWriter::getWordsUsed() const { return m_buf.length() / 4;}

+79 −29
Original line number Diff line number Diff line
@@ -79,11 +79,14 @@ LocalDictCache::drop(const char * name){
 * Global cache
 */
GlobalDictCache::GlobalDictCache(){
  DBUG_ENTER("GlobalDictCache::GlobalDictCache");
  m_tableHash.createHashTable();
  m_waitForTableCondition = NdbCondition_Create();
  DBUG_VOID_RETURN;
}

GlobalDictCache::~GlobalDictCache(){
  DBUG_ENTER("GlobalDictCache::~GlobalDictCache");
  NdbElement_t<Vector<TableVersion> > * curr = m_tableHash.getNext(0);
  while(curr != 0){
    Vector<TableVersion> * vers = curr->theData;
@@ -93,18 +96,50 @@ GlobalDictCache::~GlobalDictCache(){
	delete (* vers)[i].m_impl;
    }
    delete curr->theData;
    curr->theData= NULL;
    curr = m_tableHash.getNext(curr);
  }
  
  m_tableHash.releaseHashTable();
  NdbCondition_Destroy(m_waitForTableCondition);
  DBUG_VOID_RETURN;
}

#include <NdbOut.hpp>
void GlobalDictCache::printCache()
{
  DBUG_ENTER("GlobalDictCache::printCache");
  NdbElement_t<Vector<TableVersion> > * curr = m_tableHash.getNext(0);
  while(curr != 0){
    DBUG_PRINT("curr", ("len: %d, hash: %d, lk: %d, str: %s",
                        curr->len, curr->hash, curr->localkey1, curr->str));
    if (curr->theData){
      Vector<TableVersion> * vers = curr->theData;
      const unsigned sz = vers->size();
      for(unsigned i = 0; i<sz ; i++){
        TableVersion tv= (*vers)[i];
        DBUG_PRINT("  ", ("vers[%d]: ver: %d, refCount: %d, status: %d",
                          sz, tv.m_version, tv.m_refCount, tv.m_status));
        if(tv.m_impl != 0)
        {
          DBUG_PRINT("  ", ("m_impl: internalname: %s",
                            tv.m_impl->m_internalName.c_str()));
        }
      }
    }
    else
    {
      DBUG_PRINT("  ", ("NULL"));
    }
    curr = m_tableHash.getNext(curr);
  }
  DBUG_VOID_RETURN;
}

NdbTableImpl *
GlobalDictCache::get(const char * name)
{
  DBUG_ENTER("GlobalDictCache::get");
  DBUG_PRINT("enter", ("name: %s", name));

  const Uint32 len = strlen(name);
  Vector<TableVersion> * versions = 0;
  versions = m_tableHash.getData(name, len);
@@ -121,7 +156,7 @@ GlobalDictCache::get(const char * name)
    switch(ver->m_status){
    case OK:
      ver->m_refCount++;
      return ver->m_impl;
      DBUG_RETURN(ver->m_impl);
    case DROPPED:
      retreive = true; // Break loop
      break;
@@ -140,24 +175,28 @@ GlobalDictCache::get(const char * name)
  tmp.m_status = RETREIVING;
  tmp.m_refCount = 1; // The one retreiving it
  versions->push_back(tmp);
  return 0;
  DBUG_RETURN(0);
}

NdbTableImpl *
GlobalDictCache::put(const char * name, NdbTableImpl * tab)
{
  DBUG_ENTER("GlobalDictCache::put");
  DBUG_PRINT("enter", ("name: %s, internal_name: %s",
                       name, tab ? tab->m_internalName.c_str() : "tab NULL"));

  const Uint32 len = strlen(name);
  Vector<TableVersion> * vers = m_tableHash.getData(name, len);
  if(vers == 0){
    // Should always tried to retreive it first 
    // and then there should be a record
    // and thus there should be a record
    abort(); 
  }

  const Uint32 sz = vers->size();
  if(sz == 0){
    // Should always tried to retreive it first 
    // and then there should be a record
    // and thus there should be a record
    abort(); 
  }
  
@@ -170,7 +209,7 @@ GlobalDictCache::put(const char * name, NdbTableImpl * tab)
  }
  
  if(tab == 0){
    // No table found in db
    DBUG_PRINT("info", ("No table found in db"));
    vers->erase(sz - 1);
  } else {
    ver.m_impl = tab;
@@ -179,26 +218,29 @@ GlobalDictCache::put(const char * name, NdbTableImpl * tab)
  }
  
  NdbCondition_Broadcast(m_waitForTableCondition);
  return tab;
  DBUG_RETURN(tab);
} 

void
GlobalDictCache::drop(NdbTableImpl * tab)
{
  DBUG_ENTER("GlobalDictCache::drop");
  DBUG_PRINT("enter", ("internal_name: %s", tab->m_internalName.c_str()));

  unsigned i;
  const Uint32 len = strlen(tab->m_internalName.c_str());
  Vector<TableVersion> * vers = 
    m_tableHash.getData(tab->m_internalName.c_str(), len);
  if(vers == 0){
    // Should always tried to retreive it first 
    // and then there should be a record
    // and thus there should be a record
    abort(); 
  }

  const Uint32 sz = vers->size();
  if(sz == 0){
    // Should always tried to retreive it first 
    // and then there should be a record
    // and thus there should be a record
    abort(); 
  }

@@ -207,46 +249,53 @@ GlobalDictCache::drop(NdbTableImpl * tab)
    if(ver.m_impl == tab){
      if(ver.m_refCount == 0 || ver.m_status == RETREIVING ||
	 ver.m_version != tab->m_version){
	ndbout_c("Dropping with refCount=%d status=%d impl=%p",
		 ver.m_refCount, ver.m_status, ver.m_impl);
	DBUG_PRINT("info", ("Dropping with refCount=%d status=%d impl=%p",
                            ver.m_refCount, ver.m_status, ver.m_impl));
	break;
      }
      
      DBUG_PRINT("info", ("Found table to drop, i: %d, name: %s",
                          i, ver.m_impl->m_internalName.c_str()));
      ver.m_refCount--;
      ver.m_status = DROPPED;
      if(ver.m_refCount == 0){
        DBUG_PRINT("info", ("refCount is zero, deleting m_impl"))
	delete ver.m_impl;
	vers->erase(i);
      }
      return;
      DBUG_VOID_RETURN;
    }
  }

  for(i = 0; i<sz; i++){
    TableVersion & ver = (* vers)[i];
    ndbout_c("%d: version: %d refCount: %d status: %d impl: %p",
	     i, ver.m_version, ver.m_refCount, ver.m_status, ver.m_impl);
    DBUG_PRINT("info", ("%d: version: %d refCount: %d status: %d impl: %p",
                        i, ver.m_version, ver.m_refCount,
                        ver.m_status, ver.m_impl));
  }
  
  abort();
}

void
GlobalDictCache::release(NdbTableImpl * tab){
GlobalDictCache::release(NdbTableImpl * tab)
{
  DBUG_ENTER("GlobalDictCache::release");
  DBUG_PRINT("enter", ("internal_name: %s", tab->m_internalName.c_str()));

  unsigned i;
  const Uint32 len = strlen(tab->m_internalName.c_str());
  Vector<TableVersion> * vers = 
    m_tableHash.getData(tab->m_internalName.c_str(), len);
  if(vers == 0){
    // Should always tried to retreive it first 
    // and then there should be a record
    // and thus there should be a record
    abort(); 
  }

  const Uint32 sz = vers->size();
  if(sz == 0){
    // Should always tried to retreive it first 
    // and then there should be a record
    // and thus there should be a record
    abort(); 
  }
  
@@ -255,20 +304,21 @@ GlobalDictCache::release(NdbTableImpl * tab){
    if(ver.m_impl == tab){
      if(ver.m_refCount == 0 || ver.m_status == RETREIVING || 
	 ver.m_version != tab->m_version){
	ndbout_c("Releasing with refCount=%d status=%d impl=%p",
		 ver.m_refCount, ver.m_status, ver.m_impl);
	DBUG_PRINT("info", ("Releasing with refCount=%d status=%d impl=%p",
                            ver.m_refCount, ver.m_status, ver.m_impl));
	break;
      }
      
      ver.m_refCount--;
      return;
      DBUG_VOID_RETURN;
    }
  }
  
  for(i = 0; i<sz; i++){
    TableVersion & ver = (* vers)[i];
    ndbout_c("%d: version: %d refCount: %d status: %d impl: %p",
	     i, ver.m_version, ver.m_refCount, ver.m_status, ver.m_impl);
    DBUG_PRINT("info", ("%d: version: %d refCount: %d status: %d impl: %p",
                        i, ver.m_version, ver.m_refCount,
                        ver.m_status, ver.m_impl));
  }
  
  abort();
Loading