void MapReduceBase::handle() { if (running_) { LOG(FATAL) << "Duplicate launch of " << to_string(); } running_ = true; LOG(INFO) << "Started running: " << to_string() << " NUMA node=" << static_cast<int>(numa_node_); thread::NumaThreadScope scope(numa_node_); ErrorStack result = handle_process(); // calls main logic in derived class if (result.is_error()) { if (result.get_error_code() == kErrorCodeSnapshotCancelled) { LOG(WARNING) << to_string() << " cancelled"; } else { LOG(ERROR) << to_string() << " got an error while processing:" << result; parent_.increment_error_count(); parent_.wakeup(); } } else { LOG(INFO) << to_string() << " successfully finished"; } // let the gleaner know that I'm done. uint16_t value_after = parent_.increment_completed_count(); ASSERT_ND(value_after <= parent_.get_all_count()); if (value_after == parent_.get_all_count()) { // I was the last one to go into sleep, this means everything is fully processed. // let gleaner knows about it. ASSERT_ND(parent_.is_all_completed()); LOG(INFO) << to_string() << " was the last one to finish, waking up gleaner.. "; parent_.wakeup(); } parent_.increment_exit_count(); LOG(INFO) << "Stopped running: " << to_string(); running_ = false; }
void IOTracePopStr(char* buffer,int size) { if (errorstack.empty()) { *buffer = 0; return; } strncpy(buffer,errorstack.top().c_str(),size); errorstack.pop(); }
virtual bool reap_error(ErrorStack& errs) { if (!the_error) return false; errs.push(the_error.release()); return true; }
namespace KDL { // Trace of the call stack of the I/O routines to help user // interprete error messages from I/O typedef std::stack<std::string> ErrorStack; ErrorStack errorstack; // should be in Thread Local Storage if this gets multithreaded one day... void IOTrace(const std::string& description) { errorstack.push(description); } void IOTracePop() { errorstack.pop(); } void IOTraceOutput(std::ostream& os) { while (!errorstack.empty()) { os << errorstack.top().c_str() << std::endl; errorstack.pop(); } } void IOTracePopStr(char* buffer,int size) { if (errorstack.empty()) { *buffer = 0; return; } strncpy(buffer,errorstack.top().c_str(),size); errorstack.pop(); } }
// For argument dependent lookup inline void swap(ErrorStack& s1, ErrorStack& s2) { s1.swap(s2); }
void IOTraceOutput(std::ostream& os) { while (!errorstack.empty()) { os << errorstack.top().c_str() << std::endl; errorstack.pop(); } }
void IOTracePop() { errorstack.pop(); }
void IOTrace(const std::string& description) { errorstack.push(description); }
void swap(ParseStatus& other) noexcept { std::swap(m_code, other.m_code); std::swap(m_offset, other.m_offset); m_stack.swap(other.m_stack); }
bool has_error() const { return m_code != 0 || !m_stack.empty(); }
const_iterator end() const { return m_stack.end(); }
const_iterator begin() const { return m_stack.begin(); }