Bdb packages | Design docs | Source docs | Guidelines | Recent releases

Search | Site Map .

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/BdbClustering/BdbFSSupportClustH.cc

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // File:
00003 //      BdbFSSupportClustH.cc
00004 //
00005 // Description:
00006 //
00007 // Environment:
00008 //      Software developed for the BaBar Detector at the SLAC B-Factory
00009 //
00010 // Author List:
00011 //      Jacek Becla                 Original Author
00012 //      Igor A. Gaponenko           Modified to use DBFS interace of BdbDomain class
00013 //
00014 // Copyright Information:
00015 //      Copyright (C) 1997          Stanford Linear Accelerator Center
00016 //
00017 //------------------------------------------------------------------------------
00018 
00019 // -------------------------
00020 // -- This Class's Header --
00021 // -------------------------
00022 #include "BdbClustering/BdbFSSupportClustH.hh"
00023 
00024 // ---------------------------------
00025 // -- Collaborating Class Headers --
00026 // ---------------------------------
00027 #include "BdbApplication/BdbDebug.hh"
00028 #include "BdbApplication/BdbErrorSignal.hh"
00029 #include "BdbAccess/BdbFSMgr.hh"
00030 #include "BdbAccess/BdbClusterConfigMgr.hh"
00031 #include "BdbClustering/BdbClusteringErrors.hh"
00032 
00033 // -------------------------------
00034 // -- Constructors / Destructor --
00035 // -------------------------------
00036 
00037 BdbFSSupportClustH::BdbFSSupportClustH(d_Boolean quiet)
00038 {
00039         _currentAuthLevel = BdbDomain::IllegalAuth ;
00040         _currentDomain    = BdbDomain::IllegalDomain ;
00041     _currentAuthName  = 0;
00042    _fsMgr = new BdbFSMgr ;
00043    _es = new BdbErrorSignal(quiet);
00044    _quietMode = quiet;
00045 }
00046 
00047 
00048 BdbFSSupportClustH::BdbFSSupportClustH(const BdbDomain& domain, 
00049                                        d_Boolean quiet)
00050 {
00051     _domain           = &domain ;
00052     _currentAuthLevel = BdbDomain::IllegalAuth ;
00053     _currentDomain    = BdbDomain::IllegalDomain ;
00054     _currentAuthName  = 0;
00055 
00056    _fsMgr = new BdbFSMgr ;
00057    _es = new BdbErrorSignal(quiet);
00058    _quietMode = quiet;
00059 }
00060 
00061 
00062 BdbFSSupportClustH::BdbFSSupportClustH(const BdbFSSupportClustH& obj)
00063 : _currentPath(obj._currentPath), 
00064   _currentDbName(obj._currentDbName)
00065 
00066 {
00067    _domain           = obj._domain ;
00068    _fsMgr            = new BdbFSMgr ;
00069    _defFS            = obj._defFS ;
00070    _currentAuthLevel = obj._currentAuthLevel ;
00071 
00072     const char* n = obj._currentAuthName.head();
00073     if ( 0 == n ) {
00074         _currentAuthName = 0;
00075     } else {
00076         _currentAuthName.resize(strlen(n)+1);
00077         _currentAuthName = n;
00078     }
00079 
00080    _currentDomain    = obj._currentDomain ;
00081    _es               = new BdbErrorSignal(obj._es->mode());
00082    _quietMode        = obj._quietMode;
00083 }
00084 
00085 BdbFSSupportClustH::~BdbFSSupportClustH()
00086 {
00087     if ( _fsMgr != 0 ) {
00088         delete _fsMgr ;
00089     }
00090     delete _es;
00091 }
00092 
00093 
00094 
00095 
00096 void 
00097 BdbFSSupportClustH::setDbNameAndPath(const char* name, const char* path)
00098 {
00099     _currentDbName.resize(strlen(name)+1);
00100     _currentDbName = name;
00101     
00102     _currentPath.resize(strlen(path)+1);
00103     _currentPath = path;
00104 }
00105 
00106 
00107 
00108 const BdbDomain* 
00109 BdbFSSupportClustH::domain() const
00110 {
00111     if ( _domain == 0 ) {
00112         _es->BdbFSig(BdbClusteringErrFunctionFailed,
00113                   "BdbFSSupportClustH::domain", "_domain not initialized") ;
00114     }
00115     return _domain ;
00116 }
00117 
00118 void 
00119 BdbFSSupportClustH::refreshCurrentAuthLevel()
00120 {
00121     _currentAuthLevel = domain()->authLevel() ; 
00122 }
00123 
00124 void 
00125 BdbFSSupportClustH::refreshCurrentAuthName()
00126 {
00127     const char* nnn = domain()->authName();
00128     const char* old = _currentAuthName.head();
00129     
00130     if ( 0 == nnn ) {
00131         if ( 0 != old ) {
00132             _currentAuthName.resize(0);
00133             _currentAuthName = 0;
00134         }
00135         return;
00136     }
00137     
00138     if ( 0 != old ) {
00139         if ( !strcmp(old, nnn) ) {
00140             return;
00141         }
00142     }
00143     
00144     _currentAuthName.resize(strlen(nnn)+1);
00145     _currentAuthName = nnn;
00146 }
00147 
00148 
00149 void 
00150 BdbFSSupportClustH::refreshCurrentDomain()
00151 {
00152     _currentDomain = domain()->domain() ;
00153 }
00154 
00155 d_Boolean 
00156 BdbFSSupportClustH::authLevelChanged() const
00157 {       
00158     return ( domain()->authLevel() != _currentAuthLevel ) ; 
00159 }
00160 
00161 
00162 d_Boolean 
00163 BdbFSSupportClustH::authNameChanged() const
00164 {
00165     const char* a = domain()->authName();
00166     const char* c = _currentAuthName.head();
00167     if ( a == 0 && c == 0 ) {
00168         return d_False;
00169     }
00170     if ( (a == 0 && c != 0) || (a != 0 && c == 0)  ) {
00171         return d_True;
00172     }
00173     
00174     return strcmp(a, c); 
00175 }
00176 
00177 
00178 d_Boolean 
00179 BdbFSSupportClustH::domainChanged() const
00180 {
00181     return ( domain()->domain() != _currentDomain ) ;
00182 }
00183 
00184 d_Boolean 
00185 BdbFSSupportClustH::allowRemoteFS() const
00186 {
00187     return ! _fsMgr->daemonDisabled() ; 
00188 }
00189 
00190 const char* 
00191 BdbFSSupportClustH::currentHost()
00192 {
00193     return fsMgr()->host(defFS()) ;
00194 }
00195 
00196 const char* 
00197 BdbFSSupportClustH::baseDirectory()
00198 {  
00199     return fsMgr()->baseDir(defFS()) ;  
00200 }
00201 
00202 
00203 
00204 BdbStatus
00205 BdbFSSupportClustH::makeMetadataDir()
00206 {
00207     const char* fn = "BdbFSSupportClustH::makeMetadataDir";
00208 
00209     if ( prepareMetadataSpec() != BdbcSuccess ) {
00210         return _es->BdbESig(BdbClusteringErrFunctionFailed, 
00211                             fn, "in prepareMetadataSpec") ;
00212     }
00213 
00214     // this will return with success immediatelly if the directory exists
00215     if ( fsMgr()->mkDir(currentPath(), d_False) != BdbcSuccess ) {
00216         return _es->BdbESig(BdbClusteringErrFunctionFailed,
00217                             fn, "in mkDir") ;
00218     }
00219 
00220     return BdbcSuccess ;
00221 }
00222 
00223 
00224 
00225 BdbStatus 
00226 BdbFSSupportClustH::buildBaseDirectories(d_Boolean defaultFS)
00227 {
00228     const char* fn = "BdbFSSupportClustH::buildBaseDirectories";
00229 
00230     // maybe the whole structure already exist...
00231     if ( prepareNameSpec(defaultFS) != BdbcSuccess ) {
00232         return _es->BdbESig(BdbClusteringErrFunctionFailed, 
00233                             fn, "in prepareNameSpec") ;
00234     }
00235     if ( fsMgr()->checkExist( currentPath(), defaultFS )) {
00236         return BdbcSuccess ;
00237     }
00238 
00239     // Make the path in one step
00240     if ( fsMgr()->mkDir(currentPath(), defaultFS) != BdbcSuccess ) {
00241         return _es->BdbESig(BdbClusteringErrFunctionFailed, 
00242                             fn, "in mkDir") ;
00243     }
00244 
00245     return BdbcSuccess ;
00246 }
00247 
00248 BdbStatus 
00249 BdbFSSupportClustH::prepareBaseDirSpec(d_Boolean defaultFS)
00250 {
00251     setDefFS(defaultFS) ;
00252     strcpyPath(baseDirectory()) ;
00253       
00254     return BdbcSuccess ;
00255 }
00256 
00257 
00258 
00259 BdbStatus
00260 BdbFSSupportClustH::prepareMetadataSpec()
00261 {
00262     const char* fn = "BdbFSSupportClustH::prepareMetadataDir";
00263 
00264     if ( prepareBaseDirSpec(d_False) != BdbcSuccess ) {
00265         return _es->BdbESig(BdbClusteringErrFunctionFailed,
00266                             fn, "in prepareBaseDirSpec");
00267     }
00268 
00269     strcatPath("metadata");
00270 
00271     char* str = ((BdbDomain*) domain())->getDBFSDomainRelativePath();
00272     char buf[16]; 
00273     strcpy(buf, domain()->shortDomainName(str));
00274     buf[4] = '\0';
00275     strcpyDbName (buf);
00276 
00277     return BdbcSuccess;
00278 }
00279 
00280 
00281 
00282 
00283 
00284 
00285 BdbStatus 
00286 BdbFSSupportClustH::prepareDomainSpec(d_Boolean defaultFS)
00287 {
00288     if ( prepareBaseDirSpec(defaultFS) != BdbcSuccess ) {
00289         return _es->BdbESig(BdbClusteringErrFunctionFailed, 
00290                  "BdbFSSupportClustH::prepareDomainSpec", "in prepareBaseDirSpec") ;
00291     }
00292     
00293     char* str = ((BdbDomain*) domain())->getDBFSDomainRelativePath() ;
00294     strcatPath ( str ) ;
00295  
00296     char buf[16] ; strcpy(buf, domain()->shortDomainName(str)) ;  buf[4] = '\0' ;
00297     strcpyDbName ( buf ) ;
00298 
00299     delete [] str;    
00300     return BdbcSuccess ;
00301 }
00302 
00303 
00304 BdbStatus 
00305 BdbFSSupportClustH::prepareNameSpec(d_Boolean defaultFS)
00306 {
00307   // Get the relative directory path & prefix name
00308   // from the domain's translation table.
00309 
00310     char* relativePath = ((BdbDomain*) domain())->getDBFSRelativePath() ;
00311     char* namePrefix   = ((BdbDomain*) domain())->getDBFSNamePrefix() ;
00312 
00313     if (( relativePath == (char*) 0 )||( namePrefix == (char*) 0 )) {
00314 
00315         delete [] relativePath ;
00316         delete [] namePrefix ;
00317 
00318         resetBoth() ;
00319 
00320         return _es->BdbESig(BdbClusteringErrFunctionFailed, 
00321                  "BdbFSSupportClustH::prepareNameSpec", "in getDBFSRelativePath") ;
00322     }
00323     
00324   // Initialize base directory (beginning of the) path.
00325  
00326     if ( prepareBaseDirSpec(defaultFS) != BdbcSuccess ) {
00327     
00328         delete [] relativePath ;
00329         delete [] namePrefix ;
00330 
00331         resetBoth() ;
00332 
00333         return _es->BdbESig(BdbClusteringErrFunctionFailed, 
00334                     "BdbFSSupportClustH::prepareNameSpec", "in prepareBaseDirSpec") ;
00335     }
00336 
00337   // Complete the path by concatenating the elative path by the end of
00338   // the base one.
00339   // Initialize the database name.
00340 
00341     strcatPath(relativePath) ;
00342     strcpyDbName(namePrefix) ;
00343     
00344     delete [] relativePath ;
00345     delete [] namePrefix ;
00346 
00347     return BdbcSuccess ;
00348 }
00349 
00350 BdbStatus 
00351 BdbFSSupportClustH::prepareConfigDBSpec()
00352 {
00353     const char* fn = "BdbFSSupportClustH::prepareConfigDBSpec";
00354 
00355     if ( prepareMetadataSpec() != BdbcSuccess ) {
00356         return _es->BdbESig(BdbClusteringErrFunctionFailed, 
00357                             fn, "in prepareNameSpec");
00358     }
00359     strcatDbName( "clustHintConfig" ) ;
00360 
00361     const char *clN = BdbClusterConfigMgr::getClusterName();
00362     if ( 0 != clN ) {
00363         strcatDbName(clN);
00364     }    
00365 
00366     return BdbcSuccess ;
00367 }
00368 
00369 
00370 BdbStatus 
00371 BdbFSSupportClustH::verifyDiskSpace(d_Boolean* rebuildDb)
00372 {
00373     const char* fn = "BdbFSSupportClustH::verifyDiskSpace";
00374 
00375     if ( ! allowRemoteFS()) {
00376         return BdbcSuccess;   // do not check the space for catalogFS
00377     }
00378     if ( ! fsMgr()->verifyDiskSpace(rebuildDb) ) {
00379         return _es->BdbESig(BdbClusteringErrFunctionFailed,
00380                             fn, "in verifyDiskSpace") ;
00381     }
00382 
00383     return BdbcSuccess ;
00384 }
00385 

 


BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us

Page Owner: Jacek Becla
Last Update: October 04, 2002