36{
38
39 _open.push([
this, name, updatesEnabledForThis, &pool]() ->
bool
40 {
41 std::string
const dbString =
sConfigMgr->GetOption<std::string>(name +
"DatabaseInfo",
"");
42 if (dbString.empty())
43 {
44 LOG_ERROR(
_logger,
"Database {} not specified in configuration file!", name);
45 return false;
46 }
47
49 if (asyncThreads < 1 || asyncThreads > 32)
50 {
51 LOG_ERROR(
_logger,
"{} database: invalid number of worker threads specified. "
52 "Please pick a value between 1 and 32.", name);
53 return false;
54 }
55
57
59
61 {
62
63 if (error == CR_CONNECTION_ERROR)
64 {
67 uint8 reconnectCount = 0;
68
69 while (reconnectCount < attempts)
70 {
72 std::this_thread::sleep_for(reconnectSeconds);
74
75 if (error == CR_CONNECTION_ERROR)
76 {
77 reconnectCount++;
78 }
79 else
80 {
81 break;
82 }
83 }
84 }
85
86
87 if ((error == ER_BAD_DB_ERROR) && updatesEnabledForThis &&
_autoSetup)
88 {
89
91 {
92 error = 0;
93 }
94 }
95
96
97 if (error)
98 {
99 LOG_ERROR(
_logger,
"DatabasePool {} NOT opened. There were errors opening the MySQL connections. "
100 "Check your log file for specific errors", name);
101
102 return false;
103 }
104 }
105
107 {
109 });
110
111 return true;
112 });
113
114
115 if (updatesEnabledForThis)
116 {
117 _populate.push([
this, name, &pool]() ->
bool
118 {
120 {
121 LOG_ERROR(
_logger,
"Could not populate the {} database, see log for details.", name);
122 return false;
123 }
124
125 return true;
126 });
127
128 _update.push([
this, name, &pool]() ->
bool
129 {
131 {
132 LOG_ERROR(
_logger,
"Could not update the {} database, see log for details.", name);
133 return false;
134 }
135
136 return true;
137 });
138 }
139
140 _prepare.push([
this, name, &pool]() ->
bool
141 {
143 {
144 LOG_ERROR(
_logger,
"Could not prepare statements of the {} database, see log for details.", name);
145 return false;
146 }
147
148 return true;
149 });
150
151 return *this;
152}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:156
#define LOG_WARN(filterType__,...)
Definition: Log.h:160
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition: Duration.h:30
std::uint8_t uint8
Definition: Define.h:109
bool PrepareStatements()
Prepares all prepared statements.
Definition: DatabaseWorkerPool.cpp:133
uint32 Open()
Definition: DatabaseWorkerPool.cpp:87
void SetConnectionInfo(std::string_view infoString, uint8 const asyncThreads, uint8 const synchThreads)
Definition: DatabaseWorkerPool.cpp:78
void Close()
Definition: DatabaseWorkerPool.cpp:113
std::queue< Predicate > _populate
Definition: DatabaseLoader.h:78
std::queue< Predicate > _prepare
Definition: DatabaseLoader.h:78
std::queue< Predicate > _update
Definition: DatabaseLoader.h:78
std::queue< Predicate > _open
Definition: DatabaseLoader.h:78
std::stack< Closer > _close
Definition: DatabaseLoader.h:79
Definition: DBUpdater.h:68
static bool IsEnabled(uint32 const updateMask)