OmniSciDB  d2f719934e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
query_state::QueryState Class Reference

#include <QueryState.h>

+ Inheritance diagram for query_state::QueryState:
+ Collaboration diagram for query_state::QueryState:

Public Member Functions

QueryStateProxy createQueryStateProxy ()
 
QueryStateProxy createQueryStateProxy (Events::iterator parent)
 
Timer createTimer (char const *event_name, Events::iterator parent)
 
bool emptyLog () const
 
logger::QueryId getId () const
 
std::string constgetQueryStr () const
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const
getConstSessionInfo () const
 
boost::optional< SessionData >
const
getSessionData () const
 
bool isLogged () const
 
void logCallStack (std::stringstream &)
 
logger::QidScopeGuard setThreadLocalQueryId () const
 
void setQuerySubmittedTime (const std::string &t)
 
const std::string getQuerySubmittedTime () const
 
void setLogged (bool logged)
 

Static Public Member Functions

template<typename... ARGS>
static std::shared_ptr
< QueryState
create (ARGS &&...args)
 

Private Member Functions

void logCallStack (std::stringstream &, unsigned const depth, Events::iterator parent)
 
 QueryState (std::shared_ptr< Catalog_Namespace::SessionInfo const > const &, std::string query_str)
 

Private Attributes

logger::QueryId const id_
 
boost::optional< SessionDatasession_data_
 
std::string const query_str_
 
Events events_
 
std::mutex events_mutex_
 
std::atomic< bool > logged_
 
std::string submitted_
 

Static Private Attributes

static std::atomic
< logger::QueryId
s_next_id {1}
 

Friends

class QueryStates
 

Detailed Description

Definition at line 128 of file QueryState.h.

Constructor & Destructor Documentation

query_state::QueryState::QueryState ( std::shared_ptr< Catalog_Namespace::SessionInfo const > const session_info,
std::string  query_str 
)
private

Definition at line 65 of file QueryState.cpp.

Referenced by create().

68  : id_(s_next_id++)
69  , session_data_(session_info ? boost::make_optional<SessionData>(session_info)
70  : boost::none)
71  , query_str_(std::move(query_str))
72  , logged_(false)
73  , submitted_(::toString(std::chrono::system_clock::now())) {}
boost::optional< SessionData > session_data_
Definition: QueryState.h:131
std::string toString(const ExtArgumentType &sig_type)
logger::QueryId const id_
Definition: QueryState.h:130
std::string submitted_
Definition: QueryState.h:136
std::string const query_str_
Definition: QueryState.h:132
static std::atomic< logger::QueryId > s_next_id
Definition: QueryState.h:129
std::atomic< bool > logged_
Definition: QueryState.h:135

+ Here is the caller graph for this function:

Member Function Documentation

template<typename... ARGS>
static std::shared_ptr<QueryState> query_state::QueryState::create ( ARGS &&...  args)
inlinestatic

Definition at line 145 of file QueryState.h.

References run_benchmark_import::args, and QueryState().

Referenced by query_state::QueryStates::create(), Parser::InsertIntoTableAsSelectStmt::execute(), Parser::CreateTableAsSelectStmt::execute(), Parser::ExportQueryStmt::execute(), and Parser::CreateViewStmt::execute().

145  {
146  // Trick to call std::make_shared with private constructors.
147  struct EnableMakeShared : public QueryState {
148  EnableMakeShared(ARGS&&... args) : QueryState(std::forward<ARGS>(args)...) {}
149  };
150  return std::make_shared<EnableMakeShared>(std::forward<ARGS>(args)...);
151  }
QueryState(std::shared_ptr< Catalog_Namespace::SessionInfo const > const &, std::string query_str)
Definition: QueryState.cpp:65

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QueryStateProxy query_state::QueryState::createQueryStateProxy ( )

Definition at line 75 of file QueryState.cpp.

References events_.

75  {
76  return createQueryStateProxy(events_.end());
77 }
QueryStateProxy createQueryStateProxy()
Definition: QueryState.cpp:75
QueryStateProxy query_state::QueryState::createQueryStateProxy ( Events::iterator  parent)

Definition at line 79 of file QueryState.cpp.

79  {
80  return QueryStateProxy(*this, parent);
81 }
Timer query_state::QueryState::createTimer ( char const event_name,
Events::iterator  parent 
)

Definition at line 83 of file QueryState.cpp.

References events_, and events_mutex_.

Referenced by query_state::QueryStateProxy::createTimer().

83  {
84  std::lock_guard<std::mutex> lock(events_mutex_);
85  return Timer(shared_from_this(), events_.emplace(events_.end(), event_name, parent));
86 }
std::mutex events_mutex_
Definition: QueryState.h:134

+ Here is the caller graph for this function:

bool query_state::QueryState::emptyLog ( ) const
inline

Definition at line 155 of file QueryState.h.

References events_, and query_str_.

155 { return events_.empty() && query_str_.empty(); }
std::string const query_str_
Definition: QueryState.h:132
std::shared_ptr< Catalog_Namespace::SessionInfo const > query_state::QueryState::getConstSessionInfo ( ) const

Definition at line 88 of file QueryState.cpp.

References session_data_.

Referenced by Calcite::checkAccessedObjectsPrivileges(), DBHandler::execute_rel_alg(), DBHandler::execute_rel_alg_df(), Parser::LocalConnector::getOuterFragmentCount(), DBHandler::parse_to_ra(), Parser::InsertIntoTableAsSelectStmt::populateData(), Calcite::processImpl(), Parser::LocalConnector::query(), and DBHandler::sql_execute_impl().

89  {
90  if (!session_data_) {
91  throw std::runtime_error("session_info_ was not set for this QueryState.");
92  }
93  if (auto retval = session_data_->session_info.lock()) {
94  return retval;
95  } else {
96  // This can happen for a query on a database that is simultaneously dropped.
97  throw std::runtime_error("session_info requested but has expired.");
98  }
99 }
boost::optional< SessionData > session_data_
Definition: QueryState.h:131

+ Here is the caller graph for this function:

logger::QueryId query_state::QueryState::getId ( ) const
inline

Definition at line 156 of file QueryState.h.

References id_.

156 { return id_; }
logger::QueryId const id_
Definition: QueryState.h:130
std::string const& query_state::QueryState::getQueryStr ( ) const
inline

Definition at line 157 of file QueryState.h.

References query_str_.

Referenced by DBHandler::execute_rel_alg_with_filter_push_down(), and DBHandler::sql_execute_impl().

157 { return query_str_; }
std::string const query_str_
Definition: QueryState.h:132

+ Here is the caller graph for this function:

const std::string query_state::QueryState::getQuerySubmittedTime ( ) const

Definition at line 105 of file QueryState.cpp.

References events_mutex_, and submitted_.

Referenced by Parser::InsertIntoTableAsSelectStmt::populateData(), Parser::LocalConnector::query(), and DBHandler::sql_execute_impl().

105  {
106  std::lock_guard<std::mutex> lock(events_mutex_);
107  return submitted_;
108 }
std::string submitted_
Definition: QueryState.h:136
std::mutex events_mutex_
Definition: QueryState.h:134

+ Here is the caller graph for this function:

boost::optional<SessionData> const& query_state::QueryState::getSessionData ( ) const
inline

Definition at line 160 of file QueryState.h.

References session_data_.

160 { return session_data_; }
boost::optional< SessionData > session_data_
Definition: QueryState.h:131
bool query_state::QueryState::isLogged ( ) const
inline

Definition at line 161 of file QueryState.h.

References logged_.

161 { return logged_.load(); }
std::atomic< bool > logged_
Definition: QueryState.h:135
void query_state::QueryState::logCallStack ( std::stringstream &  ss,
unsigned const  depth,
Events::iterator  parent 
)
private

Definition at line 116 of file QueryState.cpp.

References events_.

Referenced by logCallStack().

118  {
119  auto it = parent == events_.end() ? events_.begin() : std::next(parent);
120  for (; it != events_.end(); ++it) {
121  if (it->parent == parent) {
122  auto duration = it->duration(); // std::optional, true if event completed
123  ss << '\n'
124  << std::setw(depth << 1) << ' ' << it->name << ' ' << it->thread_id
125  << " - total time " << (duration ? *duration : -1) << " ms";
126  logCallStack(ss, depth + 1, it);
127  // If events_ is expendable, then this can be put here to speed-up large lists.
128  // it = events_.erase(it); } else { ++it; } (and remove above ++it.)
129  }
130  }
131 }
void logCallStack(std::stringstream &, unsigned const depth, Events::iterator parent)
Definition: QueryState.cpp:116

+ Here is the caller graph for this function:

void query_state::QueryState::logCallStack ( std::stringstream &  ss)

Definition at line 133 of file QueryState.cpp.

References events_, events_mutex_, and logCallStack().

133  {
134  std::lock_guard<std::mutex> lock(events_mutex_);
135  logCallStack(ss, 1, events_.end());
136 }
void logCallStack(std::stringstream &, unsigned const depth, Events::iterator parent)
Definition: QueryState.cpp:116
std::mutex events_mutex_
Definition: QueryState.h:134

+ Here is the call graph for this function:

void query_state::QueryState::setLogged ( bool  logged)
inline

Definition at line 167 of file QueryState.h.

References logged_.

167 { logged_.store(logged); }
std::atomic< bool > logged_
Definition: QueryState.h:135
void query_state::QueryState::setQuerySubmittedTime ( const std::string &  t)

Definition at line 101 of file QueryState.cpp.

References events_mutex_, submitted_, and t.

101  {
102  std::lock_guard<std::mutex> lock(events_mutex_);
103  submitted_ = t;
104 }
std::string submitted_
Definition: QueryState.h:136
char * t
std::mutex events_mutex_
Definition: QueryState.h:134
logger::QidScopeGuard query_state::QueryState::setThreadLocalQueryId ( ) const

Definition at line 111 of file QueryState.cpp.

References id_, and logger::set_thread_local_query_id().

111  {
113 }
QidScopeGuard set_thread_local_query_id(QueryId const query_id)
Definition: Logger.cpp:483
logger::QueryId const id_
Definition: QueryState.h:130

+ Here is the call graph for this function:

Friends And Related Function Documentation

friend class QueryStates
friend

Definition at line 168 of file QueryState.h.

Member Data Documentation

Events query_state::QueryState::events_
private

Definition at line 133 of file QueryState.h.

Referenced by createQueryStateProxy(), createTimer(), emptyLog(), and logCallStack().

std::mutex query_state::QueryState::events_mutex_
mutableprivate
logger::QueryId const query_state::QueryState::id_
private

Definition at line 130 of file QueryState.h.

Referenced by getId(), and setThreadLocalQueryId().

std::atomic<bool> query_state::QueryState::logged_
private

Definition at line 135 of file QueryState.h.

Referenced by isLogged(), and setLogged().

std::string const query_state::QueryState::query_str_
private

Definition at line 132 of file QueryState.h.

Referenced by emptyLog(), and getQueryStr().

std::atomic< logger::QueryId > query_state::QueryState::s_next_id {1}
staticprivate

Definition at line 129 of file QueryState.h.

boost::optional<SessionData> query_state::QueryState::session_data_
private

Definition at line 131 of file QueryState.h.

Referenced by getConstSessionInfo(), and getSessionData().

std::string query_state::QueryState::submitted_
private

Definition at line 136 of file QueryState.h.

Referenced by getQuerySubmittedTime(), and setQuerySubmittedTime().


The documentation for this class was generated from the following files: