From 043408a88df82619215ae7f97a97991310cf7d83 Mon Sep 17 00:00:00 2001 From: Suhas Thalanki Date: Thu, 24 Jul 2025 17:58:09 -0400 Subject: [PATCH] fixed PR, removed spillover content from other PRs --- libs/walproposer/src/api_bindings.rs | 3 -- pgxn/neon/neon_perf_counters.c | 48 ---------------------------- pgxn/neon/neon_perf_counters.h | 1 - pgxn/neon/walproposer.h | 6 ---- 4 files changed, 58 deletions(-) diff --git a/libs/walproposer/src/api_bindings.rs b/libs/walproposer/src/api_bindings.rs index b6c1d7e48e..c3be1e1dae 100644 --- a/libs/walproposer/src/api_bindings.rs +++ b/libs/walproposer/src/api_bindings.rs @@ -450,9 +450,6 @@ pub fn empty_shmem() -> crate::bindings::WalproposerShmemState { replica_promote: false, min_ps_feedback: empty_feedback, wal_rate_limiter: empty_wal_rate_limiter, - num_safekeepers: 0, - safekeeper_status: [0; 32], - safekeeper_commit_lsn: [0; 32], } } diff --git a/pgxn/neon/neon_perf_counters.c b/pgxn/neon/neon_perf_counters.c index f8ce62b1a9..a38f876a0c 100644 --- a/pgxn/neon/neon_perf_counters.c +++ b/pgxn/neon/neon_perf_counters.c @@ -45,7 +45,6 @@ DatabricksMetricsShmemInit(void) pg_atomic_init_u32(&databricks_metrics_shared->index_corruption_count, 0); pg_atomic_init_u32(&databricks_metrics_shared->data_corruption_count, 0); pg_atomic_init_u32(&databricks_metrics_shared->internal_error_count, 0); - pg_atomic_init_u32(&databricks_metrics_shared->ps_corruption_detected, 0); } } /* END_HADRON */ @@ -428,12 +427,6 @@ neon_get_perf_counters(PG_FUNCTION_ARGS) if (lakebase_mode) { - /* BEGIN_HADRON */ - WalproposerShmemState *wp_shmem; - uint32 num_safekeepers; - uint32 num_active_safekeepers; - XLogRecPtr max_active_safekeeper_commit_lag; - if (databricks_test_hook == TestHookCorruption) { ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), @@ -442,52 +435,11 @@ neon_get_perf_counters(PG_FUNCTION_ARGS) // Not ideal but piggyback our databricks counters into the neon perf counters view // so that we don't need to introduce neon--1.x+1.sql to add a new view. - { - // Keeping this code in its own block to work around the C90 "don't mix declarations and code" rule when we define - // the `databricks_metrics` array in the next block. Yes, we are seriously dealing with C90 rules in 2025. - - // Read safekeeper status from wal proposer shared memory first. - // Note that we are taking a mutex when reading from walproposer shared memory so that the total safekeeper count is - // consistent with the active wal acceptors count. Assuming that we don't query this view too often the mutex should - // not be a huge deal. - XLogRecPtr min_commit_lsn = InvalidXLogRecPtr; - XLogRecPtr max_commit_lsn = InvalidXLogRecPtr; - XLogRecPtr lsn; - - wp_shmem = GetWalpropShmemState(); - SpinLockAcquire(&wp_shmem->mutex); - - num_safekeepers = wp_shmem->num_safekeepers; - num_active_safekeepers = 0; - for (int i = 0; i < num_safekeepers; i++) { - if (wp_shmem->safekeeper_status[i] == 1) { - num_active_safekeepers++; - // Only track the commit LSN lag among active safekeepers. - // If there are inactive safekeepers we will raise another alert so this lag value - // is less critical. - lsn = wp_shmem->safekeeper_commit_lsn[i]; - if (XLogRecPtrIsInvalid(min_commit_lsn) || lsn < min_commit_lsn) { - min_commit_lsn = lsn; - } - if (XLogRecPtrIsInvalid(max_commit_lsn) || lsn > max_commit_lsn) { - max_commit_lsn = lsn; - } - } - } - // Calculate max commit LSN lag across active safekeepers - max_active_safekeeper_commit_lag = (XLogRecPtrIsInvalid(min_commit_lsn) ? 0 : max_commit_lsn - min_commit_lsn); - - SpinLockRelease(&wp_shmem->mutex); - } { metric_t databricks_metrics[] = { {"sql_index_corruption_count", false, 0, (double) pg_atomic_read_u32(&databricks_metrics_shared->index_corruption_count)}, {"sql_data_corruption_count", false, 0, (double) pg_atomic_read_u32(&databricks_metrics_shared->data_corruption_count)}, {"sql_internal_error_count", false, 0, (double) pg_atomic_read_u32(&databricks_metrics_shared->internal_error_count)}, - {"ps_corruption_detected", false, 0, (double) pg_atomic_read_u32(&databricks_metrics_shared->ps_corruption_detected)}, - {"num_active_safekeepers", false, 0.0, (double) num_active_safekeepers}, - {"num_configured_safekeepers", false, 0.0, (double) num_safekeepers}, - {"max_active_safekeeper_commit_lag", false, 0.0, (double) max_active_safekeeper_commit_lag}, {NULL, false, 0, 0}, }; for (int i = 0; databricks_metrics[i].name != NULL; i++) diff --git a/pgxn/neon/neon_perf_counters.h b/pgxn/neon/neon_perf_counters.h index 6a6e16cd26..5062340cae 100644 --- a/pgxn/neon/neon_perf_counters.h +++ b/pgxn/neon/neon_perf_counters.h @@ -187,7 +187,6 @@ typedef struct pg_atomic_uint32 index_corruption_count; pg_atomic_uint32 data_corruption_count; pg_atomic_uint32 internal_error_count; - pg_atomic_uint32 ps_corruption_detected; } databricks_metrics; extern databricks_metrics *databricks_metrics_shared; diff --git a/pgxn/neon/walproposer.h b/pgxn/neon/walproposer.h index a51133d897..5507294c3b 100644 --- a/pgxn/neon/walproposer.h +++ b/pgxn/neon/walproposer.h @@ -430,12 +430,6 @@ typedef struct WalproposerShmemState /* BEGIN_HADRON */ /* The WAL rate limiter */ WalRateLimiter wal_rate_limiter; - /* Number of safekeepers in the config */ - uint32 num_safekeepers; - /* Per-safekeeper status flags: 0=inactive, 1=active */ - uint8 safekeeper_status[MAX_SAFEKEEPERS]; - /* Per-safekeeper commit LSN for metrics */ - XLogRecPtr safekeeper_commit_lsn[MAX_SAFEKEEPERS]; /* END_HADRON */ } WalproposerShmemState;