~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_write.c

  • Committer: Brian Aker
  • Date: 2008-08-05 06:19:05 UTC
  • mfrom: (244.1.1 drizzle-mem-ebay)
  • mto: This revision was merged to the branch mainline in revision 264.
  • Revision ID: brian@tangent.org-20080805061905-1r8krslxae65qh76
Merge from Harrison Fisk of the Ebay + Google Hash engine.

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);
29
28
static HASH_INFO *hp_find_free_hash(HP_SHARE *info, HP_BLOCK *block,
30
29
                                     ulong records);
31
30
 
34
33
  HP_KEYDEF *keydef, *end;
35
34
  uchar *pos;
36
35
  HP_SHARE *share=info->s;
37
 
  if (!(pos=next_free_record_pos(share)))
 
36
  uint 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)))
38
47
    return(my_errno);
39
48
  share->changed=1;
40
49
 
45
54
      goto err;
46
55
  }
47
56
 
48
 
  memcpy(pos,record,(size_t) share->reclength);
49
 
  pos[share->reclength]=1;              /* Mark record as not deleted */
 
57
  hp_copy_record_data_to_chunkset(share, record, pos);
 
58
 
50
59
  if (++share->records == share->blength)
51
60
    share->blength+= share->blength;
 
61
 
52
62
  info->current_ptr=pos;
53
63
  info->current_hash_ptr=0;
54
64
  info->update|=HA_STATE_AKTIV;
75
85
    keydef--;
76
86
  } 
77
87
 
78
 
  share->deleted++;
79
 
  *((uchar**) pos)=share->del_link;
80
 
  share->del_link=pos;
81
 
  pos[share->reclength]=0;                      /* Record deleted */
 
88
  hp_free_chunks(&share->recordspace, pos);
82
89
 
83
90
  return(my_errno);
84
91
} /* heap_write */
116
123
  return 0;
117
124
}
118
125
 
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
 
 
151
126
/*
152
127
  Write a hash-key to the hash-index
153
128
  SYNOPSIS