--- parser3/src/main/Attic/pa_db_connection.C 2001/10/27 09:35:12 1.17 +++ parser3/src/main/Attic/pa_db_connection.C 2001/10/30 15:08:19 1.24 @@ -4,11 +4,13 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_db_connection.C,v 1.17 2001/10/27 09:35:12 paf Exp $ + $Id: pa_db_connection.C,v 1.24 2001/10/30 15:08:19 paf Exp $ + + developed with LIBDB 2.7.4 */ #include "pa_config_includes.h" -#ifdef HAVE_LIBDB +#ifdef DB2 #include "pa_db_connection.h" #include "pa_db_table.h" @@ -19,10 +21,6 @@ // defines -#define DB_ERROR_PREFIX "db_err: " -#define DB_EXCEPTION_NO_LOG_MESSAGE1 DB_ERROR_PREFIX"Ignoring log file" -#define DB_EXCEPTION_NO_LOG_MESSAGE2 DB_ERROR_PREFIX"log_get: unable to find checkpoint record" - // consts /// @test increase @@ -43,16 +41,16 @@ static void db_paniccall(DB_ENV *dbenv, static void db_errcall(const char *, char *buffer) { throw Exception(0, 0, 0, - DB_ERROR_PREFIX "%s", + "db_err: %s", buffer); } static void expire_table(const Hash::Key& key, Hash::Val *& value, void *info) { - DB_Connection& table=*static_cast(value); + DB_Table& table=*static_cast(value); time_t older_dies=reinterpret_cast(info); if(table.expired(older_dies)) { - table.~DB_Connection(); value=0; + table.~DB_Table(); value=0; } } @@ -90,7 +88,9 @@ DB_Connection::DB_Connection(Pool& apool memset(&dbenv, 0, sizeof(dbenv)); // error handlers +#if DB_VERSION_MINOR >= 7 dbenv.db_paniccall=db_paniccall; +#endif dbenv.db_errcall=db_errcall; // init @@ -119,23 +119,39 @@ void DB_Connection::check(const char *op break; default: - throw Exception(0, 0, - source, - "db %s error: %s (%d)", - operation, strerror(error), error); + if(error<0) + throw Exception(0, 0, + source, + "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 *source) { // checkpoint - check("checkpoint", source, - txn_checkpoint(dbenv.tx_info, 0/*kbyte*/, DB_CHECKPOINT_MINUTES/*min*/)); + { + int error=txn_checkpoint(dbenv.tx_info, 0/*kbyte*/, DB_CHECKPOINT_MINUTES/*min*/); + /* + 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 DB_Table *result=get_table_from_cache(request_file_name); if(!result) { // no cached table // make global_file_name C-string on global pool - const char *request_file_name_cstr=request_file_name.cstr(String::UL_AS_IS); + const char *request_file_name_cstr=request_file_name.cstr(); char *global_file_name_cstr=(char *)malloc(strlen(request_file_name_cstr)+1); strcpy(global_file_name_cstr, request_file_name_cstr); // make global_file_name string on global pool @@ -152,20 +168,6 @@ DB_Table_ptr DB_Connection::get_table_pt // return auto-it 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 /// @todo get rid of memory spending Stack [zeros deep inside got accumulated]