-
Notifications
You must be signed in to change notification settings - Fork 256
/
sql_pooling.cc
151 lines (134 loc) · 5.14 KB
/
sql_pooling.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2010-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
// Written by Marco van Wieringen, March 2010
/**
* @file
* BAREOS sql pooling code that manages the database connection pools.
*/
#include "include/bareos.h"
#if HAVE_MYSQL || HAVE_POSTGRESQL || HAVE_DBI
# include "cats.h"
# include "cats_backends.h"
/**
* Get a non-pooled connection used when either sql pooling is
* runtime disabled or at compile time. Or when we run out of
* pooled connections and need more database connections.
*/
BareosDb* DbSqlGetNonPooledConnection(JobControlRecord* jcr,
const char* db_drivername,
const char* db_name,
const char* db_user,
const char* db_password,
const char* db_address,
int db_port,
const char* db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool try_reconnect,
bool exit_on_fatal,
bool need_private)
{
BareosDb* mdb;
# if defined(HAVE_DYNAMIC_CATS_BACKENDS)
Dmsg2(100,
"DbSqlGetNonPooledConnection allocating 1 new non pooled database "
"connection to database %s, backend type %s\n",
db_name, db_drivername);
# else
Dmsg1(100,
"DbSqlGetNonPooledConnection allocating 1 new non pooled database "
"connection to database %s\n",
db_name);
# endif
mdb = db_init_database(jcr, db_drivername, db_name, db_user, db_password,
db_address, db_port, db_socket, mult_db_connections,
disable_batch_insert, try_reconnect, exit_on_fatal,
need_private);
if (mdb == NULL) { return NULL; }
if (!mdb->OpenDatabase(jcr)) {
Jmsg(jcr, M_FATAL, 0, "%s", mdb->strerror());
mdb->CloseDatabase(jcr);
return NULL;
}
return mdb;
}
/**
* Initialize the sql connection pool.
* For non pooling this is a no-op.
*/
bool db_sql_pool_initialize(const char*,
const char*,
const char*,
const char*,
const char*,
int,
const char*,
bool,
bool,
bool,
int,
int,
int,
int,
int)
{
return true;
}
/**
* Cleanup the sql connection pools.
* For non pooling this is a no-op.
*/
void DbSqlPoolDestroy(void) {}
/**
* Flush the sql connection pools.
* For non pooling this is a no-op.
*/
void DbSqlPoolFlush(void) {}
/**
* Get a new connection from the pool.
* For non pooling we just call DbSqlGetNonPooledConnection.
*/
BareosDb* DbSqlGetPooledConnection(JobControlRecord* jcr,
const char* db_drivername,
const char* db_name,
const char* db_user,
const char* db_password,
const char* db_address,
int db_port,
const char* db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool try_reconnect,
bool exit_on_fatal,
bool need_private)
{
return DbSqlGetNonPooledConnection(
jcr, db_drivername, db_name, db_user, db_password, db_address, db_port,
db_socket, mult_db_connections, disable_batch_insert, try_reconnect,
exit_on_fatal, need_private);
}
/**
* Put a connection back onto the pool for reuse.
* For non pooling we just do a CloseDatabase.
*/
void DbSqlClosePooledConnection(JobControlRecord* jcr, BareosDb* mdb, bool)
{
mdb->CloseDatabase(jcr);
}
#endif /* HAVE_MYSQL || HAVE_POSTGRESQL || HAVE_DBI */