Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
status.cc
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <boost/foreach.hpp>
16 #include <boost/algorithm/string/join.hpp>
17 
18 #include "common/status.h"
19 #include "util/debug-util.h"
20 
21 #include "common/names.h"
22 
23 namespace impala {
24 
25 // NOTE: this is statically initialized and we must be very careful what
26 // functions these constructors call. In particular, we cannot call
27 // glog functions which also rely on static initializations.
28 // TODO: is there a more controlled way to do this.
29 const Status Status::OK;
30 
31 const Status Status::CANCELLED(ErrorMsg::Init(TErrorCode::CANCELLED, "Cancelled"));
32 
33 const Status Status::MEM_LIMIT_EXCEEDED(
34  ErrorMsg::Init(TErrorCode::MEM_LIMIT_EXCEEDED, "Memory limit exceeded"));
35 
36 const Status Status::DEPRECATED_RPC(ErrorMsg::Init(TErrorCode::NOT_IMPLEMENTED_ERROR,
37  "Deprecated RPC; please update your client"));
38 
39 Status::Status(TErrorCode::type code)
40  : msg_(new ErrorMsg(code)) {
41  VLOG(1) << msg_->msg() << "\n" << GetStackTrace();
42 }
43 
44 Status::Status(TErrorCode::type code, const ArgType& arg0)
45  : msg_(new ErrorMsg(code, arg0)) {
46  VLOG(1) << msg_->msg() << "\n" << GetStackTrace();
47 }
48 
49 Status::Status(TErrorCode::type code, const ArgType& arg0, const ArgType& arg1)
50  : msg_(new ErrorMsg(code, arg0, arg1)) {
51  VLOG(1) << msg_->msg() << "\n" << GetStackTrace();
52 }
53 
54 Status::Status(TErrorCode::type code, const ArgType& arg0, const ArgType& arg1,
55  const ArgType& arg2)
56  : msg_(new ErrorMsg(code, arg0, arg1, arg2)) {
57  VLOG(1) << msg_->msg() << "\n" << GetStackTrace();
58 }
59 Status::Status(TErrorCode::type code, const ArgType& arg0, const ArgType& arg1,
60  const ArgType& arg2, const ArgType& arg3)
61  : msg_(new ErrorMsg(code, arg0, arg1, arg2, arg3)) {
62  VLOG(1) << msg_->msg() << "\n" << GetStackTrace();
63 }
64 
65 Status::Status(TErrorCode::type code, const ArgType& arg0, const ArgType& arg1,
66  const ArgType& arg2, const ArgType& arg3, const ArgType& arg4)
67  : msg_(new ErrorMsg(code, arg0, arg1, arg2, arg3, arg4)) {
68  VLOG(1) << msg_->msg() << "\n" << GetStackTrace();
69 }
70 
71 Status::Status(TErrorCode::type code, const ArgType& arg0, const ArgType& arg1,
72  const ArgType& arg2, const ArgType& arg3, const ArgType& arg4,
73  const ArgType& arg5)
74  : msg_(new ErrorMsg(code, arg0, arg1, arg2, arg3, arg4, arg5)) {
75  VLOG(1) << msg_->msg() << "\n" << GetStackTrace();
76 }
77 
78 Status::Status(TErrorCode::type code, const ArgType& arg0, const ArgType& arg1,
79  const ArgType& arg2, const ArgType& arg3, const ArgType& arg4,
80  const ArgType& arg5, const ArgType& arg6)
81  : msg_(new ErrorMsg(code, arg0, arg1, arg2, arg3, arg4, arg5, arg6)) {
82  VLOG(1) << msg_->msg() << "\n" << GetStackTrace();
83 }
84 
85 Status::Status(TErrorCode::type code, const ArgType& arg0, const ArgType& arg1,
86  const ArgType& arg2, const ArgType& arg3, const ArgType& arg4,
87  const ArgType& arg5, const ArgType& arg6, const ArgType& arg7)
88  : msg_(new ErrorMsg(code, arg0, arg1, arg2, arg3, arg4, arg5, arg6,
89  arg7)) {
90  VLOG(1) << msg_->msg() << "\n" << GetStackTrace();
91 }
92 
93 Status::Status(TErrorCode::type code, const ArgType& arg0, const ArgType& arg1,
94  const ArgType& arg2, const ArgType& arg3, const ArgType& arg4,
95  const ArgType& arg5, const ArgType& arg6, const ArgType& arg7,
96  const ArgType& arg8)
97  : msg_(new ErrorMsg(code, arg0, arg1, arg2, arg3, arg4, arg5, arg6,
98  arg7, arg8)) {
99  VLOG(1) << msg_->msg() << "\n" << GetStackTrace();
100 }
101 
102 Status::Status(TErrorCode::type code, const ArgType& arg0, const ArgType& arg1,
103  const ArgType& arg2, const ArgType& arg3, const ArgType& arg4,
104  const ArgType& arg5, const ArgType& arg6, const ArgType& arg7,
105  const ArgType& arg8, const ArgType& arg9)
106  : msg_(new ErrorMsg(code, arg0, arg1, arg2, arg3, arg4, arg5, arg6,
107  arg7, arg8, arg9)) {
108  VLOG(1) << msg_->msg() << "\n" << GetStackTrace();
109 }
110 
111 Status::Status(const string& error_msg)
112  : msg_(new ErrorMsg(TErrorCode::GENERAL, error_msg)) {
113  VLOG(1) << msg_->msg() << "\n" << GetStackTrace();
114 }
115 
116 Status::Status(const string& error_msg, bool silent)
117  : msg_(new ErrorMsg(TErrorCode::GENERAL, error_msg)) {
118  if (!silent) {
119  VLOG(1) << msg_->msg() << "\n" << GetStackTrace();
120  }
121 }
122 
123 Status::Status(const ErrorMsg& message)
124  : msg_(new ErrorMsg(message)) { }
125 
126 Status::Status(const TStatus& status)
127  : msg_(status.status_code == TErrorCode::OK
128  ? NULL : new ErrorMsg(status.status_code, status.error_msgs)) { }
129 
130 Status& Status::operator=(const TStatus& status) {
131  delete msg_;
132  if (status.status_code == TErrorCode::OK) {
133  msg_ = NULL;
134  } else {
135  msg_ = new ErrorMsg(status.status_code, status.error_msgs);
136  }
137  return *this;
138 }
139 
140 Status::Status(const apache::hive::service::cli::thrift::TStatus& hs2_status)
141  : msg_(
142  hs2_status.statusCode
143  == apache::hive::service::cli::thrift::TStatusCode::SUCCESS_STATUS ? NULL
144  : new ErrorMsg(
145  static_cast<TErrorCode::type>(hs2_status.statusCode),
146  hs2_status.errorMessage)) {
147 }
148 
150  const apache::hive::service::cli::thrift::TStatus& hs2_status) {
151  delete msg_;
152  if (hs2_status.statusCode
153  == apache::hive::service::cli::thrift::TStatusCode::SUCCESS_STATUS) {
154  msg_ = NULL;
155  } else {
156  msg_ = new ErrorMsg(
157  static_cast<TErrorCode::type>(hs2_status.statusCode), hs2_status.errorMessage);
158  }
159  return *this;
160 }
161 
162 Status Status::Expected(const std::string& error_msg) {
163  return Status(error_msg, true);
164 }
165 
166 void Status::AddDetail(const std::string& msg) {
167  DCHECK_NOTNULL(msg_);
168  msg_->AddDetail(msg);
169  VLOG(2) << msg;
170 }
171 
172 void Status::MergeStatus(const Status& status) {
173  if (status.ok()) return;
174  if (msg_ == NULL) {
175  msg_ = new ErrorMsg(*status.msg_);
176  } else {
177  msg_->AddDetail(status.msg().msg());
178  BOOST_FOREACH(const string& s, status.msg_->details()) {
179  msg_->AddDetail(s);
180  }
181  }
182 }
183 
184 const string Status::GetDetail() const {
185  return msg_ != NULL ? msg_->GetFullMessageDetails() : "";
186 }
187 
188 void Status::ToThrift(TStatus* status) const {
189  status->error_msgs.clear();
190  if (msg_ == NULL) {
191  status->status_code = TErrorCode::OK;
192  } else {
193  status->status_code = msg_->error();
194  status->error_msgs.push_back(msg_->msg());
195  BOOST_FOREACH(const string& s, msg_->details()) {
196  status->error_msgs.push_back(s);
197  }
198  status->__isset.error_msgs = true;
199  }
200 }
201 
202 }
const std::string & msg() const
Returns the formatted error string.
Definition: error-util.h:118
const std::string GetDetail() const
Definition: status.cc:184
static const Status DEPRECATED_RPC
Definition: status.h:90
strings::internal::SubstituteArg ArgType
Definition: status.h:83
void MergeStatus(const Status &status)
Definition: status.cc:172
TErrorCode::type error() const
Definition: error-util.h:105
void AddDetail(const std::string &msg)
Add a detail string. Calling this method is only defined on a non-OK message.
Definition: status.cc:166
Status & operator=(const Status &status)
same as copy c'tor
Definition: status.h:146
ErrorMsg * msg_
Definition: status.h:238
void ToThrift(TStatus *status) const
Convert into TStatus.
Definition: status.cc:188
void AddDetail(const std::string &d)
Add detail string message.
Definition: error-util.h:108
static const Status CANCELLED
Definition: status.h:88
static Status Expected(const std::string &error_msg)
Create a status instance that represents an expected error and will not be logged.
Definition: status.cc:162
static const Status MEM_LIMIT_EXCEEDED
Definition: status.h:89
std::string GetFullMessageDetails() const
Definition: error-util.h:128
static ErrorMsg Init(TErrorCode::type error, const ArgType &arg0=ArgType::NoArg, const ArgType &arg1=ArgType::NoArg, const ArgType &arg2=ArgType::NoArg, const ArgType &arg3=ArgType::NoArg, const ArgType &arg4=ArgType::NoArg, const ArgType &arg5=ArgType::NoArg, const ArgType &arg6=ArgType::NoArg, const ArgType &arg7=ArgType::NoArg, const ArgType &arg8=ArgType::NoArg, const ArgType &arg9=ArgType::NoArg)
Definition: error-util.cc:122
static const Status OK
Definition: status.h:87
const ErrorMsg & msg() const
Returns the error message associated with a non-successful status.
Definition: status.h:189
string GetStackTrace()
Definition: debug-util.cc:246
const std::vector< std::string > & details() const
Definition: error-util.h:122
bool ok() const
Definition: status.h:172