Skip to content

Commit

Permalink
Improve log message and suppress stack trace for Issue #767
Browse files Browse the repository at this point in the history
  • Loading branch information
umegane committed Jan 6, 2025
1 parent cf3f7a3 commit 007ea02
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/limestone/datastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ datastore::datastore(configuration const& conf) : location_(conf.data_locations_
fd_for_flock_ = internal::acquire_manifest_lock(location_);
if (fd_for_flock_ == -1) {
if (errno == EWOULDBLOCK) {
std::string err_msg = "another process is using the log directory: " + location_.string() + ".";
throw limestone_exception(exception_type::initialization_failure, err_msg);
std::string err_msg = "another process is using the log directory: " + location_.string();
LOG(FATAL) << "/:limestone:config:datastore " << err_msg;
throw limestone_exception(exception_type::initialization_failure, err_msg);
}
std::string err_msg = "failed to acquire lock for manifest in directory: " + location_.string() + ".";
std::string err_msg = "failed to acquire lock for manifest in directory: " + location_.string();
LOG(FATAL) << "/:limestone:config:datastore " << err_msg;
throw limestone_io_exception(exception_type::initialization_failure, err_msg, errno);
}

Expand Down
6 changes: 3 additions & 3 deletions src/limestone/dblogutil/dblogutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ int main(char *dir, subcommand mode) { // NOLINT
check_and_migrate_logdir_format(p);
int lock_fd = acquire_manifest_lock(p);
if (lock_fd == -1) {
LOG(ERROR) << "Another process is using the log directory: " << p
<< ". Command execution aborted.";
log_and_exit(64);
LOG(ERROR) << "Log directory " << p
<< " is already in use by another process. Operation aborted.";
log_and_exit(64);
}
dblog_scan ds(p);
ds.set_thread_num(FLAGS_thread_num);
Expand Down
7 changes: 3 additions & 4 deletions src/limestone/limestone_exception_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,15 @@ inline void handle_exception_and_abort(std::string_view func_name) {
throw;
} catch (const limestone_exception& e) {
if (limestone::testing::enable_exception_throwing) {
throw;
throw;
}
switch (e.type()) {
case exception_type::fatal_error:
LOG_LP(FATAL) << "Fatal error in " << func_name << ": " << e.what();
std::abort(); // Safety measure: this should never be reached due to LOG_LP(FATAL)
break;
case exception_type::initialization_failure:
LOG(ERROR) << "Initialization failed. The process will now terminate: " << e.what();
std::abort();
throw;
break;
}
} catch (const std::runtime_error& e) {
Expand All @@ -106,4 +105,4 @@ inline void handle_exception_and_abort(std::string_view func_name) {
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define HANDLE_EXCEPTION_AND_ABORT() handle_exception_and_abort(static_cast<const char*>(__func__))

} // namespace limestone
} // namespace limestone
4 changes: 2 additions & 2 deletions test/limestone/api/datastore_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ TEST_F(datastore_test, prevent_double_start_test) { // NOLINT

// another process is using the log directory
ASSERT_DEATH({
auto ds2 = std::make_unique<limestone::api::datastore_test>(conf);
}, "Initialization failed. The process will now terminate: another process is using the log directory: /tmp/datastore_test/data_location.");
auto ds2 = std::make_unique<limestone::api::datastore_test>(conf);
}, "another process is using the log directory: /tmp/datastore_test/data_location.");

// Ather datastore is created after the first one is destroyed
ds1->shutdown();
Expand Down
2 changes: 1 addition & 1 deletion test/limestone/utils/dblogutil_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ TEST_F(dblogutil_test, execution_fails_while_active_datastore) {
auto [rc_active, out_active] = inspect("pwal_0000", data_normal);
EXPECT_NE(rc_active, 0);
std::cerr << out_active << std::endl;
EXPECT_TRUE(contains(out_active, "Another process is using the log directory:"));
EXPECT_TRUE(contains(out_active, "Log directory \"/tmp/dblogutil_test\" is already in use by another process. Operation aborted."));

// Inactive datastore
ds1->shutdown();
Expand Down

0 comments on commit 007ea02

Please sign in to comment.