Zero  0.1.0
tpcc_env.h
Go to the documentation of this file.
1 /* -*- mode:C++; c-basic-offset:4 -*-
2  Shore-kits -- Benchmark implementations for Shore-MT
3 
4  Copyright (c) 2007-2009
5  Data Intensive Applications and Systems Labaratory (DIAS)
6  Ecole Polytechnique Federale de Lausanne
7 
8  All Rights Reserved.
9 
10  Permission to use, copy, modify and distribute this software and
11  its documentation is hereby granted, provided that both the
12  copyright notice and this permission notice appear in all copies of
13  the software, derivative works or modified versions, and any
14  portions thereof, and that both notices appear in supporting
15  documentation.
16 
17  This code is distributed in the hope that it will be useful, but
18  WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS
20  DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
21  RESULTING FROM THE USE OF THIS SOFTWARE.
22 */
23 
31 #ifndef __TPCC_ENV_H
32 #define __TPCC_ENV_H
33 
34 #include "sm_vas.h"
35 
36 #include "shore_env.h"
37 // #include "shore_asc_sort_buf.h"
38 #include "trx_worker.h"
39 #include "daemons.h"
40 
41 #include "tpcc_const.h"
42 #include "tpcc_schema_man.h"
43 #include "tpcc_input.h"
44 
45 #include <map>
46 
47 using std::map;
48 
49 namespace tpcc {
50 
51 #define TPCC_SCALING_FACTOR 100
52 #define QUERIED_TPCC_SCALING_FACTOR 100
53 
54 /******************************************************************
55  *
56  * @struct: ShoreTPCCEnv Stats
57  *
58  * @brief: TPCC Environment statistics
59  *
60  ******************************************************************/
61 
63  uint new_order;
64 
65  uint payment;
66 
68 
69  uint delivery;
70 
72 
73  uint mbench_wh;
74 
76 
78  new_order += rhs.new_order;
79  payment += rhs.payment;
80  order_status += rhs.order_status;
81  delivery += rhs.delivery;
82  stock_level += rhs.stock_level;
83  mbench_wh += rhs.mbench_wh;
84  mbench_cust += rhs.mbench_cust;
85  return (*this);
86  }
87 
89  new_order -= rhs.new_order;
90  payment -= rhs.payment;
91  order_status -= rhs.order_status;
92  delivery -= rhs.delivery;
93  stock_level -= rhs.stock_level;
94  mbench_wh -= rhs.mbench_wh;
95  mbench_cust -= rhs.mbench_cust;
96  return (*this);
97  }
98 
99  uint total() const {
100  return (new_order + payment + order_status + delivery + stock_level +
101  mbench_wh + mbench_cust);
102  }
103  }; // EOF: ShoreTPCCTrxCount
104 
105 
106 
109 
111 
113 
115  attempted += other.attempted;
116  failed += other.failed;
117  deadlocked += other.deadlocked;
118  return (*this);
119  }
120 
122  attempted -= other.attempted;
123  failed -= other.failed;
124  deadlocked -= other.deadlocked;
125  return (*this);
126  }
127  }; // EOF: ShoreTPCCTrxStats
128 
129 
130 
131 /********************************************************************
132  *
133  * ShoreTPCCEnv
134  *
135  * Shore TPC-C Database.
136  *
137  ********************************************************************/
138 
139 // For P-Loader
140  static int const NORD_PER_UNIT = 9;
141 
142  static int const CUST_PER_UNIT = 30;
143 
144  static int const HIST_PER_UNIT = 30;
145 
146  static int const ORDERS_PER_UNIT = 30;
147 
148  static int const STOCK_PER_UNIT = 100;
149 
150  static int const UNIT_PER_WH = 1000;
151 
152  static int const UNIT_PER_DIST = 100;
153 
154  static int const ORDERS_PER_DIST = 3000;
155 
156  class ShoreTPCCEnv : public ShoreEnv {
157  public:
158 
159  typedef std::map<pthread_t, ShoreTPCCTrxStats*> statmap_t;
160 
161  class table_builder_t;
162 class table_creator_t;
163 
164  public:
165 
166  ShoreTPCCEnv(boost::program_options::variables_map map);
167 
168  virtual ~ShoreTPCCEnv();
169 
170 
171  // DB INTERFACE
172 
173  virtual int set(envVarMap* /* vars */) {
174  return (0); /* do nothing */ };
175 
176  virtual int open() {
177  return (0); /* do nothing */ };
178 
179  virtual int pause() {
180  return (0); /* do nothing */ };
181 
182  virtual int resume() {
183  return (0); /* do nothing */ };
184 
185  virtual w_rc_t newrun() {
186  return (RCOK); /* do nothing */ };
187 
188  virtual int post_init();
189 
190  virtual w_rc_t load_schema();
191 
192  virtual w_rc_t load_and_register_fids();
193 
194  virtual int conf();
195 
196  virtual int start();
197 
198  virtual int stop();
199 
200  virtual int info() const;
201 
202  virtual int statistics();
203 
204  int dump();
205 
206  virtual void print_throughput(const double iQueriedSF,
207  const int iSpread,
208  const int iNumOfThreads,
209  const double delay);
210 
211 
212 
213  // Public methods //
214 
215  // --- operations over tables --- //
216  w_rc_t create_tables();
217 
218  w_rc_t load_data();
219 
220  w_rc_t warmup();
221 
222  w_rc_t check_consistency();
223 
224 
225  // TPCC Tables
226  DECLARE_TABLE(warehouse_t, warehouse_man_impl, warehouse);
227 
228  DECLARE_TABLE(district_t, district_man_impl, district);
229 
230  DECLARE_TABLE(customer_t, customer_man_impl, customer);
231 
232  DECLARE_TABLE(history_t, history_man_impl, history);
233 
235 
236  DECLARE_TABLE(order_t, order_man_impl, order);
237 
238  DECLARE_TABLE(order_line_t, order_line_man_impl, order_line);
239 
240  DECLARE_TABLE(item_t, item_man_impl, item);
241 
242  DECLARE_TABLE(stock_t, stock_man_impl, stock);
243 
244 
245  // --- kit trxs --- //
246 
247  w_rc_t run_one_xct(Request* prequest);
248 
250 
252 
254 
256 
258 
260 
262 
263  // P-Loader
264  DECLARE_TRX(populate_baseline);
265 
266  DECLARE_TRX(populate_one_unit);
267 
268  // Helper xcts
269  w_rc_t _xct_delivery_helper(const int xct_id, delivery_input_t& pdin,
270  std::vector<int>& dlist, int& d_id,
271  const bool SPLIT_TRX);
272 
273  // for thread-local stats
274  virtual void env_thread_init();
275 
276  virtual void env_thread_fini();
277 
278  // stat map
279  statmap_t _statmap;
280 
281  // snapshot taken at the beginning of each experiment
283 
284  virtual void reset_stats();
285 
286  ShoreTPCCTrxStats _get_stats();
287 
288  // set load imbalance and time to apply it
289  void set_skew(int area, int load, int start_imbalance, int skew_type, bool shifting);
290 
291  void start_load_imbalance();
292 
293  void reset_skew();
294 
295  //print the current tables into files
296  w_rc_t db_print(int lines);
297 
298  //fetch the pages of the current tables and their indexes into the buffer pool
299  virtual w_rc_t db_fetch();
300  }; // EOF ShoreTPCCEnv
301 
302 };
303 
304 #endif // __TPCC_ENV_H
: Constants needed by the TPC-C kit
const w_rc_t RCOK
Definition: w_rc.h:239
static int const ORDERS_PER_DIST
Definition: tpcc_env.h:154
Declaration of the (common) inputs for the TPC-C trxs.
Definition: tpcc_schema_man.h:74
ShoreTPCCTrxStats & operator+=(ShoreTPCCTrxStats const &other)
Definition: tpcc_env.h:114
#define DECLARE_TABLE(table, manimpl, abbrv)
Definition: shore_env.h:71
ShoreTPCCTrxCount deadlocked
Definition: tpcc_env.h:112
uint stock_level
Definition: tpcc_env.h:71
Definition: reqs.h:278
Definition: tpcc_schema_man.h:107
Definition: tpcc_input.h:267
ShoreTPCCTrxStats & operator-=(ShoreTPCCTrxStats const &other)
Definition: tpcc_env.h:121
Definition: tpcc_schema_man.h:180
static int const CUST_PER_UNIT
Definition: tpcc_env.h:142
: Definition of a Shore environment (database)
Definition: tpcc_schema_man.h:46
Definition: tpcc_client.cpp:33
ShoreTPCCTrxCount failed
Definition: tpcc_env.h:110
: Wrapper for the worker threads in Baseline (specialization of the Shore workers) ...
ShoreTPCCTrxCount attempted
Definition: tpcc_env.h:108
: Declaration of the TPC-C table managers
ShoreTPCCTrxCount & operator+=(ShoreTPCCTrxCount const &rhs)
Definition: tpcc_env.h:77
uint mbench_wh
Definition: tpcc_env.h:73
static int const HIST_PER_UNIT
Definition: tpcc_env.h:144
Definition: tpcc_schema_man.h:305
uint delivery
Definition: tpcc_env.h:69
std::map< pthread_t, ShoreTPCCTrxStats * > statmap_t
Definition: tpcc_env.h:159
Definition: tpcc_schema_man.h:211
Return code for most functions and methods.
Definition: w_rc.h:87
map< string, string > envVarMap
Definition: shore_env.h:245
ShoreTPCCTrxCount & operator-=(ShoreTPCCTrxCount const &rhs)
Definition: tpcc_env.h:88
Definition: tpcc_env.h:107
uint mbench_cust
Definition: tpcc_env.h:75
static int const UNIT_PER_WH
Definition: tpcc_env.h:150
Definition: tpcc_schema_man.h:168
virtual int resume()
Definition: tpcc_env.h:182
Definition: tpcc_env.cpp:82
Definition: tpcc_env.h:156
static int const UNIT_PER_DIST
Definition: tpcc_env.h:152
Definition: tpcc_schema_man.h:244
uint payment
Definition: tpcc_env.h:65
: Definition of helper loader thread classes
uint total() const
Definition: tpcc_env.h:99
virtual int pause()
Definition: tpcc_env.h:179
uint new_order
Definition: tpcc_env.h:63
#define DECLARE_TRX(trxlid)
Definition: shore_env.h:63
statmap_t _statmap
Definition: tpcc_env.h:279
static int const STOCK_PER_UNIT
Definition: tpcc_env.h:148
Definition: tpcc_env.h:62
Definition: shore_env.h:349
virtual int open()
Definition: tpcc_env.h:176
static int const ORDERS_PER_UNIT
Definition: tpcc_env.h:146
Definition: tpcc_schema_man.h:281
static int const NORD_PER_UNIT
Definition: tpcc_env.h:140
Definition: tpcc_env.cpp:62
ShoreTPCCTrxStats _last_stats
Definition: tpcc_env.h:282
uint order_status
Definition: tpcc_env.h:67
virtual w_rc_t newrun()
Definition: tpcc_env.h:185