Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine cop exceptions #314

Merged
merged 2 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion dbms/src/Flash/Coprocessor/DAGDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <Interpreters/executeQuery.h>
#include <Storages/Transaction/LockException.h>
#include <Storages/Transaction/RegionException.h>
#include <pingcap/Exception.h>

namespace DB
{
Expand Down Expand Up @@ -105,14 +106,24 @@ catch (const LockException & e)
}
catch (const Exception & e)
{
LOG_ERROR(log, __PRETTY_FUNCTION__ << ": Exception: " << e.getStackTrace().toString());
LOG_ERROR(log, __PRETTY_FUNCTION__ << ": DB Exception: " << e.message() << "\n" << e.getStackTrace().toString());
recordError(e.code(), e.message());
}
catch (const pingcap::Exception & e)
{
LOG_ERROR(log, __PRETTY_FUNCTION__ << ": KV Client Exception: " << e.message());
recordError(e.code(), e.message());
}
catch (const std::exception & e)
{
LOG_ERROR(log, __PRETTY_FUNCTION__ << ": std exception: " << e.what());
recordError(ErrorCodes::UNKNOWN_EXCEPTION, e.what());
}
catch (...)
{
LOG_ERROR(log, __PRETTY_FUNCTION__ << ": other exception");
recordError(ErrorCodes::UNKNOWN_EXCEPTION, "other exception");
}

void DAGDriver::recordError(Int32 err_code, const String & err_msg)
{
Expand Down
5 changes: 3 additions & 2 deletions dbms/src/Flash/Coprocessor/DAGDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class DAGDriver

void execute();

private:
void recordError(Int32 err_code, const String & err_msg);

private:
Context & context;

Expand All @@ -36,7 +39,5 @@ class DAGDriver
bool internal;

Poco::Logger * log;

void recordError(Int32 err_code, const String & err_msg);
};
} // namespace DB
41 changes: 23 additions & 18 deletions dbms/src/Flash/CoprocessorHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ try
}
catch (const LockException & e)
{
LOG_ERROR(log, __PRETTY_FUNCTION__ << ": LockException: " << e.getStackTrace().toString());
LOG_ERROR(log,
__PRETTY_FUNCTION__ << ": LockException: region " << cop_request->context().region_id() << "\n"
<< e.getStackTrace().toString());
cop_response->Clear();
kvrpcpb::LockInfo * lock_info = cop_response->mutable_locked();
lock_info->set_key(e.lock_infos[0]->key);
Expand All @@ -72,7 +74,9 @@ catch (const LockException & e)
}
catch (const RegionException & e)
{
LOG_ERROR(log, __PRETTY_FUNCTION__ << ": RegionException: " << e.getStackTrace().toString());
LOG_ERROR(log,
__PRETTY_FUNCTION__ << ": RegionException: region " << cop_request->context().region_id() << "\n"
<< e.getStackTrace().toString());
cop_response->Clear();
errorpb::Error * region_err;
switch (e.status)
Expand All @@ -95,30 +99,31 @@ catch (const RegionException & e)
}
catch (const Exception & e)
{
LOG_ERROR(log, __PRETTY_FUNCTION__ << ": Exception: " << e.getStackTrace().toString());
cop_response->Clear();
cop_response->set_other_error(e.message());

if (e.code() == ErrorCodes::NOT_IMPLEMENTED)
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, e.message());

// TODO: Map other DB error codes to grpc codes.

return grpc::Status(grpc::StatusCode::INTERNAL, e.message());
LOG_ERROR(log, __PRETTY_FUNCTION__ << ": DB Exception: " << e.message() << "\n" << e.getStackTrace().toString());
return recordError(e.code() == ErrorCodes::NOT_IMPLEMENTED ? grpc::StatusCode::UNIMPLEMENTED : grpc::StatusCode::INTERNAL, e.message());
}
catch (const pingcap::Exception & e)
{
LOG_ERROR(log, __PRETTY_FUNCTION__ << ": KV Client Exception: " << e.message());
return recordError(e.code() == ErrorCodes::NOT_IMPLEMENTED ? grpc::StatusCode::UNIMPLEMENTED : grpc::StatusCode::INTERNAL, e.message());
}
catch (const std::exception & e)
{
LOG_ERROR(log, __PRETTY_FUNCTION__ << ": std exception: " << e.what());
cop_response->Clear();
cop_response->set_other_error(e.what());
return grpc::Status(grpc::StatusCode::INTERNAL, e.what());
return recordError(grpc::StatusCode::INTERNAL, e.what());
}
catch (...)
{
LOG_ERROR(log, __PRETTY_FUNCTION__ << ": catch other exception.");
LOG_ERROR(log, __PRETTY_FUNCTION__ << ": other exception");
return recordError(grpc::StatusCode::INTERNAL, "other exception");
}

grpc::Status CoprocessorHandler::recordError(grpc::StatusCode err_code, const String & err_msg)
{
cop_response->Clear();
cop_response->set_other_error("other exception");
return grpc::Status(grpc::StatusCode::INTERNAL, "other exception");
cop_response->set_other_error(err_msg);

return grpc::Status(err_code, err_msg);
}

} // namespace DB
3 changes: 3 additions & 0 deletions dbms/src/Flash/CoprocessorHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class CoprocessorHandler

grpc::Status execute();

protected:
grpc::Status recordError(grpc::StatusCode err_code, const String & err_msg);

protected:
enum
{
Expand Down