~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_write.c

  • Committer: Patrick Galbraith
  • Date: 2008-07-24 16:57:40 UTC
  • mto: (202.2.4 rename-mysql-to-drizzle)
  • mto: This revision was merged to the branch mainline in revision 212.
  • Revision ID: patg@ishvara-20080724165740-x58yw6zs6d9o17lf
Most everything working with client rename
mysqlslap test still fails... can't connect to the server

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#define HIGHFIND 4
26
26
#define HIGHUSED 8
27
27
 
 
28
static uchar *next_free_record_pos(HP_SHARE *info);
28
29
static HASH_INFO *hp_find_free_hash(HP_SHARE *info, HP_BLOCK *block,
29
 
                                     uint32_t records);
 
30
                                     ulong records);
30
31
 
31
 
int heap_write(HP_INFO *info, const unsigned char *record)
 
32
int heap_write(HP_INFO *info, const uchar *record)
32
33
{
33
34
  HP_KEYDEF *keydef, *end;
34
 
  unsigned char *pos;
 
35
  uchar *pos;
35
36
  HP_SHARE *share=info->s;
36
 
  uint32_t rec_length, chunk_count;
37
 
 
38
 
  if ((share->records >= share->max_records && share->max_records) ||
39
 
    (share->recordspace.total_data_length + share->index_length >= share->max_table_size))
40
 
  {
41
 
    return(my_errno=HA_ERR_RECORD_FILE_FULL);
42
 
  }
43
 
 
44
 
  rec_length = hp_get_encoded_data_length(share, record, &chunk_count);
45
 
 
46
 
  if (!(pos=hp_allocate_chunkset(&share->recordspace, chunk_count)))
 
37
  if (!(pos=next_free_record_pos(share)))
47
38
    return(my_errno);
48
39
  share->changed=1;
49
40
 
54
45
      goto err;
55
46
  }
56
47
 
57
 
  hp_copy_record_data_to_chunkset(share, record, pos);
58
 
 
 
48
  memcpy(pos,record,(size_t) share->reclength);
 
49
  pos[share->reclength]=1;              /* Mark record as not deleted */
59
50
  if (++share->records == share->blength)
60
51
    share->blength+= share->blength;
61
 
 
62
52
  info->current_ptr=pos;
63
53
  info->current_hash_ptr=0;
64
54
  info->update|=HA_STATE_AKTIV;
85
75
    keydef--;
86
76
  } 
87
77
 
88
 
  hp_free_chunks(&share->recordspace, pos);
 
78
  share->deleted++;
 
79
  *((uchar**) pos)=share->del_link;
 
80
  share->del_link=pos;
 
81
  pos[share->reclength]=0;                      /* Record deleted */
89
82
 
90
83
  return(my_errno);
91
84
} /* heap_write */
94
87
  Write a key to rb_tree-index 
95
88
*/
96
89
 
97
 
int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const unsigned char *record, 
98
 
                    unsigned char *recpos)
 
90
int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record, 
 
91
                    uchar *recpos)
99
92
{
100
93
  heap_rb_param custom_arg;
101
 
  uint32_t old_allocated;
 
94
  uint old_allocated;
102
95
 
103
96
  custom_arg.keyseg= keyinfo->seg;
104
97
  custom_arg.key_length= hp_rb_make_key(keyinfo, info->recbuf, record, recpos);
123
116
  return 0;
124
117
}
125
118
 
 
119
        /* Find where to place new record */
 
120
 
 
121
static uchar *next_free_record_pos(HP_SHARE *info)
 
122
{
 
123
  int block_pos;
 
124
  uchar *pos;
 
125
  size_t length;
 
126
 
 
127
  if (info->del_link)
 
128
  {
 
129
    pos=info->del_link;
 
130
    info->del_link= *((uchar**) pos);
 
131
    info->deleted--;
 
132
    return(pos);
 
133
  }
 
134
  if (!(block_pos=(info->records % info->block.records_in_block)))
 
135
  {
 
136
    if ((info->records > info->max_records && info->max_records) ||
 
137
        (info->data_length + info->index_length >= info->max_table_size))
 
138
    {
 
139
      my_errno=HA_ERR_RECORD_FILE_FULL;
 
140
      return(NULL);
 
141
    }
 
142
    if (hp_get_new_block(&info->block,&length))
 
143
      return(NULL);
 
144
    info->data_length+=length;
 
145
  }
 
146
  return((uchar*) info->block.level_info[0].last_blocks+
 
147
              block_pos*info->block.recbuffer);
 
148
}
 
149
 
 
150
 
126
151
/*
127
152
  Write a hash-key to the hash-index
128
153
  SYNOPSIS
149
174
*/
150
175
 
151
176
int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
152
 
                 const unsigned char *record, unsigned char *recpos)
 
177
                 const uchar *record, uchar *recpos)
153
178
{
154
179
  HP_SHARE *share = info->s;
155
180
  int flag;
156
 
  uint32_t halfbuff,hashnr,first_index;
157
 
  unsigned char *ptr_to_rec= NULL,*ptr_to_rec2= NULL;
 
181
  ulong halfbuff,hashnr,first_index;
 
182
  uchar *ptr_to_rec= NULL,*ptr_to_rec2= NULL;
158
183
  HASH_INFO *empty, *gpos= NULL, *gpos2= NULL, *pos;
159
184
 
160
185
  flag=0;
341
366
        /* Returns ptr to block, and allocates block if neaded */
342
367
 
343
368
static HASH_INFO *hp_find_free_hash(HP_SHARE *info,
344
 
                                     HP_BLOCK *block, uint32_t records)
 
369
                                     HP_BLOCK *block, ulong records)
345
370
{
346
 
  uint32_t block_pos;
 
371
  uint block_pos;
347
372
  size_t length;
348
373
 
349
374
  if (records < block->last_allocated)
355
380
    info->index_length+=length;
356
381
  }
357
382
  block->last_allocated=records+1;
358
 
  return((HASH_INFO*) ((unsigned char*) block->level_info[0].last_blocks+
 
383
  return((HASH_INFO*) ((uchar*) block->level_info[0].last_blocks+
359
384
                       block_pos*block->recbuffer));
360
385
}