Zero  0.1.0
reqs.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 
32 #ifndef __REQS_H
33 #define __REQS_H
34 
35 #include "sm_vas.h"
36 #include "util/condex.h"
37 
38 const int NO_VALID_TRX_ID = -1;
39 
40 /********************************************************************
41  *
42  * @enum TrxState
43  *
44  * @brief Possible states of a transaction
45  *
46  ********************************************************************/
47 
48 enum TrxState {
49  UNDEF = 0x0,
50  UNSUBMITTED = 0x1,
51  SUBMITTED = 0x2,
52  POISSONED = 0x4,
53  COMMITTED = 0x8,
54  ROLLBACKED = 0x10
55 };
56 
57 /********************************************************************
58  *
59  * @enum: eWorkerControl
60  *
61  * @brief: States for controling a worker thread
62  *
63  * @note: A thread initially is paused then it starts working, until
64  * someone changes the status to stopped. There is an extra
65  * mode which is set during recovery.
66  *
67  ********************************************************************/
68 
70  WC_PAUSED = 0x1,
71  WC_ACTIVE = 0x2,
72  WC_STOPPED = 0x4,
74 };
75 
76 /********************************************************************
77  *
78  * @enum: eWorkingState
79  *
80  * @brief: Possible states while worker thread active
81  *
82  * States:
83  *
84  * UNDEF = Unitialized
85  * LOOP = Idle and spinning
86  * SLEEP = Sleeping on the condvar
87  * COMMIT_Q = Serving to-be-committed requests
88  * INPUT_Q = Serving a normal request
89  * FINISHED = Done assigned job but still trx not decided
90  *
91  ********************************************************************/
92 
94  WS_UNDEF = 0x1,
95  WS_LOOP = 0x2,
96  WS_SLEEP = 0x4,
97  WS_COMMIT_Q = 0x8,
98  WS_INPUT_Q = 0x10,
99  WS_FINISHED = 0x20
100 };
101 
102 /********************************************************************
103  *
104  * @enum: eDataOwnerState
105  *
106  * @brief: Owning status for the worker thread of the data partition
107  *
108  ********************************************************************/
109 
111  DOS_UNDEF = 0x1,
112  DOS_ALONE = 0x2,
114 };
115 
116 /********************************************************************
117  *
118  * @class: trx_result_tuple_t
119  *
120  * @brief: Class used to represent the result of a transaction
121  *
122  ********************************************************************/
123 
125 private:
126 
128 
129  int R_ID;
130 
132 
133 public:
134 
136  reset(UNDEF, -1, nullptr);
137  }
138 
139  trx_result_tuple_t(TrxState aTrxState, int anID, condex* apcx = nullptr) {
140  reset(aTrxState, anID, apcx);
141  }
142 
144 
145  // @fn copy constructor
147  reset(t.R_STATE, t.R_ID, t._notify);
148  }
149 
150  // @fn copy assingment
152  reset(t.R_STATE, t.R_ID, t._notify);
153  return (*this);
154  }
155 
156  // @fn equality operator
157  friend bool operator==(const trx_result_tuple_t& t,
158  const trx_result_tuple_t& s) {
159  return ((t.R_STATE == s.R_STATE) && (t.R_ID == s.R_ID));
160  }
161 
162  // Access methods
163  condex* get_notify() const {
164  return (_notify);
165  }
166 
167  void set_notify(condex* notify) {
168  _notify = notify;
169  }
170 
171  int get_id() const {
172  return (R_ID);
173  }
174 
175  void set_id(const int aID) {
176  R_ID = aID;
177  }
178 
180  return (R_STATE);
181  }
182 
183  void set_state(TrxState aState) {
184  assert ((aState >= UNDEF) && (aState <= ROLLBACKED));
185  R_STATE = aState;
186  }
187 
188  void reset(TrxState aTrxState, int anID, condex* notify) {
189  // check for validity of inputs
190  assert ((aTrxState >= UNDEF) && (aTrxState <= ROLLBACKED));
191  assert (anID >= NO_VALID_TRX_ID);
192 
193  R_STATE = aTrxState;
194  R_ID = anID;
195  _notify = notify;
196  }
197 }; // EOF: trx_result_tuple_t
198 
199 
200 
201 /********************************************************************
202  *
203  * @struct: base_request_t
204  *
205  * @brief: Base class for the requests
206  *
207  ********************************************************************/
208 
210  // trx-specific
211  xct_t* _xct; // Not the owner
213 
214  int _xct_id;
215 
217 
219  : _xct(nullptr),
220  _xct_id(-1) {}
221 
222  base_request_t(xct_t* pxct, const tid_t& atid, const int axctid,
223  const trx_result_tuple_t& aresult)
224  : _xct(pxct),
225  _tid(atid),
226  _xct_id(axctid),
227  _result(aresult) {
228  assert (pxct);
229  }
230 
232  _xct = nullptr;
233  }
234 
235  inline void set(xct_t* pxct, const tid_t& atid, const int axctid,
236  const trx_result_tuple_t& aresult) {
237  _xct = pxct;
238  _tid = atid;
239  _xct_id = axctid;
240  _result = aresult;
241  }
242 
243  inline xct_t* xct() {
244  return (_xct);
245  }
246 
247  inline tid_t tid() const {
248  return (_tid);
249  }
250 
251  inline int xct_id() const {
252  return (_xct_id);
253  }
254 
255  void notify_client();
256 
258 
259  inline void set_last_lsn(const lsn_t& alsn) {
260  _my_last_lsn = alsn;
261  }
262 
263  inline lsn_t my_last_lsn() {
264  return (_my_last_lsn);
265  }
266 }; // EOF: base_request_t
267 
268 
269 
270 /********************************************************************
271  *
272  * @struct: trx_request_t
273  *
274  * @brief: Represents the requests in the Baseline system
275  *
276  ********************************************************************/
277 
278 struct trx_request_t : public base_request_t {
280 
281  int _spec_id;
282 
283  int _tspread;
284 
286  : base_request_t(),
287  _xct_type(-1),
288  _spec_id(0) {}
289 
290  trx_request_t(xct_t* pxct, const tid_t& atid, const int axctid,
291  const trx_result_tuple_t& aresult,
292  const int axcttype, const int aspecid,
293  int tspread = 0)
294  : base_request_t(pxct, atid, axctid, aresult),
295  _xct_type(axcttype),
296  _spec_id(aspecid),
297  _tspread(tspread) {}
298 
300 
301  void set(xct_t* pxct, const tid_t& atid, const int axctid,
302  const trx_result_tuple_t& aresult,
303  const int axcttype, const int aspecid, int tspread) {
304  base_request_t::set(pxct, atid, axctid, aresult);
305  _xct_type = axcttype;
306  _spec_id = aspecid;
307  _tspread = tspread;
308  }
309 
310  inline int type() const {
311  return (_xct_type);
312  }
313 
314  inline void set_type(const int atype) {
315  _xct_type = atype;
316  }
317 
318  inline int selectedID() {
319  return (_spec_id);
320  }
321 
322  int tspread() const {
323  return _tspread;
324  }
325 }; // EOF: trx_request_t
326 
327 #endif // __REQS_H
Definition: reqs.h:53
Definition: reqs.h:71
Definition: reqs.h:52
int selectedID()
Definition: reqs.h:318
lsn_t _my_last_lsn
Definition: reqs.h:257
void set_notify(condex *notify)
Definition: reqs.h:167
A transaction. Internal to the storage manager.This class may be used in a limited way for the handli...
Definition: xct.h:185
Definition: reqs.h:73
void reset(TrxState aTrxState, int anID, condex *notify)
Definition: reqs.h:188
Definition: reqs.h:95
trx_result_tuple_t()
Definition: reqs.h:135
Definition: reqs.h:278
Definition: reqs.h:50
condex * _notify
Definition: reqs.h:131
int _xct_type
Definition: reqs.h:279
Definition: reqs.h:72
void set_id(const int aID)
Definition: reqs.h:175
void set_last_lsn(const lsn_t &alsn)
Definition: reqs.h:259
friend bool operator==(const trx_result_tuple_t &t, const trx_result_tuple_t &s)
Definition: reqs.h:157
trx_result_tuple_t & operator=(const trx_result_tuple_t &t)
Definition: reqs.h:151
~trx_result_tuple_t()
Definition: reqs.h:143
Definition: reqs.h:96
xct_t * _xct
Definition: reqs.h:211
Definition: reqs.h:99
int type() const
Definition: reqs.h:310
int xct_id() const
Definition: reqs.h:251
trx_request_t(xct_t *pxct, const tid_t &atid, const int axctid, const trx_result_tuple_t &aresult, const int axcttype, const int aspecid, int tspread=0)
Definition: reqs.h:290
Definition: reqs.h:111
int R_ID
Definition: reqs.h:129
condex * get_notify() const
Definition: reqs.h:163
const int NO_VALID_TRX_ID
Definition: reqs.h:38
Definition: reqs.h:97
lsn_t my_last_lsn()
Definition: reqs.h:263
int _spec_id
Definition: reqs.h:281
Log Sequence Number. See Log Sequence Numbers (LSN).
Definition: lsn.h:243
eWorkerControl
Definition: reqs.h:69
Definition: reqs.h:51
Definition: reqs.h:94
int get_id() const
Definition: reqs.h:171
tid_t _tid
Definition: reqs.h:212
xct_t * xct()
Definition: reqs.h:243
Definition: reqs.h:113
Definition: reqs.h:49
TrxState
Definition: reqs.h:48
TrxState get_state()
Definition: reqs.h:179
int tspread() const
Definition: reqs.h:322
trx_result_tuple_t(const trx_result_tuple_t &t)
Definition: reqs.h:146
eDataOwnerState
Definition: reqs.h:110
Definition: reqs.h:124
Definition: reqs.h:54
~base_request_t()
Definition: reqs.h:231
base_request_t(xct_t *pxct, const tid_t &atid, const int axctid, const trx_result_tuple_t &aresult)
Definition: reqs.h:222
Definition: reqs.h:70
void set_state(TrxState aState)
Definition: reqs.h:183
int _tspread
Definition: reqs.h:283
Definition: condex.h:37
uint64_t tid_t
Definition: tid_t.h:59
trx_request_t()
Definition: reqs.h:285
eWorkingState
Definition: reqs.h:93
int _xct_id
Definition: reqs.h:214
~trx_request_t()
Definition: reqs.h:299
Definition: reqs.h:209
tid_t tid() const
Definition: reqs.h:247
TrxState R_STATE
Definition: reqs.h:127
void set(xct_t *pxct, const tid_t &atid, const int axctid, const trx_result_tuple_t &aresult)
Definition: reqs.h:235
trx_result_tuple_t(TrxState aTrxState, int anID, condex *apcx=nullptr)
Definition: reqs.h:139
trx_result_tuple_t _result
Definition: reqs.h:216
base_request_t()
Definition: reqs.h:218
Definition: reqs.h:112
void set_type(const int atype)
Definition: reqs.h:314
Definition: reqs.h:98