Commit 6195a016 authored by Will DeVries's avatar Will DeVries Committed by Sergei Petrunia

Remove st_clustrixdb_trx.

parent 84cfedff
...@@ -154,10 +154,14 @@ int clustrix_connection::read_query_response() ...@@ -154,10 +154,14 @@ int clustrix_connection::read_query_response()
int clustrix_connection::begin_trans() int clustrix_connection::begin_trans()
{ {
if (has_transaction)
return 0;
const char *stmt = "BEGIN TRANSACTION"; const char *stmt = "BEGIN TRANSACTION";
int error_code = mysql_real_query(&clustrix_net, stmt, strlen(stmt)); int error_code = mysql_real_query(&clustrix_net, stmt, strlen(stmt));
if (error_code) if (error_code)
return mysql_errno(&clustrix_net); return mysql_errno(&clustrix_net);
has_transaction = TRUE;
return error_code; return error_code;
} }
...@@ -167,6 +171,8 @@ int clustrix_connection::commit_trans() ...@@ -167,6 +171,8 @@ int clustrix_connection::commit_trans()
int error_code = mysql_real_query(&clustrix_net, stmt, strlen(stmt)); int error_code = mysql_real_query(&clustrix_net, stmt, strlen(stmt));
if (error_code) if (error_code)
return mysql_errno(&clustrix_net); return mysql_errno(&clustrix_net);
has_transaction = FALSE;
has_statement_trans = FALSE;
return error_code; return error_code;
} }
...@@ -176,6 +182,41 @@ int clustrix_connection::rollback_trans() ...@@ -176,6 +182,41 @@ int clustrix_connection::rollback_trans()
int error_code = mysql_real_query(&clustrix_net, stmt, strlen(stmt)); int error_code = mysql_real_query(&clustrix_net, stmt, strlen(stmt));
if (error_code) if (error_code)
return mysql_errno(&clustrix_net); return mysql_errno(&clustrix_net);
has_transaction = FALSE;
has_statement_trans = FALSE;
return error_code;
}
int clustrix_connection::begin_stmt_trans()
{
if (has_statement_trans)
return 0;
const char *stmt = "SAVEPOINT STMT_TRANS";
int error_code = mysql_real_query(&clustrix_net, stmt, strlen(stmt));
if (error_code)
return mysql_errno(&clustrix_net);
has_statement_trans = TRUE;
return error_code;
}
int clustrix_connection::commit_stmt_trans()
{
const char *stmt = "RELEASE SAVEPOINT STMT_TRANS";
int error_code = mysql_real_query(&clustrix_net, stmt, strlen(stmt));
if (error_code)
return mysql_errno(&clustrix_net);
has_statement_trans = FALSE;
return error_code;
}
int clustrix_connection::rollback_stmt_trans()
{
const char *stmt = "ROLLBACK TO STMT_TRANS";
int error_code = mysql_real_query(&clustrix_net, stmt, strlen(stmt));
if (error_code)
return mysql_errno(&clustrix_net);
has_statement_trans = FALSE;
return error_code; return error_code;
} }
...@@ -330,7 +371,7 @@ int clustrix_connection::scan_init(ulonglong clustrix_table_oid, uint index, ...@@ -330,7 +371,7 @@ int clustrix_connection::scan_init(ulonglong clustrix_table_oid, uint index,
* Sends a command over mysql protocol connection to initiate an * Sends a command over mysql protocol connection to initiate an
* arbitrary query using a query text. * arbitrary query using a query text.
* Uses field types, field metadata and nullability to explicitly * Uses field types, field metadata and nullability to explicitly
* cast result to expected data type. Exploits RBR TABLE_MAP_EVENT * cast result to expected data type. Exploits RBR TABLE_MAP_EVENT
* format + sends SQL text. * format + sends SQL text.
* @args * @args
* stmt& Query text to send * stmt& Query text to send
...@@ -356,7 +397,7 @@ int clustrix_connection::scan_query_init(String &stmt, uchar *fieldtype, ...@@ -356,7 +397,7 @@ int clustrix_connection::scan_query_init(String &stmt, uchar *fieldtype,
if ((error_code = add_command_operand_str(fieldtype, fields))) if ((error_code = add_command_operand_str(fieldtype, fields)))
return error_code; return error_code;
if ((error_code = add_command_operand_str(field_metadata, field_metadata_size))) if ((error_code = add_command_operand_str(field_metadata, field_metadata_size)))
return error_code; return error_code;
......
...@@ -36,12 +36,17 @@ class clustrix_connection ...@@ -36,12 +36,17 @@ class clustrix_connection
uchar *reply_buffer; uchar *reply_buffer;
size_t reply_length; size_t reply_length;
bool has_transaction;
bool has_statement_trans;
public: public:
ulonglong last_insert_id; ulonglong last_insert_id;
clustrix_connection() clustrix_connection()
: command_buffer(NULL), command_buffer_length(0), command_length(0) : command_buffer(NULL), command_buffer_length(0), command_length(0)
{ {
memset(&clustrix_net, 0, sizeof(MYSQL)); memset(&clustrix_net, 0, sizeof(MYSQL));
has_statement_trans = FALSE;
has_transaction = FALSE;
} }
~clustrix_connection() ~clustrix_connection()
...@@ -64,6 +69,18 @@ class clustrix_connection ...@@ -64,6 +69,18 @@ class clustrix_connection
int begin_trans(); int begin_trans();
int commit_trans(); int commit_trans();
int rollback_trans(); int rollback_trans();
inline bool has_trans()
{
return has_transaction;
}
int begin_stmt_trans();
int commit_stmt_trans();
int rollback_stmt_trans();
inline bool has_stmt_trans()
{
return has_statement_trans;
}
int create_table(String &stmt); int create_table(String &stmt);
int delete_table(String &stmt); int delete_table(String &stmt);
......
This diff is collapsed.
...@@ -21,27 +21,9 @@ Copyright (c) 2019, MariaDB Corporation. ...@@ -21,27 +21,9 @@ Copyright (c) 2019, MariaDB Corporation.
#include "../../sql/rpl_record.h" #include "../../sql/rpl_record.h"
size_t estimate_row_size(TABLE *table); size_t estimate_row_size(TABLE *table);
class st_clustrixdb_trx; clustrix_connection *get_trx(THD *thd, int *error_code);
st_clustrixdb_trx *get_trx(THD *thd, int *error_code);
bool get_enable_sh(THD* thd); bool get_enable_sh(THD* thd);
class ha_clustrixdb;
class st_clustrixdb_trx
{
public:
THD *thd;
clustrix_connection *clustrix_net;
//query_id_t query_id;
//MEM_ROOT mem_root; /* Memory allocated for the executing transaction */
bool has_transaction;
st_clustrixdb_trx(THD* trx_thd);
~st_clustrixdb_trx();
int net_init();
int begin_trans();
};
class ha_clustrixdb : public handler class ha_clustrixdb : public handler
{ {
private: private:
......
...@@ -99,7 +99,7 @@ create_clustrixdb_select_handler(THD* thd, SELECT_LEX* select_lex) ...@@ -99,7 +99,7 @@ create_clustrixdb_select_handler(THD* thd, SELECT_LEX* select_lex)
int error_code = 0; int error_code = 0;
int field_metadata_size = 0; int field_metadata_size = 0;
ulonglong scan_refid = 0; ulonglong scan_refid = 0;
st_clustrixdb_trx *trx = 0; clustrix_connection *trx = NULL;
// We presume this number is equal to types.elements in get_field_types // We presume this number is equal to types.elements in get_field_types
uint items_number = select_lex->get_item_list()->elements; uint items_number = select_lex->get_item_list()->elements;
...@@ -125,7 +125,7 @@ create_clustrixdb_select_handler(THD* thd, SELECT_LEX* select_lex) ...@@ -125,7 +125,7 @@ create_clustrixdb_select_handler(THD* thd, SELECT_LEX* select_lex)
if (!trx) if (!trx)
goto err; goto err;
if ((error_code = trx->clustrix_net->scan_query_init(query, fieldtype, items_number, if ((error_code = trx->scan_query_init(query, fieldtype, items_number,
null_bits, num_null_bytes, field_metadata, field_metadata_size, &scan_refid))) { null_bits, num_null_bytes, field_metadata, field_metadata_size, &scan_refid))) {
goto err; goto err;
} }
...@@ -169,12 +169,12 @@ ha_clustrixdb_select_handler::ha_clustrixdb_select_handler( ...@@ -169,12 +169,12 @@ ha_clustrixdb_select_handler::ha_clustrixdb_select_handler(
ha_clustrixdb_select_handler::~ha_clustrixdb_select_handler() ha_clustrixdb_select_handler::~ha_clustrixdb_select_handler()
{ {
int error_code; int error_code;
st_clustrixdb_trx *trx = get_trx(thd, &error_code); clustrix_connection *trx = get_trx(thd, &error_code);
if (!trx) { if (!trx) {
// TBD Log this // TBD Log this
} }
if (trx && scan_refid) if (trx && scan_refid)
trx->clustrix_net->scan_end(scan_refid); trx->scan_end(scan_refid);
// If the ::init_scan has been executed // If the ::init_scan has been executed
if (table__) if (table__)
...@@ -217,7 +217,7 @@ int ha_clustrixdb_select_handler::init_scan() ...@@ -217,7 +217,7 @@ int ha_clustrixdb_select_handler::init_scan()
int ha_clustrixdb_select_handler::next_row() int ha_clustrixdb_select_handler::next_row()
{ {
int error_code = 0; int error_code = 0;
st_clustrixdb_trx *trx = get_trx(thd, &error_code); clustrix_connection *trx = get_trx(thd, &error_code);
if (!trx) if (!trx)
return error_code; return error_code;
...@@ -225,8 +225,7 @@ int ha_clustrixdb_select_handler::next_row() ...@@ -225,8 +225,7 @@ int ha_clustrixdb_select_handler::next_row()
uchar *rowdata; uchar *rowdata;
ulong rowdata_length; ulong rowdata_length;
if ((error_code = trx->clustrix_net->scan_next(scan_refid, &rowdata, if ((error_code = trx->scan_next(scan_refid, &rowdata, &rowdata_length)))
&rowdata_length)))
return error_code; return error_code;
uchar const *current_row_end; uchar const *current_row_end;
...@@ -284,7 +283,7 @@ create_clustrixdb_derived_handler(THD* thd, TABLE_LIST *derived) ...@@ -284,7 +283,7 @@ create_clustrixdb_derived_handler(THD* thd, TABLE_LIST *derived)
int error_code = 0; int error_code = 0;
int field_metadata_size = 0; int field_metadata_size = 0;
ulonglong scan_refid = 0; ulonglong scan_refid = 0;
st_clustrixdb_trx *trx = 0; clustrix_connection *trx = NULL;
// We presume this number is equal to types.elements in get_field_types // We presume this number is equal to types.elements in get_field_types
uint items_number = select_lex->get_item_list()->elements; uint items_number = select_lex->get_item_list()->elements;
...@@ -310,7 +309,7 @@ create_clustrixdb_derived_handler(THD* thd, TABLE_LIST *derived) ...@@ -310,7 +309,7 @@ create_clustrixdb_derived_handler(THD* thd, TABLE_LIST *derived)
if (!trx) if (!trx)
goto err; goto err;
if ((error_code = trx->clustrix_net->scan_query_init(query, fieldtype, items_number, if ((error_code = trx->scan_query_init(query, fieldtype, items_number,
null_bits, num_null_bytes, field_metadata, field_metadata_size, &scan_refid))) { null_bits, num_null_bytes, field_metadata, field_metadata_size, &scan_refid))) {
goto err; goto err;
} }
...@@ -354,12 +353,12 @@ ha_clustrixdb_derived_handler::ha_clustrixdb_derived_handler( ...@@ -354,12 +353,12 @@ ha_clustrixdb_derived_handler::ha_clustrixdb_derived_handler(
ha_clustrixdb_derived_handler::~ha_clustrixdb_derived_handler() ha_clustrixdb_derived_handler::~ha_clustrixdb_derived_handler()
{ {
int error_code; int error_code;
st_clustrixdb_trx *trx = get_trx(thd, &error_code); clustrix_connection *trx = get_trx(thd, &error_code);
if (!trx) { if (!trx) {
// TBD Log this. // TBD Log this.
} }
if (trx && scan_refid) if (trx && scan_refid)
trx->clustrix_net->scan_end(scan_refid); trx->scan_end(scan_refid);
// If the ::init_scan has been executed // If the ::init_scan has been executed
if (table__) if (table__)
...@@ -402,7 +401,7 @@ int ha_clustrixdb_derived_handler::init_scan() ...@@ -402,7 +401,7 @@ int ha_clustrixdb_derived_handler::init_scan()
int ha_clustrixdb_derived_handler::next_row() int ha_clustrixdb_derived_handler::next_row()
{ {
int error_code = 0; int error_code = 0;
st_clustrixdb_trx *trx = get_trx(thd, &error_code); clustrix_connection *trx = get_trx(thd, &error_code);
if (!trx) if (!trx)
return error_code; return error_code;
...@@ -410,8 +409,7 @@ int ha_clustrixdb_derived_handler::next_row() ...@@ -410,8 +409,7 @@ int ha_clustrixdb_derived_handler::next_row()
uchar *rowdata; uchar *rowdata;
ulong rowdata_length; ulong rowdata_length;
if ((error_code = trx->clustrix_net->scan_next(scan_refid, &rowdata, if ((error_code = trx->scan_next(scan_refid, &rowdata, &rowdata_length)))
&rowdata_length)))
return error_code; return error_code;
uchar const *current_row_end; uchar const *current_row_end;
......
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