00001 // Copyright (C) 2001, Compaq Computer Corporation 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 // 00020 // VDirVolatileRoot.H 00021 // Last modified on Fri Feb 10 19:00:18 EST 2006 by ken@xorian.net 00022 // modified on Mon Nov 27 17:12:21 PST 2000 by mann 00023 // 00024 // One-of-a-kind pseudo-directory used to keep track of volatile 00025 // directories that have been created. Unlike true VestaSource 00026 // objects, this object has real state, not just a short pointer into 00027 // the sweepable memory pool. 00028 // 00029 00030 #ifndef _VDIRVOLR 00031 #define _VDIRVOLR 00032 00033 #include "VestaSource.H" 00034 #include "ReadersWritersLock.H" 00035 00036 // This directory is protected by VolatileRootLock. Each subtree 00037 // immediately below it is protected by a separate lock of its own, 00038 // which can be obtained using the lookupIndexAndLock method. A write 00039 // lock on the root and every tree below can be acquired/released with 00040 // the lockAll/unlockAll methods. Only one volatile root directory 00041 // exists. Multiple VDirVolatileRoot objects can be created, but they 00042 // all reference the same directory. 00043 00044 class VDirVolatileRoot : public VestaSource { 00045 public: 00046 // Must be called exactly once during repository initialization. 00047 static void init() throw(); 00048 00049 // Our versions of virtual methods from base class. 00050 // These require VolatileRootLock.read and do not obtain any locks. 00051 inline void resync(AccessControl::Identity who =NULL) throw () { }; 00052 VestaSource::errorCode lookup(Arc arc, VestaSource*& result, 00053 AccessControl::Identity who =NULL, 00054 unsigned int indexOffset =0) throw (); 00055 VestaSource::errorCode lookupIndex(unsigned int index, 00056 VestaSource*& result, 00057 char* arcbuf =NULL) throw(); 00058 VestaSource::errorCode 00059 list(unsigned int firstIndex, 00060 VestaSource::listCallback callback, void* closure, 00061 AccessControl::Identity who =NULL, 00062 bool deltaOnly =false, unsigned int indexOffset =0) 00063 throw (); 00064 inline time_t timestamp() throw() { return 2; }; 00065 00066 // Garbage collection support 00067 // Requrires VolatileRootLock.write and all subtree write locks. 00068 void mark(bool byName =true, ArcTable* hidden =NULL) throw(); 00069 00070 // Write the volatile memory checkpoint 00071 // Requrires VolatileRootLock.write and all subtree write locks. 00072 Bit32 checkpoint(Bit32& nextSP, std::fstream& ckpt) throw(); 00073 00074 // Checkpoint other state as log-style records 00075 // Requrires VolatileRootLock.write and all subtree write locks. 00076 static void finishCheckpoint(std::fstream& ckpt) throw(); 00077 00078 // Special methods for this object type only: 00079 00080 // Create a new volatile directory under the volatile root, based 00081 // on an evaluatorDirectory specified by (hostname, port, handle), and 00082 // lock it. May acquire and release StableLock, and takes care of 00083 // acquiring VolatileRootLock, so caller must not hold them. 00084 VestaSource::errorCode 00085 createVolatileDirectory(char* hostname, char* port, Bit64 handle, 00086 VestaSource*& result, time_t timestamp, 00087 LongId::lockKindTag lockKind, 00088 ReadersWritersLock** lock, 00089 bool readOnlyExisting) throw(); 00090 00091 00092 // Delete by index. Not needed in other kinds of directory. 00093 // Requrires VolatileRootLock.write. 00094 VestaSource::errorCode 00095 deleteIndex(unsigned int index) throw(); 00096 00097 // Lookup by index and lock the subtree. 00098 // Requrires VolatileRootLock.write. 00099 VestaSource::errorCode 00100 lookupIndexAndLock(unsigned int index, VestaSource*& result, 00101 LongId::lockKindTag lockKind, 00102 ReadersWritersLock** lock) throw(); 00103 00104 // Lock the root and all subtrees. 00105 static void lockAll(); 00106 00107 // Unlock the root and all subtrees. 00108 static void unlockAll(); 00109 00110 virtual VestaSource *copy() throw(); 00111 }; 00112 00113 00114 #endif // _VDIRVOLR