Commit 196e8529 authored by Sergei Golubchik's avatar Sergei Golubchik

misc IO_CACHE cleanups

* remove unused (and not implemented) WRITE_NET type
* remove cast in my_b_write() macro. my_b_* macros are
  function-like, casts are responsibility of the caller
* replace hackish _my_b_write(info,0,0) with the explicit
  my_b_flush_io_cache() in my_b_write_byte()
* remove unused my_b_fill_cache()
* replace pbool -> my_bool
* make internal IO_CACHE functions static
* reformat comments, correct typos, remove obsolete comments (ISAM)
* assert valid cache type in init_functions()
* use IO_ROUND_DN() macro where appropriate
* remove unused DBUG_EXECUTE_IF in _my_b_cache_write()
* remove unnecessary __attribute__((unused))
* fix goto error in parse_file.cc
* remove redundant reinit_io_cache() in uniques.cc
* don't do reinit_io_cache() if the cache was not initialized
  in ma_check.c
* extract duplicate functionality from various _my_b_*_read
  functions into a common wrapper. Same for _my_b_*_write
* create _my_b_cache_write_r instead of having if's in
  _my_b_cache_write (similar to existing _my_b_cache_read and
  _my_b_cache_read_r)
* don't call mysql_file_write() from my_b_flush_io_cache(),
  call info->write_function() instead
parent 1841557e
......@@ -285,7 +285,7 @@ enum cache_type
{
TYPE_NOT_SET= 0, READ_CACHE, WRITE_CACHE,
SEQ_READ_APPEND /* sequential read or append */,
READ_FIFO, READ_NET,WRITE_NET};
READ_FIFO, READ_NET};
enum flush_type
{
......@@ -517,14 +517,12 @@ extern my_error_reporter my_charset_error_reporter;
#define my_b_read(info,Buffer,Count) \
((info)->read_pos + (Count) <= (info)->read_end ?\
(memcpy(Buffer,(info)->read_pos,(size_t) (Count)), \
((info)->read_pos+=(Count)),0) :\
(*(info)->read_function)((info),Buffer,Count))
((info)->read_pos+=(Count)), 0) : _my_b_read((info), (Buffer), (Count)))
#define my_b_write(info,Buffer,Count) \
((info)->write_pos + (Count) <=(info)->write_end ?\
(memcpy((info)->write_pos, (Buffer), (size_t)(Count)),\
((info)->write_pos+=(Count)),0) : \
(*(info)->write_function)((info),(uchar *)(Buffer),(Count)))
((info)->write_pos+=(Count)), 0) : _my_b_write((info), (Buffer), (Count)))
#define my_b_get(info) \
((info)->read_pos != (info)->read_end ?\
......@@ -535,10 +533,7 @@ extern my_error_reporter my_charset_error_reporter;
#define my_b_write_byte(info,chr) \
(((info)->write_pos < (info)->write_end) ?\
((*(info)->write_pos++)=(chr)) :\
(_my_b_write(info,0,0) , ((*(info)->write_pos++)=(chr))))
#define my_b_fill_cache(info) \
(((info)->read_end=(info)->read_pos),(*(info)->read_function)(info,0,0))
((my_b_flush_io_cache(info, 1)), ((*(info)->write_pos++)=(chr))))
#define my_b_tell(info) ((info)->pos_in_file + \
(size_t) (*(info)->current_pos - (info)->request_pos))
......@@ -741,18 +736,15 @@ void my_store_ptr(uchar *buff, size_t pack_length, my_off_t pos);
my_off_t my_get_ptr(uchar *ptr, size_t pack_length);
extern int init_io_cache(IO_CACHE *info,File file,size_t cachesize,
enum cache_type type,my_off_t seek_offset,
pbool use_async_io, myf cache_myflags);
my_bool use_async_io, myf cache_myflags);
extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
my_off_t seek_offset,pbool use_async_io,
pbool clear_cache);
my_off_t seek_offset, my_bool use_async_io,
my_bool clear_cache);
extern void setup_io_cache(IO_CACHE* info);
extern int _my_b_read(IO_CACHE *info,uchar *Buffer,size_t Count);
extern int _my_b_read_r(IO_CACHE *info,uchar *Buffer,size_t Count);
extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
IO_CACHE *write_cache, uint num_threads);
extern void remove_io_thread(IO_CACHE *info);
extern int _my_b_seq_read(IO_CACHE *info,uchar *Buffer,size_t Count);
extern int _my_b_net_read(IO_CACHE *info,uchar *Buffer,size_t Count);
extern int _my_b_get(IO_CACHE *info);
extern int _my_b_async_read(IO_CACHE *info,uchar *Buffer,size_t Count);
extern int _my_b_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
......
......@@ -20,11 +20,12 @@
#include "my_static.h"
#include "mysys_err.h"
/*
Remove an open tempfile so that it doesn't survive
if we crash; If the operating system doesn't support
this, just remember the file name for later removal
*/
/**
Remove an open tempfile so that it doesn't survive if we crash
If the operating system doesn't support this, just remember
the file name for later removal
*/
static my_bool cache_remove_open_tmp(IO_CACHE *cache __attribute__((unused)),
const char *name)
......@@ -49,14 +50,14 @@ static my_bool cache_remove_open_tmp(IO_CACHE *cache __attribute__((unused)),
return 0;
}
/*
** Open tempfile cached by IO_CACHE
** Should be used when no seeks are done (only reinit_io_buff)
** Return 0 if cache is inited ok
** The actual file is created when the IO_CACHE buffer gets filled
** If dir is not given, use TMPDIR.
*/
/**
Open tempfile cached by IO_CACHE
Should be used when no seeks are done (only reinit_io_buff)
Return 0 if cache is inited ok
The actual file is created when the IO_CACHE buffer gets filled
If dir is not given, use TMPDIR.
*/
my_bool open_cached_file(IO_CACHE *cache, const char* dir, const char *prefix,
size_t cache_size, myf cache_myflags)
{
......@@ -71,7 +72,7 @@ my_bool open_cached_file(IO_CACHE *cache, const char* dir, const char *prefix,
cache->prefix[0]= 0;
cache->file_name=0;
cache->buffer=0; /* Mark that not open */
if (!init_io_cache(cache,-1,cache_size,WRITE_CACHE,0L,0,
if (!init_io_cache(cache, -1, cache_size, WRITE_CACHE, 0L, 0,
MYF(cache_myflags | MY_NABP)))
{
DBUG_RETURN(0);
......@@ -79,8 +80,9 @@ my_bool open_cached_file(IO_CACHE *cache, const char* dir, const char *prefix,
DBUG_RETURN(1);
}
/* Create the temporary file */
/**
Create the temporary file
*/
my_bool real_open_cached_file(IO_CACHE *cache)
{
char name_buff[FN_REFLEN];
......
This diff is collapsed.
......@@ -51,7 +51,7 @@
#include "rpl_utility.h"
#include "sql_digest.h"
#define my_b_write_string(A, B) my_b_write((A), (B), (uint) (sizeof(B) - 1))
#define my_b_write_string(A, B) my_b_write((A), (uchar*)(B), (uint) (sizeof(B) - 1))
using std::max;
......@@ -353,13 +353,13 @@ static void pretty_print_str(IO_CACHE* cache, const char* str, int len)
{
char c;
switch ((c=*str++)) {
case '\n': my_b_write(cache, "\\n", 2); break;
case '\r': my_b_write(cache, "\\r", 2); break;
case '\\': my_b_write(cache, "\\\\", 2); break;
case '\b': my_b_write(cache, "\\b", 2); break;
case '\t': my_b_write(cache, "\\t", 2); break;
case '\'': my_b_write(cache, "\\'", 2); break;
case 0 : my_b_write(cache, "\\0", 2); break;
case '\n': my_b_write(cache, (uchar*)"\\n", 2); break;
case '\r': my_b_write(cache, (uchar*)"\\r", 2); break;
case '\\': my_b_write(cache, (uchar*)"\\\\", 2); break;
case '\b': my_b_write(cache, (uchar*)"\\b", 2); break;
case '\t': my_b_write(cache, (uchar*)"\\t", 2); break;
case '\'': my_b_write(cache, (uchar*)"\\'", 2); break;
case 0 : my_b_write(cache, (uchar*)"\\0", 2); break;
default:
my_b_write_byte(cache, c);
break;
......@@ -755,7 +755,7 @@ static void print_set_option(IO_CACHE* file, uint32 bits_changed,
if (bits_changed & option)
{
if (*need_comma)
my_b_write(file, ", ", 2);
my_b_write(file, (uchar*)", ", 2);
my_b_printf(file, "%s=%d", name, MY_TEST(flags & option));
*need_comma= 1;
}
......@@ -1797,7 +1797,7 @@ static void hexdump_minimal_header_to_io_cache(IO_CACHE *file,
DBUG_ASSERT(static_cast<size_t>(emit_buf_written) < sizeof(emit_buf));
my_b_write(file, reinterpret_cast<uchar*>(emit_buf), emit_buf_written);
my_b_write(file, "#\n", 2);
my_b_write(file, (uchar*)"#\n", 2);
}
......@@ -1913,7 +1913,7 @@ static void hexdump_data_to_io_cache(IO_CACHE *file,
my_b_write(file, reinterpret_cast<uchar*>(emit_buffer),
c - emit_buffer);
}
my_b_write(file, "#\n", 2);
my_b_write(file, (uchar*)"#\n", 2);
}
/*
......@@ -1970,7 +1970,7 @@ void Log_event::print_header(IO_CACHE* file,
Prefix the next line so that the output from print_helper()
will appear as a comment.
*/
my_b_write(file, "# Event: ", 9);
my_b_write(file, (uchar*)"# Event: ", 9);
}
DBUG_VOID_RETURN;
}
......@@ -1996,9 +1996,9 @@ my_b_write_quoted(IO_CACHE *file, const uchar *ptr, uint length)
if (*s > 0x1F)
my_b_write_byte(file, *s);
else if (*s == '\'')
my_b_write(file, "\\'", 2);
my_b_write(file, (uchar*)"\\'", 2);
else if (*s == '\\')
my_b_write(file, "\\\\", 2);
my_b_write(file, (uchar*)"\\\\", 2);
else
{
uchar hex[10];
......@@ -2021,7 +2021,7 @@ static void
my_b_write_bit(IO_CACHE *file, const uchar *ptr, uint nbits)
{
uint bitnum, nbits8= ((nbits + 7) / 8) * 8, skip_bits= nbits8 - nbits;
my_b_write(file, "b'", 2);
my_b_write(file, (uchar*)"b'", 2);
for (bitnum= skip_bits ; bitnum < nbits8; bitnum++)
{
int is_set= (ptr[(bitnum) / 8] >> (7 - bitnum % 8)) & 0x01;
......@@ -2158,7 +2158,7 @@ log_event_print_value(IO_CACHE *file, const uchar *ptr,
size_t length;
longlong si= sint8korr(ptr);
length= (longlong10_to_str(si, tmp, -10) - tmp);
my_b_write(file, tmp, length);
my_b_write(file, (uchar*)tmp, length);
if (si < 0)
{
ulonglong ui= uint8korr(ptr);
......@@ -2187,7 +2187,7 @@ log_event_print_value(IO_CACHE *file, const uchar *ptr,
pos+= sprintf(pos, "%09d.", dec.buf[i]);
pos+= sprintf(pos, "%09d", dec.buf[i]);
length= (uint) (pos - buff);
my_b_write(file, buff, length);
my_b_write(file, (uchar*)buff, length);
my_snprintf(typestr, typestr_length, "DECIMAL(%d,%d)",
precision, decimals);
return bin_size;
......@@ -2239,7 +2239,7 @@ log_event_print_value(IO_CACHE *file, const uchar *ptr,
struct timeval tm;
my_timestamp_from_binary(&tm, ptr, meta);
int buflen= my_timeval_to_str(&tm, buf, meta);
my_b_write(file, buf, buflen);
my_b_write(file, (uchar*)buf, buflen);
my_snprintf(typestr, typestr_length, "TIMESTAMP(%d)", meta);
return my_timestamp_binary_length(meta);
}
......@@ -2477,7 +2477,7 @@ Rows_log_event::print_verbose_one_row(IO_CACHE *file, table_def *td,
if (print_event_info->verbose > 1)
{
my_b_write(file, " /* ", 4);
my_b_write(file, (uchar*)" /* ", 4);
if (typestr[0])
my_b_printf(file, "%s ", typestr);
......@@ -2487,7 +2487,7 @@ Rows_log_event::print_verbose_one_row(IO_CACHE *file, table_def *td,
my_b_printf(file, "meta=%d nullable=%d is_null=%d ",
td->field_metadata(i),
td->maybe_null(i), is_null);
my_b_write(file, "*/", 2);
my_b_write(file, (uchar*)"*/", 2);
}
my_b_write_byte(file, '\n');
......
......@@ -294,7 +294,7 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name,
if (my_b_append(&file, (const uchar *)STRING_WITH_LEN("TYPE=")) ||
my_b_append(&file, (const uchar *)type->str, type->length) ||
my_b_append(&file, (const uchar *)STRING_WITH_LEN("\n")))
goto err_w_file;
goto err_w_cache;
// write parameters to temporary file
for (param= parameters; param->name.str; param++)
......
......@@ -42,6 +42,8 @@
#include "sql_derived.h"
#include "sql_show.h"
extern "C" int _my_b_net_read(IO_CACHE *info, uchar *Buffer, size_t Count);
class XML_TAG {
public:
int level;
......
......@@ -53,7 +53,7 @@ int unique_write_to_file(uchar* key, element_count count, Unique *unique)
int unique_write_to_file_with_count(uchar* key, element_count count, Unique *unique)
{
return my_b_write(&unique->file, key, unique->size) ||
my_b_write(&unique->file, &count, sizeof(element_count)) ? 1 : 0;
my_b_write(&unique->file, (uchar*)&count, sizeof(element_count)) ? 1 : 0;
}
int unique_write_to_ptrs(uchar* key, element_count count, Unique *unique)
......@@ -694,7 +694,6 @@ bool Unique::merge(TABLE *table, uchar *buff, bool without_last_merge)
open_cached_file(outfile,mysql_tmpdir,TEMP_PREFIX,READ_RECORD_BUFFER,
MYF(MY_WME))))
return 1;
reinit_io_cache(outfile,WRITE_CACHE,0L,0,0);
Sort_param sort_param;
bzero((char*) &sort_param,sizeof(sort_param));
......
......@@ -458,7 +458,7 @@ void wsrep_dump_rbr_buf_with_header(THD *thd, const void *rbr_buf,
goto cleanup2;
}
if (ev->write(&cache) || my_b_write(&cache, rbr_buf, buf_len) ||
if (ev->write(&cache) || my_b_write(&cache, (uchar*)rbr_buf, buf_len) ||
flush_io_cache(&cache))
{
WSREP_ERROR("Failed to write to '%s'.", filename);
......
......@@ -81,7 +81,7 @@ my_bool _ma_read_cache(MARIA_HA *handler, IO_CACHE *info, uchar *buff,
}
else
info->read_pos=info->read_end; /* All block used */
if (!(*info->read_function)(info,buff,length))
if (!_my_b_read(info,buff,length))
DBUG_RETURN(0);
read_length=info->error;
}
......
......@@ -4021,8 +4021,9 @@ int maria_repair_by_sort(HA_CHECK *param, register MARIA_HA *info,
share->state.state.data_file_length=sort_param.max_pos;
param->read_cache.file= info->dfile.file; /* re-init read cache */
reinit_io_cache(&param->read_cache,READ_CACHE,share->pack.header_length,
1,1);
if (share->data_file_type != BLOCK_RECORD)
reinit_io_cache(&param->read_cache, READ_CACHE,
share->pack.header_length, 1, 1);
}
if (param->testflag & T_WRITE_LOOP)
......
......@@ -82,7 +82,7 @@ int _mi_read_cache(IO_CACHE *info, uchar *buff, my_off_t pos, uint length,
}
else
info->read_pos=info->read_end; /* All block used */
if (!(*info->read_function)(info,buff,length))
if (!_my_b_read(info,buff,length))
DBUG_RETURN(0);
read_length=info->error;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment