54{
56
57 _open.push([
this, name, updatesEnabledForThis, &pool]() ->
bool
58 {
59 std::string const& defaultDatabaseInfo = GetDefaultDatabaseInfo(name);
60 std::string
const dbString =
sConfigMgr->GetOption<std::string>(name +
"DatabaseInfo", defaultDatabaseInfo);
61 if (dbString.empty())
62 {
63 LOG_ERROR(
_logger,
"Database {} not specified in configuration file!", name);
64 return false;
65 }
66
68 if (asyncThreads < 1 || asyncThreads > 32)
69 {
70 LOG_ERROR(
_logger,
"{} database: invalid number of worker threads specified. "
71 "Please pick a value between 1 and 32.", name);
72 return false;
73 }
74
76
78
80 {
81
82 if (error == CR_CONNECTION_ERROR)
83 {
86 uint8 reconnectCount = 0;
87
88 while (reconnectCount < attempts)
89 {
91 std::this_thread::sleep_for(reconnectSeconds);
93
94 if (error == CR_CONNECTION_ERROR)
95 {
96 reconnectCount++;
97 }
98 else
99 {
100 break;
101 }
102 }
103 }
104
105
106 if ((error == ER_BAD_DB_ERROR) && updatesEnabledForThis &&
_autoSetup)
107 {
108
110 {
111 error = 0;
112 }
113 }
114
115
116 if (error)
117 {
118 LOG_ERROR(
_logger,
"DatabasePool {} NOT opened. There were errors opening the MySQL connections. "
119 "Check your log file for specific errors", name);
120
121 return false;
122 }
123 }
124
126 {
128 });
129
130 return true;
131 });
132
133
134 if (updatesEnabledForThis)
135 {
136 _populate.push([
this, name, &pool]() ->
bool
137 {
139 {
140 LOG_ERROR(
_logger,
"Could not populate the {} database, see log for details.", name);
141 return false;
142 }
143
144 return true;
145 });
146
147 _update.push([
this, name, &pool]() ->
bool
148 {
150 {
151 LOG_ERROR(
_logger,
"Could not update the {} database, see log for details.", name);
152 return false;
153 }
154
155 return true;
156 });
157 }
158
159 _prepare.push([
this, name, &pool]() ->
bool
160 {
162 {
163 LOG_ERROR(
_logger,
"Could not prepare statements of the {} database, see log for details.", name);
164 return false;
165 }
166
167 return true;
168 });
169
170 return *this;
171}
std::uint8_t uint8
Definition Define.h:109
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition Duration.h:30
#define LOG_ERROR(filterType__,...)
Definition Log.h:158
#define LOG_WARN(filterType__,...)
Definition Log.h:162
Definition DBUpdater.h:69
static bool IsEnabled(uint32 const updateMask)
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
bool PrepareStatements()
Prepares all prepared statements.
Definition DatabaseWorkerPool.cpp:137
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