Diff for /parser3/src/main/Attic/pa_db_connection.C between versions 1.14 and 1.22

version 1.14, 2001/10/26 15:26:37 version 1.22, 2001/10/28 14:24:26
Line 5 Line 5
         Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)          Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
   
         $Id$          $Id$
   
           developed with LIBDB 2.7.4
 */  */
   
 #include "pa_config_includes.h"  #include "pa_config_includes.h"
 #ifdef HAVE_LIBDB  #ifdef DB2
   
 #include "pa_db_connection.h"  #include "pa_db_connection.h"
 #include "pa_db_table.h"  #include "pa_db_table.h"
Line 25 Line 27
   
 // consts  // consts
   
   /// @test increase
   const int DB_CHECKPOINT_MINUTES=1; 
   
 const int EXPIRE_UNUSED_TABLE_SECONDS=60;  const int EXPIRE_UNUSED_TABLE_SECONDS=60;
 const int CHECK_EXPIRED_TABLES_SECONDS=EXPIRE_UNUSED_TABLE_SECONDS*2;  const int CHECK_EXPIRED_TABLES_SECONDS=EXPIRE_UNUSED_TABLE_SECONDS*2;
   
Line 45  static void db_errcall(const char *, cha Line 50  static void db_errcall(const char *, cha
 }  }
   
 static void expire_table(const Hash::Key& key, Hash::Val *& value, void *info) {  static void expire_table(const Hash::Key& key, Hash::Val *& value, void *info) {
         DB_Connection& table=*static_cast<DB_Connection *>(value);          DB_Table& table=*static_cast<DB_Table *>(value);
         time_t older_dies=reinterpret_cast<time_t>(info);          time_t older_dies=reinterpret_cast<time_t>(info);
   
         if(table.expired(older_dies)) {          if(table.expired(older_dies)) {
                 table.~DB_Connection();  value=0;                  table.~DB_Table();  value=0;
         }          }
 }  }
   
Line 83  DB_Connection::DB_Connection(Pool& apool Line 88  DB_Connection::DB_Connection(Pool& apool
                 | DB_CREATE                   | DB_CREATE 
                 | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN;                  | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN;
   
         try {          // trying to open with SOFT RECOVER option set
                 // 1: trying to open with SOFT RECOVER option set          memset(&dbenv, 0, sizeof(dbenv));
                 memset(&dbenv, 0, sizeof(dbenv));          
                 check("db_appinit soft recover", &fdb_home, db_appinit(  
                         db_home_cstr,  
                         db_config,   
                         &dbenv,   
                         flags | DB_RECOVER  
                 ));  
         } catch(const Exception& e) {  
                 if(  
                         strncmp(  
                                 e.comment(),   
                                 DB_EXCEPTION_NO_LOG_MESSAGE1,   
                                 strlen(DB_EXCEPTION_NO_LOG_MESSAGE1))==0 ||   
                         strncmp(  
                                 e.comment(),   
                                 DB_EXCEPTION_NO_LOG_MESSAGE2,   
                                 strlen(DB_EXCEPTION_NO_LOG_MESSAGE2))==0) {  
                         // no log = no SOFT RECOVER  
                         // 2.1: trying to open with NO RECOVER option set  
                         memset(&dbenv, 0, sizeof(dbenv));  
                         check("db_appinit no recover", &fdb_home, db_appinit(  
                                 db_home_cstr,  
                                 db_config,   
                                 &dbenv,   
                                 flags  
                         ));  
                 } else {  
                         // some serious error  
                         // 2.2: trying to open with FATAL RECOVER option set  
                         memset(&dbenv, 0, sizeof(dbenv));  
                         check("db_appinit fatal recover", &fdb_home, db_appinit(  
                                 db_home_cstr,  
                                 db_config,   
                                 &dbenv,   
                                 flags | DB_RECOVER_FATAL  
                         ));  
                 }  
         }  
   
         // error handlers          // error handlers
   #if DB_VERSION_MINOR >= 7
         dbenv.db_paniccall=db_paniccall;          dbenv.db_paniccall=db_paniccall;
   #endif
         dbenv.db_errcall=db_errcall;          dbenv.db_errcall=db_errcall;
   
           // init
           check("db_appinit", &fdb_home, db_appinit(
                   db_home_cstr,
                   db_config, 
                   &dbenv, 
                   flags
                   ));
 }  }
   
 DB_Connection::~DB_Connection() {  DB_Connection::~DB_Connection() {
Line 146  void DB_Connection::check(const char *op Line 123  void DB_Connection::check(const char *op
                 break;                   break; 
                   
         default:          default:
                 throw Exception(0, 0,                   if(error<0)
                         source,                           throw Exception(0, 0, 
                         "db %s error: %s (%d)",                                   source, 
                         operation, strerror(error), error);                                  "db %s error: %d", 
                                   operation, error);
                   else
                           throw Exception(0, 0, 
                                   source, 
                                   "db %s error: %s (%d)", 
                                   operation, strerror(error), error);
         }          }
 }  }
   
 DB_Table_ptr DB_Connection::get_table_ptr(const String& request_file_name, const String *origin) {  DB_Table_ptr DB_Connection::get_table_ptr(const String& request_file_name, const String *source) {
         if(!used)          // checkpoint
                 throw(0, 0,          {
                         origin,                  int error=txn_checkpoint(dbenv.tx_info, 0/*kbyte*/, DB_CHECKPOINT_MINUTES/*min*/);
                         "note to parser3 programmer: your forgot about DB_Connection_usage");                  /*
                   DB_INCOMPLETE if there were pages that needed to be written 
                   but that memp_sync was unable to write immediately. 
                   In this case, the txn_checkpoint call should be retried. 
   
                   we'll just ignore that
                   */
                   if(error!=DB_INCOMPLETE)
                           check("checkpoint", source, error);
           }
   
         // first trying to get cached table          // first trying to get cached table
         DB_Table *result=get_table_from_cache(request_file_name);          DB_Table *result=get_table_from_cache(request_file_name);
Line 180  DB_Table_ptr DB_Connection::get_table_pt Line 172  DB_Table_ptr DB_Connection::get_table_pt
         // return auto-it          // return auto-it
         return DB_Table_ptr(result);          return DB_Table_ptr(result);
 }  }
 void DB_Connection::clear_dbfile(const String& file_name) {  
         // open&clear  
         DB *db;  
         DB_INFO dbinfo;  
         memset(&dbinfo, 0, sizeof(dbinfo));  
         check("open(clear)", &file_name, db_open(  
                 file_name.cstr(String::UL_FILE_SPEC),   
                 PA_DB_ACCESS_METHOD,   
                 DB_CREATE | DB_TRUNCATE/* used in single thread, no need for |DB_THREAD*/,  
                 0666,   
                 &dbenv, &dbinfo, &db));  
   
         check("close", &file_name, db->close(db, 0/*flags*/));  db=0;   
 }  
   
 // table cache  // table cache
 /// @todo get rid of memory spending Stack [zeros deep inside got accumulated]  /// @todo get rid of memory spending Stack [zeros deep inside got accumulated]
 DB_Table *DB_Connection::get_table_from_cache(const String& file_name) {   DB_Table *DB_Connection::get_table_from_cache(const String& file_name) { 
         SYNCHRONIZED;          SYNCHRONIZED;
   
           maybe_expire_table_cache();
   
         return static_cast<DB_Table *>(table_cache.get(file_name));          return static_cast<DB_Table *>(table_cache.get(file_name));
 }  }
   

Removed from v.1.14  
changed lines
  Added in v.1.22


E-mail: