From b65dbb61143e7add58481dc4bc184c530a9a5582 Mon Sep 17 00:00:00 2001
From: "monty@donna.mysql.com" <>
Date: Tue, 21 Nov 2000 03:43:34 +0200
Subject: Fixed problem with auto-repair of MyISAM tables Fixed bug in ISAM and
 MyISAM when updating from multiple-processes

---
 myisam/mi_locking.c | 1 +
 myisam/mi_open.c    | 5 +++--
 myisam/mi_rnext.c   | 7 +++++--
 myisam/mi_rprev.c   | 5 +++--
 myisam/myisamchk.c  | 9 ++++++++-
 5 files changed, 20 insertions(+), 7 deletions(-)

(limited to 'myisam')

diff --git a/myisam/mi_locking.c b/myisam/mi_locking.c
index 45bb2cd7164..057efb96185 100644
--- a/myisam/mi_locking.c
+++ b/myisam/mi_locking.c
@@ -382,6 +382,7 @@ int _mi_test_if_changed(register MI_INFO *info)
       share->state.unique  != info->last_unique ||
       share->state.update_count != info->last_loop)
   {						/* Keyfile has changed */
+    DBUG_PRINT("info",("index file changed"));
     if (share->state.process != share->this_process)
       VOID(flush_key_blocks(share->kfile,FLUSH_RELEASE));
     share->last_process=share->state.process;
diff --git a/myisam/mi_open.c b/myisam/mi_open.c
index c29a4a843ca..2eab33228dc 100644
--- a/myisam/mi_open.c
+++ b/myisam/mi_open.c
@@ -182,7 +182,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
     {
       DBUG_PRINT("error",("Table is marked as crashed"));
       my_errno=((share->state.changed & STATE_CRASHED_ON_REPAIR) ?
-		HA_ERR_CRASHED_ON_REPAIR : HA_ERR_CRASHED);
+		HA_ERR_CRASHED_ON_REPAIR : HA_ERR_CRASHED_ON_USAGE);
       goto err;
     }
     /* Correct max_file_length based on length of sizeof_t */
@@ -732,7 +732,8 @@ char *mi_state_info_read(char *ptr, MI_STATE_INFO *state)
   state->process= mi_uint4korr(ptr);		ptr +=4;
   state->unique = mi_uint4korr(ptr);		ptr +=4;
   state->status = mi_uint4korr(ptr);		ptr +=4;
-						ptr +=4; /* extra */
+  state->update_count=mi_uint4korr(ptr);	ptr +=4;
+
   for (i=0; i < keys; i++)
   {
     state->key_root[i]= mi_sizekorr(ptr);	ptr +=8;
diff --git a/myisam/mi_rnext.c b/myisam/mi_rnext.c
index f7e7b61d934..f297740af60 100644
--- a/myisam/mi_rnext.c
+++ b/myisam/mi_rnext.c
@@ -25,7 +25,7 @@
 
 int mi_rnext(MI_INFO *info, byte *buf, int inx)
 {
-  int error;
+  int error,changed;
   uint flag;
   DBUG_ENTER("mi_rnext");
 
@@ -39,10 +39,13 @@ int mi_rnext(MI_INFO *info, byte *buf, int inx)
     DBUG_RETURN(my_errno);
   if (info->s->concurrent_insert)
     rw_rdlock(&info->s->key_root_lock[inx]);
+  changed=_mi_test_if_changed(info);
   if (!flag)
+  {
     error=_mi_search_first(info,info->s->keyinfo+inx,
 			   info->s->state.key_root[inx]);
-  else if (_mi_test_if_changed(info) == 0)
+  }
+  else if (!changed)
     error=_mi_search_next(info,info->s->keyinfo+inx,info->lastkey,
 			  info->lastkey_length,flag,
 			  info->s->state.key_root[inx]);
diff --git a/myisam/mi_rprev.c b/myisam/mi_rprev.c
index 471eecc33f5..69d18b10287 100644
--- a/myisam/mi_rprev.c
+++ b/myisam/mi_rprev.c
@@ -25,7 +25,7 @@
 
 int mi_rprev(MI_INFO *info, byte *buf, int inx)
 {
-  int error;
+  int error,changed;
   register uint flag;
   MYISAM_SHARE *share=info->s;
   DBUG_ENTER("mi_rprev");
@@ -38,12 +38,13 @@ int mi_rprev(MI_INFO *info, byte *buf, int inx)
 
   if (_mi_readinfo(info,F_RDLCK,1))
     DBUG_RETURN(my_errno);
+  changed=_mi_test_if_changed(info);
   if (share->concurrent_insert)
     rw_rdlock(&share->key_root_lock[inx]);
   if (!flag)
     error=_mi_search_last(info, share->keyinfo+inx,
 			  share->state.key_root[inx]);
-  else if (_mi_test_if_changed(info) == 0)
+  else if (!changed)
     error=_mi_search_next(info,share->keyinfo+inx,info->lastkey,
 			  info->lastkey_length,flag,
 			  share->state.key_root[inx]);
diff --git a/myisam/myisamchk.c b/myisam/myisamchk.c
index b18f42bfb81..d045bf0018b 100644
--- a/myisam/myisamchk.c
+++ b/myisam/myisamchk.c
@@ -196,7 +196,7 @@ static struct option long_options[] =
 
 static void print_version(void)
 {
-  printf("%s  Ver 1.36 for %s at %s\n",my_progname,SYSTEM_TYPE,
+  printf("%s  Ver 1.37 for %s at %s\n",my_progname,SYSTEM_TYPE,
 	 MACHINE_TYPE);
 }
 
@@ -502,8 +502,15 @@ static int myisamchk(MI_CHECK *param, my_string filename)
     param->error_printed=1;
     switch (my_errno) {
     case HA_ERR_CRASHED:
+    case HA_ERR_WRONG_TABLE_DEF:
       mi_check_print_error(param,"'%s' is not a MyISAM-table",filename);
       break;
+    case HA_ERR_CRASHED_ON_USAGE:
+      mi_check_print_error(param,"'%s' is marked as crashed",filename);
+      break;
+    case HA_ERR_CRASHED_ON_REPAIR:
+      mi_check_print_error(param,"'%s' is marked as crashed after last repair",filename);
+      break;
     case HA_ERR_OLD_FILE:
       mi_check_print_error(param,"'%s' is a old type of MyISAM-table", filename);
       break;
-- 
cgit v1.2.1