risingwave_frontend/expr/function_impl/
rw_recovery_status.rs1use std::sync::Arc;
16
17use risingwave_expr::{ExprError, Result, capture_context, function};
18use risingwave_pb::meta::RecoveryStatus;
19
20use super::context::META_CLIENT;
21use crate::meta_client::FrontendMetaClient;
22
23#[function("rw_recovery_status() -> varchar", volatile)]
24async fn rw_recovery_status(writer: &mut impl std::fmt::Write) -> Result<()> {
25 writer
26 .write_str(
27 rw_recovery_status_impl_captured()
28 .await?
29 .as_str_name()
30 .strip_prefix("STATUS_")
31 .unwrap(),
32 )
33 .unwrap();
34 Ok(())
35}
36
37#[function("pg_is_in_recovery() -> boolean", volatile)]
38async fn pg_is_in_recovery() -> Result<bool> {
39 let status = rw_recovery_status_impl_captured().await?;
40 Ok(status != RecoveryStatus::StatusRunning)
41}
42
43#[capture_context(META_CLIENT)]
44async fn rw_recovery_status_impl(
45 meta_client: &Arc<dyn FrontendMetaClient>,
46) -> Result<RecoveryStatus> {
47 meta_client
48 .get_cluster_recovery_status()
49 .await
50 .map_err(|e| ExprError::Internal(e.into()))
51}