Skip to content

Commit e4fb3b4

Browse files
committed
Merge branch 'tickets/DM-50445'
2 parents 47a45e5 + e343196 commit e4fb3b4

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

src/ccontrol/UserQueryFactory.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ std::shared_ptr<UserQuery> _makeUserQueryProcessList(query::SelectStmt::Ptr& stm
133133
}
134134
LOGS(_log, LOG_LVL_DEBUG, "SELECT query is a PROCESSLIST");
135135
try {
136-
return std::make_shared<UserQueryProcessList>(stmt, sharedResources->resultDbConn.get(),
137-
sharedResources->qMetaSelect,
136+
return std::make_shared<UserQueryProcessList>(stmt, sharedResources->qMetaSelect,
138137
sharedResources->qMetaCzarId, userQueryId, resultDb);
139138
} catch (std::exception const& exc) {
140139
return std::make_shared<UserQueryInvalid>(exc.what());
@@ -411,8 +410,7 @@ UserQuery::Ptr UserQueryFactory::newUserQuery(std::string const& aQuery, std::st
411410
} else if (UserQueryType::isShowProcessList(query, full)) {
412411
LOGS(_log, LOG_LVL_DEBUG, "make UserQueryProcessList: full=" << (full ? 'y' : 'n'));
413412
try {
414-
return std::make_shared<UserQueryProcessList>(full, _userQuerySharedResources->resultDbConn.get(),
415-
_userQuerySharedResources->qMetaSelect,
413+
return std::make_shared<UserQueryProcessList>(full, _userQuerySharedResources->qMetaSelect,
416414
_userQuerySharedResources->qMetaCzarId, userQueryId,
417415
resultDb);
418416
} catch (std::exception const& exc) {

src/ccontrol/UserQueryProcessList.cc

+11-10
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@
3535
// Qserv headers
3636
#include "css/CssAccess.h"
3737
#include "css/CssError.h"
38+
#include "cconfig/CzarConfig.h"
3839
#include "qdisp/MessageStore.h"
3940
#include "qmeta/Exceptions.h"
4041
#include "qmeta/QMetaSelect.h"
4142
#include "query/FromList.h"
4243
#include "query/SelectStmt.h"
4344
#include "sql/SqlConnection.h"
45+
#include "sql/SqlConnectionFactory.h"
4446
#include "sql/SqlErrorObject.h"
4547
#include "sql/SqlBulkInsert.h"
4648
#include "sql/statement.h"
@@ -61,12 +63,10 @@ namespace lsst::qserv::ccontrol {
6163

6264
// Constructor
6365
UserQueryProcessList::UserQueryProcessList(std::shared_ptr<query::SelectStmt> const& statement,
64-
sql::SqlConnection* resultDbConn,
6566
std::shared_ptr<qmeta::QMetaSelect> const& qMetaSelect,
6667
qmeta::CzarId qMetaCzarId, std::string const& userQueryId,
6768
std::string const& resultDb)
68-
: _resultDbConn(resultDbConn),
69-
_qMetaSelect(qMetaSelect),
69+
: _qMetaSelect(qMetaSelect),
7070
_qMetaCzarId(qMetaCzarId),
7171
_messageStore(std::make_shared<qdisp::MessageStore>()),
7272
_resultTableName(::g_nextResultTableId(userQueryId)),
@@ -90,12 +90,10 @@ UserQueryProcessList::UserQueryProcessList(std::shared_ptr<query::SelectStmt> co
9090
}
9191
}
9292

93-
UserQueryProcessList::UserQueryProcessList(bool full, sql::SqlConnection* resultDbConn,
94-
std::shared_ptr<qmeta::QMetaSelect> const& qMetaSelect,
93+
UserQueryProcessList::UserQueryProcessList(bool full, std::shared_ptr<qmeta::QMetaSelect> const& qMetaSelect,
9594
qmeta::CzarId qMetaCzarId, std::string const& userQueryId,
9695
std::string const& resultDb)
97-
: _resultDbConn(resultDbConn),
98-
_qMetaSelect(qMetaSelect),
96+
: _qMetaSelect(qMetaSelect),
9997
_qMetaCzarId(qMetaCzarId),
10098
_messageStore(std::make_shared<qdisp::MessageStore>()),
10199
_resultTableName(::g_nextResultTableId(userQueryId)),
@@ -156,8 +154,11 @@ void UserQueryProcessList::submit() {
156154
if (col.colType.sqlType == "TIMESTAMP") createTable += " NULL";
157155
}
158156
createTable += ')';
157+
159158
LOGS(_log, LOG_LVL_DEBUG, "creating result table: " << createTable);
160-
if (!_resultDbConn->runQuery(createTable, errObj)) {
159+
auto const czarConfig = cconfig::CzarConfig::instance();
160+
auto const resultDbConn = sql::SqlConnectionFactory::make(czarConfig->getMySqlResultConfig());
161+
if (!resultDbConn->runQuery(createTable, errObj)) {
161162
LOGS(_log, LOG_LVL_ERROR, "failed to create result table: " << errObj.errMsg());
162163
std::string message = "Internal failure, failed to create result table: " + errObj.errMsg();
163164
_messageStore->addMessage(-1, "PROCESSLIST", 1051, message, MessageSeverity::MSG_ERROR);
@@ -172,7 +173,7 @@ void UserQueryProcessList::submit() {
172173
}
173174

174175
// copy stuff over to result table
175-
sql::SqlBulkInsert bulkInsert(_resultDbConn, _resultTableName, resColumns);
176+
sql::SqlBulkInsert bulkInsert(resultDbConn.get(), _resultTableName, resColumns);
176177
for (auto& row : *results) {
177178
std::vector<std::string> values;
178179
for (unsigned i = 0; i != row.size(); ++i) {
@@ -191,7 +192,7 @@ void UserQueryProcessList::submit() {
191192
values.push_back(std::string(ptr, ptr + len));
192193
} else {
193194
// everything else should be quoted
194-
values.push_back("'" + _resultDbConn->escapeString(std::string(ptr, ptr + len)) + "'");
195+
values.push_back("'" + resultDbConn->escapeString(std::string(ptr, ptr + len)) + "'");
195196
}
196197
}
197198

src/ccontrol/UserQueryProcessList.h

+3-11
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ namespace lsst::qserv::query {
4444
class SelectStmt;
4545
}
4646

47-
namespace lsst::qserv::sql {
48-
class SqlConnection;
49-
}
50-
5147
namespace lsst::qserv::ccontrol {
5248

5349
/// UserQueryProcessList : implementation of the UserQuery for SHOWPROCESS statements.
@@ -57,28 +53,25 @@ class UserQueryProcessList : public UserQuery {
5753
* Constructor for "SELECT ... FROM INFORMATION_SCHEMA.PROCESSLIST ...".
5854
*
5955
* @param statement: Parsed SELECT statement
60-
* @param resultDbConn: Connection to results database
6156
* @param qMetaSelect: QMetaSelect instance
6257
* @param qMetaCzarId: Czar ID for QMeta queries
6358
* @param userQueryId: Unique string identifying query
6459
*/
6560
UserQueryProcessList(std::shared_ptr<query::SelectStmt> const& statement,
66-
sql::SqlConnection* resultDbConn,
6761
std::shared_ptr<qmeta::QMetaSelect> const& qMetaSelect, qmeta::CzarId qMetaCzarId,
6862
std::string const& userQueryId, std::string const& resultDb);
6963

7064
/**
7165
* Constructor for "SHOW [FULL] PROCESSLIST".
7266
*
7367
* @param full: True if FULL is in query
74-
* @param resultDbConn: Connection to results database
7568
* @param qMetaSelect: QMetaSelect instance
7669
* @param qMetaCzarId: Czar ID for QMeta queries
7770
* @param userQueryId: Unique string identifying query
7871
*/
79-
UserQueryProcessList(bool full, sql::SqlConnection* resultDbConn,
80-
std::shared_ptr<qmeta::QMetaSelect> const& qMetaSelect, qmeta::CzarId qMetaCzarId,
81-
std::string const& userQueryId, std::string const& resultDb);
72+
UserQueryProcessList(bool full, std::shared_ptr<qmeta::QMetaSelect> const& qMetaSelect,
73+
qmeta::CzarId qMetaCzarId, std::string const& userQueryId,
74+
std::string const& resultDb);
8275

8376
UserQueryProcessList(UserQueryProcessList const&) = delete;
8477
UserQueryProcessList& operator=(UserQueryProcessList const&) = delete;
@@ -118,7 +111,6 @@ class UserQueryProcessList : public UserQuery {
118111
/// @return ORDER BY part of SELECT statement that gets executed by the proxy
119112
std::string _getResultOrderBy() const { return _orderBy; }
120113

121-
sql::SqlConnection* _resultDbConn;
122114
std::shared_ptr<qmeta::QMetaSelect> _qMetaSelect;
123115
qmeta::CzarId const _qMetaCzarId; ///< Czar ID in QMeta database
124116
QueryState _qState = UNKNOWN;

0 commit comments

Comments
 (0)