Skip to content
Permalink
Browse files

MDEV-19955 make argument of handler::ha_write_row() const

MDEV-19486 and one more similar bug appeared because handler::write_row() interface
welcomes to modify buffer by storage engine. But callers are not ready for that
thus bugs are possible in future.

handler::write_row():
handler::ha_write_row(): make argument const
  • Loading branch information...
kevgs committed Jul 4, 2019
1 parent 23c12ed commit c9aa495fb67ab4fd5c9790d4f61b7e988423619f
Showing with 86 additions and 85 deletions.
  1. +1 −1 include/maria.h
  2. +1 −1 include/myisam.h
  3. +1 −1 include/myisammrg.h
  4. +1 −1 sql/field.h
  5. +1 −1 sql/ha_partition.cc
  6. +1 −1 sql/ha_partition.h
  7. +1 −1 sql/ha_sequence.cc
  8. +1 −1 sql/ha_sequence.h
  9. +5 −4 sql/handler.cc
  10. +3 −3 sql/handler.h
  11. +4 −4 storage/archive/ha_archive.cc
  12. +4 −4 storage/archive/ha_archive.h
  13. +1 −1 storage/blackhole/ha_blackhole.cc
  14. +1 −1 storage/blackhole/ha_blackhole.h
  15. +1 −1 storage/cassandra/ha_cassandra.cc
  16. +1 −1 storage/cassandra/ha_cassandra.h
  17. +1 −1 storage/connect/ha_connect.cc
  18. +1 −1 storage/connect/ha_connect.h
  19. +1 −1 storage/csv/ha_tina.cc
  20. +1 −1 storage/csv/ha_tina.h
  21. +1 −1 storage/example/ha_example.cc
  22. +1 −1 storage/example/ha_example.h
  23. +1 −1 storage/federated/ha_federated.cc
  24. +1 −1 storage/federated/ha_federated.h
  25. +1 −1 storage/federatedx/ha_federatedx.cc
  26. +1 −1 storage/federatedx/ha_federatedx.h
  27. +1 −1 storage/heap/ha_heap.cc
  28. +1 −1 storage/heap/ha_heap.h
  29. +1 −1 storage/innobase/handler/ha_innodb.cc
  30. +1 −1 storage/innobase/handler/ha_innodb.h
  31. +1 −1 storage/maria/ha_maria.cc
  32. +1 −1 storage/maria/ha_maria.h
  33. +1 −1 storage/maria/ma_write.c
  34. +7 −7 storage/mroonga/ha_mroonga.cpp
  35. +7 −7 storage/mroonga/ha_mroonga.hpp
  36. +1 −1 storage/myisam/ha_myisam.cc
  37. +1 −1 storage/myisam/ha_myisam.h
  38. +1 −1 storage/myisam/mi_write.c
  39. +1 −1 storage/myisammrg/ha_myisammrg.cc
  40. +1 −1 storage/myisammrg/ha_myisammrg.h
  41. +1 −1 storage/myisammrg/myrg_write.c
  42. +1 −1 storage/oqgraph/ha_oqgraph.cc
  43. +1 −1 storage/oqgraph/ha_oqgraph.h
  44. +1 −1 storage/perfschema/ha_perfschema.cc
  45. +1 −1 storage/perfschema/ha_perfschema.h
  46. +1 −1 storage/perfschema/pfs_engine_table.cc
  47. +2 −2 storage/perfschema/pfs_engine_table.h
  48. +1 −1 storage/perfschema/table_setup_actors.cc
  49. +1 −1 storage/perfschema/table_setup_actors.h
  50. +1 −1 storage/perfschema/table_setup_objects.cc
  51. +1 −1 storage/perfschema/table_setup_objects.h
  52. +1 −1 storage/rocksdb/ha_rocksdb.cc
  53. +1 −1 storage/rocksdb/ha_rocksdb.h
  54. +1 −1 storage/spider/ha_spider.cc
  55. +1 −1 storage/spider/ha_spider.h
  56. +3 −3 storage/tokudb/ha_tokudb.cc
  57. +3 −3 storage/tokudb/ha_tokudb.h
@@ -305,7 +305,7 @@ extern int maria_rsame_with_pos(MARIA_HA *file, uchar *record,
int inx, MARIA_RECORD_POS pos);
extern int maria_update(MARIA_HA *file, const uchar *old,
const uchar *new_record);
extern int maria_write(MARIA_HA *file, uchar *buff);
extern int maria_write(MARIA_HA *file, const uchar *buff);
extern MARIA_RECORD_POS maria_position(MARIA_HA *file);
extern int maria_status(MARIA_HA *info, MARIA_INFO *x, uint flag);
extern int maria_lock_database(MARIA_HA *file, int lock_type);
@@ -276,7 +276,7 @@ extern int mi_rsame_with_pos(struct st_myisam_info *file,uchar *record,
int inx, my_off_t pos);
extern int mi_update(struct st_myisam_info *file,const uchar *old,
const uchar *new_record);
extern int mi_write(struct st_myisam_info *file,uchar *buff);
extern int mi_write(struct st_myisam_info *file,const uchar *buff);
extern my_off_t mi_position(struct st_myisam_info *file);
extern int mi_status(struct st_myisam_info *info, MI_ISAMINFO *x, uint flag);
extern int mi_lock_database(struct st_myisam_info *file,int lock_type);
@@ -106,7 +106,7 @@ extern int myrg_rrnd(MYRG_INFO *file,uchar *buf,ulonglong pos);
extern int myrg_rsame(MYRG_INFO *file,uchar *record,int inx);
extern int myrg_update(MYRG_INFO *file,const uchar *old,
const uchar *new_rec);
extern int myrg_write(MYRG_INFO *info,uchar *rec);
extern int myrg_write(MYRG_INFO *info,const uchar *rec);
extern int myrg_status(MYRG_INFO *file,MYMERGE_INFO *x,int flag);
extern int myrg_lock_database(MYRG_INFO *file,int lock_type);
extern int myrg_create(const char *name, const char **table_names,
@@ -1364,7 +1364,7 @@ class Field: public Value_source
virtual uint max_packed_col_length(uint max_length)
{ return max_length;}

uint offset(uchar *record) const
uint offset(const uchar *record) const
{
return (uint) (ptr - record);
}
@@ -4247,7 +4247,7 @@ void ha_partition::try_semi_consistent_read(bool yes)
determining which partition the row should be written to.
*/

int ha_partition::write_row(uchar * buf)
int ha_partition::write_row(const uchar * buf)
{
uint32 part_id;
int error;
@@ -628,7 +628,7 @@ class ha_partition :public handler
start_bulk_insert and end_bulk_insert is called before and after a
number of calls to write_row.
*/
virtual int write_row(uchar * buf);
virtual int write_row(const uchar * buf);
virtual bool start_bulk_update();
virtual int exec_bulk_update(ha_rows *dup_key_found);
virtual int end_bulk_update();
@@ -194,7 +194,7 @@ int ha_sequence::create(const char *name, TABLE *form,
the sequence with 'buf' as the sequence object is already up to date.
*/

int ha_sequence::write_row(uchar *buf)
int ha_sequence::write_row(const uchar *buf)
{
int error;
sequence_definition tmp_seq;
@@ -71,7 +71,7 @@ class ha_sequence :public handler
int create(const char *name, TABLE *form,
HA_CREATE_INFO *create_info);
handler *clone(const char *name, MEM_ROOT *mem_root);
int write_row(uchar *buf);
int write_row(const uchar *buf);
Table_flags table_flags() const;
/* One can't update or delete from sequence engine */
int update_row(const uchar *old_data, const uchar *new_data)
@@ -6499,7 +6499,7 @@ static int wsrep_after_row(THD *thd)
#endif /* WITH_WSREP */

static int check_duplicate_long_entry_key(TABLE *table, handler *h,
uchar *new_rec, uint key_no)
const uchar *new_rec, uint key_no)
{
Field *hash_field;
int result, error= 0;
@@ -6588,7 +6588,8 @@ static int check_duplicate_long_entry_key(TABLE *table, handler *h,
unique constraint on long columns.
@returns 0 if no duplicate else returns error
*/
static int check_duplicate_long_entries(TABLE *table, handler *h, uchar *new_rec)
static int check_duplicate_long_entries(TABLE *table, handler *h,
const uchar *new_rec)
{
table->file->errkey= -1;
int result;
@@ -6657,7 +6658,7 @@ static int check_duplicate_long_entries_update(TABLE *table, handler *h, uchar *
return error;
}

int handler::ha_write_row(uchar *buf)
int handler::ha_write_row(const uchar *buf)
{
int error;
Log_func *log_func= Write_rows_log_event::binlog_row_logging_function;
@@ -6746,7 +6747,7 @@ int handler::ha_update_row(const uchar *old_data, const uchar *new_data)
Update first row. Only used by sequence tables
*/

int handler::update_first_row(uchar *new_data)
int handler::update_first_row(const uchar *new_data)
{
int error;
if (likely(!(error= ha_rnd_init(1))))
@@ -3238,7 +3238,7 @@ class handler :public Sql_alloc
and delete_row() below.
*/
int ha_external_lock(THD *thd, int lock_type);
int ha_write_row(uchar * buf);
int ha_write_row(const uchar * buf);
int ha_update_row(const uchar * old_data, const uchar * new_data);
int ha_delete_row(const uchar * buf);
void ha_release_auto_increment();
@@ -4548,7 +4548,7 @@ class handler :public Sql_alloc
*/
virtual int rnd_init(bool scan)= 0;
virtual int rnd_end() { return 0; }
virtual int write_row(uchar *buf __attribute__((unused)))
virtual int write_row(const uchar *buf __attribute__((unused)))
{
return HA_ERR_WRONG_COMMAND;
}
@@ -4571,7 +4571,7 @@ class handler :public Sql_alloc
Optimized function for updating the first row. Only used by sequence
tables
*/
virtual int update_first_row(uchar *new_data);
virtual int update_first_row(const uchar *new_data);

virtual int delete_row(const uchar *buf __attribute__((unused)))
{
@@ -371,7 +371,7 @@ int Archive_share::write_v1_metafile()
@return Length of packed row
*/

unsigned int ha_archive::pack_row_v1(uchar *record)
unsigned int ha_archive::pack_row_v1(const uchar *record)
{
uint *blob, *end;
uchar *pos;
@@ -868,7 +868,7 @@ int ha_archive::create(const char *name, TABLE *table_arg,
/*
This is where the actual row is written out.
*/
int ha_archive::real_write_row(uchar *buf, azio_stream *writer)
int ha_archive::real_write_row(const uchar *buf, azio_stream *writer)
{
my_off_t written;
unsigned int r_pack_length;
@@ -917,7 +917,7 @@ uint32 ha_archive::max_row_length(const uchar *record)
}


unsigned int ha_archive::pack_row(uchar *record, azio_stream *writer)
unsigned int ha_archive::pack_row(const uchar *record, azio_stream *writer)
{
uchar *ptr;
my_ptrdiff_t const rec_offset= record - table->record[0];
@@ -959,7 +959,7 @@ unsigned int ha_archive::pack_row(uchar *record, azio_stream *writer)
for implementing start_bulk_insert() is that we could skip
setting dirty to true each time.
*/
int ha_archive::write_row(uchar *buf)
int ha_archive::write_row(const uchar *buf)
{
int rc;
uchar *read_buf= NULL;
@@ -95,7 +95,7 @@ class ha_archive: public handler
void destroy_record_buffer(archive_record_buffer *r);
int frm_copy(azio_stream *src, azio_stream *dst);
int frm_compare(azio_stream *src);
unsigned int pack_row_v1(uchar *record);
unsigned int pack_row_v1(const uchar *record);

public:
ha_archive(handlerton *hton, TABLE_SHARE *table_arg);
@@ -131,8 +131,8 @@ class ha_archive: public handler
int index_next(uchar * buf);
int open(const char *name, int mode, uint test_if_locked);
int close(void);
int write_row(uchar * buf);
int real_write_row(uchar *buf, azio_stream *writer);
int write_row(const uchar * buf);
int real_write_row(const uchar *buf, azio_stream *writer);
int truncate();
int rnd_init(bool scan=1);
int rnd_next(uchar *buf);
@@ -168,7 +168,7 @@ class ha_archive: public handler
uint32 max_row_length(const uchar *buf);
bool fix_rec_buff(unsigned int length);
int unpack_row(azio_stream *file_to_read, uchar *record);
unsigned int pack_row(uchar *record, azio_stream *writer);
unsigned int pack_row(const uchar *record, azio_stream *writer);
bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes);
int external_lock(THD *thd, int lock_type);
private:
@@ -117,7 +117,7 @@ const char *ha_blackhole::index_type(uint key_number)
HA_KEY_ALG_RTREE) ? "RTREE" : "BTREE");
}

int ha_blackhole::write_row(uchar * buf)
int ha_blackhole::write_row(const uchar * buf)
{
DBUG_ENTER("ha_blackhole::write_row");
DBUG_RETURN(table->next_number_field ? update_auto_increment() : 0);
@@ -96,7 +96,7 @@ class ha_blackhole: public handler
THR_LOCK_DATA **to,
enum thr_lock_type lock_type);
private:
virtual int write_row(uchar *buf);
virtual int write_row(const uchar *buf);
virtual int update_row(const uchar *old_data, const uchar *new_data);
virtual int delete_row(const uchar *buf);
};
@@ -1931,7 +1931,7 @@ void ha_cassandra::free_dynamic_row(DYNAMIC_COLUMN_VALUE **vals,
*names= 0;
}

int ha_cassandra::write_row(uchar *buf)
int ha_cassandra::write_row(const uchar *buf)
{
my_bitmap_map *old_map;
int ires;
@@ -239,7 +239,7 @@ class ha_cassandra: public handler
int open(const char *name, int mode, uint test_if_locked);
int close(void);

int write_row(uchar *buf);
int write_row(const uchar *buf);
int update_row(const uchar *old_data, const uchar *new_data);
int delete_row(const uchar *buf);

@@ -3576,7 +3576,7 @@ int ha_connect::close(void)
item_sum.cc, item_sum.cc, sql_acl.cc, sql_insert.cc,
sql_insert.cc, sql_select.cc, sql_table.cc, sql_udf.cc and sql_update.cc
*/
int ha_connect::write_row(uchar *buf)
int ha_connect::write_row(const uchar *buf)
{
int rc= 0;
PGLOBAL& g= xp->g;
@@ -388,7 +388,7 @@ virtual int check(THD* thd, HA_CHECK_OPT* check_opt);
We implement this in ha_connect.cc. It's not an obligatory method;
skip it and and MySQL will treat it as not implemented.
*/
int write_row(uchar *buf);
int write_row(const uchar *buf);

/** @brief
We implement this in ha_connect.cc. It's not an obligatory method;
@@ -1004,7 +1004,7 @@ int ha_tina::close(void)
of the file and appends the data. In an error case it really should
just truncate to the original position (this is not done yet).
*/
int ha_tina::write_row(uchar * buf)
int ha_tina::write_row(const uchar * buf)
{
int size;
DBUG_ENTER("ha_tina::write_row");
@@ -136,7 +136,7 @@ class ha_tina: public handler

int open(const char *name, int mode, uint open_options);
int close(void);
int write_row(uchar * buf);
int write_row(const uchar * buf);
int update_row(const uchar * old_data, const uchar * new_data);
int delete_row(const uchar * buf);
int rnd_init(bool scan=1);
@@ -398,7 +398,7 @@ int ha_example::close(void)
sql_insert.cc, sql_select.cc, sql_table.cc, sql_udf.cc and sql_update.cc
*/

int ha_example::write_row(uchar *buf)
int ha_example::write_row(const uchar *buf)
{
DBUG_ENTER("ha_example::write_row");
/*
@@ -180,7 +180,7 @@ class ha_example: public handler
We implement this in ha_example.cc. It's not an obligatory method;
skip it and and MySQL will treat it as not implemented.
*/
int write_row(uchar *buf);
int write_row(const uchar *buf);

/** @brief
We implement this in ha_example.cc. It's not an obligatory method;
@@ -1825,7 +1825,7 @@ bool ha_federated::append_stmt_insert(String *query)
sql_insert.cc, sql_select.cc, sql_table.cc, sql_udf.cc, and sql_update.cc.
*/

int ha_federated::write_row(uchar *buf)
int ha_federated::write_row(const uchar *buf)
{
char values_buffer[FEDERATED_QUERY_BUFFER_SIZE];
char insert_field_value_buffer[STRING_BUFFER_USUAL_SIZE];
@@ -209,7 +209,7 @@ class ha_federated: public handler

void start_bulk_insert(ha_rows rows, uint flags);
int end_bulk_insert();
int write_row(uchar *buf);
int write_row(const uchar *buf);
int update_row(const uchar *old_data, const uchar *new_data);
int delete_row(const uchar *buf);
int index_init(uint keynr, bool sorted);
@@ -1987,7 +1987,7 @@ bool ha_federatedx::append_stmt_insert(String *query)
sql_insert.cc, sql_select.cc, sql_table.cc, sql_udf.cc, and sql_update.cc.
*/

int ha_federatedx::write_row(uchar *buf)
int ha_federatedx::write_row(const uchar *buf)
{
char values_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
char insert_field_value_buffer[STRING_BUFFER_USUAL_SIZE];
@@ -397,7 +397,7 @@ class ha_federatedx: public handler

void start_bulk_insert(ha_rows rows, uint flags);
int end_bulk_insert();
int write_row(uchar *buf);
int write_row(const uchar *buf);
int update_row(const uchar *old_data, const uchar *new_data);
int delete_row(const uchar *buf);
int index_init(uint keynr, bool sorted);
@@ -228,7 +228,7 @@ void ha_heap::update_key_stats()
}


int ha_heap::write_row(uchar * buf)
int ha_heap::write_row(const uchar * buf)
{
int res;
if (table->next_number_field && buf == table->record[0])
@@ -70,7 +70,7 @@ class ha_heap: public handler
int open(const char *name, int mode, uint test_if_locked);
int close(void);
void set_keys_for_scanning(void);
int write_row(uchar * buf);
int write_row(const uchar * buf);
int update_row(const uchar * old_data, const uchar * new_data);
int delete_row(const uchar * buf);
virtual void get_auto_increment(ulonglong offset, ulonglong increment,
@@ -7997,7 +7997,7 @@ handle.
int
ha_innobase::write_row(
/*===================*/
uchar* record) /*!< in: a row in MySQL format */
const uchar* record) /*!< in: a row in MySQL format */
{
dberr_t error;
#ifdef WITH_WSREP
@@ -112,7 +112,7 @@ class ha_innobase final: public handler

int delete_all_rows() override;

int write_row(uchar * buf) override;
int write_row(const uchar * buf) override;

int update_row(const uchar * old_data, const uchar * new_data) override;

@@ -1227,7 +1227,7 @@ int ha_maria::close(void)
}


int ha_maria::write_row(uchar * buf)
int ha_maria::write_row(const uchar * buf)
{
/*
If we have an auto_increment column and we are writing a changed row
@@ -73,7 +73,7 @@ class ha_maria :public handler

int open(const char *name, int mode, uint test_if_locked);
int close(void);
int write_row(uchar * buf);
int write_row(const uchar * buf);
int update_row(const uchar * old_data, const uchar * new_data);
int delete_row(const uchar * buf);
int index_read_map(uchar * buf, const uchar * key, key_part_map keypart_map,
@@ -83,7 +83,7 @@ my_bool _ma_write_abort_default(MARIA_HA *info __attribute__((unused)))

/* Write new record to a table */

int maria_write(MARIA_HA *info, uchar *record)
int maria_write(MARIA_HA *info, const uchar *record)
{
MARIA_SHARE *share= info->s;
uint i;

0 comments on commit c9aa495

Please sign in to comment.
You can’t perform that action at this time.