From dd53484c170943e805c562b5884051e64fad7ffd Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Mon, 14 Jul 2025 20:12:19 +0300 Subject: [PATCH] Fix running without neon storage --- .../communicator/src/worker_process/main_loop.rs | 8 ++++---- .../src/worker_process/worker_interface.rs | 16 ++++++++++++---- pgxn/neon/communicator_process.c | 5 +++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/pgxn/neon/communicator/src/worker_process/main_loop.rs b/pgxn/neon/communicator/src/worker_process/main_loop.rs index f3d7733904..6247abd46e 100644 --- a/pgxn/neon/communicator/src/worker_process/main_loop.rs +++ b/pgxn/neon/communicator/src/worker_process/main_loop.rs @@ -10,11 +10,11 @@ pub struct CommunicatorWorkerProcessStruct { } pub(super) async fn init( - tenant_id: String, - timeline_id: String, + tenant_id: Option<&str>, + timeline_id: Option<&str>, ) -> CommunicatorWorkerProcessStruct { - let _tenant_id = TenantId::from_str(&tenant_id).expect("invalid tenant ID"); - let _timeline_id = TimelineId::from_str(&timeline_id).expect("invalid timeline ID"); + let _tenant_id = tenant_id.map(|s| TenantId::from_str(s).expect("invalid tenant ID")); + let _timeline_id = timeline_id.map(|s| TimelineId::from_str(s).expect("invalid timeline ID")); CommunicatorWorkerProcessStruct { // metrics diff --git a/pgxn/neon/communicator/src/worker_process/worker_interface.rs b/pgxn/neon/communicator/src/worker_process/worker_interface.rs index 2ed30d20f6..f60fa3329f 100644 --- a/pgxn/neon/communicator/src/worker_process/worker_interface.rs +++ b/pgxn/neon/communicator/src/worker_process/worker_interface.rs @@ -15,8 +15,16 @@ pub extern "C" fn communicator_worker_process_launch( timeline_id: *const c_char, ) -> &'static CommunicatorWorkerProcessStruct { // Convert the arguments into more convenient Rust types - let tenant_id = unsafe { CStr::from_ptr(tenant_id) }.to_str().unwrap(); - let timeline_id = unsafe { CStr::from_ptr(timeline_id) }.to_str().unwrap(); + let tenant_id = if tenant_id.is_null() { + None + } else { + Some(unsafe { CStr::from_ptr(tenant_id) }.to_str().unwrap()) + }; + let timeline_id = if timeline_id.is_null() { + None + } else { + Some(unsafe { CStr::from_ptr(timeline_id) }.to_str().unwrap()) + }; let runtime = tokio::runtime::Builder::new_multi_thread() .enable_all() @@ -25,8 +33,8 @@ pub extern "C" fn communicator_worker_process_launch( .unwrap(); let worker_struct = runtime.block_on(main_loop::init( - tenant_id.to_string(), - timeline_id.to_string(), + tenant_id, + timeline_id, )); let worker_struct = Box::leak(Box::new(worker_struct)); diff --git a/pgxn/neon/communicator_process.c b/pgxn/neon/communicator_process.c index f4beb0202a..0324582e78 100644 --- a/pgxn/neon/communicator_process.c +++ b/pgxn/neon/communicator_process.c @@ -94,8 +94,9 @@ communicator_new_bgworker_main(Datum main_arg) logging = configure_logging(); proc_handle = communicator_worker_process_launch( - neon_tenant, - neon_timeline); + neon_tenant[0] == '\0' ? NULL : neon_tenant, + neon_timeline[0] == '\0' ? NULL : neon_timeline + ); /* proc_handle is not currently used, but will be in the future */ (void) proc_handle;