X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fcats%2Fsql.c;h=bbee8561b840073c21884939587ba6c6b9c0eead;hb=d6a2978cea17ce237b4ea9c71853cb96b9f4416f;hp=99d949b44152d6fa4aac02939f45058386afb036;hpb=2440f05a9e0d90af391fa2a8137fc74334a55c16;p=bacula%2Fbacula diff --git a/bacula/src/cats/sql.c b/bacula/src/cats/sql.c index 99d949b441..bbee8561b8 100644 --- a/bacula/src/cats/sql.c +++ b/bacula/src/cats/sql.c @@ -311,33 +311,6 @@ char *db_strerror(B_DB *mdb) return mdb->errmsg; } -static void update_lock_dbg(B_DB *mdb) -{ - if (mdb->allow_transactions) { /* batch connection */ - return; - } - if (_db_lock_recurse_count && !pthread_equal(_db_lock_threadid, pthread_self())) { - Dmsg2(1, "ERROR: not the same threadif %p != %p\n", _db_lock_threadid, pthread_self()); - } - _db_lock_recurse_count++; - _db_lock_time = (utime_t) time(NULL); - _db_lock_threadid = pthread_self(); -} - -static void update_unlock_dbg(B_DB *mdb) -{ - if (mdb->allow_transactions) { /* batch connection */ - return; - } - if (!pthread_equal(_db_lock_threadid, pthread_self())) { - Dmsg2(1, "ERROR: not the same threadid %p != %p", _db_lock_threadid, pthread_self()); - } - _db_lock_recurse_count--; - if (!_db_lock_recurse_count) { - memset(&_db_lock_threadid, 0, sizeof(_db_lock_threadid)); - } -} - /* * Lock database, this can be called multiple times by the same * thread without blocking, but must be unlocked the number of @@ -351,7 +324,6 @@ void _db_lock(const char *file, int line, B_DB *mdb) e_msg(file, line, M_FATAL, 0, "rwl_writelock failure. stat=%d: ERR=%s\n", errstat, be.bstrerror(errstat)); } - update_lock_dbg(mdb); } /* @@ -362,7 +334,6 @@ void _db_lock(const char *file, int line, B_DB *mdb) void _db_unlock(const char *file, int line, B_DB *mdb) { int errstat; - update_unlock_dbg(mdb); if ((errstat=rwl_writeunlock(&mdb->lock)) != 0) { berrno be; e_msg(file, line, M_FATAL, 0, "rwl_writeunlock failure. stat=%d: ERR=%s\n", @@ -769,4 +740,28 @@ bool db_open_batch_connexion(JCR *jcr, B_DB *mdb) return true; } +/* + * !!! WARNING !!! Use this function only when bacula is stopped. + * ie, after a fatal signal and before exiting the program + * Print information about a B_DB object. + */ +void _dbg_print_db(JCR *jcr, FILE *fp) +{ + B_DB *mdb = jcr->db; + + if (!mdb) { + return; + } + + fprintf(fp, "B_DB=%p db_name=%s db_user=%s connected=%i\n", + mdb, NPRTB(mdb->db_name), NPRTB(mdb->db_user), mdb->connected); + fprintf(fp, "\tcmd=\"%s\" changes=%i\n", NPRTB(mdb->cmd), mdb->changes); + if (mdb->lock.valid == RWLOCK_VALID) { + fprintf(fp, "\tRWLOCK=%p w_active=%i w_wait=%i\n", &mdb->lock, mdb->lock.w_active, mdb->lock.w_wait); +#ifndef HAVE_WIN32 + fprintf(fp, "\t\tthreadid=0x%x mutex=%p\n", (int)mdb->lock.writer_id, &mdb->lock.mutex); +#endif + } +} + #endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL*/