[Commits] Rev 3515: Cassandra SE: in file:///data0/psergey/dev2/5.5-cassandra-r01/

Sergey Petrunya psergey at askmonty.org
Thu Sep 20 13:22:37 EEST 2012


At file:///data0/psergey/dev2/5.5-cassandra-r01/

------------------------------------------------------------
revno: 3515
revision-id: psergey at askmonty.org-20120920102236-1wb6p3dfkui79yux
parent: psergey at askmonty.org-20120916082221-dmjflcumsduprzac
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: 5.5-cassandra-r01
timestamp: Thu 2012-09-20 14:22:36 +0400
message:
  Cassandra SE:
  - Added @@cassandra_thrift_host global variable.
=== modified file 'mysql-test/r/cassandra.result'
--- a/mysql-test/r/cassandra.result	2012-09-12 03:36:23 +0000
+++ b/mysql-test/r/cassandra.result	2012-09-20 10:22:36 +0000
@@ -13,7 +13,7 @@
 ERROR HY000: Unable to connect to foreign data source: Default TException. [Keyspace no_such_keyspace does not exist]
 create table t1 (rowkey char(10) primary key, column1 char(10)) engine=cassandra 
 thrift_host='localhost' keyspace='no_such_keyspace';
-ERROR HY000: Unable to connect to foreign data source: thrift_host, keyspace, and column_family table options must be s
+ERROR HY000: Unable to connect to foreign data source: keyspace and column_family table options must be specified
 # Now, create a table for real and insert data
 create table t1 (pk varchar(36) primary key, data1 varchar(60), data2 bigint) engine=cassandra 
 thrift_host='localhost' keyspace='mariadbtest2' column_family='cf1';
@@ -266,6 +266,9 @@
 9b5658dc-f32f-11e1-94cd-f46d046e9f09	1234
 delete from t2;
 drop table t2;
+# 
+# boolean datatype support
+#
 CREATE TABLE t2 (rowkey int PRIMARY KEY, boolcol bool) ENGINE=CASSANDRA
 thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf7';
 insert into t2 values (0, 0);
@@ -276,6 +279,9 @@
 1	1
 delete from t2;
 drop table t2;
+# 
+# Counter datatype support (read-only)
+#
 CREATE TABLE t2 (rowkey varchar(32) PRIMARY KEY, countercol bigint) ENGINE=CASSANDRA
 thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf8';
 select * from t2;
@@ -283,3 +289,20 @@
 cnt1	1
 cnt2	100
 drop table t2;
+# 
+# Check that @@cassandra_default_thrift_host works
+#
+show variables like 'cassandra_default_thrift_host';
+Variable_name	Value
+cassandra_default_thrift_host	
+set cassandra_default_thrift_host='localhost';
+ERROR HY000: Variable 'cassandra_default_thrift_host' is a GLOBAL variable and should be set with SET GLOBAL
+set global cassandra_default_thrift_host='localhost';
+# Try creating a table without specifying thrift_host:
+CREATE TABLE t2 (rowkey varchar(32) PRIMARY KEY, countercol bigint) ENGINE=CASSANDRA
+keyspace='mariadbtest2' column_family = 'cf8';
+select * from t2;
+rowkey	countercol
+cnt1	1
+cnt2	100
+drop table t2;

=== modified file 'mysql-test/t/cassandra.test'
--- a/mysql-test/t/cassandra.test	2012-09-12 03:36:23 +0000
+++ b/mysql-test/t/cassandra.test	2012-09-20 10:22:36 +0000
@@ -356,6 +356,9 @@
 drop table t2;
 
 
+--echo # 
+--echo # boolean datatype support
+--echo #
 # create columnfamily cf7 (rowkey int primary key, boolcol boolean);
 CREATE TABLE t2 (rowkey int PRIMARY KEY, boolcol bool) ENGINE=CASSANDRA
   thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf7';
@@ -366,13 +369,29 @@
 drop table t2;
 
 
-# Counter type
+--echo # 
+--echo # Counter datatype support (read-only)
+--echo #
 # create columnfamily cf8 (rowkey int primary key, countercol counter);
 CREATE TABLE t2 (rowkey varchar(32) PRIMARY KEY, countercol bigint) ENGINE=CASSANDRA
   thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf8';
 select * from t2;
 drop table t2;
 
+--echo # 
+--echo # Check that @@cassandra_default_thrift_host works
+--echo #
+show variables like 'cassandra_default_thrift_host';
+--error ER_GLOBAL_VARIABLE
+set cassandra_default_thrift_host='localhost';
+set global cassandra_default_thrift_host='localhost';
+
+--echo # Try creating a table without specifying thrift_host:
+CREATE TABLE t2 (rowkey varchar(32) PRIMARY KEY, countercol bigint) ENGINE=CASSANDRA
+  keyspace='mariadbtest2' column_family = 'cf8';
+select * from t2;
+drop table t2;
+
 ############################################################################
 ## Cassandra cleanup
 ############################################################################

=== modified file 'storage/cassandra/ha_cassandra.cc'
--- a/storage/cassandra/ha_cassandra.cc	2012-09-16 08:22:21 +0000
+++ b/storage/cassandra/ha_cassandra.cc	2012-09-20 10:22:36 +0000
@@ -1,6 +1,18 @@
 /* 
-  MP AB copyrights 
-*/
+   Copyright (c) 2012, Monty Program Ab
+
+   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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 #ifdef USE_PRAGMA_IMPLEMENTATION
 #pragma implementation        // gcc: Class implementation
@@ -70,12 +82,54 @@
   "Number of rows in an rnd_read (full scan) batch",
   NULL, NULL, /*default*/ 10*1000, /*min*/ 1, /*max*/ 1024*1024*1024, 0);
 
+mysql_mutex_t cassandra_default_host_lock;
+static char* cassandra_default_thrift_host = NULL;
+static char cassandra_default_host_buf[256]="";
+
+static void 
+cassandra_default_thrift_host_update(THD *thd, 
+                                     struct st_mysql_sys_var* var,
+                                     void* var_ptr, /*!< out: where the
+                                                    formal string goes */
+                                     const void* save) /*!< in: immediate result 
+                                                       from check function */
+{
+  const char *new_host= *((char**)save);
+  const size_t max_len= sizeof(cassandra_default_host_buf);
+
+  mysql_mutex_lock(&cassandra_default_host_lock);
+  
+  if (new_host)
+  {
+    strncpy(cassandra_default_host_buf, new_host, max_len);
+    cassandra_default_host_buf[max_len]= 0;
+    cassandra_default_thrift_host= cassandra_default_host_buf;
+  }
+  else
+  {
+    cassandra_default_host_buf[0]= 0;
+    cassandra_default_thrift_host= NULL;
+  }
+  
+  *((const char**)var_ptr)= cassandra_default_thrift_host;
+
+  mysql_mutex_unlock(&cassandra_default_host_lock);
+}
+
+
+static MYSQL_SYSVAR_STR(default_thrift_host, cassandra_default_thrift_host,
+                        PLUGIN_VAR_RQCMDARG, 
+                        "Default host for Cassandra thrift connections", 
+                        /*check*/NULL,
+                        cassandra_default_thrift_host_update, 
+                        /*default*/NULL);
+
 static struct st_mysql_sys_var* cassandra_system_variables[]= {
   MYSQL_SYSVAR(insert_batch_size),
   MYSQL_SYSVAR(multiget_batch_size),
   MYSQL_SYSVAR(rnd_batch_size),
-//  MYSQL_SYSVAR(enum_var),
-//  MYSQL_SYSVAR(ulong_var),
+
+  MYSQL_SYSVAR(default_thrift_host),
   NULL
 };
 
@@ -158,6 +212,9 @@
   cassandra_hton->table_options= cassandra_table_option_list;
   //cassandra_hton->field_options= example_field_option_list;
   cassandra_hton->field_options= NULL;
+  
+  mysql_mutex_init(0 /* no instrumentation */, 
+                   &cassandra_default_host_lock, MY_MUTEX_INIT_FAST);
 
   DBUG_RETURN(0);
 }
@@ -171,6 +228,7 @@
     error= 1;
   my_hash_free(&cassandra_open_tables);
   mysql_mutex_destroy(&cassandra_mutex);
+  mysql_mutex_destroy(&cassandra_default_host_lock);
   DBUG_RETURN(error);
 }
 
@@ -277,22 +335,23 @@
 
 int ha_cassandra::open(const char *name, int mode, uint test_if_locked)
 {
+  ha_table_option_struct *options= table->s->option_struct;
+  int res;
   DBUG_ENTER("ha_cassandra::open");
 
   if (!(share = get_share(name, table)))
     DBUG_RETURN(1);
   thr_lock_data_init(&share->lock,&lock,NULL);
   
-  ha_table_option_struct *options= table->s->option_struct;
-  fprintf(stderr, "ha_cass: open thrift_host=%s keyspace=%s column_family=%s\n", 
-          options->thrift_host, options->keyspace, options->column_family);
-  
   DBUG_ASSERT(!se);
-  if (!options->thrift_host || !options->keyspace || !options->column_family)
-    DBUG_RETURN(HA_WRONG_CREATE_OPTION);
+  if ((res= check_table_options(options)))
+    DBUG_RETURN(res);
+
   se= get_cassandra_se();
   se->set_column_family(options->column_family);
-  if (se->connect(options->thrift_host, options->thrift_port, options->keyspace))
+  const char *thrift_host= options->thrift_host? options->thrift_host:
+                           cassandra_default_thrift_host;
+  if (se->connect(thrift_host, options->thrift_port, options->keyspace))
   {
     my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), se->error_str());
     DBUG_RETURN(HA_ERR_NO_CONNECTION);
@@ -320,6 +379,27 @@
 }
 
 
+int ha_cassandra::check_table_options(ha_table_option_struct *options)
+{
+  if (!options->thrift_host && (!cassandra_default_thrift_host ||
+                                !cassandra_default_thrift_host[0]))
+  {
+    my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), 
+             "thrift_host table option must be specified, or "
+             "@@cassandra_default_thrift_host must be set");
+    return HA_WRONG_CREATE_OPTION;
+  }
+
+  if (!options->keyspace || !options->column_family)
+  {
+    my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), 
+             "keyspace and column_family table options must be specified");
+    return HA_WRONG_CREATE_OPTION;
+  }
+  return 0;
+}
+
+
 /**
   @brief
   create() is called to create a database. The variable name will have the name
@@ -343,18 +423,11 @@
                          HA_CREATE_INFO *create_info)
 {
   ha_table_option_struct *options= table_arg->s->option_struct;
+  int res;
   DBUG_ENTER("ha_cassandra::create");
   DBUG_ASSERT(options);
   
-
   Field **pfield= table_arg->s->field;
-/*  
-  if (strcmp((*pfield)->field_name, "rowkey"))
-  {
-    my_error(ER_WRONG_COLUMN_NAME, MYF(0), "First column must be named 'rowkey'");
-    DBUG_RETURN(HA_WRONG_CREATE_OPTION);
-  }
-*/
   if (!((*pfield)->flags & NOT_NULL_FLAG))
   {
     my_error(ER_WRONG_COLUMN_NAME, MYF(0), "First column must be NOT NULL");
@@ -391,15 +464,14 @@
 */
 #endif
   DBUG_ASSERT(!se);
-  if (!options->thrift_host  || !options->keyspace || !options->column_family)
-  {
-    my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), 
-             "thrift_host, keyspace, and column_family table options must be specified");
-    DBUG_RETURN(HA_WRONG_CREATE_OPTION);
-  }
+  if ((res= check_table_options(options)))
+    DBUG_RETURN(res);
+
   se= get_cassandra_se();
   se->set_column_family(options->column_family);
-  if (se->connect(options->thrift_host, options->thrift_port, options->keyspace))
+  const char *thrift_host= options->thrift_host? options->thrift_host:
+                           cassandra_default_thrift_host;
+  if (se->connect(thrift_host, options->thrift_port, options->keyspace))
   {
     my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), se->error_str());
     DBUG_RETURN(HA_ERR_NO_CONNECTION);

=== modified file 'storage/cassandra/ha_cassandra.h'
--- a/storage/cassandra/ha_cassandra.h	2012-08-31 06:49:36 +0000
+++ b/storage/cassandra/ha_cassandra.h	2012-09-20 10:22:36 +0000
@@ -1,6 +1,18 @@
 /* 
-  MP AB copyrights 
-*/
+   Copyright (c) 2012, Monty Program Ab
+
+   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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 #ifdef USE_PRAGMA_INTERFACE
 #pragma interface			/* gcc class implementation */
 #endif
@@ -26,6 +38,8 @@
 
 class ColumnDataConverter;
 
+struct ha_table_option_struct;
+
 /** @brief
   Class definition for the storage engine
 */
@@ -45,6 +59,7 @@
   void free_field_converters();
   
   void read_cassandra_columns(bool unpack_pk);
+  int check_table_options(struct ha_table_option_struct* options);
 
   bool doing_insert_batch;
   ha_rows insert_rows_batched;



More information about the commits mailing list