From 404b02b216516d968df165d9d2ca17dfac620636 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 13 May 2007 19:38:30 +0000 Subject: [PATCH] Fixed the batch insert MySQL thread specific data that was not being freed. See cats/mysql.c:db_thread_cleanup(). git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4772 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/cats/bdb.c | 3 +++ bacula/src/cats/mysql.c | 13 +++++++++++++ bacula/src/cats/postgresql.c | 3 +++ bacula/src/cats/protos.h | 18 +++++++++--------- bacula/src/cats/sqlite.c | 3 +++ bacula/src/dird/msgchan.c | 1 + bacula/technotes-2.1 | 2 ++ 7 files changed, 34 insertions(+), 9 deletions(-) diff --git a/bacula/src/cats/bdb.c b/bacula/src/cats/bdb.c index e49feadde4..1e7bb71be8 100644 --- a/bacula/src/cats/bdb.c +++ b/bacula/src/cats/bdb.c @@ -289,6 +289,9 @@ void db_close_database(JCR *jcr, B_DB *mdb) V(mutex); } +void db_thread_cleanup() +{ } + void db_escape_string(char *snew, char *old, int len) { diff --git a/bacula/src/cats/mysql.c b/bacula/src/cats/mysql.c index 645dbb4385..a8211c7934 100644 --- a/bacula/src/cats/mysql.c +++ b/bacula/src/cats/mysql.c @@ -258,6 +258,19 @@ db_close_database(JCR *jcr, B_DB *mdb) V(mutex); } +/* + * This call is needed because the message channel thread + * opens a database on behalf of a jcr that was created in + * a different thread. MySQL then allocates thread specific + * data, which is NOT freed when the original jcr thread + * closes the database. Thus the msgchan must call here + * to cleanup any thread specific data that it created. + */ +void db_thread_cleanup() +{ + my_thread_end(); +} + /* * Return the next unique index (auto-increment) for * the given table. Return NULL on error. diff --git a/bacula/src/cats/postgresql.c b/bacula/src/cats/postgresql.c index 0b0218a72d..a96ac4a095 100644 --- a/bacula/src/cats/postgresql.c +++ b/bacula/src/cats/postgresql.c @@ -253,6 +253,9 @@ db_close_database(JCR *jcr, B_DB *mdb) V(mutex); } +void db_thread_cleanup() +{ } + /* * Return the next unique index (auto-increment) for * the given table. Return NULL on error. diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index 342fa51438..8a8b2f0185 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -1,14 +1,7 @@ -/* - * - * Database routines that are exported by the cats library for - * use elsewhere in Bacula (mainly the Director). - * - * Version $Id$ - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2000-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -32,6 +25,13 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * + * Database routines that are exported by the cats library for + * use elsewhere in Bacula (mainly the Director). + * + * Version $Id$ + */ #ifndef __SQL_PROTOS_H #define __SQL_PROTOS_H @@ -53,7 +53,7 @@ int db_sql_query(B_DB *mdb, const char *cmd, DB_RESULT_HANDLER *result_handler, void db_start_transaction(JCR *jcr, B_DB *mdb); void db_end_transaction(JCR *jcr, B_DB *mdb); int db_int64_handler(void *ctx, int num_fields, char **row); - +void db_thread_cleanup(); /* create.c */ bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar); diff --git a/bacula/src/cats/sqlite.c b/bacula/src/cats/sqlite.c index 856a769699..642af3815c 100644 --- a/bacula/src/cats/sqlite.c +++ b/bacula/src/cats/sqlite.c @@ -253,6 +253,9 @@ db_close_database(JCR *jcr, B_DB *mdb) V(mutex); } +void db_thread_cleanup() +{ } + /* * Return the next unique index (auto-increment) for * the given table. Return 0 on error. diff --git a/bacula/src/dird/msgchan.c b/bacula/src/dird/msgchan.c index 0a29de1e0e..e6f85cee49 100644 --- a/bacula/src/dird/msgchan.c +++ b/bacula/src/dird/msgchan.c @@ -344,6 +344,7 @@ extern "C" void msg_thread_cleanup(void *arg) pthread_cond_broadcast(&jcr->term_wait); /* wakeup any waiting threads */ Dmsg1(100, "=== End msg_thread. use=%d\n", jcr->use_count()); free_jcr(jcr); /* release jcr */ + db_thread_cleanup(); /* remove thread specific data */ } /* diff --git a/bacula/technotes-2.1 b/bacula/technotes-2.1 index edaa2e404f..bb55ab07c2 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -2,6 +2,8 @@ General: 13May07 +kes Fixed the batch insert MySQL thread specific data that was not + being freed. See cats/mysql.c:db_thread_cleanup(). kes Fix restore before command. kes Convert old hdr.name to name() in a few places. kes Implement update jobid command. -- 2.39.5