sm_s.h

00001 /* -*- mode:C++; c-basic-offset:4 -*-
00002      Shore-MT -- Multi-threaded port of the SHORE storage manager
00003    
00004                        Copyright (c) 2007-2009
00005       Data Intensive Applications and Systems Labaratory (DIAS)
00006                Ecole Polytechnique Federale de Lausanne
00007    
00008                          All Rights Reserved.
00009    
00010    Permission to use, copy, modify and distribute this software and
00011    its documentation is hereby granted, provided that both the
00012    copyright notice and this permission notice appear in all copies of
00013    the software, derivative works or modified versions, and any
00014    portions thereof, and that both notices appear in supporting
00015    documentation.
00016    
00017    This code is distributed in the hope that it will be useful, but
00018    WITHOUT ANY WARRANTY; without even the implied warranty of
00019    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS
00020    DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
00021    RESULTING FROM THE USE OF THIS SOFTWARE.
00022 */
00023 
00024 /*<std-header orig-src='shore' incl-file-exclusion='SM_S_H'>
00025 
00026  $Id: sm_s.h,v 1.93 2010/10/27 17:04:23 nhall Exp $
00027 
00028 SHORE -- Scalable Heterogeneous Object REpository
00029 
00030 Copyright (c) 1994-99 Computer Sciences Department, University of
00031                       Wisconsin -- Madison
00032 All Rights Reserved.
00033 
00034 Permission to use, copy, modify and distribute this software and its
00035 documentation is hereby granted, provided that both the copyright
00036 notice and this permission notice appear in all copies of the
00037 software, derivative works or modified versions, and any portions
00038 thereof, and that both notices appear in supporting documentation.
00039 
00040 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
00041 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
00042 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
00043 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
00044 
00045 This software was developed with support by the Advanced Research
00046 Project Agency, ARPA order number 018 (formerly 8230), monitored by
00047 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
00048 Further funding for this work was provided by DARPA through
00049 Rome Research Laboratory Contract No. F30602-97-2-0247.
00050 
00051 */
00052 
00053 #ifndef SM_S_H
00054 #define SM_S_H
00055 
00056 #include "w_defines.h"
00057 
00058 /*  -- do not edit anything above this line --   </std-header>*/
00059 
00060 /**\brief Extent Number
00061  *\ingroup IDS
00062  * \details
00063  * This type represents an extent number, 
00064  * used in extid_t.
00065  */
00066 typedef w_base_t::uint4_t        extnum_t;
00067 
00068 #ifndef STHREAD_H
00069 #include <sthread.h>
00070 #endif
00071 
00072 #ifndef STID_T_H
00073 #include <stid_t.h>
00074 #endif
00075 
00076 #ifdef __GNUG__
00077 #pragma interface
00078 #endif
00079 
00080 /**\brief Extent ID.
00081  * \details
00082  * Identifies an extent of a volume.  Needed to
00083  * acquire an extent lock.  Most of the internal interfaces use
00084  * the extnum_t since the volume is implicit.
00085  */
00086 class extid_t {
00087 public:
00088     vid_t        vol; 
00089     fill2        filler; // because vol is 2 bytes & ext is 4
00090     extnum_t     ext;
00091 
00092     friend ostream& operator<<(ostream&, const extid_t& x);
00093     friend istream& operator>>(istream&, extid_t &x); 
00094 };
00095 
00096 /**\brief Long page ID.
00097  * \details
00098  * Store ID (volume number + store number) + page number.
00099  */
00100 class lpid_t {
00101 public:
00102     stid_t        _stid;
00103     shpid_t        page;
00104     
00105     lpid_t();
00106     lpid_t(const stid_t& s, shpid_t p);
00107     lpid_t(vid_t v, snum_t s, shpid_t p);
00108     //    operator bool() const;
00109     bool valid() const;
00110 
00111     vid_t         vol()   const {return _stid.vol;}
00112     snum_t        store() const {return _stid.store;}
00113     const stid_t& stid() const {return _stid;}
00114 
00115     // necessary and sufficient conditions for
00116     // is_null() are determined by default constructor, q.v.
00117     bool        is_null() const { return page == 0; }
00118 
00119     bool operator==(const lpid_t& p) const;
00120     bool operator!=(const lpid_t& p) const;
00121     bool operator<(const lpid_t& p) const;
00122     bool operator<=(const lpid_t& p) const;
00123     bool operator>(const lpid_t& p) const;
00124     bool operator>=(const lpid_t& p) const;
00125     friend ostream& operator<<(ostream&, const lpid_t& p);
00126     friend istream& operator>>(istream&, lpid_t& p);
00127 
00128 
00129     static const lpid_t bof;
00130     static const lpid_t eof;
00131     static const lpid_t null;
00132 };
00133 
00134 
00135 
00136 class rid_t;
00137 
00138 /**\brief Short Record ID
00139  *\ingroup IDS
00140  * \details
00141  * This class represents a short record identifier, which is
00142  * used when the volume id is implied somehow.
00143  *
00144  * A short record id contains a slot, a (short) page id, and a store number.
00145  * A short page id is just a page number (in basics.h).
00146  *
00147  * See \ref IDS.
00148  */
00149 class shrid_t {
00150 public:
00151     shpid_t        page;
00152     snum_t        store;
00153     slotid_t        slot;
00154     fill2        filler; // because page, snum_t are 4 bytes, slotid_t is 2
00155 
00156     shrid_t();
00157     shrid_t(const rid_t& r);
00158     shrid_t(shpid_t p, snum_t st, slotid_t sl) : page(p), store(st), slot(sl) {}
00159     friend ostream& operator<<(ostream&, const shrid_t& s);
00160     friend istream& operator>>(istream&, shrid_t& s);
00161 };
00162 
00163 
00164 #define RID_T
00165 
00166 /**\brief Record ID
00167  *\ingroup IDS
00168  * \details
00169  * This class represents a long record identifier, used in the
00170  * Storage Manager API, but not stored persistently.
00171  *
00172  * A record id contains a slot and a (long) page id.
00173  * A long page id contains a store id and a volume id.
00174  *
00175  * See \ref IDS.
00176  */
00177 class rid_t {
00178 public:
00179     lpid_t        pid;
00180     slotid_t        slot;
00181     fill2        filler;  // for initialization of last 2 unused bytes
00182 
00183     rid_t();
00184     rid_t(vid_t vid, const shrid_t& shrid);
00185     rid_t(const lpid_t& p, slotid_t s) : pid(p), slot(s) {};
00186 
00187     stid_t stid() const;
00188 
00189     bool operator==(const rid_t& r) const;
00190     bool operator!=(const rid_t& r) const;
00191     friend ostream& operator<<(ostream&, const rid_t& s);
00192     friend istream& operator>>(istream&, rid_t& s);
00193 
00194     static const rid_t null;
00195 };
00196 
00197 #include <lsn.h>
00198 
00199 /**\brief Encapsulates metadata about the type of an index key.
00200  * \details Contains the following type metadata:
00201  * - indication of integer/float/uninterpreted
00202  * - length (size as well as indication of fixed or variable) 
00203  * - indication of compressed or not
00204  */
00205 struct key_type_s {
00206     enum type_t {
00207         i = 'i',                // integer (1,2,4)
00208         I = 'I',                // integer (1,2,4), compressed
00209         u = 'u',                // unsigned integer (1,2,4)
00210         U = 'U',                // unsigned integer (1,2,4), compressed
00211         f = 'f',                // float (4,8)
00212         F = 'F',                // float (4,8), compressed
00213         b = 'b',                // binary (uninterpreted) (vbl or fixed-len)
00214         B = 'B'                        // compressed binary (uninterpreted) (vbl or fixed-len)
00215         // NB : u1==b1, u2==b2, u4==b4 semantically, 
00216         // BUT
00217         // u2, u4 must be  aligned, whereas b2, b4 need not be,
00218         // AND
00219         // u2, u4 may use faster comparisons than b2, b4, which will 
00220         // always use umemcmp (possibly not optimized). 
00221     };
00222     enum max_length_t { max_len = 2000 };
00223     char        type;
00224     char        variable; // Boolean - but its size is unpredictable
00225     uint2_t     length;        
00226     char        compressed; // Boolean - but its size is unpredictable
00227 #ifdef __GNUG__        /* XXX ZERO_INIT canidate? */
00228     fill1        dummy; 
00229 #endif
00230 
00231     key_type_s(type_t t = (type_t)0, char v = 0, uint2_t l = 0) 
00232         : type((char) t), variable(v), length(l), compressed(false)  {};
00233 
00234     // This function parses a key descriptor string "s" and
00235     // translates it into an array of key_type_s, "kc".  The initial
00236     // length of the array is passed in through "count" and
00237     // the number of elements filled in "kc" is returned through
00238     // "count". 
00239     static w_rc_t parse_key_type(const char* s, w_base_t::uint4_t& count, key_type_s kc[]);
00240     static w_rc_t get_key_type(char* s, int buflen, w_base_t::uint4_t count, const key_type_s *kc);
00241 
00242 };
00243 #define null_lsn (lsn_t::null)
00244 #define max_lsn  (lsn_t::max)
00245 
00246 inline ostream& operator<<(ostream& o, const lsn_t& l)
00247 {
00248     return o << l.file() << '.' << l.rba();
00249 }
00250 
00251 inline istream& operator>>(istream& i, lsn_t& l)
00252 {
00253     sm_diskaddr_t d;
00254     char c;
00255     w_base_t::uint8_t f;
00256     i >> f >> c >> d;
00257     l = lsn_t(f, d);
00258     return i;
00259 }
00260 
00261 inline lpid_t::lpid_t() : page(0) {}
00262 
00263 inline lpid_t::lpid_t(const stid_t& s, shpid_t p) : _stid(s), page(p)
00264 {}
00265 
00266 inline lpid_t::lpid_t(vid_t v, snum_t s, shpid_t p) :
00267         _stid(v, s), page(p)
00268 {}
00269 
00270 inline shrid_t::shrid_t() : page(0), store(0), slot(0)
00271 {}
00272 inline shrid_t::shrid_t(const rid_t& r) :
00273         page(r.pid.page), store(r.pid.store()), slot(r.slot)
00274 {}
00275 
00276 inline rid_t::rid_t() : slot(0)
00277 {}
00278 
00279 inline rid_t::rid_t(vid_t vid, const shrid_t& shrid) :
00280         pid(vid, shrid.store, shrid.page), slot(shrid.slot)
00281 {}
00282 
00283 inline stid_t rid_t::stid() const
00284 {
00285     return pid.stid();
00286 }
00287 
00288 inline bool lpid_t::operator==(const lpid_t& p) const
00289 {
00290     return (page == p.page) && (stid() == p.stid());
00291 }
00292 
00293 inline bool lpid_t::operator!=(const lpid_t& p) const
00294 {
00295     return !(*this == p);
00296 }
00297 
00298 inline bool lpid_t::operator<=(const lpid_t& p) const
00299 {
00300     return _stid == p._stid && page <= p.page;
00301 }
00302 
00303 inline bool lpid_t::operator>=(const lpid_t& p) const
00304 {
00305     return _stid == p._stid && page >= p.page;
00306 }
00307 
00308 inline bool rid_t::operator==(const rid_t& r) const
00309 {
00310     return (pid == r.pid && slot == r.slot);
00311 }
00312 
00313 inline bool rid_t::operator!=(const rid_t& r) const
00314 {
00315     return !(*this == r);
00316 }
00317 
00318 /*<std-footer incl-file-exclusion='SM_S_H'>  -- do not edit anything below this line -- */
00319 
00320 #endif          /*</std-footer>*/

Generated on Mon Nov 8 11:12:38 2010 for Shore Storage Manager by  doxygen 1.4.7