Skip to content

Instantly share code, notes, and snippets.

@b0bu
Created May 25, 2021 13:11
Show Gist options
  • Save b0bu/5a2060ff59f8920b4200c2a08ad4814c to your computer and use it in GitHub Desktop.
Save b0bu/5a2060ff59f8920b4200c2a08ad4814c to your computer and use it in GitHub Desktop.
corefiles in the kernel for mariadb

Enable coredumps for the kernel

mkdir /data/corefiles
chmod 777 /data/corefiles
echo /data/corefiles/core > /proc/sys/kernel/core_pattern
echo 1 > /proc/sys/kernel/core_uses_pid
sysctl -w fs.suid_dumpable=2
cat <<SETCORE > /etc/sysctl.d/mariadb_core.conf
kernel.core_pattern=/data/corefiles/core
kernel.core_uses_pid=1
SETCORE

also set mariadb's server.cnf to enable core dumps

[server]
core_file

Launch a repl

gdb /usr/bin/mysql /path/to/core.<pid>

Enabled snap len 0 so you can actually see what's going on

set print pretty on
set print element 0

bt
frame N
p *thd

After selection the appropriate frame / thread you can explore it by dereferencing it, or if you know what you're looking for directly query the struct members:

# The seqno that causes the core dump
p thd->wsrep_trx_meta->gtid->seqno
$13 = 16848902
# the last operations the process was doing
thd->proc_info 
  proc_info = 0x7f9de4005e28 "Update_rows_log_event::ha_update_row(16848902)",
# replication state info and its status
thd->wsrep_info
 wsrep_info = "Update_rows_log_event::ha_update_row(16848902)\000\071\060\062)", '\000' <repeats 76 times>,
 ha_data = {{
      ha_ptr = 0x7fa008107120,
      ha_info = {{
          m_next = 0x0,
          m_ht = 0x55b72b1addd8,
          m_flags = 1 '\001'
        }, {
          m_next = 0x0,
          m_ht = 0x55b72b1addd8,
          m_flags = 0 '\000'
---Type <return> to continue, or q <return> to quit---
        }},
      lock = 0x55b72b1e0c70
    }, {
  wsrep_query_state = QUERY_EXEC,
  wsrep_conflict_state = MUST_ABORT
  .....
# seq again but this time from gtid perspective
p thd->wsrep_trx_meta->gtid->seqno
$13 = 16848902

The below query is shortened to ...

# the query that was being executed just before coredump
p thd->query_string
    query_string = {
      string = {
        str = 0x7f9f68013dc3 "UPDATE `<redacted>` SET `<redacted>` = NULL, `<redacted>` = '1868947', `DateCreated` = timestamp('2021-05-12 15:03:53.000000'), `DateModified` = timestamp('2021-05-12 15:03:58"..., length = 553}, cs = 0x5621d9f41b40 <my_charset_utf8mb4_unicode_ci>} timestamp('2021-05-13 07:12:30"...,
        length = 568
      },
    .....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment