Skip to content

Commit

Permalink
Cleanup's and more DBUG_PRINT's
Browse files Browse the repository at this point in the history
- Rewrote bool Query_compressed_log_event::write() to make it more readable
  (no logic changes).
- Changed DBUG_PRINT of 'is_error:' to 'is_error():' to make it easier to
  find error: in traces.
- Ensure that 'db' is never null in Query_log_event (Simplified code).
  • Loading branch information
montywi committed Jun 19, 2020
1 parent 605555f commit 1a49c5e
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 35 deletions.
13 changes: 11 additions & 2 deletions sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5850,8 +5850,10 @@ bool ha_table_exists(THD *thd, const LEX_CSTRING *db,

if ((type= dd_frm_type(thd, path, &engine, is_sequence)) ==
TABLE_TYPE_UNKNOWN)
{
DBUG_PRINT("exit", ("Does not exist"));
DBUG_RETURN(true); // Frm exists

}
if (type != TABLE_TYPE_VIEW)
{
plugin_ref p= plugin_lock_by_name(thd, &engine,
Expand All @@ -5866,6 +5868,7 @@ bool ha_table_exists(THD *thd, const LEX_CSTRING *db,
else
*hton= view_pseudo_hton;
}
DBUG_PRINT("exit", (exists ? "Exists" : "Does not exist"));
DBUG_RETURN(exists);
}

Expand All @@ -5875,13 +5878,16 @@ bool ha_table_exists(THD *thd, const LEX_CSTRING *db,
{
if (hton)
*hton= args.hton;
DBUG_PRINT("exit", ("discovery found file"));
DBUG_RETURN(TRUE);
}

if (need_full_discover_for_existence)
{
TABLE_LIST table;
bool exists;
uint flags = GTS_TABLE | GTS_VIEW;

if (!hton)
flags|= GTS_NOLOCK;

Expand All @@ -5898,9 +5904,12 @@ bool ha_table_exists(THD *thd, const LEX_CSTRING *db,
}

// the table doesn't exist if we've caught ER_NO_SUCH_TABLE and nothing else
DBUG_RETURN(!no_such_table_handler.safely_trapped_errors());
exists= !no_such_table_handler.safely_trapped_errors();
DBUG_PRINT("exit", (exists ? "Exists" : "Does not exist"));
DBUG_RETURN(exists);
}

DBUG_PRINT("exit", ("Does not exist"));
DBUG_RETURN(FALSE);
}

Expand Down
14 changes: 9 additions & 5 deletions sql/item_func.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3747,12 +3747,13 @@ longlong Item_master_pos_wait::val_int()
THD* thd = current_thd;
String *log_name = args[0]->val_str(&value);
int event_count= 0;
DBUG_ENTER("Item_master_pos_wait::val_int");

null_value=0;
if (thd->slave_thread || !log_name || !log_name->length())
{
null_value = 1;
return 0;
DBUG_RETURN(0);
}
#ifdef HAVE_REPLICATION
longlong pos = (ulong)args[1]->val_int();
Expand Down Expand Up @@ -3788,13 +3789,15 @@ longlong Item_master_pos_wait::val_int()
}
mi->release();
#endif
return event_count;
DBUG_PRINT("exit", ("event_count: %d null_value: %d", event_count,
(int) null_value));
DBUG_RETURN(event_count);

#ifdef HAVE_REPLICATION
err:
{
null_value = 1;
return 0;
DBUG_RETURN(0);
}
#endif
}
Expand All @@ -3805,11 +3808,12 @@ longlong Item_master_gtid_wait::val_int()
DBUG_ASSERT(fixed == 1);
longlong result= 0;
String *gtid_pos __attribute__((unused)) = args[0]->val_str(&value);
DBUG_ENTER("Item_master_gtid_wait::val_int");

if (args[0]->null_value)
{
null_value= 1;
return 0;
DBUG_RETURN(0);
}

null_value=0;
Expand All @@ -3826,7 +3830,7 @@ longlong Item_master_gtid_wait::val_int()
#else
null_value= 0;
#endif /* REPLICATION */
return result;
DBUG_RETURN(result);
}


Expand Down
3 changes: 2 additions & 1 deletion sql/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6557,7 +6557,8 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info, my_bool *with_annotate)
nodes. A check has been added to stop them from getting logged into
binary log files.
*/
if (WSREP(thd)) option_bin_log_flag= true;
if (WSREP(thd))
option_bin_log_flag= true;

if ((!(option_bin_log_flag)) ||
(thd->lex->sql_command != SQLCOM_ROLLBACK_TO_SAVEPOINT &&
Expand Down
58 changes: 37 additions & 21 deletions sql/log_event_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -736,12 +736,14 @@ void Log_event::init_show_field_list(THD *thd, List<Item>* field_list)
@note A side effect of the method is altering Log_event::checksum_alg
it the latter was undefined at calling.
@return true (positive) or false (negative)
@return true Checksum should be used. Log_event::checksum_alg is set.
@return false No checksum
*/

my_bool Log_event::need_checksum()
{
DBUG_ENTER("Log_event::need_checksum");
my_bool ret;
DBUG_ENTER("Log_event::need_checksum");
/*
few callers of Log_event::write
(incl FD::write, FD constructing code on the slave side, Rotate relay log
Expand Down Expand Up @@ -1310,35 +1312,46 @@ bool Query_log_event::write()
Calculate length of whole event
The "1" below is the \0 in the db's length
*/
event_length= (uint) (start-buf) + get_post_header_size_for_derived() + db_len + 1 + q_len;
event_length= ((uint) (start-buf) + get_post_header_size_for_derived() +
db_len + 1 + q_len);

return write_header(event_length) ||
write_data(buf, QUERY_HEADER_LEN) ||
write_post_header_for_derived() ||
write_data(start_of_status, (uint) (start-start_of_status)) ||
write_data(safe_str(db), db_len + 1) ||
write_data(start_of_status, (uint) status_vars_len) ||
write_data(db, db_len + 1) ||
write_data(query, q_len) ||
write_footer();
}

bool Query_compressed_log_event::write()
{
const char *query_tmp = query;
uint32 q_len_tmp = q_len;
uint32 alloc_size;
bool ret = true;
q_len = alloc_size = binlog_get_compress_len(q_len);
query = (char *)my_safe_alloca(alloc_size);
if(query && !binlog_buf_compress(query_tmp, (char *)query, q_len_tmp, &q_len))
char *buffer;
uint32 alloc_size, compressed_size;
bool ret= true;

compressed_size= alloc_size= binlog_get_compress_len(q_len);
buffer= (char*) my_safe_alloca(alloc_size);
if (buffer &&
!binlog_buf_compress(query, buffer, q_len, &compressed_size))
{
ret = Query_log_event::write();
}
my_safe_afree((void *)query, alloc_size);
query = query_tmp;
q_len = q_len_tmp;
/*
Write the compressed event. We have to temporarily store the event
in query and q_len as Query_log_event::write() uses these.
*/
const char *query_tmp= query;
uint32 q_len_tmp= q_len;
query= buffer;
q_len= compressed_size;
ret= Query_log_event::write();
query= query_tmp;
q_len= q_len_tmp;
}
my_safe_afree(buffer, alloc_size);
return ret;
}


/**
The simplest constructor that could possibly work. This is used for
creating static objects that have a special meaning and are invisible
Expand Down Expand Up @@ -1377,7 +1390,7 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
(suppress_use ? LOG_EVENT_SUPPRESS_USE_F : 0),
using_trans),
data_buf(0), query(query_arg), catalog(thd_arg->catalog),
db(thd_arg->db.str), q_len((uint32) query_length),
q_len((uint32) query_length),
thread_id(thd_arg->thread_id),
/* save the original thread id; we already know the server id */
slave_proxy_id((ulong)thd_arg->variables.pseudo_thread_id),
Expand All @@ -1390,6 +1403,8 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
table_map_for_update((ulonglong)thd_arg->table_map_for_update),
master_data_written(0)
{
/* status_vars_len is set just before writing the event */

time_t end_time;

#ifdef WITH_WSREP
Expand All @@ -1408,7 +1423,6 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,

memset(&user, 0, sizeof(user));
memset(&host, 0, sizeof(host));

error_code= errcode;

end_time= my_time(0);
Expand All @@ -1418,8 +1432,10 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
as an existing catalog of length zero. is that safe? /sven
*/
catalog_len = (catalog) ? (uint32) strlen(catalog) : 0;
/* status_vars_len is set just before writing the event */
db_len = (db) ? (uint32) strlen(db) : 0;

if (!(db= thd->db.str))
db= "";
db_len= (uint32) strlen(db);
if (thd_arg->variables.collation_database != thd_arg->db_charset)
charset_database_number= thd_arg->variables.collation_database->number;

Expand Down
3 changes: 2 additions & 1 deletion sql/sql_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3503,7 +3503,8 @@ my_bool Query_cache::register_all_tables(THD *thd,

my_bool
Query_cache::insert_table(THD *thd, size_t key_len, const char *key,
Query_cache_block_table *node, size_t db_length, uint8 suffix_length_arg,
Query_cache_block_table *node, size_t db_length,
uint8 suffix_length_arg,
uint8 cache_type,
qc_engine_callback callback,
ulonglong engine_data,
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7368,7 +7368,7 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg,
log event is written to the binary log, we pretend that no
table maps were written.
*/
if(binlog_should_compress(query_len))
if (binlog_should_compress(query_len))
{
Query_compressed_log_event qinfo(this, query_arg, query_len, is_trans, direct,
suppress_use, errcode);
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_insert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2538,7 +2538,7 @@ bool delayed_get_table(THD *thd, MDL_request *grl_protection_request,

end_create:
mysql_mutex_unlock(&LOCK_delayed_create);
DBUG_PRINT("exit", ("is_error: %d", thd->is_error()));
DBUG_PRINT("exit", ("is_error(): %d", thd->is_error()));
DBUG_RETURN(thd->is_error());
}

Expand Down
2 changes: 1 addition & 1 deletion sql/sql_parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5949,7 +5949,7 @@ mysql_execute_command(THD *thd)
lex->create_info.set(DDL_options_st::OPT_IF_EXISTS);
DBUG_ASSERT(lex->m_sql_cmd != NULL);
res= lex->m_sql_cmd->execute(thd);
DBUG_PRINT("result", ("res: %d killed: %d is_error: %d",
DBUG_PRINT("result", ("res: %d killed: %d is_error(): %d",
res, thd->killed, thd->is_error()));
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_show.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ static bool get_field_default_value(THD *thd, Field *field, String *def_value,
@param thd thread handler
@param packet string to append
@param opt list of options
@param check_options only print known options
@param check_options print all used options
@param rules list of known options
*/

Expand Down
1 change: 1 addition & 0 deletions storage/maria/ha_s3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ static int s3_discover_table_existance(handlerton *hton, const char *db,

res= s3_frm_exists(s3_client, &s3_info);
s3_deinit(s3_client);
DBUG_PRINT("exit", ("exists: %d", res == 0));
DBUG_RETURN(res == 0); // Return 1 if exists
}

Expand Down
2 changes: 1 addition & 1 deletion storage/maria/s3_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ int s3_check_frm_version(ms3_st *s3_client, S3_INFO *s3_info)
if (res)
DBUG_PRINT("error", ("Wrong table version"));
else
DBUG_PRINT("error", ("Version strings matches"));
DBUG_PRINT("exit", ("Version strings matches"));
DBUG_RETURN(res);
}

Expand Down

0 comments on commit 1a49c5e

Please sign in to comment.