|
|
| version 1.31, 2001/11/05 16:07:16 | version 1.37, 2002/02/08 08:30:15 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: sql driver connection implementation. | Parser: sql driver connection implementation. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| $Id$ | $Id$ |
| Line 27 | Line 27 |
| /// @test increase | /// @test increase |
| const int DB_CHECKPOINT_MINUTES=1; | const int DB_CHECKPOINT_MINUTES=1; |
| const int EXPIRE_UNUSED_TABLE_SECONDS=3; //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; |
| // callbacks | // callbacks |
| Line 47 static void db_errcall(const char *, cha | Line 47 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) { |
| if(DB_Table *table=static_cast<DB_Table *>(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_Table(); value=0; | table->~DB_Table(); value=0; |
| } | |
| } | } |
| } | } |
| Line 65 DB_Connection::DB_Connection(Pool& apool | Line 64 DB_Connection::DB_Connection(Pool& apool |
| prev_expiration_pass_time(0) { | prev_expiration_pass_time(0) { |
| //_asm int 3; | //_asm int 3; |
| char DB_DATA_DIR__VALUE[MAX_STRING]; | char DB_DATA_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]; |
| const char *db_home_cstr=fdb_home.cstr(String::UL_FILE_SPEC); | const char *db_home_cstr=fdb_home.cstr(String::UL_FILE_SPEC); |
| snprintf(DB_DATA_DIR__VALUE, MAX_STRING, "DB_DATA_DIR %s", db_home_cstr); | snprintf(DB_DATA_DIR__VALUE, MAX_STRING, "DB_DATA_DIR %s", db_home_cstr); |
| snprintf(DB_LOG_DIR__VALUE, MAX_STRING, "DB_LOG_DIR %s", db_home_cstr); | |
| snprintf(DB_TMP_DIR__VALUE, MAX_STRING, "DB_TMP_DIR %s", db_home_cstr); | snprintf(DB_TMP_DIR__VALUE, MAX_STRING, "DB_TMP_DIR %s", db_home_cstr); |
| char *db_config[] = { | char *db_config[] = { |
| DB_DATA_DIR__VALUE, | DB_DATA_DIR__VALUE, |
| DB_LOG_DIR__VALUE, | |
| DB_TMP_DIR__VALUE, | DB_TMP_DIR__VALUE, |
| 0 | 0 |
| }; | }; |
| Line 84 DB_Connection::DB_Connection(Pool& apool | Line 80 DB_Connection::DB_Connection(Pool& apool |
| u_int32_t flags= | u_int32_t flags= |
| (parser_multithreaded?DB_THREAD:0) | (parser_multithreaded?DB_THREAD:0) |
| | DB_CREATE | | DB_CREATE |
| | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN; | | DB_INIT_MPOOL; |
| // prepare dbenv structure | // prepare dbenv structure |
| memset(&dbenv, 0, sizeof(dbenv)); | memset(&dbenv, 0, sizeof(dbenv)); |
| Line 105 DB_Connection::DB_Connection(Pool& apool | Line 101 DB_Connection::DB_Connection(Pool& apool |
| &dbenv, | &dbenv, |
| flags | flags |
| )); | )); |
| // after some hang noticed this to be null | |
| if(!dbenv.tx_info) | |
| throw Exception(0, 0, | |
| &fdb_home, | |
| "transaction system failed to initialize"); | |
| } | } |
| DB_Connection::~DB_Connection() { | DB_Connection::~DB_Connection() { |
| // close tables | // close tables |
| table_cache.for_each(expire_table, | table_cache.for_each(expire_table, |
| reinterpret_cast<void *>(time(0)/* =now= expire[close] all*/)); | reinterpret_cast<void *>(time(0)+1/* =future= expire[close] all*/)); |
| // destroy connection data | // destroy connection data |
| check("db_appexit", &fdb_home, db_appexit(&dbenv)); | check("db_appexit", &fdb_home, db_appexit(&dbenv)); |
| Line 144 void DB_Connection::check(const char *op | Line 134 void DB_Connection::check(const char *op |
| } | } |
| DB_Table_ptr DB_Connection::get_table_ptr(const String& request_file_name, const String *source) { | DB_Table_ptr DB_Connection::get_table_ptr(const String& request_file_name, const String *source) { |
| // checkpoint | |
| { | |
| 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 | // 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); |
| if(!result) { // no cached table | if(!result) { // no cached table |
| Line 208 void DB_Connection::maybe_expire_table_c | Line 184 void DB_Connection::maybe_expire_table_c |
| } | } |
| static void add_table_to_status_table(const Hash::Key& key, Hash::Val *& value, void *info) { | static void add_table_to_status_table(const Hash::Key& key, Hash::Val *& value, void *info) { |
| if(DB_Table *db_table=static_cast<DB_Table *>(value)) { | DB_Table *db_table=static_cast<DB_Table *>(value); |
| Table& status_table=*static_cast<Table *>(info); | Table& status_table=*static_cast<Table *>(info); |
| Pool& pool=status_table.pool(); | Pool& pool=status_table.pool(); |
| Array& row=*new(pool) Array(pool); | Array& row=*new(pool) Array(pool); |
| // name | // name |
| row+=&db_table->file_name(); | row+=&db_table->file_name(); |
| // time | // time |
| time_t time_stamp=db_table->get_time_used(); | time_t time_stamp=db_table->get_time_used(); |
| const char *unsafe_time_cstr=ctime(&time_stamp); | const char *unsafe_time_cstr=ctime(&time_stamp); |
| int time_buf_size=strlen(unsafe_time_cstr); | int time_buf_size=strlen(unsafe_time_cstr); |
| char *safe_time_buf=(char *)pool.malloc(time_buf_size); | char *safe_time_buf=(char *)pool.malloc(time_buf_size); |
| memcpy(safe_time_buf, unsafe_time_cstr, time_buf_size); | memcpy(safe_time_buf, unsafe_time_cstr, time_buf_size); |
| row+=new(pool) String(pool, safe_time_buf, time_buf_size); | row+=new(pool) String(pool, safe_time_buf, time_buf_size); |
| // users | // users |
| char *users_buf=(char *)pool.malloc(MAX_NUMBER); | char *users_buf=(char *)pool.malloc(MAX_NUMBER); |
| row+=new(pool) String(pool, | row+=new(pool) String(pool, |
| users_buf, snprintf(users_buf, MAX_NUMBER, "%d", db_table->get_users_count())); | users_buf, snprintf(users_buf, MAX_NUMBER, "%d", db_table->get_users_count())); |
| status_table+=&row; | status_table+=&row; |
| } | |
| } | } |
| Value& DB_Connection::get_status(Pool& pool, const String *source) { | Value& DB_Connection::get_status(Pool& pool, const String *source) { |
| Array& columns=*new(pool) Array(pool); | Array& columns=*new(pool) Array(pool); |