#At file:///Users/jdd/bzr-repo/working/cluster-7.2-labs-memcached/ based on revid:john.duncan@stripped
4174 John David Duncan 2011-05-15
Refactor DataTypeHandler so that readFromNdb() and writeToNdb() return an int -- the length read/written, or < 0 for error.
modified:
storage/ndb/memcache/include/DataTypeHandler.h
storage/ndb/memcache/include/Operation.h
storage/ndb/memcache/include/Record.h
storage/ndb/memcache/src/DataTypeHandler.cc
storage/ndb/memcache/src/Record.cc
=== modified file 'storage/ndb/memcache/include/DataTypeHandler.h'
--- a/storage/ndb/memcache/include/DataTypeHandler.h 2011-03-30 06:54:53 +0000
+++ b/storage/ndb/memcache/include/DataTypeHandler.h 2011-05-16 05:49:22 +0000
@@ -36,25 +36,24 @@
/* Return status codes from some of the functions:
*/
-// TODO: Return an int: the encoded/read length, or < 0 on error.
-enum TypeHandlerStatus {
- DTH_OK = 0,
- DTH_NOT_SUPPORTED,
- DTH_VALUE_TOO_LONG
+
+enum { /* These can be returned by readFromNdb() or writeToNdb() */
+ DTH_NOT_SUPPORTED = -1,
+ DTH_VALUE_TOO_LONG = -2
};
/* DataTypeHandler interface:
*/
typedef struct {
- // String Readers
- TypeHandlerStatus (*readFromNdb)(const NdbDictionary::Column *col, size_t &len,
- char * &str, const void * const buf);
+ // String Readers. Returns length read.
+ int (*readFromNdb)(const NdbDictionary::Column *col,
+ char * &str, const void * const buf);
size_t (*getStringifiedLength)(const NdbDictionary::Column *col,
const void * const buf);
- // String Writer
- TypeHandlerStatus (*writeToNdb)(const NdbDictionary::Column *col, size_t len,
- size_t offset, const char *str, void * const buf);
+ // String Writer. Returns length written or < 0 for error.
+ int (*writeToNdb)(const NdbDictionary::Column *col, size_t len,
+ size_t offset, const char *str, void * const buf);
// For an integer column, this holds the int's size in bytes. Otherwise zero.
int direct_int_size;
=== modified file 'storage/ndb/memcache/include/Operation.h'
--- a/storage/ndb/memcache/include/Operation.h 2011-04-07 11:20:56 +0000
+++ b/storage/ndb/memcache/include/Operation.h 2011-05-16 05:49:22 +0000
@@ -134,8 +134,8 @@ inline void Operation::clearKeyNullBits(
}
inline bool Operation::setKeyPart(int idx, const char *strval, size_t strlen) {
- TypeHandlerStatus s = plan->key_record->encode(idx, strval, strlen, key_buffer);
- return (s == DTH_OK);
+ int s = plan->key_record->encode(idx, strval, strlen, key_buffer);
+ return (s > 0);
}
inline bool Operation::setKeyPartInt(int idx, int value) {
@@ -157,8 +157,8 @@ inline void Operation::clearNullBits() {
}
inline bool Operation::setColumn(int idx, const char *strval, size_t strlen) {
- TypeHandlerStatus s = record->encode(idx, strval, strlen, buffer);
- return (s == DTH_OK);
+ int s = record->encode(idx, strval, strlen, buffer);
+ return (s > 0);
}
inline bool Operation::setColumnInt(int idx, int value) {
=== modified file 'storage/ndb/memcache/include/Record.h'
--- a/storage/ndb/memcache/include/Record.h 2011-04-07 11:20:56 +0000
+++ b/storage/ndb/memcache/include/Record.h 2011-05-16 05:49:22 +0000
@@ -76,7 +76,7 @@ class Record {
int getIntValue(int idx, char *data) const;
bool setUint64Value(int idx, Uint64 value, char *buffer) const;
Uint64 getUint64Value(int idx, char *data) const;
- TypeHandlerStatus encode(int idx, const char *key, int nkey, char *buffer) const;
+ int encode(int idx, const char *key, int nkey, char *buffer) const;
size_t getStringifiedLength(char *data) const;
bool decodeNoCopy(int idx, char **dest_ptr, size_t *len_ptr,
const char * const src) const;
=== modified file 'storage/ndb/memcache/src/DataTypeHandler.cc'
--- a/storage/ndb/memcache/src/DataTypeHandler.cc 2011-03-30 06:54:53 +0000
+++ b/storage/ndb/memcache/src/DataTypeHandler.cc 2011-05-16 05:49:22 +0000
@@ -31,13 +31,13 @@
#include "DataTypeHandler.h"
#include "debug.h"
-#define DECODE_ARGS const NdbDictionary::Column *, size_t &, char * &, const void *
+#define DECODE_ARGS const NdbDictionary::Column *, char * &, const void *
#define SFDLEN_ARGS const NdbDictionary::Column *, const void *
-#define WRITE_ARGS const NdbDictionary::Column *, size_t, size_t, const char *, void *
+#define WRITE_ARGS const NdbDictionary::Column *, size_t, size_t, const char *, void *
-typedef TypeHandlerStatus impl_readFromNdb(DECODE_ARGS);
-typedef size_t impl_getStringifiedLength(SFDLEN_ARGS);
-typedef TypeHandlerStatus impl_writeToNdb(WRITE_ARGS);
+typedef int impl_readFromNdb(DECODE_ARGS);
+typedef size_t impl_getStringifiedLength(SFDLEN_ARGS);
+typedef int impl_writeToNdb(WRITE_ARGS);
/* Implementations for readFromNdb() */
@@ -171,12 +171,11 @@ size_t getColumnRecordSize(const NdbDict
/******************* IMPLEMENTATIONS *******************/
/***** VARCHAR *****/
-TypeHandlerStatus dth_decode_varchar(const NdbDictionary::Column *col,
- size_t &len, char * &str,
- const void *buf) {
- len = dth_sfdlen_varchar(col, buf);
+int dth_decode_varchar(const NdbDictionary::Column *col,
+ char * &str, const void *buf) {
+ size_t len = dth_sfdlen_varchar(col, buf);
str = ((char *) buf) + 1;
- return DTH_OK;
+ return len;
}
@@ -187,9 +186,8 @@ size_t dth_sfdlen_varchar(const NdbDicti
}
-TypeHandlerStatus dth_encode_varchar(const NdbDictionary::Column *col,
- size_t len, size_t offset,
- const char *str, void *buf) {
+int dth_encode_varchar(const NdbDictionary::Column *col,
+ size_t len, size_t offset, const char *str, void *buf) {
size_t total_len = len + offset;
uint8_t * length_byte = (uint8_t *) buf;
char *char_buffer = ((char *) buf) + 1 + offset;
@@ -203,18 +201,17 @@ TypeHandlerStatus dth_encode_varchar(con
/* Copy string value into buffer */
strncpy(char_buffer, str, len);
- return DTH_OK;
+ return len;
}
/***** LONGVARCHAR *****/
-TypeHandlerStatus dth_decode_longvarchar(const NdbDictionary::Column *col,
- size_t &len, char * &str,
- const void *buf) {
- len = dth_sfdlen_longvarchar(col, buf);
+int dth_decode_longvarchar(const NdbDictionary::Column *col,
+ char * &str, const void *buf) {
+ size_t len = dth_sfdlen_longvarchar(col, buf);
str = ((char *) buf) + 2;
- return DTH_OK;
+ return len;
}
@@ -227,7 +224,7 @@ size_t dth_sfdlen_longvarchar(const NdbD
}
-TypeHandlerStatus dth_encode_longvarchar(const NdbDictionary::Column *col,
+int dth_encode_longvarchar(const NdbDictionary::Column *col,
size_t len, size_t offset,
const char *str, void *buf) {
char *cbuf = ((char *) buf);
@@ -246,16 +243,14 @@ TypeHandlerStatus dth_encode_longvarchar
/* Copy string value into buffer */
strncpy(dest, str, len);
- return DTH_OK;
+ return len;
}
/***** INT *****/
-TypeHandlerStatus dth_decode_int(const NdbDictionary::Column *col, size_t &len,
- char * &str, const void *buf) {
- len = sprintf(str, "%d",* (int *) buf) + 1; // +1 for null terminator
-
- return DTH_OK;
+int dth_decode_int(const NdbDictionary::Column *col,
+ char * &str, const void *buf) {
+ return sprintf(str, "%d",* (int *) buf) + 1; // +1 for null terminator
}
@@ -267,23 +262,20 @@ size_t dth_sfdlen_int(const NdbDictionar
}
-TypeHandlerStatus dth_encode_int(const NdbDictionary::Column *col,
- size_t len, size_t offset,
- const char *str, void *buf) {
+int dth_encode_int(const NdbDictionary::Column *col,
+ size_t len, size_t offset, const char *str, void *buf) {
assert(offset == 0);
int *ibuf = (int *) buf;
*ibuf = strtol(str, NULL, 10);
- return DTH_OK;
+ return len;
}
/***** BIGINT UNSIGNED *****/
-TypeHandlerStatus dth_decode_ubigint(const NdbDictionary::Column *col, size_t &len,
- char * &str, const void *buf) {
- len = sprintf(str, "%"PRIu64,* (uint64_t *) buf) + 1; // +1 for null
-
- return DTH_OK;
+int dth_decode_ubigint(const NdbDictionary::Column *col,
+ char * &str, const void *buf) {
+ return sprintf(str, "%"PRIu64,* (uint64_t *) buf) + 1; // +1 for null
}
@@ -295,37 +287,33 @@ size_t dth_sfdlen_ubigint(const NdbDicti
}
-TypeHandlerStatus dth_encode_ubigint(const NdbDictionary::Column *col,
- size_t len, size_t offset,
- const char *str, void *buf) {
+int dth_encode_ubigint(const NdbDictionary::Column *col,
+ size_t len, size_t offset, const char *str, void *buf) {
assert(offset == 0);
uint64_t *ibuf = (uint64_t *) buf;
*ibuf = strtoull(str, NULL, 10);
- return DTH_OK;
+ return len;
}
/***** ENUM *****/
-TypeHandlerStatus dth_decode_char1(const NdbDictionary::Column *col, size_t &len,
- char * &str, const void *buf) {
- *str = * (char *) buf;
- len = 1;
-
- return DTH_OK;
+int dth_decode_char1(const NdbDictionary::Column *col,
+ char * &str, const void *buf) {
+ *str = * (char *) buf;
+ return 1;
}
size_t dth_sfdlen_char1(const NdbDictionary::Column *col, const void *buf) {
return 1;
}
-TypeHandlerStatus dth_encode_char1(const NdbDictionary::Column *col,
- size_t len, size_t offset,
- const char *str, void *buf) {
+int dth_encode_char1(const NdbDictionary::Column *col,
+ size_t len, size_t offset, const char *str, void *buf) {
assert(offset == 0);
char *cbuf = (char *) buf;
*cbuf = *str;
- return DTH_OK;
+ return 1;
}
=== modified file 'storage/ndb/memcache/src/Record.cc'
--- a/storage/ndb/memcache/src/Record.cc 2011-04-30 14:20:42 +0000
+++ b/storage/ndb/memcache/src/Record.cc 2011-05-16 05:49:22 +0000
@@ -149,7 +149,7 @@ bool Record::complete(NdbDictionary::Dic
bool Record::appendCRLF(int idx, size_t len, char *buffer) const {
if( handlers[col[idx]]->contains_string
&& handlers[col[idx]]->writeToNdb(specs[col[idx]].column, 2, len, "\r\n", buffer)
- == DTH_OK)
+ >= 0)
{
return true;
}
@@ -164,7 +164,7 @@ bool Record::decodeNoCopy(int idx,
if(! handlers[col[idx]]->contains_string) return false;
const char * src_buffer = src + specs[col[idx]].offset;
- handlers[col[idx]]->readFromNdb(specs[col[idx]].column, *len, *dest, src_buffer);
+ *len = handlers[col[idx]]->readFromNdb(specs[col[idx]].column, *dest, src_buffer);
return true;
}
@@ -181,7 +181,7 @@ size_t Record::decodeCopy(int idx, char
else { /* Types other than VARCHAR */
/* this works but it's strange; something has to be sorted out here.
handlers[col[idx]] but specs[idx] ?? */
- handlers[col[idx]]->readFromNdb(specs[idx].column, out_len, dest, src_buffer);
+ out_len = handlers[col[idx]]->readFromNdb(specs[idx].column, dest, src_buffer);
}
*(dest + out_len) = 0; // terminating null; may be overwritten by a tab
return out_len;
@@ -234,7 +234,7 @@ Uint64 Record::getUint64Value(int idx, c
}
-TypeHandlerStatus Record::encode(int idx, const char *key, int nkey,
+int Record::encode(int idx, const char *key, int nkey,
char *buffer) const {
return handlers[col[idx]]->writeToNdb(specs[col[idx]].column, nkey, 0, key,
buffer + specs[col[idx]].offset);
Attachment: [text/bzr-bundle] bzr/john.duncan@oracle.com-20110516054922-oiw5dunl4uac01g0.bundle
| Thread |
|---|
| • bzr commit into mysql-5.1-telco-7.2 branch (john.duncan:4174) | John David Duncan | 16 May |