Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
e86fe113
Commit
e86fe113
authored
Sep 11, 2020
by
Carla Guillen
Browse files
adding checks for initialized mysql pointer
parent
3ba3288e
Changes
1
Hide whitespace changes
Inline
Side-by-side
analytics/operators/persystsql/MariaDB.cpp
View file @
e86fe113
...
...
@@ -111,11 +111,15 @@ std::mutex MariaDB::mut;
std
::
once_flag
MariaDB
::
init_once
;
void
MariaDB
::
print_error
(){
LOG
(
error
)
<<
"Error("
<<
mysql_errno
(
_mysql
)
<<
") ["
<<
mysql_sqlstate
(
_mysql
)
<<
"]
\"
"
<<
mysql_error
(
_mysql
)
<<
"
\"
"
;
if
(
mysql_errno
(
_mysql
)
==
2006
){
mysql_close
(
_mysql
);
_initialized
=
false
;
}
if
(
_initialized
){
LOG
(
error
)
<<
"Error("
<<
mysql_errno
(
_mysql
)
<<
") ["
<<
mysql_sqlstate
(
_mysql
)
<<
"]
\"
"
<<
mysql_error
(
_mysql
)
<<
"
\"
"
;
if
(
mysql_errno
(
_mysql
)
==
2006
){
mysql_close
(
_mysql
);
_initialized
=
false
;
}
}
else
{
LOG
(
error
)
<<
"MySQL connection not initialized, will try to initialize on the next measurement..."
;
}
}
MariaDB
::
MariaDB
()
:
_mysql
(
NULL
),
_rotation
(
EVERY_MONTH
),
_every_x_days
(
0
),
_end_aggregate_timestamp
(
0
),
_initialized
(
false
)
{
...
...
@@ -174,7 +178,7 @@ bool MariaDB::getDBJobID(const std::string & job_id_string, std::string& job_db_
build_query
<<
" AND nodes="
<<
number_nodes
<<
" AND batch_domain="
<<
batch_domain
;
auto
query
=
build_query
.
str
();
LOG
(
debug
)
<<
query
;
if
(
mysql_real_query
(
_mysql
,
query
.
c_str
(),
query
.
size
()))
{
if
(
_initialized
&&
mysql_real_query
(
_mysql
,
query
.
c_str
(),
query
.
size
()))
{
print_error
();
return
false
;
}
...
...
@@ -213,7 +217,7 @@ bool MariaDB::getCurrentSuffixAggregateTable(std::string & suffix){
auto
query
=
build_query
.
str
();
LOG
(
debug
)
<<
query
;
if
(
mysql_real_query
(
_mysql
,
query
.
c_str
(),
query
.
size
())){
if
(
_initialized
&&
mysql_real_query
(
_mysql
,
query
.
c_str
(),
query
.
size
())){
print_error
();
return
false
;
}
...
...
@@ -252,7 +256,7 @@ bool MariaDB::insertIntoJob(const std::string& job_id_string, const std::string&
auto
select_query
=
build_query
.
str
();
LOG
(
debug
)
<<
select_query
;
if
(
mysql_real_query
(
_mysql
,
select_query
.
c_str
(),
select_query
.
size
()))
{
if
(
_initialized
&&
mysql_real_query
(
_mysql
,
select_query
.
c_str
(),
select_query
.
size
()))
{
print_error
();
return
false
;
}
...
...
@@ -281,7 +285,7 @@ bool MariaDB::insertIntoJob(const std::string& job_id_string, const std::string&
std
::
string
query
=
build_insert
.
str
();
LOG
(
debug
)
<<
query
;
if
(
mysql_real_query
(
_mysql
,
query
.
c_str
(),
query
.
size
()))
{
if
(
_initialized
&&
mysql_real_query
(
_mysql
,
query
.
c_str
(),
query
.
size
()))
{
print_error
();
return
false
;
}
...
...
@@ -309,7 +313,7 @@ bool MariaDB::insertInAggregateTable(const std::string& suffix, Aggregate_info_t
LOG
(
debug
)
<<
query
;
std
::
lock_guard
<
std
::
mutex
>
lock
(
mut
);
if
(
mysql_real_query
(
_mysql
,
query
.
c_str
(),
query
.
size
())){
if
(
_initialized
&&
mysql_real_query
(
_mysql
,
query
.
c_str
(),
query
.
size
())){
print_error
();
return
false
;
}
...
...
@@ -318,7 +322,7 @@ bool MariaDB::insertInAggregateTable(const std::string& suffix, Aggregate_info_t
bool
MariaDB
::
createNewAggregate
(
std
::
string
&
new_suffix
){
std
::
string
select
=
"SELECT suffix, end_timestamp FROM SuffixToAggregateTable ORDER BY end_timestamp DESC LIMIT 1"
;
if
(
mysql_real_query
(
_mysql
,
select
.
c_str
(),
select
.
size
())){
if
(
_initialized
&&
mysql_real_query
(
_mysql
,
select
.
c_str
(),
select
.
size
())){
print_error
();
}
std
::
string
last_suffix
=
"0"
;
...
...
@@ -351,7 +355,7 @@ bool MariaDB::createNewAggregate(std::string& new_suffix){
auto
query
=
build_insert
.
str
();
LOG
(
debug
)
<<
query
;
if
(
mysql_real_query
(
_mysql
,
query
.
c_str
(),
query
.
size
())){
if
(
_initialized
&&
mysql_real_query
(
_mysql
,
query
.
c_str
(),
query
.
size
())){
print_error
();
return
false
;
}
...
...
@@ -360,7 +364,7 @@ bool MariaDB::createNewAggregate(std::string& new_suffix){
auto
query2
=
build_create
.
str
();
LOG
(
debug
)
<<
query2
;
if
(
mysql_real_query
(
_mysql
,
query2
.
c_str
(),
query2
.
size
()
)){
if
(
_initialized
&&
mysql_real_query
(
_mysql
,
query2
.
c_str
(),
query2
.
size
()
)){
if
(
mysql_errno
(
_mysql
)
==
1050
){
return
true
;
//table exists!
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment