~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-08 16:17:31 UTC
  • Revision ID: brian@tangent.org-20080708161731-io36j7igglok79py
DATE cleanup.

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