MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AsyncIoThread.hpp
1 /* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
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 Street, Fifth Floor, Boston, MA 02110-1301, USA */
15 
16 #ifndef AsyncIoThread_H
17 #define AsyncIoThread_H
18 
19 #include <kernel_types.h>
20 #include "MemoryChannel.hpp"
21 #include <signaldata/BuildIndxImpl.hpp>
22 
23 // Use this define if you want printouts from AsyncFile class
24 //#define DEBUG_ASYNCFILE
25 
26 #ifdef DEBUG_ASYNCFILE
27 #include <NdbOut.hpp>
28 #define DEBUG(x) x
29 #define PRINT_ERRORANDFLAGS(f) printErrorAndFlags(f)
30 void printErrorAndFlags(Uint32 used_flags);
31 #else
32 #define DEBUG(x)
33 #define PRINT_ERRORANDFLAGS(f)
34 #endif
35 
36 const int ERR_ReadUnderflow = 1000;
37 
38 class AsyncFile;
39 struct Block_context;
40 
41 class Request
42 {
43 public:
44  Request() {}
45 
46  void atGet() { m_do_bind = false; }
47 
48  enum Action {
49  open,
50  close,
51  closeRemove,
52  read, // Allways leave readv directly after
53  // read because SimblockAsyncFileSystem depends on it
54  readv,
55  write,// Allways leave writev directly after
56  // write because SimblockAsyncFileSystem depends on it
57  writev,
58  writeSync,// Allways leave writevSync directly after
59  // writeSync because SimblockAsyncFileSystem depends on it
60  writevSync,
61  sync,
62  end,
63  append,
64  append_synch,
65  rmrf,
66  readPartial,
67  allocmem,
68  buildindx,
69  suspend
70  };
71  Action action;
72  union {
73  struct {
74  Uint32 flags;
75  Uint32 page_size;
76  Uint64 file_size;
77  Uint32 auto_sync_size;
78  } open;
79  struct {
80  int numberOfPages;
81  struct{
82  char *buf;
83  size_t size;
84  off_t offset;
85  } pages[32];
86  } readWrite;
87  struct {
88  const char * buf;
89  size_t size;
90  } append;
91  struct {
92  bool directory;
93  bool own_directory;
94  } rmrf;
95  struct {
96  Block_context* ctx;
97  Uint32 requestInfo;
98  Uint64 bytes;
99  } alloc;
100  struct {
101  struct mt_BuildIndxReq m_req;
102  } build;
103  struct {
104  Uint32 milliseconds;
105  } suspend;
106  } par;
107  int error;
108 
109  void set(BlockReference userReference,
110  Uint32 userPointer,
111  Uint16 filePointer);
112  BlockReference theUserReference;
113  Uint32 theUserPointer;
114  Uint16 theFilePointer;
115  // Information for open, needed if the first open action fails.
116  AsyncFile* file;
117  Uint32 theTrace;
118  bool m_do_bind;
119 
121 };
122 
123 NdbOut& operator <<(NdbOut&, const Request&);
124 
125 inline
126 void
127 Request::set(BlockReference userReference,
128  Uint32 userPointer, Uint16 filePointer)
129 {
130  theUserReference= userReference;
131  theUserPointer= userPointer;
132  theFilePointer= filePointer;
133 }
134 
136 {
137  friend class Ndbfs;
138  friend class AsyncFile;
139 public:
140  AsyncIoThread(class Ndbfs&, bool bound);
141  virtual ~AsyncIoThread() {};
142 
143  struct NdbThread* doStart();
144  void shutdown();
145 
146  // its a thread so its always running
147  void run();
148 
153  void dispatch(Request*);
154 
155  AsyncFile * m_current_file;
156  Request *m_current_request, *m_last_request;
157 
158 private:
159  Ndbfs & m_fs;
160 
161  MemoryChannel<Request> *theReportTo;
162  MemoryChannel<Request> *theMemoryChannelPtr;
163  MemoryChannel<Request> theMemoryChannel; // If file-bound
164 
165  bool theStartFlag;
166  struct NdbThread* theThreadPtr;
167  NdbMutex* theStartMutexPtr;
168  NdbCondition* theStartConditionPtr;
169 
173  void allocMemReq(Request*);
174 
178  void buildIndxReq(Request*);
179 
180  void attach(AsyncFile*);
181  void detach(AsyncFile*);
182 };
183 
184 #endif