Skip to content

Commit f62fdca

Browse files
committed
Bug#28865321: MAKE THD METHODS CONST WHEN POSSIBLE
Mark a number of THD methods as const so that it is obvious that they do not modify THD state and to allow more usage of const THD pointers. Change-Id: If6d8881ae86e2131a2e3fa0d449f55532dc2f958
1 parent 1e887b7 commit f62fdca

16 files changed

+75
-73
lines changed

Diff for: include/violite.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ bool vio_was_timeout(MYSQL_VIO vio);
169169
#define VIO_DESCRIPTION_SIZE 30 /* size of description */
170170
void vio_description(MYSQL_VIO vio, char *buf);
171171
/* Return the type of the connection */
172-
enum enum_vio_type vio_type(MYSQL_VIO vio);
172+
enum enum_vio_type vio_type(const MYSQL_VIO vio);
173173
/* Return last error number */
174174
int vio_errno(MYSQL_VIO vio);
175175
/* Get socket number */

Diff for: sql/binlog.cc

+9-8
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ static xa_status_code binlog_xa_rollback(handlerton *hton, XID *xid);
177177
static void exec_binlog_error_action_abort(const char *err_string);
178178
static int binlog_recover(Binlog_file_reader *binlog_file_reader,
179179
my_off_t *valid_pos);
180+
static bool binlog_row_event_extra_data_eq(const uchar *a, const uchar *b);
181+
static void binlog_prepare_row_images(const THD *thd, TABLE *table);
180182

181183
static inline bool has_commit_order_manager(THD *thd) {
182184
return is_mts_worker(thd) &&
@@ -3043,7 +3045,7 @@ bool purge_master_logs_before_date(THD *thd, time_t purge_time) {
30433045
/*
30443046
Helper function to get the error code of the query to be binlogged.
30453047
*/
3046-
int query_error_code(THD *thd, bool not_killed) {
3048+
int query_error_code(const THD *thd, bool not_killed) {
30473049
int error;
30483050

30493051
if (not_killed) {
@@ -5137,7 +5139,7 @@ int MYSQL_BIN_LOG::raw_get_current_log(LOG_INFO *linfo) {
51375139
return 0;
51385140
}
51395141

5140-
bool MYSQL_BIN_LOG::check_write_error(THD *thd) {
5142+
bool MYSQL_BIN_LOG::check_write_error(const THD *thd) {
51415143
DBUG_ENTER("MYSQL_BIN_LOG::check_write_error");
51425144

51435145
bool checked = false;
@@ -8933,7 +8935,7 @@ inline void MYSQL_BIN_LOG::update_binlog_end_pos(const char *file,
89338935
unlock_binlog_end_pos();
89348936
}
89358937

8936-
bool THD::is_binlog_cache_empty(bool is_transactional) {
8938+
bool THD::is_binlog_cache_empty(bool is_transactional) const {
89378939
DBUG_ENTER("THD::is_binlog_cache_empty(bool)");
89388940

89398941
// If opt_bin_log==0, it is not safe to call thd_get_cache_mngr
@@ -10651,7 +10653,7 @@ int THD::binlog_update_row(TABLE *table, bool is_trans,
1065110653
not needed for binlogging. This is done according to the:
1065210654
binlog-row-image option.
1065310655
*/
10654-
binlog_prepare_row_images(table);
10656+
binlog_prepare_row_images(this, table);
1065510657

1065610658
Row_data_memory row_data(table, before_record, after_record,
1065710659
variables.binlog_row_value_options);
@@ -10706,7 +10708,7 @@ int THD::binlog_delete_row(TABLE *table, bool is_trans, uchar const *record,
1070610708
not needed for binlogging. This is done according to the:
1070710709
binlog-row-image option.
1070810710
*/
10709-
binlog_prepare_row_images(table);
10711+
binlog_prepare_row_images(this, table);
1071010712

1071110713
/*
1071210714
Pack records into format for transfer. We are allocating more
@@ -10737,7 +10739,7 @@ int THD::binlog_delete_row(TABLE *table, bool is_trans, uchar const *record,
1073710739
return error;
1073810740
}
1073910741

10740-
void THD::binlog_prepare_row_images(TABLE *table) {
10742+
void binlog_prepare_row_images(const THD *thd, TABLE *table) {
1074110743
DBUG_ENTER("THD::binlog_prepare_row_images");
1074210744
/**
1074310745
Remove from read_set spurious columns. The write_set has been
@@ -10746,7 +10748,6 @@ void THD::binlog_prepare_row_images(TABLE *table) {
1074610748

1074710749
DBUG_PRINT_BITSET("debug", "table->read_set (before preparing): %s",
1074810750
table->read_set);
10749-
THD *thd = table->in_use;
1075010751

1075110752
/**
1075210753
if there is a primary key in the table (ie, user declared PK or a
@@ -10844,7 +10845,7 @@ int THD::binlog_flush_pending_rows_event(bool stmt_end, bool is_transactional) {
1084410845
@return
1084510846
true if the referenced structures are equal
1084610847
*/
10847-
bool THD::binlog_row_event_extra_data_eq(const uchar *a, const uchar *b) {
10848+
static bool binlog_row_event_extra_data_eq(const uchar *a, const uchar *b) {
1084810849
return ((a == b) ||
1084910850
((a != NULL) && (b != NULL) &&
1085010851
(a[EXTRA_ROW_INFO_LEN_OFFSET] == b[EXTRA_ROW_INFO_LEN_OFFSET]) &&

Diff for: sql/binlog.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ class MYSQL_BIN_LOG : public TC_LOG {
755755
bool write_dml_directly(THD *thd, const char *stmt, size_t stmt_len);
756756

757757
void report_cache_write_error(THD *thd, bool is_transactional);
758-
bool check_write_error(THD *thd);
758+
bool check_write_error(const THD *thd);
759759
bool write_incident(THD *thd, bool need_lock_log, const char *err_msg,
760760
bool do_flush_and_sync = true);
761761
bool write_incident(Incident_log_event *ev, THD *thd, bool need_lock_log,
@@ -930,7 +930,7 @@ void check_binlog_cache_size(THD *thd);
930930
void check_binlog_stmt_cache_size(THD *thd);
931931
bool binlog_enabled();
932932
void register_binlog_handler(THD *thd, bool trx);
933-
int query_error_code(THD *thd, bool not_killed);
933+
int query_error_code(const THD *thd, bool not_killed);
934934

935935
extern const char *log_bin_index;
936936
extern const char *log_bin_basename;

Diff for: sql/mdl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class MDL_context_owner {
164164
Get random seed specific to this THD to be used for initialization
165165
of PRNG for the MDL_context.
166166
*/
167-
virtual uint get_rand_seed() = 0;
167+
virtual uint get_rand_seed() const = 0;
168168
};
169169

170170
/**

Diff for: sql/mdl_context_backup.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class MDL_context_backup_manager::MDL_context_backup
7878

7979
void notify_hton_post_release_exclusive(const MDL_key *) override { return; }
8080

81-
uint get_rand_seed() override { return (uint)1; }
81+
uint get_rand_seed() const override { return 1; }
8282

8383
bool is_connected() override { return true; }
8484
// End implementation of MDL_context_owner interface.

Diff for: sql/protocol.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ class Protocol {
122122
*/
123123
enum { SEND_NUM_ROWS = 1, SEND_DEFAULTS = 2, SEND_EOF = 4 };
124124

125-
virtual enum enum_protocol_type type() = 0;
125+
virtual enum enum_protocol_type type() const = 0;
126126

127-
virtual enum enum_vio_type connection_type() = 0;
127+
virtual enum enum_vio_type connection_type() const = 0;
128128

129129
/* Data sending functions */
130130
virtual bool store_null() = 0;
@@ -194,7 +194,7 @@ class Protocol {
194194
true if the connection is still alive
195195
false otherwise
196196
*/
197-
virtual bool connection_alive() = 0;
197+
virtual bool connection_alive() const = 0;
198198

199199
/**
200200
Result set sending functions

Diff for: sql/protocol_callback.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int Protocol_callback::get_command(COM_DATA *, enum_server_command *) {
7878
@return
7979
VIO_TYPE_PLUGIN
8080
*/
81-
enum enum_vio_type Protocol_callback::connection_type() {
81+
enum enum_vio_type Protocol_callback::connection_type() const {
8282
return VIO_TYPE_PLUGIN;
8383
}
8484

@@ -266,7 +266,7 @@ int Protocol_callback::shutdown(bool server_shutdown) {
266266
@return
267267
true alive
268268
*/
269-
bool Protocol_callback::connection_alive() { return true; }
269+
bool Protocol_callback::connection_alive() const { return true; }
270270

271271
/**
272272
Should return protocol's reading/writing status. Returns 0 (idle) as it this

Diff for: sql/protocol_callback.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ class Protocol_callback : public Protocol {
8585
false success
8686
true failure
8787
*/
88-
virtual enum enum_protocol_type type() { return PROTOCOL_PLUGIN; }
88+
virtual enum enum_protocol_type type() const { return PROTOCOL_PLUGIN; }
8989

9090
/**
9191
Returns the type of the connection
9292
9393
@return
9494
enum enum_vio_type
9595
*/
96-
virtual enum enum_vio_type connection_type();
96+
virtual enum enum_vio_type connection_type() const;
9797

9898
/**
9999
Sends null value
@@ -300,7 +300,7 @@ class Protocol_callback : public Protocol {
300300
@return
301301
true alive
302302
*/
303-
virtual bool connection_alive();
303+
virtual bool connection_alive() const;
304304

305305
/**
306306
Should return protocol's reading/writing status. Returns 0 (idle) as it

Diff for: sql/protocol_classic.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,8 @@ NET *Protocol_classic::get_net() { return &m_thd->net; }
13561356

13571357
Vio *Protocol_classic::get_vio() { return m_thd->net.vio; }
13581358

1359+
const Vio *Protocol_classic::get_vio() const { return m_thd->net.vio; }
1360+
13591361
void Protocol_classic::set_vio(Vio *vio) { m_thd->net.vio = vio; }
13601362

13611363
void Protocol_classic::set_output_pkt_nr(uint pkt_nr) {
@@ -3156,7 +3158,9 @@ bool store(Protocol *prot, I_List<i_string> *str_list) {
31563158
All data are sent as 'packed-string-length' followed by 'string-data'
31573159
****************************************************************************/
31583160

3159-
bool Protocol_classic::connection_alive() { return m_thd->net.vio != NULL; }
3161+
bool Protocol_classic::connection_alive() const {
3162+
return m_thd->net.vio != nullptr;
3163+
}
31603164

31613165
void Protocol_text::start_row() {
31623166
#ifndef DBUG_OFF

Diff for: sql/protocol_classic.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,16 @@ class Protocol_classic : public Protocol {
130130
virtual bool send_field_metadata(Send_field *field,
131131
const CHARSET_INFO *item_charset);
132132
virtual void abort_row() {}
133-
virtual enum enum_protocol_type type() = 0;
133+
virtual enum enum_protocol_type type() const = 0;
134134

135135
/**
136136
Returns the type of the connection
137137
138138
@return
139139
enum enum_vio_type
140140
*/
141-
virtual enum enum_vio_type connection_type() {
142-
Vio *v = get_vio();
141+
virtual enum enum_vio_type connection_type() const {
142+
const Vio *v = get_vio();
143143
return v ? vio_type(v) : NO_VIO_TYPE;
144144
}
145145

@@ -161,7 +161,7 @@ class Protocol_classic : public Protocol {
161161
/* Wipe NET with zeros */
162162
void wipe_net();
163163
/* Check whether VIO is healhty */
164-
virtual bool connection_alive();
164+
virtual bool connection_alive() const;
165165
/* Returns the client capabilities */
166166
virtual ulong get_client_capabilities() { return m_client_capabilities; }
167167
/* Sets the client capabilities */
@@ -186,6 +186,7 @@ class Protocol_classic : public Protocol {
186186
NET *get_net();
187187
/* return VIO */
188188
Vio *get_vio();
189+
const Vio *get_vio() const;
189190
/* Set VIO */
190191
void set_vio(Vio *vio);
191192
/* Set packet number */
@@ -228,7 +229,7 @@ class Protocol_text : public Protocol_classic {
228229
virtual void start_row();
229230
virtual bool send_parameters(List<Item_param> *parameters, bool);
230231

231-
virtual enum enum_protocol_type type() { return PROTOCOL_TEXT; }
232+
virtual enum enum_protocol_type type() const { return PROTOCOL_TEXT; }
232233

233234
protected:
234235
virtual bool store(const char *from, size_t length,
@@ -264,7 +265,7 @@ class Protocol_binary : public Protocol_text {
264265
virtual bool send_parameters(List<Item_param> *parameters,
265266
bool is_sql_prepare);
266267

267-
virtual enum enum_protocol_type type() { return PROTOCOL_BINARY; }
268+
virtual enum enum_protocol_type type() const { return PROTOCOL_BINARY; }
268269

269270
protected:
270271
virtual bool store(const char *from, size_t length,

Diff for: sql/sql_class.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ int THD::send_explain_fields(Query_result *result) {
15401540
this, field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF));
15411541
}
15421542

1543-
enum_vio_type THD::get_vio_type() {
1543+
enum_vio_type THD::get_vio_type() const {
15441544
DBUG_ENTER("THD::get_vio_type");
15451545
DBUG_RETURN(get_protocol()->connection_type());
15461546
}
@@ -2606,7 +2606,7 @@ void THD::rpl_reattach_engine_ha_data() {
26062606
if (rli) rli->reattach_engine_ha_data(this);
26072607
}
26082608

2609-
bool THD::rpl_unflag_detached_engine_ha_data() {
2609+
bool THD::rpl_unflag_detached_engine_ha_data() const {
26102610
Relay_log_info *rli =
26112611
is_binlog_applier() ? rli_fake : (slave_thread ? rli_slave : NULL);
26122612
return rli ? rli->unflag_detached_engine_ha_data() : false;

0 commit comments

Comments
 (0)