|
|
| version 1.13, 2001/10/26 13:48:19 | version 1.20, 2001/10/28 11:40:48 |
|---|---|
| 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 17 | Line 19 |
| #include "pa_stack.h" | #include "pa_stack.h" |
| #include "pa_common.h" | #include "pa_common.h" |
| // 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 | // 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; |
| const char *DB_WARNING1="Finding last valid log LSN"; | |
| // callbacks | // callbacks |
| static void db_paniccall(DB_ENV *dbenv, int error) { | static void db_paniccall(DB_ENV *dbenv, int error) { |
| Line 34 static void db_paniccall(DB_ENV *dbenv, | Line 43 static void db_paniccall(DB_ENV *dbenv, |
| } | } |
| static void db_errcall(const char *, char *buffer) { | static void db_errcall(const char *, char *buffer) { |
| // were it warning? | |
| if(strncmp(buffer, DB_WARNING1, strlen(DB_WARNING1))==0) | |
| return; | |
| throw Exception(0, 0, | throw Exception(0, 0, |
| 0, | 0, |
| "db_err: %s", | DB_ERROR_PREFIX "%s", |
| buffer); | buffer); |
| } | } |
| Line 61 DB_Connection::DB_Connection(Pool& apool | Line 66 DB_Connection::DB_Connection(Pool& apool |
| table_cache(apool), | table_cache(apool), |
| prev_expiration_pass_time(0) { | prev_expiration_pass_time(0) { |
| //_asm int 3; | //_asm int 3; |
| memset(&dbenv, 0, sizeof(dbenv)); | |
| dbenv.db_paniccall=db_paniccall; | |
| dbenv.db_errcall=db_errcall; | |
| char DB_DATA_DIR__VALUE[MAX_STRING]; | char DB_DATA_DIR__VALUE[MAX_STRING]; |
| char DB_LOG_DIR__VALUE[MAX_STRING]; | char DB_LOG_DIR__VALUE[MAX_STRING]; |
| char DB_TMP_DIR__VALUE[MAX_STRING]; | char DB_TMP_DIR__VALUE[MAX_STRING]; |
| Line 87 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)); |
| check("db_appinit soft recover", &fdb_home, db_appinit( | |
| db_home_cstr, | // error handlers |
| db_config, | #if DB_VERSION_MINOR >= 7 |
| &dbenv, | dbenv.db_paniccall=db_paniccall; |
| flags | DB_RECOVER | #endif |
| dbenv.db_errcall=db_errcall; | |
| // init | |
| check("db_appinit", &fdb_home, db_appinit( | |
| db_home_cstr, | |
| db_config, | |
| &dbenv, | |
| flags | |
| )); | )); |
| } catch(...) { | |
| try {*/ | |
| // 2: trying to open WITHOUT SOFT RECOVER option set | |
| check("db_appinit no recover", &fdb_home, db_appinit( | |
| db_home_cstr, | |
| db_config, | |
| &dbenv, | |
| flags | |
| )); | |
| /* } catch(...) { | |
| // 3: trying to open with FATAL RECOVER option set | |
| check("db_appinit fatal recover", &fdb_home, db_appinit( | |
| db_home_cstr, | |
| db_config, | |
| &dbenv, | |
| flags | DB_RECOVER_FATAL | |
| )); | |
| } | |
| }*/ | |
| } | } |
| DB_Connection::~DB_Connection() { | DB_Connection::~DB_Connection() { |
| Line 140 void DB_Connection::check(const char *op | Line 130 void DB_Connection::check(const char *op |
| } | } |
| } | } |
| 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, | check("checkpoint", source, |
| origin, | txn_checkpoint(dbenv.tx_info, 0/*kbyte*/, DB_CHECKPOINT_MINUTES/*min*/)); |
| "note to parser3 programmer: your forgot about DB_Connection_usage"); | |
| // 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 167 DB_Table_ptr DB_Connection::get_table_pt | Line 156 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)); |
| } | } |