From 0875c2284cf9251a8e3e88732162f9bd07ea2004 Mon Sep 17 00:00:00 2001 From: Anastasia Lubennikova Date: Wed, 28 Jun 2023 18:15:56 +0300 Subject: [PATCH] Fix shared_preload_libraries parsing. Don't try to download already existing shared_preload_libraries files --- compute_tools/src/compute.rs | 46 ++++++++++++++++++++------- compute_tools/src/extension_server.rs | 15 ++++++++- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/compute_tools/src/compute.rs b/compute_tools/src/compute.rs index 70dba0a14f..d421b08cee 100644 --- a/compute_tools/src/compute.rs +++ b/compute_tools/src/compute.rs @@ -688,24 +688,48 @@ LIMIT 100", // 2. parse shared_preload_libraries from spec let mut libs_vec = Vec::new(); - info!("shared_preload_libraries is set to {:?}", libs_vec); if let Some(libs) = spec.cluster.settings.find("shared_preload_libraries") { libs_vec = libs - .split(',') - .filter(|s| *s != "neon") + .split(&[',', '\'', ' ']) + .filter(|s| *s != "neon" && !s.is_empty()) .map(str::to_string) .collect(); } - // TODO write a proper test for this - // Currently pytest doesn't pass cluster settings to compute_ctl - // We need to add this to pytest. - // and neon_local pass to spec - // info!( - // "shared_preload_libraries extra settings set to {:?}", - // libs_vec - // ); + info!( + "shared_preload_libraries parsed from spec.cluster.settings: {:?}", + libs_vec + ); + + // also parse shared_preload_libraries from provided postgresql.conf + // that is used in neon_local and python tests + if let Some(conf) = &spec.cluster.postgresql_conf { + let conf_lines = conf.split('\n').collect::>(); + + let mut shared_preload_libraries_line = ""; + for line in conf_lines { + if line.starts_with("shared_preload_libraries") { + shared_preload_libraries_line = line; + } + } + + let mut preload_libs_vec = Vec::new(); + if let Some(libs) = shared_preload_libraries_line.split("='").nth(1) { + preload_libs_vec = libs + .split(&[',', '\'', ' ']) + .filter(|s| *s != "neon" && !s.is_empty()) + .map(str::to_string) + .collect(); + } + + info!( + "shared_preload_libraries parsed from spec.cluster.postgresql_conf: {:?}", + preload_libs_vec + ); + + libs_vec.extend(preload_libs_vec.clone()); + } // download extension control files & shared_preload_libraries diff --git a/compute_tools/src/extension_server.rs b/compute_tools/src/extension_server.rs index dcdc0ff24a..9d7edfd5c3 100644 --- a/compute_tools/src/extension_server.rs +++ b/compute_tools/src/extension_server.rs @@ -66,6 +66,11 @@ async fn download_helper( None => download_location.join(remote_from_path.object_name().expect("bad object")), }; + if local_path.exists() { + info!("File {:?} already exists. Skipping download", &local_path); + return Ok(()); + } + info!( "Downloading {:?} to location {:?}", &remote_from_path, &local_path @@ -171,11 +176,19 @@ pub async fn get_available_libraries( // add file extension if it isn't in the filename let lib_name_with_ext = enforce_so_end(&lib_name); info!("looking for library {:?}", &lib_name_with_ext); + match all_available_libraries.get(&*lib_name_with_ext) { Some(remote_path) => { download_helper(remote_storage, remote_path, None, &local_libdir).await? } - None => bail!("Shared library file {lib_name} is not found in the extension store"), + None => { + let file_path = local_libdir.join(&lib_name_with_ext); + if file_path.exists() { + info!("File {:?} already exists. Skipping download", &file_path); + } else { + bail!("Shared library file {lib_name} is not found in the extension store") + } + } } }