Skip to content

Commit c48e368

Browse files
committed
Fix metastore read replica startup routing
1 parent 6a05637 commit c48e368

1 file changed

Lines changed: 24 additions & 17 deletions

File tree

  • quickwit/quickwit-serve/src

quickwit/quickwit-serve/src/lib.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,23 @@ fn build_metastore_client_from_balance_channel(
174174
)
175175
}
176176

177+
async fn metastore_balance_channel(
178+
cluster: &Cluster,
179+
) -> anyhow::Result<BalanceChannel<SocketAddr>> {
180+
info!("connecting to metastore");
181+
182+
let balance_channel = balance_channel_for_service(cluster, QuickwitService::Metastore).await;
183+
if !balance_channel
184+
.wait_for(Duration::from_secs(300), |connections| {
185+
!connections.is_empty()
186+
})
187+
.await
188+
{
189+
bail!("could not find any metastore node in the cluster");
190+
}
191+
Ok(balance_channel)
192+
}
193+
177194
static CP_GRPC_CLIENT_METRICS_LAYER: LazyLock<GrpcMetricsLayer> =
178195
LazyLock::new(|| GrpcMetricsLayer::new("control_plane", "client"));
179196
static CP_GRPC_SERVER_METRICS_LAYER: LazyLock<GrpcMetricsLayer> =
@@ -550,19 +567,7 @@ pub async fn serve_quickwit(
550567
if let Some(metastore_server) = &metastore_server_opt {
551568
metastore_server.clone()
552569
} else {
553-
info!("connecting to metastore");
554-
555-
let balance_channel =
556-
balance_channel_for_service(&cluster, QuickwitService::Metastore).await;
557-
558-
if !balance_channel
559-
.wait_for(Duration::from_secs(300), |connections| {
560-
!connections.is_empty()
561-
})
562-
.await
563-
{
564-
bail!("could not find any metastore node in the cluster");
565-
}
570+
let balance_channel = metastore_balance_channel(&cluster).await?;
566571
build_metastore_client_from_balance_channel(
567572
balance_channel,
568573
grpc_config.max_message_size,
@@ -722,11 +727,13 @@ pub async fn serve_quickwit(
722727
};
723728

724729
let searcher_metastore_client: MetastoreReadServiceClient =
725-
if node_config.metastore_read_replica_uri.is_some() {
726-
let balance_channel =
727-
balance_channel_for_service(&cluster, QuickwitService::Metastore).await;
730+
if let Some(metastore_read_replica_server) = &metastore_read_replica_server_opt {
731+
Arc::new(metastore_read_replica_server.clone())
732+
} else if node_config.metastore_read_replica_uri.is_some() {
733+
let balance_channel = metastore_balance_channel(&cluster).await?;
728734
// The read-replica header is honored at the metastore gRPC server boundary,
729-
// so read-only callers must use a remote metastore client when a replica exists.
735+
// so remote read-only callers must use a remote metastore client when a
736+
// replica exists.
730737
let metastore_read_only_client = build_metastore_client_from_balance_channel(
731738
balance_channel,
732739
grpc_config.max_message_size,

0 commit comments

Comments
 (0)