Central class for all backend execution state (example: the FragmentInstanceStates of the individual fragment instances) created for a particular query. This class contains or makes accessible state that is shared across fragment instances; in contrast, fragment instance-specific state is collected in FragmentInstanceState. The lifetime of a QueryState is dictated by a reference count. Any thread
| 120 | /// TODO: |
| 121 | /// - set up kudu clients in Init(), remove related locking |
| 122 | class QueryState { |
| 123 | public: |
| 124 | /// Stores information about which file is scheduled to which hosts. |
| 125 | struct FileSchedulingInfo { |
| 126 | std::string file_path; |
| 127 | std::vector<NetworkAddressPB> hosts; |
| 128 | bool is_relative_path; |
| 129 | |
| 130 | FileSchedulingInfo(const string& fn, bool is_rel) |
| 131 | : file_path(fn), is_relative_path(is_rel) {} |
| 132 | }; |
| 133 | |
| 134 | /// Stores information about which file is scheduled to which hosts, grouped by scan |
| 135 | /// node ID. |
| 136 | typedef std::unordered_map<int, std::vector<FileSchedulingInfo>> NodeToFileSchedulings; |
| 137 | |
| 138 | /// Use this class to obtain a QueryState for the duration of a function/block, |
| 139 | /// rather than manually via QueryExecMgr::Get-/ReleaseQueryState(). |
| 140 | /// Pattern: |
| 141 | /// { |
| 142 | /// QueryState::ScopedRef qs(qid); |
| 143 | /// if (qs->query_state() == nullptr) <do something, such as return> |
| 144 | /// ... |
| 145 | /// } |
| 146 | class ScopedRef { |
| 147 | public: |
| 148 | /// Looks up the query state with GetQueryState(). The query state is non-NULL if |
| 149 | /// the query was already registered. |
| 150 | ScopedRef(const TUniqueId& query_id); |
| 151 | ~ScopedRef(); |
| 152 | |
| 153 | /// may return nullptr |
| 154 | QueryState* get() const { return query_state_; } |
| 155 | QueryState* operator->() const { return query_state_; } |
| 156 | |
| 157 | private: |
| 158 | QueryState* query_state_; |
| 159 | DISALLOW_COPY_AND_ASSIGN(ScopedRef); |
| 160 | }; |
| 161 | |
| 162 | /// a shared pool for all objects that have query lifetime |
| 163 | ObjectPool* obj_pool() { return &obj_pool_; } |
| 164 | |
| 165 | const TQueryCtx& query_ctx() const { return query_ctx_; } |
| 166 | const TUniqueId& query_id() const { return query_ctx().query_id; } |
| 167 | const TQueryOptions& query_options() const { |
| 168 | return query_ctx_.client_request.query_options; |
| 169 | } |
| 170 | bool codegen_cache_enabled() const; |
| 171 | bool is_initialized(); |
| 172 | MemTracker* query_mem_tracker() const { return query_mem_tracker_; } |
| 173 | RuntimeProfile* host_profile() const { return host_profile_; } |
| 174 | const NodeToFileSchedulings* node_to_file_schedulings() const { |
| 175 | return &node_to_file_schedulings_; |
| 176 | } |
| 177 | UniqueIdPB GetCoordinatorBackendId() const; |
| 178 | |
| 179 | /// The following getters are only valid after Init(). |