[MDEV-5959] thread_id using different C types in different functions and source sections Created: 2014-03-27  Updated: 2014-10-16

Status: Open
Project: MariaDB Server
Component/s: None
Affects Version/s: 10.0.9
Fix Version/s: 10.1

Type: Bug Priority: Minor
Reporter: Arjen Lentz Assignee: Sergei Golubchik
Resolution: Unresolved Votes: 0
Labels: None


 Description   

There appears to be a significant amount of inconsistency in the type used to store incarnations of thread_id in various places.
See below for some grep output that I hand-edited to only show the declaration spots and not other uses.

We see longlong, ulonglong, DWORD, but even int, there's also a dedicated my_thread_id type that doesn't appear to get used very much.

In storage it's generally regarded as a 4 byte integer, mostly regarded as unsigned but not always.

With this kind of juggling, things can easily go wrong at some point.
Suggestion: someone go through it and clean up, very carefully.
thanks

Regards,
Arjen.

$ grep thread_id sql/* include/*
sql/event_scheduler.cc:836:  printf("Thread id  : %lu\n", scheduler_thd? scheduler_thd->thread_id : 0);
sql/filesort.cc:413:                        (ulong) thd->thread_id,
sql/ha_ndbcluster_binlog.cc:261:  ulong save_thread_id= thd->variables.pseudo_thread_id;
sql/item_func.cc:4415:  ulong thread_id = thd->mdl_context.get_lock_owner(&ull_key);
sql/item_func.h:1680:  my_thread_id entry_thread_id;
sql/log.cc:631:              uint user_host_len, int thread_id,
sql/log.cc:712:      table->field[2]->store((longlong) thread_id, TRUE) ||
sql/log.cc:923:  if (table->field[11]->store((longlong) thd->thread_id, TRUE))
sql/log.cc:1035:              uint user_host_len, int thread_id,
sql/log.cc:2689:                            uint user_host_len, int thread_id,
sql/log.cc:2728:      length= my_snprintf(buff, 32, "%5ld ", (long) thread_id);
sql/log.cc:2848:                    (ulong) thd->thread_id, (thd->db ? thd->db : ""),
sql/log_event.cc:3358:  slave_proxy_id= thread_id = uint4korr(buf + Q_THREAD_ID_OFFSET);
sql/log_event.cc:3804:    my_b_printf(file, "\t%s\tthread_id=%lu\texec_time=%lu\terror_code=%d\n",
sql/log_event.cc:3805:                get_type_str(), (ulong) thread_id, (ulong) exec_time,
sql/log_event.cc:3837:    my_b_printf(file,"SET @@session.pseudo_thread_id=%lu%s\n",
sql/log_event.cc:3838:                short_form ? 999999999 : (ulong)thread_id,
sql/log_event.cc:5546:  slave_proxy_id= thread_id= uint4korr(data_head + L_THREAD_ID_OFFSET);
sql/log_event.cc:5612:    my_b_printf(&cache, "\tQuery\tthread_id=%ld\texec_time=%ld\n",
sql/log_event.cc:5613:                thread_id, exec_time);
sql/log_event.cc:5636:    my_b_printf(&cache,"%sSET @@session.pseudo_thread_id=%lu%s\n",
sql/log_event.cc:5637:            commented ? "# " : "", (ulong)thread_id,
sql/log_event.h:798:  uint thread_id;
sql/log_event.h:1896:  ulong thread_id;
sql/log_event.h:2351:  ulong thread_id;
sql/log.h:350:             uint user_host_len, int thread_id,
sql/log.h:829:                           uint user_host_len, int thread_id,
sql/log.h:858:                           uint user_host_len, int thread_id,
sql/log.h:890:                           uint user_host_len, int thread_id,
sql/mdl.h:932:  ulong get_thread_id() const { return thd_get_thread_id(get_thd()); }
sql/mdl.h:971:extern "C" unsigned long thd_get_thread_id(const MYSQL_THD thd);
sql/mysqld.cc:539:ulong thread_id=1L,current_pid;
sql/mysqld.cc:1888:    sql_print_warning("Got signal %d from thread %ld", sig,my_thread_id());
sql/mysqld.cc:3805:extern "C" my_thread_id mariadb_dbug_id()
sql/mysqld.cc:3810:    return thd->thread_id;
sql/mysqld.cc:3878:  max_system_variables.pseudo_thread_id= (ulong)~0;
sql/mysqld.cc:5881:  DBUG_PRINT("info",(("creating thread %lu"), thd->thread_id));
sql/mysqld.cc:8144:  global_query_id= thread_id= 1L;
sql/mysqld.h:151:extern ulong thread_id;
sql/signal_handler.cc:195:                          (ulong) thd->thread_id);
sql/sql_audit.cc:97:  event.thread_id= va_arg(ap, unsigned long);
sql/sql_audit.cc:121:  event.thread_id= va_arg(ap, unsigned long);
sql/sql_audit.h:233:                       (int)(lock == F_RDLCK), (ulong)thd->thread_id,
sql/sql_audit.h:251:                       0, (ulong)thd->thread_id,
sql/sql_audit.h:267:                       0, (ulong)thd->thread_id,
sql/sql_audit.h:284:                       0, (ulong)thd->thread_id,
sql/sql_audit.h:300:                       0, (ulong)thd->thread_id,
sql/sql_base.cc:206:  int4store(key + key_length + 4, thd->variables.pseudo_thread_id);
sql/sql_base.cc:1526:  int4store(key + key_length + 4, thd->variables.pseudo_thread_id);
sql/sql_base.cc:5528:              "pseudo_thread_id: %lu",
sql/sql_base.cc:5531:              (ulong) thd->variables.pseudo_thread_id));
sql/sql_base.cc:5789:               ("query_id: %lu  server_id: %u  pseudo_thread_id: %lu",
sql/sql_base.cc:5791:                (ulong) thd->variables.pseudo_thread_id));
sql/sql_class.cc:761:                   thd->thread_id, (ulong) thd->real_id, (ulong) thd->query_id);
sql/sql_class.cc:4192:extern "C" unsigned long thd_get_thread_id(const MYSQL_THD thd)
sql/sql_class.cc:4194:  return((unsigned long)thd->thread_id);
sql/sql_class.h:577:  my_thread_id pseudo_thread_id;
sql/sql_class.h:2507:  my_thread_id  thread_id;
sql/sql_parse.cc:7321:    if (id == (query_id ? tmp->query_id : (longlong) tmp->thread_id))
sql/sql_partition_admin.cc:566:              tmp_file_prefix, current_pid, thd->thread_id);
sql/sql_show.cc:2174:  ulong thread_id;
sql/sql_show.cc:2321:    protocol->store((ulonglong) thd_info->thread_id);
sql/sql_show.cc:2493:  my_thread_id  thread_id;
sql/sql_show.cc:2497:  thread_id= thd->lex->value_list.head()->val_int();
sql/sql_show.cc:2632:      table->field[0]->store((longlong) tmp->thread_id, TRUE);
sql/sql_test.cc:390:  ulong thread_id;
sql/sys_vars.cc:1361:static Sys_var_ulong Sys_pseudo_thread_id(
sql/sys_vars.cc:1362:       "pseudo_thread_id",
sql/sys_vars.cc:1364:       SESSION_ONLY(pseudo_thread_id),
sql/threadpool_unix.cc:609:  pthread_t thread_id;
sql/threadpool_unix.cc:614:  mysql_thread_create(key_timer_thread,&thread_id, NULL, timer_thread, timer);
sql/threadpool_unix.cc:793:  pthread_t thread_id;
include/my_pthread.h:48:  DWORD thread_id;
include/my_pthread.h:683:typedef ulong my_thread_id;
include/my_pthread.h:692:extern my_thread_id my_thread_dbug_id(void);
include/my_pthread.h:723:  my_thread_id id;
include/mysql.h:269:  unsigned long thread_id;		/* Id for connection in server */
include/mysql.h:411:unsigned long STDCALL mysql_thread_id(MYSQL *mysql);
include/mysql.h.pp:349:  unsigned long thread_id;
include/mysql.h.pp:415:unsigned long mysql_thread_id(MYSQL *mysql);
include/my_sys.h:158:void sf_report_leaked_memory(my_thread_id id);
include/my_sys.h:159:extern my_thread_id (*sf_malloc_dbug_id)(void);
include/thr_alarm.h:88:  my_thread_id thread_id;
include/thr_alarm.h:101:void thr_alarm_kill(my_thread_id thread_id);
include/thr_lock.h:97:  my_thread_id thread_id;
include/thr_lock.h:156:my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread);
include/violite.h:287:  DWORD thread_id; /* Used on XP only by vio_shutdown() */


Generated at Thu Feb 08 07:08:19 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.