Skip to content

Commit 55875c0

Browse files
authored
catalog: Prevent duplicate catalog metrics reg (#23541)
This commit prevents catalog metrics from being registered multiple times and panicking. Resolves #23465
1 parent c93d62f commit 55875c0

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

src/catalog-debug/src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,8 @@ async fn run(args: Args) -> Result<(), anyhow::Error> {
242242
};
243243
let persist_client = persist_clients.open(persist_location).await?;
244244
let organization_id = args.organization_id.expect("required for persist");
245-
Box::new(
246-
persist_backed_catalog_state(persist_client, organization_id, &metrics_registry)
247-
.await,
248-
)
245+
let metrics = Arc::new(mz_catalog::durable::Metrics::new(&metrics_registry));
246+
Box::new(persist_backed_catalog_state(persist_client, organization_id, metrics).await)
249247
}
250248
};
251249

src/catalog/src/durable.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
use async_trait::async_trait;
1313
use std::fmt::Debug;
1414
use std::num::NonZeroI64;
15+
use std::sync::Arc;
1516
use std::time::Duration;
1617
use uuid::Uuid;
1718

1819
use mz_stash::DebugStashFactory;
1920

2021
use crate::durable::debug::{DebugCatalogState, Trace};
2122
pub use crate::durable::error::{CatalogError, DurableCatalogError};
23+
pub use crate::durable::impls::persist::metrics::Metrics;
2224
use crate::durable::impls::persist::PersistHandle;
2325
use crate::durable::impls::shadow::OpenableShadowCatalogState;
2426
use crate::durable::impls::stash::{OpenableConnection, TestOpenableConnection};
@@ -276,9 +278,9 @@ pub fn test_stash_backed_catalog_state(
276278
pub async fn persist_backed_catalog_state(
277279
persist_client: PersistClient,
278280
organization_id: Uuid,
279-
registry: &MetricsRegistry,
281+
metrics: Arc<Metrics>,
280282
) -> PersistHandle {
281-
PersistHandle::new(persist_client, organization_id, registry).await
283+
PersistHandle::new(persist_client, organization_id, metrics).await
282284
}
283285

284286
/// Creates an openable durable catalog state implemented using persist that is meant to be used in
@@ -287,7 +289,8 @@ pub async fn test_persist_backed_catalog_state(
287289
persist_client: PersistClient,
288290
organization_id: Uuid,
289291
) -> PersistHandle {
290-
persist_backed_catalog_state(persist_client, organization_id, &MetricsRegistry::new()).await
292+
let metrics = Arc::new(Metrics::new(&MetricsRegistry::new()));
293+
persist_backed_catalog_state(persist_client, organization_id, metrics).await
291294
}
292295

293296
/// Creates an openable durable catalog state implemented using both the stash and persist, that

src/catalog/src/durable/impls/persist.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// the Business Source License, use of this software will be governed
88
// by the Apache License, Version 2.0.
99

10-
mod metrics;
10+
pub(crate) mod metrics;
1111
pub(crate) mod state_update;
1212

1313
use std::collections::BTreeMap;
@@ -23,7 +23,7 @@ use futures::StreamExt;
2323
use itertools::Itertools;
2424
use mz_audit_log::{VersionedEvent, VersionedStorageUsage};
2525
use mz_ore::collections::CollectionExt;
26-
use mz_ore::metrics::{MetricsFutureExt, MetricsRegistry};
26+
use mz_ore::metrics::MetricsFutureExt;
2727
use mz_ore::now::EpochMillis;
2828
use mz_ore::retry::{Retry, RetryResult};
2929
use mz_ore::{soft_assert, soft_assert_eq, soft_assert_ne};
@@ -103,7 +103,7 @@ impl PersistHandle {
103103
pub(crate) async fn new(
104104
persist_client: PersistClient,
105105
organization_id: Uuid,
106-
registry: &MetricsRegistry,
106+
metrics: Arc<Metrics>,
107107
) -> PersistHandle {
108108
const SEED: usize = 1;
109109
let shard_id = Self::shard_id(organization_id, SEED);
@@ -117,7 +117,6 @@ impl PersistHandle {
117117
)
118118
.await
119119
.expect("invalid usage");
120-
let metrics = Arc::new(Metrics::new(registry));
121120
PersistHandle {
122121
write_handle,
123122
read_handle,

src/environmentd/src/bin/environmentd/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ fn run(mut args: Args) -> Result<(), anyhow::Error> {
946946
},
947947
CatalogKind::Persist => CatalogConfig::Persist {
948948
persist_clients,
949-
metrics_registry: metrics_registry.clone(),
949+
metrics: Arc::new(mz_catalog::durable::Metrics::new(&metrics_registry)),
950950
},
951951
CatalogKind::Shadow => CatalogConfig::Shadow {
952952
url: args.adapter_stash_url.expect("required for shadow catalog"),

src/environmentd/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ pub enum CatalogConfig {
261261
Persist {
262262
/// A process-global cache of (blob_uri, consensus_uri) -> PersistClient.
263263
persist_clients: Arc<PersistClientCache>,
264-
/// Metrics registry.
265-
metrics_registry: MetricsRegistry,
264+
/// Persist catalog metrics.
265+
metrics: Arc<mz_catalog::durable::Metrics>,
266266
},
267267
/// The catalog contents are stored in both persist and the stash and their contents are
268268
/// compared. This is mostly used for testing purposes.
@@ -728,7 +728,7 @@ async fn catalog_opener(
728728
}
729729
CatalogConfig::Persist {
730730
persist_clients,
731-
metrics_registry,
731+
metrics,
732732
} => {
733733
info!("Using persist backed catalog");
734734
let persist_client = persist_clients
@@ -739,7 +739,7 @@ async fn catalog_opener(
739739
mz_catalog::durable::persist_backed_catalog_state(
740740
persist_client,
741741
environment_id.organization_id(),
742-
metrics_registry,
742+
Arc::clone(metrics),
743743
)
744744
.await,
745745
)

0 commit comments

Comments
 (0)