diff --git a/java/yb-pgsql/src/test/java/org/yb/pgsql/TestYbAsh.java b/java/yb-pgsql/src/test/java/org/yb/pgsql/TestYbAsh.java index 1a1fe57cd812..d8b9686a6df6 100644 --- a/java/yb-pgsql/src/test/java/org/yb/pgsql/TestYbAsh.java +++ b/java/yb-pgsql/src/test/java/org/yb/pgsql/TestYbAsh.java @@ -40,9 +40,11 @@ public class TestYbAsh extends BasePgSQLTest { private void setAshConfigAndRestartCluster( int sampling_interval, int sample_size) throws Exception { Map flagMap = super.getTServerFlags(); - flagMap.put("TEST_yb_enable_ash", "true"); - flagMap.put("ysql_pg_conf_csv", "yb_ash_sampling_interval=" + sampling_interval + - ",yb_ash_sample_size=" + sample_size); + flagMap.put("allowed_preview_flags_csv", "ysql_yb_ash_enable_infra,ysql_yb_enable_ash"); + flagMap.put("ysql_yb_ash_enable_infra", "true"); + flagMap.put("ysql_yb_enable_ash", "true"); + flagMap.put("ysql_yb_ash_sampling_interval", String.valueOf(sampling_interval)); + flagMap.put("ysql_yb_ash_sample_size", String.valueOf(sample_size)); restartClusterWithFlags(Collections.emptyMap(), flagMap); } @@ -60,7 +62,7 @@ public void testAshViewWithoutEnablingAsh() throws Exception { restartCluster(); try (Statement statement = connection.createStatement()) { runInvalidQuery(statement, "SELECT * FROM " + ASH_VIEW, - "TEST_yb_enable_ash gflag must be enabled"); + "ysql_yb_ash_enable_infra gflag must be enabled"); } } diff --git a/src/postgres/src/backend/postmaster/pgstat.c b/src/postgres/src/backend/postmaster/pgstat.c index e3470c41793d..9a99bd0e4ccf 100644 --- a/src/postgres/src/backend/postmaster/pgstat.c +++ b/src/postgres/src/backend/postmaster/pgstat.c @@ -3613,7 +3613,7 @@ pgstat_get_wait_event_type(uint32 wait_event_info) /* report process as not waiting. */ if (wait_event_info == 0) { - if (IsYugaByteEnabled() && YBEnableAsh()) + if (IsYugaByteEnabled() && yb_ash_enable_infra) return "YSQLQuery"; return NULL; } @@ -3651,7 +3651,7 @@ pgstat_get_wait_event_type(uint32 wait_event_info) break; default: event_type = "???"; - if (IsYugaByteEnabled() && YBEnableAsh()) + if (IsYugaByteEnabled() && yb_ash_enable_infra) event_type = YBCGetWaitEventClass(wait_event_info); break; } @@ -3675,7 +3675,7 @@ pgstat_get_wait_event(uint32 wait_event_info) /* report process as not waiting. */ if (wait_event_info == 0) { - if (IsYugaByteEnabled() && YBEnableAsh()) + if (IsYugaByteEnabled() && yb_ash_enable_infra) return "QueryProcessing"; return NULL; } @@ -3734,7 +3734,7 @@ pgstat_get_wait_event(uint32 wait_event_info) } default: event_name = "unknown wait event"; - if (IsYugaByteEnabled() && YBEnableAsh()) + if (IsYugaByteEnabled() && yb_ash_enable_infra) event_name = YBCGetWaitEventName(wait_event_info); break; } diff --git a/src/postgres/src/backend/postmaster/postmaster.c b/src/postgres/src/backend/postmaster/postmaster.c index 91ab9d9b1c98..bda25732ad80 100644 --- a/src/postgres/src/backend/postmaster/postmaster.c +++ b/src/postgres/src/backend/postmaster/postmaster.c @@ -1039,7 +1039,7 @@ PostmasterMain(int argc, char *argv[]) ApplyLauncherRegister(); /* Register ASH collector */ - if (YBIsEnabledInPostgresEnvVar() && YBEnableAsh()) + if (YBIsEnabledInPostgresEnvVar() && yb_ash_enable_infra) YbAshRegister(); /* diff --git a/src/postgres/src/backend/storage/ipc/ipci.c b/src/postgres/src/backend/storage/ipc/ipci.c index cf8b87cf3404..1e568db31494 100644 --- a/src/postgres/src/backend/storage/ipc/ipci.c +++ b/src/postgres/src/backend/storage/ipc/ipci.c @@ -157,7 +157,7 @@ CreateSharedMemoryAndSemaphores(int port) size = add_size(size, ShmemBackendArraySize()); #endif - if (YBIsEnabledInPostgresEnvVar() && YBEnableAsh()) + if (YBIsEnabledInPostgresEnvVar() && yb_ash_enable_infra) size = add_size(size, YbAshShmemSize()); /* freeze the addin request size and include it */ @@ -274,7 +274,7 @@ CreateSharedMemoryAndSemaphores(int port) AsyncShmemInit(); BackendRandomShmemInit(); - if (YBIsEnabledInPostgresEnvVar() && YBEnableAsh()) + if (YBIsEnabledInPostgresEnvVar() && yb_ash_enable_infra) YbAshShmemInit(); #ifdef EXEC_BACKEND diff --git a/src/postgres/src/backend/utils/init/postinit.c b/src/postgres/src/backend/utils/init/postinit.c index d1a0f168b496..13f932b37042 100644 --- a/src/postgres/src/backend/utils/init/postinit.c +++ b/src/postgres/src/backend/utils/init/postinit.c @@ -704,7 +704,7 @@ InitPostgresImpl(const char *in_dbname, Oid dboid, const char *username, * constant throughout the session. We don't want to do this during * bootstrap because it won't have client address anyway. */ - if (IsYugaByteEnabled() && YBEnableAsh() && !bootstrap) + if (IsYugaByteEnabled() && yb_ash_enable_infra && !bootstrap) YbSetAshClientAddrAndPort(); if (IsYugaByteEnabled() && !bootstrap) diff --git a/src/postgres/src/backend/utils/misc/guc.c b/src/postgres/src/backend/utils/misc/guc.c index 135f458c0d0b..6b1861ff005a 100644 --- a/src/postgres/src/backend/utils/misc/guc.c +++ b/src/postgres/src/backend/utils/misc/guc.c @@ -2501,6 +2501,33 @@ static struct config_bool ConfigureNamesBool[] = NULL, NULL, NULL }, + { + {"yb_ash_enable_infra", PGC_POSTMASTER, RESOURCES, + gettext_noop("Allocate shared memory for ASH, start the " + "background worker, create instrumentation hooks " + "and enable querying the yb_active_session_history " + "view."), + NULL, + GUC_NOT_IN_SAMPLE + }, + &yb_ash_enable_infra, + false, + NULL, NULL, NULL + }, + + { + {"yb_enable_ash", PGC_SIGHUP, STATS_COLLECTOR, + gettext_noop("Starts sampling and instrumenting YSQL and YCQL queries, " + "and various background activities. This does nothing if " + "ysql_yb_ash_enable_infra is disabled."), + NULL, + GUC_NOT_IN_SAMPLE + }, + &yb_enable_ash, + false, + yb_enable_ash_check_hook, NULL, NULL + }, + /* End-of-list marker */ { {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL @@ -3946,10 +3973,9 @@ static struct config_int ConfigureNamesInt[] = { {"yb_ash_circular_buffer_size", PGC_POSTMASTER, STATS_MONITORING, - gettext_noop("Size of the circular buffer that stores wait events"), + gettext_noop("Size (in KiBs) of ASH circular buffer that stores the samples"), NULL, - GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | - GUC_DISALLOW_IN_FILE | GUC_UNIT_KB + GUC_UNIT_KB }, &yb_ash_circular_buffer_size, 16 * 1024, 0, INT_MAX, @@ -3957,8 +3983,8 @@ static struct config_int ConfigureNamesInt[] = }, { - {"yb_ash_sampling_interval", PGC_SUSET, STATS_MONITORING, - gettext_noop("Duration between each sample"), + {"yb_ash_sampling_interval", PGC_SIGHUP, STATS_MONITORING, + gettext_noop("Time (in milliseconds) between two consecutive sampling events"), NULL, GUC_UNIT_MS }, @@ -3968,8 +3994,8 @@ static struct config_int ConfigureNamesInt[] = }, { - {"yb_ash_sample_size", PGC_SUSET, STATS_MONITORING, - gettext_noop("Number of wait events captured in each sample"), + {"yb_ash_sample_size", PGC_SIGHUP, STATS_MONITORING, + gettext_noop("Number of samples captured from each component per sampling event"), NULL }, &yb_ash_sample_size, diff --git a/src/postgres/src/backend/utils/misc/pg_yb_utils.c b/src/postgres/src/backend/utils/misc/pg_yb_utils.c index cebbf4d90f72..b6b4a7bfb9d1 100644 --- a/src/postgres/src/backend/utils/misc/pg_yb_utils.c +++ b/src/postgres/src/backend/utils/misc/pg_yb_utils.c @@ -857,10 +857,13 @@ YBInitPostgresBackend( callbacks.ConstructArrayDatum = &YbConstructArrayDatum; callbacks.CheckUserMap = &check_usermap; callbacks.PgstatReportWaitStart = &yb_pgstat_report_wait_start; - YBCInitPgGate(type_table, count, callbacks, session_id, &MyProc->yb_ash_metadata, - &MyProc->yb_is_ash_metadata_set); + YBCPgAshConfig ash_config; + ash_config.metadata = &MyProc->yb_ash_metadata; + ash_config.is_metadata_set = &MyProc->yb_is_ash_metadata_set; + ash_config.yb_enable_ash = &yb_enable_ash; + YBCInitPgGate(type_table, count, callbacks, session_id, &ash_config); YBCInstallTxnDdlHook(); - if (YBEnableAsh()) + if (yb_ash_enable_infra) YbAshInstallHooks(); /* @@ -880,7 +883,7 @@ YBInitPostgresBackend( * mapped to PG backends. */ yb_pgstat_add_session_info(YBCPgGetSessionID()); - if (YBEnableAsh()) + if (yb_ash_enable_infra) YbAshSetSessionId(YBCPgGetSessionID()); } } diff --git a/src/postgres/src/backend/utils/misc/yb_ash.c b/src/postgres/src/backend/utils/misc/yb_ash.c index 4833269f781d..e0cf2b6edebd 100644 --- a/src/postgres/src/backend/utils/misc/yb_ash.c +++ b/src/postgres/src/backend/utils/misc/yb_ash.c @@ -51,6 +51,8 @@ #include "yb/yql/pggate/util/ybc_util.h" /* GUC variables */ +bool yb_ash_enable_infra; +bool yb_enable_ash; int yb_ash_circular_buffer_size; int yb_ash_sampling_interval_ms; int yb_ash_sample_size; @@ -101,6 +103,17 @@ static void uchar_to_uuid(unsigned char *in, pg_uuid_t *out); static void client_ip_to_string(unsigned char *client_addr, uint16 client_port, uint8_t addr_family, char *client_ip); +bool +yb_enable_ash_check_hook(bool *newval, void **extra, GucSource source) +{ + if (*newval && !yb_ash_enable_infra) + { + GUC_check_errdetail("ysql_yb_ash_enable_infra must be enabled."); + return false; + } + return true; +} + void YbAshRegister(void) { @@ -205,11 +218,14 @@ yb_ash_post_parse_analyze(ParseState *pstate, Query *query) * pg_stat_statements does. query_id can also be zero when pg_stat_statements * is disabled, then this field won't be useful for ASH users at all. */ - uint64 query_id = query->queryId != 0 - ? query->queryId - : yb_ash_utility_query_id(pstate->p_sourcetext, query->stmt_len, - query->stmt_location); - yb_set_ash_metadata(query_id); + if (yb_enable_ash) + { + uint64 query_id = query->queryId != 0 + ? query->queryId + : yb_ash_utility_query_id(pstate->p_sourcetext, query->stmt_len, + query->stmt_location); + yb_set_ash_metadata(query_id); + } } static void @@ -219,7 +235,7 @@ yb_ash_ExecutorStart(QueryDesc *queryDesc, int eflags) * In case of prepared statements, the 'Parse' phase might be skipped. * We set the ASH metadata here if it's not been set yet. */ - if (MyProc->yb_is_ash_metadata_set == false) + if (yb_enable_ash && MyProc->yb_is_ash_metadata_set == false) { /* Query id can be zero here only if pg_stat_statements is disabled */ uint64 query_id = queryDesc->plannedstmt->queryId != 0 @@ -248,7 +264,8 @@ yb_ash_ExecutorEnd(QueryDesc *queryDesc) * Unset ASH metadata. Utility statements do not go through this * code path. */ - yb_unset_ash_metadata(); + if (yb_enable_ash) + yb_unset_ash_metadata(); } static void @@ -270,7 +287,7 @@ yb_ash_ProcessUtility(PlannedStmt *pstmt, const char *queryString, * Unset ASH metadata in case of utility statements. This function * might recurse, and we only want to unset in the last step. */ - if (YBGetDdlNestingLevel() == 0) + if (yb_enable_ash && YBGetDdlNestingLevel() == 0) yb_unset_ash_metadata(); } @@ -420,7 +437,7 @@ YbAshMain(Datum main_arg) (errmsg("bgworker yb_ash signal: processed SIGHUP"))); } - if (yb_ash_sample_size > 0) + if (yb_enable_ash && yb_ash_sample_size > 0) { sample_time = GetCurrentTimestamp(); @@ -541,7 +558,7 @@ yb_active_session_history(PG_FUNCTION_ARGS) if (!yb_ash) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("TEST_yb_enable_ash gflag must be enabled"))); + errmsg("ysql_yb_ash_enable_infra gflag must be enabled"))); /* check to see if caller supports us returning a tuplestore */ if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo)) diff --git a/src/postgres/src/common/pg_yb_common.c b/src/postgres/src/common/pg_yb_common.c index ca47cb77c346..bf7bd1ab8aeb 100644 --- a/src/postgres/src/common/pg_yb_common.c +++ b/src/postgres/src/common/pg_yb_common.c @@ -229,13 +229,3 @@ YBColocateDatabaseByDefault() } return cached_value; } - -bool -YBEnableAsh() -{ - static int cached_value = -1; - if (cached_value == -1) - cached_value = YBCIsEnvVarTrue("FLAGS_TEST_yb_enable_ash"); - - return cached_value; -} diff --git a/src/postgres/src/include/common/pg_yb_common.h b/src/postgres/src/include/common/pg_yb_common.h index 551aad05f8be..0c8babb81ef4 100644 --- a/src/postgres/src/include/common/pg_yb_common.h +++ b/src/postgres/src/include/common/pg_yb_common.h @@ -150,9 +150,4 @@ extern const bool kTestOnlyUseOSDefaultCollation; */ extern bool YBColocateDatabaseByDefault(); -/** - * Returns true if Active Session History should be enabled. - */ -extern bool YBEnableAsh(); - #endif /* PG_YB_COMMON_H */ diff --git a/src/postgres/src/include/pgstat.h b/src/postgres/src/include/pgstat.h index bdeb89ee4a75..bfa1e59f91e1 100644 --- a/src/postgres/src/include/pgstat.h +++ b/src/postgres/src/include/pgstat.h @@ -21,6 +21,7 @@ #include "utils/hsearch.h" #include "utils/relcache.h" +#include "yb_ash.h" /* ---------- * Paths for the statistics files (relative to installation's $PGDATA). @@ -1447,6 +1448,10 @@ pgstat_report_wait_end(void) static inline uint32 yb_pgstat_report_wait_start(uint32 wait_event_info) { + /* If ASH is disabled, do nothing */ + if (!yb_enable_ash) + return wait_event_info; + uint32 prev_wait_event_info = 0; volatile PGPROC *proc = MyProc; diff --git a/src/postgres/src/include/yb_ash.h b/src/postgres/src/include/yb_ash.h index 5eed26105590..4645bcd58c20 100644 --- a/src/postgres/src/include/yb_ash.h +++ b/src/postgres/src/include/yb_ash.h @@ -27,9 +27,12 @@ #include "postgres.h" #include "storage/proc.h" +#include "utils/guc.h" #include "utils/timestamp.h" /* GUC variables */ +extern bool yb_ash_enable_infra; +extern bool yb_enable_ash; extern int yb_ash_circular_buffer_size; extern int yb_ash_sampling_interval_ms; extern int yb_ash_sample_size; @@ -47,4 +50,8 @@ extern bool YbAshStoreSample(PGPROC *proc, int num_procs, TimestampTz sample_time, int *samples_stored); +extern bool yb_enable_ash_check_hook(bool *newval, + void **extra, + GucSource source); + #endif /* YB_ASH_H */ diff --git a/src/yb/ash/wait_state.cc b/src/yb/ash/wait_state.cc index da43c33fad60..64098a265852 100644 --- a/src/yb/ash/wait_state.cc +++ b/src/yb/ash/wait_state.cc @@ -19,8 +19,40 @@ #include "yb/util/tostring.h" #include "yb/util/trace.h" -DEFINE_test_flag(bool, yb_enable_ash, false, - "True to enable Active Session History"); +// The reason to include yb_ash_enable_infra in this file and not +// pg_wrapper.cc: +// +// The runtime gFlag yb_enable_ash should only be enabled if the +// non-runtime gFlag yb_ash_enable_infra is true. Postgres GUC +// check framework is used to enforce this check. But if both the flags +// are to be enabled at startup, yb_ash_enable_infra must be registered +// first, otherwise the check will incorrectly fail. +// +// Postmaster processes the list of GUCs twice, once directly from the arrays +// in guc.c and once from the config file that WriteConfigFile() writes into. +// AppendPgGFlags() decides the order of Pg gFlags that are going to be written +// in the same order that GetAllFlags() returns, and GetAllFlags() sorts it +// internally by the filename (which includes some parts of the filepath as well) +// and since this is in the folder 'ash', which is lexicographically smaller than +// the folder 'yql', the flags of this file will be written to the config file +// before the flags of pg_wrapper.cc and, and hence processed first by postmaster. +// In the same file, the flags will be sorted lexicographically based on their +// names, so yb_ash_enable_infra will come before yb_enable_ash. +// +// So, to ensure that the GUC check hook doesn't fail, these two flags are +// defined here. Both the flags are not defined in pg_wrapper.cc since yb_enable_ash +// is required in other parts of the code as well like cql_server.cc and yb_rpc.cc. + +DEFINE_NON_RUNTIME_PG_PREVIEW_FLAG(bool, yb_ash_enable_infra, false, + "Allocate shared memory for ASH, start the background worker, create " + "instrumentation hooks and enable querying the yb_active_session_history " + "view."); + +DEFINE_RUNTIME_PG_PREVIEW_FLAG(bool, yb_enable_ash, false, + "Starts sampling and instrumenting YSQL and YCQL queries, " + "and various background activities. This does nothing if " + "ysql_yb_enable_ash_infra is disabled."); + DEFINE_test_flag(bool, export_wait_state_names, yb::IsDebug(), "Exports wait-state name as a human understandable string."); DEFINE_test_flag(bool, trace_ash_wait_code_updates, yb::IsDebug(), @@ -112,8 +144,8 @@ void AshAuxInfo::UpdateFrom(const AshAuxInfo &other) { } } -WaitStateInfo::WaitStateInfo(AshMetadata &&meta) - : metadata_(std::move(meta)) {} +WaitStateInfo::WaitStateInfo() + : metadata_(AshMetadata{}) {} void WaitStateInfo::set_code(WaitStateCode c) { if (GetAtomicFlag(&FLAGS_TEST_trace_ash_wait_code_updates)) { @@ -198,12 +230,6 @@ const WaitStateInfoPtr& WaitStateInfo::CurrentWaitState() { return threadlocal_wait_state_; } -WaitStateInfoPtr WaitStateInfo::CreateIfAshIsEnabled() { - return yb::GetAtomicFlag(&FLAGS_TEST_yb_enable_ash) - ? std::make_shared(yb::ash::AshMetadata{}) - : nullptr; -} - // // ScopedAdoptWaitState // diff --git a/src/yb/ash/wait_state.h b/src/yb/ash/wait_state.h index 278778b49fd2..688e18763a3e 100644 --- a/src/yb/ash/wait_state.h +++ b/src/yb/ash/wait_state.h @@ -28,6 +28,7 @@ #include "yb/util/net/net_util.h" #include "yb/util/uuid.h" +DECLARE_bool(ysql_yb_enable_ash); DECLARE_bool(TEST_export_wait_state_names); DECLARE_bool(TEST_export_ash_uuids_as_hex_strings); @@ -317,8 +318,7 @@ struct AshAuxInfo { class WaitStateInfo { public: - WaitStateInfo() {} - explicit WaitStateInfo(AshMetadata&& meta); + WaitStateInfo(); virtual ~WaitStateInfo() = default; void set_code(WaitStateCode c); @@ -384,7 +384,12 @@ class WaitStateInfo { void TEST_SleepForTests(uint32_t sleep_time_ms); static bool TEST_EnteredSleep(); - static WaitStateInfoPtr CreateIfAshIsEnabled(); + template + static std::shared_ptr CreateIfAshIsEnabled() { + return FLAGS_ysql_yb_enable_ash + ? std::make_shared() + : nullptr; + } virtual void VTrace(int level, GStringPiece data) { VTraceTo(nullptr, level, data); diff --git a/src/yb/consensus/log.cc b/src/yb/consensus/log.cc index fab16d8cb042..0a972e35367c 100644 --- a/src/yb/consensus/log.cc +++ b/src/yb/consensus/log.cc @@ -437,7 +437,7 @@ Log::Appender::Appender(Log* log, ThreadPool* append_thread_pool) std::bind(&Log::Appender::ProcessBatch, this, _1), append_thread_pool, FLAGS_taskstream_queue_max_size, MonoDelta::FromMilliseconds(FLAGS_taskstream_queue_max_wait_ms))), - wait_state_(ash::WaitStateInfo::CreateIfAshIsEnabled()) { + wait_state_(ash::WaitStateInfo::CreateIfAshIsEnabled()) { if (wait_state_) { wait_state_->set_query_id(yb::to_underlying(yb::ash::FixedQueryId::kQueryIdForLogAppender)); wait_state_->UpdateAuxInfo({.tablet_id = log_->tablet_id(), .method = "RaftWAL"}); diff --git a/src/yb/integration-tests/system_table_fault_tolerance.cc b/src/yb/integration-tests/system_table_fault_tolerance.cc index 0de972c9c3a1..2448a577b374 100644 --- a/src/yb/integration-tests/system_table_fault_tolerance.cc +++ b/src/yb/integration-tests/system_table_fault_tolerance.cc @@ -99,7 +99,7 @@ TEST_F(SystemTableFaultTolerance, TestFaultTolerance) { /* parser_pool= */ nullptr, clock, ql::TransactionPoolProvider()); Synchronizer s; ql::StatementParameters statement_parameters; - ADOPT_WAIT_STATE(ash::WaitStateInfo::CreateIfAshIsEnabled()); + ADOPT_WAIT_STATE(ash::WaitStateInfo::CreateIfAshIsEnabled()); processor->RunAsync("SELECT * from system.peers", statement_parameters, Bind(&SystemTableFaultTolerance::RunAsyncDone, Unretained(this), Bind(&Synchronizer::StatusCB, Unretained(&s)))); diff --git a/src/yb/integration-tests/wait_states-itest.cc b/src/yb/integration-tests/wait_states-itest.cc index 9d352ae7363b..43b5f9f06d41 100644 --- a/src/yb/integration-tests/wait_states-itest.cc +++ b/src/yb/integration-tests/wait_states-itest.cc @@ -46,6 +46,9 @@ using namespace std::literals; +DECLARE_bool(ysql_yb_ash_enable_infra); +DECLARE_bool(ysql_yb_enable_ash); + DECLARE_bool(allow_index_table_read_write); DECLARE_int32(client_read_write_timeout_ms); DECLARE_int32(cql_prepare_child_threshold_ms); @@ -65,7 +68,6 @@ DECLARE_bool(TEST_writequery_stuck_from_callback_leak); DECLARE_int32(TEST_txn_participant_inject_latency_on_apply_update_txn_ms); DECLARE_int32(TEST_inject_mvcc_delay_add_leader_pending_ms); -DECLARE_bool(TEST_yb_enable_ash); DECLARE_uint32(TEST_yb_ash_sleep_at_wait_state_ms); DECLARE_uint32(TEST_yb_ash_wait_code_to_sleep_at); DECLARE_int32(num_concurrent_backfills_allowed); @@ -97,7 +99,8 @@ class WaitStateITest : public pgwrapper::PgMiniTestBase { void SetUp() override { ANNOTATE_UNPROTECTED_WRITE(FLAGS_rpc_slow_query_threshold_ms) = kTimeMultiplier * 10000; - ANNOTATE_UNPROTECTED_WRITE(FLAGS_TEST_yb_enable_ash) = true; + ANNOTATE_UNPROTECTED_WRITE(FLAGS_ysql_yb_ash_enable_infra) = true; + ANNOTATE_UNPROTECTED_WRITE(FLAGS_ysql_yb_enable_ash) = true; ANNOTATE_UNPROTECTED_WRITE(FLAGS_TEST_export_wait_state_names) = true; ANNOTATE_UNPROTECTED_WRITE(FLAGS_collect_end_to_end_traces) = true; pgwrapper::PgMiniTestBase::SetUp(); diff --git a/src/yb/rocksdb/db/compaction_job.cc b/src/yb/rocksdb/db/compaction_job.cc index d34c14e7c012..6c38093f5fd3 100644 --- a/src/yb/rocksdb/db/compaction_job.cc +++ b/src/yb/rocksdb/db/compaction_job.cc @@ -259,7 +259,7 @@ CompactionJob::CompactionJob( earliest_write_conflict_snapshot_(earliest_write_conflict_snapshot), file_numbers_provider_(file_numbers_provider), table_cache_(std::move(table_cache)), - wait_state_(yb::ash::WaitStateInfo::CreateIfAshIsEnabled()), + wait_state_(yb::ash::WaitStateInfo::CreateIfAshIsEnabled()), event_logger_(event_logger), paranoid_file_checks_(paranoid_file_checks), measure_io_stats_(measure_io_stats) { diff --git a/src/yb/rocksdb/db/flush_job.cc b/src/yb/rocksdb/db/flush_job.cc index 029b4ee2c8e5..a43c99f73468 100644 --- a/src/yb/rocksdb/db/flush_job.cc +++ b/src/yb/rocksdb/db/flush_job.cc @@ -118,7 +118,7 @@ FlushJob::FlushJob(const std::string& dbname, ColumnFamilyData* cfd, output_compression_(output_compression), stats_(stats), event_logger_(event_logger), - wait_state_(yb::ash::WaitStateInfo::CreateIfAshIsEnabled()) { + wait_state_(yb::ash::WaitStateInfo::CreateIfAshIsEnabled()) { if (wait_state_) { wait_state_->set_query_id(yb::to_underlying(yb::ash::FixedQueryId::kQueryIdForFlush)); wait_state_->set_rpc_request_id(job_context_->job_id); diff --git a/src/yb/rpc/inbound_call.cc b/src/yb/rpc/inbound_call.cc index b9dd5709af95..e568ed7bf973 100644 --- a/src/yb/rpc/inbound_call.cc +++ b/src/yb/rpc/inbound_call.cc @@ -63,8 +63,6 @@ DEFINE_RUNTIME_int32(rpc_slow_query_threshold_ms, 10000, "Traces for calls that take longer than this threshold (in ms) are logged"); TAG_FLAG(rpc_slow_query_threshold_ms, advanced); -DECLARE_bool(TEST_yb_enable_ash); - namespace yb { namespace rpc { @@ -107,10 +105,7 @@ int64_t NextInstanceId() { InboundCall::InboundCall( ConnectionPtr conn, RpcMetrics* rpc_metrics, CallProcessedListener* call_processed_listener) - : wait_state_( - GetAtomicFlag(&FLAGS_TEST_yb_enable_ash) - ? std::make_shared() - : nullptr), + : wait_state_(ash::WaitStateInfo::CreateIfAshIsEnabled()), trace_holder_(Trace::MaybeGetNewTraceForParent(Trace::CurrentTrace())), trace_(trace_holder_.get()), instance_id_(NextInstanceId()), diff --git a/src/yb/rpc/local_call.cc b/src/yb/rpc/local_call.cc index c9f5b5125874..a08274d8ed54 100644 --- a/src/yb/rpc/local_call.cc +++ b/src/yb/rpc/local_call.cc @@ -25,8 +25,6 @@ #include "yb/util/result.h" #include "yb/util/status_format.h" -DECLARE_bool(TEST_yb_enable_ash); - namespace yb { namespace rpc { diff --git a/src/yb/rpc/yb_rpc.cc b/src/yb/rpc/yb_rpc.cc index e96c486b2d07..690755ce6ca2 100644 --- a/src/yb/rpc/yb_rpc.cc +++ b/src/yb/rpc/yb_rpc.cc @@ -51,7 +51,7 @@ DEFINE_test_flag(uint64, yb_inbound_big_calls_parse_delay_ms, false, "Test flag for simulating slow parsing of inbound calls larger than " "rpc_throttle_threshold_bytes"); -DECLARE_bool(TEST_yb_enable_ash); +DECLARE_bool(ysql_yb_enable_ash); DECLARE_uint64(rpc_connection_timeout_ms); DECLARE_int32(rpc_slow_query_threshold_ms); DECLARE_int64(rpc_throttle_threshold_bytes); @@ -281,7 +281,7 @@ void YBInboundCall::UpdateWaitStateInfo() { .method = method_name().ToBuffer(), }); } else { - LOG_IF(ERROR, GetAtomicFlag(&FLAGS_TEST_yb_enable_ash)) + LOG_IF(ERROR, GetAtomicFlag(&FLAGS_ysql_yb_enable_ash)) << "Wait state is nullptr for " << ToString(); } } diff --git a/src/yb/yql/cql/cqlserver/cql_server.cc b/src/yb/yql/cql/cqlserver/cql_server.cc index 15b4a76f1683..af053c621e9e 100644 --- a/src/yb/yql/cql/cqlserver/cql_server.cc +++ b/src/yb/yql/cql/cqlserver/cql_server.cc @@ -57,7 +57,7 @@ TAG_FLAG(cql_limit_nodelist_refresh_to_subscribed_conns, advanced); DEFINE_UNKNOWN_int64(cql_rpc_memory_limit, 0, "CQL RPC memory limit"); -DECLARE_bool(TEST_yb_enable_ash); +DECLARE_bool(ysql_yb_enable_ash); namespace yb { namespace cqlserver { @@ -92,7 +92,7 @@ CQLServer::CQLServer(const CQLServerOptions& opts, if (tserver_) { tserver_->RegisterCertificateReloader(std::bind(&CQLServer::ReloadKeysAndCertificates, this)); - if (GetAtomicFlag(&FLAGS_TEST_yb_enable_ash) && tserver) { + if (FLAGS_ysql_yb_enable_ash && tserver) { tserver->SetCQLServer(this); } } diff --git a/src/yb/yql/cql/cqlserver/system_query_cache.cc b/src/yb/yql/cql/cqlserver/system_query_cache.cc index 65bba6087a6d..4654c42841c4 100644 --- a/src/yb/yql/cql/cqlserver/system_query_cache.cc +++ b/src/yb/yql/cql/cqlserver/system_query_cache.cc @@ -210,7 +210,7 @@ MonoDelta SystemQueryCache::GetStaleness() { void SystemQueryCache::RefreshCache() { VLOG(1) << "Refreshing system query cache"; - ADOPT_WAIT_STATE(ash::WaitStateInfo::CreateIfAshIsEnabled()); + ADOPT_WAIT_STATE(ash::WaitStateInfo::CreateIfAshIsEnabled()); auto new_cache = std::make_unique>(); for (const auto& query : queries_) { Status status; diff --git a/src/yb/yql/cql/ql/exec/executor.cc b/src/yb/yql/cql/ql/exec/executor.cc index efe34a8c1521..e422163d02c4 100644 --- a/src/yb/yql/cql/ql/exec/executor.cc +++ b/src/yb/yql/cql/ql/exec/executor.cc @@ -76,7 +76,7 @@ #include "yb/yql/cql/ql/util/errcodes.h" #include "yb/util/flags.h" -DECLARE_bool(TEST_yb_enable_ash); +DECLARE_bool(ysql_yb_enable_ash); using namespace std::literals; using namespace std::placeholders; @@ -888,7 +888,7 @@ Status Executor::ExecPTNode(const PTSelectStmt *tnode, TnodeContext* tnode_conte if (const auto& wait_state = ash::WaitStateInfo::CurrentWaitState()) { wait_state->UpdateAuxInfo({.table_id{table->id()}}); } else { - LOG_IF(DFATAL, GetAtomicFlag(&FLAGS_TEST_yb_enable_ash)) << "No wait state here."; + LOG_IF(DFATAL, GetAtomicFlag(&FLAGS_ysql_yb_enable_ash)) << "No wait state here."; } // If there is a table id in the statement parameter's paging state, this is a continuation of a @@ -940,7 +940,7 @@ Status Executor::ExecPTNode(const PTSelectStmt *tnode, TnodeContext* tnode_conte if (const auto& wait_state = ash::WaitStateInfo::CurrentWaitState()) { wait_state->MetadataToPB(req->mutable_ash_metadata()); } else { - LOG_IF(DFATAL, GetAtomicFlag(&FLAGS_TEST_yb_enable_ash)) << "No wait state here."; + LOG_IF(DFATAL, GetAtomicFlag(&FLAGS_ysql_yb_enable_ash)) << "No wait state here."; } // Where clause - Hash, range, and regular columns. @@ -1291,7 +1291,7 @@ Status Executor::ExecPTNode(const PTInsertStmt *tnode, TnodeContext* tnode_conte wait_state->UpdateAuxInfo({.table_id{table->id()}}); wait_state->MetadataToPB(req->mutable_ash_metadata()); } else { - LOG_IF(DFATAL, GetAtomicFlag(&FLAGS_TEST_yb_enable_ash)) << "No wait state here."; + LOG_IF(DFATAL, GetAtomicFlag(&FLAGS_ysql_yb_enable_ash)) << "No wait state here."; } // Set the ttl. @@ -1366,7 +1366,7 @@ Status Executor::ExecPTNode(const PTDeleteStmt *tnode, TnodeContext* tnode_conte wait_state->UpdateAuxInfo({.table_id{table->id()}}); wait_state->MetadataToPB(req->mutable_ash_metadata()); } else { - LOG_IF(DFATAL, GetAtomicFlag(&FLAGS_TEST_yb_enable_ash)) << "No wait state here."; + LOG_IF(DFATAL, GetAtomicFlag(&FLAGS_ysql_yb_enable_ash)) << "No wait state here."; } // Set the timestamp. @@ -2485,7 +2485,7 @@ void Executor::AddOperation(const YBqlReadOpPtr& op, TnodeContext *tnode_context if (const auto& wait_state = ash::WaitStateInfo::CurrentWaitState()) { wait_state->set_rpc_request_id(exec_context_->params().request_id()); } else { - LOG_IF(DFATAL, GetAtomicFlag(&FLAGS_TEST_yb_enable_ash)) << "No wait state here."; + LOG_IF(DFATAL, GetAtomicFlag(&FLAGS_ysql_yb_enable_ash)) << "No wait state here."; } tnode_context->AddOperation(op); diff --git a/src/yb/yql/cql/ql/test/ql-statement-test.cc b/src/yb/yql/cql/ql/test/ql-statement-test.cc index 96de8340ffa3..618d1553f922 100644 --- a/src/yb/yql/cql/ql/test/ql-statement-test.cc +++ b/src/yb/yql/cql/ql/test/ql-statement-test.cc @@ -42,7 +42,7 @@ class TestQLStatement : public QLTestBase { } Status ExecuteAsync(Statement *stmt, QLProcessor *processor, Callback cb) { - ADOPT_WAIT_STATE(ash::WaitStateInfo::CreateIfAshIsEnabled()); + ADOPT_WAIT_STATE(ash::WaitStateInfo::CreateIfAshIsEnabled()); return stmt->ExecuteAsync(processor, StatementParameters(), Bind(&TestQLStatement::ExecuteAsyncDone, Unretained(this), cb)); } diff --git a/src/yb/yql/cql/ql/test/ql-test-base.cc b/src/yb/yql/cql/ql/test/ql-test-base.cc index 92dda2e4739f..a1c70f90c0e8 100644 --- a/src/yb/yql/cql/ql/test/ql-test-base.cc +++ b/src/yb/yql/cql/ql/test/ql-test-base.cc @@ -130,7 +130,7 @@ Status TestQLProcessor::Run(const Statement& stmt, const StatementParameters& pa result_ = nullptr; parse_tree_.reset(); // Delete previous parse tree. - ADOPT_WAIT_STATE(ash::WaitStateInfo::CreateIfAshIsEnabled()); + ADOPT_WAIT_STATE(ash::WaitStateInfo::CreateIfAshIsEnabled()); Synchronizer s; // Reschedule() loop in QLProcessor class is not used here. RETURN_NOT_OK(stmt.ExecuteAsync( @@ -147,7 +147,7 @@ void TestQLProcessor::RunAsyncInternal(const std::string& stmt, const StatementP if (PREDICT_FALSE(!s.ok())) { return cb.Run(s, nullptr /* result */); } - ADOPT_WAIT_STATE(ash::WaitStateInfo::CreateIfAshIsEnabled()); + ADOPT_WAIT_STATE(ash::WaitStateInfo::CreateIfAshIsEnabled()); // Do not make a copy of stmt and params when binding to the RunAsyncDone callback because when // error occurs due to stale matadata, the statement needs to be reexecuted. We should pass the // original references which are guaranteed to still be alive when the statement is reexecuted. diff --git a/src/yb/yql/pggate/pg_client.cc b/src/yb/yql/pggate/pg_client.cc index c3201ea17fef..029ab2fa948f 100644 --- a/src/yb/yql/pggate/pg_client.cc +++ b/src/yb/yql/pggate/pg_client.cc @@ -222,8 +222,7 @@ class PgClient::Impl : public BigDataFetcher { rpc::Scheduler* scheduler, const tserver::TServerSharedObject& tserver_shared_object, std::optional session_id, - const YBCAshMetadata* ash_metadata, - bool* is_ash_metadata_set) { + const YBCPgAshConfig* ash_config) { CHECK_NOTNULL(&tserver_shared_object); MonoDelta resolve_cache_timeout; const auto& tserver_shared_data_ = *tserver_shared_object; @@ -249,9 +248,8 @@ class PgClient::Impl : public BigDataFetcher { LOG_WITH_PREFIX(INFO) << "Session id acquired. Postgres backend pid: " << getpid(); heartbeat_poller_.Start(scheduler, FLAGS_pg_client_heartbeat_interval_ms * 1ms); - ash_metadata_ = ash_metadata; - is_ash_metadata_set_ = is_ash_metadata_set; - memcpy(local_tserver_uuid_, tserver_shared_data_.tserver_uuid(), 16); + ash_config_ = *ash_config; + memcpy(ash_config_.yql_endpoint_tserver_uuid, tserver_shared_data_.tserver_uuid(), 16); return Status::OK(); } @@ -525,18 +523,16 @@ class PgClient::Impl : public BigDataFetcher { tserver::PgPerformOptionsPB* options, PgsqlOps* operations) { auto& arena = operations->front()->arena(); tserver::LWPgPerformRequestPB req(&arena); - - if (FLAGS_TEST_yb_enable_ash) { + if (*ash_config_.yb_enable_ash) { // Don't send ASH metadata if it's not set // ash_metadata_ can be null during tests which directly create the // pggate layer without the PG backend. // session_id is not set here as it's already set in PgPerformRequestPB - if (is_ash_metadata_set_ != nullptr && ash_metadata_ != nullptr && - *is_ash_metadata_set_) { + if (*ash_config_.is_metadata_set) { auto* ash_metadata = options->mutable_ash_metadata(); - ash_metadata->set_yql_endpoint_tserver_uuid(local_tserver_uuid_, 16); - ash_metadata->set_root_request_id(ash_metadata_->root_request_id, 16); - ash_metadata->set_query_id(ash_metadata_->query_id); + ash_metadata->set_yql_endpoint_tserver_uuid(ash_config_.yql_endpoint_tserver_uuid, 16); + ash_metadata->set_root_request_id(ash_config_.metadata->root_request_id, 16); + ash_metadata->set_query_id(ash_config_.metadata->query_id); } } @@ -1072,9 +1068,7 @@ class PgClient::Impl : public BigDataFetcher { std::array tablet_server_count_cache_; MonoDelta timeout_ = FLAGS_yb_client_admin_operation_timeout_sec * 1s; - const YBCAshMetadata* ash_metadata_; - bool* is_ash_metadata_set_; - unsigned char local_tserver_uuid_[16]; + YBCPgAshConfig ash_config_; }; std::string DdlMode::ToString() const { @@ -1096,10 +1090,9 @@ PgClient::~PgClient() = default; Status PgClient::Start( rpc::ProxyCache* proxy_cache, rpc::Scheduler* scheduler, const tserver::TServerSharedObject& tserver_shared_object, - std::optional session_id, const YBCAshMetadata* ash_metadata, - bool* is_ash_metadata_set) { + std::optional session_id, const YBCPgAshConfig* ash_config) { return impl_->Start(proxy_cache, scheduler, tserver_shared_object, session_id, - ash_metadata, is_ash_metadata_set); + ash_config); } void PgClient::Shutdown() { diff --git a/src/yb/yql/pggate/pg_client.h b/src/yb/yql/pggate/pg_client.h index 67afdc81deb3..b71c82a0bce2 100644 --- a/src/yb/yql/pggate/pg_client.h +++ b/src/yb/yql/pggate/pg_client.h @@ -122,8 +122,7 @@ class PgClient { rpc::Scheduler* scheduler, const tserver::TServerSharedObject& tserver_shared_object, std::optional session_id, - const YBCAshMetadata* ash_metadata, - bool* is_ash_metadata_set); + const YBCPgAshConfig* ash_config); void Shutdown(); diff --git a/src/yb/yql/pggate/pg_session.cc b/src/yb/yql/pggate/pg_session.cc index cd903174717c..db06276216c2 100644 --- a/src/yb/yql/pggate/pg_session.cc +++ b/src/yb/yql/pggate/pg_session.cc @@ -221,12 +221,6 @@ Status UpdateReadTime(tserver::PgPerformOptionsPB* options, const ReadHybridTime return Status::OK(); } -// This function is used as a dummy function when the GFlag FLAGS_TEST_yb_enable_ash -// is disabled. This will be removed once the flag is removed. -uint32_t PgstatReportWaitStartNoOp(uint32_t wait_event) { - return wait_event; -} - } // namespace //-------------------------------------------------------------------------------------------------- @@ -396,8 +390,7 @@ PgSession::PgSession( pg_txn_manager_(std::move(pg_txn_manager)), metrics_(stats_state), pg_callbacks_(pg_callbacks), - wait_starter_(FLAGS_TEST_yb_enable_ash - ? pg_callbacks_.PgstatReportWaitStart : &PgstatReportWaitStartNoOp), + wait_starter_(pg_callbacks_.PgstatReportWaitStart), buffer_( [this](BufferableOperations&& ops, bool transactional) { return FlushOperations(std::move(ops), transactional); diff --git a/src/yb/yql/pggate/pggate.cc b/src/yb/yql/pggate/pggate.cc index c7de0663e3cf..5496fd58f785 100644 --- a/src/yb/yql/pggate/pggate.cc +++ b/src/yb/yql/pggate/pggate.cc @@ -493,7 +493,7 @@ Result PgApiImpl::TupleIdBuilder::Build( PgApiImpl::PgApiImpl( PgApiContext context, const YBCPgTypeEntity *YBCDataTypeArray, int count, YBCPgCallbacks callbacks, std::optional session_id, - const YBCAshMetadata *ash_metadata, bool *is_ash_metadata_set) + const YBCPgAshConfig* ash_config) : metric_registry_(std::move(context.metric_registry)), metric_entity_(std::move(context.metric_entity)), mem_tracker_(std::move(context.mem_tracker)), @@ -515,7 +515,7 @@ PgApiImpl::PgApiImpl( CHECK_OK(pg_client_.Start( proxy_cache_.get(), &messenger_holder_.messenger->scheduler(), - tserver_shared_object_, session_id, ash_metadata, is_ash_metadata_set)); + tserver_shared_object_, session_id, ash_config)); } PgApiImpl::~PgApiImpl() { diff --git a/src/yb/yql/pggate/pggate.h b/src/yb/yql/pggate/pggate.h index c972eb284078..286bb1da3352 100644 --- a/src/yb/yql/pggate/pggate.h +++ b/src/yb/yql/pggate/pggate.h @@ -120,7 +120,7 @@ class PgApiImpl { public: PgApiImpl(PgApiContext context, const YBCPgTypeEntity *YBCDataTypeTable, int count, YBCPgCallbacks pg_callbacks, std::optional session_id, - const YBCAshMetadata *ash_metadata, bool *is_ash_metadata_set); + const YBCPgAshConfig* ash_config); ~PgApiImpl(); const YBCPgCallbacks* pg_callbacks() { diff --git a/src/yb/yql/pggate/pggate_flags.cc b/src/yb/yql/pggate/pggate_flags.cc index 1e2e088474ed..f18525185166 100644 --- a/src/yb/yql/pggate/pggate_flags.cc +++ b/src/yb/yql/pggate/pggate_flags.cc @@ -156,5 +156,3 @@ DEFINE_NON_RUNTIME_bool(ysql_enable_create_database_oid_collision_retry, true, TAG_FLAG(ysql_enable_create_database_oid_collision_retry, advanced); DEFINE_NON_RUNTIME_bool(ysql_use_relcache_file, true, "Use relcache init file"); - -DECLARE_bool(TEST_yb_enable_ash); diff --git a/src/yb/yql/pggate/pggate_flags.h b/src/yb/yql/pggate/pggate_flags.h index ffcb81209c10..27a641749ce1 100644 --- a/src/yb/yql/pggate/pggate_flags.h +++ b/src/yb/yql/pggate/pggate_flags.h @@ -47,5 +47,3 @@ DECLARE_bool(TEST_yb_lwlock_crash_after_acquire_pg_stat_statements_reset); DECLARE_bool(ysql_enable_read_request_caching); DECLARE_bool(ysql_enable_create_database_oid_collision_retry); DECLARE_bool(ysql_use_relcache_file); - -DECLARE_bool(TEST_yb_enable_ash); diff --git a/src/yb/yql/pggate/test/pggate_test.cc b/src/yb/yql/pggate/test/pggate_test.cc index 2d123be3b8ba..1bb24a5cd3c8 100644 --- a/src/yb/yql/pggate/test/pggate_test.cc +++ b/src/yb/yql/pggate/test/pggate_test.cc @@ -73,6 +73,13 @@ const char* GetDebugQueryStringStub() { return "GetDebugQueryString not implemented in test"; } +uint32_t PgstatReportWaitStartNoOp(uint32_t wait_event) { + return wait_event; +} + +// Not defined locally in PggateTest::Init to avoid asan use-after-return error +bool yb_enable_ash = false; + } // namespace PggateTest::PggateTest() @@ -143,11 +150,16 @@ Status PggateTest::Init(const char *test_name, int count = 0; YBCTestGetTypeTable(&type_table, &count); YBCPgCallbacks callbacks; + YBCPgAshConfig ash_config; + auto* session_stats = static_cast(PggateTestAlloc(sizeof(YBCPgExecStatsState))); memset(session_stats, 0, sizeof(YBCPgExecStatsState)); callbacks.GetCurrentYbMemctx = &GetCurrentTestYbMemctx; callbacks.GetDebugQueryString = &GetDebugQueryStringStub; + callbacks.PgstatReportWaitStart = &PgstatReportWaitStartNoOp; + + ash_config.yb_enable_ash = &yb_enable_ash; { auto proxy = cluster_->GetProxy(cluster_->tablet_server(0)); @@ -161,7 +173,7 @@ Status PggateTest::Init(const char *test_name, } ANNOTATE_UNPROTECTED_WRITE(FLAGS_pggate_tserver_shm_fd) = tserver_shared_object_.GetFd(); - YBCInitPgGate(type_table, count, callbacks, nullptr, nullptr, nullptr); + YBCInitPgGate(type_table, count, callbacks, nullptr, &ash_config); // Setup session. CHECK_YBC_STATUS(YBCPgInitSession(nullptr /* database_name */, session_stats)); diff --git a/src/yb/yql/pggate/ybc_pg_typedefs.h b/src/yb/yql/pggate/ybc_pg_typedefs.h index 9d2950da8dd9..8da81d3138bd 100644 --- a/src/yb/yql/pggate/ybc_pg_typedefs.h +++ b/src/yb/yql/pggate/ybc_pg_typedefs.h @@ -657,6 +657,14 @@ typedef struct AshSample { uint64_t sample_time; } YBCAshSample; +// A struct to pass ASH postgres config to PgClient +typedef struct PgAshConfig { + YBCAshMetadata* metadata; + bool* is_metadata_set; + bool* yb_enable_ash; + unsigned char yql_endpoint_tserver_uuid[16]; +} YBCPgAshConfig; + typedef struct YBCBindColumn { int attr_num; const YBCPgTypeEntity* type_entity; diff --git a/src/yb/yql/pggate/ybc_pggate.cc b/src/yb/yql/pggate/ybc_pggate.cc index 96868d7513a9..2a4de116c4e2 100644 --- a/src/yb/yql/pggate/ybc_pggate.cc +++ b/src/yb/yql/pggate/ybc_pggate.cc @@ -204,13 +204,12 @@ Status InitPgGateImpl(const YBCPgTypeEntity* data_type_table, int count, const PgCallbacks& pg_callbacks, uint64_t *session_id, - const YBCAshMetadata* ash_metadata, - bool* is_ash_metadata_set) { + const YBCPgAshConfig* ash_config) { auto opt_session_id = session_id ? std::optional(*session_id) : std::nullopt; return WithMaskedYsqlSignals( - [data_type_table, count, &pg_callbacks, opt_session_id, ash_metadata, is_ash_metadata_set] { + [data_type_table, count, &pg_callbacks, opt_session_id, &ash_config] { YBCInitPgGateEx(data_type_table, count, pg_callbacks, nullptr /* context */, opt_session_id, - ash_metadata, is_ash_metadata_set); + ash_config); return static_cast(Status::OK()); }); } @@ -364,7 +363,7 @@ void AshCopyTServerSamples( void YBCInitPgGateEx(const YBCPgTypeEntity *data_type_table, int count, PgCallbacks pg_callbacks, PgApiContext* context, std::optional session_id, - const YBCAshMetadata* ash_metadata, bool *is_ash_metadata_set) { + const YBCPgAshConfig* ash_config) { // TODO: We should get rid of hybrid clock usage in YSQL backend processes (see #16034). // However, this is added to allow simulating and testing of some known bugs until we remove // HybridClock usage. @@ -383,11 +382,10 @@ void YBCInitPgGateEx(const YBCPgTypeEntity *data_type_table, int count, PgCallba pgapi_shutdown_done.exchange(false); if (context) { pgapi = new pggate::PgApiImpl( - std::move(*context), data_type_table, count, pg_callbacks, session_id, ash_metadata, - is_ash_metadata_set); + std::move(*context), data_type_table, count, pg_callbacks, session_id, ash_config); } else { pgapi = new pggate::PgApiImpl(PgApiContext(), data_type_table, count, pg_callbacks, session_id, - ash_metadata, is_ash_metadata_set); + ash_config); } VLOG(1) << "PgGate open"; @@ -396,10 +394,8 @@ void YBCInitPgGateEx(const YBCPgTypeEntity *data_type_table, int count, PgCallba extern "C" { void YBCInitPgGate(const YBCPgTypeEntity *data_type_table, int count, PgCallbacks pg_callbacks, - uint64_t *session_id, const YBCAshMetadata *ash_metadata, - bool *is_ash_metadata_set) { - CHECK_OK(InitPgGateImpl(data_type_table, count, pg_callbacks, session_id, ash_metadata, - is_ash_metadata_set)); + uint64_t *session_id, const YBCPgAshConfig* ash_config) { + CHECK_OK(InitPgGateImpl(data_type_table, count, pg_callbacks, session_id, ash_config)); } void YBCDestroyPgGate() { diff --git a/src/yb/yql/pggate/ybc_pggate.h b/src/yb/yql/pggate/ybc_pggate.h index 1de79d91d1c9..b874ad733af1 100644 --- a/src/yb/yql/pggate/ybc_pggate.h +++ b/src/yb/yql/pggate/ybc_pggate.h @@ -30,7 +30,7 @@ typedef YBCAshSample* (*YBCAshGetNextCircularBufferSlot)(); // functions in this API are called. void YBCInitPgGate(const YBCPgTypeEntity *YBCDataTypeTable, int count, YBCPgCallbacks pg_callbacks, uint64_t *session_id, - const YBCAshMetadata *ash_metadata, bool *is_ash_metadata_set); + const YBCPgAshConfig* ash_config); void YBCDestroyPgGate(); void YBCInterruptPgGate(); @@ -834,7 +834,7 @@ struct PgApiContext; void YBCInitPgGateEx( const YBCPgTypeEntity *data_type_table, int count, YBCPgCallbacks pg_callbacks, PgApiContext *context, std::optional session_id, - const YBCAshMetadata* ash_metadata, bool *is_ash_metadata_set); + const YBCPgAshConfig* ash_config); } // namespace pggate } // namespace yb diff --git a/src/yb/yql/pgwrapper/pg_mini-test.cc b/src/yb/yql/pgwrapper/pg_mini-test.cc index 48ddc8edfe0f..213023ef2253 100644 --- a/src/yb/yql/pgwrapper/pg_mini-test.cc +++ b/src/yb/yql/pgwrapper/pg_mini-test.cc @@ -111,6 +111,9 @@ DECLARE_bool(rocksdb_disable_compactions); DECLARE_uint64(pg_client_session_expiration_ms); DECLARE_uint64(pg_client_heartbeat_interval_ms); +DECLARE_bool(ysql_yb_ash_enable_infra); +DECLARE_bool(ysql_yb_enable_ash); + METRIC_DECLARE_entity(tablet); METRIC_DECLARE_gauge_uint64(aborted_transactions_pending_cleanup); @@ -392,7 +395,8 @@ TEST_F(PgMiniTest, Simple) { class PgMiniAsh : public PgMiniTestSingleNode { public: void SetUp() override { - ANNOTATE_UNPROTECTED_WRITE(FLAGS_TEST_yb_enable_ash) = true; + ANNOTATE_UNPROTECTED_WRITE(FLAGS_ysql_yb_ash_enable_infra) = true; + ANNOTATE_UNPROTECTED_WRITE(FLAGS_ysql_yb_enable_ash) = true; PgMiniTestSingleNode::SetUp(); } }; diff --git a/src/yb/yql/pgwrapper/pg_wrapper.cc b/src/yb/yql/pgwrapper/pg_wrapper.cc index 2daad8702b39..872cf54c0d9e 100644 --- a/src/yb/yql/pgwrapper/pg_wrapper.cc +++ b/src/yb/yql/pgwrapper/pg_wrapper.cc @@ -247,6 +247,15 @@ DEFINE_validator(ysql_yb_xcluster_consistency_level, &ValidateXclusterConsistenc DEFINE_NON_RUNTIME_string(ysql_conn_mgr_warmup_db, "yugabyte", "Database for which warmup needs to be done."); +DEFINE_NON_RUNTIME_PG_FLAG(int32, yb_ash_circular_buffer_size, 16 * 1024, + "Size (in KiBs) of ASH circular buffer that stores the samples"); + +DEFINE_RUNTIME_PG_FLAG(int32, yb_ash_sampling_interval, 1000, + "Time (in milliseconds) between two consecutive sampling events"); + +DEFINE_RUNTIME_PG_FLAG(int32, yb_ash_sample_size, 500, + "Number of samples captured from each component per sampling event"); + using gflags::CommandLineFlagInfo; using std::string; using std::vector;