~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_update.c

  • Committer: Brian Aker
  • Date: 2008-07-13 21:20:24 UTC
  • Revision ID: brian@tangent.org-20080713212024-o6263c1vha7yxdeu
More bool removal. More cow bell!

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
/* Update an old row in a MyISAM table */
17
17
 
18
18
#include "myisamdef.h"
19
 
#include <drizzled/util/test.h>
20
19
 
21
 
int mi_update(register MI_INFO *info, const unsigned char *oldrec, unsigned char *newrec)
 
20
int mi_update(register MI_INFO *info, const uchar *oldrec, uchar *newrec)
22
21
{
23
22
  int flag,key_changed,save_errno;
24
23
  register my_off_t pos;
25
 
  uint32_t i;
26
 
  unsigned char old_key[MI_MAX_KEY_BUFF],*new_key;
27
 
  bool auto_key_changed=0;
28
 
  uint64_t changed;
 
24
  uint i;
 
25
  uchar old_key[MI_MAX_KEY_BUFF],*new_key;
 
26
  my_bool auto_key_changed=0;
 
27
  ulonglong changed;
29
28
  MYISAM_SHARE *share= info->s;
30
29
  ha_checksum old_checksum= 0;
 
30
  DBUG_ENTER("mi_update");
31
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););
32
35
  if (!(info->update & HA_STATE_AKTIV))
33
36
  {
34
 
    return(my_errno=HA_ERR_KEY_NOT_FOUND);
 
37
    DBUG_RETURN(my_errno=HA_ERR_KEY_NOT_FOUND);
35
38
  }
36
39
  if (share->options & HA_OPTION_READ_ONLY_DATA)
37
40
  {
38
 
    return(my_errno=EACCES);
 
41
    DBUG_RETURN(my_errno=EACCES);
39
42
  }
40
43
  if (info->state->key_file_length >= share->base.margin_key_file_length)
41
44
  {
42
 
    return(my_errno=HA_ERR_INDEX_FILE_FULL);
 
45
    DBUG_RETURN(my_errno=HA_ERR_INDEX_FILE_FULL);
43
46
  }
44
47
  pos=info->lastpos;
45
48
  if (_mi_readinfo(info,F_WRLCK,1))
46
 
    return(my_errno);
 
49
    DBUG_RETURN(my_errno);
47
50
 
48
51
  if (share->calc_checksum)
49
52
    old_checksum=info->checksum=(*share->calc_checksum)(info,oldrec);
82
85
    if (mi_is_key_active(share->state.key_map, i))
83
86
    {
84
87
      {
85
 
        uint32_t new_length=_mi_make_key(info,i,new_key,newrec,pos);
86
 
        uint32_t old_length=_mi_make_key(info,i,old_key,oldrec,pos);
 
88
        uint new_length=_mi_make_key(info,i,new_key,newrec,pos);
 
89
        uint old_length=_mi_make_key(info,i,old_key,oldrec,pos);
87
90
 
88
91
        /* The above changed info->lastkey2. Inform mi_rnext_same(). */
89
92
        info->update&= ~HA_STATE_RNEXT_SAME;
90
93
 
91
94
        if (new_length != old_length ||
92
 
            memcmp(old_key,new_key,new_length))
 
95
            memcmp((uchar*) old_key,(uchar*) new_key,new_length))
93
96
        {
94
97
          if ((int) i == info->lastinx)
95
98
            key_changed|=HA_STATE_WRITTEN;      /* Mark that keyfile changed */
96
 
          changed|=((uint64_t) 1 << i);
 
99
          changed|=((ulonglong) 1 << i);
97
100
          share->keyinfo[i].version++;
98
101
          if (share->keyinfo[i].ck_delete(info,i,old_key,old_length)) goto err;
99
102
          if (share->keyinfo[i].ck_insert(info,i,new_key,new_length)) goto err;
107
110
    If we are running with external locking, we must update the index file
108
111
    that something has changed.
109
112
  */
110
 
  if (changed)
 
113
  if (changed || !my_disable_locking)
111
114
    key_changed|= HA_STATE_CHANGED;
112
115
 
113
116
  if (share->calc_checksum)
125
128
    ha_rows org_split;
126
129
    my_off_t org_delete_link;
127
130
 
128
 
    memcpy(&state, info->state, sizeof(state));
 
131
    memcpy((char*) &state, (char*) info->state, sizeof(state));
129
132
    org_split=       share->state.split;
130
133
    org_delete_link= share->state.dellink;
131
134
    if ((*share->update_record)(info,pos,newrec))
132
135
      goto err;
133
136
    if (!key_changed &&
134
 
        (memcmp(&state, info->state, sizeof(state)) ||
 
137
        (memcmp((char*) &state, (char*) info->state, sizeof(state)) ||
135
138
         org_split != share->state.split ||
136
139
         org_delete_link != share->state.dellink))
137
140
      key_changed|= HA_STATE_CHANGED;           /* Must update index file */
144
147
 
145
148
  info->update= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED | HA_STATE_AKTIV |
146
149
                 key_changed);
 
150
  myisam_log_record(MI_LOG_UPDATE,info,newrec,info->lastpos,0);
147
151
  /*
148
152
    Every myisam function that updates myisam table must end with
149
153
    call to _mi_writeinfo(). If operation (second param of
154
158
    mi_update() must always pass !0 value as operation, since even if
155
159
    there is no index change there could be data change.
156
160
  */
157
 
  _mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE);
 
161
  VOID(_mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE));
158
162
  if (info->invalidator != 0)
159
163
  {
 
164
    DBUG_PRINT("info", ("invalidator... '%s' (update)", info->filename));
160
165
    (*info->invalidator)(info->filename);
161
166
    info->invalidator=0;
162
167
  }
163
 
  return(0);
 
168
  DBUG_RETURN(0);
164
169
 
165
170
err:
 
171
  DBUG_PRINT("error",("key: %d  errno: %d",i,my_errno));
166
172
  save_errno=my_errno;
167
173
  if (changed)
168
174
    key_changed|= HA_STATE_CHANGED;
173
179
    flag=0;
174
180
    do
175
181
    {
176
 
      if (((uint64_t) 1 << i) & changed)
 
182
      if (((ulonglong) 1 << i) & changed)
177
183
      {
178
184
        {
179
 
          uint32_t new_length=_mi_make_key(info,i,new_key,newrec,pos);
180
 
          uint32_t old_length= _mi_make_key(info,i,old_key,oldrec,pos);
 
185
          uint new_length=_mi_make_key(info,i,new_key,newrec,pos);
 
186
          uint old_length= _mi_make_key(info,i,old_key,oldrec,pos);
181
187
          if ((flag++ && _mi_ck_delete(info,i,new_key,new_length)) ||
182
188
              _mi_ck_write(info,i,old_key,old_length))
183
189
            break;
194
200
                 key_changed);
195
201
 
196
202
 err_end:
197
 
  _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
 
203
  myisam_log_record(MI_LOG_UPDATE,info,newrec,info->lastpos,my_errno);
 
204
  VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
198
205
  if (save_errno == HA_ERR_KEY_NOT_FOUND)
199
206
  {
200
207
    mi_print_error(info->s, HA_ERR_CRASHED);
201
208
    save_errno=HA_ERR_CRASHED;
202
209
  }
203
 
  return(my_errno=save_errno);
 
210
  DBUG_RETURN(my_errno=save_errno);
204
211
} /* mi_update */