~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_cache.cc

  • Committer: Stewart Smith
  • Date: 2009-06-16 06:55:11 UTC
  • mto: This revision was merged to the branch mainline in revision 1094.
  • Revision ID: stewart@flamingspork.com-20090616065511-ps3ewfxj7918lwy3
rollback.test for MyISAM temp only.
- rename to myisam_rollback to reflect what it's testing
- just use create temporary table

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2003 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
 
 
16
 
/*
17
 
  Functions for read record cacheing with myisam
18
 
  Used for reading dynamic/compressed records from datafile.
19
 
 
20
 
  Can fetch data directly from file (outside cache),
21
 
  if reading a small chunk straight before the cached part (with possible
22
 
  overlap).
23
 
 
24
 
  Can be explicitly asked not to use cache (by not setting READING_NEXT in
25
 
  flag) - useful for occasional out-of-cache reads, when the next read is
26
 
  expected to hit the cache again.
27
 
 
28
 
  Allows "partial read" errors in the record header (when READING_HEADER flag
29
 
  is set) - unread part is zero'ed
30
 
 
31
 
  Note: out-of-cache reads are enabled for shared IO_CACHE's too,
32
 
  as these reads will be cached by OS cache (and my_pread is always atomic)
33
 
*/
34
 
 
35
 
 
36
 
#include "myisam_priv.h"
37
 
 
38
 
#include <algorithm>
39
 
 
40
 
using namespace std;
41
 
using namespace drizzled;
42
 
 
43
 
 
44
 
int _mi_read_cache(internal::IO_CACHE *info, unsigned char *buff, internal::my_off_t pos, uint32_t length,
45
 
                   int flag)
46
 
{
47
 
  uint32_t read_length,in_buff_length;
48
 
  internal::my_off_t offset;
49
 
  unsigned char *in_buff_pos;
50
 
 
51
 
  if (pos < info->pos_in_file)
52
 
  {
53
 
    read_length=length;
54
 
    if ((internal::my_off_t) read_length > (internal::my_off_t) (info->pos_in_file-pos))
55
 
      read_length=(uint) (info->pos_in_file-pos);
56
 
    info->seek_not_done=1;
57
 
    if (my_pread(info->file,buff,read_length,pos,MYF(MY_NABP)))
58
 
      return(1);
59
 
    if (!(length-=read_length))
60
 
      return(0);
61
 
    pos+=read_length;
62
 
    buff+=read_length;
63
 
  }
64
 
  if (pos >= info->pos_in_file &&
65
 
      (offset= (internal::my_off_t) (pos - info->pos_in_file)) <
66
 
      (internal::my_off_t) (info->read_end - info->request_pos))
67
 
  {
68
 
    in_buff_pos=info->request_pos+(uint) offset;
69
 
    in_buff_length= min(length, (uint32_t) (info->read_end-in_buff_pos));
70
 
    memcpy(buff,info->request_pos+(uint) offset,(size_t) in_buff_length);
71
 
    if (!(length-=in_buff_length))
72
 
      return(0);
73
 
    pos+=in_buff_length;
74
 
    buff+=in_buff_length;
75
 
  }
76
 
  else
77
 
    in_buff_length=0;
78
 
  if (flag & READING_NEXT)
79
 
  {
80
 
    if (pos != (info->pos_in_file +
81
 
                (uint) (info->read_end - info->request_pos)))
82
 
    {
83
 
      info->pos_in_file=pos;                            /* Force start here */
84
 
      info->read_pos=info->read_end=info->request_pos;  /* Everything used */
85
 
      info->seek_not_done=1;
86
 
    }
87
 
    else
88
 
      info->read_pos=info->read_end;                    /* All block used */
89
 
    if (!(*info->read_function)(info,buff,length))
90
 
      return(0);
91
 
    read_length=info->error;
92
 
  }
93
 
  else
94
 
  {
95
 
    info->seek_not_done=1;
96
 
    if ((read_length=my_pread(info->file,buff,length,pos,MYF(0))) == length)
97
 
      return(0);
98
 
  }
99
 
  if (!(flag & READING_HEADER) || (int) read_length == -1 ||
100
 
      read_length+in_buff_length < 3)
101
 
  {
102
 
    if (!errno || errno == -1)
103
 
      errno=HA_ERR_WRONG_IN_RECORD;
104
 
    return(1);
105
 
  }
106
 
  memset(buff+read_length, 0,
107
 
         MI_BLOCK_INFO_HEADER_LENGTH - in_buff_length - read_length);
108
 
  return(0);
109
 
} /* _mi_read_cache */