Bug #97358 The log.flush_notifier_mutex in log_sys is useless
Submitted: 24 Oct 11:59 Modified: 25 Oct 11:53
Reporter: chen zongzhi (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S5 (Performance)
Version:8.0.* OS:Any
Assigned to: CPU Architecture:Any

[24 Oct 11:59] chen zongzhi
Description:
Hello

The MySQL code version is 8.0.17

There is only three places that call log_flush_notifier_mutex_enter(log),  all of these places ad in log_flush_notifier function(). 

And there is only one log_flush_notifier thread that will call this function.  The log_flush_notifier thread is used for notifier user thread if the redo log that it write has flush to disk

The whole there place is below:

```
2397 void log_flush_notifier(log_t *log_ptr) {
2398   ut_a(log_ptr != nullptr);
2399
2400   log_t &log = *log_ptr;
2401   lsn_t lsn = log.flushed_to_disk_lsn.load() + 1;
2402
2403   log_flush_notifier_mutex_enter(log);
2404
2405   Log_thread_waiting waiting{log, log.flush_notifier_event,
2406                              srv_log_flush_notifier_spin_delay,
2407                              srv_log_flush_notifier_timeout};
2408
          ........
2422
2423     auto stop_condition = [&log, lsn, &released](bool wait) {
2424       LOG_SYNC_POINT("log_flush_notifier_after_event_reset");
2425       if (released) {
2426         log_flush_notifier_mutex_enter(log);
2427         released = false;
2428       }
2429
2430       LOG_SYNC_POINT("log_flush_notifier_before_check");
2431

          ...

2441
2442       if (wait) {
2443         log_flush_notifier_mutex_exit(log);
2444         released = true;
2445       }
2446       LOG_SYNC_POINT("log_flush_notifier_before_wait");
2447
2448       return (false);
2449     };

```

How to repeat:
read the code
[24 Oct 12:36] Sinisa Milivojevic
Hello Mr. zongzhi,

Thank you for your bug report.

What you write is true, but there is one detail that you miss. That code, which you are referring to, can run in several threads. Hence, the mutex lock is necessary.

Let us know if you disagree ........
[24 Oct 19:06] chen zongzhi
No, I am not agree.
There is only one log_flush_notifier..
The log_flush_notifier thread is created in  log_start_background_threads() function

```
  srv_threads.m_log_flush_notifier =
      os_thread_create(log_flush_notifier_thread_key, log_flush_notifier, &log);
```
[25 Oct 11:53] Sinisa Milivojevic
Hi Mr. zongzhi,

I have revisited the code and I think that you are right.

Verified as a performance improvement contribution.