~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/hp_write.cc

Added pandora check for berkeley db.

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
 
25
25
#define HIGHFIND 4
26
26
#define HIGHUSED 8
27
27
 
28
 
using namespace drizzled;
29
 
 
30
28
static HASH_INFO *hp_find_free_hash(HP_SHARE *info, HP_BLOCK *block,
31
29
                                     uint32_t records);
32
30
 
34
32
{
35
33
  HP_KEYDEF *keydef, *end;
36
34
  unsigned char *pos;
37
 
  HP_SHARE *share=info->getShare();
 
35
  HP_SHARE *share=info->s;
 
36
  uint32_t rec_length, chunk_count;
38
37
 
39
38
  if ((share->records >= share->max_records && share->max_records) ||
40
39
    (share->recordspace.total_data_length + share->index_length >= share->max_table_size))
41
40
  {
42
 
    return(errno=HA_ERR_RECORD_FILE_FULL);
 
41
    return(my_errno=HA_ERR_RECORD_FILE_FULL);
43
42
  }
44
43
 
45
 
  if (!(pos=hp_allocate_chunkset(&share->recordspace, 1)))
46
 
    return(errno);
 
44
  rec_length = hp_get_encoded_data_length(share, record, &chunk_count);
 
45
 
 
46
  if (!(pos=hp_allocate_chunkset(&share->recordspace, chunk_count)))
 
47
    return(my_errno);
47
48
  share->changed=1;
48
49
 
49
50
  for (keydef = share->keydef, end = keydef + share->keys; keydef < end;
50
51
       keydef++)
51
52
  {
52
 
    if (hp_write_key(info, keydef, record, pos))
 
53
    if ((*keydef->write_key)(info, keydef, record, pos))
53
54
      goto err;
54
55
  }
55
56
 
67
68
 
68
69
err:
69
70
  info->errkey= keydef - share->keydef;
 
71
  /*
 
72
    We don't need to delete non-inserted key from rb-tree.  Also, if
 
73
    we got ENOMEM, the key wasn't inserted, so don't try to delete it
 
74
    either.  Otherwise for HASH index on HA_ERR_FOUND_DUPP_KEY the key
 
75
    was inserted and we have to delete it.
 
76
  */
 
77
  if (keydef->algorithm == HA_KEY_ALG_BTREE || my_errno == ENOMEM)
 
78
  {
 
79
    keydef--;
 
80
  }
70
81
  while (keydef >= share->keydef)
71
82
  {
72
 
    if (hp_delete_key(info, keydef, record, pos, 0))
 
83
    if ((*keydef->delete_key)(info, keydef, record, pos, 0))
73
84
      break;
74
85
    keydef--;
75
86
  }
76
87
 
77
88
  hp_free_chunks(&share->recordspace, pos);
78
89
 
79
 
  return(errno);
 
90
  return(my_errno);
80
91
} /* heap_write */
81
92
 
82
93
/*
 
94
  Write a key to rb_tree-index
 
95
*/
 
96
 
 
97
int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const unsigned char *record,
 
98
                    unsigned char *recpos)
 
99
{
 
100
  heap_rb_param custom_arg;
 
101
  uint32_t old_allocated;
 
102
 
 
103
  custom_arg.keyseg= keyinfo->seg;
 
104
  custom_arg.key_length= hp_rb_make_key(keyinfo, info->recbuf, record, recpos);
 
105
  if (keyinfo->flag & HA_NOSAME)
 
106
  {
 
107
    custom_arg.search_flag= SEARCH_FIND | SEARCH_UPDATE;
 
108
    keyinfo->rb_tree.flag= TREE_NO_DUPS;
 
109
  }
 
110
  else
 
111
  {
 
112
    custom_arg.search_flag= SEARCH_SAME;
 
113
    keyinfo->rb_tree.flag= 0;
 
114
  }
 
115
  old_allocated= keyinfo->rb_tree.allocated;
 
116
  if (!tree_insert(&keyinfo->rb_tree, (void*)info->recbuf,
 
117
                   custom_arg.key_length, &custom_arg))
 
118
  {
 
119
    my_errno= HA_ERR_FOUND_DUPP_KEY;
 
120
    return 1;
 
121
  }
 
122
  info->s->index_length+= (keyinfo->rb_tree.allocated-old_allocated);
 
123
  return 0;
 
124
}
 
125
 
 
126
/*
83
127
  Write a hash-key to the hash-index
84
128
  SYNOPSIS
85
129
    info     Heap table info
107
151
int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
108
152
                 const unsigned char *record, unsigned char *recpos)
109
153
{
110
 
  HP_SHARE *share = info->getShare();
 
154
  HP_SHARE *share = info->s;
111
155
  int flag;
112
156
  uint32_t halfbuff,hashnr,first_index;
113
157
  unsigned char *ptr_to_rec= NULL,*ptr_to_rec2= NULL;
286
330
      {
287
331
        if (! hp_rec_key_cmp(keyinfo, record, pos->ptr_to_rec, 1))
288
332
        {
289
 
          return(errno=HA_ERR_FOUND_DUPP_KEY);
 
333
          return(my_errno=HA_ERR_FOUND_DUPP_KEY);
290
334
        }
291
335
      } while ((pos=pos->next_key));
292
336
    }