1 /*
2    Copyright (c) 2003, 2015, 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_TRANSACTIONS_HPP
26 #define HUGO_TRANSACTIONS_HPP
27 
28 
29 #include <NDBT.hpp>
30 #include <HugoCalculator.hpp>
31 #include <HugoOperations.hpp>
32 class NDBT_Stats;
33 
34 class HugoTransactions : public HugoOperations {
35 public:
36   struct HugoBound { int attr; int type; const void* value; };
37 
38   HugoTransactions(const NdbDictionary::Table&,
39 		   const NdbDictionary::Index* idx = 0);
40   ~HugoTransactions();
41   int loadTable(Ndb*,
42 		int records,
43 		int batch = 512,
44 		bool allowConstraintViolation = true,
45 		int doSleep = 0,
46                 bool oneTrans = false,
47 		int updateValue = 0,
48 		bool abort = false,
49                 bool abort_on_first_error = false);
50 
51   int loadTableStartFrom(Ndb*,
52                          int startFrom,
53                          int records,
54                          int batch = 512,
55                          bool allowConstraintViolation = true,
56                          int doSleep = 0,
57                          bool oneTrans = false,
58                          int updateValue = 0,
59                          bool abort = false,
60                          bool abort_on_first_error = false);
61 
62   int scanReadRecords(Ndb*,
63 		      int records,
64 		      int abort = 0,
65 		      int parallelism = 0,
66 		      NdbOperation::LockMode = NdbOperation::LM_Read,
67                       int scan_flags = 0);
68 
69   int scanReadRecords(Ndb*,
70 		      const NdbDictionary::Index*,
71 		      int records,
72 		      int abort = 0,
73 		      int parallelism = 0,
74 		      NdbOperation::LockMode = NdbOperation::LM_Read,
75                       int scan_flags = 0,
76                       int bound_cnt = 0, const HugoBound* bound_arr = 0);
77 
78   int pkReadRecords(Ndb*,
79 		    int records,
80 		    int batchsize = 1,
81 		    NdbOperation::LockMode = NdbOperation::LM_Read,
82                     int rand = 0);
83 
84   int pkReadUnlockRecords(Ndb*,
85                           int records,
86                           int batchsize = 1,
87                           NdbOperation::LockMode = NdbOperation::LM_Read);
88 
89   int scanUpdateRecords(Ndb*, NdbScanOperation::ScanFlag,
90 			int records,
91 			int abort = 0,
92 			int parallelism = 0);
93 
94   int scanUpdateRecords(Ndb*,
95 			int records,
96 			int abort = 0,
97 			int parallelism = 0);
98 
99   int scanUpdateRecords1(Ndb*,
100 			 int records,
101 			 int abort = 0,
102 			 int parallelism = 0);
103   int scanUpdateRecords2(Ndb*,
104 			 int records,
105 			 int abort = 0,
106 			 int parallelism = 0);
107   int scanUpdateRecords3(Ndb*,
108 			 int records,
109 			 int abort = 0,
110 			 int parallelism = 0);
111 
112   int pkUpdateRecords(Ndb*,
113 		      int records,
114 		      int batchsize = 1,
115 		      int doSleep = 0);
116   int pkInterpretedUpdateRecords(Ndb*,
117 				 int records,
118 				 int batchsize = 1);
119   int pkDelRecords(Ndb*,
120 		   int records = 0,
121 		   int batch = 1,
122 		   bool allowConstraintViolation = true,
123 		   int doSleep = 0);
124 
125   int pkRefreshRecords(Ndb*, int startFrom, int count = 1, int batch = 1);
126 
127   int lockRecords(Ndb*,
128 		  int records,
129 		  int percentToLock = 1,
130 		  int lockTime = 1000);
131 
132   int fillTable(Ndb*,
133 		int batch=512);
134 
135   int fillTableStartFrom(Ndb*, int startFrom, int batch=512);
136 
137   /**
138    * Reading using UniqHashIndex with key = pk
139    */
140   int indexReadRecords(Ndb*,
141 		       const char * idxName,
142 		       int records,
143 		       int batchsize = 1);
144 
145   int indexUpdateRecords(Ndb*,
146 			 const char * idxName,
147 			 int records,
148 			 int batchsize = 1);
149 
setRetryMax(int retryMax=100)150   void setRetryMax(int retryMax = 100) { m_retryMax = retryMax; }
151   // XXX only for scanUpdateRecords
getRetryMaxReached() const152   bool getRetryMaxReached() const { return m_retryMaxReached; }
153 
154   Uint64 m_latest_gci;
155 
setStatsLatency(NDBT_Stats * stats)156   void setStatsLatency(NDBT_Stats* stats) { m_stats_latency = stats; }
157 
158   // allows multiple threads to update separate batches
setThrInfo(int thr_count,int thr_no)159   void setThrInfo(int thr_count, int thr_no) {
160     m_thr_count = thr_count;
161     m_thr_no = thr_no;
162   }
163 
164   // generate empty updates for testing
setAllowEmptyUpdates(bool allow)165   void setAllowEmptyUpdates(bool allow) {
166     m_empty_update = allow;
167   }
168 
169 protected:
170   NDBT_ResultRow row;
171   int m_defaultScanUpdateMethod;
172   int m_retryMax;
173   bool m_retryMaxReached;
174 
175   NDBT_Stats* m_stats_latency;
176 
177   int m_thr_count;      // 0 if no separation between threads
178   int m_thr_no;
179 
180   bool m_empty_update;
181 };
182 
183 
184 
185 
186 #endif
187 
188