~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_update.c

  • Committer: Monty Taylor
  • Date: 2008-07-05 18:10:38 UTC
  • mto: This revision was merged to the branch mainline in revision 63.
  • Revision ID: monty@inaugust.com-20080705181038-0ih0nnamu5qrut0y
Fixed prototypes. Cleaned define a little bit.

Show diffs side-by-side

added added

removed removed

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