mirror of
https://github.com/neondatabase/neon.git
synced 2026-06-02 04:50:38 +00:00
Load tenants in list_tenants for testing feature
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
//! This module acts as a switchboard to access different repositories managed by this
|
||||
//! page server.
|
||||
|
||||
use futures::future::join_all;
|
||||
use std::collections::{hash_map, HashMap};
|
||||
use std::ffi::OsStr;
|
||||
use std::path::Path;
|
||||
@@ -610,6 +611,32 @@ pub enum TenantMapListError {
|
||||
///
|
||||
/// Get list of tenants, for the mgmt API
|
||||
///
|
||||
#[cfg(feature = "testing")]
|
||||
pub async fn list_tenants() -> Result<Vec<(TenantId, TenantState)>, TenantMapListError> {
|
||||
let tenants = TENANTS.read().await;
|
||||
match &*tenants {
|
||||
TenantsMap::Initializing => Err(TenantMapListError::Initializing),
|
||||
TenantsMap::Open(m) => Ok(join_all(m.map.iter().map(|(id, tenant)| async {
|
||||
(
|
||||
*id,
|
||||
tenant
|
||||
.get_or_try_init(|| m.try_load_tenant(id))
|
||||
.await
|
||||
.map_or(
|
||||
TenantState::broken_from_reason("Failed to load tenant".to_string()),
|
||||
|t| t.current_state(),
|
||||
),
|
||||
)
|
||||
}))
|
||||
.await),
|
||||
TenantsMap::ShuttingDown(m) => Ok(m
|
||||
.iter()
|
||||
.map(|(id, tenant)| (*id, tenant.current_state()))
|
||||
.collect()),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "testing"))]
|
||||
pub async fn list_tenants() -> Result<Vec<(TenantId, TenantState)>, TenantMapListError> {
|
||||
let tenants = TENANTS.read().await;
|
||||
match &*tenants {
|
||||
|
||||
Reference in New Issue
Block a user