List:Commits« Previous MessageNext Message »
From:Magnus Blåudd Date:October 27 2011 8:41am
Subject:bzr push into mysql-5.5-cluster branch (magnus.blaudd:3625 to 3626)
View as plain text  
 3626 Magnus Blåudd	2011-10-27
      ndbcluster
       - move NdbValue,  'ndb_pack_varchar' and 'get_ndb_blobs_value' to ndb_ndbapi_util.h
       - change use of ERR_RETURN -> DBUG_RETURN(-1), callers only check for 0 as in success anyway.

    added:
      sql/ndb_ndbapi_util.cc
      sql/ndb_ndbapi_util.h
    modified:
      sql/ha_ndbcluster.cc
      sql/ha_ndbcluster.h
      sql/ha_ndbcluster_binlog.cc
      sql/ha_ndbcluster_binlog.h
      storage/ndb/CMakeLists.txt
 3625 Magnus Blåudd	2011-10-27
      ndb binlog
       - move anyvalue functions to their own file

    added:
      sql/ndb_anyvalue.cc
      sql/ndb_anyvalue.h
    modified:
      sql/ha_ndbcluster.cc
      sql/ha_ndbcluster_binlog.cc
      sql/ha_ndbcluster_binlog.h
      storage/ndb/CMakeLists.txt
=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2011-10-27 07:42:25 +0000
+++ b/sql/ha_ndbcluster.cc	2011-10-27 08:27:44 +0000
@@ -1877,87 +1877,6 @@ ha_ndbcluster::set_blob_values(const Ndb
   DBUG_RETURN(res);
 }
 
-/*
-  This routine is shared by injector.  There is no common blobs buffer
-  so the buffer and length are passed by reference.  Injector also
-  passes a record pointer diff.
- */
-int get_ndb_blobs_value(TABLE* table, NdbValue* value_array,
-                        uchar*& buffer, uint& buffer_size,
-                        my_ptrdiff_t ptrdiff)
-{
-  DBUG_ENTER("get_ndb_blobs_value");
-
-  // Field has no field number so cannot use TABLE blob_field
-  // Loop twice, first only counting total buffer size
-  for (int loop= 0; loop <= 1; loop++)
-  {
-    uint32 offset= 0;
-    for (uint i= 0; i < table->s->fields; i++)
-    {
-      Field *field= table->field[i];
-      NdbValue value= value_array[i];
-      if (! (field->flags & BLOB_FLAG))
-        continue;
-      if (value.blob == NULL)
-      {
-        DBUG_PRINT("info",("[%u] skipped", i));
-        continue;
-      }
-      Field_blob *field_blob= (Field_blob *)field;
-      NdbBlob *ndb_blob= value.blob;
-      int isNull;
-      if (ndb_blob->getNull(isNull) != 0)
-        ERR_RETURN(ndb_blob->getNdbError());
-      if (isNull == 0) {
-        Uint64 len64= 0;
-        if (ndb_blob->getLength(len64) != 0)
-          ERR_RETURN(ndb_blob->getNdbError());
-        // Align to Uint64
-        uint32 size= Uint32(len64);
-        if (size % 8 != 0)
-          size+= 8 - size % 8;
-        if (loop == 1)
-        {
-          uchar *buf= buffer + offset;
-          uint32 len= 0xffffffff;  // Max uint32
-          if (ndb_blob->readData(buf, len) != 0)
-            ERR_RETURN(ndb_blob->getNdbError());
-          DBUG_PRINT("info", ("[%u] offset: %u  buf: 0x%lx  len=%u  [ptrdiff=%d]",
-                              i, offset, (long) buf, len, (int)ptrdiff));
-          DBUG_ASSERT(len == len64);
-          // Ugly hack assumes only ptr needs to be changed
-          field_blob->set_ptr_offset(ptrdiff, len, buf);
-        }
-        offset+= size;
-      }
-      else if (loop == 1) // undefined or null
-      {
-        // have to set length even in this case
-        uchar *buf= buffer + offset; // or maybe NULL
-        uint32 len= 0;
-	field_blob->set_ptr_offset(ptrdiff, len, buf);
-        DBUG_PRINT("info", ("[%u] isNull=%d", i, isNull));
-      }
-    }
-    if (loop == 0 && offset > buffer_size)
-    {
-      my_free(buffer, MYF(MY_ALLOW_ZERO_PTR));
-      buffer_size= 0;
-      DBUG_PRINT("info", ("allocate blobs buffer size %u", offset));
-      buffer= (uchar*) my_malloc(offset, MYF(MY_WME));
-      if (buffer == NULL)
-      {
-        sql_print_error("ha_ndbcluster::get_ndb_blobs_value: "
-                        "my_malloc(%u) failed", offset);
-        DBUG_RETURN(-1);
-      }
-      buffer_size= offset;
-    }
-  }
-  DBUG_RETURN(0);
-}
-
 
 /**
   Check if any set or get of blob value in current query.

=== modified file 'sql/ha_ndbcluster.h'
--- a/sql/ha_ndbcluster.h	2011-10-20 19:52:11 +0000
+++ b/sql/ha_ndbcluster.h	2011-10-27 08:27:44 +0000
@@ -108,12 +108,7 @@ public:
   Uint32 old_table_version;
 };
 
-typedef union { const NdbRecAttr *rec; NdbBlob *blob; void *ptr; } NdbValue;
-
-int get_ndb_blobs_value(TABLE* table, NdbValue* value_array,
-                        uchar*& buffer, uint& buffer_size,
-                        my_ptrdiff_t ptrdiff);
-
+#include "ndb_ndbapi_util.h"
 #include "ndb_share.h"
 
 struct Ndb_tuple_id_range_guard {

=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc	2011-10-27 07:42:25 +0000
+++ b/sql/ha_ndbcluster_binlog.cc	2011-10-27 08:27:44 +0000
@@ -1389,29 +1389,6 @@ ndb_binlog_setup(THD *thd)
 #define SCHEMA_SIZE 9u
 #define SCHEMA_SLOCK_SIZE 32u
 
-/*
-  helper function to pack a ndb varchar
-*/
-char *ndb_pack_varchar(const NDBCOL *col, char *buf,
-                       const char *str, int sz)
-{
-  switch (col->getArrayType())
-  {
-    case NDBCOL::ArrayTypeFixed:
-      memcpy(buf, str, sz);
-      break;
-    case NDBCOL::ArrayTypeShortVar:
-      *(uchar*)buf= (uchar)sz;
-      memcpy(buf + 1, str, sz);
-      break;
-    case NDBCOL::ArrayTypeMediumVar:
-      int2store(buf, sz);
-      memcpy(buf + 2, str, sz);
-      break;
-  }
-  return buf;
-}
-
 
 /*
   log query in schema table

=== modified file 'sql/ha_ndbcluster_binlog.h'
--- a/sql/ha_ndbcluster_binlog.h	2011-10-27 07:42:25 +0000
+++ b/sql/ha_ndbcluster_binlog.h	2011-10-27 08:27:44 +0000
@@ -214,9 +214,6 @@ int cmp_frm(const NDBTAB *ndbtab, const
             size_t pack_length);
 int ndbcluster_find_all_files(THD *thd);
 
-char *ndb_pack_varchar(const NDBCOL *col, char *buf,
-                       const char *str, int sz);
-
 NDB_SHARE *ndbcluster_get_share(const char *key,
                                 TABLE *table,
                                 bool create_if_not_exists,

=== added file 'sql/ndb_ndbapi_util.cc'
--- a/sql/ndb_ndbapi_util.cc	1970-01-01 00:00:00 +0000
+++ b/sql/ndb_ndbapi_util.cc	2011-10-27 08:27:44 +0000
@@ -0,0 +1,131 @@
+/*
+   Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+*/
+
+#include "ndb_ndbapi_util.h"
+
+#include <string.h> // memcpy
+
+/*
+  helper function to pack a ndb varchar
+*/
+char *ndb_pack_varchar(const NdbDictionary::Column *col, char *buf,
+                       const char *str, int sz)
+{
+  switch (col->getArrayType())
+  {
+    case NdbDictionary::Column::ArrayTypeFixed:
+      memcpy(buf, str, sz);
+      break;
+    case NdbDictionary::Column::ArrayTypeShortVar:
+      *(uchar*)buf= (uchar)sz;
+      memcpy(buf + 1, str, sz);
+      break;
+    case NdbDictionary::Column::ArrayTypeMediumVar:
+      int2store(buf, sz);
+      memcpy(buf + 2, str, sz);
+      break;
+  }
+  return buf;
+}
+
+
+#ifndef MYSQL_SERVER
+#define MYSQL_SERVER
+#endif
+
+#include <sql_class.h> // TABLE, Field etc.
+
+/*
+  This routine is shared by injector.  There is no common blobs buffer
+  so the buffer and length are passed by reference.  Injector also
+  passes a record pointer diff.
+ */
+int get_ndb_blobs_value(TABLE* table, NdbValue* value_array,
+                        uchar*& buffer, uint& buffer_size,
+                        my_ptrdiff_t ptrdiff)
+{
+  DBUG_ENTER("get_ndb_blobs_value");
+
+  // Field has no field number so cannot use TABLE blob_field
+  // Loop twice, first only counting total buffer size
+  for (int loop= 0; loop <= 1; loop++)
+  {
+    uint32 offset= 0;
+    for (uint i= 0; i < table->s->fields; i++)
+    {
+      Field *field= table->field[i];
+      NdbValue value= value_array[i];
+      if (! (field->flags & BLOB_FLAG))
+        continue;
+      if (value.blob == NULL)
+      {
+        DBUG_PRINT("info",("[%u] skipped", i));
+        continue;
+      }
+      Field_blob *field_blob= (Field_blob *)field;
+      NdbBlob *ndb_blob= value.blob;
+      int isNull;
+      if (ndb_blob->getNull(isNull) != 0)
+        DBUG_RETURN(-1);
+      if (isNull == 0) {
+        Uint64 len64= 0;
+        if (ndb_blob->getLength(len64) != 0)
+          DBUG_RETURN(-1);
+        // Align to Uint64
+        uint32 size= Uint32(len64);
+        if (size % 8 != 0)
+          size+= 8 - size % 8;
+        if (loop == 1)
+        {
+          uchar *buf= buffer + offset;
+          uint32 len= 0xffffffff;  // Max uint32
+          if (ndb_blob->readData(buf, len) != 0)
+            DBUG_RETURN(-1);
+          DBUG_PRINT("info", ("[%u] offset: %u  buf: 0x%lx  len=%u  [ptrdiff=%d]",
+                              i, offset, (long) buf, len, (int)ptrdiff));
+          DBUG_ASSERT(len == len64);
+          // Ugly hack assumes only ptr needs to be changed
+          field_blob->set_ptr_offset(ptrdiff, len, buf);
+        }
+        offset+= size;
+      }
+      else if (loop == 1) // undefined or null
+      {
+        // have to set length even in this case
+        uchar *buf= buffer + offset; // or maybe NULL
+        uint32 len= 0;
+        field_blob->set_ptr_offset(ptrdiff, len, buf);
+        DBUG_PRINT("info", ("[%u] isNull=%d", i, isNull));
+        }
+    }
+    if (loop == 0 && offset > buffer_size)
+    {
+      my_free(buffer);
+      buffer_size= 0;
+      DBUG_PRINT("info", ("allocate blobs buffer size %u", offset));
+      buffer= (uchar*) my_malloc(offset, MYF(MY_WME));
+      if (buffer == NULL)
+      {
+        sql_print_error("ha_ndbcluster::get_ndb_blobs_value: "
+                        "my_malloc(%u) failed", offset);
+        DBUG_RETURN(-1);
+      }
+      buffer_size= offset;
+    }
+  }
+  DBUG_RETURN(0);
+}

=== added file 'sql/ndb_ndbapi_util.h'
--- a/sql/ndb_ndbapi_util.h	1970-01-01 00:00:00 +0000
+++ b/sql/ndb_ndbapi_util.h	2011-10-27 08:27:44 +0000
@@ -0,0 +1,41 @@
+/*
+   Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+*/
+
+#ifndef NDB_NDBAPI_UTIL_H
+#define NDB_NDBAPI_UTIL_H
+
+#include <my_global.h>
+
+#include <ndbapi/NdbRecAttr.hpp>
+#include <ndbapi/NdbBlob.hpp>
+#include <ndbapi/NdbDictionary.hpp>
+
+union NdbValue
+{
+  const NdbRecAttr *rec;
+  NdbBlob *blob;
+  void *ptr;
+};
+
+int get_ndb_blobs_value(struct TABLE* table, NdbValue* value_array,
+                        uchar*& buffer, uint& buffer_size,
+                        my_ptrdiff_t ptrdiff);
+
+char *ndb_pack_varchar(const NdbDictionary::Column *col,
+                       char *buf, const char *str, int sz);
+
+#endif

=== modified file 'storage/ndb/CMakeLists.txt'
--- a/storage/ndb/CMakeLists.txt	2011-10-27 07:42:25 +0000
+++ b/storage/ndb/CMakeLists.txt	2011-10-27 08:27:44 +0000
@@ -81,6 +81,7 @@ SET(NDBCLUSTER_SOURCES
   ../../sql/ndb_mi.cc
   ../../sql/ndb_conflict_trans.cc
   ../../sql/ndb_anyvalue.cc
+  ../../sql/ndb_ndbapi_util.cc
 )
 
 # Include directories used when building ha_ndbcluster

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.5-cluster branch (magnus.blaudd:3625 to 3626) Magnus Blåudd27 Oct