Commit c99fd2ca authored by unknown's avatar unknown

Ensure that share->tot_locks s updated correctly

This fixes that mysamchk --sort-records works on windows.


myisam/mi_check.c:
  Ensure that share->tot_locks s updated correctly
myisam/mi_close.c:
  Ensure that share->tot_locks s updated correctly
myisam/mi_dynrec.c:
  Ensure that share->tot_locks s updated correctly
myisam/mi_open.c:
  Ensure that share->tot_locks s updated correctly
myisam/mi_statrec.c:
  Ensure that share->tot_locks s updated correctly
myisam/myisamchk.c:
  Ensure that share->tot_locks s updated correctly
parent c47044f0
...@@ -1551,7 +1551,7 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, my_string name) ...@@ -1551,7 +1551,7 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, my_string name)
old_state=share->state; /* save state if not stored */ old_state=share->state; /* save state if not stored */
r_locks=share->r_locks; w_locks=share->w_locks; r_locks=share->r_locks; w_locks=share->w_locks;
/* Put same locks as old file */ /* Put same locks as old file */
share->r_locks=share->w_locks=0; share->r_locks= share->w_locks= share->tot_locks= 0;
(void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
VOID(my_close(share->kfile,MYF(MY_WME))); VOID(my_close(share->kfile,MYF(MY_WME)));
share->kfile = -1; share->kfile = -1;
...@@ -1564,6 +1564,7 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, my_string name) ...@@ -1564,6 +1564,7 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, my_string name)
_mi_readinfo(info,F_WRLCK,0); /* Will lock the table */ _mi_readinfo(info,F_WRLCK,0); /* Will lock the table */
info->lock_type=F_WRLCK; info->lock_type=F_WRLCK;
share->r_locks=r_locks; share->w_locks=w_locks; share->r_locks=r_locks; share->w_locks=w_locks;
share->tot_locks= r_locks+w_locks;
share->state=old_state; /* Restore old state */ share->state=old_state; /* Restore old state */
info->state->key_file_length=param->new_file_pos; info->state->key_file_length=param->new_file_pos;
...@@ -3139,9 +3140,11 @@ int update_state_info(MI_CHECK *param, MI_INFO *info,uint update) ...@@ -3139,9 +3140,11 @@ int update_state_info(MI_CHECK *param, MI_INFO *info,uint update)
{ /* Force update of status */ { /* Force update of status */
int error; int error;
uint r_locks=share->r_locks,w_locks=share->w_locks; uint r_locks=share->r_locks,w_locks=share->w_locks;
share->r_locks=share->w_locks=0; share->r_locks= share->w_locks= share->tot_locks= 0;
error=_mi_writeinfo(info,WRITEINFO_NO_UNLOCK); error=_mi_writeinfo(info,WRITEINFO_NO_UNLOCK);
share->r_locks=r_locks; share->w_locks=w_locks; share->r_locks=r_locks;
share->w_locks=w_locks;
share->tot_locks=r_locks+w_locks;
if (!error) if (!error)
return 0; return 0;
} }
......
...@@ -29,8 +29,7 @@ int mi_close(register MI_INFO *info) ...@@ -29,8 +29,7 @@ int mi_close(register MI_INFO *info)
MYISAM_SHARE *share=info->s; MYISAM_SHARE *share=info->s;
DBUG_ENTER("mi_close"); DBUG_ENTER("mi_close");
DBUG_PRINT("enter",("base: %lx reopen: %u locks: %u", DBUG_PRINT("enter",("base: %lx reopen: %u locks: %u",
info,(uint) share->reopen, info,(uint) share->reopen, (uint) share->tot_locks));
(uint) (share->w_locks+share->r_locks)));
pthread_mutex_lock(&THR_LOCK_myisam); pthread_mutex_lock(&THR_LOCK_myisam);
if (info->lock_type == F_EXTRA_LCK) if (info->lock_type == F_EXTRA_LCK)
...@@ -47,7 +46,10 @@ int mi_close(register MI_INFO *info) ...@@ -47,7 +46,10 @@ int mi_close(register MI_INFO *info)
pthread_mutex_lock(&share->intern_lock); pthread_mutex_lock(&share->intern_lock);
if (share->options & HA_OPTION_READ_ONLY_DATA) if (share->options & HA_OPTION_READ_ONLY_DATA)
{
share->r_locks--; share->r_locks--;
share->tot_locks--;
}
if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED)) if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
{ {
if (end_io_cache(&info->rec_cache)) if (end_io_cache(&info->rec_cache))
......
...@@ -1275,7 +1275,7 @@ int _mi_read_rnd_dynamic_record(MI_INFO *info, byte *buf, ...@@ -1275,7 +1275,7 @@ int _mi_read_rnd_dynamic_record(MI_INFO *info, byte *buf,
if (info->lock_type == F_UNLCK) if (info->lock_type == F_UNLCK)
{ {
#ifndef UNSAFE_LOCKING #ifndef UNSAFE_LOCKING
if (share->r_locks == 0 && share->w_locks == 0) if (share->tot_locks == 0)
{ {
if (my_lock(share->kfile,F_RDLCK,0L,F_TO_EOF, if (my_lock(share->kfile,F_RDLCK,0L,F_TO_EOF,
MYF(MY_SEEK_NOT_DONE) | info->lock_wait)) MYF(MY_SEEK_NOT_DONE) | info->lock_wait))
......
...@@ -486,6 +486,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) ...@@ -486,6 +486,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
{ {
info.lock_type=F_RDLCK; info.lock_type=F_RDLCK;
share->r_locks++; share->r_locks++;
share->tot_locks++;
} }
if ((open_flags & HA_OPEN_TMP_TABLE) || if ((open_flags & HA_OPEN_TMP_TABLE) ||
(share->options & HA_OPTION_TMP_TABLE)) (share->options & HA_OPTION_TMP_TABLE))
...@@ -493,6 +494,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) ...@@ -493,6 +494,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
share->temporary=share->delay_key_write=1; share->temporary=share->delay_key_write=1;
share->write_flag=MYF(MY_NABP); share->write_flag=MYF(MY_NABP);
share->w_locks++; /* We don't have to update status */ share->w_locks++; /* We don't have to update status */
share->tot_locks++;
info.lock_type=F_WRLCK; info.lock_type=F_WRLCK;
} }
if (((open_flags & HA_OPEN_DELAY_KEY_WRITE) || if (((open_flags & HA_OPEN_DELAY_KEY_WRITE) ||
......
...@@ -239,7 +239,7 @@ int _mi_read_rnd_static_record(MI_INFO *info, byte *buf, ...@@ -239,7 +239,7 @@ int _mi_read_rnd_static_record(MI_INFO *info, byte *buf,
{ /* We don't nead new info */ { /* We don't nead new info */
#ifndef UNSAFE_LOCKING #ifndef UNSAFE_LOCKING
if ((! cache_read || share->base.reclength > cache_length) && if ((! cache_read || share->base.reclength > cache_length) &&
share->r_locks == 0 && share->w_locks == 0) share->tot_locks == 0)
{ /* record not in cache */ { /* record not in cache */
if (my_lock(share->kfile,F_RDLCK,0L,F_TO_EOF, if (my_lock(share->kfile,F_RDLCK,0L,F_TO_EOF,
MYF(MY_SEEK_NOT_DONE) | info->lock_wait)) MYF(MY_SEEK_NOT_DONE) | info->lock_wait))
......
...@@ -729,6 +729,7 @@ static int myisamchk(MI_CHECK *param, my_string filename) ...@@ -729,6 +729,7 @@ static int myisamchk(MI_CHECK *param, my_string filename)
} }
share=info->s; share=info->s;
share->options&= ~HA_OPTION_READ_ONLY_DATA; /* We are modifing it */ share->options&= ~HA_OPTION_READ_ONLY_DATA; /* We are modifing it */
share->tot_locks-= share->r_locks;
share->r_locks=0; share->r_locks=0;
raid_chunks=share->base.raid_chunks; raid_chunks=share->base.raid_chunks;
...@@ -806,6 +807,7 @@ static int myisamchk(MI_CHECK *param, my_string filename) ...@@ -806,6 +807,7 @@ static int myisamchk(MI_CHECK *param, my_string filename)
rep_quick|=T_QUICK; rep_quick|=T_QUICK;
} }
share=info->s; share=info->s;
share->tot_locks-= share->r_locks;
share->r_locks=0; share->r_locks=0;
} }
...@@ -835,6 +837,7 @@ static int myisamchk(MI_CHECK *param, my_string filename) ...@@ -835,6 +837,7 @@ static int myisamchk(MI_CHECK *param, my_string filename)
goto end2; goto end2;
} }
share->w_locks++; /* Mark for writeinfo */ share->w_locks++; /* Mark for writeinfo */
share->tot_locks++;
info->lock_type= F_EXTRA_LCK; /* Simulate as locked */ info->lock_type= F_EXTRA_LCK; /* Simulate as locked */
info->tmp_lock_type=lock_type; info->tmp_lock_type=lock_type;
datafile=info->dfile; datafile=info->dfile;
...@@ -1011,6 +1014,7 @@ static int myisamchk(MI_CHECK *param, my_string filename) ...@@ -1011,6 +1014,7 @@ static int myisamchk(MI_CHECK *param, my_string filename)
info->update&= ~HA_STATE_CHANGED; info->update&= ~HA_STATE_CHANGED;
} }
share->w_locks--; share->w_locks--;
share->tot_locks--;
end2: end2:
if (mi_close(info)) if (mi_close(info))
{ {
......
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