Add --tenant-id and --timeline-id options

This commit is contained in:
Heikki Linnakangas
2024-09-12 13:28:12 +03:00
parent abed35589b
commit fe975acc71
3 changed files with 22 additions and 11 deletions

View File

@@ -2,8 +2,11 @@ use anyhow;
use camino::Utf8PathBuf;
use clap::Parser;
use pageserver::{pg_import, virtual_file::{self, api::IoEngineKind}};
use utils::id::{TenantId, TimelineId};
use utils::logging::{self, LogFormat, TracingErrorLayerEnablement};
use std::str::FromStr;
//project_git_version!(GIT_VERSION);
#[derive(Parser)]
@@ -18,6 +21,11 @@ struct CliOpts {
/// Path to local dir where the layer files will be stored
dest_path: Utf8PathBuf,
#[arg(long, default_value_t = TenantId::from_str("42424242424242424242424242424242").unwrap())]
tenant_id: TenantId,
#[arg(long, default_value_t = TimelineId::from_str("42424242424242424242424242424242").unwrap())]
timeline_id: TimelineId,
}
fn main() -> anyhow::Result<()> {
@@ -45,7 +53,9 @@ fn main() -> anyhow::Result<()> {
}
async fn async_main(cli: CliOpts) -> anyhow::Result<()> {
let mut import = pg_import::PgImportEnv::init().await?;
import.import_datadir(&cli.pgdata, &cli.dest_path).await?;
let mut import = pg_import::PgImportEnv::init(&cli.dest_path, cli.tenant_id, cli.timeline_id).await?;
import.import_datadir(&cli.pgdata).await?;
Ok(())
}

View File

@@ -1,4 +1,4 @@
use std::{fs::metadata, path::Path, str::FromStr};
use std::{fs::metadata, path::Path};
use anyhow::{bail, ensure, Context};
use bytes::Bytes;
@@ -27,20 +27,18 @@ pub struct PgImportEnv {
impl PgImportEnv {
pub async fn init() -> anyhow::Result<PgImportEnv> {
pub async fn init(dstdir: &Utf8Path, tenant_id: TenantId, timeline_id: TimelineId) -> anyhow::Result<PgImportEnv> {
let ctx: RequestContext = RequestContext::new(TaskKind::DebugTool, DownloadBehavior::Error);
let config = toml_edit::Document::new();
let conf = PageServerConf::parse_and_validate(
NodeId(42),
&config,
&Utf8PathBuf::from("layers")
dstdir
)?;
let conf = Box::leak(Box::new(conf));
let tni = TenantId::from_str("42424242424242424242424242424242")?;
let tli = TimelineId::from_str("42424242424242424242424242424242")?;
let tsi = TenantShardId {
tenant_id: tni,
tenant_id,
shard_number: ShardNumber(0),
shard_count: ShardCount(0),
};
@@ -48,16 +46,18 @@ impl PgImportEnv {
Ok(PgImportEnv {
ctx,
conf,
tli,
tli: timeline_id,
tsi,
})
}
pub async fn import_datadir(&mut self, pgdata_path: &Utf8Path, _tenant_path: &Utf8Path) -> anyhow::Result<()> {
pub async fn import_datadir(&mut self, pgdata_path: &Utf8Path) -> anyhow::Result<()> {
let pgdata_lsn = import_datadir::get_lsn_from_controlfile(&pgdata_path)?.align();
println!("Importing {pgdata_path} to {_tenant_path} as lsn {pgdata_lsn}...");
let timeline_path = self.conf.timeline_path(&self.tsi, &self.tli);
println!("Importing {pgdata_path} to {timeline_path} as lsn {pgdata_lsn}...");
let range = Key::MIN..Key::NON_L0_MAX;
let mut one_big_layer = ImageLayerWriter::new(

View File

@@ -51,6 +51,7 @@ def test_pg_import(test_output_dir, pg_bin, vanilla_pg, neon_env_builder):
timeline_id = TimelineId.generate()
tline_path = env.pageserver_remote_storage.timeline_path(tenant_id, timeline_id)
tline_path.mkdir(parents=True)
cli = ImportCli(env)
cli.run_import(vanilla_pg.pgdatadir, tline_path)