Commit 53b88c20 authored by serg@sergbook.mysql.com's avatar serg@sergbook.mysql.com

Merge work:/home/bk/mysql-4.0

into sergbook.mysql.com:/usr/home/serg/Abk/mysql-4.0
parents 38e34bc7 2fe3fec4
......@@ -378,6 +378,8 @@ typedef struct st_mi_sort_param
uint key, key_length,real_key_length,sortbuff_size;
uint maxbuffers, keys, find_length, sort_keys_length;
uchar **sort_keys;
byte *rec_buff;
uint alloced_rec_buff_length;
void *wordlist, *wordptr;
MI_KEYDEF *keyinfo;
SORT_INFO *sort_info;
......
......@@ -898,7 +898,7 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend)
info->checksum=mi_checksum(info,record);
if (param->testflag & (T_EXTEND | T_MEDIUM | T_VERBOSE))
{
if (_mi_rec_check(info,record))
if (_mi_rec_check(info,record, info->rec_buff))
{
mi_check_print_error(param,"Found wrong packed record at %s",
llstr(start_recpos,llbuff));
......@@ -1143,6 +1143,8 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info,
MYF(MY_WME | MY_WAIT_IF_FULL)))
goto err;
info->opt_flag|=WRITE_CACHE_USED;
sort_param.rec_buff=info->rec_buff;
sort_param.alloced_rec_buff_length=info->alloced_rec_buff_length;
if (!(sort_param.record=(byte*) my_malloc((uint) share->base.pack_reclength,
MYF(0))))
{
......@@ -1787,6 +1789,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
param->testflag|=T_REP; /* for easy checking */
bzero((char*)&sort_info,sizeof(sort_info));
bzero((char *)&sort_param, sizeof(sort_param));
if (!(sort_info.key_block=
alloc_key_blocks(param,
(uint) param->sort_key_blocks,
......@@ -1804,6 +1807,8 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
info->opt_flag|=WRITE_CACHE_USED;
info->rec_cache.file=info->dfile; /* for sort_delete_record */
sort_param.rec_buff=info->rec_buff;
sort_param.alloced_rec_buff_length=info->alloced_rec_buff_length;
if (!(sort_param.record=(byte*) my_malloc((uint) share->base.pack_reclength,
MYF(0))))
{
......@@ -2164,7 +2169,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
goto err;
sort_info.key_block_end=sort_info.key_block+param->sort_key_blocks;
info->opt_flag|=WRITE_CACHE_USED;
info->rec_cache.file=info->dfile; /* for sort_delete_record */
info->rec_cache.file=info->dfile; /* for sort_delete_record */
if (!rep_quick)
{
......@@ -2570,15 +2575,13 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
my_off_t pos;
byte *to;
MI_BLOCK_INFO block_info;
MI_INFO *info;
MYISAM_SHARE *share;
SORT_INFO *sort_info=sort_param->sort_info;
MI_CHECK *param=sort_info->param;
MI_INFO *info=sort_info->info;
MYISAM_SHARE *share=info->s;
char llbuff[22],llbuff2[22];
DBUG_ENTER("sort_get_next_record");
info=sort_info->info;
share=info->s;
switch (share->data_file_type) {
case STATIC_RECORD:
for (;;)
......@@ -2665,9 +2668,9 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
param->testflag|=T_RETRY_WITHOUT_QUICK;
DBUG_RETURN(1); /* Something wrong with data */
}
if (((b_type=_mi_get_block_info(&block_info,-1,pos)) &
(BLOCK_ERROR | BLOCK_FATAL_ERROR)) ||
((b_type & BLOCK_FIRST) &&
b_type=_mi_get_block_info(&block_info,-1,pos);
if ((b_type & (BLOCK_ERROR | BLOCK_FATAL_ERROR)) ||
((b_type & BLOCK_FIRST) &&
(block_info.rec_len < (uint) share->base.min_pack_length ||
block_info.rec_len > (uint) share->base.max_pack_length)))
{
......@@ -2787,7 +2790,9 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
sort_param->pos=block_info.filepos+block_info.block_len;
if (share->base.blobs)
{
if (!(to=mi_fix_rec_buff_for_blob(info,block_info.rec_len)))
if (!(to=mi_alloc_rec_buff(info,block_info.rec_len,
&(sort_param->rec_buff),
&(sort_param->alloced_rec_buff_length))))
{
mi_check_print_error(param,"Not enough memory for blob at %s",
llstr(sort_param->start_recpos,llbuff));
......@@ -2795,7 +2800,7 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
}
}
else
to= info->rec_buff;
to= sort_param->rec_buff;
}
if (left_length < block_info.data_len || ! block_info.data_len)
{
......@@ -2837,7 +2842,7 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
}
} while (left_length);
if (_mi_rec_unpack(info,sort_param->record,info->rec_buff,
if (_mi_rec_unpack(info,sort_param->record,sort_param->rec_buff,
sort_param->find_length) != MY_FILE_ERROR)
{
if (sort_param->read_cache.error < 0)
......@@ -2846,7 +2851,7 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
info->checksum=mi_checksum(info,sort_param->record);
if ((param->testflag & (T_EXTEND | T_REP)) || searching)
{
if (_mi_rec_check(info, sort_param->record))
if (_mi_rec_check(info, sort_param->record, sort_param->rec_buff))
{
mi_check_print_info(param,"Found wrong packed record at %s",
llstr(sort_param->start_recpos,llbuff));
......@@ -2858,8 +2863,9 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
DBUG_RETURN(0);
}
if (!searching)
mi_check_print_info(param,"Found wrong stored record at %s",
llstr(sort_param->start_recpos,llbuff));
mi_check_print_info(param,"Key %d - Found wrong stored record at %s",
sort_param->key+1,
llstr(sort_param->start_recpos,llbuff));
try_next:
pos=(sort_param->start_recpos+=MI_DYN_ALIGN_SIZE);
searching=1;
......@@ -2894,7 +2900,7 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
llstr(sort_param->pos,llbuff));
continue;
}
if (_mi_read_cache(&sort_param->read_cache,(byte*) info->rec_buff,
if (_mi_read_cache(&sort_param->read_cache,(byte*) sort_param->rec_buff,
block_info.filepos, block_info.rec_len,
READING_NEXT))
{
......@@ -2903,7 +2909,7 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
llstr(sort_param->pos,llbuff));
continue;
}
if (_mi_pack_rec_unpack(info,sort_param->record,info->rec_buff,
if (_mi_pack_rec_unpack(info,sort_param->record,sort_param->rec_buff,
block_info.rec_len))
{
if (! searching)
......@@ -2963,7 +2969,7 @@ int sort_write_record(MI_SORT_PARAM *sort_param)
break;
case DYNAMIC_RECORD:
if (! info->blobs)
from=info->rec_buff;
from=sort_param->rec_buff;
else
{
/* must be sure that local buffer is big enough */
......@@ -3013,7 +3019,7 @@ int sort_write_record(MI_SORT_PARAM *sort_param)
if (info->s->base.blobs)
length+=save_pack_length(block_buff+length,info->blob_length);
if (my_b_write(&info->rec_cache,block_buff,length) ||
my_b_write(&info->rec_cache,(byte*) info->rec_buff,reclength))
my_b_write(&info->rec_cache,(byte*) sort_param->rec_buff,reclength))
{
mi_check_print_error(param,"%d when writing to datafile",my_errno);
DBUG_RETURN(1);
......
......@@ -60,6 +60,7 @@ int mi_close(register MI_INFO *info)
myisam_open_list=list_delete(myisam_open_list,&info->open_list);
pthread_mutex_unlock(&share->intern_lock);
my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR));
if (flag)
{
if (share->kfile >= 0 &&
......@@ -101,7 +102,6 @@ int mi_close(register MI_INFO *info)
error = my_errno;
myisam_log_command(MI_LOG_CLOSE,info,NULL,0,error);
my_free((gptr) info->rec_alloc,MYF(MY_ALLOW_ZERO_PTR));
my_free((gptr) info,MYF(0));
if (error)
......
......@@ -724,11 +724,11 @@ uint _mi_rec_pack(MI_INFO *info, register byte *to, register const byte *from)
/*
** Check if a record was correctly packed. Used only by isamchk
** Returns 0 if record is ok.
Check if a record was correctly packed. Used only by myisamchk
Returns 0 if record is ok.
*/
my_bool _mi_rec_check(MI_INFO *info,const char *record)
my_bool _mi_rec_check(MI_INFO *info,const char *record, byte *rec_buff)
{
uint length,new_length,flag,bit,i;
char *pos,*end,*packpos,*to;
......@@ -736,7 +736,7 @@ my_bool _mi_rec_check(MI_INFO *info,const char *record)
reg3 MI_COLUMNDEF *rec;
DBUG_ENTER("_mi_rec_check");
packpos=info->rec_buff; to= info->rec_buff+info->s->base.pack_bits;
packpos=rec_buff; to= rec_buff+info->s->base.pack_bits;
rec=info->s->rec;
flag= *packpos; bit=1;
......@@ -820,7 +820,7 @@ my_bool _mi_rec_check(MI_INFO *info,const char *record)
to+=length;
}
}
if (info->packed_length != (uint) (to - info->rec_buff)
if (info->packed_length != (uint) (to - rec_buff)
+ test(info->s->calc_checksum) ||
(bit != 1 && (flag & ~(bit - 1))))
goto err;
......@@ -1090,32 +1090,12 @@ err:
DBUG_RETURN(-1);
}
byte *mi_fix_rec_buff_for_blob(MI_INFO *info, ulong length)
{
uint extra;
if (! info->rec_buff || length > info->alloced_rec_buff_length)
{
byte *newptr;
extra=ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER)+MI_SPLIT_LENGTH+
MI_DYN_DELETE_BLOCK_HEADER;
if (!(newptr=(byte*) my_realloc((gptr) info->rec_alloc,length+extra,
MYF(MY_ALLOW_ZERO_PTR))))
return newptr;
info->rec_alloc=newptr;
info->rec_buff=newptr+ALIGN_SIZE(MI_DYN_DELETE_BLOCK_HEADER);
info->alloced_rec_buff_length=length;
}
return info->rec_buff;
}
/* compare unique constraint between stored rows */
int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def,
const byte *record, my_off_t pos)
{
byte *rec_buff,*rec_alloc,*old_record;
byte *rec_buff,*old_record;
uint alloced_rec_buff_length;
int error;
DBUG_ENTER("_mi_cmp_dynamic_unique");
......@@ -1125,12 +1105,10 @@ int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def,
/* Don't let the compare destroy blobs that may be in use */
rec_buff=info->rec_buff;
rec_alloc=info->rec_alloc;
alloced_rec_buff_length=info->alloced_rec_buff_length;
if (info->s->base.blobs)
{
info->rec_buff=0;
info->rec_alloc=0;
info->alloced_rec_buff_length=0;
}
error=_mi_read_dynamic_record(info,pos,old_record);
......@@ -1138,9 +1116,8 @@ int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def,
error=mi_unique_comp(def, record, old_record, def->null_are_equal);
if (info->s->base.blobs)
{
my_free(info->rec_alloc,MYF(MY_ALLOW_ZERO_PTR));
my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR));
info->rec_buff=rec_buff;
info->rec_alloc=rec_alloc;
info->alloced_rec_buff_length=alloced_rec_buff_length;
}
my_afree(old_record);
......
......@@ -328,11 +328,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function)
}
}
if (share->base.blobs)
{
my_free(info->rec_alloc,MYF(MY_ALLOW_ZERO_PTR));
info->rec_alloc=info->rec_buff=0;
mi_fix_rec_buff_for_blob(info,info->s->base.pack_reclength);
}
mi_fix_rec_buff_for_blob(info, -1);
break;
case HA_EXTRA_NORMAL: /* Theese isn't in use */
info->quick_mode=0;
......
......@@ -506,20 +506,10 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
/* Allocate buffer for one record */
extra=0;
if (share->options & HA_OPTION_PACK_RECORD)
extra=ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER)+MI_SPLIT_LENGTH+
MI_DYN_DELETE_BLOCK_HEADER;
tmp_length=max(share->base.pack_reclength,share->base.max_key_length);
info.alloced_rec_buff_length=tmp_length;
if (!(info.rec_alloc=(byte*) my_malloc(tmp_length+extra+8,
MYF(MY_WME | MY_ZEROFILL))))
/* prerequisites: bzero(info) && info->s=share; are met. */
if (!mi_fix_rec_buff_for_blob(&info, -1))
goto err;
if (extra)
info.rec_buff=info.rec_alloc+ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER);
else
info.rec_buff=info.rec_alloc;
bzero(info.rec_buff, info.alloced_rec_buff_length);
*m_info=info;
#ifdef THREAD
......@@ -569,6 +559,39 @@ err:
DBUG_RETURN (NULL);
} /* mi_open */
gptr mi_get_rec_buff_ptr(MI_INFO *info, byte *buf)
{
if (info->s->options & HA_OPTION_PACK_RECORD && buf)
return buf - MI_REC_BUFF_OFFSET;
else
return buf;
}
byte *mi_alloc_rec_buff(MI_INFO *info, ulong length, byte **buf, uint *buf_len)
{
uint extra;
if (! *buf || length > *buf_len)
{
byte *newptr = *buf;
/* to simplify initial init of info->rec_buf in mi_open and mi_extra */
if (length == (ulong)-1)
length=max(info->s->base.pack_reclength,info->s->base.max_key_length);
extra= ((info->s->options & HA_OPTION_PACK_RECORD) ?
ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER)+MI_SPLIT_LENGTH+
MI_REC_BUFF_OFFSET : 0);
if (extra && newptr)
newptr-=MI_REC_BUFF_OFFSET;
if (!(newptr=(byte*) my_realloc((gptr)newptr, length+extra+8,
MYF(MY_ALLOW_ZERO_PTR))))
return 0;
*buf=newptr+(extra ? MI_REC_BUFF_OFFSET : 0);
*buf_len=length;
}
return *buf;
}
ulonglong mi_safe_mul(ulonglong a, ulonglong b)
{
......
......@@ -222,12 +222,11 @@ struct st_myisam_info {
MI_BLOB *blobs; /* Pointer to blobs */
MI_BIT_BUFF bit_buff;
/* accumulate indexfile changes between write's */
TREE *bulk_insert;
TREE *bulk_insert;
char *filename; /* parameter to open filename */
uchar *buff, /* Temp area for key */
*lastkey,*lastkey2; /* Last used search key */
byte *rec_buff, /* Tempbuff for recordpack */
*rec_alloc; /* Malloced area for record */
byte *rec_buff; /* Tempbuff for recordpack */
uchar *int_keypos, /* Save position for next/previous */
*int_maxpos; /* -""- */
int (*read_record)(struct st_myisam_info*, my_off_t, byte*);
......@@ -249,7 +248,7 @@ struct st_myisam_info {
uint opt_flag; /* Optim. for space/speed */
uint update; /* If file changed since open */
uint alloced_rec_buff_length; /* Max recordlength malloced */
uint int_nod_flag; /* -""- */
uint int_nod_flag; /* -""- */
int lastinx; /* Last used index */
uint lastkey_length; /* Length of key in lastkey */
uint last_rkey_length; /* Last length in mi_rkey() */
......@@ -360,6 +359,7 @@ struct st_myisam_info {
#define MI_DYN_ALIGN_SIZE 4 /* Align blocks on this */
#define MI_MAX_DYN_HEADER_BYTE 13 /* max header byte for dynamic rows */
#define MI_MAX_BLOCK_LENGTH ((((ulong) 1 << 24)-1) & (~ (ulong) (MI_DYN_ALIGN_SIZE-1)))
#define MI_REC_BUFF_OFFSET ALIGN_SIZE(MI_DYN_DELETE_BLOCK_HEADER)
#define MEMMAP_EXTRA_MARGIN 7 /* Write this as a suffix for file */
......@@ -523,10 +523,14 @@ extern int _mi_read_key_record(MI_INFO *info,my_off_t filepos,byte *buf);
extern int _mi_read_cache(IO_CACHE *info,byte *buff,my_off_t pos,
uint length,int re_read_if_possibly);
extern void update_auto_increment(MI_INFO *info,const byte *record);
extern byte *mi_fix_rec_buff_for_blob(MI_INFO *info,ulong blob_length);
extern byte *mi_alloc_rec_buff(MI_INFO *,ulong, byte**, uint*);
extern gptr mi_get_rec_buff_ptr(MI_INFO *, byte *);
#define mi_fix_rec_buff_for_blob(INFO,LENGTH) \
mi_alloc_rec_buff((INFO),(LENGTH), \
&((INFO)->rec_buff), &((INFO)->alloced_rec_buff_length))
extern ulong _mi_rec_unpack(MI_INFO *info,byte *to,byte *from,
ulong reclength);
extern my_bool _mi_rec_check(MI_INFO *info,const char *from);
extern my_bool _mi_rec_check(MI_INFO *info,const char *record, byte *packpos);
extern int _mi_write_part_record(MI_INFO *info,my_off_t filepos,ulong length,
my_off_t next_filepos,byte **record,
ulong *reclength,int *flag);
......
......@@ -182,7 +182,7 @@ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages,
reinit_io_cache(&tempfile,READ_CACHE,0L,0,0))
goto err; /* purecov: inspected */
if (!no_messages)
puts(" - Last merge and dumping keys"); /* purecov: tested */
puts(" - Last merge and dumping keys\n"); /* purecov: tested */
if (merge_index(info,keys,sort_keys,dynamic_element(&buffpek,0,BUFFPEK *),
maxbuffer,&tempfile))
goto err; /* purecov: inspected */
......@@ -433,22 +433,26 @@ int thr_write_keys(MI_SORT_PARAM *sort_param)
got_error=1;
continue;
}
share->state.key_map|=(ulonglong) 1 << sinfo->key;
if (param->testflag & T_STATISTICS)
update_key_parts(sinfo->keyinfo, rec_per_key_part,
sinfo->unique, (ulonglong) info->state->records);
if (!sinfo->buffpek.elements)
if (!got_error)
{
if (param->testflag & T_VERBOSE)
share->state.key_map|=(ulonglong) 1 << sinfo->key;
if (param->testflag & T_STATISTICS)
update_key_parts(sinfo->keyinfo, rec_per_key_part,
sinfo->unique, (ulonglong) info->state->records);
if (!sinfo->buffpek.elements)
{
printf("Key %d - Dumping %u keys\n",sinfo->key+1, sinfo->keys);
fflush(stdout);
if (param->testflag & T_VERBOSE)
{
printf("Key %d - Dumping %u keys\n",sinfo->key+1, sinfo->keys);
fflush(stdout);
}
if (write_index(sinfo, sinfo->sort_keys, sinfo->keys) ||
flush_pending_blocks(sinfo))
got_error=1;
}
if (write_index(sinfo, sinfo->sort_keys, sinfo->keys) ||
flush_pending_blocks(sinfo))
got_error=1;
}
my_free((gptr) sinfo->sort_keys,MYF(0));
my_free(mi_get_rec_buff_ptr(info, sinfo->rec_buff), MYF(MY_ALLOW_ZERO_PTR));
sinfo->sort_keys=0;
}
......@@ -497,7 +501,7 @@ int thr_write_keys(MI_SORT_PARAM *sort_param)
continue;
}
if (param->testflag & T_VERBOSE)
printf("Key %d - Last merge and dumping keys", sinfo->key+1);
printf("Key %d - Last merge and dumping keys\n", sinfo->key+1);
if (merge_index(sinfo, keys, (uchar **)mergebuf,
dynamic_element(&sinfo->buffpek,0,BUFFPEK *),
maxbuffer,&sinfo->tempfile) ||
......@@ -512,7 +516,7 @@ int thr_write_keys(MI_SORT_PARAM *sort_param)
uint key_length;
if (param->testflag & T_VERBOSE)
printf("Key %d - Dumping 'long' keys", sinfo->key+1);
printf("Key %d - Dumping 'long' keys\n", sinfo->key+1);
if (flush_io_cache(&sinfo->tempfile_for_exceptions) ||
reinit_io_cache(&sinfo->tempfile_for_exceptions,READ_CACHE,0L,0,0))
......
......@@ -524,13 +524,6 @@ int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count)
}
if (lock_io_cache(info))
{
#if 0 && SAFE_MUTEX
#define PRINT_LOCK(M) printf("Thread %d: mutex is %s\n", my_thread_id(), \
(((safe_mutex_t *)(M))->count ? "Locked" : "Unlocked"))
#else
#define PRINT_LOCK(M)
#endif
PRINT_LOCK(&info->share->mutex);
info->share->active=info;
if (info->seek_not_done) /* File touched, do seek */
VOID(my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)));
......@@ -539,7 +532,6 @@ int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count)
info->error=(len == (int)length ? 0 : len);
info->pos_in_file=pos_in_file;
unlock_io_cache(info);
PRINT_LOCK(&info->share->mutex);
}
else
{
......@@ -547,7 +539,6 @@ int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count)
info->read_end= info->share->active->read_end;
info->pos_in_file= info->share->active->pos_in_file;
len= (info->error == -1 ? -1 : info->read_end-info->buffer);
PRINT_LOCK(&info->share->mutex);
}
info->read_pos=info->buffer;
info->seek_not_done=0;
......
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