Commit 99831d70 authored by Will DeVries's avatar Will DeVries Committed by Sergei Petrunia

Add row_update support.

parent 6c8cd22f
......@@ -28,7 +28,8 @@ enum clustrix_commands {
CLUSTRIX_SCAN_STOP,
CLUSTRIX_KEY_READ,
CLUSTRIX_KEY_DELETE,
CLUSTRIX_SCAN_QUERY
CLUSTRIX_SCAN_QUERY,
CLUSTRIX_KEY_UPDATE
};
/****************************************************************************
......@@ -256,6 +257,41 @@ int clustrix_connection::write_row(ulonglong clustrix_table_oid,
return error_code;
}
int clustrix_connection::key_update(ulonglong clustrix_table_oid,
uchar *packed_key, size_t packed_key_length,
MY_BITMAP *update_set,
uchar *packed_new_data,
size_t packed_new_length)
{
int error_code;
command_length = 0;
if ((error_code = add_command_operand_uchar(CLUSTRIX_KEY_UPDATE)))
return error_code;
if ((error_code = add_command_operand_ulonglong(clustrix_table_oid)))
return error_code;
if ((error_code = add_command_operand_str(packed_key, packed_key_length)))
return error_code;
if ((error_code = add_command_operand_bitmap(update_set)))
return error_code;
if ((error_code = add_command_operand_str(packed_new_data,
packed_new_length)))
return error_code;
if ((error_code = send_command()))
return error_code;
if ((error_code = read_query_response()))
return mysql_errno(&clustrix_net);
return error_code;
}
int clustrix_connection::key_delete(ulonglong clustrix_table_oid,
uchar *packed_key, size_t packed_key_length)
{
......
......@@ -86,6 +86,10 @@ class clustrix_connection
int write_row(ulonglong clustrix_table_oid,
uchar *packed_row, size_t packed_size);
int key_update(ulonglong clustrix_table_oid,
uchar *packed_key, size_t packed_key_length,
MY_BITMAP *update_set,
uchar *packed_new_data, size_t packed_new_length);
int key_delete(ulonglong clustrix_table_oid,
uchar *packed_key, size_t packed_key_length);
int key_read(ulonglong clustrix_table_oid, uint index, MY_BITMAP *read_set,
......
......@@ -373,30 +373,37 @@ int ha_clustrixdb::write_row(uchar *buf)
int ha_clustrixdb::update_row(const uchar *old_data, const uchar *new_data)
{
DBUG_ENTER("ha_clustrixdb::update_row");
int error_code;
THD *thd = ha_thd();
clustrix_connection *trx = get_trx(thd, &error_code);
if (!trx)
return error_code;
DBUG_RETURN(error_code);
assert(trx->has_stmt_trans());
size_t row_size = estimate_row_size(table);
size_t packed_key_len;
uchar *packed_key = (uchar*) my_alloca(row_size);
build_key_packed_row(table->s->primary_key, old_data,
packed_key, &packed_key_len);
uchar *packed_new_row = (uchar*) my_alloca(row_size);
// Add checks for actual size of the packed data
/*size_t packed_new_size =*/ pack_row(table, table->write_set, packed_new_row, new_data);
uchar *packed_old_row = (uchar*) my_alloca(row_size);
/*size_t packed_old_size =*/ pack_row(table, table->write_set, packed_old_row, old_data);
size_t packed_new_size = pack_row(table, table->write_set, packed_new_row,
new_data);
/* Send the packed rows to Clustrix */
error_code = trx->key_update(clustrix_table_oid, packed_key, packed_key_len,
table->write_set,
packed_new_row, packed_new_size);
if(packed_key)
my_afree(packed_key);
if(packed_new_row)
my_afree(packed_new_row);
if(packed_old_row)
my_afree(packed_old_row);
return error_code;
DBUG_RETURN(error_code);
}
int ha_clustrixdb::delete_row(const uchar *buf)
......@@ -412,7 +419,8 @@ int ha_clustrixdb::delete_row(const uchar *buf)
// The estimate should consider only key fields widths.
size_t packed_key_len;
uchar *packed_key = (uchar*) my_alloca(estimate_row_size(table));
build_key_packed_row(table->s->primary_key, packed_key, &packed_key_len);
build_key_packed_row(table->s->primary_key, table->record[0],
packed_key, &packed_key_len);
if ((error_code = trx->key_delete(clustrix_table_oid,
packed_key, packed_key_len)))
......@@ -539,7 +547,8 @@ int ha_clustrixdb::index_read(uchar * buf, const uchar * key, uint key_len,
// The estimate should consider only key fields widths.
size_t packed_key_len;
uchar *packed_key = (uchar*) my_alloca(estimate_row_size(table));
build_key_packed_row(active_index, packed_key, &packed_key_len);
build_key_packed_row(active_index, table->record[0],
packed_key, &packed_key_len);
uchar *rowdata;
ulong rowdata_length;
......@@ -753,7 +762,8 @@ int ha_clustrixdb::rnd_pos(uchar * buf, uchar *pos)
// The estimate should consider only key fields widths.
uchar *packed_key = (uchar*) my_alloca(estimate_row_size(table));
size_t packed_key_len;
build_key_packed_row(table->s->primary_key, packed_key, &packed_key_len);
build_key_packed_row(table->s->primary_key, table->record[0],
packed_key, &packed_key_len);
uchar *rowdata;
ulong rowdata_length;
......@@ -908,7 +918,8 @@ void ha_clustrixdb::remove_current_table_from_rpl_table_list()
delete rgi;
}
void ha_clustrixdb::build_key_packed_row(uint index, uchar *packed_key,
void ha_clustrixdb::build_key_packed_row(uint index, const uchar *buf,
uchar *packed_key,
size_t *packed_key_len)
{
if (index == table->s->primary_key && has_hidden_key) {
......@@ -918,7 +929,7 @@ void ha_clustrixdb::build_key_packed_row(uint index, uchar *packed_key,
// make a row from the table
table->mark_columns_used_by_index(index, &table->tmp_set);
*packed_key_len = pack_row(table, &table->tmp_set, packed_key,
table->record[0]);
buf);
}
}
......
......@@ -103,8 +103,8 @@ class ha_clustrixdb : public handler
private:
void add_current_table_to_rpl_table_list();
void remove_current_table_from_rpl_table_list();
void build_key_packed_row(uint index, uchar *packed_key,
size_t *packed_key_len);
void build_key_packed_row(uint index, const uchar *buf,
uchar *packed_key, size_t *packed_key_len);
};
bool select_handler_setting(THD* thd);
......
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