00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #ifndef EXTENT_H
00054 #define EXTENT_H
00055
00056 #include "w_defines.h"
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 class extlink_t {
00074
00075 Pmap_Align4 pmap;
00076 public:
00077
00078 extnum_t next;
00079
00080 extnum_t prev;
00081
00082 snum_t owner;
00083
00084 uint4_t pbucketmap;
00085
00086
00087
00088
00089
00090 static int logged_size();
00091 NORET extlink_t();
00092 NORET extlink_t(const extlink_t& e);
00093 extlink_t& operator=(const extlink_t&);
00094
00095 void clrall();
00096 void setall();
00097 void setmap(const Pmap &m);
00098 void getmap(Pmap &m) const;
00099 void set(int i);
00100 void clr(int i);
00101 bool is_set(int i) const;
00102 bool is_clr(int i) const;
00103 int first_set(int start) const;
00104 int first_clr(int start) const;
00105 int last_set(int start) const;
00106 int last_clr(int start) const;
00107 int num_set() const;
00108 int num_clr() const;
00109
00110 space_bucket_t get_page_bucket(int i)const;
00111
00112 friend ostream& operator<<(ostream &, const extlink_t &e);
00113 };
00114
00115 inline NORET
00116 extlink_t::extlink_t(const extlink_t& e)
00117 : pmap(e.pmap),
00118 next(e.next),
00119 prev(e.prev),
00120 owner(e.owner),
00121 pbucketmap(e.pbucketmap)
00122 {
00123
00124 w_assert9(w_offsetof(extlink_t, pmap) == 0);
00125 }
00126
00127 inline extlink_t&
00128 extlink_t::operator=(const extlink_t& e)
00129 {
00130 pmap = e.pmap;
00131 prev = e.prev;
00132 next = e.next;
00133 owner = e.owner;
00134 pbucketmap = e.pbucketmap;
00135 return *this;
00136 }
00137 inline void
00138 extlink_t::setmap(const Pmap &m)
00139 {
00140 pmap = m;
00141 }
00142 inline void
00143 extlink_t::getmap(Pmap &m) const
00144 {
00145 m = pmap;
00146 DBGTHRD(<<"getmap " << m);
00147 }
00148
00149 inline void
00150 extlink_t::clrall()
00151 {
00152 pmap.clear_all();
00153 }
00154
00155 inline void
00156 extlink_t::setall()
00157 {
00158 pmap.set_all();
00159 }
00160
00161 inline void
00162 extlink_t::set(int i)
00163 {
00164 pmap.set(i);
00165 }
00166
00167 inline void
00168 extlink_t::clr(int i)
00169 {
00170 pmap.clear(i);
00171 }
00172
00173 inline bool
00174 extlink_t::is_set(int i) const
00175 {
00176 w_assert9(i < smlevel_0::ext_sz);
00177 return pmap.is_set(i);
00178 }
00179
00180 inline bool
00181 extlink_t::is_clr(int i) const
00182 {
00183 return (! is_set(i));
00184 }
00185
00186 inline int extlink_t::first_set(int start) const
00187 {
00188 return pmap.first_set(start);
00189 }
00190
00191 inline int
00192 extlink_t::first_clr(int start) const
00193 {
00194 return pmap.first_clear(start);
00195 }
00196
00197 inline int
00198 extlink_t::last_set(int start) const
00199 {
00200 return pmap.last_set(start);
00201 }
00202
00203 inline int
00204 extlink_t::last_clr(int start) const
00205 {
00206 return pmap.last_clear(start);
00207 }
00208
00209 inline int
00210 extlink_t::num_set() const
00211 {
00212 return pmap.num_set();
00213 }
00214
00215 inline int
00216 extlink_t::num_clr() const
00217 {
00218 return pmap.num_clear();
00219 }
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 class extlink_p : public page_p {
00230 public:
00231 MAKEPAGE(extlink_p, page_p, 2);
00232
00233
00234
00235 enum { max = data_sz / sizeof(extlink_t) };
00236
00237 const extlink_t& get(slotid_t idx);
00238 void put(slotid_t idx, const extlink_t& e);
00239 w_rc_t set_byte(slotid_t idx, u_char bits,
00240 enum page_p::logical_operation);
00241 w_rc_t set_bytes(slotid_t idx,
00242 smsize_t offset,
00243 smsize_t count,
00244 const uint1_t* bits,
00245 enum page_p::logical_operation);
00246 void clr_pmap_bit(slotid_t idx, int bit);
00247 static bool on_same_page(extnum_t e1, extnum_t e2);
00248
00249 private:
00250 extlink_t& item(int i);
00251
00252 struct layout_t {
00253 extlink_t item[max];
00254 };
00255
00256
00257 friend class page_link_log;
00258 friend class extlink_i;
00259 };
00260
00261 inline bool
00262 extlink_p::on_same_page(extnum_t e1, extnum_t e2)
00263 {
00264 shpid_t p1 = e1 / (extlink_p::max);
00265 shpid_t p2 = e2 / (extlink_p::max);
00266 return (p1 == p2);
00267 }
00268
00269 inline extlink_t&
00270 extlink_p::item(int i)
00271 {
00272 w_assert9(i < max);
00273 return ((layout_t*)tuple_addr(0))->item[i];
00274 }
00275
00276
00277 inline const extlink_t&
00278 extlink_p::get(slotid_t idx)
00279 {
00280 return item(idx);
00281 }
00282
00283 inline int
00284 extlink_t::logged_size() {
00285
00286
00287
00288
00289
00290 return w_offsetof(extlink_t, pbucketmap);
00291 }
00292
00293 inline void
00294 extlink_p::put(slotid_t idx, const extlink_t& e)
00295 {
00296 DBG(<<"extlink_p::put(" << idx << " owner=" <<
00297 e.owner << ", " << e.next << ")");
00298 const vec_t extent_vec_tmp(&e, extlink_t::logged_size());
00299 W_COERCE(overwrite(0, idx * sizeof(extlink_t), extent_vec_tmp));
00300 }
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 struct stnode_t {
00311
00312 extnum_t head;
00313
00314 w_base_t::uint2_t eff;
00315
00316 w_base_t::uint2_t flags;
00317
00318 w_base_t::uint2_t deleting;
00319
00320 fill2 filler;
00321 };
00322
00323
00324
00325
00326
00327
00328
00329 class stnode_p : public page_p {
00330 public:
00331 MAKEPAGE(stnode_p, page_p, 1);
00332
00333
00334 enum { max = data_sz / sizeof(stnode_t) };
00335
00336 const stnode_t& get(slotid_t idx);
00337 rc_t put(slotid_t idx, const stnode_t& e);
00338
00339 private:
00340 stnode_t& item(snum_t i);
00341 struct layout_t {
00342 stnode_t item[max];
00343 };
00344
00345 friend class page_link_log;
00346 friend class stnode_i;
00347 };
00348
00349 inline stnode_t&
00350 stnode_p::item(snum_t i)
00351 {
00352 w_assert9(i < max);
00353 return ((layout_t*)tuple_addr(0))->item[i];
00354 }
00355
00356 inline const stnode_t&
00357 stnode_p::get(slotid_t idx)
00358 {
00359 return item(idx);
00360 }
00361
00362 inline w_rc_t
00363 stnode_p::put(slotid_t idx, const stnode_t& e)
00364 {
00365 const vec_t stnode_vec_tmp(&e, sizeof(e));
00366 W_DO(overwrite(0, idx * sizeof(stnode_t), stnode_vec_tmp));
00367 return RCOK;
00368 }
00369
00370
00371
00372
00373
00374
00375
00376 class extlink_i {
00377 public:
00378 NORET extlink_i(const lpid_t& root)
00379 :
00380 _root(root) {
00381
00382 w_assert1(root.page >= 1);
00383 }
00384
00385 bool on_same_root(extnum_t idx);
00386
00387 lpid_t get_pid(extnum_t idx) const;
00388 rc_t get(extnum_t idx, const extlink_t* &);
00389 rc_t get(extnum_t idx, extlink_t* &);
00390 rc_t get_copy(extnum_t idx, extlink_t &);
00391 rc_t put(extnum_t idx, const extlink_t&);
00392 bool on_same_page(extnum_t ext1, extnum_t ext2) const ;
00393
00394 rc_t update_histo(extnum_t ext,
00395 int offset,
00396 space_bucket_t bucket);
00397 rc_t fix_EX(extnum_t idx);
00398 void unfix();
00399 rc_t set_pmap_bits(snum_t snum, extnum_t idx, const Pmap &bits);
00400 rc_t clr_pmap_bit(snum_t snum, extnum_t idx, int bit);
00401
00402 rc_t clr_pmap_bits(snum_t snum, extnum_t idx, const Pmap &bits);
00403 rc_t set_next(extnum_t ext, extnum_t new_next, bool log_it = true);
00404 const extlink_p& page() const { return _page; }
00405
00406 private:
00407 extid_t _id;
00408 lpid_t _root;
00409 extlink_p _page;
00410
00411 inline w_rc_t update_pmap(extnum_t idx,
00412 const Pmap &pmap,
00413 page_p::logical_operation how);
00414 inline w_rc_t update_pbucketmap(extnum_t idx,
00415 uint4_t map,
00416 page_p::logical_operation how);
00417 };
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434 class stnode_i: private smlevel_0 {
00435 public:
00436 NORET stnode_i(const lpid_t& root) : _root(root) {
00437
00438
00439 w_assert1(root.page >= 1);
00440 };
00441 w_rc_t get(snum_t idx, stnode_t &stnode);
00442 w_rc_t get(snum_t idx, const stnode_t *&stnode);
00443 w_rc_t put(snum_t idx, const stnode_t& stnode);
00444 w_rc_t store_operation(const store_operation_param & op);
00445 private:
00446 lpid_t _root;
00447 stnode_p _page;
00448 };
00449
00450
00451
00452
00453 #endif