#define OSDependentInit() InitWinAPIWrapper()
+#define sbrk(x) 0
+
#if defined(BUILDING_DLL)
# define DLL_IMP_EXP _declspec(dllexport)
#define sql_free_result(x) my_mysql_free_result(x)
#define sql_fetch_row(x) mysql_fetch_row((x)->result)
#define sql_query(x, y) mysql_query((x)->db, (y))
-#define sql_close(x) mysql_close((x)->db)
#define sql_strerror(x) mysql_error((x)->db)
#define sql_num_rows(x) mysql_num_rows((x)->result)
#define sql_data_seek(x, i) mysql_data_seek((x)->result, (i))
Dmsg2(100, "DB REopen %d %s\n", mdb->ref_count, db_name);
mdb->ref_count++;
V(mutex);
+ Dmsg3(100, "initdb ref=%d connected=%d db=%p\n", mdb->ref_count,
+ mdb->connected, mdb->db);
return mdb; /* already open */
}
}
mdb->esc_name = get_pool_memory(PM_FNAME);
mdb->esc_path = get_pool_memory(PM_FNAME);
qinsert(&db_list, &mdb->bq); /* put db in list */
+ Dmsg3(100, "initdb ref=%d connected=%d db=%p\n", mdb->ref_count,
+ mdb->connected, mdb->db);
V(mutex);
return mdb;
}
V(mutex);
return 1;
}
- mdb->connected = false;
if ((errstat=rwl_init(&mdb->lock)) != 0) {
Mmsg1(&mdb->errmsg, _("Unable to initialize DB lock. ERR=%s\n"),
}
/* connect to the database */
-#ifdef HAVE_EMBEDDED_MYSQL
- mysql_server_init(0, NULL, NULL);
+#ifdef xHAVE_EMBEDDED_MYSQL
+// mysql_server_init(0, NULL, NULL);
#endif
mysql_init(&(mdb->mysql));
Dmsg0(50, "mysql_init done\n");
return 0;
}
+ mdb->connected = true;
if (!check_tables_version(jcr, mdb)) {
V(mutex);
return 0;
#ifdef HAVE_THREAD_SAFE_MYSQL
my_thread_init();
#endif
+ Dmsg3(100, "opendb ref=%d connected=%d db=%p\n", mdb->ref_count,
+ mdb->connected, mdb->db);
- mdb->connected = true;
V(mutex);
return 1;
}
}
db_end_transaction(jcr, mdb);
P(mutex);
+ sql_free_result(mdb);
mdb->ref_count--;
#if defined(HAVE_THREAD_SAFE_MYSQL)
my_thread_end();
#endif
+ Dmsg3(100, "closedb ref=%d connected=%d db=%p\n", mdb->ref_count,
+ mdb->connected, mdb->db);
if (mdb->ref_count == 0) {
qdchain(&mdb->bq);
if (mdb->connected && mdb->db) {
- sql_close(mdb);
-#ifdef HAVE_EMBEDDED_MYSQL
- mysql_server_end();
+ Dmsg1(100, "close db=%p\n", mdb->db);
+ mysql_close(&(mdb->mysql));
+#ifdef xHAVE_EMBEDDED_MYSQL
+// mysql_server_end();
#endif
}
rwl_destroy(&mdb->lock);
return 0;
}
+ mdb->connected = true;
+
if (!check_tables_version(jcr, mdb)) {
V(mutex);
return 0;
sql_query(mdb, "SET datestyle TO 'ISO, YMD'");
- mdb->connected = true;
V(mutex);
return 1;
}
}
db_end_transaction(jcr, mdb);
P(mutex);
+ sql_free_result(mdb);
mdb->ref_count--;
if (mdb->ref_count == 0) {
qdchain(&mdb->bq);
return mdb->status;
}
-void my_postgresql_free_result (B_DB *mdb)
+void my_postgresql_free_result(B_DB *mdb)
{
if (mdb->result) {
PQclear(mdb->result);
" FROM batch "
" JOIN Path ON (batch.Path = Path.Path) "
" JOIN Filename ON (batch.Name = Filename.Name) ",
- NULL,NULL))
+ NULL,NULL))
{
Jmsg(jcr, M_FATAL, 0, "Can't fill File table %s\n", jcr->db_batch->errmsg);
return false;
Dmsg0(dbglevel, "put_file_into_catalog\n");
if (!jcr->db_batch) {
+ Dmsg2(100, "Opendb attr. Stream=%d fname=%s\n", ar->Stream, ar->fname);
jcr->db_batch = db_init_database(jcr,
mdb->db_name,
mdb->db_user,
if (!sql_batch_start(jcr, jcr->db_batch)) {
Jmsg(jcr, M_FATAL, 0,
- "Can't start batch mode %s", db_strerror(jcr->db_batch));
+ "Can't start batch mode %s", db_strerror(jcr->db_batch));
return false;
}
+ Dmsg3(100, "initdb ref=%d connected=%d db=%p\n", jcr->db_batch->ref_count,
+ jcr->db_batch->connected, jcr->db_batch->db);
}
-
B_DB *bdb = jcr->db_batch;
/*
free(db_name);
V(mutex);
return 0;
- }
+ }
+ mdb->connected = true;
free(db_name);
if (!check_tables_version(jcr, mdb)) {
V(mutex);
sqlite_busy_handler(mdb->db, my_busy_handler, NULL);
#endif
- mdb->connected = true;
V(mutex);
return 1;
}
}
db_end_transaction(jcr, mdb);
P(mutex);
+ sql_free_result(mdb);
mdb->ref_count--;
if (mdb->ref_count == 0) {
qdchain(&mdb->bq);
int FDConnectTimeout;
int SDConnectTimeout;
char *configfile = NULL;
+void *start_heap;
/* Globals Imported */
extern int r_first, r_last; /* first and last resources */
char *uid = NULL;
char *gid = NULL;
+ start_heap = sbrk(0);
setlocale(LC_ALL, "");
bindtextdomain("bacula", LOCALEDIR);
textdomain("bacula");
if (db) {
Jmsg(NULL, M_FATAL, 0, _("%s"), db_strerror(db));
Pmsg1(000, "%s", db_strerror(db));
+ db_close_database(NULL, db);
}
OK = false;
continue;
-/*
- *
- * Bacula Director Job processing routines
- *
- * Kern Sibbald, October MM
- *
- * Version $Id$
- */
/*
Bacula® - The Network Backup Solution
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
+/*
+ *
+ * Bacula Director Job processing routines
+ *
+ * Kern Sibbald, October MM
+ *
+ * Version $Id$
+ */
#include "bacula.h"
#include "dird.h"
/*
* Open database
*/
- Dmsg0(150, "Open database\n");
+ Dmsg0(100, "Open database\n");
jcr->db=db_init_database(jcr, jcr->catalog->db_name, jcr->catalog->db_user,
jcr->catalog->db_password, jcr->catalog->db_address,
jcr->catalog->db_port, jcr->catalog->db_socket,
jcr->catalog->db_name);
if (jcr->db) {
Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
+ db_close_database(jcr, jcr->db);
}
goto bail_out;
}
ua->jcr->catalog = ua->catalog;
- Dmsg0(150, "Open database\n");
+ Dmsg0(100, "UA Open database\n");
ua->db = db_init_database(ua->jcr, ua->catalog->db_name, ua->catalog->db_user,
ua->catalog->db_password, ua->catalog->db_address,
ua->catalog->db_port, ua->catalog->db_socket,
jcr->pool = pool; /* override */
}
if (jcr->db) {
+ Dmsg0(100, "complete_jcr close db\n");
db_close_database(jcr, jcr->db);
jcr->db = NULL;
}
+
+ Dmsg0(100, "complete_jcr open db\n");
jcr->db = jcr->db=db_init_database(jcr, jcr->catalog->db_name, jcr->catalog->db_user,
jcr->catalog->db_password, jcr->catalog->db_address,
jcr->catalog->db_port, jcr->catalog->db_socket,
#include "bacula.h"
#include "dird.h"
-extern void *start_sbrk;
+extern void *start_heap;
static void list_scheduled_jobs(UAContext *ua);
static void list_running_jobs(UAContext *ua);
ua->send_msg(_("Daemon started %s, %d Jobs run since started.\n"),
dt, num_jobs_run);
}
- ua->send_msg(_(" Heap: sbrk=%s bytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"),
- edit_uint64_with_commas((uint64_t)sbrk(0)-(uint64_t)start_sbrk, b1),
+ ua->send_msg(_(" Heap: heap=%s smbytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"),
+ edit_uint64_with_commas((char *)sbrk(0)-(char *)start_heap, b1),
edit_uint64_with_commas(sm_bytes, b2),
edit_uint64_with_commas(sm_max_bytes, b3),
edit_uint64_with_commas(sm_buffers, b4),
/* Exported variables */
CLIENT *me; /* my resource */
bool no_signals = false;
+void *start_heap;
#define CONFIG_FILE "bacula-fd.conf" /* default config file */
char *uid = NULL;
char *gid = NULL;
+ start_heap = sbrk(0);
setlocale(LC_ALL, "");
bindtextdomain("bacula", LOCALEDIR);
textdomain("bacula");
-/*
- * Bacula File Daemon Status routines
- *
- * Kern Sibbald, August MMI
- *
- * Version $Id$
- *
- */
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
+ Copyright (C) 2001-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.
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
+/*
+ * Bacula File Daemon Status routines
+ *
+ * Kern Sibbald, August MMI
+ *
+ * Version $Id$
+ *
+ */
#include "bacula.h"
#include "filed.h"
+extern void *start_heap;
+
/* Forward referenced functions */
static void list_terminated_jobs(void sendit(const char *msg, int len, void *sarg), void *arg);
static void bsock_sendit(const char *msg, int len, void *arg);
void output_status(void sendit(const char *msg, int len, void *sarg), void *arg)
{
int sec, bps;
- char *msg, b1[32], b2[32], b3[32], b4[32];
+ char *msg, b1[32], b2[32], b3[32], b4[32], b5[5];
int len;
bool found = false;
JCR *njcr;
sendit(msg, len, arg);
}
#endif
- len = Mmsg(msg, _(" Heap: bytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"),
- edit_uint64_with_commas(sm_bytes, b1),
- edit_uint64_with_commas(sm_max_bytes, b2),
- edit_uint64_with_commas(sm_buffers, b3),
- edit_uint64_with_commas(sm_max_buffers, b4));
+ len = Mmsg(msg, _(" Heap: heap=%s smbytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"),
+ edit_uint64_with_commas((char *)sbrk(0)-(char *)start_heap, b1),
+ edit_uint64_with_commas(sm_bytes, b2),
+ edit_uint64_with_commas(sm_max_bytes, b3),
+ edit_uint64_with_commas(sm_buffers, b4),
+ edit_uint64_with_commas(sm_max_buffers, b5));
sendit(msg, len, arg);
len = Mmsg(msg, _(" Sizeof: boffset_t=%d size_t=%d debug=%d trace=%d\n"),
sizeof(boffset_t), sizeof(size_t), debug_level, get_trace());
(void)localtime_r(&ttime, &tm);
/* NOTE! since the compiler complains about %y, I use %y and cut the century */
strftime(dt, maxlen, "%d-%b-%Y %H:%M", &tm);
- strcpy(dt+7, dt+9);
+ strcpy(dt+7, dt+9); /* overlay the century */
return dt;
}
#endif
sigaction(SIGBUS, &sighandle, NULL);
sigaction(SIGFPE, &sighandle, NULL);
- sigaction(SIGKILL, &sighandle, NULL);
+/* sigaction(SIGKILL, &sighandle, NULL); cannot be trapped */
sigaction(SIGUSR1, &sighandle, NULL);
sigaction(SIGSEGV, &sighandle, NULL);
sigaction(SIGUSR2, &sighandle, NULL);
#ifdef SIGSTKFLT
sigaction(SIGSTKFLT, &sighandle, NULL);
#endif
- sigaction(SIGSTOP, &sighandle, NULL);
+/* sigaction(SIGSTOP, &sighandle, NULL); cannot be trapped */
sigaction(SIGTSTP, &sighandle, NULL);
sigaction(SIGTTIN, &sighandle, NULL);
sigaction(SIGTTOU, &sighandle, NULL);
-/*
- * Bacula thread watchdog routine. General routine that
- * allows setting a watchdog timer with a callback that is
- * called when the timer goes off.
- *
- * Kern Sibbald, January MMII
- *
- */
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2002-2006 Free Software Foundation Europe e.V.
+ Copyright (C) 2002-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.
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
+/*
+ * Bacula thread watchdog routine. General routine that
+ * allows setting a watchdog timer with a callback that is
+ * called when the timer goes off.
+ *
+ * Kern Sibbald, January MMII
+ *
+ */
#include "bacula.h"
#include "jcr.h"
/* Exported globals */
time_t watchdog_time = 0; /* this has granularity of SLEEP_TIME */
time_t watchdog_sleep_time = 60; /* examine things every 60 seconds */
-void *start_sbrk;
/* Locals */
static pthread_mutex_t timer_mutex = PTHREAD_MUTEX_INITIALIZER;
if (wd_is_init) {
return 0;
}
- start_sbrk = sbrk(0);
Dmsg0(800, "Initialising NicB-hacked watchdog thread\n");
watchdog_time = time(NULL);
P(timer_mutex);
pthread_cond_signal(&timer);
V(timer_mutex);
+ bmicrosleep(0, 100);
}
/*
}
quit = true; /* notify watchdog thread to stop */
- wd_is_init = false;
-
ping_watchdog();
+
stat = pthread_join(wd_tid, NULL);
while (!wd_queue->empty()) {
delete wd_inactive;
wd_inactive = NULL;
rwl_destroy(&lock);
+ wd_is_init = false;
return stat;
}
extern BSOCK *filed_chan;
extern int r_first, r_last;
extern struct s_res resources[];
+extern void *start_heap;
/* Static variables */
static char qstatus[] = ".status %127s\n";
AUTOCHANGER *changer;
DEVICE *dev;
char dt[MAX_TIME_LENGTH];
- char *msg, b1[35], b2[35], b3[35], b4[35];
+ char *msg, b1[35], b2[35], b3[35], b4[35], b5[35];
int bpb;
int len;
dt, num_jobs_run, num_jobs_run == 1 ? "" : "s");
sendit(msg, len, arg);
- len = Mmsg(msg, _(" Heap: bytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"),
- edit_uint64_with_commas(sm_bytes, b1),
- edit_uint64_with_commas(sm_max_bytes, b2),
- edit_uint64_with_commas(sm_buffers, b3),
- edit_uint64_with_commas(sm_max_buffers, b4));
+ len = Mmsg(msg, _(" Heap: heap=%s smbytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"),
+ edit_uint64_with_commas((char *)sbrk(0)-(char *)start_heap, b1),
+ edit_uint64_with_commas(sm_bytes, b2),
+ edit_uint64_with_commas(sm_max_bytes, b3),
+ edit_uint64_with_commas(sm_buffers, b4),
+ edit_uint64_with_commas(sm_max_buffers, b5));
sendit(msg, len, arg);
/*
bool forge_on = false; /* proceed inspite of I/O errors */
pthread_mutex_t device_release_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t wait_device_release = PTHREAD_COND_INITIALIZER;
+void *start_heap;
static uint32_t VolSessionId = 0;
char *uid = NULL;
char *gid = NULL;
+ start_heap = sbrk(0);
setlocale(LC_ALL, "");
bindtextdomain("bacula", LOCALEDIR);
textdomain("bacula");
Technical notes on version 2.1
General:
+10May07
+kes Implement heap size display in status for all daemons.
+kes Attempt to fix MySQL db open memory loss (not successfull).
+kes Don't set SIGKILL and SIGSTOP neither can be trapped.
+kes Eliminate memory loss in MySQL (possibly other SQLs) during
+ Query. This looks like a MySQL but but by doing extra releases,
+ the memory goes away. This should fix bug #847.
09May07
kes When backup fails, cancel SD before waiting for sd termination.
kes If SD is waiting for FD to connect during cancel, wake up the