#At file:///Users/jdd/bzr-repo/working/cluster-7.2-labs-memcached/ based on revid:john.duncan@stripped
4176 John David Duncan 2011-05-15
New TabSeparatedValues class
added:
storage/ndb/memcache/include/TabSeparatedValues.h
storage/ndb/memcache/src/TabSeparatedValues.cc
storage/ndb/memcache/unit/tsv.cc
modified:
storage/ndb/memcache/Makefile.am
storage/ndb/memcache/unit/Makefile.am
storage/ndb/memcache/unit/all_tests.h
storage/ndb/memcache/unit/harness.cc
=== modified file 'storage/ndb/memcache/Makefile.am'
--- a/storage/ndb/memcache/Makefile.am 2011-04-26 07:24:58 +0000
+++ b/storage/ndb/memcache/Makefile.am 2011-05-16 06:14:51 +0000
@@ -37,6 +37,7 @@ ndb_engine_la_SOURCES= \
src/QueryPlan.cc \
src/Record.cc \
src/TableSpec.cc \
+ src/TabSeparatedValues.cc \
src/workqueue.c \
src/schedulers/Stockholm.h \
src/schedulers/Stockholm.cc \
=== added file 'storage/ndb/memcache/include/TabSeparatedValues.h'
--- a/storage/ndb/memcache/include/TabSeparatedValues.h 1970-01-01 00:00:00 +0000
+++ b/storage/ndb/memcache/include/TabSeparatedValues.h 2011-05-16 06:14:51 +0000
@@ -0,0 +1,55 @@
+/*
+ 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 NDBMEMCACHE_TABSEP_H
+#define NDBMEMCACHE_TABSEP_H
+
+#include "ndbmemcache_config.h"
+#include "Record.h"
+
+class TabSeparatedValues {
+ public:
+ TabSeparatedValues(const char * string, Uint32 max_parts, size_t length);
+ int advance(); // inlined
+ const char * getPointer(); // inlined
+ size_t getLength(); // inlined
+
+ private:
+ int index;
+ int parts;
+ const char * pointers[MAX_VAL_COLUMNS];
+ size_t lengths[MAX_VAL_COLUMNS];
+ int find_tab(const char *, int) const;
+};
+
+
+inline int TabSeparatedValues::advance() {
+ return ++index < parts ? 1 : 0;
+}
+
+inline const char * TabSeparatedValues::getPointer() {
+ return pointers[index];
+}
+
+inline size_t TabSeparatedValues::getLength() {
+ return lengths[index];
+}
+
+
+#endif
=== added file 'storage/ndb/memcache/src/TabSeparatedValues.cc'
--- a/storage/ndb/memcache/src/TabSeparatedValues.cc 1970-01-01 00:00:00 +0000
+++ b/storage/ndb/memcache/src/TabSeparatedValues.cc 2011-05-16 06:14:51 +0000
@@ -0,0 +1,46 @@
+/*
+ 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 <assert.h>
+
+#include "TabSeparatedValues.h"
+
+TabSeparatedValues::TabSeparatedValues(const char *string, Uint32 max_parts, size_t length) :
+ parts(0), index(0)
+{
+ size_t parsed_len = 0;
+
+ assert(max_parts < MAX_VAL_COLUMNS);
+
+ while(parsed_len <= length && parts < max_parts) {
+ const char *s = string + parsed_len;
+ pointers[parts] = s;
+ lengths[parts] = find_tab(s, length - parsed_len);
+ parsed_len += lengths[parts] + 1;
+ parts++;
+ }
+}
+
+
+int TabSeparatedValues::find_tab(const char *s, int remaining) const {
+ int r;
+ for(r = 0; r < remaining && *(s+r) != '\t' && *(s+r) != '\0'; r++);
+ return r;
+}
=== modified file 'storage/ndb/memcache/unit/Makefile.am'
--- a/storage/ndb/memcache/unit/Makefile.am 2011-04-27 04:28:04 +0000
+++ b/storage/ndb/memcache/unit/Makefile.am 2011-05-16 06:14:51 +0000
@@ -36,7 +36,8 @@ run_unit_tests_SOURCES = harness.cc \
casbits.cc \
incr.cc \
alloc.cc \
- connpool.cc
+ connpool.cc \
+ tsv.cc
run_unit_tests_CFLAGS = -g -O0 \
-I${top_srcdir}/storage/ndb/memcache \
@@ -56,6 +57,7 @@ run_unit_tests_LDADD = ../ndb_engine_la-
../ndb_engine_la-Record.lo \
../ndb_engine_la-Stockholm.lo \
../ndb_engine_la-TableSpec.lo \
+ ../ndb_engine_la-TabSeparatedValues.lo \
../ndb_engine_la-assoc.lo \
../ndb_engine_la-atomics.lo \
../ndb_engine_la-debug.lo \
=== modified file 'storage/ndb/memcache/unit/all_tests.h'
--- a/storage/ndb/memcache/unit/all_tests.h 2011-05-16 05:37:57 +0000
+++ b/storage/ndb/memcache/unit/all_tests.h 2011-05-16 06:14:51 +0000
@@ -24,8 +24,8 @@
#include "QueryPlan.h"
#include "Operation.h"
-#define require(x) if(!(x)) return 0;
-#define pass return 1;
+#define require(x) if(!(x)) return __LINE__;
+#define pass return 0;
#define detail(v, fmt, ...) if(v) printf (fmt, ## __VA_ARGS__)
#define RESULT getNdbError().code
@@ -50,6 +50,7 @@ TESTCASE test_cas_bitshifts;
TESTCASE run_incr_test;
TESTCASE run_allocator_test;
TESTCASE run_pool_test;
+TESTCASE run_tsv_test;
#ifdef HARNESS
@@ -59,6 +60,7 @@ struct test_item all_tests[] = {
{ 1, "incr operation", run_incr_test, REQ_DEMO_TABLE },
{ 1, "allocator", run_allocator_test, REQ_NONE },
{ 0, "pool", run_pool_test, REQ_NDB_CONNECTION },
+ { 1, "tsv", run_tsv_test, REQ_NONE },
{ 0, NULL, NULL, NULL }
};
=== modified file 'storage/ndb/memcache/unit/harness.cc'
--- a/storage/ndb/memcache/unit/harness.cc 2011-05-16 05:37:57 +0000
+++ b/storage/ndb/memcache/unit/harness.cc 2011-05-16 06:14:51 +0000
@@ -114,18 +114,20 @@ int main(int argc, char *argv[]) {
if(test_number >= 0) { /* Run a particular test */
printf("%s\n", all_tests[test_number].name);
int r = all_tests[test_number].function(plan, 1); //verbose
- printf(" %s\n", r ? "[PASS]" : "[FAIL]");
- if(r) npass++;
- else nfail++;
+ if(r) {
+ printf(" [FAIL] at line %d\n", r); nfail++;
+ } else {
+ printf(" [PASS]\n"); npass++;
+ }
}
else { /* Run all tests */
for(int i = 0; all_tests[i].name; i++) {
if(all_tests[i].enabled) {
printf("%-30s", all_tests[i].name);
int r = all_tests[i].function(plan, 0); // quiet
- printf(" %s\n", r ? "[PASS]" : "[FAIL]");
- if(r) npass++;
- else nfail++;
+ printf(" %s\n", r ? "[FAIL]" : "[PASS]");
+ if(r) nfail++;
+ else npass++;
}
}
printf("\nTotals: %d pass ... %d fail\n", npass, nfail);
=== added file 'storage/ndb/memcache/unit/tsv.cc'
--- a/storage/ndb/memcache/unit/tsv.cc 1970-01-01 00:00:00 +0000
+++ b/storage/ndb/memcache/unit/tsv.cc 2011-05-16 06:14:51 +0000
@@ -0,0 +1,157 @@
+/*
+ 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 <stdio.h>
+#include <assert.h>
+
+#include "TabSeparatedValues.h"
+
+#include "all_tests.h"
+
+
+int run_tsv_test(QueryPlan *, int v) {
+ {
+ TabSeparatedValues t1("frodo.xxx", 4, 5);
+ require(t1.getLength() == 5);
+ require(t1.advance() == 0);
+ detail(v, "tsv test 1 OK\n");
+ }
+
+ {
+ char sam[16];
+
+ const char *v2 = "sam\tjessie"; // null-terminated
+ TabSeparatedValues t2(v2, 4, strlen(v2));
+ strncpy(sam, t2.getPointer(), t2.getLength());
+ require(! strcmp(sam, "sam"));
+ require(t2.getLength() == 3);
+
+ require( t2.advance() == 1);
+
+ require(* t2.getPointer() == 'j');
+ require(t2.getLength() == 6);
+ detail(v, "tsv test 2 OK\n");
+ }
+
+ {
+ char jes[16];
+ const char *v3 = "sam\tjessie......"; // no null terminator
+ TabSeparatedValues t3(v3, 4, 10);
+
+ require(t3.advance() == 1);
+ require(t3.getLength() == 6);
+ strncpy(jes, t3.getPointer(), t3.getLength());
+ require(strncmp(jes,"jessie", t3.getLength()) == 0);
+ detail(v, "tsv test 3 OK\n");
+ }
+
+ {
+ const char *v4 = "\tabc"; // 2 values
+ TabSeparatedValues t4(v4, 4, strlen(v4));
+
+ /* First value is null */
+ require(t4.getLength() == 0);
+
+ /* Second value */
+ require(t4.advance() == 1);
+ require(* t4.getPointer() == 'a');
+ require( t4.getLength() == 3);
+
+ /* No more */
+ require(t4.advance() == 0);
+ detail(v, "tsv test 4 OK\n");
+ }
+
+ {
+ const char *v5 = "\t\tabc"; // 3 values
+ TabSeparatedValues t5(v5, 4, strlen(v5));
+
+ /* First value is null */
+ require(t5.getLength() == 0);
+
+ /* Second value */
+ require(t5.advance() == 1);
+ require(t5.getLength() == 0);
+
+ /* Third value */
+ require(t5.advance() == 1);
+ require(* t5.getPointer() == 'a');
+ require( t5.getLength() == 3);
+
+ /* No more */
+ require(t5.advance() == 0);
+ detail(v, "tsv test 5 OK\n");
+ }
+
+ {
+ const char *v6 = "\t\tabc\t\t"; // 5 values with null terminator
+ TabSeparatedValues t6(v6, 6, strlen(v6));
+
+ /* First value is null */
+ require(t6.getLength() == 0);
+
+ /* Second value is null */
+ require(t6.advance() == 1);
+ require(t6.getLength() == 0);
+
+ /* Third value is abc */
+ require(t6.advance() == 1);
+ require( t6.getLength() == 3);
+
+ /* 4th value is null */
+ require(t6.advance() == 1);
+ require(t6.getLength() == 0);
+
+ /* 5th value is null */
+ require(t6.advance() == 1);
+ require(t6.getLength() == 0);
+
+ /* No more */
+ require(t6.advance() == 0);
+ detail(v, "tsv test 6 OK\n");
+ }
+
+ {
+ const char *v7 = "\t\tabc\t__"; // 4 values, no null
+ TabSeparatedValues t7(v7, 4, strlen(v7) - 2);
+
+ /* First value is null */
+ require(t7.getLength() == 0);
+
+ /* Second value is null */
+ require(t7.advance() == 1);
+ require(t7.getLength() == 0);
+
+ /* Third value is abc */
+ require(t7.advance() == 1);
+ require(t7.getLength() == 3);
+
+ /* 4th value is null */
+ require(t7.advance() == 1);
+ require(t7.getLength() == 0);
+
+ /* No more */
+ require(t7.advance() == 0);
+ detail(v, "tsv test 7 OK\n");
+ }
+
+
+ pass;
+}
+
Attachment: [text/bzr-bundle] bzr/john.duncan@oracle.com-20110516061451-8n3n4e2wdzq2p15p.bundle
| Thread |
|---|
| • bzr commit into mysql-5.1-telco-7.2 branch (john.duncan:4176) | John David Duncan | 16 May |