store_latch_manager.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='STID_T_H'>
00025 
00026  $Id: store_latch_manager.h,v 1.2 2010/05/26 01:20:12 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 STORE_LATCH_MGR_H
00054 #define STORE_LATCH_MGR_H
00055 
00056 #include "w_defines.h"
00057 
00058 /*  -- do not edit anything above this line --   </std-header>*/
00059 
00060 #ifndef BASICS_H
00061 #include "basics.h"
00062 #endif
00063 
00064 #ifndef STID_T_H
00065 #include "stid_t.h"
00066 #endif
00067 
00068 #ifndef LATCH_H
00069 #include "latch.h"
00070 #endif
00071 
00072 #include <map>
00073 
00074 /**\brief  Manages a set of latches, one per store id.
00075  *
00076  * \details
00077  *  This allows us to grab per-store latches without latching a
00078  *  buffer-pool page, which requires a read, and consumes buffer-pool
00079  *  space.
00080  *
00081  *  Used by the btree implementation and by the page allocation.
00082  *
00083  *  When a store is destroyed or its volume dismounted, the
00084  *  latch should be removed from the map and destroyed.
00085  */
00086 class store_latch_manager 
00087 {
00088 private:
00089     struct stid_cmp {
00090         bool operator() (const stid_t &lhs, const stid_t &rhs) const
00091         { return (lhs.vol < rhs.vol)  
00092             || ( (lhs.vol == rhs.vol) && (lhs.store < rhs.store)); }
00093 
00094     };
00095     typedef std::map<stid_t, latch_t*, stid_cmp> latch_map;
00096     latch_map _latches ;
00097 #define USE_OCC_LOCK_HERE 1
00098 #ifdef USE_OCC_LOCK_HERE
00099     occ_rwlock _latch_lock;
00100 #else
00101     queue_based_lock_t _latch_lock;
00102 #endif
00103     void _destroy_latches(stid_t const &store) ; // worker, assumes have lock
00104 
00105 public:
00106     // Return a ref to the per-store latch. If none exists, creates one.
00107     latch_t &find_latch(stid_t const &store) ;
00108     // Destroy latche for this store.
00109     void destroy_latches(stid_t const &store) ; // on destroy_store
00110     // Destroy all latches for stores on this volume.
00111     void destroy_latches(vid_t const &volume) ; // on dismount
00112     // Clean up for shutting down storage manager.
00113     void shutdown() ;
00114     ~store_latch_manager() ;
00115 }; 
00116 
00117 extern store_latch_manager store_latches;
00118 
00119 #endif

Generated on Wed Jul 7 17:22:32 2010 for Shore Storage Manager by  doxygen 1.4.7