MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / my_b_flush_io_cache

Function my_b_flush_io_cache

mysys/mf_iocache.c:1734–1817  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1732 unlock_append_buffer(info);
1733
1734int my_b_flush_io_cache(IO_CACHE *info,
1735 int need_append_buffer_lock __attribute__((unused)))
1736{
1737 size_t length;
1738 my_off_t pos_in_file;
1739 my_bool append_cache= (info->type == SEQ_READ_APPEND);
1740 DBUG_ENTER("my_b_flush_io_cache");
1741 DBUG_PRINT("enter", ("cache: 0x%lx", (long) info));
1742
1743 if (!append_cache)
1744 need_append_buffer_lock= 0;
1745
1746 if (info->type == WRITE_CACHE || append_cache)
1747 {
1748 if (info->file == -1)
1749 {
1750 if (real_open_cached_file(info))
1751 DBUG_RETURN((info->error= -1));
1752 }
1753 LOCK_APPEND_BUFFER;
1754
1755 if ((length=(size_t) (info->write_pos - info->write_buffer)))
1756 {
1757 /*
1758 In case of a shared I/O cache with a writer we do direct write
1759 cache to read cache copy. Do it before the write here so that
1760 the readers can work in parallel with the write.
1761 copy_to_read_buffer() relies on info->pos_in_file.
1762 */
1763 if (info->share)
1764 copy_to_read_buffer(info, info->write_buffer, length);
1765
1766 pos_in_file=info->pos_in_file;
1767 /*
1768 If we have append cache, we always open the file with
1769 O_APPEND which moves the pos to EOF automatically on every write
1770 */
1771 if (!append_cache && info->seek_not_done)
1772 { /* File touched, do seek */
1773 if (mysql_file_seek(info->file, pos_in_file, MY_SEEK_SET, MYF(0)) ==
1774 MY_FILEPOS_ERROR)
1775 {
1776 UNLOCK_APPEND_BUFFER;
1777 DBUG_RETURN((info->error= -1));
1778 }
1779 if (!append_cache)
1780 info->seek_not_done=0;
1781 }
1782 if (!append_cache)
1783 info->pos_in_file+=length;
1784 info->write_end= (info->write_buffer+info->buffer_length-
1785 ((pos_in_file+length) & (IO_SIZE-1)));
1786
1787 if (mysql_file_write(info->file,info->write_buffer,length,
1788 info->myflags | MY_NABP))
1789 info->error= -1;
1790 else
1791 info->error= 0;

Callers 4

reinit_io_cacheFunction · 0.85
_my_b_writeFunction · 0.85
my_b_appendFunction · 0.85
end_io_cacheFunction · 0.85

Calls 2

real_open_cached_fileFunction · 0.85
copy_to_read_bufferFunction · 0.85

Tested by

no test coverage detected