Zero  0.1.0
index_desc.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 
36 #ifndef __INDEX_DESC_H
37 #define __INDEX_DESC_H
38 
39 #include "sm_vas.h"
40 
41 #include <error.h>
42 #include "file_desc.h"
43 //#include "iter.h"
44 
45 #include "AtomicCounter.hpp"
46 
47 class table_desc_t;
48 
49 /******************************************************************
50  *
51  * @class: index_desc_t
52  *
53  * @brief: Description of a Shore index.
54  *
55  * @note: Even the variable length fields are treated as fixed
56  * length, with their maximum possible size.
57  *
58  ******************************************************************/
59 
60 class index_desc_t {
61  // this is needed at least for accessing the lock
62  friend class table_desc_t;
63 
64 private:
66 
68 
69  string _name;
70 
71  unsigned* _key; /* index of fields in the base table */
72  unsigned _field_count;
73 
74  bool _unique; /* whether allow duplicates or not */
75  bool _primary; /* is it primary or not */
76  bool _nolock; /* is it using locking or not */
77  bool _latchless; /* does it use any latches at all */
78  bool _rmapholder; /* it is used only for the range mapping */
79 
80  // CS: removed volatile, which has nothing to do with thread safety!
81  unsigned _maxkeysize; /* maximum key size */
82 
83  char _keydesc[MAX_KEYDESC_LEN]; /* buffer for the index key description */
84  tatas_lock _keydesc_lock; /* lock for the key desc */
85 
86 
87 public:
88 
89  /* ------------------- */
90  /* --- constructor --- */
91  /* ------------------- */
92 
94  string name, const int fieldcnt,
95  const unsigned* fields,
96  bool unique = true, bool primary = false,
97  bool rmapholder = false);
98 
99  ~index_desc_t();
100 
101  string name() const {
102  return _name;
103  }
104 
105  unsigned field_count() const {
106  return _field_count;
107  }
108 
109  table_desc_t* table() const {
110  return _table;
111  }
112 
113  bool is_fid_valid() const {
114  return (_stid != 0);
115  }
116 
118  return _stid;
119  }
120 
121  void set_stid(StoreID const& stid) {
122  _stid = stid;
123  }
124 
125  w_rc_t load_stid(ss_m* db, StoreID cat_stid);
126 
127  /* ---------------------- */
128  /* --- access methods --- */
129  /* ---------------------- */
130 
131  inline bool is_unique() const {
132  return (_unique);
133  }
134 
135  inline bool is_primary() const {
136  return (_primary);
137  }
138 
139  inline bool is_rmapholder() const {
140  return (_rmapholder);
141  }
142 
143  inline int get_keysize() {
144  return (*&_maxkeysize);
145  }
146 
147  inline void set_keysize(const unsigned sz) {
148  //atomic_swap_uint(&_maxkeysize, sz);
149  lintel::unsafe::atomic_exchange(&_maxkeysize, sz);
150  }
151 
152  bool is_key_index(unsigned i) {
153  for (unsigned j = 0; j < _field_count; j++) {
154  if (_key[j] == i) {
155  return true;
156  }
157  }
158  return false;
159  }
160 
161  // find the index_desc_t by name
162  bool matches_name(const char* name);
163 
164  int key_index(const unsigned index) const;
165 
166 
167  /* ----------------- */
168  /* --- debugging --- */
169  /* ----------------- */
170 
171  void print_desc(ostream& os);
172 }; // EOF: index_desc_t
173 
174 
175 
176 #endif // __INDEX_DESC_H
table_desc_t * _table
Definition: index_desc.h:65
w_rc_t load_stid(ss_m *db, StoreID cat_stid)
Definition: index_desc.cpp:99
int key_index(const unsigned index) const
Definition: index_desc.cpp:76
Definition: table_desc.h:122
index_desc_t(table_desc_t *table, string name, const int fieldcnt, const unsigned *fields, bool unique=true, bool primary=false, bool rmapholder=false)
Definition: index_desc.cpp:42
ss_m * db()
Definition: table_desc.h:258
void set_keysize(const unsigned sz)
Definition: index_desc.h:147
bool is_key_index(unsigned i)
Definition: index_desc.h:152
bool _rmapholder
Definition: index_desc.h:78
unsigned _maxkeysize
Definition: index_desc.h:81
Header file for lintel::Atomic class.
uint32_t StoreID
Definition: basics.h:47
unsigned _field_count
Definition: index_desc.h:72
int get_keysize()
Definition: index_desc.h:143
bool is_primary() const
Definition: index_desc.h:135
void print_desc(ostream &os)
Definition: index_desc.cpp:90
unsigned * _key
Definition: index_desc.h:71
T atomic_exchange(T *object, C desired)
Definition: AtomicCounter.hpp:396
unsigned field_count() const
Definition: index_desc.h:105
bool _unique
Definition: index_desc.h:74
This is the SHORE Storage Manager API.
Definition: sm.h:405
bool _primary
Definition: index_desc.h:75
~index_desc_t()
Definition: index_desc.cpp:64
bool is_fid_valid() const
Definition: index_desc.h:113
bool matches_name(const char *name)
Definition: index_desc.cpp:72
Return code for most functions and methods.
Definition: w_rc.h:87
Definition: index_desc.h:60
tatas_lock _keydesc_lock
Definition: index_desc.h:84
StoreID & stid()
Definition: index_desc.h:117
bool _nolock
Definition: index_desc.h:76
A test-and-test-and-set spinlock.
Definition: tatas.h:25
void set_stid(StoreID const &stid)
Definition: index_desc.h:121
string _name
Definition: index_desc.h:69
bool is_rmapholder() const
Definition: index_desc.h:139
: Descriptors for Shore files/indexes, and structures that help in keeping track of the created files...
const unsigned int MAX_KEYDESC_LEN
Definition: file_desc.h:46
bool _latchless
Definition: index_desc.h:77
StoreID _stid
Definition: index_desc.h:67
string name() const
Definition: index_desc.h:101
table_desc_t * table() const
Definition: index_desc.h:109
char _keydesc[MAX_KEYDESC_LEN]
Definition: index_desc.h:83
bool is_unique() const
Definition: index_desc.h:131