From 1dbee72783760ba16ef4997998662faf0e3c5e77 Mon Sep 17 00:00:00 2001
From: Kazuhiko Shiozaki <kazuhiko@nexedi.com>
Date: Mon, 31 Oct 2011 18:08:57 +0100
Subject: [PATCH] version up : groonga storage engine 1.0.1.

---
 component/groonga/buildout.cfg                |   4 +-
 component/mariadb/buildout.cfg                |  12 +
 ...groonga-storage-engine-1.0.1-mariadb.patch | 295 ++++++++++++++++++
 3 files changed, 309 insertions(+), 2 deletions(-)
 create mode 100644 component/mariadb/groonga-storage-engine-1.0.1-mariadb.patch

diff --git a/component/groonga/buildout.cfg b/component/groonga/buildout.cfg
index c3b4cd371..1d1698db8 100644
--- a/component/groonga/buildout.cfg
+++ b/component/groonga/buildout.cfg
@@ -8,8 +8,8 @@ parts =
 
 [groonga]
 recipe = hexagonit.recipe.cmmi
-url = http://packages.groonga.org/source/groonga/groonga-1.2.6.tar.gz
-md5sum = 21bc2f043304837717d3aacdf4118c7a
+url = http://packages.groonga.org/source/groonga/groonga-1.2.7.tar.gz
+md5sum = ef83d94b8e602507b068f3f6d5cf8e92
 configure-options =
   --disable-static
   --disable-glibtest
diff --git a/component/mariadb/buildout.cfg b/component/mariadb/buildout.cfg
index b42552684..7a9151b88 100644
--- a/component/mariadb/buildout.cfg
+++ b/component/mariadb/buildout.cfg
@@ -19,6 +19,13 @@ md5sum = d65f61829cfbcd5062f49db2b00bd6fe
 filename = mysql_create_system_tables__no_test.patch
 download-only = true
 
+[groonga-storage-engine-1.0.1-mariadb.patch]
+recipe = hexagonit.recipe.download
+url = ${:_profile_base_location_}/${:filename}
+md5sum = c477db8731f15a13e1999596a6e4bad0
+filename = ${:_buildout_section_name_}
+download-only = true
+
 [mariadb]
 recipe = hexagonit.recipe.cmmi
 version = 5.3.2-beta
@@ -54,6 +61,11 @@ environment =
 recipe = hexagonit.recipe.cmmi
 url = http://github.com/downloads/mroonga/mroonga/groonga-storage-engine-0.5.tar.gz
 md5sum = 52fed75d97a91f239750a1011ea9e468
+url = http://github.com/downloads/mroonga/mroonga/groonga-storage-engine-1.0.1.tar.gz
+md5sum = 9a910df165245a5bd3622b7ed41dfb12
+patch-options = -p1
+patches =
+  ${groonga-storage-engine-1.0.1-mariadb.patch:location}/${groonga-storage-engine-1.0.1-mariadb.patch:filename}
 configure-options =
   --with-mysql-source=${mariadb:location}__compile__/mariadb-${mariadb:version}
   --with-mysql-config=${mariadb:location}/bin/mysql_config
diff --git a/component/mariadb/groonga-storage-engine-1.0.1-mariadb.patch b/component/mariadb/groonga-storage-engine-1.0.1-mariadb.patch
new file mode 100644
index 000000000..3b351f865
--- /dev/null
+++ b/component/mariadb/groonga-storage-engine-1.0.1-mariadb.patch
@@ -0,0 +1,295 @@
+diff -ur '--exclude=doc' groonga-storage-engine-1.0.1/ha_mroonga.cc mroonga-mroonga-3345884//ha_mroonga.cc
+--- groonga-storage-engine-1.0.1/ha_mroonga.cc	2011-10-28 07:19:15.506715507 +0200
++++ groonga-storage-engine-1.0.1/ha_mroonga.cc	2011-10-31 16:37:35.000000000 +0100
+@@ -4442,7 +4443,11 @@
+     MRN_SET_WRAP_TABLE_KEY(this, table);
+     if (fulltext_searching)
+       set_pk_bitmap();
++#ifdef MRN_HANDLER_HAVE_HA_INDEX_READ_MAP
++    error = wrap_handler->ha_index_read_map(buf, key, keypart_map, find_flag);
++#else
+     error = wrap_handler->index_read_map(buf, key, keypart_map, find_flag);
++#endif
+     MRN_SET_BASE_SHARE_KEY(share, table->s);
+     MRN_SET_BASE_TABLE_KEY(this, table);
+   }
+@@ -4572,6 +4577,7 @@
+   DBUG_RETURN(error);
+ }
+ 
++#ifdef MRN_HANDLER_HAVE_INDEX_READ_LAST_MAP
+ int ha_mroonga::wrapper_index_read_last_map(uchar *buf, const uchar *key,
+                                             key_part_map keypart_map)
+ {
+@@ -4658,6 +4664,7 @@
+   }
+   DBUG_RETURN(error);
+ }
++#endif
+ 
+ int ha_mroonga::wrapper_index_next(uchar *buf)
+ {
+@@ -6226,7 +6233,11 @@
+ }
+ 
+ ha_rows ha_mroonga::wrapper_multi_range_read_info(uint keyno, uint n_ranges,
+-                                                  uint keys, uint *bufsz,
++                                                  uint keys,
++#ifdef MRN_HANDLER_HAVE_MULTI_RANGE_READ_INFO_KEY_PARTS
++                                                  uint key_parts,
++#endif
++                                                  uint *bufsz,
+                                                   uint *flags, COST_VECT *cost)
+ {
+   MRN_DBUG_ENTER_METHOD();
+@@ -6236,6 +6247,9 @@
+   if (fulltext_searching)
+     set_pk_bitmap();
+   rows = wrap_handler->multi_range_read_info(keyno, n_ranges, keys,
++#ifdef MRN_HANDLER_HAVE_MULTI_RANGE_READ_INFO_KEY_PARTS
++                                             key_parts,
++#endif
+                                              bufsz, flags, cost);
+   MRN_SET_BASE_SHARE_KEY(share, table->s);
+   MRN_SET_BASE_TABLE_KEY(this, table);
+@@ -6243,16 +6257,26 @@
+ }
+ 
+ ha_rows ha_mroonga::storage_multi_range_read_info(uint keyno, uint n_ranges,
+-                                                  uint keys, uint *bufsz,
++                                                  uint keys,
++#ifdef MRN_HANDLER_HAVE_MULTI_RANGE_READ_INFO_KEY_PARTS
++                                                  uint key_parts,
++#endif
++                                                  uint *bufsz,
+                                                   uint *flags, COST_VECT *cost)
+ {
+   MRN_DBUG_ENTER_METHOD();
+   ha_rows rows = handler::multi_range_read_info(keyno, n_ranges, keys,
++#ifdef MRN_HANDLER_HAVE_MULTI_RANGE_READ_INFO_KEY_PARTS
++                                                key_parts,
++#endif
+                                                 bufsz, flags, cost);
+   DBUG_RETURN(rows);
+ }
+ 
+ ha_rows ha_mroonga::multi_range_read_info(uint keyno, uint n_ranges, uint keys,
++#ifdef MRN_HANDLER_HAVE_MULTI_RANGE_READ_INFO_KEY_PARTS
++                                          uint key_parts,
++#endif
+                                           uint *bufsz, uint *flags,
+                                           COST_VECT *cost)
+ {
+@@ -6261,9 +6285,15 @@
+   if (share->wrapper_mode)
+   {
+     rows = wrapper_multi_range_read_info(keyno, n_ranges, keys,
++#ifdef MRN_HANDLER_HAVE_MULTI_RANGE_READ_INFO_KEY_PARTS
++                                         key_parts,
++#endif
+                                          bufsz, flags, cost);
+   } else {
+     rows = storage_multi_range_read_info(keyno, n_ranges, keys,
++#ifdef MRN_HANDLER_HAVE_MULTI_RANGE_READ_INFO_KEY_PARTS
++                                         key_parts,
++#endif
+                                          bufsz, flags, cost);
+   }
+   DBUG_RETURN(rows);
+@@ -6315,7 +6345,7 @@
+   DBUG_RETURN(error);
+ }
+ 
+-int ha_mroonga::wrapper_multi_range_read_next(char **range_info)
++int ha_mroonga::wrapper_multi_range_read_next(range_id_t *range_info)
+ {
+   MRN_DBUG_ENTER_METHOD();
+   int error = 0;
+@@ -6329,14 +6359,14 @@
+   DBUG_RETURN(error);
+ }
+ 
+-int ha_mroonga::storage_multi_range_read_next(char **range_info)
++int ha_mroonga::storage_multi_range_read_next(range_id_t *range_info)
+ {
+   MRN_DBUG_ENTER_METHOD();
+   int error = handler::multi_range_read_next(range_info);
+   DBUG_RETURN(error);
+ }
+ 
+-int ha_mroonga::multi_range_read_next(char **range_info)
++int ha_mroonga::multi_range_read_next(range_id_t *range_info)
+ {
+   MRN_DBUG_ENTER_METHOD();
+   int error = 0;
+diff -ur '--exclude=doc' groonga-storage-engine-1.0.1/ha_mroonga.h groonga-storage-engine-1.0.1/ha_mroonga.h
+--- groonga-storage-engine-1.0.1/ha_mroonga.h	2011-10-27 12:31:36.859277054 +0200
++++ groonga-storage-engine-1.0.1/ha_mroonga.h	2011-10-31 16:37:35.000000000 +0100
+@@ -47,11 +47,12 @@
+ #  define MRN_HANDLER_HAVE_ADD_INDEX 1
+ #endif
+ 
+-#if (MYSQL_VERSION_ID >= 50600) || \
++#if (MYSQL_VERSION_ID >= 50603) || \
+     (defined(MRN_MARIADB_P) && MYSQL_VERSION_ID >= 50302)
+ #  define MRN_HANDLER_HAVE_HA_CLOSE 1
+ #  define MRN_HANDLER_HAVE_HA_RND_NEXT 1
+ #  define MRN_HANDLER_HAVE_HA_RND_POS 1
++#  define MRN_HANDLER_HAVE_HA_INDEX_READ_MAP 1
+ #  define MRN_HANDLER_HAVE_HA_INDEX_READ_IDX_MAP 1
+ #  define MRN_HANDLER_HAVE_HA_INDEX_NEXT 1
+ #  define MRN_HANDLER_HAVE_HA_INDEX_PREV 1
+@@ -66,6 +67,14 @@
+ #  define MRN_HANDLER_HAVE_HA_INPLACE_INDEX_CHANGE
+ #endif
+ 
++#ifndef MRN_MARIADB_P
++#  define MRN_HANDLER_HAVE_INDEX_READ_LAST_MAP
++#endif
++
++#if (defined(MRN_MARIADB_P) && MYSQL_VERSION_ID >= 50302)
++#  define MRN_HANDLER_HAVE_MULTI_RANGE_READ_INFO_KEY_PARTS
++#endif
++
+ #if MYSQL_VERSION_ID < 50600
+   typedef Item COND;
+ #endif
+@@ -74,6 +83,10 @@
+   typedef MYSQL_ERROR Sql_condition;
+ #endif
+ 
++#ifndef MRN_MARIADB_P
++  typedef char *range_id_t;
++#endif
++
+ class ha_mroonga;
+ 
+ /* structs */
+@@ -213,11 +226,15 @@
+   ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
+   int index_init(uint idx, bool sorted);
+   int index_end();
++#ifndef MRN_HANDLER_HAVE_HA_INDEX_READ_MAP
+   int index_read_map(uchar * buf, const uchar * key,
+                      key_part_map keypart_map,
+                      enum ha_rkey_function find_flag);
++#endif
++#ifdef MRN_HANDLER_HAVE_INDEX_READ_LAST_MAP
+   int index_read_last_map(uchar *buf, const uchar *key,
+                           key_part_map keypart_map);
++#endif
+ #ifndef MRN_HANDLER_HAVE_HA_INDEX_NEXT
+   int index_next(uchar *buf);
+ #endif
+@@ -261,11 +278,14 @@
+                                       uint n_ranges, uint *bufsz,
+                                       uint *flags, COST_VECT *cost);
+   ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys,
++#ifdef MRN_HANDLER_HAVE_MULTI_RANGE_READ_INFO_KEY_PARTS
++                                uint key_parts,
++#endif
+                                 uint *bufsz, uint *flags, COST_VECT *cost);
+   int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
+                             uint n_ranges, uint mode,
+                             HANDLER_BUFFER *buf);
+-  int multi_range_read_next(char **range_info);
++  int multi_range_read_next(range_id_t *range_info);
+ #else // MRN_HANDLER_HAVE_MULTI_RANGE_READ
+   int read_multi_range_first(KEY_MULTI_RANGE **found_range_p,
+                              KEY_MULTI_RANGE *ranges,
+@@ -321,6 +341,11 @@
+ #ifdef MRN_HANDLER_HAVE_HA_RND_POS
+   int rnd_pos(uchar *buf, uchar *pos);
+ #endif
++#ifdef MRN_HANDLER_HAVE_HA_INDEX_READ_MAP
++  int index_read_map(uchar *buf, const uchar *key,
++                     key_part_map keypart_map,
++                     enum ha_rkey_function find_flag);
++#endif
+ #ifdef MRN_HANDLER_HAVE_HA_INDEX_NEXT
+   int index_next(uchar *buf);
+ #endif
+@@ -469,10 +494,12 @@
+   int storage_index_read_map(uchar *buf, const uchar *key,
+                              key_part_map keypart_map,
+                              enum ha_rkey_function find_flag);
++#ifdef MRN_HANDLER_HAVE_INDEX_READ_LAST_MAP
+   int wrapper_index_read_last_map(uchar *buf, const uchar *key,
+                                   key_part_map keypart_map);
+   int storage_index_read_last_map(uchar *buf, const uchar *key,
+                                   key_part_map keypart_map);
++#endif
+   int wrapper_index_next(uchar *buf);
+   int storage_index_next(uchar *buf);
+   int wrapper_index_prev(uchar *buf);
+@@ -533,9 +560,15 @@
+                                               uint *flags,
+                                               COST_VECT *cost);
+   ha_rows wrapper_multi_range_read_info(uint keyno, uint n_ranges, uint keys,
++#ifdef MRN_HANDLER_HAVE_MULTI_RANGE_READ_INFO_KEY_PARTS
++                                        uint key_parts,
++#endif
+                                         uint *bufsz, uint *flags,
+                                         COST_VECT *cost);
+   ha_rows storage_multi_range_read_info(uint keyno, uint n_ranges, uint keys,
++#ifdef MRN_HANDLER_HAVE_MULTI_RANGE_READ_INFO_KEY_PARTS
++                                        uint key_parts,
++#endif
+                                         uint *bufsz, uint *flags,
+                                         COST_VECT *cost);
+   int wrapper_multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
+@@ -544,8 +577,8 @@
+   int storage_multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
+                                     uint n_ranges, uint mode,
+                                     HANDLER_BUFFER *buf);
+-  int wrapper_multi_range_read_next(char **range_info);
+-  int storage_multi_range_read_next(char **range_info);
++  int wrapper_multi_range_read_next(range_id_t *range_info);
++  int storage_multi_range_read_next(range_id_t *range_info);
+ #else // MRN_HANDLER_HAVE_MULTI_RANGE_READ
+   int wrapper_read_multi_range_first(KEY_MULTI_RANGE **found_range_p,
+                                      KEY_MULTI_RANGE *ranges,
+diff -ur '--exclude=doc' groonga-storage-engine-1.0.1/test/run-sql-test.sh groonga-storage-engine-1.0.1/test/run-sql-test.sh
+--- groonga-storage-engine-1.0.1/test/run-sql-test.sh	2011-09-27 10:43:29.093290682 +0200
++++ groonga-storage-engine-1.0.1/test/run-sql-test.sh	2011-10-31 16:37:35.000000000 +0100
+@@ -24,12 +24,20 @@
+ source_test_suites_dir="${source_mysql_test_dir}/suite"
+ build_test_suites_dir="${build_mysql_test_dir}/suite"
+ case "${MYSQL_VERSION}" in
+-    5.1)
++    5.1.*)
+ 	plugins_dir="${MYSQL_BUILD}/lib/mysql/plugin"
+ 	if ! test -d "${build_test_suites_dir}"; then
+ 	    mkdir -p "${build_test_suites_dir}"
+ 	fi
+ 	;;
++    5.3.*-MariaDB*)
++	if ! test -d "${build_test_suites_dir}"; then
++	    ln -s "${source_test_suites_dir}" "${build_test_suites_dir}"
++	fi
++	if ! test -d "${MYSQL_BUILD}/plugin/mroonga"; then
++	    ln -s "${top_dir}" "${MYSQL_BUILD}/plugin/mroonga"
++	fi
++	;;
+     *)
+ 	if ! test -d "${build_test_suites_dir}"; then
+ 	    ln -s "${source_test_suites_dir}" "${build_test_suites_dir}"
+@@ -47,10 +55,14 @@
+     fi
+ done
+ 
+-make -C ${top_dir} \
+-    install-pluginLTLIBRARIES \
+-    plugindir=${plugins_dir} > /dev/null || \
+-    exit 1
++if test -n "${plugins_dir}"; then
++    make -C ${top_dir} \
++	install-pluginLTLIBRARIES \
++	plugindir=${plugins_dir} > /dev/null || \
++	exit 1
++else
++    make -C ${top_dir} > /dev/null || exit 1
++fi
+ 
+ (cd "$build_mysql_test_dir" && \
+     ./mysql-test-run.pl \
-- 
2.30.9