Skip to content

Commit

Permalink
MDEV-15215 main.partition_explicit_prune fails in bulidbot with asser…
Browse files Browse the repository at this point in the history
…tion failures and server crashes.

        ha_partition::get_open_file_sample() implemented to be used
        when we need a file sample that is surely opened.
  • Loading branch information
Alexey Botchkov committed Feb 13, 2018
1 parent 3c87973 commit ba125ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
46 changes: 23 additions & 23 deletions sql/ha_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ void ha_partition::init_handler_variables()
my_bitmap_clear(&m_key_not_found_partitions);
my_bitmap_clear(&m_mrr_used_partitions);
my_bitmap_clear(&m_opened_partitions);
m_file_sample= NULL;

#ifdef DONT_HAVE_TO_BE_INITALIZED
m_start_key.flag= 0;
Expand Down Expand Up @@ -3408,6 +3409,8 @@ bool ha_partition::init_partition_bitmaps()
if (my_bitmap_init(&m_opened_partitions, NULL, m_tot_parts, FALSE))
DBUG_RETURN(true);

m_file_sample= NULL;

/* Initialize the bitmap for read/lock_partitions */
if (!m_is_clone_of)
{
Expand Down Expand Up @@ -3445,7 +3448,6 @@ bool ha_partition::init_partition_bitmaps()
int ha_partition::open(const char *name, int mode, uint test_if_locked)
{
int error= HA_ERR_INITIALIZATION;
handler *file_sample= NULL;
handler **file;
char name_buff[FN_REFLEN + 1];
ulonglong check_table_flags;
Expand Down Expand Up @@ -3538,18 +3540,17 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)
file= &m_file[i];
goto err_handler;
}
if (!file_sample)
file_sample= m_file[i];
if (!m_file_sample)
m_file_sample= m_file[i];
name_buffer_ptr+= strlen(name_buffer_ptr) + 1;
bitmap_set_bit(&m_opened_partitions, i);
}
}
else
{
if ((error= open_read_partitions(name_buff, sizeof(name_buff),
&file_sample)))
if ((error= open_read_partitions(name_buff, sizeof(name_buff))))
goto err_handler;
m_num_locks= file_sample->lock_count();
m_num_locks= m_file_sample->lock_count();
}
/*
We want to know the upper bound for locks, to allocate enough memory.
Expand All @@ -3560,8 +3561,8 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)
m_num_locks*= m_tot_parts;

file= m_file;
ref_length= file_sample->ref_length;
check_table_flags= ((file_sample->ha_table_flags() &
ref_length= get_open_file_sample()->ref_length;
check_table_flags= ((get_open_file_sample()->ha_table_flags() &
~(PARTITION_DISABLED_TABLE_FLAGS)) |
(PARTITION_ENABLED_TABLE_FLAGS));
while (*(++file))
Expand All @@ -3584,8 +3585,8 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)
goto err_handler;
}
}
key_used_on_scan= file_sample->key_used_on_scan;
implicit_emptied= file_sample->implicit_emptied;
key_used_on_scan= get_open_file_sample()->key_used_on_scan;
implicit_emptied= get_open_file_sample()->implicit_emptied;
/*
Add 2 bytes for partition id in position ref length.
ref_length=max_in_all_partitions(ref_length) + PARTITION_BYTES_IN_POS
Expand Down Expand Up @@ -5223,7 +5224,7 @@ bool ha_partition::init_record_priority_queue()
/* Allocate record buffer for each used partition. */
m_priority_queue_rec_len= m_rec_length + PARTITION_BYTES_IN_POS;
if (!m_using_extended_keys)
m_priority_queue_rec_len += m_file[0]->ref_length;
m_priority_queue_rec_len += get_open_file_sample()->ref_length;
alloc_len= used_parts * m_priority_queue_rec_len;
/* Allocate a key for temporary use when setting up the scan. */
alloc_len+= table_share->max_key_length;
Expand Down Expand Up @@ -6481,7 +6482,8 @@ int ha_partition::multi_range_read_explain_info(uint mrr_mode, char *str,
size_t size)
{
DBUG_ENTER("ha_partition::multi_range_read_explain_info");
DBUG_RETURN(m_file[0]->multi_range_read_explain_info(mrr_mode, str, size));
DBUG_RETURN(get_open_file_sample()->
multi_range_read_explain_info(mrr_mode, str, size));
}


Expand Down Expand Up @@ -8354,16 +8356,15 @@ void ha_partition::set_partitions_to_open(List<String> *partition_names)
}


int ha_partition::open_read_partitions(char *name_buff, size_t name_buff_size,
handler **sample)
int ha_partition::open_read_partitions(char *name_buff, size_t name_buff_size)
{
handler **file;
char *name_buffer_ptr;
int error;

name_buffer_ptr= m_name_buffer_ptr;
file= m_file;
*sample= NULL;
m_file_sample= NULL;
do
{
int n_file= (int)(file-m_file);
Expand All @@ -8390,10 +8391,10 @@ int ha_partition::open_read_partitions(char *name_buff, size_t name_buff_size,
table->s->connect_string= save_connect_string;
if (error)
goto err_handler;
if (!(*sample))
*sample= *file;
bitmap_set_bit(&m_opened_partitions, n_file);
}
if (!m_file_sample && should_be_open)
m_file_sample= *file;
name_buffer_ptr+= strlen(name_buffer_ptr) + 1;
} while (*(++file));

Expand All @@ -8406,7 +8407,6 @@ int ha_partition::change_partitions_to_open(List<String> *partition_names)
{
char name_buff[FN_REFLEN+1];
int error= 0;
handler *sample;

if (m_is_clone_of)
return 0;
Expand All @@ -8428,7 +8428,7 @@ int ha_partition::change_partitions_to_open(List<String> *partition_names)
return 0;

if ((error= read_par_file(table->s->normalized_path.str)) ||
(error= open_read_partitions(name_buff, sizeof(name_buff), &sample)))
(error= open_read_partitions(name_buff, sizeof(name_buff))))
goto err_handler;

clear_handler_file();
Expand Down Expand Up @@ -9150,7 +9150,7 @@ void ha_partition::late_extra_no_cache(uint partition_id)
const key_map *ha_partition::keys_to_use_for_scanning()
{
DBUG_ENTER("ha_partition::keys_to_use_for_scanning");
DBUG_RETURN(m_file[0]->keys_to_use_for_scanning());
DBUG_RETURN(get_open_file_sample()->keys_to_use_for_scanning());
}


Expand Down Expand Up @@ -9373,7 +9373,7 @@ double ha_partition::read_time(uint index, uint ranges, ha_rows rows)
{
DBUG_ENTER("ha_partition::read_time");

DBUG_RETURN(m_file[0]->read_time(index, ranges, rows));
DBUG_RETURN(get_open_file_sample()->read_time(index, ranges, rows));
}


Expand Down Expand Up @@ -10181,8 +10181,8 @@ int ha_partition::cmp_ref(const uchar *ref1, const uchar *ref2)
uint32 diff1, diff2;
DBUG_ENTER("ha_partition::cmp_ref");

cmp= m_file[0]->cmp_ref((ref1 + PARTITION_BYTES_IN_POS),
(ref2 + PARTITION_BYTES_IN_POS));
cmp= get_open_file_sample()->cmp_ref((ref1 + PARTITION_BYTES_IN_POS),
(ref2 + PARTITION_BYTES_IN_POS));
if (cmp)
DBUG_RETURN(cmp);

Expand Down
7 changes: 5 additions & 2 deletions sql/ha_partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ class ha_partition :public handler
bool m_key_not_found;
List<String> *m_partitions_to_open;
MY_BITMAP m_opened_partitions;
/** This is one of the m_file-s that it guaranteed to be opened. */
/** It is set in open_read_partitions() */
handler *m_file_sample;
public:
handler **get_child_handlers()
{
Expand Down Expand Up @@ -840,8 +843,7 @@ class ha_partition :public handler
uint part_id);
void set_partitions_to_open(List<String> *partition_names);
int change_partitions_to_open(List<String> *partition_names);
int open_read_partitions(char *name_buff, size_t name_buff_size,
handler **sample);
int open_read_partitions(char *name_buff, size_t name_buff_size);
virtual int extra(enum ha_extra_function operation);
virtual int extra_opt(enum ha_extra_function operation, ulong cachesize);
virtual int reset(void);
Expand All @@ -868,6 +870,7 @@ class ha_partition :public handler
void late_extra_cache(uint partition_id);
void late_extra_no_cache(uint partition_id);
void prepare_extra_cache(uint cachesize);
handler *get_open_file_sample() const { return m_file_sample; }
public:

/*
Expand Down

0 comments on commit ba125ec

Please sign in to comment.