~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_update.c

Merged from trunk. 
Moved resolve_stack_dump to mysql-test. 
Removed perl-sub cruft in mysql-test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
  register my_off_t pos;
24
24
  uint i;
25
25
  uchar old_key[MI_MAX_KEY_BUFF],*new_key;
26
 
  bool auto_key_changed=0;
27
 
  uint64_t changed;
 
26
  my_bool auto_key_changed=0;
 
27
  ulonglong changed;
28
28
  MYISAM_SHARE *share= info->s;
29
29
  ha_checksum old_checksum= 0;
 
30
  DBUG_ENTER("mi_update");
30
31
 
 
32
  DBUG_EXECUTE_IF("myisam_pretend_crashed_table_on_usage",
 
33
                  mi_print_error(info->s, HA_ERR_CRASHED);
 
34
                  DBUG_RETURN(my_errno= HA_ERR_CRASHED););
31
35
  if (!(info->update & HA_STATE_AKTIV))
32
36
  {
33
 
    return(my_errno=HA_ERR_KEY_NOT_FOUND);
 
37
    DBUG_RETURN(my_errno=HA_ERR_KEY_NOT_FOUND);
34
38
  }
35
39
  if (share->options & HA_OPTION_READ_ONLY_DATA)
36
40
  {
37
 
    return(my_errno=EACCES);
 
41
    DBUG_RETURN(my_errno=EACCES);
38
42
  }
39
43
  if (info->state->key_file_length >= share->base.margin_key_file_length)
40
44
  {
41
 
    return(my_errno=HA_ERR_INDEX_FILE_FULL);
 
45
    DBUG_RETURN(my_errno=HA_ERR_INDEX_FILE_FULL);
42
46
  }
43
47
  pos=info->lastpos;
44
48
  if (_mi_readinfo(info,F_WRLCK,1))
45
 
    return(my_errno);
 
49
    DBUG_RETURN(my_errno);
46
50
 
47
51
  if (share->calc_checksum)
48
52
    old_checksum=info->checksum=(*share->calc_checksum)(info,oldrec);
88
92
        info->update&= ~HA_STATE_RNEXT_SAME;
89
93
 
90
94
        if (new_length != old_length ||
91
 
            memcmp(old_key,new_key,new_length))
 
95
            memcmp((uchar*) old_key,(uchar*) new_key,new_length))
92
96
        {
93
97
          if ((int) i == info->lastinx)
94
98
            key_changed|=HA_STATE_WRITTEN;      /* Mark that keyfile changed */
95
 
          changed|=((uint64_t) 1 << i);
 
99
          changed|=((ulonglong) 1 << i);
96
100
          share->keyinfo[i].version++;
97
101
          if (share->keyinfo[i].ck_delete(info,i,old_key,old_length)) goto err;
98
102
          if (share->keyinfo[i].ck_insert(info,i,new_key,new_length)) goto err;
106
110
    If we are running with external locking, we must update the index file
107
111
    that something has changed.
108
112
  */
109
 
  if (changed)
 
113
  if (changed || !my_disable_locking)
110
114
    key_changed|= HA_STATE_CHANGED;
111
115
 
112
116
  if (share->calc_checksum)
124
128
    ha_rows org_split;
125
129
    my_off_t org_delete_link;
126
130
 
127
 
    memcpy(&state, info->state, sizeof(state));
 
131
    memcpy((char*) &state, (char*) info->state, sizeof(state));
128
132
    org_split=       share->state.split;
129
133
    org_delete_link= share->state.dellink;
130
134
    if ((*share->update_record)(info,pos,newrec))
131
135
      goto err;
132
136
    if (!key_changed &&
133
 
        (memcmp(&state, info->state, sizeof(state)) ||
 
137
        (memcmp((char*) &state, (char*) info->state, sizeof(state)) ||
134
138
         org_split != share->state.split ||
135
139
         org_delete_link != share->state.dellink))
136
140
      key_changed|= HA_STATE_CHANGED;           /* Must update index file */
143
147
 
144
148
  info->update= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED | HA_STATE_AKTIV |
145
149
                 key_changed);
 
150
  myisam_log_record(MI_LOG_UPDATE,info,newrec,info->lastpos,0);
146
151
  /*
147
152
    Every myisam function that updates myisam table must end with
148
153
    call to _mi_writeinfo(). If operation (second param of
156
161
  VOID(_mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE));
157
162
  if (info->invalidator != 0)
158
163
  {
 
164
    DBUG_PRINT("info", ("invalidator... '%s' (update)", info->filename));
159
165
    (*info->invalidator)(info->filename);
160
166
    info->invalidator=0;
161
167
  }
162
 
  return(0);
 
168
  DBUG_RETURN(0);
163
169
 
164
170
err:
 
171
  DBUG_PRINT("error",("key: %d  errno: %d",i,my_errno));
165
172
  save_errno=my_errno;
166
173
  if (changed)
167
174
    key_changed|= HA_STATE_CHANGED;
172
179
    flag=0;
173
180
    do
174
181
    {
175
 
      if (((uint64_t) 1 << i) & changed)
 
182
      if (((ulonglong) 1 << i) & changed)
176
183
      {
177
184
        {
178
185
          uint new_length=_mi_make_key(info,i,new_key,newrec,pos);
193
200
                 key_changed);
194
201
 
195
202
 err_end:
 
203
  myisam_log_record(MI_LOG_UPDATE,info,newrec,info->lastpos,my_errno);
196
204
  VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
197
205
  if (save_errno == HA_ERR_KEY_NOT_FOUND)
198
206
  {
199
207
    mi_print_error(info->s, HA_ERR_CRASHED);
200
208
    save_errno=HA_ERR_CRASHED;
201
209
  }
202
 
  return(my_errno=save_errno);
 
210
  DBUG_RETURN(my_errno=save_errno);
203
211
} /* mi_update */