Zero  0.1.0
sm_base.h
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2011-2014, Hewlett-Packard Development Company, LP
3  */
4 
5 /* -*- mode:C++; c-basic-offset:4 -*-
6  Shore-MT -- Multi-threaded port of the SHORE storage manager
7 
8  Copyright (c) 2007-2009
9  Data Intensive Applications and Systems Labaratory (DIAS)
10  Ecole Polytechnique Federale de Lausanne
11 
12  All Rights Reserved.
13 
14  Permission to use, copy, modify and distribute this software and
15  its documentation is hereby granted, provided that both the
16  copyright notice and this permission notice appear in all copies of
17  the software, derivative works or modified versions, and any
18  portions thereof, and that both notices appear in supporting
19  documentation.
20 
21  This code is distributed in the hope that it will be useful, but
22  WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS
24  DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
25  RESULTING FROM THE USE OF THIS SOFTWARE.
26 */
27 
28 /*<std-header orig-src='shore' incl-file-exclusion='SM_BASE_H'>
29 
30  $Id: sm_base.h,v 1.158 2010/12/08 17:37:43 nhall Exp $
31 
32 SHORE -- Scalable Heterogeneous Object REpository
33 
34 Copyright (c) 1994-99 Computer Sciences Department, University of
35  Wisconsin -- Madison
36 All Rights Reserved.
37 
38 Permission to use, copy, modify and distribute this software and its
39 documentation is hereby granted, provided that both the copyright
40 notice and this permission notice appear in all copies of the
41 software, derivative works or modified versions, and any portions
42 thereof, and that both notices appear in supporting documentation.
43 
44 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
45 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
46 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
47 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 
49 This software was developed with support by the Advanced Research
50 Project Agency, ARPA order number 018 (formerly 8230), monitored by
51 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
52 Further funding for this work was provided by DARPA through
53 Rome Research Laboratory Contract No. F30602-97-2-0247.
54 
55 */
56 
57 #ifndef __SM_BASE_H
58 #define __SM_BASE_H
59 
60 #include "w_defines.h"
61 
62 /* -- do not edit anything above this line -- </std-header>*/
63 
64 #include <vector>
65 #include "basics.h"
66 #include "w_debug.h"
67 #include <cstddef>
68 #include <cstdlib>
69 #include <cstring>
70 #include <climits>
71 #include "w.h"
72 #include "vec_t.h"
73 #include "latch.h"
74 #include "smthread.h"
75 #include "tid_t.h"
76 #include "smstats.h"
77 
78 
83 #include <climits>
84 
85 class ErrLog;
86 class xct_t;
87 class xct_i;
88 class vol_t;
89 class BackupManager;
90 namespace zero::buffer_pool {
91  class BufferPool;
92 } // zero::buffer_pool
93 class comm_m;
94 class log_core;
95 class lock_m;
96 class LogArchiver;
97 class option_t;
98 class rid_t;
99 class lsn_t;
100 class sm_naive_allocator;
101 class sm_tls_allocator;
102 template<typename T, size_t A> class memalign_allocator;
103 class chkpt_m;
104 class restart_thread_t;
105 namespace zero::buffer_pool {
106  class BufferPool;
107 }
108 class btree_m;
109 class ss_m;
110 
111 #ifndef SM_EXTENTSIZE
112 #define SM_EXTENTSIZE 8
113 #endif
114 #ifndef SM_LOG_PARTITIONS
115 #define SM_LOG_PARTITIONS 8
116 #endif
117 
118 class w_rc_t;
119 
120 typedef w_rc_t rc_t;
121 
122 
144 #if W_DEBUG_LEVEL > 2
145 #define CHECK_NESTING_VARIABLES 1
146 #else
147 #define CHECK_NESTING_VARIABLES 0
148 #endif
149 
150 struct check_compensated_op_nesting {
151 #if CHECK_NESTING_VARIABLES
152  xct_t* _xd;
153  int _depth;
154  int _line;
155  const char *const _file;
156  // static methods are so we can avoid having to
157  // include xct.h here.
158  static int compensated_op_depth(xct_t* xd, int dflt);
159 
160  check_compensated_op_nesting(xct_t* xd, int line, const char *const file)
161  : _xd(xd),
162  _depth(_xd? compensated_op_depth(_xd, 0) : 0),
163  _line(line),
164  _file(file)
165  {}
166 
167  ~check_compensated_op_nesting() {
168  if(_xd) {
169  if( _depth != compensated_op_depth(_xd, _depth) ) {
170  fprintf(stderr,
171  "th.XXX check_compensated_op_nesting(%d,%s) depth was %d is %d\n",
172  _line, _file, _depth, compensated_op_depth(_xd, _depth));
173  }
174 
175 
176  w_assert0(_depth == compensated_op_depth(_xd, _depth));
177  }
178  }
179 #else
180 
181  check_compensated_op_nesting(xct_t*, int, const char* const) {}
182 
183 #endif
184 };
185 
187 class smlevel_0 : public w_base_t {
188 public:
189  // Give these enums names for doxygen purposes:
190  enum error_constant_t {
191  eNOERROR = 0,
192  eFAILURE = -1
193  };
194  enum sm_constant_t {
195  page_sz = SM_PAGESIZE, // page size (SM_PAGESIZE is set by makemake)
196  ext_sz = SM_EXTENTSIZE, // extent size
197 #if defined(_POSIX_PATH_MAX)
198  max_devname = _POSIX_PATH_MAX, // max length of unix path name
199  // BEWARE: this might be larger than you want. Array sizes depend on it.
200  // The default might be small enough, e.g., 256; getconf() yields the upper
201  // bound on this value.
202 #elif defined(MAXPATHLEN)
203  max_devname = MAXPATHLEN,
204 #else
205  max_devname = 1024,
206 #endif
207  max_xct_thread = 20, // max threads in a xct
208  max_servers = 15, // max servers to be connected with
209  max_keycomp = 20, // max key component (for btree)
210  max_openlog = SM_LOG_PARTITIONS, // max # log partitions
211 
212  /* XXX I want to propogate sthread_t::iovec_max here, but
213  it doesn't work because of sm_app.h not including
214  the thread package. */
215  max_many_pages = 64,
216 
217  srvid_map_sz = (max_servers - 1) / 8 + 1,
218  ext_map_sz_in_bytes = ((ext_sz + 7) / 8),
219 
220  dummy = 0
221  };
222 
223  enum {
224  max_rec_len = max_uint4
225  };
226 
228 
231  typedef uint32_t partition_number_t;
232 
237  enum cmp_t {
238  bad_cmp_t = badOp,
239  eq = eqOp,
240  gt = gtOp,
241  ge = geOp,
242  lt = ltOp,
243  le = leOp
244  };
245 
257  t_cc_bad, // this is an illegal value
258  t_cc_none, // no locking
263  };
264 
283  enum pg_policy_t {
284  t_append = 0x01, // retain sort order (cache 0 pages)
285  t_cache = 0x02, // look in n cached pgs
286  t_compact = 0x04 // scan file for space in pages
287 
288  };
289 
293  static void add_to_global_stats(const sm_stats_t& from);
294 
295  static void add_from_global_stats(sm_stats_t& to);
296 
297  static BackupManager* bk;
298 
299  static vol_t* vol;
300 
302 
303  static lock_m* lm;
304 
305  static log_core* log;
306 
307  static LogArchiver* logArchiver;
308 
309  static int dcommit_timeout; // to convey option to coordinator,
310  // if it is created by VAS
311 
312  static ErrLog* errlog;
313 
314  static sm_tls_allocator allocator;
315 
316  static constexpr size_t IO_ALIGN = 512;
317 
318  static memalign_allocator<char, IO_ALIGN> aligned_allocator;
319 
320  static bool shutdown_clean;
321 
322  static bool shutdown_filthy;
323 
324  static bool shutting_down;
325 
326  static bool logging_enabled;
327 
328  static bool lock_caching_default;
329 
330  static bool statistics_enabled;
331 
332  // This is a zeroed page for use wherever initialized memory
333  // is needed.
334  static char zero_page[page_sz];
335 
337  // or at least be converted properly every time we come through the API
338  enum store_flag_t {
340  st_unallocated = 0,
341 
342  st_regular = 0x01, // fully logged
343  st_tmp = 0x02, // space logging only,
344  // file destroy on dismount/restart
345  st_load_file = 0x04, // not stored in the stnode_t,
346  // only passed down to io_m and then
347  // converted to tmp and added to the
348  // list of load files for the xct. no
349  // longer needed
350  st_insert_file = 0x08, // stored in stnode, but not on page.
351  // new pages are saved as tmp, old pages as regular.
352  st_empty = 0x100 // store might be empty - used ONLY
353  // as a function argument, NOT stored
354  // persistently. Nevertheless, it's
355  // defined here to be sure that if
356  // other store flags are added, this
357  // doesn't conflict with them.
358  };
359 
360  /*
361  * for use by set_store_deleting_log;
362  * type of operation to perform on the stnode
363  */
364  enum store_operation_t {
365  t_delete_store,
366  t_create_store,
367  t_set_deleting,
368  t_set_store_flags,
369  t_set_root
370  };
371 
372  enum store_deleting_t {
373  t_not_deleting_store = 0, // must be 0: code assumes it
374  t_deleting_store,
375  t_unknown_deleting
376  };
377 
378  // CS: stuff below was from smlevels 1-4
379 
381  // The numeric equivalents of state are not significant; they are
382  // given here only for convenience in debugging/grepping
383  // Well, their ORDER is significant, so that you can only
384  // change state to a larger state with change_state().
385  enum xct_state_t {
386  xct_stale = 0x0,
387  xct_active = 0x1, // active or rolling back in
388  // doing rollback_work
389  // It is also used in Recovery for loser transaction
390  // because it is using the standard rollback logic
391  // for loser txn, check the _loser_xct flag
392  // in xct_t
393  xct_chaining = 0x3,
394  xct_committing = 0x4,
395  xct_aborting = 0x5, // normal transaction abort
396  xct_freeing_space = 0x6,
397  xct_ended = 0x7
398  };
399 
400  // Checkpoint manager
401  static chkpt_m* chkpt;
402 
403  // Recovery manager
404  static restart_thread_t* recovery;
405 
406  static btree_m* bt;
407 
408  static ss_m* SSM; // we will change to lower case later
409 
484  enum sm_store_property_t {
485  // NB: this had better match store_flag_t!!! (sm_base.h)
486  t_regular = 0x1,
487 
489  t_temporary = 0x2,
490 
493  t_load_file = 0x4,
494 
498  t_insert_file = 0x08,
499 
500  t_bad_storeproperty = 0x80// no bits in common with good properties
501  };
503 };
504 
506 typedef smlevel_0 smlevel_top;
507 
508 ostream&
509 operator<<(ostream& o, smlevel_0::sm_store_property_t p);
510 
511 class xct_log_warn_check_t : public smlevel_0 {
512 public:
513  static w_rc_t check(xct_t*&);
514 };
515 
516 ostream&
517 operator<<(ostream& o, smlevel_0::store_flag_t flag);
518 
519 ostream&
520 operator<<(ostream& o, const smlevel_0::store_operation_t op);
521 
522 ostream&
523 operator<<(ostream& o, const smlevel_0::store_deleting_t value);
524 
525 #if defined(__GNUC__) && __GNUC_MINOR__ > 6
526 ostream& operator<<(ostream& o, const smlevel_0::xct_state_t& xct_state);
527 #endif
528 
531 /*<std-footer incl-file-exclusion='SM_BASE_H'> -- do not edit anything below this line -- */
532 
533 #endif // __SM_BASE_H /*</std-footer>*/
Definition: sm_base.h:285
Definition: sm_base.h:238
Lock Manager API.See Orthogonal Key Value Locking and Light-weight Intent Lock.
Definition: lock.h:27
Definition: sm_base.h:241
Definition: sm_base.h:258
w_base_t::base_stat_t base_stat_t
Definition: btree_page_h.h:16
Definition: sm_base.h:262
Definition: buffer_pool.hpp:34
A transaction. Internal to the storage manager.This class may be used in a limited way for the handli...
Definition: xct.h:185
Definition: vol.h:21
Definition: sm_base.h:257
Definition: restart.h:51
Definition: allocator.h:59
cmp_t
Comparison types used in scan_index_iShorthand for CompareOp.
Definition: sm_base.h:237
const uint32_t max_uint4
Definition: basics.h:107
uint32_t partition_number_t
Definition: sm_base.h:231
Definition: sm_base.h:240
Definition: log_core.h:87
Definition: sm_base.h:284
int32_t base_stat_t
Definition: w_base.h:296
Definition: w_base.h:266
Definition: sm_base.h:243
Definition: chkpt.h:256
#define w_assert0(x)
Default assert/debug level is 0.
Definition: w_base.h:175
This is the SHORE Storage Manager API.
Definition: sm.h:405
Definition: sm_base.h:260
Log Sequence Number. See Log Sequence Numbers (LSN).
Definition: lsn.h:243
Definition: allocator.h:24
Definition: allocator.h:13
std::array< long, enum_to_base(sm_stat_id::stat_max)> sm_stats_t
Definition: smstats.h:205
Return code for most functions and methods.
Definition: w_rc.h:87
Definition: sm_base.h:242
Definition: sm_base.h:259
Iterator over transaction list.
Definition: xct.h:969
std::ostream & operator<<(std::ostream &os, const ConfigFile &cf)
Definition: confparser.cpp:83
Definition: btree.h:28
A buffer manager that exploits the tree structure of indexes.
Definition: buffer_pool.hpp:40
Implementation of a log archiver using asynchronous reader and writer threads.
Definition: logarchiver.h:225
Definition: sm_base.h:286
const size_t IO_ALIGN
Definition: logarchive_index.cpp:48
w_rc_t rc_t
Definition: sm_base.h:118
pg_policy_t
File-compaction policy for creating records.
Definition: sm_base.h:283
concurrency_t
Lock granularities.
Definition: sm_base.h:256
Definition: sm_base.h:239
Definition: sm_base.h:261