Skip to content

Commit

Permalink
fix(risedev): fix log check and startup failure for postgres (#18745)
Browse files Browse the repository at this point in the history
Signed-off-by: Bugen Zhao <[email protected]>
  • Loading branch information
BugenZhao authored Sep 27, 2024
1 parent 2b4e57a commit 1ddf30e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion risedev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ template:
application: "metastore"

# The docker image. Can be overridden to use a different version.
image: "postgres:15-alpine"
image: "postgres:17-alpine"

# If set to true, data will be persisted at data/{id}.
persist-data: true
Expand Down
5 changes: 4 additions & 1 deletion src/risedevtool/src/bin/risedev-dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,10 @@ fn task_main(
risedev::TcpReadyCheckTask::new(c.address.clone(), c.port, c.user_managed)?;
task.execute(&mut ctx)?;
} else {
let mut task = risedev::LogReadyCheckTask::new("ready to accept connections")?;
let mut task = risedev::LogReadyCheckTask::new_all([
"ready to accept connections", // also appears in init process
"listening on IPv4 address", // only appears when ready
])?;
task.execute(&mut ctx)?;
}
ctx.pb
Expand Down
27 changes: 17 additions & 10 deletions src/risedevtool/src/task/task_log_ready_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ use fs_err::File;
use super::{ExecuteContext, Task};
use crate::wait::wait;

/// Check if a log pattern is found in the log output indicating the service is ready.
/// Check if all log patterns are found in the log output indicating the service is ready.
pub struct LogReadyCheckTask {
pattern: String,
patterns: Vec<String>,
}

impl LogReadyCheckTask {
pub fn new(pattern: impl Into<String>) -> Result<Self> {
Ok(Self {
pattern: pattern.into(),
patterns: vec![pattern.into()],
})
}

pub fn new_all(patterns: impl IntoIterator<Item = impl Into<String>>) -> Result<Self> {
Ok(Self {
patterns: patterns.into_iter().map(Into::into).collect(),
})
}
}
Expand All @@ -41,7 +47,7 @@ impl Task for LogReadyCheckTask {
};

ctx.pb.set_message("waiting for ready...");
ctx.wait_log_contains(&self.pattern)
ctx.wait_log_contains(&self.patterns)
.with_context(|| format!("failed to wait for service `{id}` to be ready"))?;

ctx.complete_spin();
Expand All @@ -54,8 +60,7 @@ impl<W> ExecuteContext<W>
where
W: std::io::Write,
{
fn wait_log_contains(&mut self, pattern: impl AsRef<str>) -> anyhow::Result<()> {
let pattern = pattern.as_ref();
fn wait_log_contains(&mut self, patterns: &[String]) -> anyhow::Result<()> {
let log_path = self.log_path().to_path_buf();

let mut content = String::new();
Expand All @@ -68,11 +73,13 @@ where
offset += file.read_to_string(&mut content)?;

// Always going through the whole log file could be stupid, but it's reliable.
if content.contains(pattern) {
Ok(())
} else {
bail!("pattern \"{}\" not found in log", pattern)
for pattern in patterns {
if !content.contains(pattern) {
bail!("pattern \"{}\" not found in log", pattern)
}
}

Ok(())
},
&mut self.log,
self.status_file.as_ref().unwrap(),
Expand Down

0 comments on commit 1ddf30e

Please sign in to comment.