~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/memory/hp_update.cc

  • Committer: Brian Aker
  • Date: 2010-12-08 22:35:56 UTC
  • mfrom: (1819.9.158 update-innobase)
  • Revision ID: brian@tangent.org-20101208223556-37mi4omqg7lkjzf3
Merge in Stewart's changes, 1.3 changes.

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
16
/* Update current record in heap-database */
17
17
 
18
 
#include "heapdef.h"
 
18
#include "heap_priv.h"
 
19
 
 
20
using namespace drizzled;
19
21
 
20
22
int heap_update(HP_INFO *info, const unsigned char *old_record, const unsigned char *new_record)
21
23
{
22
24
  HP_KEYDEF *keydef, *end, *p_lastinx;
23
25
  unsigned char *pos;
24
26
  bool auto_key_changed= 0;
25
 
  HP_SHARE *share= info->s;
26
 
  uint32_t old_length, new_length;
27
 
  uint32_t old_chunk_count, new_chunk_count;
 
27
  HP_SHARE *share= info->getShare();
28
28
 
29
29
  test_active(info);
30
30
  pos=info->current_ptr;
31
31
 
32
32
  if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,old_record))
33
 
    return(my_errno);                           /* Record changed */
34
 
 
35
 
  old_length = hp_get_encoded_data_length(share, old_record, &old_chunk_count);
36
 
  new_length = hp_get_encoded_data_length(share, new_record, &new_chunk_count);
37
 
 
38
 
  if (new_chunk_count > old_chunk_count) {
39
 
    /* extend the old chunkset size as necessary, but do not shrink yet */
40
 
    if (hp_reallocate_chunkset(&share->recordspace, new_chunk_count, pos)) {
41
 
      return(my_errno);                          /* Out of memory or table space */
42
 
    }
43
 
  }
44
 
 
 
33
    return(errno);                              /* Record changed */
 
34
 
45
35
  if (--(share->records) < share->blength >> 1) share->blength>>= 1;
46
36
  share->changed=1;
47
37
 
50
40
  {
51
41
    if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
52
42
    {
53
 
      if ((*keydef->delete_key)(info, keydef, old_record, pos, keydef == p_lastinx) ||
54
 
          (*keydef->write_key)(info, keydef, new_record, pos))
 
43
      if (hp_delete_key(info, keydef, old_record, pos, keydef == p_lastinx) ||
 
44
          hp_write_key(info, keydef, new_record, pos))
 
45
      {
55
46
        goto err;
 
47
      }
56
48
      if (share->auto_key == (uint) (keydef - share->keydef + 1))
57
49
        auto_key_changed= 1;
58
50
    }
60
52
  hp_copy_record_data_to_chunkset(share, new_record, pos);
61
53
  if (++(share->records) == share->blength) share->blength+= share->blength;
62
54
 
63
 
  if (new_chunk_count < old_chunk_count) {
64
 
    /* Shrink the chunkset to its new size */
65
 
    hp_reallocate_chunkset(&share->recordspace, new_chunk_count, pos);
66
 
  }
67
 
 
68
55
  if (auto_key_changed)
69
56
    heap_update_auto_increment(info, new_record);
70
57
  return(0);
71
58
 
72
59
 err:
73
 
  if (my_errno == HA_ERR_FOUND_DUPP_KEY)
 
60
  if (errno == HA_ERR_FOUND_DUPP_KEY)
74
61
  {
75
62
    info->errkey = (int) (keydef - share->keydef);
76
 
    if (keydef->algorithm == HA_KEY_ALG_BTREE)
77
 
    {
78
 
      /* we don't need to delete non-inserted key from rb-tree */
79
 
      if ((*keydef->write_key)(info, keydef, old_record, pos))
80
 
      {
81
 
        if (++(share->records) == share->blength)
82
 
          share->blength+= share->blength;
83
 
        return(my_errno);
84
 
      }
85
 
      keydef--;
86
 
    }
87
63
    while (keydef >= share->keydef)
88
64
    {
89
65
      if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
90
66
      {
91
 
        if ((*keydef->delete_key)(info, keydef, new_record, pos, 0) ||
92
 
            (*keydef->write_key)(info, keydef, old_record, pos))
 
67
        if (hp_delete_key(info, keydef, new_record, pos, 0) ||
 
68
            hp_write_key(info, keydef, old_record, pos))
93
69
          break;
94
70
      }
95
71
      keydef--;
99
75
  if (++(share->records) == share->blength)
100
76
    share->blength+= share->blength;
101
77
 
102
 
  if (new_chunk_count > old_chunk_count) {
103
 
    /* Shrink the chunkset to its original size */
104
 
    hp_reallocate_chunkset(&share->recordspace, old_chunk_count, pos);
105
 
  }
106
 
 
107
 
  return(my_errno);
 
78
  return(errno);
108
79
} /* heap_update */