Skip to content

Commit

Permalink
Simple binary cache optimizations
Browse files Browse the repository at this point in the history
- Don't call my_chsize() for small (less than 64K) binary log tmp files
- Don't flush cache to disk on reset.
  • Loading branch information
montywi authored and Alexander Barkov committed Apr 7, 2017
1 parent 1bcfa14 commit 0177a9c
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions sql/log.cc
Expand Up @@ -61,6 +61,8 @@
#define MAX_LOG_BUFFER_SIZE 1024
#define MAX_TIME_SIZE 32
#define MY_OFF_T_UNDEF (~(my_off_t)0UL)
/* Truncate cache log files bigger than this */
#define CACHE_FILE_TRUNC_SIZE 65536

#define FLAGSTR(V,F) ((V)&(F)?#F" ":"")

Expand Down Expand Up @@ -313,24 +315,19 @@ class binlog_cache_data

void reset()
{
compute_statistics();
truncate(0);
if(cache_log.file != -1)
bool cache_was_empty= empty();
bool truncate_file= (cache_log.file != -1 &&
my_b_write_tell(&cache_log) > CACHE_FILE_TRUNC_SIZE);
truncate(0,1); // Forget what's in cache
if (!cache_was_empty)
compute_statistics();
if (truncate_file)
my_chsize(cache_log.file, 0, 0, MYF(MY_WME));

changes_to_non_trans_temp_table_flag= FALSE;
status= 0;
incident= FALSE;
before_stmt_pos= MY_OFF_T_UNDEF;
/*
The truncate function calls reinit_io_cache that calls
my_b_flush_io_cache which may increase disk_writes. This breaks
the disk_writes use by the binary log which aims to compute the
ratio between in-memory cache usage and disk cache usage. To
avoid this undesirable behavior, we reset the variable after
truncating the cache.
*/
cache_log.disk_writes= 0;
DBUG_ASSERT(empty());
}

Expand Down Expand Up @@ -437,11 +434,16 @@ class binlog_cache_data
*/
void compute_statistics()
{
if (!empty())
statistic_increment(*ptr_binlog_cache_use, &LOCK_status);
if (cache_log.disk_writes != 0)
{
statistic_increment(*ptr_binlog_cache_use, &LOCK_status);
if (cache_log.disk_writes != 0)
statistic_increment(*ptr_binlog_cache_disk_use, &LOCK_status);
#ifdef REAL_STATISTICS
statistic_add(*ptr_binlog_cache_disk_use,
cache_log.disk_writes, &LOCK_status);
#else
statistic_increment(*ptr_binlog_cache_disk_use, &LOCK_status);
#endif
cache_log.disk_writes= 0;
}
}

Expand Down Expand Up @@ -470,15 +472,15 @@ class binlog_cache_data
It truncates the cache to a certain position. This includes deleting the
pending event.
*/
void truncate(my_off_t pos)
void truncate(my_off_t pos, bool reset_cache=0)
{
DBUG_PRINT("info", ("truncating to position %lu", (ulong) pos));
if (pending())
{
delete pending();
set_pending(0);
}
reinit_io_cache(&cache_log, WRITE_CACHE, pos, 0, 0);
reinit_io_cache(&cache_log, WRITE_CACHE, pos, 0, reset_cache);
cache_log.end_of_file= saved_max_binlog_cache_size;
}

Expand Down

0 comments on commit 0177a9c

Please sign in to comment.