~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/hp_write.cc

fix pthread atomics. operator precedence is important. The unit test now passes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* Write a record to heap-databas */
17
17
 
34
34
{
35
35
  HP_KEYDEF *keydef, *end;
36
36
  unsigned char *pos;
37
 
  HP_SHARE *share=info->getShare();
 
37
  HP_SHARE *share=info->s;
 
38
  uint32_t rec_length, chunk_count;
38
39
 
39
40
  if ((share->records >= share->max_records && share->max_records) ||
40
41
    (share->recordspace.total_data_length + share->index_length >= share->max_table_size))
42
43
    return(errno=HA_ERR_RECORD_FILE_FULL);
43
44
  }
44
45
 
45
 
  if (!(pos=hp_allocate_chunkset(&share->recordspace, 1)))
 
46
  rec_length = hp_get_encoded_data_length(share, record, &chunk_count);
 
47
 
 
48
  if (!(pos=hp_allocate_chunkset(&share->recordspace, chunk_count)))
46
49
    return(errno);
47
50
  share->changed=1;
48
51
 
49
52
  for (keydef = share->keydef, end = keydef + share->keys; keydef < end;
50
53
       keydef++)
51
54
  {
52
 
    if (hp_write_key(info, keydef, record, pos))
 
55
    if ((*keydef->write_key)(info, keydef, record, pos))
53
56
      goto err;
54
57
  }
55
58
 
67
70
 
68
71
err:
69
72
  info->errkey= keydef - share->keydef;
 
73
  /*
 
74
    We don't need to delete non-inserted key from rb-tree.  Also, if
 
75
    we got ENOMEM, the key wasn't inserted, so don't try to delete it
 
76
    either.  Otherwise for HASH index on HA_ERR_FOUND_DUPP_KEY the key
 
77
    was inserted and we have to delete it.
 
78
  */
 
79
  if (keydef->algorithm == HA_KEY_ALG_BTREE || errno == ENOMEM)
 
80
  {
 
81
    keydef--;
 
82
  }
70
83
  while (keydef >= share->keydef)
71
84
  {
72
 
    if (hp_delete_key(info, keydef, record, pos, 0))
 
85
    if ((*keydef->delete_key)(info, keydef, record, pos, 0))
73
86
      break;
74
87
    keydef--;
75
88
  }
80
93
} /* heap_write */
81
94
 
82
95
/*
 
96
  Write a key to rb_tree-index
 
97
*/
 
98
 
 
99
int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const unsigned char *record,
 
100
                    unsigned char *recpos)
 
101
{
 
102
  heap_rb_param custom_arg;
 
103
  uint32_t old_allocated;
 
104
 
 
105
  custom_arg.keyseg= keyinfo->seg;
 
106
  custom_arg.key_length= hp_rb_make_key(keyinfo, info->recbuf, record, recpos);
 
107
  if (keyinfo->flag & HA_NOSAME)
 
108
  {
 
109
    custom_arg.search_flag= SEARCH_FIND | SEARCH_UPDATE;
 
110
    keyinfo->rb_tree.flag= TREE_NO_DUPS;
 
111
  }
 
112
  else
 
113
  {
 
114
    custom_arg.search_flag= SEARCH_SAME;
 
115
    keyinfo->rb_tree.flag= 0;
 
116
  }
 
117
  old_allocated= keyinfo->rb_tree.allocated;
 
118
  if (!tree_insert(&keyinfo->rb_tree, (void*)info->recbuf,
 
119
                   custom_arg.key_length, &custom_arg))
 
120
  {
 
121
    errno= HA_ERR_FOUND_DUPP_KEY;
 
122
    return 1;
 
123
  }
 
124
  info->s->index_length+= (keyinfo->rb_tree.allocated-old_allocated);
 
125
  return 0;
 
126
}
 
127
 
 
128
/*
83
129
  Write a hash-key to the hash-index
84
130
  SYNOPSIS
85
131
    info     Heap table info
107
153
int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
108
154
                 const unsigned char *record, unsigned char *recpos)
109
155
{
110
 
  HP_SHARE *share = info->getShare();
 
156
  HP_SHARE *share = info->s;
111
157
  int flag;
112
158
  uint32_t halfbuff,hashnr,first_index;
113
159
  unsigned char *ptr_to_rec= NULL,*ptr_to_rec2= NULL;