Skip to content

Commit

Permalink
use TOPLINGDB_TRY ... TOPLINGDB_CATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
rockeet committed Dec 21, 2024
1 parent 2917b4c commit 502d87c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 36 deletions.
26 changes: 10 additions & 16 deletions src/dcompact/dcompact_etcd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -994,9 +994,8 @@ T lim(T x, U lo, W hi) {
}
Status DcompactEtcdExec::Attempt(const CompactionParams& params,
CompactionResults* results)
#ifdef NDEBUG
try
#endif
{
TOPLINGDB_TRY
{
using namespace std::chrono;
auto f = static_cast<const DcompactEtcdExecFactory*>(m_factory);
Expand Down Expand Up @@ -1063,20 +1062,16 @@ try
auto s1 = m_env->CreateDir(output_dir);
TERARK_VERIFY_S(s1.ok(), "%s", s1.ToString());
std::string params_fname = output_dir + "/rpc.params";
#ifdef NDEBUG
try {
#endif
TOPLINGDB_TRY {
FileStream fp(params_fname, "wb+");
SerDeWrite(fp, &params);
#ifdef NDEBUG
} catch (const std::exception& ex) {
} TOPLINGDB_CATCH (const std::exception& ex) {
TERARK_DIE_S("file = %s, exception: %s", params_fname, ex);
} catch (const Status& s) {
} TOPLINGDB_CATCH (const Status& s) {
TERARK_DIE_S("file = %s, Status: %s", params_fname, s.ToString());
} catch (...) {
} TOPLINGDB_CATCH (...) {
TERARK_DIE_S("file = %s, exception: unknown", params_fname);
}
#endif
}
auto t1 = m_env->NowMicros();
auto s1 = m_env->CreateDir(AddFmt(output_dir, "/att-%02d", m_attempt));
Expand Down Expand Up @@ -1329,24 +1324,23 @@ try
//watcher.Cancel(); // watch will be canceled in destructor
return s;
}
#ifdef NDEBUG
catch (const std::exception& ex) {
TOPLINGDB_CATCH (const std::exception& ex) {
ROCKS_LOG_ERROR(m_log, "job-%05d/att-%02d at %s, exception: %s",
params.job_id, m_attempt, m_url.c_str(), ex.what());
CleanFiles(params, *results);
return Status::Corruption("DcompactEtcdExec::Attempt", ex.what());
}
catch (const Status& s) {
TOPLINGDB_CATCH (const Status& s) {
ROCKS_LOG_ERROR(m_log, "job-%05d/att-%02d at %s, caught Status: %s",
params.job_id, m_attempt, m_url.c_str(), s.ToString().c_str());
CleanFiles(params, *results);
return Status::Corruption("DcompactEtcdExec::Attempt", s.ToString());
}
catch (...) {
TOPLINGDB_CATCH (...) {
CleanFiles(params, *results);
return Status::Corruption("DcompactEtcdExec::Attempt", "caught unknown exception");
}
#endif
}

auto g_curl_init = curl_global_init(CURL_GLOBAL_DEFAULT); // NOLINT

Expand Down
28 changes: 8 additions & 20 deletions tools/dcompact/dcompact_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,14 @@ void CreatePluginTpl(FILE* fp, const ObjectRpcParam& rpc,
}
json spec;
if (!rpc.params.empty()) {
#if defined(NDEBUG)
Logger* info_log = params.info_log;
try {
TOPLINGDB_TRY {
spec = json::parse(rpc.params);
}
catch (const std::exception& ex) {
TOPLINGDB_CATCH (const std::exception& ex) {
ERROR("%s: exception: %s, json:---%s\n---", ROCKSDB_FUNC, ex, rpc.params);
THROW_Corruption(ex.what());
}
#else
spec = json::parse(rpc.params);
#endif
}
ptr = PluginFactory<Ptr>::AcquirePlugin(rpc.clazz, spec, repo);
TERARK_VERIFY(GetRawPtr(ptr) != nullptr);
Expand Down Expand Up @@ -1011,25 +1007,21 @@ int RunCompact(FILE* in) const {
MyCreatePlugin1(cfo, table_properties_collector_factories[i]);
}
DEBG("Beg SerDeRead: %s", attempt_dir);
#if defined(NDEBUG)
try {
TOPLINGDB_TRY {
SerDeRead(in, &params);
}
catch (const std::exception& ex) {
TOPLINGDB_CATCH (const std::exception& ex) {
ERROR("SerDeRead = %s", ex.what());
return 0;
}
catch (const Status& es) {
TOPLINGDB_CATCH (const Status& es) {
ERROR("SerDeRead = %s", es.ToString());
return 0;
}
catch (...) {
TOPLINGDB_CATCH (...) {
ERROR("SerDeRead = unknown exception");
return 0;
}
#else
SerDeRead(in, &params);
#endif
DEBG("End SerDeRead: %s", attempt_dir);
if (!params.full_history_ts_low.empty()) {
VERIFY_EQ(cfo.comparator->timestamp_size(),
Expand Down Expand Up @@ -2027,9 +2019,7 @@ void NotifyEtcd() const {
g_etcd->set(key, "done", ttl).then([=](pplx::task<etcd::Response> async) {
TERARK_VERIFY_EQ(self.get(), this); // must use self
TERARK_VERIFY_EQ(info_log, this->m_log.get());
#ifdef NDEBUG
try {
#endif
TOPLINGDB_TRY {
etcd::Response resp = async.get();
if (!resp.is_ok()) {
g_etcd_err.fetch_add(1, std::memory_order_relaxed);
Expand All @@ -2045,15 +2035,13 @@ try {
done_stat = 1;
cond_var.notify_all();
}
#ifdef NDEBUG
} catch (const std::exception& ex) {
} TOPLINGDB_CATCH (const std::exception& ex) {
ERROR("Etcd.set(%s, done) throws exception = %s", key, ex);
info_log->Flush();
done_stat = 2; // error
g_etcd_err.fetch_add(1, std::memory_order_relaxed);
cond_var.notify_all();
}
#endif
});
if (0 == done_stat) {
for (int retry = 0; retry < 1000; ++retry) {
Expand Down

0 comments on commit 502d87c

Please sign in to comment.