1 /* Copyright (C) 2014 InfiniDB, Inc.
2 
3    This program is free software; you can redistribute it and/or
4    modify it under the terms of the GNU General Public License
5    as published by the Free Software Foundation; version 2 of
6    the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16    MA 02110-1301, USA. */
17 
18 #ifndef IOMANAGER_H
19 #define IOMANAGER_H
20 // $Id: iomanager.h 2145 2013-08-09 22:38:19Z wweeks $
21 //
22 // C++ Interface: iomanager
23 //
24 // Description:
25 //
26 //
27 // Author: Jason Rodriguez <jrodriguez@calpont.com>
28 //
29 //
30 //
31 
32 /**
33 	@author Jason Rodriguez <jrodriguez@calpont.com>
34 */
35 
36 #include <iostream>
37 #include <iomanip>
38 #include <string>
39 #include <boost/thread.hpp>
40 #include "writeengine.h"
41 #include "configcpp.h"
42 #include "brm.h"
43 #include "fileblockrequestqueue.h"
44 #include "filebuffermgr.h"
45 
46 //#define SHARED_NOTHING_DEMO_2
47 
48 namespace dbbc
49 {
50 
51 class ioManager
52 {
53 
54 public:
55 
56     ioManager(FileBufferMgr& fbm, fileBlockRequestQueue& fbrq, int thrCount,
57               int bsPerRead);
58     //ioManager(FileBufferMgr& fbm, int thrCount);
59     ~ioManager();
readerCount()60     int readerCount() const
61     {
62         return fThreadCount;
63     }
64     fileRequest* getNextRequest();
65     void go(void);
66     void stop();
fileBufferManager()67     FileBufferMgr& fileBufferManager()
68     {
69         return fIOMfbMgr;
70     }
configPtr()71     config::Config* configPtr()
72     {
73         return fConfig;
74     }
75 
76     int localLbidLookup(BRM::LBID_t lbid,
77                               BRM::VER_t verid,
78                               bool vbFlag,
79                               BRM::OID_t& oid,
80                               uint16_t& dbRoot,
81                               uint32_t& partitionNum,
82                               uint16_t& segmentNum,
83                               uint32_t& fileBlockOffset);
84 
85     void buildOidFileName(const BRM::OID_t oid,
86                           uint16_t dbRoot,
87                           const uint32_t partNum,
88                           const uint16_t segNum,
89                           char* file_name);
90 
getExtentRows()91     uint32_t getExtentRows()
92     {
93         return fdbrm.getExtentRows();
94     }
95 
96     uint32_t blocksPerRead;
97 
IOTrace()98     bool IOTrace() const
99     {
100         return fIOTrace;
101     }
102 
MaxOpenFiles()103     uint32_t MaxOpenFiles() const
104     {
105         return fMaxOpenFiles;
106     }
107 
DecreaseOpenFilesCount()108     uint32_t DecreaseOpenFilesCount() const
109     {
110         return fDecreaseOpenFilesCount;
111     }
112 
FDCacheTrace()113     bool FDCacheTrace() const
114     {
115         return fFDCacheTrace;
116     }
117 
118     void handleBlockReadError ( fileRequest* fr,
119                                 const std::string& errMsg, bool* copyLocked, int errorCode = fileRequest::FAILED );
120 
FDTraceFile()121     std::ofstream& FDTraceFile()
122     {
123         return fFDTraceFile;
124     }
125 
dbrm()126     BRM::DBRM* dbrm()
127     {
128         return &fdbrm;
129     }
130 
131 
132 #ifdef SHARED_NOTHING_DEMO_2
133     uint32_t pmCount;
134 #endif
135 
136 private:
137 
138     FileBufferMgr& fIOMfbMgr;
139     fileBlockRequestQueue& fIOMRequestQueue;
140     int fThreadCount;
141     boost::thread_group fThreadArr;
142     void createReaders();
143     config::Config* fConfig;
144     BRM::DBRM fdbrm;
145     WriteEngine::FileOp fFileOp;
146 
147     // do not implement
148     ioManager();
149     ioManager(const ioManager& iom);
150     const ioManager& operator=(const ioManager& iom);
151     bool fIOTrace;
152     uint32_t fMaxOpenFiles;
153     uint32_t fDecreaseOpenFilesCount;
154     bool fFDCacheTrace;
155     std::ofstream fFDTraceFile;
156 };
157 
158 // @bug2631, for remount filesystem by loadBlock() in primitiveserver
159 // Shared Nothing update: Remount is no longer necessary, might have a use for these though.
160 void setReadLock();
161 void releaseReadLock();
162 void dropFDCache();
163 void purgeFDCache(std::vector<BRM::FileInfo>& files);
164 
165 }
166 #endif
167 // vim:ts=4 sw=4:
168