Skip to content

Commit 19fa621

Browse files
committed
[yugabyte#26521] YSQL: fixed vmodule flag handling
Summary: After commit f85bbca, vmodule flag is no longer respected by postgres process, for example: ``` ybd release --cxx-test pgwrapper_pg_analyze-test --gtest_filter PgAnalyzeTest.AnalyzeSamplingColocated --test-args '--vmodule=pg_sample=1' -n 2 -- -p 1 -k zgrep pg_sample ~/logs/latest_test/1.log ``` shows no vlogs. The reason is that `VLOG(1)` is used early by ``` #0 0x00007f7e1b48b090 in google::InitVLOG3__(google::SiteFlag*, int*, char const*, int)@plt () from /net/dev-server-timur/share/code/yugabyte-db/build/debug-clang19-dynamic-ninja/lib/libyb_util_shmem.so #1 0x00007f7e1b47616e in yb::(anonymous namespace)::NegotiatorSharedState::WaitProposal (this=0x7f7e215e8000) at ../../src/yb/util/shmem/reserved_address_segment.cc:108 #2 0x00007f7e1b4781e0 in yb::AddressSegmentNegotiator::Impl::NegotiateChild (fd=45) at ../../src/yb/util/shmem/reserved_address_segment.cc:252 #3 0x00007f7e1b4737ce in yb::AddressSegmentNegotiator::NegotiateChild (fd=45) at ../../src/yb/util/shmem/reserved_address_segment.cc:376 #4 0x00007f7e1b742b7b in yb::tserver::SharedMemoryManager::InitializePostmaster (this=0x7f7e202e9788 <yb::pggate::PgSharedMemoryManager()::shared_mem_manager>, fd=45) at ../../src/yb/tserver/tserver_shared_mem.cc:252 #5 0x00007f7e2023588f in yb::pggate::PgSetupSharedMemoryAddressSegment () at ../../src/yb/yql/pggate/pg_shared_mem.cc:29 #6 0x00007f7e202788e9 in YBCSetupSharedMemoryAddressSegment () at ../../src/yb/yql/pggate/ybc_pg_shared_mem.cc:22 #7 0x000055636b8956f5 in PostmasterMain (argc=21, argv=0x52937fe4e790) at ../../../../../../src/postgres/src/backend/postmaster/postmaster.c:1083 #8 0x000055636b774bfe in PostgresServerProcessMain (argc=21, argv=0x52937fe4e790) at ../../../../../../src/postgres/src/backend/main/main.c:209 #9 0x000055636b7751f2 in main () ``` and caches `vmodule` value before `InitGFlags` sets it from environment. The fix is to explicitly call `UpdateVmodule` from `InitGFlags` after setting `vmodule`. Jira: DB-15888 Test Plan: ``` ybd release --cxx-test pgwrapper_pg_analyze-test --gtest_filter PgAnalyzeTest.AnalyzeSamplingColocated --test-args '--vmodule=pg_sample=1' -n 2 -- -p 1 -k zgrep pg_sample ~/logs/latest_test/1.log ``` Reviewers: hsunder Reviewed By: hsunder Subscribers: ybase, yql Tags: #jenkins-ready, #jenkins-trigger Differential Revision: https://phorge.dev.yugabyte.com/D42731
1 parent 7cc0c3a commit 19fa621

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/yb/util/flags.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ namespace yb {
101101
// See gflags.h for more information.
102102
void ParseCommandLineFlags(int* argc, char*** argv, bool remove_flags);
103103

104+
void RegisterGlobalFlagsCallbacksOnce();
105+
104106
// Reads the given file and updates the value of all flags specified in the file. Returns true on
105107
// success, false otherwise.
106108
bool RefreshFlagsFile(const std::string& filename);

src/yb/util/flags/flags.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ Status LoadFlagsAllowlist() {
642642

643643
} // anonymous namespace
644644

645-
void ParseCommandLineFlags(int* argc, char*** argv, bool remove_flags) {
645+
void RegisterGlobalFlagsCallbacksOnce() {
646646
static GoogleOnceType once_register_vmodule_callback = GOOGLE_ONCE_INIT;
647647
// We cannot use DEFINE_validator and REGISTER_CALLBACK for vmodule since it is not DEFINED in any
648648
// yb file, and we cannot guarantee the static initialization order. Instead we register them
@@ -653,7 +653,10 @@ void ParseCommandLineFlags(int* argc, char*** argv, bool remove_flags) {
653653
flags_callback_internal::RegisterGlobalFlagUpdateCallback(
654654
&FLAGS_vmodule, "ValidateAndUpdateVmodule", &UpdateVmodule);
655655
});
656+
}
656657

658+
void ParseCommandLineFlags(int* argc, char*** argv, bool remove_flags) {
659+
RegisterGlobalFlagsCallbacksOnce();
657660
CHECK_OK(LoadFlagsAllowlist());
658661

659662
{

src/yb/yql/pggate/util/ybc_util.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,20 @@ Status InitGFlags(const char* argv0) {
9696
ChangeWorkingDir(pg_working_dir);
9797
});
9898

99+
// This is needed in case VLOG/VLOG_IS_ON was called before that and initial vmodule flag
100+
// value has already been cached.
101+
RegisterGlobalFlagsCallbacksOnce();
102+
99103
// Also allow overriding flags on the command line using the appropriate environment variables.
100104
std::vector<google::CommandLineFlagInfo> flag_infos;
101105
google::GetAllFlags(&flag_infos);
102106
for (auto& flag_info : flag_infos) {
103107
string env_var_name = "FLAGS_" + flag_info.name;
104108
const char* env_var_value = getenv(env_var_name.c_str());
105109
if (env_var_value) {
106-
google::SetCommandLineOption(flag_info.name.c_str(), env_var_value);
110+
// Make sure callbacks are called.
111+
RETURN_NOT_OK(flags_internal::SetFlagInternal(
112+
flag_info.flag_ptr, flag_info.name.c_str(), env_var_value));
107113
}
108114
}
109115

0 commit comments

Comments
 (0)