18 #include <ndb_global.h> 
   19 #include "HugoCalculator.hpp" 
   26   const Uint64 mul= 0x5deece66dull;
 
   27   const Uint64 add= 0xb;
 
   28   Uint64 loc_result = *seed * mul + add;
 
   31   return (Uint32)(loc_result >> 1);
 
   34 static char base64_table[] = 
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" 
   35                              "abcdefghijklmnopqrstuvwxyz" 
   50   for (i=0; i<m_tab.getNoOfColumns(); i++){ 
 
   59   for (i=m_tab.getNoOfColumns()-1; i>=0; i--){
 
   68   ndbout << 
"idCol = " << m_idCol << endl;
 
   69   ndbout << 
"updatesCol = " << m_updatesCol << endl;
 
   72   assert(m_idCol != m_updatesCol && m_idCol != -1 && m_updatesCol != -1);
 
   76 HugoCalculator::calcValue(
int record, 
 
   82   calcValue(record, attrib, updates, (
char*)&i, 
sizeof(i), &j);
 
   87 HugoCalculator::U_Int32 calcValue(
int record, 
int attrib, 
int updates) 
const;
 
   88 HugoCalculator::U_Int64 calcValue(
int record, 
int attrib, 
int updates) 
const;
 
   89 HugoCalculator::Int64 calcValue(
int record, 
int attrib, 
int updates) 
const;
 
   90 HugoCalculator::float calcValue(
int record, 
int attrib, 
int updates) 
const;
 
   91 HugoCalculator::double calcValue(
int record, 
int attrib, 
int updates) 
const;
 
   96 calc_len(Uint32 rvalue, 
int maxlen)
 
  100   if ((rvalue >> 16) < 4096)
 
  102   else if ((rvalue >> 16) < 8192)
 
  104   else if ((rvalue >> 16) < 16384)
 
  109   if ((Uint32)maxlen <= minlen)
 
  113   if ((rvalue & 64) == 0)
 
  116   return minlen + (rvalue % (maxlen - minlen));
 
  121 calc_blobLen(Uint32 rvalue, 
int maxlen)
 
  125   if ((rvalue >> 16) < 4096)
 
  127   else if ((rvalue >> 16) < 8192)
 
  129   else if ((rvalue >> 16) < 16384)
 
  134   if (maxlen <= minlen)
 
  137   return minlen + (rvalue % (maxlen - minlen));
 
  141 HugoCalculator::calcValue(
int record, 
 
  146                           Uint32 *outlen)
 const {
 
  153     if (attrib == m_idCol)
 
  156       memcpy(buf, &val, 4);
 
  161     if (attrib == m_updatesCol)
 
  164       memcpy(buf, &val, 4);
 
  170       seed = record + attrib;
 
  174       seed = record + attrib + updates;
 
  180   if(attr->
getNullable() && (((val >> 16) & 255) > 220))
 
  200   case NdbDictionary::Column::Olddecimalunsigned:
 
  202   case NdbDictionary::Column::Decimalunsigned:
 
  210       memcpy(buf+pos, &val, 4);
 
  216     memcpy(buf+pos, &val, len);
 
  220       Uint32 tmp = bits >> 5;
 
  221       Uint32 
size = bits & 31;
 
  223       memcpy(©, ((Uint32*)buf)+tmp, 4);
 
  224       copy &= ((1 << 
size) - 1);
 
  225       memcpy(((Uint32*)buf)+tmp, ©, 4);
 
  230       float x = (float)myRand(&seed);
 
  231       memcpy(buf+pos, &x, 4);
 
  238       double x = (double)myRand(&seed);
 
  239       memcpy(buf+pos, &x, 8);
 
  246     len = calc_len(myRand(&seed), len - 1);
 
  254     len = calc_len(myRand(&seed), len - 2);
 
  262     char* ptr= (
char*)&val;
 
  266       dst[pos++] = base64_table[ptr[0] & 0x3f];
 
  267       dst[pos++] = base64_table[ptr[1] & 0x3f];
 
  268       dst[pos++] = base64_table[ptr[2] & 0x3f];
 
  269       dst[pos++] = base64_table[ptr[3] & 0x3f];
 
  273     for(; len; len--, pos++)
 
  274       dst[pos] = base64_table[ptr[len] & 0x3f];
 
  280     * outlen = calc_blobLen(myRand(&seed), len);
 
  295 HugoCalculator::verifyRowValues(
NDBT_ResultRow* 
const  pRow)
 const{
 
  298   id = pRow->attributeStore(m_idCol)->
u_32_value();
 
  299   updates = pRow->attributeStore(m_updatesCol)->
u_32_value();
 
  304     if (i != m_updatesCol && 
id != m_idCol) {
 
  306       Uint32 len = attr->getSizeInBytes(), real_len;
 
  307       char buf[NDB_MAX_TUPLE_SIZE];
 
  308       const char* res = calcValue(
id, i, updates, buf, len, &real_len);
 
  310         if (!pRow->attributeStore(i)->
isNULL()){
 
  311           g_err << 
"|- NULL ERROR: expected a NULL but the column was not null" << endl;
 
  312           g_err << 
"|- The row: \"" << (*pRow) << 
"\"" << endl;
 
  318           g_err << 
"|- Invalid data found in attribute " << i << 
": \"" 
  319                 << 
"Length of expected=" << real_len << endl
 
  324         else if (memcmp(res, pRow->attributeStore(i)->
aRef(), real_len) != 0)
 
  326           g_err << 
"Column: " << attr->
getName() << endl;
 
  327           const char* buf2 = pRow->attributeStore(i)->
aRef();
 
  328           for (Uint32 j = 0; j < len; j++)
 
  330             g_err << j << 
":" << hex << (Uint32)(Uint8)buf[j] << "[" << hex << (Uint32)(Uint8)buf2[j] << "]";
 
  331             if (buf[j] != buf2[j])
 
  333               g_err << 
"==>Match failed!";
 
  338           g_err << 
"|- Invalid data found in attribute " << i << 
": \"" 
  339                 << pRow->attributeStore(i)->
aRef()
 
  340                 << 
"\" != \"" << res << 
"\"" << endl
 
  341                 << 
"Length of expected=" << (unsigned)strlen(res) << endl
 
  344           g_err << 
"|- The row: \"" << (* pRow) << 
"\"" << endl;
 
  355 HugoCalculator::verifyRecAttr(
int record,
 
  359   const char* valPtr = NULL;
 
  360   int attrib = recAttr->getColumn()->getAttrId();
 
  363     valPtr= (
const char*) recAttr->
aRef();
 
  365   return verifyColValue(record,
 
  373 HugoCalculator::verifyColValue(
int record, 
 
  381   if (attrib == m_updatesCol)
 
  383     int val= *((
const int*) valPtr);
 
  386       g_err << 
"|- Updates column (" << attrib << 
")" << endl;
 
  387       g_err << 
"|- Expected " << updates << 
" but found " << val << endl;
 
  391   else if (attrib == m_idCol)
 
  393     int val= *((
const int*) valPtr);
 
  396       g_err << 
"|- Identity column (" << attrib << 
")" << endl;
 
  397       g_err << 
"|- Expected " << record << 
" but found " << val << endl;
 
  405     Uint32 len = attr->getSizeInBytes(), real_len;
 
  406     char buf[NDB_MAX_TUPLE_SIZE];
 
  407     const char* res = calcValue(record, attrib, updates, buf, len, &real_len);
 
  410         g_err << 
"|- NULL ERROR: expected a NULL but the column was not null" << endl;
 
  411         g_err << 
"|- Column length is " << valLen << 
" bytes" << endl;
 
  412         g_err << 
"|- Column data follows :" << endl;
 
  413         for (Uint32 j = 0; j < valLen; j ++)
 
  415           g_err << j << 
":" << hex << (Uint32)(Uint8)valPtr[j] << endl;
 
  420       if (real_len != valLen)
 
  422         g_err << 
"|- Invalid data found in attribute " << attrib << 
": \"" 
  423               << 
"Length of expected=" << real_len << endl
 
  424               << 
"Length of passed="  
  428       else if (memcmp(res, valPtr, real_len) != 0)
 
  430         g_err << 
"|- Expected data mismatch on column " 
  431               << attr->
getName() << 
" length " << real_len 
 
  432               << 
" bytes " << endl;
 
  433         g_err << 
"|- Bytewise comparison follows :" << endl;
 
  434         for (Uint32 j = 0; j < real_len; j++)
 
  436           g_err << j << 
":" << hex << (Uint32)(Uint8)buf[j] << "[" << hex << (Uint32)(Uint8)valPtr[j] << "]";
 
  437           if (buf[j] != valPtr[j])
 
  439             g_err << 
"==>Match failed!";
 
  454   return pRow->attributeStore(m_idCol)->
u_32_value();
 
  458 HugoCalculator::getUpdatesValue(
NDBT_ResultRow* 
const pRow)
 const {
 
  459   return pRow->attributeStore(m_updatesCol)->
u_32_value();
 
  463 HugoCalculator::equalForRow(Uint8 * pRow,
 
  474       int len = attr->getSizeInBytes();
 
  475       memset(buf, 0, 
sizeof(buf));
 
  477       const char * value = calcValue(rowId, attrId, 0, buf,
 
  481       bool ret = NdbDictionary::getOffset(pRecord, attrId, off);
 
  484       memcpy(pRow + off, buf, real_len);
 
  491 HugoCalculator::setValues(Uint8 * pRow,
 
  496   int res = equalForRow(pRow, pRecord, rowId);
 
  509       int len = attr->getSizeInBytes();
 
  510       memset(buf, 0, 
sizeof(buf));
 
  512       const char * value = calcValue(rowId, attrId, updateVal, buf,
 
  517         bool ret = NdbDictionary::getOffset(pRecord, attrId, off);
 
  520         memcpy(pRow + off, buf, real_len);
 
  522           NdbDictionary::setNull(pRecord, (
char*)pRow, attrId, 
false);
 
  527         NdbDictionary::setNull(pRecord, (
char*)pRow, attrId, 
true);