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

compute_ctl: database_schema should keep process::Child as part of returned value #10273

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
31 changes: 30 additions & 1 deletion compute_tools/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,34 @@ pub async fn get_database_schema(
warn!("pg_dump stderr: {}", line)
}
});
Ok(initial_stream.chain(stdout_reader.map(|res| res.map(|b| b.freeze()))))

prepor marked this conversation as resolved.
Show resolved Hide resolved
#[allow(dead_code)]
struct SchemaStream<S> {
// We keep a reference to the child process to ensure it stays alive
// while the stream is being consumed. When SchemaStream is dropped,
// cmd will be dropped, which triggers kill_on_drop and terminates pg_dump
cmd: tokio::process::Child,
stream: S,
}

impl<S> Stream for SchemaStream<S>
where
S: Stream<Item = Result<bytes::Bytes, std::io::Error>> + Unpin,
{
type Item = Result<bytes::Bytes, std::io::Error>;

fn poll_next(
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Option<Self::Item>> {
Stream::poll_next(std::pin::Pin::new(&mut self.stream), cx)
}
}

let schema_stream = SchemaStream {
cmd,
stream: initial_stream.chain(stdout_reader.map(|res| res.map(|b| b.freeze()))),
};

Ok(schema_stream)
}
2 changes: 1 addition & 1 deletion test_runner/regress/test_compute_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_compute_catalog(neon_simple_env: NeonEnv):
ddl = client.database_schema(database=test_db["name"])

# Check that it looks like a valid PostgreSQL dump
assert "-- PostgreSQL database dump" in ddl
assert "-- PostgreSQL database dump complete" in ddl

# Check that it doesn't contain health_check and migration traces.
# They are only created in system `postgres` database, so by checking
Expand Down
Loading