root/trunk/dep/include/mysql/raid.h @ 219

Revision 2, 5.7 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/* Copyright (C) 2000 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/* Parser needs these defines  always, even if USE_RAID is not defined */
17#define RAID_TYPE_0 1       /* Striping */
18#define RAID_TYPE_x 2       /* Some new modes */
19#define RAID_TYPE_y 3
20
21#define RAID_DEFAULT_CHUNKS 4
22#define RAID_DEFAULT_CHUNKSIZE 256*1024 /* 256kB */
23
24C_MODE_START
25#define my_raid_type(raid_type)  raid_type_string[(int)(raid_type)]
26extern const char *raid_type_string[];
27C_MODE_END
28
29#ifdef DONT_USE_RAID
30#undef USE_RAID
31#endif
32#if defined(USE_RAID)
33
34#include "my_dir.h"
35
36/* Trap all occurences of my_...() in source and use our wrapper around this function */
37
38#ifdef MAP_TO_USE_RAID
39#define my_read(A,B,C,D)     my_raid_read(A,B,C,D)
40#define my_write(A,B,C,D)    my_raid_write(A,B,C,D)
41#define my_pwrite(A,B,C,D,E) my_raid_pwrite(A,B,C,D,E)
42#define my_pread(A,B,C,D,E)  my_raid_pread(A,B,C,D,E)
43#define my_chsize(A,B,C,D)   my_raid_chsize(A,B,C,D)
44#define my_close(A,B)        my_raid_close(A,B)
45#define my_tell(A,B)         my_raid_tell(A,B)
46#define my_seek(A,B,C,D)     my_raid_seek(A,B,C,D)
47#define my_lock(A,B,C,D,E)     my_raid_lock(A,B,C,D,E)
48#define my_fstat(A,B,C)     my_raid_fstat(A,B,C)
49#endif /* MAP_TO_USE_RAID */
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55  void init_raid(void);
56  void end_raid(void);
57
58  bool is_raid(File fd);
59  File my_raid_create(const char *FileName, int CreateFlags, int access_flags,
60                      uint raid_type, uint raid_chunks, ulong raid_chunksize,
61                      myf MyFlags);
62  File my_raid_open(const char *FileName, int Flags,
63                    uint raid_type, uint raid_chunks, ulong raid_chunksize,
64                    myf MyFlags);
65  int my_raid_rename(const char *from, const char *to, uint raid_chunks,
66                     myf MyFlags);
67  int my_raid_delete(const char *from, uint raid_chunks, myf MyFlags);
68  int my_raid_redel(const char *old_name, const char *new_name,
69                    uint raid_chunks, myf MyFlags);
70
71  my_off_t my_raid_seek(File fd, my_off_t pos, int whence, myf MyFlags);
72  my_off_t my_raid_tell(File fd, myf MyFlags);
73
74  uint my_raid_write(File,const byte *Buffer, uint Count, myf MyFlags);
75  uint my_raid_read(File Filedes, byte *Buffer, uint Count, myf MyFlags);
76
77  uint my_raid_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset,
78                     myf MyFlags);
79  uint my_raid_pwrite(int Filedes, const byte *Buffer, uint Count,
80                      my_off_t offset, myf MyFlags);
81
82  int my_raid_lock(File,int locktype, my_off_t start, my_off_t length,
83                   myf MyFlags);
84  int my_raid_chsize(File fd, my_off_t newlength, int filler, myf MyFlags);
85  int my_raid_close(File, myf MyFlags);
86  int my_raid_fstat(int Filedes, struct stat *buf,  myf MyFlags);
87
88#ifdef __cplusplus
89}
90
91#ifdef USE_PRAGMA_INTERFACE
92#pragma interface                       /* gcc class implementation */
93#endif
94
95class RaidName {
96  public:
97    RaidName(const char *FileName);
98    ~RaidName();
99    bool IsRaid();
100    int Rename(const char * from, const char * to, myf MyFlags);
101  private:
102    uint _raid_type;       /* RAID_TYPE_0 or RAID_TYPE_1 or RAID_TYPE_5 */
103    uint _raid_chunks;     /* 1..n */
104    ulong _raid_chunksize; /* 1..n in bytes */
105};
106
107class RaidFd {
108  public:
109    RaidFd(uint raid_type, uint raid_chunks , ulong raid_chunksize);
110    ~RaidFd();
111    File Create(const char *FileName, int CreateFlags, int access_flags,
112                myf MyFlags);
113    File Open(const char *FileName, int Flags, myf MyFlags);
114    my_off_t Seek(my_off_t pos,int whence,myf MyFlags);
115    my_off_t Tell(myf MyFlags);
116    int Write(const byte *Buffer, uint Count, myf MyFlags);
117    int Read(const byte *Buffer, uint Count, myf MyFlags);
118    int Lock(int locktype, my_off_t start, my_off_t length, myf MyFlags);
119    int Chsize(File fd, my_off_t newlength, int filler, myf MyFlags);
120    int Fstat(int fd, MY_STAT *stat_area, myf MyFlags );
121    int Close(myf MyFlags);
122    static bool IsRaid(File fd);
123    static DYNAMIC_ARRAY _raid_map;             /* Map of RaidFD* */
124  private:
125
126    uint _raid_type;       /* RAID_TYPE_0 or RAID_TYPE_1 or RAID_TYPE_5 */
127    uint _raid_chunks;     /* 1..n */
128    ulong _raid_chunksize; /* 1..n in bytes */
129
130    ulong _total_block;    /* We are operating with block no x (can be 0..many). */
131    uint _this_block;      /* can be 0.._raid_chunks */
132    uint _remaining_bytes; /* Maximum bytes that can be written in this block */
133
134    my_off_t _position;
135    my_off_t _size;        /* Cached file size for faster seek(SEEK_END) */
136    File _fd;
137    File *_fd_vector;           /* Array of File */
138    off_t *_seek_vector;        /* Array of cached seek positions */
139
140    inline void Calculate()
141    {
142      DBUG_ENTER("RaidFd::_Calculate");
143      DBUG_PRINT("info",("_position: %lu  _raid_chunksize: %lu  _size: %lu",
144                         (ulong) _position, _raid_chunksize, (ulong) _size));
145
146      _total_block = (ulong) (_position / _raid_chunksize);
147      _this_block = _total_block % _raid_chunks;    /* can be 0.._raid_chunks */
148      _remaining_bytes = (uint) (_raid_chunksize -
149                                 (_position - _total_block * _raid_chunksize));
150      DBUG_PRINT("info",
151                 ("_total_block: %lu  this_block: %d  _remaining_bytes: %d",
152                  _total_block, _this_block, _remaining_bytes));
153      DBUG_VOID_RETURN;
154    }
155};
156
157#endif /* __cplusplus */
158#endif /* USE_RAID */
Note: See TracBrowser for help on using the browser.