![]() |
|
|
Bdb packages | Design docs | Source docs | Guidelines | Recent releases |
|
Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members /BdbAdminTools/BdbAdminDbgMgr.cc
Go to the documentation of this file.00001 //------------------------------------------------------------------------------ 00002 // File: 00003 // BdbAdminDbgMgr.cc 00004 // 00005 // Description: 00006 // Transient class. Allows to debug Objectivity Federation including: 00007 // - dumping database names 00008 // - dumping containers 00009 // - converting oids to names and vice versa 00010 // - dumping db/container sizes 00011 // - others 00012 // 00013 // Environment: 00014 // Software developed for the BaBar Detector at the SLAC B-Factory 00015 // 00016 // Author List: 00017 // Jacek Becla Original Author 00018 // 00019 // Copyright Information: 00020 // Copyright (C) 1999 Stanford Linear Accelerator Center 00021 // 00022 //------------------------------------------------------------------------------ 00023 #include "BaBar/BaBar.hh" 00024 00025 00026 //----------------------- 00027 // This Class's Header -- 00028 //----------------------- 00029 #include "BdbAdminTools/BdbAdminDbgMgr.hh" 00030 00031 00032 00033 //------------------------------- 00034 // Collaborating Class Headers -- 00035 //------------------------------- 00036 #include "BdbApplication/BdbDomain.hh" 00037 #include "BdbApplication/BdbDebug.hh" 00038 #include "BdbApplication/BdbErrorSignal.hh" 00039 #include "BdbAccess/BdbContAccessMgr.hh" 00040 #include "BdbClustering/BdbPCounter.hh" 00041 #include "BdbClustering/BdbPCompParam.hh" 00042 #include "BdbClustering/BdbClustHAccess.hh" 00043 #include "BdbAdminTools/BdbAdminDbgIOMgr.hh" 00044 00045 //------------- 00046 // C Headers -- 00047 //------------- 00048 extern "C" { 00049 #include <stdlib.h> 00050 #include <sys/stat.h> /* stat */ 00051 #include <unistd.h> 00052 } 00053 00054 00055 //--------------- 00056 // C++ Headers -- 00057 //--------------- 00058 #include "ooMap.h" 00059 00060 #include <strstream.h> 00061 #include <iostream.h> 00062 #include <iomanip.h> 00063 00064 00065 00066 00067 00068 BdbAdminDbgMgr::BdbAdminDbgMgr(BdbAdminDbgIOMgr* ioMgr, d_Boolean display) 00069 : _ioMgr(ioMgr), 00070 _display(display) 00071 { 00072 _verbose = d_True; 00073 00074 ooSetLockWait(0); 00075 _noDatabases = 0; 00076 00077 _locatorMgr = new BdbClustHAccess("evs", d_True, 0); 00078 } 00079 00080 00081 BdbAdminDbgMgr::~BdbAdminDbgMgr() 00082 { 00083 delete _locatorMgr; 00084 } 00085 00086 00087 00088 00089 /** 00090 ** The function iterates over all databases in the federation 00091 ** and stores database names in an ascii file. 00092 ** It puts a readlock on the federation. 00093 **/ 00094 00095 BdbStatus 00096 BdbAdminDbgMgr::dumpDbs2File() 00097 { 00098 if ( _ioMgr->openFile_AllDbNames(d_False) != BdbcSuccess ) { 00099 COUT1 << "Cannot open output file" << endl; 00100 return BdbcError; 00101 } 00102 00103 00104 BdbApplicationOrDomain::activeInstance()->startRead("fd iteration"); 00105 00106 ooItr(ooDBObj) dbItr; 00107 if ( BdbApplicationOrDomain::activeInstance()->fd().contains(dbItr) != BdbcSuccess ) { 00108 COUT1 << "Cannot initialize fd iterator" << endl; 00109 BdbApplicationOrDomain::activeInstance()->commit("fd iteration"); 00110 return BdbcError; 00111 } 00112 00113 _noDatabases = 0; 00114 00115 while ( dbItr.next() ) { 00116 const char* theName = dbItr.name(); 00117 if ( _display ) { 00118 cout << "Found db: " << theName << endl; 00119 } 00120 _ioMgr->_outFile << theName << endl; 00121 _noDatabases ++; 00122 } 00123 00124 BdbApplicationOrDomain::activeInstance()->commit("fd iteration"); 00125 00126 _ioMgr->_outFile.close(); 00127 00128 if ( _display || _verbose ) { 00129 cout << "Total number of databases found: " << _noDatabases << endl; 00130 } 00131 00132 return BdbcSuccess; 00133 } 00134 00135 00136 00137 00138 /** 00139 ** The function processes databases (all or selected). 00140 ** 00141 **/ 00142 00143 BdbStatus 00144 BdbAdminDbgMgr::processDatabases(d_Boolean allDbs, 00145 const char* outFileName, 00146 d_Boolean showNrConts, 00147 d_Boolean showPgCounters, 00148 d_Boolean showFileSize, 00149 d_Boolean showContSize) 00150 { 00151 // open file containing list of all databases or selected list for reading 00152 if ( _ioMgr->openFile_DbNames(allDbs, d_True) != BdbcSuccess ) { 00153 cout << "Cannot open input file" << endl; 00154 return BdbcError; 00155 } 00156 00157 // open output file 00158 d_Boolean printToFile = outFileName != (char*)0; 00159 if ( printToFile ) { 00160 if ( _ioMgr->openOutFile(outFileName) != BdbcSuccess ) { 00161 COUT1 << "Cannot open output file" << endl; 00162 return BdbcError; 00163 } 00164 } 00165 00166 cout << "dbName dbid"; 00167 if ( showNrConts ) { 00168 cout << " #conts"; 00169 } 00170 if ( showPgCounters ) { 00171 cout << " #pgCnt"; 00172 } 00173 if ( showFileSize ) { 00174 cout << " fileSize"; 00175 } 00176 cout << "\n--------------------------------------------" << endl; 00177 00178 while ( ! _ioMgr->_inFile.eof() ) { 00179 char dbName[64]; 00180 _ioMgr->_inFile.getline(dbName, 64); 00181 if ( dbName[0] == '\0' ) { 00182 continue; 00183 } 00184 processOneDb(dbName, printToFile, showNrConts, showPgCounters, showFileSize, showContSize); 00185 } 00186 00187 _ioMgr->_inFile.close(); 00188 if ( printToFile ) { 00189 _ioMgr->_outFile.close(); 00190 } 00191 00192 return BdbcSuccess; 00193 } 00194 00195 00196 00197 /** The function processes one database 00198 ** It can be called independently. 00199 **/ 00200 00201 BdbStatus 00202 BdbAdminDbgMgr::processOneDb(const char* dbName, 00203 d_Boolean printToFile, 00204 d_Boolean showNrConts, 00205 d_Boolean showPgCounters, 00206 d_Boolean showFileSize, 00207 d_Boolean showContSize) 00208 { 00209 d_ULong noContainers = 0; 00210 00211 BdbApplicationOrDomain::activeInstance()->startRead("processOneDb"); 00212 00213 ooRef(ooDBObj) dbRef; 00214 if ( dbRef.open(BdbApplicationOrDomain::activeInstance()->fd(), dbName, oocRead) != BdbcSuccess ) { 00215 cout << "Cannot open db; \"" << dbName << "\" for reading" << endl; 00216 BdbApplicationOrDomain::activeInstance()->commit("processOneDb"); 00217 return BdbcError; 00218 } 00219 00220 int dbid = dbRef.get_DB(); 00221 00222 cout.setf(ios::left); 00223 cout << setw(29) << dbName << " " << setw(5) << dbid; 00224 cout.setf(ios::right); 00225 if ( printToFile ) { 00226 _ioMgr->_outFile.setf(ios::left); 00227 _ioMgr->_outFile << setw(29) << dbName << " " << setw(5) << dbid; 00228 _ioMgr->_outFile.setf(ios::right); 00229 } 00230 00231 if ( showNrConts ) { 00232 int nr = dbRef.numContObjs(); 00233 noContainers += nr; 00234 cout << " " << setw(4) << nr; 00235 if ( printToFile ) { 00236 _ioMgr->_outFile << " " << setw(4) << nr; 00237 } 00238 } 00239 00240 d_ULong counterValue = 0; 00241 if ( showPgCounters ) { 00242 char* buf = new char [64]; 00243 00244 readPageCounter(buf, dbid, counterValue); 00245 cout << " " << buf; 00246 if ( printToFile ) { 00247 _ioMgr->_outFile << " " << buf; 00248 } 00249 delete [] buf; 00250 } 00251 00252 const char* thePath = dbRef.fileName(); 00253 const char* theHost = dbRef.hostName(); 00254 00255 BdbApplicationOrDomain::activeInstance()->commit("processOneDb"); 00256 00257 if ( showFileSize ) { 00258 d_ULong size = readFileSize(thePath, theHost); 00259 size /= 1024; 00260 char buf[64]; 00261 ostrstream theStream(buf, 64); 00262 theStream << setw(10) << size << " [KB]" << ends; 00263 cout << buf; 00264 if ( printToFile ) { 00265 _ioMgr->_outFile << buf; 00266 } 00267 } 00268 00269 cout << endl; 00270 if ( printToFile ) { 00271 _ioMgr->_outFile << endl; 00272 } 00273 00274 00275 d_ULong threshold = 100000; 00276 if ( counterValue > threshold ) { 00277 cout << "\n\n Warning: value > " << threshold << ". Try to fix? (y/n)" << endl; 00278 char c; cin >> c; 00279 if ( c == 'y' ) { 00280 fixPageCounter(dbid); 00281 } 00282 } 00283 00284 return BdbcSuccess; 00285 } 00286 00287 00288 00289 00290 BdbStatus 00291 BdbAdminDbgMgr::fixPageCounter(int dbid) 00292 { 00293 BdbApplicationOrDomain::activeInstance()->startUpdate("fixPageCounter"); 00294 00295 BdbRef(BdbPCounter) counterRef; 00296 if ( _locatorMgr->locateDbPageCounter(counterRef, dbid, oocUpdate) != BdbcSuccess ) { 00297 BdbApplicationOrDomain::activeInstance()->commit("fixPageCounter"); 00298 return BdbcError; 00299 } 00300 00301 cout << "Value of extraPage counter = " << counterRef->counter() << endl; 00302 cout << "Resetting the value to 0" << endl; 00303 00304 counterRef->force(0); 00305 00306 BdbApplicationOrDomain::activeInstance()->commit("fixPageCounter"); 00307 00308 return BdbcSuccess; 00309 } 00310 00311 00312 BdbStatus 00313 BdbAdminDbgMgr::readPageCounter(char*& buf, int dbid, d_ULong& value) 00314 { 00315 BdbRef(BdbPCounter) counterRef; 00316 if ( _locatorMgr->locateDbPageCounter(counterRef, dbid, oocRead) != BdbcSuccess ) { 00317 return BdbcError; 00318 } 00319 00320 value = counterRef->counter(); 00321 00322 ostrstream theStream(buf, 64); 00323 theStream << setw(6) << value << ends; 00324 00325 return BdbcSuccess; 00326 } 00327 00328 00329 00330 d_ULong 00331 BdbAdminDbgMgr::readFileSize(const char* thePath, const char* theHost) 00332 { 00333 d_ULong theSize = 0; 00334 00335 char* buf = new char [64]; 00336 00337 gethostname( buf, 64); 00338 00339 int length = (strlen(theHost)<strlen(buf)) ? strlen(theHost) : strlen(buf); 00340 if ( ! strncmp(theHost, buf, length) ) { 00341 //cout << "The file is local" << endl; 00342 struct stat statbuf; 00343 if (stat(thePath, &statbuf) == 0) { 00344 theSize = statbuf.st_size; 00345 } else { 00346 cout << "Cannot get size of a file " << thePath << endl; 00347 } 00348 } else { 00349 //cout << "The file is remote" << endl; 00350 00351 //BdbPud::setTimeOut(1); 00352 //BdbPud daemon(theHost, 3333, d_True); 00353 //off_t nr = 0; 00354 //if ( daemon.getFileSize(thePath, (off_t&)nr) == BdbcSuccess ) { 00355 // theSize = nr; 00356 //} 00357 } 00358 00359 return theSize; 00360 } 00361 00362 00363 BdbStatus 00364 BdbAdminDbgMgr::fixBdbPCompParam(const char* contName, const char* objName) 00365 { 00366 00367 BdbApplicationOrDomain::activeInstance()->startUpdate("fixBdbPCompParam"); 00368 00369 ooMode openMode = oocUpdate; 00370 00371 BdbRef(BdbPCompParam_001) theParamRef; 00372 00373 if ( _locatorMgr->locatePCompParamObj(contName, objName, 00374 theParamRef, oocUpdate) != BdbcSuccess ) { 00375 BdbApplicationOrDomain::activeInstance()->commit("fixBdbPCompParam"); 00376 return BdbcError; 00377 } 00378 00379 cout << "Value of extraConts = " << theParamRef->extraConts() << endl; 00380 00381 cout << "Reset to 0? (y/n) "; 00382 char c; cin >> c; 00383 if ( c == 'y' ) { 00384 cout << "Resetting the value to 0" << endl; 00385 theParamRef->forceExtraConts(0); 00386 } 00387 00388 BdbApplicationOrDomain::activeInstance()->commit("fixBdbPCompParam"); 00389 00390 return BdbcSuccess; 00391 } 00392 00393 00394 00395 /** 00396 ** This function displays all containers in the clustering hint 00397 ** database (per one domain) which ends with "v1". 00398 ** In practice these are containers which contain BdbPCompParam objects. 00399 ** It will also print BdbPCompParam objects and their values. 00400 ** 00401 ** If _extraConts > 500, it will ask if the value should be reset to 0. 00402 ** If yes, it resets chosen values inside separate update transaction. 00403 ** 00404 ** All reading is done inside one read transaction, it may take long 00405 **/ 00406 00407 00408 BdbStatus 00409 BdbAdminDbgMgr::displayBdbPCompParamObjects() 00410 { 00411 d_Boolean displayAll = d_False; 00412 char theFilter[64]; 00413 d_Boolean filter = d_False; 00414 cout << "All? (y/n) "; char c; cin >> c; 00415 if ( c == 'y' ) { 00416 displayAll = d_True; 00417 } else { 00418 cout << "filter? (y/n) "; cin >> c; 00419 if ( c == 'y' ) { 00420 cout << "should contain: "; cin >> theFilter; 00421 displayAll = d_True; 00422 filter = d_True; 00423 } 00424 } 00425 00426 BdbApplicationOrDomain::activeInstance()->startRead("displayBdbPCompParamObjects"); 00427 00428 // open the db 00429 BdbHandle(BdbDBObj) dbH; 00430 if ( _locatorMgr->openClustHintDb(dbH, oocRead) != BdbcSuccess ) { 00431 BdbApplicationOrDomain::activeInstance()->commit("displayBdbPCompParamObjects"); 00432 return BdbcError; 00433 } 00434 00435 // cache up to 1000 elements which will be fixed after the 00436 // read transaction is commited 00437 _entries2Fix = new Entry2Fix[1000]; 00438 _nrElems2Fix = 0; 00439 00440 // cache all active databases 00441 _allActiveDbs = new d_ULong[64000]; 00442 _nrActiveDbsFound = 0; 00443 00444 _nrHasExtraneousActiveDbs = 0; 00445 00446 00447 if ( displayAll ) { 00448 // iterate through all containers and find these with "v1" 00449 ooItr(ooContObj) contItr; 00450 if ( dbH.contains(contItr) != BdbcSuccess ) { 00451 cout << "Cannot initialize container iterator" << endl; 00452 BdbApplicationOrDomain::activeInstance()->commit("displayBdbPCompParamObjects"); 00453 delete [] _entries2Fix; 00454 _nrElems2Fix = 0; 00455 delete [] _allActiveDbs; 00456 _nrActiveDbsFound = 0; 00457 _nrHasExtraneousActiveDbs = 0; 00458 return BdbcError; 00459 } 00460 00461 while ( contItr.next() ) { 00462 ooRef(ooContObj) contRef = contItr; 00463 const char* contName = contRef.name(); 00464 int len = strlen(contName); 00465 if ( *(contName+len-2) == 'v' && *(contName+len-1) == '1' ) { 00466 d_Boolean display; 00467 if ( ! filter ) { 00468 displayBdbPCompPObjInCont(contRef); 00469 } else { 00470 if ( strstr(contName, theFilter) != 0 ) { 00471 displayBdbPCompPObjInCont(contRef); 00472 } else { 00473 cout << "Container: " << contName << " filtered out" << endl; 00474 } 00475 } 00476 //} else { 00477 // cout << "Skipping container: " << contName << endl; 00478 } 00479 } 00480 } else { 00481 ooRef(ooContObj) contRef; 00482 char contName[64]; 00483 cout << "Container name: "; cin >> contName; 00484 if ( contRef.open(dbH, contName, oocRead) != BdbcSuccess ) { 00485 cout << "Cannot open cont " << contName << endl; 00486 BdbApplicationOrDomain::activeInstance()->commit("displayBdbPCompParamObjects"); 00487 delete [] _entries2Fix; 00488 _nrElems2Fix = 0; 00489 delete [] _allActiveDbs; 00490 _nrActiveDbsFound = 0; 00491 _nrHasExtraneousActiveDbs = 0; 00492 return BdbcError; 00493 } 00494 displayBdbPCompPObjInCont(contRef); 00495 } 00496 00497 BdbApplicationOrDomain::activeInstance()->commit("displayBdbPCompParamObjects"); 00498 00499 00500 if ( _nrElems2Fix > 0 ) { 00501 BdbApplicationOrDomain::activeInstance()->startUpdate("displayBdbPCompParamObjects-fixing"); 00502 00503 for ( int i=0 ; i<_nrElems2Fix ; i++) { 00504 ooRef(BdbPCompParam_001) theRef; 00505 _entries2Fix[i].buildRef(theRef); 00506 if ( theRef.update() != BdbcSuccess ) { 00507 cout << "Cannot obtain update lock on: "; 00508 } else { 00509 theRef->forceExtraConts(0); 00510 cout << "Resetting extraPages for: "; 00511 } 00512 _entries2Fix[i].print(); 00513 } 00514 BdbApplicationOrDomain::activeInstance()->commit("displayBdbPCompParamObjects-fixing"); 00515 } 00516 00517 if ( _nrHasExtraneousActiveDbs > 0 ) { 00518 cout << "Eextraneous active dbs found in " << _nrHasExtraneousActiveDbs << " places." << endl; 00519 } 00520 00521 delete [] _entries2Fix; 00522 _nrElems2Fix = 0; 00523 00524 delete [] _allActiveDbs; 00525 _nrActiveDbsFound = 0; 00526 00527 _nrHasExtraneousActiveDbs = 0; 00528 00529 return BdbcSuccess; 00530 } 00531 00532 00533 00534 00535 BdbStatus 00536 BdbAdminDbgMgr::displayBdbPCompPObjInCont(ooRef(ooContObj)& contRef) 00537 { 00538 const char* contName = contRef.name(); 00539 00540 cout << "In container: " << contName << endl; 00541 00542 ooItr(ooObj) objItr; 00543 if ( contRef.getNameObj(objItr) != BdbcSuccess ) { 00544 cout << "getNameObj failed" << endl; 00545 return BdbcError; 00546 } 00547 00548 while ( objItr.next() ) { 00549 cout << " object name: " << objItr.getObjName(contRef) << endl; 00550 BdbRef(BdbPCompParam_001) theRef = (BdbRef(BdbPCompParam_001)) objItr; 00551 theRef->print(); 00552 00553 // keep all found active database ids 00554 int actDbNo = theRef->nrActiveDbs(); 00555 for(int i=0 ; i<actDbNo; i++) { 00556 d_ULong dbid = theRef->_activeDbs[i]; 00557 _allActiveDbs[_nrActiveDbsFound] = dbid; 00558 _nrActiveDbsFound++; 00559 if ( i==5 ) { 00560 _nrHasExtraneousActiveDbs++; 00561 } 00562 } 00563 00564 if ( theRef->extraConts() > 500 ) { 00565 cout << "\n\nWarning: number of extra containers = " 00566 << theRef->extraConts() << ". Fix that? (y/n) "; 00567 char c; cin >> c; 00568 if ( c == 'y' ) { 00569 _entries2Fix[_nrElems2Fix].keep(theRef); 00570 _nrElems2Fix++; 00571 } 00572 } 00573 } 00574 00575 return BdbcSuccess; 00576 } 00577 00578 00579 00580 00581 00582 00583 00584 00585 /** 00586 ** This function displays all page counters 00587 ** 00588 ** All reading is done inside one read transaction, it may take long 00589 **/ 00590 00591 00592 BdbStatus 00593 BdbAdminDbgMgr::displayAllPageCounters(const char* outFileName) 00594 { 00595 // open output file 00596 if ( _ioMgr->openOutFile(outFileName) != BdbcSuccess ) { 00597 COUT1 << "Cannot open output file" << endl; 00598 return BdbcError; 00599 } 00600 00601 BdbApplicationOrDomain::activeInstance()->startRead("displayAllPageCounters"); 00602 00603 // open the db 00604 BdbHandle(BdbDBObj) dbH; 00605 if ( _locatorMgr->openClustHintDb(dbH, oocRead) != BdbcSuccess ) { 00606 BdbApplicationOrDomain::activeInstance()->commit("displayAllPageCounters"); 00607 return BdbcError; 00608 } 00609 00610 00611 // initialize iterator 00612 ooItr(ooContObj) contItr; 00613 if ( dbH.contains(contItr) != BdbcSuccess ) { 00614 cout << "Cannot initialize container iterator" << endl; 00615 BdbApplicationOrDomain::activeInstance()->commit("displayAllPageCounters"); 00616 return BdbcError; 00617 } 00618 00619 // cache all found ids 00620 d_ULong foundIds[64000]; 00621 d_ULong noPCFound = 0; 00622 d_ULong threshold = 50000; 00623 cout << "output goes to file " << outFileName << endl; 00624 cout << "Printing only values > " << threshold << endl; 00625 00626 // iterate through all containers and find these with "counter4:" 00627 while ( contItr.next() ) { 00628 ooRef(ooContObj) contRef = contItr; 00629 const char* contName = contRef.name(); 00630 int len = strlen(contName); 00631 if ( ! strncmp(contName, "counter4:", 9) ) { 00632 //cout << "Found container: " << contName << endl; 00633 00634 BdbRef(BdbPCounter) counterRef; 00635 if ( counterRef.lookupObj(contRef, contName, BdbcRead) != BdbcSuccess ) { 00636 cout << "Cannot locate object: " << contName << endl; 00637 continue; 00638 } 00639 d_ULong id = counterRef->dbNr(); 00640 d_ULong value = counterRef->counter(); 00641 _ioMgr->_outFile << "Db id=" << id << ", counter = " << setw(8) << value 00642 << " (" << setw(8) << value *16 << " KB)"; 00643 00644 if ( value > threshold ) { 00645 _ioMgr->_outFile << " ***** > " << threshold << " *****"; 00646 cout << "Db id=" << id << ", counter = " << setw(8) << value 00647 << " (" << setw(8) << value *16 << " KB)" << endl; 00648 } 00649 _ioMgr->_outFile << endl; 00650 foundIds[noPCFound] = id; 00651 noPCFound++; 00652 } else { 00653 //cout << "Skipping container: " << contName << endl; 00654 } 00655 } 00656 00657 BdbApplicationOrDomain::activeInstance()->commit("displayAllPageCounters"); 00658 00659 cout << "Total number of page counters found: " << noPCFound << endl; 00660 00661 _ioMgr->_outFile.close(); 00662 00663 return BdbcSuccess; 00664 } 00665 00666 00667 00668 00669 00670 // ---------------------------------------------------------- 00671 // ---------------------------------------------------------- 00672 // ---------------------------------------------------------- 00673 // ---------------------------------------------------------- 00674 // ---------------------------------------------------------- 00675 // ---------------------------------------------------------- 00676 // ---------------------------------------------------------- 00677 // garbage below 00678 00679 00680 00681 00682 00683 00684 void 00685 BdbAdminDbgMgr::displayAllConts(d_Boolean showNrPagesPerCont) 00686 { 00687 countDatabases(); 00688 00689 char** allDbsNames = new char* [dbCounter]; 00690 00691 loadDbNames(allDbsNames); 00692 00693 for(int i=0 ; i<dbCounter ; i++) { 00694 char* name = allDbsNames[i]; 00695 00696 cout << "\n *** *** Db: " << name << " *** *** " << endl; 00697 displayAllContsInOneDb(name, showNrPagesPerCont, d_True); 00698 delete [] name; 00699 } 00700 delete [] allDbsNames; 00701 } 00702 00703 00704 00705 void 00706 BdbAdminDbgMgr::countDatabases() 00707 { 00708 BdbApplicationOrDomain::activeInstance()->startRead("a"); 00709 00710 ooItr(ooDBObj) dbItr; 00711 if ( BdbApplicationOrDomain::activeInstance()->fd().contains(dbItr) != BdbcSuccess ) { 00712 return; 00713 } 00714 00715 dbCounter = 0; 00716 00717 while ( dbItr.next() ) { 00718 dbCounter++; 00719 } 00720 00721 BdbApplicationOrDomain::activeInstance()->commit("a"); 00722 } 00723 00724 00725 00726 00727 void 00728 BdbAdminDbgMgr::loadDbNames(char**&theArray) 00729 { 00730 BdbApplicationOrDomain::activeInstance()->startRead("a"); 00731 00732 ooItr(ooDBObj) dbItr; 00733 if ( BdbApplicationOrDomain::activeInstance()->fd().contains(dbItr) != BdbcSuccess ) { 00734 return; 00735 } 00736 00737 int cur = 0; 00738 while ( dbItr.next() ) { 00739 if ( cur<dbCounter ) { 00740 const char* name = dbItr.name(); 00741 theArray[cur] = new char [strlen(name)+1]; 00742 strcpy(theArray[cur], name); 00743 } 00744 cur++; 00745 } 00746 BdbApplicationOrDomain::activeInstance()->commit("a"); 00747 } 00748 00749 00750 00751 void 00752 BdbAdminDbgMgr::displayAllContsInOneDb(const char* name, 00753 d_Boolean showNrPagesPerCont, 00754 d_Boolean printToFile) 00755 { 00756 BdbApplicationOrDomain::activeInstance()->startRead("a"); 00757 00758 ooRef(BdbDBObj) dbRef; 00759 if ( dbRef.exist(BdbApplicationOrDomain::activeInstance()->fd(), name, oocRead) != BdbcSuccess ) { 00760 cout << "Db \"" << name << "\" cannot be open for reading" << endl; 00761 return; 00762 } 00763 00764 ooItr(ooContObj) contItr; 00765 if ( dbRef.contains(contItr) != BdbcSuccess ) { 00766 return; 00767 } 00768 00769 if ( printToFile ) { 00770 char outFName[64]; 00771 sprintf(outFName, "allConts4%s", name); 00772 _ioMgr->openOutFile(outFName); 00773 } 00774 00775 long totalNrPages = 0; 00776 long totalNrConts = 0; 00777 long minNrPages = 90000; 00778 while ( contItr.next() ) { 00779 ooRef(ooContObj) contRef = contItr; 00780 const char* name = contRef.name(); 00781 int dbid = contRef.get_DB(); 00782 int contid = contRef.get_OC(); 00783 if ( showNrPagesPerCont ) { 00784 int nrPages = contRef.nPage(); 00785 cout << " container \"" << setw(20) << name << "\" [" 00786 << dbid << "-" << contid << "]" 00787 << ", nr of pages = " << setw(4) << nrPages 00788 << " (" << setw(6) << nrPages*16 << " KB)" << endl; 00789 if ( printToFile ) { 00790 _ioMgr->_outFile << " container \"" << setw(20) << name << "\" [" 00791 << dbid << "-" << contid << "]" 00792 << ", nr of pages = " << setw(4) << nrPages 00793 << " (" << setw(6) << nrPages*16 << " KB)" << endl; 00794 } 00795 if ( contid != 2 ) { // skip default container 00796 totalNrPages += nrPages; 00797 if ( nrPages < minNrPages ) { 00798 minNrPages = nrPages; 00799 } 00800 } 00801 } else { 00802 cout << " container \"" << setw(20) << name << "\" [" 00803 << dbid << "-" << contid << "-0-0]" << endl; 00804 if ( printToFile ) { 00805 _ioMgr->_outFile << " container \"" << setw(20) << name << "\" [" 00806 << dbid << "-" << contid << "-0-0]" << endl; 00807 } 00808 } 00809 if ( contid != 2 ) { // skip default container 00810 totalNrConts ++; 00811 } 00812 } 00813 00814 BdbApplicationOrDomain::activeInstance()->commit("a"); 00815 00816 cout << "Total number of containers (without default) = " << totalNrConts << endl; 00817 if ( showNrPagesPerCont ) { 00818 long averNrPages = totalNrPages / totalNrConts; 00819 long size = totalNrPages * 16; // in KB 00820 cout << "Total number of pages (without default) = " << totalNrPages 00821 << " (" << size << " KB)" << endl; 00822 cout << "Min number of pages = " << minNrPages << endl; 00823 cout << "Average number of pages = " << averNrPages << endl; 00824 if ( printToFile ) { 00825 _ioMgr->_outFile << "Total number of pages = " << totalNrPages 00826 << " (" << size << " KB)" << endl; 00827 _ioMgr->_outFile << "Min number of pages = " << minNrPages << endl; 00828 _ioMgr->_outFile << "Average number of pages = " << averNrPages << endl; 00829 } 00830 } 00831 00832 if ( printToFile ) { 00833 _ioMgr->_outFile.close(); 00834 } 00835 } 00836 00837 00838 BdbStatus 00839 BdbAdminDbgMgr::displayRegistryDbsWEP(const char* theName) 00840 { 00841 char contName[64]; 00842 sprintf(contName, "dbsWEP_%s", theName); 00843 00844 BdbApplicationOrDomain::activeInstance()->startNestedRead(); 00845 00846 00847 // open the db 00848 BdbHandle(BdbDBObj) dbH; 00849 if ( _locatorMgr->openClustHintDb(dbH, oocRead) != BdbcSuccess ) { 00850 BdbApplicationOrDomain::activeInstance()->commitNested() ; 00851 return BdbcError; 00852 } 00853 00854 BdbHandle(BdbContObj) contH; 00855 BdbRef(ooMap) theMap; 00856 BdbRef(BdbPCounter) counterRef; 00857 ooMapItr mapI(theMap); 00858 00859 BdbContAccessMgr contMgr; 00860 00861 if ( contH.exist(dbH, contName, oocRead) != BdbcSuccess ) { 00862 cout << theName << " locked"; 00863 goto done; 00864 } 00865 00866 if ( ! theMap.lookupObj(contH, "theRegistry", BdbcRead) ) { 00867 cout << "map ! found"; 00868 goto done; 00869 } 00870 cout << "Registered databases:" << endl; 00871 00872 while ( mapI.next() ) { 00873 BdbRef(ooObj) cRef = mapI->oid(); 00874 counterRef = (BdbRef(BdbPCounter)&) cRef; 00875 cout << " " << mapI->name() << endl; 00876 } 00877 done: 00878 BdbApplicationOrDomain::activeInstance()->commitNested() ; 00879 00880 return BdbcSuccess; 00881 } 00882
BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us
Page Owner: Jacek Becla
Last Update: October 04, 2002