mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-29 19:10:38 +00:00
Issue #144: Refactor errors handling during branches tree printing
This commit is contained in:
committed by
Stas Kelvich
parent
0ec56cd21f
commit
b5f60f3874
@@ -118,7 +118,10 @@ pub fn init_repo(conf: &PageServerConf, repo_dir: &Path) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn get_branches(repository: &dyn Repository) -> Result<Vec<BranchInfo>> {
|
||||
pub(crate) fn get_branches(
|
||||
conf: &PageServerConf,
|
||||
repository: &dyn Repository,
|
||||
) -> Result<Vec<BranchInfo>> {
|
||||
// Each branch has a corresponding record (text file) in the refs/branches
|
||||
// with timeline_id.
|
||||
let branches_dir = std::path::Path::new("refs").join("branches");
|
||||
@@ -134,9 +137,7 @@ pub(crate) fn get_branches(repository: &dyn Repository) -> Result<Vec<BranchInfo
|
||||
.map(|timeline| timeline.get_last_valid_lsn())
|
||||
.ok();
|
||||
|
||||
let ancestor_path = std::path::Path::new("timelines")
|
||||
.join(timeline_id.to_string())
|
||||
.join("ancestor");
|
||||
let ancestor_path = conf.ancestor_path(timeline_id);
|
||||
let mut ancestor_id: Option<String> = None;
|
||||
let mut ancestor_lsn: Option<String> = None;
|
||||
|
||||
@@ -144,8 +145,18 @@ pub(crate) fn get_branches(repository: &dyn Repository) -> Result<Vec<BranchInfo
|
||||
let ancestor = std::fs::read_to_string(ancestor_path)?;
|
||||
let mut strings = ancestor.split('@');
|
||||
|
||||
ancestor_id = Some(strings.next().unwrap().to_owned());
|
||||
ancestor_lsn = Some(strings.next().unwrap().to_owned());
|
||||
ancestor_id = Some(
|
||||
strings
|
||||
.next()
|
||||
.with_context(|| "wrong branch ancestor point in time format")?
|
||||
.to_owned(),
|
||||
);
|
||||
ancestor_lsn = Some(
|
||||
strings
|
||||
.next()
|
||||
.with_context(|| "wrong branch ancestor point in time format")?
|
||||
.to_owned(),
|
||||
);
|
||||
}
|
||||
|
||||
Ok(BranchInfo {
|
||||
|
||||
@@ -59,6 +59,10 @@ impl PageServerConf {
|
||||
self.timeline_path(timelineid).join("snapshots")
|
||||
}
|
||||
|
||||
fn ancestor_path(&self, timelineid: ZTimelineId) -> PathBuf {
|
||||
self.timeline_path(timelineid).join("ancestor")
|
||||
}
|
||||
|
||||
//
|
||||
// Postgres distribution paths
|
||||
//
|
||||
|
||||
@@ -763,7 +763,8 @@ impl Connection {
|
||||
self.write_message_noflush(&BeMessage::DataRow(Bytes::from(branch)))?;
|
||||
self.write_message_noflush(&BeMessage::CommandComplete)?;
|
||||
} else if query_string.starts_with(b"branch_list") {
|
||||
let branches = crate::branches::get_branches(&*page_cache::get_repository())?;
|
||||
let branches =
|
||||
crate::branches::get_branches(&self.conf, &*page_cache::get_repository())?;
|
||||
let branches_buf = serde_json::to_vec(&branches)?;
|
||||
|
||||
self.write_message_noflush(&BeMessage::RowDescription)?;
|
||||
|
||||
Reference in New Issue
Block a user