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

Sergey Petrunya psergey at askmonty.org
Thu Sep 27 15:08:29 EEST 2012


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

------------------------------------------------------------
revno: 3524
revision-id: psergey at askmonty.org-20120927120828-jn079t6ub2uu5naf
parent: psergey at askmonty.org-20120927075914-c90so471vax0fhop
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: 5.5-cassandra-r01
timestamp: Thu 2012-09-27 16:08:28 +0400
message:
  Cassandra SE: lazy connections
  - Don't connect right away in ha_cassandra::open. If we do this, it becomes 
    impossible to do SHOW CREATE TABLE when the server is not present. 
  - Note: CREATE TABLE still requires that connection is present, as it needs 
    to check whether the specified DDL can be used with Cassandra.  We could
    delay that check also, but then one would not be able to find out about 
    errors in table DDL until they do a SELECT.
=== modified file 'storage/cassandra/cassandra_se.cc'
--- a/storage/cassandra/cassandra_se.cc	2012-09-27 07:59:14 +0000
+++ b/storage/cassandra/cassandra_se.cc	2012-09-27 12:08:28 +0000
@@ -159,7 +159,7 @@
 /////////////////////////////////////////////////////////////////////////////
 // Connection and setup
 /////////////////////////////////////////////////////////////////////////////
-Cassandra_se_interface *get_cassandra_se()
+Cassandra_se_interface *create_cassandra_se()
 {
   return new Cassandra_se_impl;
 }

=== modified file 'storage/cassandra/cassandra_se.h'
--- a/storage/cassandra/cassandra_se.h	2012-09-27 07:59:14 +0000
+++ b/storage/cassandra/cassandra_se.h	2012-09-27 12:08:28 +0000
@@ -110,5 +110,5 @@
 extern Cassandra_status_vars cassandra_counters;
 
 
-Cassandra_se_interface *get_cassandra_se();
+Cassandra_se_interface *create_cassandra_se();
 

=== modified file 'storage/cassandra/ha_cassandra.cc'
--- a/storage/cassandra/ha_cassandra.cc	2012-09-27 07:59:14 +0000
+++ b/storage/cassandra/ha_cassandra.cc	2012-09-27 12:08:28 +0000
@@ -375,10 +375,36 @@
 }
 
 
+int ha_cassandra::connect_and_check_options(TABLE *table_arg)
+{
+  ha_table_option_struct *options= table_arg->s->option_struct;
+  int res;
+  DBUG_ENTER("ha_cassandra::connect_and_check_options");
+
+  if ((res= check_table_options(options)))
+    DBUG_RETURN(res);
+
+  se= create_cassandra_se();
+  se->set_column_family(options->column_family);
+  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);
+  }
+
+  if (setup_field_converters(table_arg->field, table_arg->s->fields))
+  {
+    DBUG_RETURN(HA_ERR_NO_CONNECTION);
+  }
+
+  DBUG_RETURN(0);
+}
+
+
 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)))
@@ -386,23 +412,17 @@
   thr_lock_data_init(&share->lock,&lock,NULL);
   
   DBUG_ASSERT(!se);
-  if ((res= check_table_options(options)))
+  /*
+    Don't do the following on open: it prevents SHOW CREATE TABLE when the server
+    has gone away.
+  */
+  /*
+  int res;
+  if ((res= connect_and_check_options(table)))
+  {
     DBUG_RETURN(res);
-
-  se= get_cassandra_se();
-  se->set_column_family(options->column_family);
-  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);
-  }
-
-  if (setup_field_converters(table->field, table->s->fields))
-  {
-    DBUG_RETURN(HA_ERR_NO_CONNECTION);
-  }
+  }
+  */
 
   info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
   insert_lineno= 0;
@@ -444,7 +464,7 @@
 
 /**
   @brief
-  create() is called to create a database. The variable name will have the name
+  create() is called to create a table. The variable name will have the name
   of the table.
 
   @details
@@ -485,45 +505,10 @@
     DBUG_RETURN(HA_WRONG_CREATE_OPTION);
   }
 
-#ifndef DBUG_OFF
-/*  
-  DBUG_PRINT("info", ("strparam: '%-.64s'  ullparam: %llu  enumparam: %u  "\
-                      "boolparam: %u",
-                      (options->strparam ? options->strparam : "<NULL>"),
-                      options->ullparam, options->enumparam, options->boolparam));
-
-  psergey-todo: check table definition!
-  for (Field **field= table_arg->s->field; *field; field++)
-  {
-    ha_field_option_struct *field_options= (*field)->option_struct;
-    DBUG_ASSERT(field_options);
-    DBUG_PRINT("info", ("field: %s  complex: '%-.64s'",
-                         (*field)->field_name,
-                         (field_options->complex_param_to_parse_it_in_engine ?
-                          field_options->complex_param_to_parse_it_in_engine :
-                          "<NULL>")));
-  }
-*/
-#endif
   DBUG_ASSERT(!se);
-  if ((res= check_table_options(options)))
+  if ((res= connect_and_check_options(table_arg)))
     DBUG_RETURN(res);
 
-  se= get_cassandra_se();
-  se->set_column_family(options->column_family);
-  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);
-  }
-  
-  if (setup_field_converters(table_arg->s->field, table_arg->s->fields))
-  {
-    my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), "setup_field_converters");
-    DBUG_RETURN(HA_ERR_NO_CONNECTION);
-  }
   insert_lineno= 0;
   DBUG_RETURN(0);
 }
@@ -1064,6 +1049,14 @@
 }
 
 
+int ha_cassandra::index_init(uint idx, bool sorted)
+{
+  int ires;
+  if (!se && (ires= connect_and_check_options(table)))
+    return ires;
+  return 0;
+}
+
 void store_key_image_to_rec(Field *field, uchar *ptr, uint len);
 
 int ha_cassandra::index_read_map(uchar *buf, const uchar *key,
@@ -1198,8 +1191,12 @@
 int ha_cassandra::write_row(uchar *buf)
 {
   my_bitmap_map *old_map;
+  int ires;
   DBUG_ENTER("ha_cassandra::write_row");
   
+  if (!se && (ires= connect_and_check_options(table)))
+    DBUG_RETURN(ires);
+
   if (!doing_insert_batch)
     se->clear_insert_buffer();
 
@@ -1260,6 +1257,10 @@
 
 void ha_cassandra::start_bulk_insert(ha_rows rows)
 {
+  int ires;
+  if (!se && (ires= connect_and_check_options(table)))
+    return;
+
   doing_insert_batch= true;
   insert_rows_batched= 0;
 
@@ -1283,7 +1284,12 @@
 int ha_cassandra::rnd_init(bool scan)
 {
   bool bres;
+  int ires;
   DBUG_ENTER("ha_cassandra::rnd_init");
+
+  if (!se && (ires= connect_and_check_options(table)))
+    DBUG_RETURN(ires);
+
   if (!scan)
   {
     /* Prepare for rnd_pos() calls. We don't need to anything. */
@@ -1338,8 +1344,12 @@
 int ha_cassandra::delete_all_rows()
 {
   bool bres;
+  int ires;
   DBUG_ENTER("ha_cassandra::delete_all_rows");
 
+  if (!se && (ires= connect_and_check_options(table)))
+    DBUG_RETURN(ires);
+
   bres= se->truncate();
   
   if (bres)

=== modified file 'storage/cassandra/ha_cassandra.h'
--- a/storage/cassandra/ha_cassandra.h	2012-09-27 07:59:14 +0000
+++ b/storage/cassandra/ha_cassandra.h	2012-09-27 12:08:28 +0000
@@ -69,6 +69,7 @@
   ha_rows insert_lineno;
   void print_conversion_error(const char *field_name, 
                               char *cass_value, int cass_value_len);
+  int connect_and_check_options(TABLE *table_arg);
 public:
   ha_cassandra(handlerton *hton, TABLE_SHARE *table_arg);
   ~ha_cassandra()
@@ -152,7 +153,8 @@
    */
   uint max_supported_key_length()    const { return 16*1024; /* just to return something*/ }
   
-  /* At the moment, we're ok with default handler::index_init() implementation. */
+  int index_init(uint idx, bool sorted);
+
   int index_read_map(uchar * buf, const uchar * key,
                      key_part_map keypart_map,
                      enum ha_rkey_function find_flag);



More information about the commits mailing list