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 /*
19 * $Id: we_bulkrollbackfilecompressed.h 4726 2013-08-07 03:38:36Z bwilkinson $
20 */
21 
22 /** @file
23  * Contains class to restore compressed db files on behalf of BulkRollBackMgr.
24  */
25 
26 #ifndef WE_BULKROLLBACKFILECOMPRESSED_H_
27 #define WE_BULKROLLBACKFILECOMPRESSED_H_
28 
29 #include <cstdio>
30 #include <cstring>
31 
32 #include "we_define.h"
33 #include "we_type.h"
34 #include "we_bulkrollbackfile.h"
35 
36 #include "idbcompress.h"
37 
38 namespace WriteEngine
39 {
40 class BulkRollbackMgr;
41 
42 //------------------------------------------------------------------------------
43 /** @brief Class used by BulkRollbackMgr to restore compressed db files.
44  */
45 //------------------------------------------------------------------------------
46 class BulkRollbackFileCompressed : public BulkRollbackFile
47 {
48 public:
49 
50     /** @brief BulkRollbackFile constructor
51      * @param mgr The controlling BulkRollbackMgr object.
52      */
53     BulkRollbackFileCompressed(BulkRollbackMgr* mgr);
54 
55     /** @brief BulkRollbackFile destructor
56      */
57     virtual     ~BulkRollbackFileCompressed();
58 
59     /** @brief Do we reinit trailing blocks in the HWM extent for the specified
60      * segment file
61      *
62      * @param columnOID OID of the segment file in question
63      * @param dbRoot DBRoot for the segment file in question
64      * @param partNum Partition number for the segment file in question
65      * @param segNum Segment number for the segment file in question
66      */
67     virtual bool doWeReInitExtent( OID columnOID,
68                                    uint32_t   dbRoot,
69                                    uint32_t   partNum,
70                                    uint32_t   segNum) const;
71 
72     /** @brief Reinitialize the specified column segment file starting at
73      * startOffsetBlk, and truncate trailing extents.
74      * @param columnOID OID of the relevant segment file
75      * @param dbRoot DBRoot of the relevant segment file
76      * @param partNum Partition number of the relevant segment file
77      * @param segNum Segment number of the relevant segment file
78      * @param startOffsetBlk Starting block offset where file is to be
79      *        reinitialized
80      * @param nBlocks Number of blocks to be reinitialized
81      * @param colType Column type of the relevant segment file
82      * @param colWidth Width in bytes of column.
83      * @param restoreHwmChk Restore HWM chunk
84      */
85     virtual void reInitTruncColumnExtent(OID columnOID,
86                                          uint32_t   dbRoot,
87                                          uint32_t   partNum,
88                                          uint32_t   segNum,
89                                          long long   startOffsetBlk,
90                                          int         nBlocks,
91                                          execplan::CalpontSystemCatalog::ColDataType colType,
92                                          uint32_t   colWidth,
93                                          bool        restoreHwmChk );
94 
95     /** @brief Reinitialize the specified dictionary store segment file starting
96      * at startOffsetBlk, and truncate trailing extents.
97      * @param columnOID OID of the relevant segment file
98      * @param dbRoot DBRoot of the relevant segment file
99      * @param partNum Partition number of the relevant segment file
100      * @param segNum Segment number of the relevant segment file
101      * @param startOffsetBlk Starting block offset where file is to be
102      *        reinitialized
103      * @param nBlocks Number of blocks to be reinitialized
104      */
105     virtual void reInitTruncDctnryExtent(OID columnOID,
106                                          uint32_t   dbRoot,
107                                          uint32_t   partNum,
108                                          uint32_t   segNum,
109                                          long long   startOffsetBlk,
110                                          int         nBlocks );
111 
112     /** @brief Truncate the specified segment file to a specified num of bytes
113      * @param columnOID OID of the relevant segment file
114      * @param dbRoot DBRoot of the relevant segment file
115      * @param partNum Partition number of the relevant segment file
116      * @param segNum Segment number of the relevant segment file
117      * @param fileSizeBlocks Number of blocks to retain in the file
118      */
119     virtual void truncateSegmentFile( OID    columnOID,
120                                       uint32_t   dbRoot,
121                                       uint32_t   partNum,
122                                       uint32_t   segNum,
123                                       long long   filesSizeBlocks );
124 
125 private:
126     // Disable unnecessary copy constructor and assignment operator
127     BulkRollbackFileCompressed(const BulkRollbackFileCompressed& rhs);
128     BulkRollbackFileCompressed& operator=(const BulkRollbackFileCompressed& rhs);
129 
130     size_t readFillBuffer    (  IDBDataFile* pFile,
131                                 char*       buffer,
132                                 size_t      bytesReq) const;
133     int restoreHWMChunk      (  IDBDataFile* pFile,
134                                 OID         columnOID,
135                                 uint32_t   partNum,
136                                 uint32_t   segNum,
137                                 uint64_t    fileOffsetByteForRestoredChunk,
138                                 uint64_t&   restoredChunkLen,
139                                 uint64_t&   restoredFileSize,
140                                 std::string& errMsg );
141     int loadColumnHdrPtrs    (  IDBDataFile* pFile,
142                                 char*       hdrs,
143                                 compress::CompChunkPtrList& chunkPtrs,
144                                 std::string& errMsg) const;
145     int loadDctnryHdrPtrs    (  IDBDataFile* pFile,
146                                 char*       controlHdr,
147                                 compress::CompChunkPtrList& chunkPtrs,
148                                 uint64_t&   ptrHdrSize,
149                                 std::string& errMsg ) const;
150 
151     compress::IDBCompressInterface fCompressor;
152 };
153 
154 } //end of namespace
155 
156 #endif // WE_BULKROLLBACKFILECOMPRESSED_H_
157