Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(risedev): fix log check and startup failure for postgres #18745

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading