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

ShortIdBlock.H

Go to the documentation of this file.
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 // ShortIdBlock.H
00021 // Last modified on Mon Nov 12 18:37:56 EST 2001 by ken@xorian.net
00022 //      modified on Fri Jul 27 18:24:29 PDT 2001 by mann
00023 //
00024 // This is a low-level interface to the repository server, used by the 
00025 // SourceOrDerived library code.  
00026 //
00027 #ifndef _VSIDB
00028 #define _VSIDB
00029 
00030 #include <sys/socket.h>
00031 #include <sys/types.h>
00032 #include "SourceOrDerived.H"
00033 #include "SRPC.H"
00034 
00035 // A ShortIdBlock represents a block of (possibly) available ShortIds.
00036 // They all have the same leafflag value.  Methods here are all local code,
00037 // not RPC.
00038 // 
00039 class ShortIdBlock {
00040   public:
00041     enum { size=256 }; // must be a power of 2
00042     Bit8 bits[size / 8];
00043     ShortId start;
00044     time_t leaseExpires;
00045     enum { leaseNonexpiring = 0x7fffffff };
00046     // ShortIdBlock will not assign a ShortId with dirFlag set and
00047     //  leafFlag clear; only DirShortId will do that.  (Note: the
00048     //  present allocator does not use ShortIds with dirFlag and
00049     //  leafFlag both set, but some are still assigned at SRC as normal
00050     //  leaf blocks for historical reasons.)
00051     enum { leafFlag = 0x80000000, dirFlag = 0x40000000 };
00052     ShortId next;     // next >= start
00053 
00054     ShortId assignNextAvail() throw();  // => NullShortId if none available
00055     inline bool assigned(ShortId s) const throw()
00056       { return (bool) ((bits[(s-start)/8] & (1 << ((s-start)%8))) != 0); };
00057     inline void set(ShortId s) throw()
00058       { bits[(s-start)/8] |= 1 << ((s-start)%8); };
00059     inline bool leaf() throw()
00060       { return SourceOrDerived::leafShortId(start); };
00061     inline void init(ShortId st) throw() {
00062         memset((void *) bits, 0, sizeof(bits));
00063         next = start = st;
00064         leaseExpires = 0;
00065     };
00066 
00067     // The following are methods only for name scoping purposes
00068 
00069     // Convert ShortId to filename.  If prepend is "", the name is
00070     // relative to [Repository]metadata_root as defined in the
00071     // vesta.cfg file.  If prepend is nonempty, its value is prepended
00072     // to the string that would otherwise be returned.  The caller is
00073     // responsible for freeing the storage returned.
00074     static char* shortIdToName(ShortId sid, const char* prepend ="") throw();
00075 
00076     // RPC to get a new block of ShortIds from the server, all with
00077     // the specified leafflag.  On return, the block is leased to the
00078     // caller until block->leaseExpires (set by the function).  If the
00079     // lease expires without being renewed (below), the server will
00080     // eventually notice and reclaim all unused ShortIds in the block.
00081     // The caller is responsible for freeing the storage returned.
00082     //
00083     static ShortIdBlock *acquire(bool leafflag =false) throw (SRPC::failure);
00084 
00085     // RPC to renew the lease on a block.  Returns false if the block's
00086     // lease had already expired.  (Allowing a lease to expire is a fatal
00087     // client error.)  Otherwise, returns true, and the block is leased to
00088     // the caller until block.leaseExpires (set by the function).  
00089     //
00090     static bool renew(ShortIdBlock *block) throw (SRPC::failure);
00091 
00092     // RPC to return a block to the server.  The caller promises not
00093     // to assign any more ShortIds from this block, even if some are
00094     // still unused.  This routine should be called when a process is
00095     // going to shut down, or when it has used up a block.
00096     // This routine does not free the local storage for the block.
00097     //
00098     static void release(ShortIdBlock *block) throw (SRPC::failure);
00099 
00100     // RPC Weeder interface.  See SourceOrDerived.H.
00101     static int keepDerived(ShortIdsFile ds, time_t dt, bool force)
00102       throw (SRPC::failure);
00103     static void checkpoint() throw (SRPC::failure);
00104     static void getWeedingState(ShortIdsFile& ds, time_t& dt,
00105                                 ShortIdsFile& ss, time_t& st,
00106                                 bool& sourceWeedInProgress,
00107                                 bool& deletionsInProgress,
00108                                 bool& deletionsDone,
00109                                 bool& checkpointInProgress)
00110       throw(SRPC::failure);
00111 };
00112 
00113 #endif // _VSIDB
00114 
00115 
00116 

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