~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_page.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000-2004, 2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
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 */
 
15
 
 
16
/* Read and write key blocks */
 
17
 
 
18
#include "myisam_priv.h"
 
19
 
 
20
using namespace drizzled;
 
21
 
 
22
        /* Fetch a key-page in memory */
 
23
 
 
24
unsigned char *_mi_fetch_keypage(register MI_INFO *info, MI_KEYDEF *keyinfo,
 
25
                         internal::my_off_t page, int level,
 
26
                         unsigned char *buff, int return_buffer)
 
27
{
 
28
  unsigned char *tmp;
 
29
  uint32_t page_size;
 
30
 
 
31
  tmp=(unsigned char*) key_cache_read(info->s->key_cache,
 
32
                             info->s->kfile, page, level, (unsigned char*) buff,
 
33
                             (uint) keyinfo->block_length,
 
34
                             (uint) keyinfo->block_length,
 
35
                             return_buffer);
 
36
  if (tmp == info->buff)
 
37
    info->buff_used=1;
 
38
  else if (!tmp)
 
39
  {
 
40
    info->last_keypage=HA_OFFSET_ERROR;
 
41
    mi_print_error(info->s, HA_ERR_CRASHED);
 
42
    errno=HA_ERR_CRASHED;
 
43
    return(0);
 
44
  }
 
45
  info->last_keypage=page;
 
46
  page_size=mi_getint(tmp);
 
47
  if (page_size < 4 || page_size > keyinfo->block_length)
 
48
  {
 
49
    info->last_keypage = HA_OFFSET_ERROR;
 
50
    mi_print_error(info->s, HA_ERR_CRASHED);
 
51
    errno = HA_ERR_CRASHED;
 
52
    tmp = 0;
 
53
  }
 
54
  return(tmp);
 
55
} /* _mi_fetch_keypage */
 
56
 
 
57
 
 
58
        /* Write a key-page on disk */
 
59
 
 
60
int _mi_write_keypage(register MI_INFO *info, register MI_KEYDEF *keyinfo,
 
61
                      internal::my_off_t page, int level, unsigned char *buff)
 
62
{
 
63
  register uint32_t length;
 
64
 
 
65
#ifndef FAST                                    /* Safety check */
 
66
  if (page < info->s->base.keystart ||
 
67
      page+keyinfo->block_length > info->state->key_file_length ||
 
68
      (page & (MI_MIN_KEY_BLOCK_LENGTH-1)))
 
69
  {
 
70
    errno=EINVAL;
 
71
    return((-1));
 
72
  }
 
73
#endif
 
74
 
 
75
  if ((length=keyinfo->block_length) > IO_SIZE*2 &&
 
76
      info->state->key_file_length != page+length)
 
77
    length= ((mi_getint(buff)+IO_SIZE-1) & (uint) ~(IO_SIZE-1));
 
78
#ifdef HAVE_purify
 
79
  {
 
80
    length=mi_getint(buff);
 
81
    memset(buff+length, 0, keyinfo->block_length-length);
 
82
    length=keyinfo->block_length;
 
83
  }
 
84
#endif
 
85
  return((key_cache_write(info->s->key_cache,
 
86
                         info->s->kfile,page, level, (unsigned char*) buff,length,
 
87
                         (uint) keyinfo->block_length,
 
88
                         (int) ((info->lock_type != F_UNLCK) ||
 
89
                                info->s->delay_key_write))));
 
90
} /* mi_write_keypage */
 
91
 
 
92
 
 
93
        /* Remove page from disk */
 
94
 
 
95
int _mi_dispose(register MI_INFO *info, MI_KEYDEF *keyinfo, internal::my_off_t pos,
 
96
                int level)
 
97
{
 
98
  internal::my_off_t old_link;
 
99
  unsigned char buff[8];
 
100
 
 
101
  old_link= info->s->state.key_del[keyinfo->block_size_index];
 
102
  info->s->state.key_del[keyinfo->block_size_index]= pos;
 
103
  mi_sizestore(buff,old_link);
 
104
  info->s->state.changed|= STATE_NOT_SORTED_PAGES;
 
105
  return(key_cache_write(info->s->key_cache,
 
106
                              info->s->kfile, pos , level, buff,
 
107
                              sizeof(buff),
 
108
                              (uint) keyinfo->block_length,
 
109
                              (int) (info->lock_type != F_UNLCK)));
 
110
} /* _mi_dispose */
 
111
 
 
112
 
 
113
        /* Make new page on disk */
 
114
 
 
115
internal::my_off_t _mi_new(register MI_INFO *info, MI_KEYDEF *keyinfo, int level)
 
116
{
 
117
  internal::my_off_t pos;
 
118
  unsigned char buff[8];
 
119
 
 
120
  if ((pos= info->s->state.key_del[keyinfo->block_size_index]) ==
 
121
      HA_OFFSET_ERROR)
 
122
  {
 
123
    if (info->state->key_file_length >=
 
124
        info->s->base.max_key_file_length - keyinfo->block_length)
 
125
    {
 
126
      errno=HA_ERR_INDEX_FILE_FULL;
 
127
      return(HA_OFFSET_ERROR);
 
128
    }
 
129
    pos=info->state->key_file_length;
 
130
    info->state->key_file_length+= keyinfo->block_length;
 
131
  }
 
132
  else
 
133
  {
 
134
    if (!key_cache_read(info->s->key_cache,
 
135
                        info->s->kfile, pos, level,
 
136
                        buff,
 
137
                        (uint) sizeof(buff),
 
138
                        (uint) keyinfo->block_length,0))
 
139
      pos= HA_OFFSET_ERROR;
 
140
    else
 
141
      info->s->state.key_del[keyinfo->block_size_index]= mi_sizekorr(buff);
 
142
  }
 
143
  info->s->state.changed|= STATE_NOT_SORTED_PAGES;
 
144
  return(pos);
 
145
} /* _mi_new */