Skip to content

Commit b581b6a

Browse files
committed
Fixed a bug in an implementation of the query status reporting method
The older version of the method didn't return the complete info on queries that already finished. The new code uses the final query statistics where it's needed.
1 parent 23546a7 commit b581b6a

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/czar/Czar.cc

+24-7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ using namespace std;
7272

7373
extern XrdSsiProvider* XrdSsiProviderClient;
7474

75+
// This macro is used to convert empty strings into "0" in order to avoid
76+
// problems with calling std::atoi() when the string is empty.
77+
#define ZERO_IF_EMPTY_STR(x) ((x.empty()) ? "0" : (x))
78+
7579
namespace {
7680

7781
string const createAsyncResultTmpl(
@@ -548,7 +552,12 @@ void Czar::removeOldResultTables() {
548552
SubmitResult Czar::getQueryInfo(QueryId queryId) const {
549553
string const context = "Czar::" + string(__func__) + " ";
550554
auto sqlConn = sql::SqlConnectionFactory::make(_czarConfig->getMySqlQmetaConfig());
551-
string sql = "SELECT status,messageTable,resultQuery FROM QInfo WHERE queryId=" + to_string(queryId);
555+
string sql =
556+
"SELECT "
557+
"status,UNIX_TIMESTAMP(submitted),UNIX_TIMESTAMP(completed),chunkCount,messageTable,resultQuery "
558+
"FROM QInfo WHERE "
559+
"queryId=" +
560+
to_string(queryId);
552561
sql::SqlResults results;
553562
sql::SqlErrorObject err;
554563
if (!sqlConn->runQuery(sql, results, err)) {
@@ -558,9 +567,13 @@ SubmitResult Czar::getQueryInfo(QueryId queryId) const {
558567
throw runtime_error(msg);
559568
}
560569
vector<string> colStatus;
570+
vector<string> colSubmitted;
571+
vector<string> colCompleted;
572+
vector<string> colChunkCount;
561573
vector<string> colMessageTable;
562574
vector<string> colResultQuery;
563-
if (!results.extractFirst3Columns(colStatus, colMessageTable, colResultQuery, err)) {
575+
if (!results.extractFirst6Columns(colStatus, colSubmitted, colCompleted, colChunkCount, colMessageTable,
576+
colResultQuery, err)) {
564577
string const msg = context + "Failed to extract info for the user query, err=" + err.printErrMsg() +
565578
", sql=" + sql;
566579
throw runtime_error(msg);
@@ -606,14 +619,18 @@ SubmitResult Czar::getQueryInfo(QueryId queryId) const {
606619
}
607620
switch (colTotalChunks.size()) {
608621
case 0:
609-
// No stats means the query is over
622+
// No stats means the query is over. Pull the final stats from the main table.
623+
result.totalChunks = stoi(ZERO_IF_EMPTY_STR(colChunkCount[0]));
624+
result.completedChunks = result.totalChunks;
625+
result.queryBeginEpoch = stoi(ZERO_IF_EMPTY_STR(colSubmitted[0]));
626+
result.lastUpdateEpoch = stoi(ZERO_IF_EMPTY_STR(colCompleted[0]));
610627
break;
611628
case 1:
612629
// The query might be still in progress
613-
result.totalChunks = stoi(colTotalChunks[0]);
614-
result.completedChunks = stoi(colCompletedChunks[0]);
615-
result.queryBeginEpoch = stoi(colQueryBeginEpoch[0]);
616-
result.lastUpdateEpoch = stoi(colLastUpdateEpoch[0]);
630+
result.totalChunks = stoi(ZERO_IF_EMPTY_STR(colTotalChunks[0]));
631+
result.completedChunks = stoi(ZERO_IF_EMPTY_STR(colCompletedChunks[0]));
632+
result.queryBeginEpoch = stoi(ZERO_IF_EMPTY_STR(colQueryBeginEpoch[0]));
633+
result.lastUpdateEpoch = stoi(ZERO_IF_EMPTY_STR(colLastUpdateEpoch[0]));
617634
break;
618635
default:
619636
// Should never be here.

0 commit comments

Comments
 (0)