void ResponseTask::operator()() { Json::Value response; if (getDependencyCount() > _resultTaskIndex) { response = generateResponseJson(); } size_t status = 200; if (!_error_messages.empty()) { Json::Value errors; for (const auto& msg : _error_messages) { errors.append(Json::Value(msg)); } response["error"] = errors; status = 500; } LOG4CXX_DEBUG(_logger, response); Json::FastWriter fw; if (_group_commit) { io::GroupCommitter::getInstance().push( std::tuple<net::AbstractConnection*, size_t, std::string>(connection, status, fw.write(response))); } else { connection->respond(fw.write(response), status); } }
std::shared_ptr<PlanOperation> ResponseTask::getResultTask() { // FIXME not thread safe! if (getDependencyCount() > _resultTaskIndex) { return std::dynamic_pointer_cast<PlanOperation>(_dependencies[_resultTaskIndex]); } return nullptr; }
void ResponseTask::operator()() { epoch_t responseStart = get_epoch_nanoseconds(); Json::Value response; if (getDependencyCount() > 0) { PapiTracer pt; pt.addEvent("PAPI_TOT_CYC"); pt.start(); auto predecessor = getResultTask(); const auto& result = predecessor->getResultTable(); if (predecessor->getState() != OpFail) { if (result) { // Make header Json::Value json_header(Json::arrayValue); for (unsigned col = 0; col < result->columnCount(); ++col) { Json::Value colname(result->nameOfColumn(col)); json_header.append(colname); } // Copy the complete result response["real_size"] = result->size(); response["rows"] = generateRowsJson(result, _transmitLimit); response["header"] = json_header; } // Copy Performance Data Json::Value json_perf(Json::arrayValue); for (const auto & attr: performance_data) { Json::Value element; element["papi_event"] = Json::Value(attr->papiEvent); element["duration"] = Json::Value((Json::UInt64) attr->duration); element["data"] = Json::Value((Json::UInt64) attr->data); element["name"] = Json::Value(attr->name); element["id"] = Json::Value(attr->operatorId); element["startTime"] = Json::Value((double)(attr->startTime - queryStart) / 1000000); element["endTime"] = Json::Value((double)(attr->endTime - queryStart) / 1000000); element["executingThread"] = Json::Value(attr->executingThread); json_perf.append(element); } pt.stop(); Json::Value responseElement; responseElement["duration"] = Json::Value((Json::UInt64) pt.value("PAPI_TOT_CYC")); responseElement["name"] = Json::Value("ResponseTask"); responseElement["id"] = Json::Value("respond"); responseElement["startTime"] = Json::Value((double)(responseStart - queryStart) / 1000000); responseElement["endTime"] = Json::Value((double)(get_epoch_nanoseconds() - queryStart) / 1000000); std::string threadId = boost::lexical_cast<std::string>(std::this_thread::get_id()); responseElement["executingThread"] = Json::Value(threadId); json_perf.append(responseElement); response["performanceData"] = json_perf; } else { LOG4CXX_ERROR(_logger, "Error during plan execution: " << predecessor->getErrorMessage()); response["error"] = predecessor->getErrorMessage(); } LOG4CXX_DEBUG(_logger, "Table Use Count: " << result.use_count()); } else { response["error"] = "Query parsing failed, see server error log"; } connection->respond(response.toStyledString()); }
std::shared_ptr<_PlanOperation> ResponseTask::getResultTask() { if (getDependencyCount() > 0) { return std::dynamic_pointer_cast<_PlanOperation>(_dependencies[0]); } return nullptr; }