Commit 004e0247 authored by Sergey Petrunya's avatar Sergey Petrunya

Cassandra SE:

- Added @@cassandra_thrift_host global variable.
parent eb63b07a
...@@ -13,7 +13,7 @@ thrift_host='localhost' keyspace='no_such_keyspace' column_family='colfam'; ...@@ -13,7 +13,7 @@ thrift_host='localhost' keyspace='no_such_keyspace' column_family='colfam';
ERROR HY000: Unable to connect to foreign data source: Default TException. [Keyspace no_such_keyspace does not exist] 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 create table t1 (rowkey char(10) primary key, column1 char(10)) engine=cassandra
thrift_host='localhost' keyspace='no_such_keyspace'; 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 # Now, create a table for real and insert data
create table t1 (pk varchar(36) primary key, data1 varchar(60), data2 bigint) engine=cassandra create table t1 (pk varchar(36) primary key, data1 varchar(60), data2 bigint) engine=cassandra
thrift_host='localhost' keyspace='mariadbtest2' column_family='cf1'; thrift_host='localhost' keyspace='mariadbtest2' column_family='cf1';
...@@ -266,6 +266,9 @@ rowkey col1 ...@@ -266,6 +266,9 @@ rowkey col1
9b5658dc-f32f-11e1-94cd-f46d046e9f09 1234 9b5658dc-f32f-11e1-94cd-f46d046e9f09 1234
delete from t2; delete from t2;
drop table t2; drop table t2;
#
# boolean datatype support
#
CREATE TABLE t2 (rowkey int PRIMARY KEY, boolcol bool) ENGINE=CASSANDRA CREATE TABLE t2 (rowkey int PRIMARY KEY, boolcol bool) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf7'; thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf7';
insert into t2 values (0, 0); insert into t2 values (0, 0);
...@@ -276,6 +279,9 @@ rowkey boolcol ...@@ -276,6 +279,9 @@ rowkey boolcol
1 1 1 1
delete from t2; delete from t2;
drop table t2; drop table t2;
#
# Counter datatype support (read-only)
#
CREATE TABLE t2 (rowkey varchar(32) PRIMARY KEY, countercol bigint) ENGINE=CASSANDRA CREATE TABLE t2 (rowkey varchar(32) PRIMARY KEY, countercol bigint) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf8'; thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf8';
select * from t2; select * from t2;
...@@ -283,3 +289,20 @@ rowkey countercol ...@@ -283,3 +289,20 @@ rowkey countercol
cnt1 1 cnt1 1
cnt2 100 cnt2 100
drop table t2; 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;
...@@ -356,6 +356,9 @@ delete from t2; ...@@ -356,6 +356,9 @@ delete from t2;
drop table t2; drop table t2;
--echo #
--echo # boolean datatype support
--echo #
# create columnfamily cf7 (rowkey int primary key, boolcol boolean); # create columnfamily cf7 (rowkey int primary key, boolcol boolean);
CREATE TABLE t2 (rowkey int PRIMARY KEY, boolcol bool) ENGINE=CASSANDRA CREATE TABLE t2 (rowkey int PRIMARY KEY, boolcol bool) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf7'; thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf7';
...@@ -366,13 +369,29 @@ delete from t2; ...@@ -366,13 +369,29 @@ delete from t2;
drop table t2; drop table t2;
# Counter type --echo #
--echo # Counter datatype support (read-only)
--echo #
# create columnfamily cf8 (rowkey int primary key, countercol counter); # create columnfamily cf8 (rowkey int primary key, countercol counter);
CREATE TABLE t2 (rowkey varchar(32) PRIMARY KEY, countercol bigint) ENGINE=CASSANDRA CREATE TABLE t2 (rowkey varchar(32) PRIMARY KEY, countercol bigint) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf8'; thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf8';
select * from t2; select * from t2;
drop table 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 ## Cassandra cleanup
############################################################################ ############################################################################
......
/* /*
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 #ifdef USE_PRAGMA_IMPLEMENTATION
#pragma implementation // gcc: Class implementation #pragma implementation // gcc: Class implementation
...@@ -70,12 +82,54 @@ static MYSQL_THDVAR_ULONG(rnd_batch_size, PLUGIN_VAR_RQCMDARG, ...@@ -70,12 +82,54 @@ static MYSQL_THDVAR_ULONG(rnd_batch_size, PLUGIN_VAR_RQCMDARG,
"Number of rows in an rnd_read (full scan) batch", "Number of rows in an rnd_read (full scan) batch",
NULL, NULL, /*default*/ 10*1000, /*min*/ 1, /*max*/ 1024*1024*1024, 0); 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[]= { static struct st_mysql_sys_var* cassandra_system_variables[]= {
MYSQL_SYSVAR(insert_batch_size), MYSQL_SYSVAR(insert_batch_size),
MYSQL_SYSVAR(multiget_batch_size), MYSQL_SYSVAR(multiget_batch_size),
MYSQL_SYSVAR(rnd_batch_size), MYSQL_SYSVAR(rnd_batch_size),
// MYSQL_SYSVAR(enum_var),
// MYSQL_SYSVAR(ulong_var), MYSQL_SYSVAR(default_thrift_host),
NULL NULL
}; };
...@@ -158,6 +212,9 @@ static int cassandra_init_func(void *p) ...@@ -158,6 +212,9 @@ static int cassandra_init_func(void *p)
cassandra_hton->table_options= cassandra_table_option_list; cassandra_hton->table_options= cassandra_table_option_list;
//cassandra_hton->field_options= example_field_option_list; //cassandra_hton->field_options= example_field_option_list;
cassandra_hton->field_options= NULL; cassandra_hton->field_options= NULL;
mysql_mutex_init(0 /* no instrumentation */,
&cassandra_default_host_lock, MY_MUTEX_INIT_FAST);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -171,6 +228,7 @@ static int cassandra_done_func(void *p) ...@@ -171,6 +228,7 @@ static int cassandra_done_func(void *p)
error= 1; error= 1;
my_hash_free(&cassandra_open_tables); my_hash_free(&cassandra_open_tables);
mysql_mutex_destroy(&cassandra_mutex); mysql_mutex_destroy(&cassandra_mutex);
mysql_mutex_destroy(&cassandra_default_host_lock);
DBUG_RETURN(error); DBUG_RETURN(error);
} }
...@@ -277,22 +335,23 @@ const char **ha_cassandra::bas_ext() const ...@@ -277,22 +335,23 @@ const char **ha_cassandra::bas_ext() const
int ha_cassandra::open(const char *name, int mode, uint test_if_locked) 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"); DBUG_ENTER("ha_cassandra::open");
if (!(share = get_share(name, table))) if (!(share = get_share(name, table)))
DBUG_RETURN(1); DBUG_RETURN(1);
thr_lock_data_init(&share->lock,&lock,NULL); 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); DBUG_ASSERT(!se);
if (!options->thrift_host || !options->keyspace || !options->column_family) if ((res= check_table_options(options)))
DBUG_RETURN(HA_WRONG_CREATE_OPTION); DBUG_RETURN(res);
se= get_cassandra_se(); se= get_cassandra_se();
se->set_column_family(options->column_family); 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()); my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), se->error_str());
DBUG_RETURN(HA_ERR_NO_CONNECTION); DBUG_RETURN(HA_ERR_NO_CONNECTION);
...@@ -320,6 +379,27 @@ int ha_cassandra::close(void) ...@@ -320,6 +379,27 @@ int ha_cassandra::close(void)
} }
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 @brief
create() is called to create a database. The variable name will have the name create() is called to create a database. The variable name will have the name
...@@ -343,18 +423,11 @@ int ha_cassandra::create(const char *name, TABLE *table_arg, ...@@ -343,18 +423,11 @@ int ha_cassandra::create(const char *name, TABLE *table_arg,
HA_CREATE_INFO *create_info) HA_CREATE_INFO *create_info)
{ {
ha_table_option_struct *options= table_arg->s->option_struct; ha_table_option_struct *options= table_arg->s->option_struct;
int res;
DBUG_ENTER("ha_cassandra::create"); DBUG_ENTER("ha_cassandra::create");
DBUG_ASSERT(options); DBUG_ASSERT(options);
Field **pfield= table_arg->s->field; 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)) if (!((*pfield)->flags & NOT_NULL_FLAG))
{ {
my_error(ER_WRONG_COLUMN_NAME, MYF(0), "First column must be NOT NULL"); my_error(ER_WRONG_COLUMN_NAME, MYF(0), "First column must be NOT NULL");
...@@ -391,15 +464,14 @@ int ha_cassandra::create(const char *name, TABLE *table_arg, ...@@ -391,15 +464,14 @@ int ha_cassandra::create(const char *name, TABLE *table_arg,
*/ */
#endif #endif
DBUG_ASSERT(!se); DBUG_ASSERT(!se);
if (!options->thrift_host || !options->keyspace || !options->column_family) if ((res= check_table_options(options)))
{ DBUG_RETURN(res);
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);
}
se= get_cassandra_se(); se= get_cassandra_se();
se->set_column_family(options->column_family); 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()); my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), se->error_str());
DBUG_RETURN(HA_ERR_NO_CONNECTION); DBUG_RETURN(HA_ERR_NO_CONNECTION);
......
/* /*
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 #ifdef USE_PRAGMA_INTERFACE
#pragma interface /* gcc class implementation */ #pragma interface /* gcc class implementation */
#endif #endif
...@@ -26,6 +38,8 @@ typedef struct st_cassandra_share { ...@@ -26,6 +38,8 @@ typedef struct st_cassandra_share {
class ColumnDataConverter; class ColumnDataConverter;
struct ha_table_option_struct;
/** @brief /** @brief
Class definition for the storage engine Class definition for the storage engine
*/ */
...@@ -45,6 +59,7 @@ class ha_cassandra: public handler ...@@ -45,6 +59,7 @@ class ha_cassandra: public handler
void free_field_converters(); void free_field_converters();
void read_cassandra_columns(bool unpack_pk); void read_cassandra_columns(bool unpack_pk);
int check_table_options(struct ha_table_option_struct* options);
bool doing_insert_batch; bool doing_insert_batch;
ha_rows insert_rows_batched; ha_rows insert_rows_batched;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment