Skip to content

Commit 1856030

Browse files
committed
Rebase fixes.
1 parent 0baa2a7 commit 1856030

28 files changed

Lines changed: 613 additions & 152 deletions

src/ccontrol/MergingHandler.cc

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "lsst/log/Log.h"
4040

4141
// Qserv headers
42+
#include "cconfig/CzarConfig.h"
4243
#include "ccontrol/msgCode.h"
4344
#include "global/clock_defs.h"
4445
#include "global/debugUtil.h"
@@ -49,7 +50,6 @@
4950
#include "qdisp/CzarStats.h"
5051
#include "qdisp/Executive.h"
5152
#include "qdisp/JobQuery.h"
52-
#include "qdisp/QueryRequest.h"
5353
#include "qdisp/UberJob.h"
5454
#include "rproc/InfileMerger.h"
5555
#include "util/Bug.h"
@@ -84,7 +84,6 @@ lsst::qserv::TimeCountTracker<double>::CALLBACKFUNC const reportFileRecvRate =
8484
}
8585
};
8686

87-
8887
string readHttpFileAndMerge(lsst::qserv::qdisp::UberJob::Ptr const& uberJob, string const& httpUrl,
8988
size_t fileSize, function<void(char const*, uint32_t)> const& messageIsReady,
9089
shared_ptr<http::ClientConnPool> const& httpConnPool) {
@@ -180,52 +179,6 @@ MergingHandler::MergingHandler(std::shared_ptr<rproc::InfileMerger> const& merge
180179

181180
MergingHandler::~MergingHandler() { LOGS(_log, LOG_LVL_TRACE, __func__); }
182181

183-
184-
bool MergingHandler::flush(proto::ResponseSummary const& resp) {
185-
_wName = resp.wname();
186-
187-
// This is needed to ensure the job query would be staying alive for the duration
188-
// of the operation to prevent inconsistency within the application.
189-
auto const jobQuery = getJobQuery().lock();
190-
if (jobQuery == nullptr) {
191-
LOGS(_log, LOG_LVL_ERROR, __func__ << " failed, jobQuery was NULL");
192-
return false;
193-
}
194-
auto const jobQuery = std::dynamic_pointer_cast<qdisp::JobQuery>(jobBase);
195-
196-
LOGS(_log, LOG_LVL_TRACE,
197-
"MergingHandler::" << __func__ << " jobid=" << resp.jobid() << " transmitsize="
198-
<< resp.transmitsize() << " rowcount=" << resp.rowcount() << " rowSize="
199-
<< " attemptcount=" << resp.attemptcount() << " errorcode=" << resp.errorcode()
200-
<< " errormsg=" << resp.errormsg());
201-
202-
if (resp.errorcode() != 0 || !resp.errormsg().empty()) {
203-
_error = util::Error(resp.errorcode(), resp.errormsg(), util::ErrorCode::MYSQLEXEC);
204-
_setError(ccontrol::MSG_RESULT_ERROR, _error.getMsg());
205-
LOGS(_log, LOG_LVL_ERROR,
206-
"MergingHandler::" << __func__ << " error from worker:" << resp.wname() << " error: " << _error);
207-
// This way we can track if the worker has reported this error. The current implementation
208-
// requires the large result size to be reported as an error via the InfileMerger regardless
209-
// of an origin of the error (Czar or the worker). Note that large results can be produced
210-
// by the Czar itself, e.g., when the aggregate result of multiple worker queries is too large
211-
// or by the worker when the result set of a single query is too large.
212-
// The error will be reported to the Czar as a part of the response summary.
213-
if (resp.errorcode() == util::ErrorCode::WORKER_RESULT_TOO_LARGE) {
214-
_infileMerger->setResultSizeLimitExceeded();
215-
}
216-
return false;
217-
}
218-
219-
bool const success = _merge(resp, jobQuery);
220-
221-
if (success) {
222-
_infileMerger->mergeCompleteFor(resp.jobid());
223-
qdisp::CzarStats::get()->addTotalRowsRecv(resp.rowcount());
224-
qdisp::CzarStats::get()->addTotalBytesRecv(resp.transmitsize());
225-
}
226-
return success;
227-
}
228-
229182
void MergingHandler::errorFlush(std::string const& msg, int code) {
230183
_setError(code, msg, util::ErrorCode::RESULT_IMPORT);
231184
// Might want more info from result service.

src/ccontrol/MergingHandler.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,13 @@ class MergingHandler : public qdisp::ResponseHandler {
9191
/// Set error code and string.
9292
void _setError(int code, std::string const& msg, int errorState);
9393

94-
/// Check if the query is no longer active.
95-
/// This is used to prevent the query from being processed after it has been cancelled
96-
/// or finished for any reason.
97-
/// @param jobQuery the query to check
98-
/// @return true if the query is no longer active
99-
bool _queryIsNoLongerActive(std::shared_ptr<qdisp::JobQuery> const& jobQuery) const;
94+
// All instances of the HTTP client class are members of the same pool. This allows
95+
// connection reuse and a significant reduction of the kernel memory pressure.
96+
// Note that the pool gets instantiated at the very first call to method _getHttpConnPool()
97+
// because the instantiation depends on the availability of the Czar configuration.
98+
static std::shared_ptr<http::ClientConnPool> const& _getHttpConnPool();
99+
static std::shared_ptr<http::ClientConnPool> _httpConnPool;
100+
static std::mutex _httpConnPoolMutex;
100101

101102
std::shared_ptr<rproc::InfileMerger> _infileMerger; ///< Merging delegate
102103
std::atomic<bool> _errorSet{false}; ///< Set to true when an error is set.

src/ccontrol/UserQueryFactory.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "qmeta/QMetaMysql.h"
6060
#include "qmeta/QMetaSelect.h"
6161
#include "qmeta/QProgress.h"
62+
#include "qmeta/QProgressHistory.h"
6263
#include "qproc/DatabaseModels.h"
6364
#include "qproc/QuerySession.h"
6465
#include "qproc/SecondaryIndex.h"
@@ -134,7 +135,7 @@ std::shared_ptr<UserQuery> _makeUserQueryProcessList(query::SelectStmt::Ptr& stm
134135
LOGS(_log, LOG_LVL_DEBUG, "SELECT query is a PROCESSLIST");
135136
try {
136137
return std::make_shared<UserQueryProcessList>(stmt, sharedResources->qMetaSelect,
137-
sharedResources->qMetaCzarId, userQueryId, resultDb);
138+
sharedResources->czarId, userQueryId, resultDb);
138139
} catch (std::exception const& exc) {
139140
return std::make_shared<UserQueryInvalid>(exc.what());
140141
}
@@ -215,6 +216,7 @@ std::shared_ptr<UserQuerySharedResources> makeUserQuerySharedResources(
215216
std::make_shared<qmeta::QMetaMysql>(czarConfig->getMySqlQmetaConfig(),
216217
czarConfig->getMaxMsgSourceStore()),
217218
std::make_shared<qmeta::QProgress>(czarConfig->getMySqlQStatusDataConfig()),
219+
qmeta::QProgressHistory::create(czarConfig->getMySqlQStatusDataConfig()),
218220
std::make_shared<qmeta::QMetaSelect>(czarConfig->getMySqlQmetaConfig()), dbModels, czarName,
219221
czarConfig->getInteractiveChunkLimit());
220222
}
@@ -352,9 +354,10 @@ UserQuery::Ptr UserQueryFactory::newUserQuery(std::string const& aQuery, std::st
352354
std::shared_ptr<qdisp::Executive> executive;
353355
std::shared_ptr<rproc::InfileMergerConfig> infileMergerConfig;
354356
if (sessionValid) {
355-
executive =
356-
qdisp::Executive::create(_qmetaSecondsBetweenUpdates, messageStore, qdispPool,
357-
_userQuerySharedResources->queryStatsData, qs, _asioIoService);
357+
executive = qdisp::Executive::create(_qmetaSecondsBetweenUpdates, messageStore, qdispPool,
358+
_userQuerySharedResources->queryProgress,
359+
_userQuerySharedResources->queryProgressHistory, qs,
360+
_asioIoService);
358361
infileMergerConfig =
359362
std::make_shared<rproc::InfileMergerConfig>(_userQuerySharedResources->mysqlResultConfig);
360363
infileMergerConfig->debugNoMerge = _debugNoMerge;
@@ -369,7 +372,8 @@ UserQuery::Ptr UserQueryFactory::newUserQuery(std::string const& aQuery, std::st
369372
qs, messageStore, executive, _userQuerySharedResources->databaseModels, infileMergerConfig,
370373
_userQuerySharedResources->secondaryIndex, _userQuerySharedResources->queryMetadata,
371374
_userQuerySharedResources->queryProgress, _userQuerySharedResources->czarId, errorExtra,
372-
async, resultDb);
375+
async, resultDb, uberJobMaxChunks);
376+
373377
if (sessionValid) {
374378
uq->qMetaRegister(resultLocation, msgTableName);
375379
uq->setupMerger();

src/ccontrol/UserQueryProcessList.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ UserQueryProcessList::UserQueryProcessList(std::shared_ptr<query::SelectStmt> co
6767
qmeta::CzarId czarId, std::string const& userQueryId,
6868
std::string const& resultDb)
6969
: _qMetaSelect(qMetaSelect),
70-
_qMetaCzarId(qMetaCzarId),
70+
_czarId(czarId),
7171
_messageStore(std::make_shared<qmeta::MessageStore>()),
7272
_resultTableName(::g_nextResultTableId(userQueryId)),
7373
_resultDb(resultDb) {
@@ -94,7 +94,7 @@ UserQueryProcessList::UserQueryProcessList(bool full, std::shared_ptr<qmeta::QMe
9494
qmeta::CzarId czarId, std::string const& userQueryId,
9595
std::string const& resultDb)
9696
: _qMetaSelect(qMetaSelect),
97-
_qMetaCzarId(qMetaCzarId),
97+
_czarId(czarId),
9898
_messageStore(std::make_shared<qmeta::MessageStore>()),
9999
_resultTableName(::g_nextResultTableId(userQueryId)),
100100
_resultDb(resultDb) {

src/ccontrol/UserQueryResources.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ UserQuerySharedResources::UserQuerySharedResources(
3636
std::shared_ptr<qproc::SecondaryIndex> const& secondaryIndex_,
3737
std::shared_ptr<qmeta::QMeta> const& queryMetadata_,
3838
std::shared_ptr<qmeta::QProgress> const& queryProgress_,
39+
std::shared_ptr<qmeta::QProgressHistory> const& queryProgressHistory_,
3940
std::shared_ptr<qmeta::QMetaSelect> const& qMetaSelect_,
4041
std::shared_ptr<qproc::DatabaseModels> const& dbModels_, std::string const& czarName,
4142
int interactiveChunkLimit_)
@@ -44,6 +45,7 @@ UserQuerySharedResources::UserQuerySharedResources(
4445
secondaryIndex(secondaryIndex_),
4546
queryMetadata(queryMetadata_),
4647
queryProgress(queryProgress_),
48+
queryProgressHistory(queryProgressHistory_),
4749
qMetaSelect(qMetaSelect_),
4850
databaseModels(dbModels_),
4951
interactiveChunkLimit(interactiveChunkLimit_) {

src/ccontrol/UserQueryResources.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace lsst::qserv::qmeta {
4646
class QMeta;
4747
class QMetaSelect;
4848
class QProgress;
49+
class QProgressHistory;
4950
} // namespace lsst::qserv::qmeta
5051

5152
namespace lsst::qserv::qproc {
@@ -66,6 +67,7 @@ class UserQuerySharedResources {
6667
std::shared_ptr<qproc::SecondaryIndex> const& secondaryIndex_,
6768
std::shared_ptr<qmeta::QMeta> const& queryMetadata_,
6869
std::shared_ptr<qmeta::QProgress> const& queryProgress_,
70+
std::shared_ptr<qmeta::QProgressHistory> const& queryProgressHistory_,
6971
std::shared_ptr<qmeta::QMetaSelect> const& qMetaSelect_,
7072
std::shared_ptr<qproc::DatabaseModels> const& databaseModels_,
7173
std::string const& czarName, int interactiveChunkLimit_);
@@ -78,6 +80,7 @@ class UserQuerySharedResources {
7880
std::shared_ptr<qproc::SecondaryIndex> secondaryIndex;
7981
std::shared_ptr<qmeta::QMeta> queryMetadata;
8082
std::shared_ptr<qmeta::QProgress> queryProgress;
83+
std::shared_ptr<qmeta::QProgressHistory> queryProgressHistory;
8184
std::shared_ptr<qmeta::QMetaSelect> qMetaSelect;
8285
std::shared_ptr<qproc::DatabaseModels> databaseModels;
8386
qmeta::CzarId czarId; ///< Czar ID in QMeta database

src/ccontrol/UserQueryResultDelete.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include "cconfig/CzarConfig.h"
4040
#include "qmeta/Exceptions.h"
4141
#include "qmeta/QMeta.h"
42-
#include "qdisp/MessageStore.h"
42+
#include "qmeta/MessageStore.h"
4343
#include "sql/SqlConnection.h"
4444
#include "sql/SqlConnectionFactory.h"
4545
#include "sql/SqlErrorObject.h"
@@ -57,7 +57,7 @@ namespace lsst::qserv::ccontrol {
5757

5858
UserQueryResultDelete::UserQueryResultDelete(shared_ptr<UserQueryResources> const& queryResources,
5959
string const& value)
60-
: _value(value), _queryResources(queryResources), _messageStore(make_shared<qdisp::MessageStore>()) {}
60+
: _value(value), _queryResources(queryResources), _messageStore(make_shared<qmeta::MessageStore>()) {}
6161

6262
void UserQueryResultDelete::submit() {
6363
LOGS(_log, LOG_LVL_DEBUG, "UserQueryResultDelete::submit: " << _value);

src/ccontrol/UserQuerySelect.cc

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void UserQuerySelect::submit() {
241241
LOGS(_log, LOG_LVL_DEBUG, "UserQuerySelect beginning submission");
242242
assert(_infileMerger);
243243

244-
_ttn = std::make_shared<TmpTableName>(_qMetaQueryId, _qSession->getOriginal());
244+
_ttn = std::make_shared<TmpTableName>(_queryId, _qSession->getOriginal());
245245
std::vector<int> chunks;
246246
std::mutex chunksMtx;
247247
JobId sequence = 0;
@@ -269,10 +269,7 @@ void UserQuerySelect::submit() {
269269
++i) {
270270
auto& chunkSpec = *i;
271271

272-
std::function<void(util::CmdData*)> funcBuildJob = [this, sequence, // sequence must be a copy
273-
&chunkSpec, &queryTemplates, &ttn,
274-
&taskMsgFactory](util::CmdData*) {
275-
QSERV_LOGCONTEXT_QUERY(_queryId);
272+
QSERV_LOGCONTEXT_QUERY(_queryId);
276273

277274
// TODO:UJ The template(s) is generated here and later it is compared to other
278275
// templates. It would be better to create the list of query templates here
@@ -299,7 +296,7 @@ void UserQuerySelect::submit() {
299296
ResourceUnit ru;
300297
ru.setAsDbChunk(cs->db, cs->chunkId);
301298
qdisp::JobDescription::Ptr jobDesc =
302-
qdisp::JobDescription::create(_qMetaCzarId, exec->getId(), sequence, ru, cs);
299+
qdisp::JobDescription::create(_czarId, exec->getId(), sequence, ru, cs);
303300
auto job = exec->add(jobDesc);
304301
++sequence;
305302
}
@@ -312,17 +309,11 @@ void UserQuerySelect::submit() {
312309
LOGS(_log, LOG_LVL_DEBUG, "total jobs in query=" << sequence);
313310
// TODO:UJ Waiting for all jobs to start may not be needed anymore?
314311
exec->waitForAllJobsToStart();
315-
316-
// we only care about per-chunk info for ASYNC queries
317-
if (_async) {
318-
std::lock_guard<std::mutex> lock(chunksMtx);
319-
_qMetaAddChunks(chunks);
320-
}
321312
}
322313

323314
void UserQuerySelect::buildAndSendUberJobs() {
324315
// TODO:UJ Is special handling needed for the dummy chunk, 1234567890 ?
325-
string const funcN("UserQuerySelect::" + string(__func__) + " QID=" + to_string(_qMetaQueryId));
316+
string const funcN("UserQuerySelect::" + string(__func__) + " QID=" + to_string(_queryId));
326317
LOGS(_log, LOG_LVL_DEBUG, funcN << " start " << _uberJobMaxChunks);
327318

328319
// Ensure `_monitor()` doesn't do anything until everything is ready.
@@ -473,8 +464,7 @@ void UserQuerySelect::buildAndSendUberJobs() {
473464
string uberResultName = _ttn->make(ujId);
474465
auto respHandler =
475466
ccontrol::MergingHandler::Ptr(new ccontrol::MergingHandler(_infileMerger, exec));
476-
auto uJob = qdisp::UberJob::create(exec, respHandler, exec->getId(), ujId, _qMetaCzarId,
477-
targetWorker);
467+
auto uJob = qdisp::UberJob::create(exec, respHandler, exec->getId(), ujId, _czarId, targetWorker);
478468
uJob->setWorkerContactInfo(wInfUJ->wInf);
479469
wInfUJ->uberJobPtr = uJob;
480470
};
@@ -574,7 +564,6 @@ QueryState UserQuerySelect::join() {
574564
auto const status = resultSizeLimitExceeded ? qmeta::QInfo::FAILED_LR : qmeta::QInfo::FAILED;
575565
_qMetaUpdateStatus(status, collectedRows, collectedBytes, finalRows);
576566
LOGS(_log, LOG_LVL_ERROR, "Joined everything (failure!) QID=" << getQueryId());
577-
operation = proto::QueryManagement::CANCEL;
578567
state = ERROR;
579568
}
580569
auto const czarConfig = cconfig::CzarConfig::instance();
@@ -807,7 +796,7 @@ void UserQuerySelect::qMetaRegister(std::string const& resultLocation, std::stri
807796

808797
auto exec = _executive;
809798
if (exec != nullptr) {
810-
exec->setQueryId(_qMetaQueryId);
799+
exec->setQueryId(_queryId);
811800
} else {
812801
LOGS(_log, LOG_LVL_WARN, "No Executive, assuming invalid query");
813802
}

src/ccontrol/UserQuerySelectCountStar.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ UserQuerySelectCountStar::UserQuerySelectCountStar(std::string query,
6262
: _qMetaSelect(qMetaSelect),
6363
_queryMetadata(queryMetadata),
6464
_messageStore(std::make_shared<qmeta::MessageStore>()),
65-
_resultTableName(::g_nextResultTableId(userQueryId)),
65+
//&&&_resultTableName(::g_nextResultTableId(userQueryId)),
6666
_userQueryId(userQueryId),
6767
_rowsTable(rowsTable),
6868
_resultDb(resultDb),

src/ccontrol/UserQuerySelectCountStar.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ class UserQuerySelectCountStar : public UserQuery {
119119
std::shared_ptr<qmeta::MessageStore> _messageStore;
120120
std::string _resultTable;
121121
std::string _resultLoc; ///< Result location
122-
std::string _resultTableName;
123122
std::string _userQueryId;
124123
std::string _rowsTable;
125124
std::string _resultDb;

0 commit comments

Comments
 (0)