fixed most of the errors preventing it from building

This commit is contained in:
Alek Westover
2023-06-06 16:33:08 -04:00
parent fb6a942665
commit bf033294b1
6 changed files with 96 additions and 22 deletions

View File

@@ -60,7 +60,7 @@ fn main() -> Result<()> {
let matches = cli().get_matches();
let config = get_S3_config(matches);
download_extension(matches, ExtensionType::Shared);
download_extension(&matches, ExtensionType::Shared);
let http_port = *matches
.get_one::<u16>("http-port")
@@ -206,7 +206,7 @@ fn main() -> Result<()> {
let mut state = compute.state.lock().unwrap();
// Now we have the spec, and also the tenant id, so we can download the user's personal extensions
// download_extension(matches, ExtensionType::Tenant(FIXME tenant_id.into()));
// download_extension(&matches, ExtensionType::Tenant(FIXME tenant_id.into()));
// Record for how long we slept waiting for the spec.
state.metrics.wait_for_spec_ms = Utc::now()
@@ -228,7 +228,7 @@ fn main() -> Result<()> {
launch_configurator(&compute).expect("cannot launch configurator thread");
// Now we are ready to download library extensions
// download_extension(matches, ExtensionType::Library(FIXME library_name.into()));
// download_extension(&matches, ExtensionType::Library(FIXME library_name.into()));
// Start Postgres
let mut delay_exit = false;

View File

@@ -13,3 +13,4 @@ pub mod monitor;
pub mod params;
pub mod pg_helpers;
pub mod spec;
pub mod pg_extensions;

View File

@@ -1,6 +1,8 @@
// This is some code for downloading postgres extensions from AWS S3
use std::{env, ops::ControlFlow, path::Path, str::FromStr};
use clap::{Arg, ArgAction, Command};
use std::{ops::ControlFlow, path::Path};
use clap::{ArgMatches};
use tracing::*;
use remote_storage::*;
fn get_pg_config(argument: &str) -> String {
// NOTE: this function panics if it runs into any issues;
@@ -15,13 +17,13 @@ fn get_pg_config(argument: &str) -> String {
stdout.trim().to_string()
}
fn download_helper(config: RemoteStorageConfig, from_path: &str, to_path: &str) -> anyhow::Result<()> {
fn download_helper(config: &RemoteStorageConfig, from_path: &str, to_path: &str) -> anyhow::Result<()> {
let mut remote_storage = GenericRemoteStorage::from_config(config)?;
let data = remote_storage.download(remote_path);
// TODO: write "data" to "to_path"
println("received data");
println!("{:?}", data);
Ok(());
let remote_from_path = RemotePath::new(Path::new(from_path))?;
let data = remote_storage.download(&remote_from_path);
println!("received data, hopefully");
Ok(())
// TODO: somehow write "data" to "to_path"
}
pub enum ExtensionType {
@@ -31,40 +33,41 @@ pub enum ExtensionType {
}
// TODO: should I make this async?
pub fn download_extension(config: RemoteStorageConfig, ext_type: ExtensionType) -> anyhow::Result<()>{
pub fn download_extension(config: &RemoteStorageConfig, ext_type: ExtensionType) -> anyhow::Result<()>{
let sharedir = get_pg_config("--sharedir");
let sharedir = format!("{}/extension", sharedir);
let libdir = get_pg_config("--libdir");
match ext_type {
Shared => {
ExtensionType::Shared => {
// 1. Download control files from s3-bucket/public/*.control to SHAREDIR/extension
// We can do this step even before we have spec,
// because public extensions are common for all projects.
let from_path = "s3-bucket/public/*.control"
download_helper(config, from_path, sharedir);
let from_path = "s3-bucket/public/*.control";
download_helper(config, from_path, &sharedir);
}
Tenant(tenant_id) => {
ExtensionType::Tenant(tenant_id) => {
// 2. After we have spec, before project start
// Download control files from s3-bucket/[tenant-id]/*.control to SHAREDIR/extension
let from_path = format!("s3-bucket/{tenant_id}/*.control");
download_helper(config, from_path, sharedir);
download_helper(config, &from_path, &sharedir);
}
Library(library_name) => {
ExtensionType::Library(library_name) => {
// 3. After we have spec, before postgres start
// Download preload_shared_libraries from s3-bucket/public/[library-name].control into LIBDIR/
let from_path = format!("s3-bucket/public/{library_name}.control");
download_helper(config, from_path, libdir);
download_helper(config, &from_path, &libdir);
}
}
Ok(())
}
pub get_S3_config(arg_matches: ArgMatches) -> anyhow::Result<RemoteStorageConfig> {
pub fn get_S3_config(arg_matches: ArgMatches) -> anyhow::Result<RemoteStorageConfig> {
let workdir = arg_matches
.get_one::<String>("workdir")
.map(Path::new)
.unwrap_or_else(|| Path::new(".neon"))
.canonicalize()
.unwrap_or_else(|| Path::new(".neon"));
workdir = workdir.canonicalize()
.with_context(|| format!("Error opening workdir '{}'", workdir.display()))?;
// TODO: is this the correct file location?