summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2017-04-07 10:08:20 +0300
committerAlexander Barkov <bar@mariadb.org>2017-04-07 19:12:58 +0400
commit0177a9c74a44d7f3b3a2353f5e024286c81979e1 (patch)
treee4d6913d5f2158af1829bf243bf0ee8be3c61350 /sql
parent1bcfa14e26f96d5438277a87fce63c926e7766a2 (diff)
downloadmariadb-git-0177a9c74a44d7f3b3a2353f5e024286c81979e1.tar.gz
Simple binary cache optimizations
- Don't call my_chsize() for small (less than 64K) binary log tmp files - Don't flush cache to disk on reset.
Diffstat (limited to 'sql')
-rw-r--r--sql/log.cc38
1 files changed, 20 insertions, 18 deletions
diff --git a/sql/log.cc b/sql/log.cc
index 91da94af878..1f55b283a13 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -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" ":"")
@@ -313,24 +315,19 @@ public:
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());
}
@@ -437,11 +434,16 @@ private:
*/
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;
}
}
@@ -470,7 +472,7 @@ private:
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())
@@ -478,7 +480,7 @@ private:
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;
}