Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

MutableSidref.C

Go to the documentation of this file.
00001 // Copyright (C) 2005, Vesta free software project
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // MutableSidref.C - suopport functions for mutable shortid reference
00020 // counting in the mutable root
00021 
00022 #include "MutableSidref.H"
00023 #include "VDirChangeable.H"
00024 #include "logging.H"
00025 
00026 // Should we skip the check altogether?
00027 static bool skip_check = true;
00028 
00029 // Should we automatically correct any inconsistency detected?
00030 static bool auto_correct = true;
00031 
00032 // Should we consistency check across log recovery?
00033 static bool recovery_check = false;
00034 
00035 // Single-time initialization code
00036 static pthread_once_t MutableSidrefCheck_once = PTHREAD_ONCE_INIT;
00037 extern "C"
00038 {
00039   static void MutableSidrefCheck_init()
00040   {
00041     Text value;
00042     if(VestaConfig::get("Repository", "mutable_sid_refcount_paranoia", /*OUT*/ value))
00043       {
00044         // Development mode: abort if an inconsistency is detected
00045         if(value == "abort")
00046           {
00047             skip_check = false;
00048             auto_correct = false;
00049 
00050             // Do extra checking that recovering log entries updates
00051             // sidref correctly.
00052             recovery_check = true;
00053           }
00054         // Early deployment mode: auto-correct if an inconsistency is
00055         // detected
00056         else if(value == "correct")
00057           {
00058             skip_check = false;
00059             auto_correct = true;
00060           }
00061         // Default to skipping the check
00062         else
00063           {
00064             skip_check = true;
00065           }
00066       }
00067     else
00068       {
00069         skip_check = true;
00070       }
00071   }
00072 }
00073 
00074 void MutableSidrefInit()
00075 {
00076   Repos::dprintf(DBG_ALWAYS, 
00077                  "Rebuilding mutable shortid reference counts\n");
00078   ((VDirChangeable *) VestaSource::mutableRoot())->buildMutableSidref();
00079   Repos::dprintf(DBG_ALWAYS, 
00080                  "Done rebuilding mutable shortid reference counts\n");
00081 }
00082 
00083 void MutableSidrefCheck(VestaSource *vs, ReadersWritersLock *lock)
00084 {
00085   if((vs != 0) && (lock != 0))
00086     MutableSidrefCheck(vs->longid, lock);
00087 }
00088 
00089 void MutableSidrefCheck(const LongId &longid, ReadersWritersLock *lock)
00090 {
00091   if(MutableRootLongId.isAncestorOf(longid))
00092     {
00093       MutableSidrefCheck(lock, LongId::checkLock);
00094     }
00095 }
00096 
00097 void MutableSidrefCheck(ReadersWritersLock *lock,
00098                         LongId::lockKindTag lockKind)
00099 {
00100   // Ensure that we've initialized our settings
00101   pthread_once(&MutableSidrefCheck_once, MutableSidrefCheck_init);
00102 
00103   // Do nothing if we're supposed to skip the check
00104   if(skip_check) return;
00105 
00106   // Acquire or check the lock
00107   bool releaseLock = false;
00108   VestaSource *mr = 0;
00109   if(lock != 0)
00110     {
00111       mr = VestaSource::mutableRoot(LongId::checkLock, &lock);
00112     }
00113   else
00114     {
00115       mr = VestaSource::mutableRoot(lockKind, &lock);
00116       releaseLock = (lock != 0);
00117     }
00118   assert(mr != 0);
00119 
00120   // Perform the consistency check
00121   ((VDirChangeable *) mr)->checkMutableSidref();
00122 
00123   // Release the lock if needed
00124   if(releaseLock) lock->releaseWrite();
00125 }
00126 
00127 bool MutableSidrefRecoveryCheck()
00128 {
00129   // Ensure that we've initialized our settings
00130   pthread_once(&MutableSidrefCheck_once, MutableSidrefCheck_init);
00131 
00132   return recovery_check; 
00133 }

Generated on Mon May 8 00:48:45 2006 for Vesta by  doxygen 1.4.2