Bug #115538 mysqlbinlog missing some events when tmpdir not accessible
Submitted: 8 Jul 2024 8:58 Modified: 8 Jul 2024 9:05
Reporter: Vitale Jiang (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Replication Severity:S3 (Non-critical)
Version:5.7 and 8.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution

[8 Jul 2024 8:58] Vitale Jiang
Description:
mysqlbinlog return EXIT_SUCCESS even if some events missing when creating tempfile failed, if we customized tmpdir by setting TMPDIR environment variable, only existency of $TMPDIR will be checked but not permission.

mysqlbinlog would create temp file when printing some big binlog events which need more than IO_CACHE write buffer size in tmpdir, which may be not writable.

backtrace may be like:

  create_temp_file (mysys/mf_tempfile.cc:324)
  inline_mysql_file_create_temp
  real_open_cached_file
  my_b_flush_io_cache
  _my_b_write
  my_b_write
  my_b_vprintf
  my_b_printf
  Rows_log_event::print_verbose
  Log_event::print_base64
  Rows_log_event::print_helper
  Write_rows_log_event::print
  process_event
  dump_local_log_entries
  dump_single_log
  dump_multiple_logs
  main

How to repeat:
1. create test table and tmpdir:

CREATE TABLE `t1` (
  `id` int NOT NULL AUTO_INCREMENT,
  `c1` varchar(4000) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

[ root ] # mkdir /data/tmpdir

2. insert 1000 rows for binlog;

3. print binlog events with normal user and set TMPDIR=/data/tmpdir:

$ TMPDIR=/data/tmpdir mysqlbinlog /data/mysql_data/3306/binlog.000001
mysqlbinlog: Can't create/write to file '/root/tmp.b8mK7G' (OS errno 13 - Permission denied)
$ echo $?
0

4. check output and we can found some fragmented events.

Suggested fix:
IMHO, exit and reporting failure would be better when creating tempfile failed, we can check tmpdir permission if TMPDIR set.
[8 Jul 2024 9:02] Vitale Jiang
check tmpdir permission if user set TMPDIR

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: mysqlbinlog-check-tmpdir-permission.patch (application/octet-stream, text), 664 bytes.

[8 Jul 2024 9:05] MySQL Verification Team
Hello Vitale Jiang,

Thank you for the report and contribution.

regards,
Umesh