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.94 2010/12/08 17:37:43 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 /**\brief Record ID
00165  *\ingroup IDS
00166  * \details
00167  * This class represents a long record identifier, used in the
00168  * Storage Manager API, but not stored persistently.
00169  *
00170  * A record id contains a slot and a (long) page id.
00171  * A long page id contains a store id and a volume id.
00172  *
00173  * See \ref IDS.
00174  */
00175 class rid_t {
00176 public:
00177     lpid_t        pid;
00178     slotid_t        slot;
00179     fill2        filler;  // for initialization of last 2 unused bytes
00180 
00181     rid_t();
00182     rid_t(vid_t vid, const shrid_t& shrid);
00183     rid_t(const lpid_t& p, slotid_t s) : pid(p), slot(s) {};
00184 
00185     stid_t stid() const;
00186 
00187     bool operator==(const rid_t& r) const;
00188     bool operator!=(const rid_t& r) const;
00189     friend ostream& operator<<(ostream&, const rid_t& s);
00190     friend istream& operator>>(istream&, rid_t& s);
00191 
00192     static const rid_t null;
00193 };
00194 
00195 #include <lsn.h>
00196 
00197 /**\brief Encapsulates metadata about the type of an index key.
00198  * \details Contains the following type metadata:
00199  * - indication of integer/float/uninterpreted
00200  * - length (size as well as indication of fixed or variable) 
00201  * - indication of compressed or not
00202  */
00203 struct key_type_s {
00204     enum type_t {
00205         i = 'i',                // integer (1,2,4)
00206         I = 'I',                // integer (1,2,4), compressed
00207         u = 'u',                // unsigned integer (1,2,4)
00208         U = 'U',                // unsigned integer (1,2,4), compressed
00209         f = 'f',                // float (4,8)
00210         F = 'F',                // float (4,8), compressed
00211         b = 'b',                // binary (uninterpreted) (vbl or fixed-len)
00212         B = 'B'                        // compressed binary (uninterpreted) (vbl or fixed-len)
00213         // NB : u1==b1, u2==b2, u4==b4 semantically, 
00214         // BUT
00215         // u2, u4 must be  aligned, whereas b2, b4 need not be,
00216         // AND
00217         // u2, u4 may use faster comparisons than b2, b4, which will 
00218         // always use umemcmp (possibly not optimized). 
00219     };
00220     enum max_length_t { max_len = 2000 };
00221     char        type;
00222     char        variable; // Boolean - but its size is unpredictable
00223     uint2_t     length;        
00224     char        compressed; // Boolean - but its size is unpredictable
00225 #ifdef __GNUG__        /* XXX ZERO_INIT canidate? */
00226     fill1        dummy; 
00227 #endif
00228 
00229     key_type_s(type_t t = (type_t)0, char v = 0, uint2_t l = 0) 
00230         : type((char) t), variable(v), length(l), compressed(false)  {};
00231 
00232     // This function parses a key descriptor string "s" and
00233     // translates it into an array of key_type_s, "kc".  The initial
00234     // length of the array is passed in through "count" and
00235     // the number of elements filled in "kc" is returned through
00236     // "count". 
00237     static w_rc_t parse_key_type(const char* s, w_base_t::uint4_t& count, key_type_s kc[]);
00238     static w_rc_t get_key_type(char* s, int buflen, w_base_t::uint4_t count, const key_type_s *kc);
00239 
00240 };
00241 
00242 inline ostream& operator<<(ostream& o, const lsn_t& l)
00243 {
00244     return o << l.file() << '.' << l.rba();
00245 }
00246 
00247 inline istream& operator>>(istream& i, lsn_t& l)
00248 {
00249     sm_diskaddr_t d;
00250     char c;
00251     w_base_t::uint8_t f;
00252     i >> f >> c >> d;
00253     l = lsn_t(f, d);
00254     return i;
00255 }
00256 
00257 inline lpid_t::lpid_t() : page(0) {}
00258 
00259 inline lpid_t::lpid_t(const stid_t& s, shpid_t p) : _stid(s), page(p)
00260 {}
00261 
00262 inline lpid_t::lpid_t(vid_t v, snum_t s, shpid_t p) :
00263         _stid(v, s), page(p)
00264 {}
00265 
00266 inline shrid_t::shrid_t() : page(0), store(0), slot(0)
00267 {}
00268 inline shrid_t::shrid_t(const rid_t& r) :
00269         page(r.pid.page), store(r.pid.store()), slot(r.slot)
00270 {}
00271 
00272 inline rid_t::rid_t() : slot(0)
00273 {}
00274 
00275 inline rid_t::rid_t(vid_t vid, const shrid_t& shrid) :
00276         pid(vid, shrid.store, shrid.page), slot(shrid.slot)
00277 {}
00278 
00279 inline stid_t rid_t::stid() const
00280 {
00281     return pid.stid();
00282 }
00283 
00284 inline bool lpid_t::operator==(const lpid_t& p) const
00285 {
00286     return (page == p.page) && (stid() == p.stid());
00287 }
00288 
00289 inline bool lpid_t::operator!=(const lpid_t& p) const
00290 {
00291     return !(*this == p);
00292 }
00293 
00294 inline bool lpid_t::operator<=(const lpid_t& p) const
00295 {
00296     return _stid == p._stid && page <= p.page;
00297 }
00298 
00299 inline bool lpid_t::operator>=(const lpid_t& p) const
00300 {
00301     return _stid == p._stid && page >= p.page;
00302 }
00303 
00304 inline bool rid_t::operator==(const rid_t& r) const
00305 {
00306     return (pid == r.pid && slot == r.slot);
00307 }
00308 
00309 inline bool rid_t::operator!=(const rid_t& r) const
00310 {
00311     return !(*this == r);
00312 }
00313 
00314 /*<std-footer incl-file-exclusion='SM_S_H'>  -- do not edit anything below this line -- */
00315 
00316 #endif          /*</std-footer>*/

Generated on Mon Jan 2 15:13:57 2012 for Shore Storage Manager by  doxygen 1.4.7