1 /*
2    Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #ifndef HUGO_OPERATIONS_HPP
26 #define HUGO_OPERATIONS_HPP
27 
28 #include <NDBT.hpp>
29 #include <HugoCalculator.hpp>
30 #include <UtilTransactions.hpp>
31 #include <Vector.hpp>
32 
33 class HugoOperations : public UtilTransactions {
34 public:
35   HugoOperations(const NdbDictionary::Table&,
36 		 const NdbDictionary::Index* idx = 0);
37 
38   ~HugoOperations();
39   int startTransaction(Ndb*, const NdbDictionary::Table *table= 0,
40                        const char  *keyData= 0, Uint32 keyLen= 0);
41   int startTransaction(Ndb*, Uint32 node_id, Uint32 instance_id);
42   int setTransaction(NdbTransaction*,bool not_null_ok= false);
43   int closeTransaction(Ndb*);
44   NdbTransaction* getTransaction();
45   void refresh();
46 
47   void setTransactionId(Uint64);
48 
49   int pkInsertRecord(Ndb*,
50 		     int recordNo,
51 		     int numRecords = 1,
52 		     int updatesValue = 0,
53                      int row_step = 1);
54 
55   int pkWriteRecord(Ndb*,
56 		    int recordNo,
57 		    int numRecords = 1,
58 		    int updatesValue = 0);
59 
60   int pkWritePartialRecord(Ndb*,
61 			   int recordNo,
62 			   int numRecords = 1);
63 
64   int pkReadRecord(Ndb*,
65                    int record,
66                    int numRecords = 1,
67                    NdbOperation::LockMode lm = NdbOperation::LM_Read,
68                    NdbOperation::LockMode * lmused = 0,
69                    bool noWait = false);
70 
71   int pkReadRandRecord(Ndb*,
72                        int records,
73                        int numRecords = 1,
74                        NdbOperation::LockMode lm = NdbOperation::LM_Read,
75                        NdbOperation::LockMode * lmused = 0);
76 
77   int pkReadRecordLockHandle(Ndb*,
78                              Vector<const NdbLockHandle*>& lockHandles,
79                              int record,
80                              int numRecords = 1,
81                              NdbOperation::LockMode lm = NdbOperation::LM_Read,
82                              NdbOperation::LockMode * lmused = 0);
83 
84   int pkUnlockRecord(Ndb*,
85                      Vector<const NdbLockHandle*>& lockHandles,
86                      int offset = 0,
87                      int numRecords = ~(0),
88                      NdbOperation::AbortOption ao = NdbOperation::AbortOnError);
89 
90   int pkUpdateRecord(Ndb*,
91 		     int recordNo,
92 		     int numRecords = 1,
93 		     int updatesValue = 0);
94 
95   int pkDeleteRecord(Ndb*,
96 		     int recordNo,
97 		     int numRecords = 1,
98                      int step = 1);
99 
100   int pkRefreshRecord(Ndb*,
101                       int recordNo,
102                       int numRecords = 1,
103                       int anyValueInfo = 0); /* 0 - none, 1+ Val | record */
104 
105   int execute_Commit(Ndb*,
106 		     AbortOption ao = AbortOnError);
107   int execute_NoCommit(Ndb*,
108 		       AbortOption ao = AbortOnError);
109   int execute_Rollback(Ndb*);
110 
111   int saveCopyOfRecord(int numRecords = 1);
112   int compareRecordToCopy(int numRecords = 1);
113 
114   BaseString getRecordStr(int recordNum);
115   int getRecordGci(int recordNum);
116 
117   int setValueForAttr(NdbOperation*,
118 		      int attrId,
119 		      int rowId,
120 		      int updateId);
121 
122   int equalForAttr(NdbOperation*,
123 		   int attrId,
124 		   int rowId);
125 
126   int equalForRow(NdbOperation*, int rowid);
127 
128   bool getPartIdForRow(const NdbOperation* pOp, int rowid, Uint32& partId);
129 
130   int setValues(NdbOperation*, int rowId, int updateId);
131   int setNonPkValues(NdbOperation*, int rowId, int updateId);
132 
133   int verifyUpdatesValue(int updatesValue, int _numRows = 0);
134 
135   int indexReadRecords(Ndb*, const char * idxName, int recordNo,
136 		       bool exclusive = false,
137 		       int records = 1);
138 
139   int indexUpdateRecord(Ndb*,
140 			const char * idxName,
141 			int recordNo,
142 			int numRecords = 1,
143 			int updatesValue = 0);
144 
145   int scanReadRecords(Ndb*, NdbScanOperation::LockMode =
146 		      NdbScanOperation::LM_CommittedRead,
147 		      int numRecords = 1);
148 
149   NdbIndexScanOperation* pIndexScanOp;
150 
get_row(Uint32 idx)151   NDBT_ResultRow& get_row(Uint32 idx) { return *rows[idx];}
152 
153   int execute_async(Ndb*, NdbTransaction::ExecType, NdbOperation::AbortOption = NdbOperation::AbortOnError);
154   int execute_async_prepare(Ndb*, NdbTransaction::ExecType, NdbOperation::AbortOption = NdbOperation::AbortOnError);
155 
156   int wait_async(Ndb*, int timeout = -1);
157 
158   int releaseLockHandles(Ndb*,
159                          Vector<const NdbLockHandle*>& lockHandles,
160                          int offset = 0,
161                          int numRecords = ~(0));
162 
163   const NdbError& getNdbError() const;
setQuiet()164   void setQuiet() { m_quiet = true; }
165 
166   typedef Uint32 (*AnyValueCallback)(Ndb*, NdbTransaction*, int rowid, int updVal);
167 
168   void setAnyValueCallback(AnyValueCallback);
169 
170 protected:
171   void allocRows(int rows);
172   void deallocRows();
173 
174   Vector<NDBT_ResultRow*> rows;
175   Vector<NdbIndexScanOperation*> indexScans;
176   HugoCalculator calc;
177 
178   Vector<BaseString> savedRecords;
179 
180   struct RsPair { NdbScanOperation* m_result_set; int records; };
181   Vector<RsPair> m_result_sets;
182   Vector<RsPair> m_executed_result_sets;
183 
184   int m_async_reply;
185   int m_async_return;
186   friend void HugoOperations_async_callback(int, NdbTransaction*, void*);
187   void callback(int res, NdbTransaction*);
188   Uint32 getAnyValueForRowUpd(int row, int update);
189 
190 
191   void setNdbError(const NdbError& error);
192   NdbError m_error;
193   bool m_quiet;
194   AnyValueCallback avCallback;
195 };
196 
197 #endif
198