mirror of
https://github.com/MariaDB/server.git
synced 2025-01-27 01:04:19 +01:00
alloc_on_stack: simplify the API
This commit is contained in:
parent
6c50875a38
commit
2e665fb294
14 changed files with 162 additions and 283 deletions
|
@ -18,10 +18,10 @@
|
||||||
#define _my_stack_alloc_h
|
#define _my_stack_alloc_h
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Do allocation trough alloca if there is enough stack available.
|
Do allocation through alloca if there is enough stack available.
|
||||||
If not, use my_malloc() instead.
|
If not, use my_malloc() instead.
|
||||||
|
|
||||||
The idea is that to be able to alloc as much as possible trough the
|
The idea is that to be able to alloc as much as possible through the
|
||||||
stack. To ensure this, we have two different limits, on for big
|
stack. To ensure this, we have two different limits, on for big
|
||||||
blocks and one for small blocks. This will enable us to continue to
|
blocks and one for small blocks. This will enable us to continue to
|
||||||
do allocation for small blocks even when there is less stack space
|
do allocation for small blocks even when there is less stack space
|
||||||
|
@ -42,47 +42,25 @@
|
||||||
/* Allocate small blocks as long as there is this much left */
|
/* Allocate small blocks as long as there is this much left */
|
||||||
#define STACK_ALLOC_SMALL_BLOCK 1024*32
|
#define STACK_ALLOC_SMALL_BLOCK 1024*32
|
||||||
|
|
||||||
struct st_stack_alloc
|
/* Allocate small blocks as long as there is this much left */
|
||||||
{
|
#define STACK_ALLOC_SMALL_BLOCK_SIZE 4096
|
||||||
void **stack_ends_here; /* Set on init */
|
|
||||||
size_t stack_for_big_blocks;
|
|
||||||
size_t stack_for_small_blocks;
|
|
||||||
size_t small_block_size;
|
|
||||||
};
|
|
||||||
typedef struct st_stack_alloc STACK_ALLOC;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Initialize STACK_ALLOC structure
|
Allocate a block on stack or through malloc.
|
||||||
*/
|
|
||||||
|
|
||||||
static inline void init_stack_alloc(STACK_ALLOC *alloc,
|
|
||||||
size_t stack_for_big_blocks,
|
|
||||||
size_t stack_for_small_blocks,
|
|
||||||
size_t small_block_size)
|
|
||||||
{
|
|
||||||
alloc->stack_ends_here= &my_thread_var->stack_ends_here;
|
|
||||||
alloc->stack_for_big_blocks= stack_for_big_blocks;
|
|
||||||
alloc->stack_for_small_blocks= stack_for_small_blocks;
|
|
||||||
alloc->small_block_size= small_block_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Allocate a block on stack or trough malloc.
|
|
||||||
The 'must_be_freed' variable will be set to 1 if malloc was called.
|
The 'must_be_freed' variable will be set to 1 if malloc was called.
|
||||||
'must_be_freed' must be a variable on the stack!
|
'must_be_freed' must be a variable on the stack!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_ALLOCA
|
#ifdef HAVE_ALLOCA
|
||||||
#define alloc_on_stack(alloc, res, must_be_freed, size) \
|
#define alloc_on_stack(stack_end, res, must_be_freed, size) \
|
||||||
|
do \
|
||||||
{ \
|
{ \
|
||||||
size_t stack_left= available_stack_size(&(must_be_freed), \
|
size_t alloc_size= (size); \
|
||||||
*(alloc)->stack_ends_here); \
|
size_t stack_left= available_stack_size(&alloc_size, (stack_end)); \
|
||||||
if (stack_left > (size_t) (size) && \
|
if (stack_left > alloc_size && \
|
||||||
((alloc)->stack_for_big_blocks < stack_left - (size) || \
|
(STACK_ALLOC_BIG_BLOCK < stack_left - alloc_size || \
|
||||||
(((alloc)->stack_for_small_blocks < stack_left - (size)) && \
|
((STACK_ALLOC_SMALL_BLOCK < stack_left - alloc_size) && \
|
||||||
((alloc)->small_block_size <= (size_t) (size))))) \
|
(STACK_ALLOC_SMALL_BLOCK_SIZE <= alloc_size)))) \
|
||||||
{ \
|
{ \
|
||||||
(must_be_freed)= 0; \
|
(must_be_freed)= 0; \
|
||||||
(res)= alloca(size); \
|
(res)= alloca(size); \
|
||||||
|
@ -92,13 +70,13 @@ static inline void init_stack_alloc(STACK_ALLOC *alloc,
|
||||||
(must_be_freed)= 1; \
|
(must_be_freed)= 1; \
|
||||||
(res)= my_malloc(size, MYF(MY_THREAD_SPECIFIC | MY_WME)); \
|
(res)= my_malloc(size, MYF(MY_THREAD_SPECIFIC | MY_WME)); \
|
||||||
} \
|
} \
|
||||||
}
|
} while(0)
|
||||||
#else
|
#else
|
||||||
#define alloc_on_stack(alloc, res, must_be_freed, size) \
|
#define alloc_on_stack(stack_end, res, must_be_freed, size) \
|
||||||
{ \
|
do { \
|
||||||
(must_be_freed)= 1; \
|
(must_be_freed)= 1; \
|
||||||
(res)= my_malloc(size, MYF(MY_THREAD_SPECIFIC | MY_WME)); \
|
(res)= my_malloc(size, MYF(MY_THREAD_SPECIFIC | MY_WME)); \
|
||||||
}
|
} while(0)
|
||||||
#endif /* HAVE_ALLOCA */
|
#endif /* HAVE_ALLOCA */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ typedef struct st_handler_check_param
|
||||||
my_bool retry_repair, force_sort, calc_checksum, static_row_size;
|
my_bool retry_repair, force_sort, calc_checksum, static_row_size;
|
||||||
char temp_filename[FN_REFLEN];
|
char temp_filename[FN_REFLEN];
|
||||||
IO_CACHE read_cache;
|
IO_CACHE read_cache;
|
||||||
STACK_ALLOC stack_alloc;
|
void **stack_end_ptr;
|
||||||
enum_handler_stats_method stats_method;
|
enum_handler_stats_method stats_method;
|
||||||
/* For reporting progress */
|
/* For reporting progress */
|
||||||
uint stage, max_stage;
|
uint stage, max_stage;
|
||||||
|
|
|
@ -2804,7 +2804,7 @@ int ha_maria::external_lock(THD *thd, int lock_type)
|
||||||
file->state= &file->s->state.state; // Restore state if clone
|
file->state= &file->s->state.state; // Restore state if clone
|
||||||
|
|
||||||
/* Remember stack end for this thread */
|
/* Remember stack end for this thread */
|
||||||
aria_init_stack_alloc(file);
|
file->stack_end_ptr= &ha_thd()->mysys_var->stack_ends_here;
|
||||||
DBUG_RETURN(result);
|
DBUG_RETURN(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2458,16 +2458,13 @@ static my_bool free_full_pages(MARIA_HA *info, MARIA_ROW *row)
|
||||||
/* Compact events by removing filler and tail events */
|
/* Compact events by removing filler and tail events */
|
||||||
uchar *new_block= 0;
|
uchar *new_block= 0;
|
||||||
uchar *end, *to, *compact_extent_info;
|
uchar *end, *to, *compact_extent_info;
|
||||||
my_bool result, buff_alloced;
|
my_bool res, buff_alloced;
|
||||||
uint extents_count;
|
uint extents_count;
|
||||||
|
|
||||||
{
|
alloc_on_stack(*info->stack_end_ptr, compact_extent_info, buff_alloced,
|
||||||
void *res;
|
row->extents_count * ROW_EXTENT_SIZE);
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
if (!compact_extent_info)
|
||||||
row->extents_count * ROW_EXTENT_SIZE);
|
DBUG_RETURN(1);
|
||||||
if (!(compact_extent_info= res))
|
|
||||||
DBUG_RETURN(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
to= compact_extent_info;
|
to= compact_extent_info;
|
||||||
for (end= extents + row->extents_count * ROW_EXTENT_SIZE ;
|
for (end= extents + row->extents_count * ROW_EXTENT_SIZE ;
|
||||||
|
@ -2514,14 +2511,14 @@ static my_bool free_full_pages(MARIA_HA *info, MARIA_ROW *row)
|
||||||
log_array[TRANSLOG_INTERNAL_PARTS + 0].length= sizeof(log_data);
|
log_array[TRANSLOG_INTERNAL_PARTS + 0].length= sizeof(log_data);
|
||||||
log_array[TRANSLOG_INTERNAL_PARTS + 1].str= compact_extent_info;
|
log_array[TRANSLOG_INTERNAL_PARTS + 1].str= compact_extent_info;
|
||||||
log_array[TRANSLOG_INTERNAL_PARTS + 1].length= extents_length;
|
log_array[TRANSLOG_INTERNAL_PARTS + 1].length= extents_length;
|
||||||
result= translog_write_record(&lsn, LOGREC_REDO_FREE_BLOCKS, info->trn,
|
res= translog_write_record(&lsn, LOGREC_REDO_FREE_BLOCKS, info->trn,
|
||||||
info,
|
info,
|
||||||
(translog_size_t) (sizeof(log_data) +
|
(translog_size_t) (sizeof(log_data) +
|
||||||
extents_length),
|
extents_length),
|
||||||
TRANSLOG_INTERNAL_PARTS + 2, log_array,
|
TRANSLOG_INTERNAL_PARTS + 2, log_array,
|
||||||
log_data, NULL);
|
log_data, NULL);
|
||||||
stack_alloc_free(compact_extent_info, buff_alloced);
|
stack_alloc_free(compact_extent_info, buff_alloced);
|
||||||
if (result)
|
if (res)
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5199,13 +5196,10 @@ my_bool _ma_cmp_block_unique(MARIA_HA *info, MARIA_UNIQUEDEF *def,
|
||||||
my_bool buff_alloced;
|
my_bool buff_alloced;
|
||||||
DBUG_ENTER("_ma_cmp_block_unique");
|
DBUG_ENTER("_ma_cmp_block_unique");
|
||||||
|
|
||||||
{
|
alloc_on_stack(*info->stack_end_ptr, old_record, buff_alloced,
|
||||||
void *res;
|
info->s->base.reclength);
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
if (!old_record)
|
||||||
info->s->base.reclength);
|
DBUG_RETURN(1);
|
||||||
if (!(old_record= res))
|
|
||||||
DBUG_RETURN(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Don't let the compare destroy blobs that may be in use */
|
/* Don't let the compare destroy blobs that may be in use */
|
||||||
org_rec_buff= info->rec_buff;
|
org_rec_buff= info->rec_buff;
|
||||||
|
|
|
@ -126,10 +126,7 @@ void maria_chk_init(HA_CHECK *param)
|
||||||
param->pagecache_block_size= KEY_CACHE_BLOCK_SIZE;
|
param->pagecache_block_size= KEY_CACHE_BLOCK_SIZE;
|
||||||
param->stats_method= MI_STATS_METHOD_NULLS_NOT_EQUAL;
|
param->stats_method= MI_STATS_METHOD_NULLS_NOT_EQUAL;
|
||||||
param->max_stage= 1;
|
param->max_stage= 1;
|
||||||
init_stack_alloc(¶m->stack_alloc,
|
param->stack_end_ptr= &my_thread_var->stack_ends_here;
|
||||||
STACK_ALLOC_BIG_BLOCK,
|
|
||||||
STACK_ALLOC_SMALL_BLOCK,
|
|
||||||
4096);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -876,15 +873,12 @@ static int chk_index(HA_CHECK *param, MARIA_HA *info, MARIA_KEYDEF *keyinfo,
|
||||||
if (keyinfo->flag & (HA_SPATIAL | HA_RTREE_INDEX))
|
if (keyinfo->flag & (HA_SPATIAL | HA_RTREE_INDEX))
|
||||||
DBUG_RETURN(0);
|
DBUG_RETURN(0);
|
||||||
|
|
||||||
|
alloc_on_stack(*param->stack_end_ptr, temp_buff, temp_buff_alloced,
|
||||||
|
(keyinfo->block_length + keyinfo->max_store_length));
|
||||||
|
if (!temp_buff)
|
||||||
{
|
{
|
||||||
void *res;
|
_ma_check_print_error(param,"Not enough memory for keyblock");
|
||||||
alloc_on_stack(¶m->stack_alloc, res, temp_buff_alloced,
|
DBUG_RETURN(-1);
|
||||||
(keyinfo->block_length + keyinfo->max_store_length));
|
|
||||||
if (!(temp_buff= res))
|
|
||||||
{
|
|
||||||
_ma_check_print_error(param,"Not enough memory for keyblock");
|
|
||||||
DBUG_RETURN(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
tmp_key_buff= temp_buff+ keyinfo->block_length;
|
tmp_key_buff= temp_buff+ keyinfo->block_length;
|
||||||
|
|
||||||
|
@ -3246,15 +3240,12 @@ static int sort_one_index(HA_CHECK *param, MARIA_HA *info,
|
||||||
param->new_file_pos+=keyinfo->block_length;
|
param->new_file_pos+=keyinfo->block_length;
|
||||||
key.keyinfo= keyinfo;
|
key.keyinfo= keyinfo;
|
||||||
|
|
||||||
|
alloc_on_stack(*param->stack_end_ptr, buff, buff_alloced,
|
||||||
|
keyinfo->block_length + keyinfo->max_store_length);
|
||||||
|
if (!buff)
|
||||||
{
|
{
|
||||||
void *res;
|
_ma_check_print_error(param,"Not enough memory for keyblock");
|
||||||
alloc_on_stack(¶m->stack_alloc, res, buff_alloced,
|
DBUG_RETURN(-1);
|
||||||
keyinfo->block_length + keyinfo->max_store_length);
|
|
||||||
if (!(buff= res))
|
|
||||||
{
|
|
||||||
_ma_check_print_error(param,"Not enough memory for keyblock");
|
|
||||||
DBUG_RETURN(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
key.data= buff + keyinfo->block_length;
|
key.data= buff + keyinfo->block_length;
|
||||||
|
|
||||||
|
|
|
@ -166,13 +166,11 @@ my_bool _ma_ck_delete(MARIA_HA *info, MARIA_KEY *key)
|
||||||
DBUG_ENTER("_ma_ck_delete");
|
DBUG_ENTER("_ma_ck_delete");
|
||||||
|
|
||||||
LINT_INIT_STRUCT(org_key);
|
LINT_INIT_STRUCT(org_key);
|
||||||
{
|
|
||||||
void *res;
|
alloc_on_stack(*info->stack_end_ptr, key_buff, buff_alloced,
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
key->keyinfo->max_store_length);
|
||||||
key->keyinfo->max_store_length);
|
if (!key_buff)
|
||||||
if (!(key_buff= res))
|
DBUG_RETURN(1);
|
||||||
DBUG_RETURN(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
save_key_data= key->data;
|
save_key_data= key->data;
|
||||||
if (share->now_transactional)
|
if (share->now_transactional)
|
||||||
|
@ -221,13 +219,10 @@ my_bool _ma_ck_real_delete(register MARIA_HA *info, MARIA_KEY *key,
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
alloc_on_stack(*info->stack_end_ptr, root_buff, buff_alloced,
|
||||||
void *res;
|
(keyinfo->block_length + keyinfo->max_store_length*2));
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
if (!root_buff)
|
||||||
(keyinfo->block_length + keyinfo->max_store_length*2));
|
DBUG_RETURN(1);
|
||||||
if (!(root_buff= res))
|
|
||||||
DBUG_RETURN(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
DBUG_PRINT("info",("root_page: %lu",
|
DBUG_PRINT("info",("root_page: %lu",
|
||||||
(ulong) (old_root / keyinfo->block_length)));
|
(ulong) (old_root / keyinfo->block_length)));
|
||||||
|
@ -305,13 +300,10 @@ static int d_search(MARIA_HA *info, MARIA_KEY *key, uint32 comp_flag,
|
||||||
DBUG_ENTER("d_search");
|
DBUG_ENTER("d_search");
|
||||||
DBUG_DUMP("page", anc_page->buff, anc_page->size);
|
DBUG_DUMP("page", anc_page->buff, anc_page->size);
|
||||||
|
|
||||||
{
|
alloc_on_stack(*info->stack_end_ptr, lastkey, lastkey_alloced,
|
||||||
void *res;
|
keyinfo->max_store_length);
|
||||||
alloc_on_stack(&info->stack_alloc, res, lastkey_alloced,
|
if (!lastkey)
|
||||||
keyinfo->max_store_length);
|
DBUG_RETURN(1);
|
||||||
if (!(lastkey= res))
|
|
||||||
DBUG_RETURN(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
flag=(*keyinfo->bin_search)(key, anc_page, comp_flag, &keypos, lastkey,
|
flag=(*keyinfo->bin_search)(key, anc_page, comp_flag, &keypos, lastkey,
|
||||||
&last_key);
|
&last_key);
|
||||||
|
@ -406,13 +398,11 @@ static int d_search(MARIA_HA *info, MARIA_KEY *key, uint32 comp_flag,
|
||||||
/* Read left child page */
|
/* Read left child page */
|
||||||
leaf_page.pos= _ma_kpos(nod_flag,keypos);
|
leaf_page.pos= _ma_kpos(nod_flag,keypos);
|
||||||
|
|
||||||
{
|
alloc_on_stack(*info->stack_end_ptr, leaf_buff, buff_alloced,
|
||||||
void *res;
|
(keyinfo->block_length + keyinfo->max_store_length*2));
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
if (!leaf_buff)
|
||||||
(keyinfo->block_length + keyinfo->max_store_length*2));
|
goto err;
|
||||||
if (!(leaf_buff= res))
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
if (_ma_fetch_keypage(&leaf_page, info,keyinfo, leaf_page.pos,
|
if (_ma_fetch_keypage(&leaf_page, info,keyinfo, leaf_page.pos,
|
||||||
PAGECACHE_LOCK_WRITE, DFLT_INIT_HITS, leaf_buff,
|
PAGECACHE_LOCK_WRITE, DFLT_INIT_HITS, leaf_buff,
|
||||||
0))
|
0))
|
||||||
|
@ -590,13 +580,10 @@ static int del(MARIA_HA *info, MARIA_KEY *key,
|
||||||
keypos));
|
keypos));
|
||||||
DBUG_DUMP("leaf_buff", leaf_page->buff, leaf_page->size);
|
DBUG_DUMP("leaf_buff", leaf_page->buff, leaf_page->size);
|
||||||
|
|
||||||
{
|
alloc_on_stack(*info->stack_end_ptr, keybuff, keybuff_alloced,
|
||||||
void *res;
|
keyinfo->max_store_length);
|
||||||
alloc_on_stack(&info->stack_alloc, res, keybuff_alloced,
|
if (!keybuff)
|
||||||
keyinfo->max_store_length);
|
DBUG_RETURN(1);
|
||||||
if (!(keybuff= res))
|
|
||||||
DBUG_RETURN(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
page_flag= leaf_page->flag;
|
page_flag= leaf_page->flag;
|
||||||
leaf_length= leaf_page->size;
|
leaf_length= leaf_page->size;
|
||||||
|
@ -614,13 +601,10 @@ static int del(MARIA_HA *info, MARIA_KEY *key,
|
||||||
{
|
{
|
||||||
next_page.pos= _ma_kpos(nod_flag,endpos);
|
next_page.pos= _ma_kpos(nod_flag,endpos);
|
||||||
|
|
||||||
{
|
alloc_on_stack(*info->stack_end_ptr, next_buff, buff_alloced,
|
||||||
void *res;
|
(keyinfo->block_length + keyinfo->max_store_length*2));
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
if (!next_buff)
|
||||||
(keyinfo->block_length + keyinfo->max_store_length*2));
|
goto err;
|
||||||
if (!(next_buff= res))
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_ma_fetch_keypage(&next_page, info, keyinfo, next_page.pos,
|
if (_ma_fetch_keypage(&next_page, info, keyinfo, next_page.pos,
|
||||||
PAGECACHE_LOCK_WRITE, DFLT_INIT_HITS, next_buff, 0))
|
PAGECACHE_LOCK_WRITE, DFLT_INIT_HITS, next_buff, 0))
|
||||||
|
@ -820,14 +804,12 @@ static int underflow(MARIA_HA *info, MARIA_KEYDEF *keyinfo,
|
||||||
DBUG_DUMP("anc_buff", anc_page->buff, anc_page->size);
|
DBUG_DUMP("anc_buff", anc_page->buff, anc_page->size);
|
||||||
DBUG_DUMP("leaf_buff", leaf_page->buff, leaf_page->size);
|
DBUG_DUMP("leaf_buff", leaf_page->buff, leaf_page->size);
|
||||||
|
|
||||||
{
|
alloc_on_stack(*info->stack_end_ptr, anc_key_buff, buff_alloced,
|
||||||
void *res;
|
keyinfo->max_store_length*2);
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
if (!anc_key_buff)
|
||||||
keyinfo->max_store_length*2);
|
DBUG_RETURN(1);
|
||||||
if (!(anc_key_buff= res))
|
|
||||||
DBUG_RETURN(1);
|
leaf_key_buff= anc_key_buff+ keyinfo->max_store_length;
|
||||||
leaf_key_buff= anc_key_buff+ keyinfo->max_store_length;
|
|
||||||
}
|
|
||||||
|
|
||||||
anc_page_flag= anc_page->flag;
|
anc_page_flag= anc_page->flag;
|
||||||
anc_buff= anc_page->buff;
|
anc_buff= anc_page->buff;
|
||||||
|
|
|
@ -256,14 +256,11 @@ my_bool _ma_write_blob_record(MARIA_HA *info, const uchar *record)
|
||||||
reclength= (info->s->base.pack_reclength +
|
reclength= (info->s->base.pack_reclength +
|
||||||
_ma_calc_total_blob_length(info,record)+ extra);
|
_ma_calc_total_blob_length(info,record)+ extra);
|
||||||
|
|
||||||
|
alloc_on_stack(*info->stack_end_ptr, rec_buff, buff_alloced, reclength);
|
||||||
|
if (!rec_buff)
|
||||||
{
|
{
|
||||||
void *res;
|
my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced, reclength);
|
return(1);
|
||||||
if (!(rec_buff= res))
|
|
||||||
{
|
|
||||||
my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reclength2= _ma_rec_pack(info,
|
reclength2= _ma_rec_pack(info,
|
||||||
|
@ -308,15 +305,13 @@ my_bool _ma_update_blob_record(MARIA_HA *info, MARIA_RECORD_POS pos,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
alloc_on_stack(*info->stack_end_ptr, rec_buff, buff_alloced, reclength);
|
||||||
|
if (!rec_buff)
|
||||||
{
|
{
|
||||||
void *res;
|
my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced, reclength);
|
return(1);
|
||||||
if (!(rec_buff= res))
|
|
||||||
{
|
|
||||||
my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reclength2= _ma_rec_pack(info, rec_buff+
|
reclength2= _ma_rec_pack(info, rec_buff+
|
||||||
ALIGN_SIZE(MARIA_MAX_DYN_BLOCK_HEADER),
|
ALIGN_SIZE(MARIA_MAX_DYN_BLOCK_HEADER),
|
||||||
record);
|
record);
|
||||||
|
@ -1595,13 +1590,10 @@ my_bool _ma_cmp_dynamic_unique(MARIA_HA *info, MARIA_UNIQUEDEF *def,
|
||||||
my_bool error, buff_alloced;
|
my_bool error, buff_alloced;
|
||||||
DBUG_ENTER("_ma_cmp_dynamic_unique");
|
DBUG_ENTER("_ma_cmp_dynamic_unique");
|
||||||
|
|
||||||
{
|
alloc_on_stack(*info->stack_end_ptr, old_record, buff_alloced,
|
||||||
void *res;
|
info->s->base.reclength);
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
if (!old_record)
|
||||||
info->s->base.reclength);
|
DBUG_RETURN(1);
|
||||||
if (!(old_record= res))
|
|
||||||
DBUG_RETURN(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Don't let the compare destroy blobs that may be in use */
|
/* Don't let the compare destroy blobs that may be in use */
|
||||||
old_rec_buff= info->rec_buff;
|
old_rec_buff= info->rec_buff;
|
||||||
|
@ -1657,12 +1649,9 @@ my_bool _ma_cmp_dynamic_record(register MARIA_HA *info,
|
||||||
buffer_length= (info->s->base.pack_reclength +
|
buffer_length= (info->s->base.pack_reclength +
|
||||||
_ma_calc_total_blob_length(info,record));
|
_ma_calc_total_blob_length(info,record));
|
||||||
|
|
||||||
{
|
alloc_on_stack(*info->stack_end_ptr, buffer, buff_alloced, buffer_length);
|
||||||
void *res;
|
if (!buffer)
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced, buffer_length);
|
DBUG_RETURN(1);
|
||||||
if (!(buffer= res))
|
|
||||||
DBUG_RETURN(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!(reclength= _ma_rec_pack(info,buffer,record)))
|
if (!(reclength= _ma_rec_pack(info,buffer,record)))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
|
@ -1176,7 +1176,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags,
|
||||||
mysql_mutex_unlock(&THR_LOCK_maria);
|
mysql_mutex_unlock(&THR_LOCK_maria);
|
||||||
|
|
||||||
m_info->open_flags= open_flags;
|
m_info->open_flags= open_flags;
|
||||||
aria_init_stack_alloc(m_info);
|
m_info->stack_end_ptr= &my_thread_var->stack_ends_here;
|
||||||
DBUG_PRINT("exit", ("table: %p name: %s",m_info, name));
|
DBUG_PRINT("exit", ("table: %p name: %s",m_info, name));
|
||||||
DBUG_RETURN(m_info);
|
DBUG_RETURN(m_info);
|
||||||
|
|
||||||
|
|
|
@ -68,15 +68,12 @@ static int maria_rtree_find_req(MARIA_HA *info, MARIA_KEYDEF *keyinfo,
|
||||||
MARIA_PAGE page;
|
MARIA_PAGE page;
|
||||||
my_bool buff_alloced;
|
my_bool buff_alloced;
|
||||||
|
|
||||||
|
alloc_on_stack(*info->stack_end_ptr, page_buf, buff_alloced,
|
||||||
|
keyinfo->block_length);
|
||||||
|
if (!page_buf)
|
||||||
{
|
{
|
||||||
void *res;
|
my_errno= HA_ERR_OUT_OF_MEM;
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
return(-1);
|
||||||
keyinfo->block_length);
|
|
||||||
if (!(page_buf= res))
|
|
||||||
{
|
|
||||||
my_errno= HA_ERR_OUT_OF_MEM;
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_ma_fetch_keypage(&page, info, keyinfo, page_pos,
|
if (_ma_fetch_keypage(&page, info, keyinfo, page_pos,
|
||||||
|
@ -339,15 +336,12 @@ static int maria_rtree_get_req(MARIA_HA *info, MARIA_KEYDEF *keyinfo,
|
||||||
my_bool buff_alloced;
|
my_bool buff_alloced;
|
||||||
MARIA_PAGE page;
|
MARIA_PAGE page;
|
||||||
|
|
||||||
|
alloc_on_stack(*info->stack_end_ptr, page_buf, buff_alloced,
|
||||||
|
keyinfo->block_length);
|
||||||
|
if (!page_buf)
|
||||||
{
|
{
|
||||||
void *res;
|
my_errno= HA_ERR_OUT_OF_MEM;
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
return(-1);
|
||||||
keyinfo->block_length);
|
|
||||||
if (!(page_buf= res))
|
|
||||||
{
|
|
||||||
my_errno= HA_ERR_OUT_OF_MEM;
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_ma_fetch_keypage(&page, info, keyinfo, page_pos,
|
if (_ma_fetch_keypage(&page, info, keyinfo, page_pos,
|
||||||
|
@ -627,15 +621,12 @@ static int maria_rtree_insert_req(MARIA_HA *info, MARIA_KEY *key,
|
||||||
MARIA_PAGE page;
|
MARIA_PAGE page;
|
||||||
DBUG_ENTER("maria_rtree_insert_req");
|
DBUG_ENTER("maria_rtree_insert_req");
|
||||||
|
|
||||||
|
alloc_on_stack(*info->stack_end_ptr, page_buf, buff_alloced,
|
||||||
|
keyinfo->block_length + keyinfo->max_store_length);
|
||||||
|
if (!page_buf)
|
||||||
{
|
{
|
||||||
void *res;
|
my_errno= HA_ERR_OUT_OF_MEM;
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
DBUG_RETURN(-1); /* purecov: inspected */
|
||||||
keyinfo->block_length + keyinfo->max_store_length);
|
|
||||||
if (!(page_buf= res))
|
|
||||||
{
|
|
||||||
my_errno= HA_ERR_OUT_OF_MEM;
|
|
||||||
DBUG_RETURN(-1); /* purecov: inspected */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_ma_fetch_keypage(&page, info, keyinfo, page_pos, PAGECACHE_LOCK_WRITE,
|
if (_ma_fetch_keypage(&page, info, keyinfo, page_pos, PAGECACHE_LOCK_WRITE,
|
||||||
|
@ -798,15 +789,12 @@ int maria_rtree_insert_level(MARIA_HA *info, MARIA_KEY *key, int ins_level,
|
||||||
|
|
||||||
DBUG_PRINT("rtree", ("root was split, grow a new root"));
|
DBUG_PRINT("rtree", ("root was split, grow a new root"));
|
||||||
|
|
||||||
|
alloc_on_stack(*info->stack_end_ptr, new_root_buf, new_root_buf_alloced,
|
||||||
|
keyinfo->block_length + keyinfo->max_store_length);
|
||||||
|
if (!new_root_buf)
|
||||||
{
|
{
|
||||||
void *res;
|
my_errno= HA_ERR_OUT_OF_MEM;
|
||||||
alloc_on_stack(&info->stack_alloc, res, new_root_buf_alloced,
|
DBUG_RETURN(-1); /* purecov: inspected */
|
||||||
keyinfo->block_length + keyinfo->max_store_length);
|
|
||||||
if (!(new_root_buf= res))
|
|
||||||
{
|
|
||||||
my_errno= HA_ERR_OUT_OF_MEM;
|
|
||||||
DBUG_RETURN(-1); /* purecov: inspected */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bzero(new_root_buf, keyinfo->block_length);
|
bzero(new_root_buf, keyinfo->block_length);
|
||||||
|
@ -956,15 +944,12 @@ static int maria_rtree_delete_req(MARIA_HA *info, const MARIA_KEY *key,
|
||||||
MARIA_PAGE page;
|
MARIA_PAGE page;
|
||||||
DBUG_ENTER("maria_rtree_delete_req");
|
DBUG_ENTER("maria_rtree_delete_req");
|
||||||
|
|
||||||
|
alloc_on_stack(*info->stack_end_ptr, page_buf, buff_alloced,
|
||||||
|
keyinfo->block_length);
|
||||||
|
if (!page_buf)
|
||||||
{
|
{
|
||||||
void *res;
|
my_errno= HA_ERR_OUT_OF_MEM;
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
DBUG_RETURN(-1);
|
||||||
keyinfo->block_length);
|
|
||||||
if (!(page_buf= res))
|
|
||||||
{
|
|
||||||
my_errno= HA_ERR_OUT_OF_MEM;
|
|
||||||
DBUG_RETURN(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_ma_fetch_keypage(&page, info, keyinfo, page_pos, PAGECACHE_LOCK_WRITE,
|
if (_ma_fetch_keypage(&page, info, keyinfo, page_pos, PAGECACHE_LOCK_WRITE,
|
||||||
|
@ -1193,15 +1178,12 @@ my_bool maria_rtree_real_delete(MARIA_HA *info, MARIA_KEY *key,
|
||||||
|
|
||||||
if (ReinsertList.n_pages)
|
if (ReinsertList.n_pages)
|
||||||
{
|
{
|
||||||
|
alloc_on_stack(*info->stack_end_ptr, page_buf, buff_alloced,
|
||||||
|
keyinfo->block_length);
|
||||||
|
if (!page_buf)
|
||||||
{
|
{
|
||||||
void *res;
|
my_errno= HA_ERR_OUT_OF_MEM;
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
goto err;
|
||||||
keyinfo->block_length);
|
|
||||||
if (!(page_buf= res))
|
|
||||||
{
|
|
||||||
my_errno= HA_ERR_OUT_OF_MEM;
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i= 0; i < ReinsertList.n_pages; ++i)
|
for (i= 0; i < ReinsertList.n_pages; ++i)
|
||||||
|
@ -1313,13 +1295,10 @@ ha_rows maria_rtree_estimate(MARIA_HA *info, MARIA_KEY *key, uint32 flag)
|
||||||
if ((root= share->state.key_root[key->keyinfo->key_nr]) == HA_OFFSET_ERROR)
|
if ((root= share->state.key_root[key->keyinfo->key_nr]) == HA_OFFSET_ERROR)
|
||||||
return HA_POS_ERROR;
|
return HA_POS_ERROR;
|
||||||
|
|
||||||
{
|
alloc_on_stack(*info->stack_end_ptr, page_buf, buff_alloced,
|
||||||
void *res;
|
keyinfo->block_length);
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
if (!page_buf)
|
||||||
keyinfo->block_length);
|
return(HA_POS_ERROR);
|
||||||
if (!(page_buf= res))
|
|
||||||
return(HA_POS_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_ma_fetch_keypage(&page, info, keyinfo, root,
|
if (_ma_fetch_keypage(&page, info, keyinfo, root,
|
||||||
PAGECACHE_LOCK_LEFT_UNLOCKED, DFLT_INIT_HITS, page_buf,
|
PAGECACHE_LOCK_LEFT_UNLOCKED, DFLT_INIT_HITS, page_buf,
|
||||||
|
|
|
@ -396,15 +396,11 @@ int maria_rtree_split_page(const MARIA_KEY *key, MARIA_PAGE *page,
|
||||||
|
|
||||||
n_dim= keyinfo->keysegs / 2;
|
n_dim= keyinfo->keysegs / 2;
|
||||||
|
|
||||||
{
|
alloc_on_stack(*info->stack_end_ptr, coord_buf, coord_buf_alloced,
|
||||||
void *res;
|
(n_dim * 2 * sizeof(double) * (max_keys + 1 + 4) +
|
||||||
size_t length= (n_dim * 2 * sizeof(double) *
|
sizeof(SplitStruct) * (max_keys + 1)));
|
||||||
(max_keys + 1 + 4) +
|
if (!coord_buf)
|
||||||
sizeof(SplitStruct) * (max_keys + 1));
|
DBUG_RETURN(-1);
|
||||||
alloc_on_stack(&info->stack_alloc, res, coord_buf_alloced, length);
|
|
||||||
if (!(coord_buf= res))
|
|
||||||
DBUG_RETURN(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
task= (SplitStruct *)(coord_buf + n_dim * 2 * (max_keys + 1 + 4));
|
task= (SplitStruct *)(coord_buf + n_dim * 2 * (max_keys + 1 + 4));
|
||||||
|
|
||||||
|
@ -439,17 +435,13 @@ int maria_rtree_split_page(const MARIA_KEY *key, MARIA_PAGE *page,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate buffer for new page and piece of log record */
|
/* Allocate buffer for new page and piece of log record */
|
||||||
|
alloc_on_stack(*info->stack_end_ptr, new_page_buff, new_page_buff_alloced,
|
||||||
|
(keyinfo->block_length +
|
||||||
|
(transactional ? max_keys * (2 + 2) + 1 + 2 + 1 + 2 : 0)));
|
||||||
|
if (!new_page_buff)
|
||||||
{
|
{
|
||||||
void *res;
|
err_code= -1;
|
||||||
size_t len= (keyinfo->block_length +
|
goto split_err;
|
||||||
(transactional ? (max_keys * (2 + 2) + 1 + 2 + 1 + 2) : 0));
|
|
||||||
|
|
||||||
alloc_on_stack(&info->stack_alloc, res, new_page_buff_alloced, len);
|
|
||||||
if (!(new_page_buff= res))
|
|
||||||
{
|
|
||||||
err_code= -1;
|
|
||||||
goto split_err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log_internal_copy= log_internal_copy_ptr= new_page_buff +
|
log_internal_copy= log_internal_copy_ptr= new_page_buff +
|
||||||
|
|
|
@ -138,13 +138,10 @@ static int _ma_search_no_save(register MARIA_HA *info, MARIA_KEY *key,
|
||||||
DBUG_RETURN(1); /* Search at upper levels */
|
DBUG_RETURN(1); /* Search at upper levels */
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
alloc_on_stack(*info->stack_end_ptr, lastkey, buff_alloced,
|
||||||
void *res;
|
keyinfo->max_store_length);
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
if (!lastkey)
|
||||||
keyinfo->max_store_length);
|
DBUG_RETURN(1);
|
||||||
if (!(lastkey= res))
|
|
||||||
DBUG_RETURN(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_ma_fetch_keypage(&page, info, keyinfo, pos,
|
if (_ma_fetch_keypage(&page, info, keyinfo, pos,
|
||||||
PAGECACHE_LOCK_READ, DFLT_INIT_HITS, 0, 0))
|
PAGECACHE_LOCK_READ, DFLT_INIT_HITS, 0, 0))
|
||||||
|
|
|
@ -629,13 +629,11 @@ static int w_search(register MARIA_HA *info, uint32 comp_flag, MARIA_KEY *key,
|
||||||
DBUG_ENTER("w_search");
|
DBUG_ENTER("w_search");
|
||||||
DBUG_PRINT("enter", ("page: %lu", (ulong) (page_pos/keyinfo->block_length)));
|
DBUG_PRINT("enter", ("page: %lu", (ulong) (page_pos/keyinfo->block_length)));
|
||||||
|
|
||||||
{
|
alloc_on_stack(*info->stack_end_ptr, temp_buff, buff_alloced,
|
||||||
void *res;
|
(keyinfo->block_length + keyinfo->max_store_length*3));
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
if (!temp_buff)
|
||||||
(keyinfo->block_length + keyinfo->max_store_length*3));
|
DBUG_RETURN(1);
|
||||||
if (!(temp_buff= res))
|
|
||||||
DBUG_RETURN(1);
|
|
||||||
}
|
|
||||||
keybuff= temp_buff + (keyinfo->block_length + keyinfo->max_store_length*2);
|
keybuff= temp_buff + (keyinfo->block_length + keyinfo->max_store_length*2);
|
||||||
|
|
||||||
if (_ma_fetch_keypage(&page, info, keyinfo, page_pos, PAGECACHE_LOCK_WRITE,
|
if (_ma_fetch_keypage(&page, info, keyinfo, page_pos, PAGECACHE_LOCK_WRITE,
|
||||||
|
@ -1257,13 +1255,10 @@ static int _ma_balance_page(MARIA_HA *info, MARIA_KEYDEF *keyinfo,
|
||||||
MARIA_PAGE next_page, extra_page, *left_page, *right_page;
|
MARIA_PAGE next_page, extra_page, *left_page, *right_page;
|
||||||
DBUG_ENTER("_ma_balance_page");
|
DBUG_ENTER("_ma_balance_page");
|
||||||
|
|
||||||
{
|
alloc_on_stack(*info->stack_end_ptr, tmp_part_key, buff_alloced,
|
||||||
void *res;
|
keyinfo->max_store_length);
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
if (!tmp_part_key)
|
||||||
keyinfo->max_store_length);
|
DBUG_RETURN(-1);
|
||||||
if (!(tmp_part_key= res))
|
|
||||||
DBUG_RETURN(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
k_length= keyinfo->keylength;
|
k_length= keyinfo->keylength;
|
||||||
father_length= father_page->size;
|
father_length= father_page->size;
|
||||||
|
|
|
@ -2028,19 +2028,16 @@ static int sort_record_index(MARIA_SORT_PARAM *sort_param,
|
||||||
nod_flag= ma_page->node;
|
nod_flag= ma_page->node;
|
||||||
tmp_key.keyinfo= (MARIA_KEYDEF*) keyinfo;
|
tmp_key.keyinfo= (MARIA_KEYDEF*) keyinfo;
|
||||||
|
|
||||||
|
alloc_on_stack(*info->stack_end_ptr, lastkey, buff_alloced,
|
||||||
|
(nod_flag ? keyinfo->block_length : 0) +
|
||||||
|
ALIGN_SIZE(keyinfo->max_store_length));
|
||||||
|
if (!lastkey)
|
||||||
{
|
{
|
||||||
void *res;
|
_ma_check_print_error(param,"Not Enough memory");
|
||||||
alloc_on_stack(&info->stack_alloc, res, buff_alloced,
|
DBUG_RETURN(-1);
|
||||||
(nod_flag ? keyinfo->block_length : 0) +
|
|
||||||
ALIGN_SIZE(keyinfo->max_store_length));
|
|
||||||
if (!(lastkey= res))
|
|
||||||
{
|
|
||||||
_ma_check_print_error(param,"Not Enough memory");
|
|
||||||
DBUG_RETURN(-1);
|
|
||||||
}
|
|
||||||
if (nod_flag)
|
|
||||||
temp_buff= lastkey + ALIGN_SIZE(keyinfo->max_store_length);
|
|
||||||
}
|
}
|
||||||
|
if (nod_flag)
|
||||||
|
temp_buff= lastkey + ALIGN_SIZE(keyinfo->max_store_length);
|
||||||
|
|
||||||
tmp_key.data= lastkey;
|
tmp_key.data= lastkey;
|
||||||
|
|
||||||
|
|
|
@ -623,7 +623,7 @@ struct st_maria_handler
|
||||||
MARIA_STATUS_INFO *state_start; /* State at start of transaction */
|
MARIA_STATUS_INFO *state_start; /* State at start of transaction */
|
||||||
MARIA_USED_TABLES *used_tables;
|
MARIA_USED_TABLES *used_tables;
|
||||||
struct ms3_st *s3;
|
struct ms3_st *s3;
|
||||||
STACK_ALLOC stack_alloc;
|
void **stack_end_ptr;
|
||||||
MARIA_ROW cur_row; /* The active row that we just read */
|
MARIA_ROW cur_row; /* The active row that we just read */
|
||||||
MARIA_ROW new_row; /* Storage for a row during update */
|
MARIA_ROW new_row; /* Storage for a row during update */
|
||||||
MARIA_KEY last_key; /* Last found key */
|
MARIA_KEY last_key; /* Last found key */
|
||||||
|
@ -1468,18 +1468,3 @@ static inline void unmap_file(MARIA_HA *info __attribute__((unused)))
|
||||||
_ma_unmap_file(info);
|
_ma_unmap_file(info);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void aria_init_stack_alloc(MARIA_HA *info)
|
|
||||||
{
|
|
||||||
#ifndef DEBUG_STACK_ALLOC
|
|
||||||
init_stack_alloc(&info->stack_alloc,
|
|
||||||
STACK_ALLOC_BIG_BLOCK,
|
|
||||||
STACK_ALLOC_SMALL_BLOCK,
|
|
||||||
4096);
|
|
||||||
#else
|
|
||||||
/*
|
|
||||||
Force all allocation to go trough malloc to more easily find corruptions
|
|
||||||
*/
|
|
||||||
init_stack_alloc(&info->stack_alloc, 10000000, 10000000, 4096);
|
|
||||||
#endif /* DEBUG_STACK_ALLOC */
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue