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_ddlcommandproc.h 3043 2011-08-29 22:03:03Z chao $
20 *
21 *******************************************************************************/
22 #ifndef WE_DMLCOMMANDPROC_H__
23 #define WE_DMLCOMMANDPROC_H__
24 
25 #include <unistd.h>
26 #include <boost/scoped_ptr.hpp>
27 #include "bytestream.h"
28 #include "we_messages.h"
29 #include "dbrm.h"
30 #include "we_message_handlers.h"
31 #include "calpontdmlpackage.h"
32 #include "updatedmlpackage.h"
33 #include "calpontsystemcatalog.h"
34 #include "insertdmlpackage.h"
35 #include "liboamcpp.h"
36 #include "dataconvert.h"
37 #include "writeengine.h"
38 #include "we_convertor.h"
39 #include "we_dbrootextenttracker.h"
40 #include "we_rbmetawriter.h"
41 #include "rowgroup.h"
42 #include "we_log.h"
43 
44 #if defined(_MSC_VER) && defined(xxxDDLPKGPROC_DLLEXPORT)
45 #define EXPORT __declspec(dllexport)
46 #else
47 #define EXPORT
48 #endif
49 
50 namespace WriteEngine
51 {
52 
53 class WE_DMLCommandProc
54 {
55 public:
56     typedef std::vector<std::string> ColValues;
57 
58     EXPORT WE_DMLCommandProc();
59     EXPORT WE_DMLCommandProc(const WE_DMLCommandProc& rhs);
60     EXPORT ~WE_DMLCommandProc();
isFirstBatchPm(bool firstBatch)61     inline void isFirstBatchPm (bool firstBatch)
62     {
63         fIsFirstBatchPm = firstBatch;
64     }
65 
isFirstBatchPm()66     inline bool isFirstBatchPm ()
67     {
68         return fIsFirstBatchPm;
69     }
70 
71     //Convert rid from logical block rid to file relative rid
convertToRelativeRid(uint64_t & rid,const uint8_t extentNum,const uint16_t blockNum)72     inline void convertToRelativeRid (uint64_t& rid, const uint8_t extentNum, const uint16_t blockNum)
73     {
74         rid = rid + extentNum * extentRows + blockNum * 8192;
75     }
76 
77     EXPORT uint8_t processSingleInsert(messageqcpp::ByteStream& bs, std::string& err);
78     EXPORT uint8_t commitVersion(messageqcpp::ByteStream& bs, std::string& err);
79     EXPORT uint8_t rollbackBlocks(messageqcpp::ByteStream& bs, std::string& err);
80     EXPORT uint8_t rollbackVersion(messageqcpp::ByteStream& bs, std::string& err);
81     EXPORT uint8_t processBatchInsert(messageqcpp::ByteStream& bs, std::string& err, ByteStream::quadbyte& PMId);
82     EXPORT uint8_t processBatchInsertBinary(messageqcpp::ByteStream& bs, std::string& err, ByteStream::quadbyte& PMId);
83     EXPORT uint8_t commitBatchAutoOn(messageqcpp::ByteStream& bs, std::string& err);
84     EXPORT uint8_t commitBatchAutoOff(messageqcpp::ByteStream& bs, std::string& err);
85     EXPORT uint8_t rollbackBatchAutoOn(messageqcpp::ByteStream& bs, std::string& err);
86     EXPORT uint8_t rollbackBatchAutoOff(messageqcpp::ByteStream& bs, std::string& err);
87     EXPORT uint8_t processBatchInsertHwm(messageqcpp::ByteStream& bs, std::string& err);
88     EXPORT uint8_t processUpdate(messageqcpp::ByteStream& bs, std::string& err, ByteStream::quadbyte& PMId, uint64_t& blocksChanged);
89     EXPORT uint8_t processUpdate1(messageqcpp::ByteStream& bs, std::string& err);
90     EXPORT uint8_t processFlushFiles(messageqcpp::ByteStream& bs, std::string& err);
91     EXPORT uint8_t processDelete(messageqcpp::ByteStream& bs, std::string& err, ByteStream::quadbyte& PMId, uint64_t& blocksChanged);
92     EXPORT uint8_t processRemoveMeta(messageqcpp::ByteStream& bs, std::string& err);
93     EXPORT uint8_t processBulkRollback(messageqcpp::ByteStream& bs, std::string& err);
94     EXPORT uint8_t processBulkRollbackCleanup(messageqcpp::ByteStream& bs, std::string& err);
95     EXPORT uint8_t updateSyscolumnNextval(ByteStream& bs, std::string& err);
96     EXPORT uint8_t processPurgeFDCache(ByteStream& bs, std::string& err);
97     EXPORT uint8_t processEndTransaction(ByteStream& bs, std::string& err);
98     EXPORT uint8_t processFixRows(ByteStream& bs, std::string& err, ByteStream::quadbyte& PMId);
99     EXPORT uint8_t getWrittenLbids(messageqcpp::ByteStream& bs, std::string& err, ByteStream::quadbyte& PMId);
100     int validateColumnHWMs(
101         execplan::CalpontSystemCatalog::RIDList& ridList,
102         boost::shared_ptr<execplan::CalpontSystemCatalog> systemCatalogPtr,
103         const std::vector<DBRootExtentInfo>& segFileInfo,
104         const char* stage );
105 private:
106     WriteEngineWrapper fWEWrapper;
107     boost::scoped_ptr<RBMetaWriter> fRBMetaWriter;
108     std::vector<boost::shared_ptr<DBRootExtentTracker> >   dbRootExtTrackerVec;
isDictCol(execplan::CalpontSystemCatalog::ColType colType)109     inline bool isDictCol ( execplan::CalpontSystemCatalog::ColType colType )
110     {
111         if (((colType.colDataType == execplan::CalpontSystemCatalog::CHAR) && (colType.colWidth > 8))
112                 || ((colType.colDataType == execplan::CalpontSystemCatalog::VARCHAR) && (colType.colWidth > 7))
113                 || ((colType.colDataType == execplan::CalpontSystemCatalog::DECIMAL) && (colType.precision > 18))
114                 || ((colType.colDataType == execplan::CalpontSystemCatalog::UDECIMAL) && (colType.precision > 18))
115                 || (colType.colDataType == execplan::CalpontSystemCatalog::VARBINARY)
116                 || (colType.colDataType == execplan::CalpontSystemCatalog::BLOB)
117                 || (colType.colDataType == execplan::CalpontSystemCatalog::TEXT))
118         {
119             return true;
120         }
121         else
122             return false;
123     }
124     uint8_t processBatchInsertHwmFlushChunks(uint32_t tableOID, int txnID,
125             const std::vector<BRM::FileInfo>& files,
126             const std::vector<BRM::OID_t>& oidsToFlush,
127             std::string& err);
128 
129     bool fIsFirstBatchPm;
130     std::map<uint32_t, rowgroup::RowGroup*> rowGroups;
131     std::map<uint32_t, dmlpackage::UpdateDMLPackage> cpackages;
132     BRM::DBRM fDbrm;
133     unsigned  extentsPerSegmentFile, extentRows, filesPerColumnPartition, dbrootCnt;
134     Log fLog;
135 };
136 
137 }
138 #undef EXPORT
139 #endif
140