Skip to content
Draft

test #1595

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
26 changes: 20 additions & 6 deletions google/cloud/odbc/bq_driver/internal/trace_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,12 @@ void UpdateTraceOption(std::optional<int> log_level,
std::optional<int> log_file_size,
std::optional<int> log_file_count,
std::optional<std::uint32_t> max_threads) {
if (!kTraceOptsFile.Ok() || !(log_level || log_path || log_file_size ||
auto trace_opts = GetTraceOptsFile();
if (!trace_opts.Ok() || !(log_level || log_path || log_file_size ||
log_file_count || max_threads))
return;

auto const& trace_options = kTraceOptsFile.GetValue();
auto const& trace_options = trace_opts.GetValue();
std::lock_guard<std::mutex> lock(trace_options->m);

if (log_level) {
Expand All @@ -186,8 +187,9 @@ std::string GetLogFileWithIndex(std::string const& log_path) {
std::string base_dir = log_path;

int file_index = 0;
if (kTraceOptsFile.Ok()) {
auto const& trace_opts = kTraceOptsFile.GetValue();
auto trace_opts_file = GetTraceOptsFile();
if (trace_opts_file.Ok()) {
auto const& trace_opts = trace_opts_file.GetValue();
file_index = trace_opts->current_file_index;
}
std::string separator =
Expand Down Expand Up @@ -216,8 +218,9 @@ bool TraceOptions::InitializeLogging(bool is_trace_override) {
std::call_once(absl_log_init_flag, []() { absl::InitializeLog(); });
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfinity);

if (!kTraceOptsFile.Ok()) return false;
auto const& trace_opts = kTraceOptsFile.GetValue();
auto trace_opts_file = GetTraceOptsFile();
if (!trace_opts_file.Ok()) return false;
auto const& trace_opts = trace_opts_file.GetValue();

// If logging is disabled, return false
if (trace_opts->log_level <= 0) {
Expand Down Expand Up @@ -312,4 +315,15 @@ std::shared_ptr<TraceOptions> TraceOptions::GetTraceOption() {
return options_file_;
}

// Returns the singleton TraceOptions instance, lazily initialized on first
// use. This avoids the static initialization order fiasco and prevents
// abseil flat_hash_map corruption that can occur when this was previously
// an inline function in a header file (which caused each translation unit
// to have its own copy and resulted in ASAN assertion failures).
odbc_internal::StatusRecordOr<std::shared_ptr<TraceOptions>> GetTraceOptsFile() {
static auto const kTraceOptsFile =
TraceOptions::CreateTraceOptionsFile(GetOdbcTraceConfigPath());
return kTraceOptsFile;
}

} // namespace google::cloud::odbc_bq_driver_internal
12 changes: 8 additions & 4 deletions google/cloud/odbc/bq_driver/internal/trace_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,14 @@ std::string GetFormattedMsg(absl::LogEntry const& entry);
// Struct types.
/////////////////////////////////////////////

static odbc_internal::StatusRecordOr<std::shared_ptr<TraceOptions>> const
kTraceOptsFile =
TraceOptions::CreateTraceOptionsFile(GetOdbcTraceConfigPath());
// Returns the singleton TraceOptions instance, lazily initialized on first
// use. This avoids the static initialization order fiasco and prevents
// abseil flat_hash_map corruption that can occur when kTraceOptsFile was
// previously a static variable in a header file (which caused each
// translation unit to have its own copy and resulted in ASAN assertion
// failures).
odbc_internal::StatusRecordOr<std::shared_ptr<TraceOptions>> GetTraceOptsFile();

} // namespace google::cloud::odbc_bq_driver_internal

#endif // CPP_BIGQUERY_ODBC_GOOGLE_CLOUD_ODBC_BQ_DRIVER_INTERNAL_TRACE_UTILS_H
#endif // CPP_BIGQUERY_ODBC_GOOGLE_CLOUD_ODBC_BQ_DRIVER_INTERNAL_TRACE_UTILS_H
7 changes: 4 additions & 3 deletions google/cloud/odbc/bq_driver/odbc_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using google::cloud::odbc_bq_driver_internal::EnvironmentHandle;
using google::cloud::odbc_bq_driver_internal::GetDefaultPemFile;
using google::cloud::odbc_bq_driver_internal::GetMissingAttributesStr;
using google::cloud::odbc_bq_driver_internal::GetUpperStr;
using google::cloud::odbc_bq_driver_internal::kTraceOptsFile;
using google::cloud::odbc_bq_driver_internal::GetTraceOptsFile;
using google::cloud::odbc_bq_driver_internal::LogAndReturnCode;
using google::cloud::odbc_bq_driver_internal::PopulateOutputConnectionString;
using google::cloud::odbc_bq_driver_internal::Section;
Expand Down Expand Up @@ -323,8 +323,9 @@ SQLRETURN SQLDriverConnectInternal(SQLHDBC conn_handle, SQLHWND window_handle,
dsn_section[property] = it.second;
}
}
if (kTraceOptsFile.Ok()) {
auto const& trace_options = kTraceOptsFile.GetValue();
auto trace_opts_file = GetTraceOptsFile();
if (trace_opts_file.Ok()) {
auto const& trace_options = trace_opts_file.GetValue();
if (!trace_options->logging_enabled) {
config_res = ConfigTraceFromSection(dsn_section);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4292,6 +4292,7 @@ TEST(SQLMoreResults, ProcedureWithDescriptorAndQueryParams) {
status = SQLPrepare(conn->hstmt, (SQLCHAR*)call_proc.c_str(), SQL_NTS);
CheckError(status, "SQLPrepare (call procedure)", conn);


// Bind parameters
SQLCHAR str_val[] = "Test String 5";
SQLLEN str_ind = SQL_NTS;
Expand Down
Loading