|
61 | 61 | #define MAX_LOG_BUFFER_SIZE 1024
|
62 | 62 | #define MAX_TIME_SIZE 32
|
63 | 63 | #define MY_OFF_T_UNDEF (~(my_off_t)0UL)
|
| 64 | +/* Truncate cache log files bigger than this */ |
| 65 | +#define CACHE_FILE_TRUNC_SIZE 65536 |
64 | 66 |
|
65 | 67 | #define FLAGSTR(V,F) ((V)&(F)?#F" ":"")
|
66 | 68 |
|
@@ -313,24 +315,19 @@ class binlog_cache_data
|
313 | 315 |
|
314 | 316 | void reset()
|
315 | 317 | {
|
316 |
| - compute_statistics(); |
317 |
| - truncate(0); |
318 |
| - if(cache_log.file != -1) |
| 318 | + bool cache_was_empty= empty(); |
| 319 | + bool truncate_file= (cache_log.file != -1 && |
| 320 | + my_b_write_tell(&cache_log) > CACHE_FILE_TRUNC_SIZE); |
| 321 | + truncate(0,1); // Forget what's in cache |
| 322 | + if (!cache_was_empty) |
| 323 | + compute_statistics(); |
| 324 | + if (truncate_file) |
319 | 325 | my_chsize(cache_log.file, 0, 0, MYF(MY_WME));
|
320 | 326 |
|
321 | 327 | changes_to_non_trans_temp_table_flag= FALSE;
|
322 | 328 | status= 0;
|
323 | 329 | incident= FALSE;
|
324 | 330 | before_stmt_pos= MY_OFF_T_UNDEF;
|
325 |
| - /* |
326 |
| - The truncate function calls reinit_io_cache that calls |
327 |
| - my_b_flush_io_cache which may increase disk_writes. This breaks |
328 |
| - the disk_writes use by the binary log which aims to compute the |
329 |
| - ratio between in-memory cache usage and disk cache usage. To |
330 |
| - avoid this undesirable behavior, we reset the variable after |
331 |
| - truncating the cache. |
332 |
| - */ |
333 |
| - cache_log.disk_writes= 0; |
334 | 331 | DBUG_ASSERT(empty());
|
335 | 332 | }
|
336 | 333 |
|
@@ -437,11 +434,16 @@ class binlog_cache_data
|
437 | 434 | */
|
438 | 435 | void compute_statistics()
|
439 | 436 | {
|
440 |
| - if (!empty()) |
| 437 | + statistic_increment(*ptr_binlog_cache_use, &LOCK_status); |
| 438 | + if (cache_log.disk_writes != 0) |
441 | 439 | {
|
442 |
| - statistic_increment(*ptr_binlog_cache_use, &LOCK_status); |
443 |
| - if (cache_log.disk_writes != 0) |
444 |
| - statistic_increment(*ptr_binlog_cache_disk_use, &LOCK_status); |
| 440 | +#ifdef REAL_STATISTICS |
| 441 | + statistic_add(*ptr_binlog_cache_disk_use, |
| 442 | + cache_log.disk_writes, &LOCK_status); |
| 443 | +#else |
| 444 | + statistic_increment(*ptr_binlog_cache_disk_use, &LOCK_status); |
| 445 | +#endif |
| 446 | + cache_log.disk_writes= 0; |
445 | 447 | }
|
446 | 448 | }
|
447 | 449 |
|
@@ -470,15 +472,15 @@ class binlog_cache_data
|
470 | 472 | It truncates the cache to a certain position. This includes deleting the
|
471 | 473 | pending event.
|
472 | 474 | */
|
473 |
| - void truncate(my_off_t pos) |
| 475 | + void truncate(my_off_t pos, bool reset_cache=0) |
474 | 476 | {
|
475 | 477 | DBUG_PRINT("info", ("truncating to position %lu", (ulong) pos));
|
476 | 478 | if (pending())
|
477 | 479 | {
|
478 | 480 | delete pending();
|
479 | 481 | set_pending(0);
|
480 | 482 | }
|
481 |
| - reinit_io_cache(&cache_log, WRITE_CACHE, pos, 0, 0); |
| 483 | + reinit_io_cache(&cache_log, WRITE_CACHE, pos, 0, reset_cache); |
482 | 484 | cache_log.end_of_file= saved_max_binlog_cache_size;
|
483 | 485 | }
|
484 | 486 |
|
|
0 commit comments