add test for restore from local pgdata

This commit is contained in:
anastasia
2021-04-14 19:47:05 +03:00
committed by lubennikovaav
parent 1190030872
commit d7eeaec706
4 changed files with 59 additions and 3 deletions

View File

@@ -260,7 +260,7 @@ impl PostgresNode {
Ok(())
}
fn pgdata(&self) -> PathBuf {
pub fn pgdata(&self) -> PathBuf {
self.env.compute_dir().join(self.name.clone())
}

View File

@@ -54,6 +54,23 @@ impl TestStorageControlPlane {
}
}
pub fn one_page_server_no_start() -> TestStorageControlPlane {
let env = local_env::test_env();
let pserver = Arc::new(PageServerNode {
env: env.clone(),
kill_on_exit: true,
listen_address: None,
});
pserver.init();
TestStorageControlPlane {
wal_acceptors: Vec::new(),
pageserver: pserver,
test_done: AtomicBool::new(false),
}
}
// postgres <-> {wal_acceptor1, wal_acceptor2, ...}
pub fn fault_tolerant(redundancy: usize) -> TestStorageControlPlane {
let env = local_env::test_env();

View File

@@ -3,6 +3,9 @@
use control_plane::compute::ComputeControlPlane;
use control_plane::storage::TestStorageControlPlane;
use std::thread::sleep;
use std::time::Duration;
// XXX: force all redo at the end
// -- restart + seqscan won't read deleted stuff
// -- pageserver api endpoint to check all rels
@@ -109,3 +112,36 @@ fn test_pageserver_multitenancy() {
println!("sum = {}", count);
assert_eq!(count, 15000150000);
}
#[test]
fn test_upload_pageserver_local() {
// Init pageserver that reads WAL directly from that postgres
// Don't start yet
let storage_cplane = TestStorageControlPlane::one_page_server_no_start();
let mut compute_cplane = ComputeControlPlane::local(&storage_cplane.pageserver);
// init postgres node
let node = compute_cplane.new_test_node();
//upload data to pageserver & start it
&storage_cplane
.pageserver
.start_fromdatadir(node.pgdata().to_str().unwrap().to_string())
.unwrap();
sleep(Duration::from_secs(10));
// start postgres node
node.start().unwrap();
// check basic work with table
node.safe_psql(
"postgres",
"CREATE TABLE t(key int primary key, value text)",
);
node.safe_psql(
"postgres",
"INSERT INTO t SELECT generate_series(1,100000), 'payload'",
);
}

View File

@@ -52,7 +52,8 @@ fn main() -> Result<(), io::Error> {
.long("daemonize")
.takes_value(false)
.help("Run in the background"))
.arg(Arg::with_name("restore-from")
.arg(Arg::with_name("restore_from")
.long("restore-from")
.takes_value(true)
.help("Upload data from s3 or datadir"))
.get_matches();
@@ -154,14 +155,16 @@ fn start_pageserver(conf: PageServerConf) -> Result<(), io::Error> {
let mut threads = Vec::new();
info!("starting...");
info!("starting... {}", conf.restore_from);
// Before opening up for connections, restore the latest base backup from S3.
// (We don't persist anything to local disk at the moment, so we need to do
// this at every startup)
if conf.restore_from.eq("s3") {
info!("restore-from s3...");
restore_s3::restore_main(&conf);
} else if conf.restore_from.eq("local") {
info!("restore-from local...");
restore_datadir::restore_main(&conf);
}