21 #include <boost/algorithm/string/join.hpp>
22 #include <gutil/strings/substitute.h>
64 RuntimeState::RuntimeState(
const TPlanFragmentInstanceCtx& fragment_instance_ctx,
65 const string& cgroup, ExecEnv* exec_env)
67 fragment_instance_ctx_(fragment_instance_ctx),
68 now_(
new TimestampValue(fragment_instance_ctx_.query_ctx.now_string.c_str(),
69 fragment_instance_ctx_.query_ctx.now_string.size())),
72 "Fragment " +
PrintId(fragment_instance_ctx_.fragment_instance_id)),
74 query_resource_mgr_(NULL),
76 Status status = Init(exec_env);
77 DCHECK(status.ok()) << status.GetDetail();
80 RuntimeState::RuntimeState(
const TQueryCtx& query_ctx)
83 query_ctx.now_string.size())),
87 query_resource_mgr_(NULL),
97 typedef boost::unordered_map<SlotId, Bitmap*>::iterator SlotBitmapIterator;
100 if (it->second != NULL) {
129 if (query_options.max_errors <= 0) {
132 query_options.max_errors = 100;
134 if (query_options.batch_size <= 0) {
139 if (exec_env != NULL) {
153 int64_t query_bytes_limit, int64_t query_rm_reservation_limit_bytes) {
155 if (pool_name != NULL) {
157 query_parent_tracker);
171 if (block_mgr_limit < 0) block_mgr_limit = numeric_limits<int64_t>::max();
174 if (block_mgr_limit < 0) block_mgr_limit = 0;
178 LOG(ERROR) <<
"Block mgr mem limit: "
193 codegen_->EnableOptimizations(
true);
221 file_errors_.push_back(make_pair(file_name, num_errors));
241 BOOST_FOREACH(ErrorLogMap::value_type v,
error_log_) {
242 v.second.messages.clear();
248 int64_t failed_allocation_size) {
249 DCHECK_GE(failed_allocation_size, 0);
261 ss <<
"Memory Limit Exceeded\n";
262 if (failed_allocation_size != 0) {
263 DCHECK_NOTNULL(tracker);
264 ss <<
" " << tracker->
label() <<
" could not allocate "
266 <<
" without exceeding limit." << endl;
276 if (!
query_ctx().__isset.parent_query_id &&
277 query_ctx().__isset.tables_missing_stats &&
278 !
query_ctx().tables_missing_stats.empty()) {
295 bool* acquired_ownership) {
296 *acquired_ownership =
false;
297 if (bitmap != NULL) {
301 DCHECK_NOTNULL(existing_bitmap);
302 existing_bitmap->
And(bitmap);
307 *acquired_ownership =
true;
boost::shared_ptr< MemTracker > query_mem_tracker_
static boost::shared_ptr< MemTracker > GetQueryMemTracker(const TUniqueId &id, int64_t byte_limit, int64_t rm_reserved_limit, MemTracker *parent, QueryResourceMgr *res_mgr)
const std::string & msg() const
Returns the formatted error string.
string GetTablesMissingStatsWarning(const vector< TTableName > &tables_missing_stats)
static Status LoadImpalaIR(ObjectPool *, const std::string &id, boost::scoped_ptr< LlvmCodeGen > *codegen)
void And(const Bitmap *src)
Bitwise ANDs the src bitmap into this one.
string PrintErrorMapToString(const ErrorLogMap &errors)
boost::shared_ptr< BufferedBlockMgr > block_mgr_
RuntimeProfile::Counter * total_storage_wait_timer_
Total time waiting in storage (across all threads)
const TUniqueId & query_id() const
const std::string & label() const
std::string ErrorLog()
Returns the error log lines as a string joined with ' '.
boost::scoped_ptr< ObjectPool > obj_pool_
Object pool owned by the coordinator. Any executor will have its own pool.
void InitMemTrackers(const TUniqueId &query_id, const std::string *request_pool, int64_t query_bytes_limit, int64_t query_rm_reservation_limit_bytes=-1)
const TUniqueId & query_id() const
boost::scoped_ptr< ObjectPool > obj_pool_
RuntimeProfile * runtime_profile()
Returns runtime state profile.
#define RETURN_IF_ERROR(stmt)
some generally useful macros
ResourcePool * RegisterPool()
void GetUnreportedErrors(ErrorLogMap *new_errors)
SpinLock query_status_lock_
#define ADD_TIMER(profile, name)
MemTracker * query_mem_tracker()
Status Init(ExecEnv *exec_env)
Set per-fragment state.
string PrintId(const TUniqueId &id, const string &separator)
SpinLock error_log_lock_
Lock protecting error_log_ and unreported_error_idx_.
static std::string Print(bool value, TUnit::type ignored, bool verbose=false)
void AddBitmapFilter(SlotId slot, Bitmap *bitmap, bool *acquired_ownership)
boost::scoped_ptr< LlvmCodeGen > codegen_
std::vector< std::pair< std::string, int > > file_errors_
Stores the number of parse errors per file.
MemTracker * process_mem_tracker()
SpinLock bitmap_lock_
Lock protecting slot_bitmap_filters_.
LLVM code generator. This is the top level object to generate jitted code.
void AppendError(ErrorLogMap *map, const ErrorMsg &e)
QueryResourceMgr * query_resource_mgr() const
boost::unordered_map< SlotId, Bitmap * > slot_bitmap_filters_
bool LogError(const ErrorMsg &msg)
const TQueryOptions & query_options() const
void ReportFileErrors(const std::string &file_name, int num_errors)
Report that num_errors occurred while parsing file_name.
static Status Create(RuntimeState *state, MemTracker *parent, RuntimeProfile *profile, int64_t mem_limit, int64_t buffer_size, boost::shared_ptr< BufferedBlockMgr > *block_mgr)
boost::scoped_ptr< MemTracker > instance_mem_tracker_
Memory usage of this fragment instance.
~RuntimeState()
Empty d'tor to avoid issues with scoped_ptr.
RuntimeProfile::Counter * total_cpu_timer_
Total CPU time (across all threads), including all wait times.
const TUniqueId & fragment_instance_id() const
std::string FileErrors()
Returns a string representation of the file_errors_.
This class is thread-safe.
SpinLock file_errors_lock_
Lock protecting file_errors_.
static const Status MEM_LIMIT_EXCEEDED
size_t ErrorCount(const ErrorLogMap &errors)
Status SetMemLimitExceeded(MemTracker *tracker=NULL, int64_t failed_allocation_size=0)
static const int DEFAULT_BATCH_SIZE
static MemTracker * GetRequestPoolMemTracker(const std::string &pool_name, MemTracker *parent)
const TQueryCtx & query_ctx() const
DECLARE_int32(max_errors)
bool ErrorLogIsEmpty()
Return true if error log is empty.
Status CreateBlockMgr()
Gets/Creates the query wide block mgr.
std::string LogUsage(const std::string &prefix="") const
Logs the usage of this tracker and all of its children (recursively).
RuntimeProfile::Counter * total_network_send_timer_
Total time spent sending over the network (across all threads)
Status GetCodegen(LlvmCodeGen **codegen, bool initialize=true)
static const int64_t BLOCK_MGR_MEM_MIN_REMAINING
ErrorLogMap error_log_
Logs error messages.
ThreadResourceMgr::ResourcePool * resource_pool_
void AddChild(RuntimeProfile *child, bool indent=true, RuntimeProfile *location=NULL)
ThreadResourceMgr * thread_mgr()
static const float BLOCK_MGR_MEM_FRACTION
std::map< TErrorCode::type, TErrorLogEntry > ErrorLogMap
Tracks log messages per error code.
TPlanFragmentInstanceCtx fragment_instance_ctx_
RuntimeProfile::Counter * total_network_receive_timer_
Total time spent receiving over the network (across all threads)
bool IsMemLimitExceeded() const
Counter * total_time_counter()
Returns the counter for the total elapsed time.