From 2e13a3aa7ab117870b0b46525f65aa5cff0c3e2c Mon Sep 17 00:00:00 2001 From: John Spray Date: Thu, 16 Jan 2025 16:56:44 +0000 Subject: [PATCH] storage controller: handle legacy TenantConf in consistency_check (#10422) ## Problem We were comparing serialized configs from the database with serialized configs from memory. If fields have been added/removed to TenantConfig, this generates spurious consistency errors. This is fine in test environments, but limits the usefulness of this debug API in the field. Closes: https://github.com/neondatabase/neon/issues/10369 ## Summary of changes - Do a decode/encode cycle on the config before comparing it, so that it will have exactly the expected fields. --- storage_controller/src/service.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/storage_controller/src/service.rs b/storage_controller/src/service.rs index 1d85839881..f56b683b9f 100644 --- a/storage_controller/src/service.rs +++ b/storage_controller/src/service.rs @@ -5411,6 +5411,15 @@ impl Service { expect_shards.sort_by_key(|tsp| (tsp.tenant_id.clone(), tsp.shard_number, tsp.shard_count)); + // Because JSON contents of persistent tenants might disagree with the fields in current `TenantConfig` + // definition, we will do an encode/decode cycle to ensure any legacy fields are dropped and any new + // fields are added, before doing a comparison. + for tsp in &mut persistent_shards { + let config: TenantConfig = serde_json::from_str(&tsp.config) + .map_err(|e| ApiError::InternalServerError(e.into()))?; + tsp.config = serde_json::to_string(&config).expect("Encoding config is infallible"); + } + if persistent_shards != expect_shards { tracing::error!("Consistency check failed on shards.");