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 BLOCKREQUESTPROCESSOR_H 19 #define BLOCKREQUESTPROCESSOR_H 20 21 /*************************************************************************** 22 * 23 * $Id: blockrequestprocessor.h 725 2008-09-26 16:26:47Z jrodriguez $ 24 * 25 * jrodriguez@calpont.com * 26 * * 27 ***************************************************************************/ 28 29 30 #include "blocksize.h" 31 #include "fileblockrequestqueue.h" 32 #include "filebuffermgr.h" 33 #include "iomanager.h" 34 35 /** 36 @author Jason Rodriguez <jrodriguez@calpont.com> 37 */ 38 39 namespace dbbc 40 { 41 42 typedef std::list<FileBuffer> FileBufferList_t; 43 44 /** 45 * @brief class to control the populating of the Disk Block Buffer Cache and manage Block requests. 46 **/ 47 48 class BlockRequestProcessor 49 { 50 51 public: 52 53 /** 54 * @brief default ctor 55 **/ 56 BlockRequestProcessor(uint32_t numBlcks, int thrCount, int blocksPerRead, uint32_t deleteBlocks = 0, 57 uint32_t blckSz = BLOCK_SIZE); 58 59 /** 60 * @brief default dtor 61 **/ 62 virtual ~BlockRequestProcessor(); 63 64 /** 65 * @brief send a request for disk blocks to the IO manager 66 **/ 67 int sendRequest(fileRequest& blk); 68 69 /** 70 * @brief verify that the lbid@ver disk block is in the block cache. Send request if it is not 71 **/ 72 int check(BRM::LBID_t lbid, BRM::VER_t ver, bool flg, bool& wasBlockInCache); 73 74 /** 75 * @brief verify the LBIDRange of disk blocks is in the block cache. Send request if it is not 76 **/ 77 int check(const BRM::InlineLBIDRange& range, const BRM::VER_t ver, uint32_t& lbidCount); 78 79 /** 80 * @brief retrieve the lbid@ver disk block from the block cache 81 **/ 82 FileBuffer* getBlockPtr(const BRM::LBID_t lbid, const BRM::VER_t ver); 83 84 const int read(const BRM::LBID_t& lbid, const BRM::VER_t& ver, FileBuffer& fb); 85 86 /** 87 * @brief retrieve the lbid@ver disk block from the block cache 88 **/ 89 const int read(const BRM::LBID_t& lbid, const BRM::VER_t& ver, void* bufferPtr); 90 91 /** 92 * @brief retrieve the LBIDRange of disk blocks from the block cache 93 **/ 94 const int read(const BRM::InlineLBIDRange& range, FileBufferList_t& fbList, const BRM::VER_t ver); 95 96 const int getBlock(const BRM::LBID_t& lbid, const BRM::VER_t& ver, void* bufferPtr, 97 bool flg, bool& wasCached); 98 99 bool exists(BRM::LBID_t lbid, BRM::VER_t ver); 100 101 /** 102 * @brief 103 **/ 104 void flushCache(); 105 106 //const uint32_t resize(const uint32_t s); 107 108 std::ostream& formatLRUList(std::ostream& os) const; 109 110 private: 111 112 FileBufferMgr fbMgr; 113 fileBlockRequestQueue fBRPRequestQueue; 114 ioManager fIOMgr; 115 pthread_mutex_t check_mutex; 116 117 /** 118 * helper function for public check functions 119 **/ 120 int check(fileRequest& rqstBlk); 121 122 /** 123 * send stop requests for IOmanager and request Q 124 **/ 125 void stop(); 126 127 std::ofstream fLogFile; 128 bool fTrace; 129 130 BRM::DBRM fdbrm; 131 132 // do not implement 133 BlockRequestProcessor(const BlockRequestProcessor& brp); 134 BlockRequestProcessor& operator=(const BlockRequestProcessor& brp); 135 136 }; 137 138 } 139 #endif 140