mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-14 08:52:56 +00:00
Implement API for cloning a single timeline inside a safekeeper. Also add API for calculating a sha256 hash of WAL, which is used in tests. `/copy` API works by copying objects inside S3 for all but the last segments, and the last segments are copied on-disk. A special temporary directory is created for a timeline, because copy can take a lot of time, especially for large timelines. After all files segments have been prepared, this directory is mounted to the main tree and timeline is loaded to memory. Some caveats: - large timelines can take a lot of time to copy, because we need to copy many S3 segments - caller should wait for HTTP call to finish indefinetely and don't close the HTTP connection, because it will stop the process, which is not continued in the background - `until_lsn` must be a valid LSN, otherwise bad things can happen - API will return 200 if specified `timeline_id` already exists, even if it's not a copy - each safekeeper will try to copy S3 segments, so it's better to not call this API in-parallel on different safekeepers
60 lines
1.7 KiB
Rust
60 lines
1.7 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
use utils::{
|
|
id::{NodeId, TenantId, TimelineId},
|
|
lsn::Lsn,
|
|
};
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
pub struct TimelineCreateRequest {
|
|
pub tenant_id: TenantId,
|
|
pub timeline_id: TimelineId,
|
|
pub peer_ids: Option<Vec<NodeId>>,
|
|
pub pg_version: u32,
|
|
pub system_id: Option<u64>,
|
|
pub wal_seg_size: Option<u32>,
|
|
pub commit_lsn: Lsn,
|
|
// If not passed, it is assigned to the beginning of commit_lsn segment.
|
|
pub local_start_lsn: Option<Lsn>,
|
|
}
|
|
|
|
fn lsn_invalid() -> Lsn {
|
|
Lsn::INVALID
|
|
}
|
|
|
|
/// Data about safekeeper's timeline, mirrors broker.proto.
|
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
pub struct SkTimelineInfo {
|
|
/// Term.
|
|
pub term: Option<u64>,
|
|
/// Term of the last entry.
|
|
pub last_log_term: Option<u64>,
|
|
/// LSN of the last record.
|
|
#[serde(default = "lsn_invalid")]
|
|
pub flush_lsn: Lsn,
|
|
/// Up to which LSN safekeeper regards its WAL as committed.
|
|
#[serde(default = "lsn_invalid")]
|
|
pub commit_lsn: Lsn,
|
|
/// LSN up to which safekeeper has backed WAL.
|
|
#[serde(default = "lsn_invalid")]
|
|
pub backup_lsn: Lsn,
|
|
/// LSN of last checkpoint uploaded by pageserver.
|
|
#[serde(default = "lsn_invalid")]
|
|
pub remote_consistent_lsn: Lsn,
|
|
#[serde(default = "lsn_invalid")]
|
|
pub peer_horizon_lsn: Lsn,
|
|
#[serde(default = "lsn_invalid")]
|
|
pub local_start_lsn: Lsn,
|
|
/// A connection string to use for WAL receiving.
|
|
#[serde(default)]
|
|
pub safekeeper_connstr: Option<String>,
|
|
#[serde(default)]
|
|
pub http_connstr: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
pub struct TimelineCopyRequest {
|
|
pub target_timeline_id: TimelineId,
|
|
pub until_lsn: Lsn,
|
|
}
|