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