diff --git a/pgxn/neon/communicator/src/integrated_cache.rs b/pgxn/neon/communicator/src/integrated_cache.rs index 6b6ce03a66..a69af44492 100644 --- a/pgxn/neon/communicator/src/integrated_cache.rs +++ b/pgxn/neon/communicator/src/integrated_cache.rs @@ -333,13 +333,6 @@ impl<'t> IntegratedCacheWriteAccess<'t> { } } - /// Returns the last written LSN. - pub fn get_lsn(&'t self) -> Lsn { - // TODO: supposedly, this should be the last written LSN, but it is not - // , perhaps - Lsn(self.global_lw_lsn.load(Ordering::Relaxed)) - } - pub fn get_db_size(&'t self, _db_oid: u32) -> CacheResult { // TODO: it would be nice to cache database sizes too. Getting the database size // is not a very common operation, but when you do it, it's often interactive, with diff --git a/pgxn/neon/communicator/src/lib.rs b/pgxn/neon/communicator/src/lib.rs index 050391051d..84e7038842 100644 --- a/pgxn/neon/communicator/src/lib.rs +++ b/pgxn/neon/communicator/src/lib.rs @@ -2,6 +2,7 @@ //! - async tokio communicator core, which receives requests and processes them. //! - Main loop and requests queues, which routes requests from backends to the core //! - the per-backend glue code, which submits requests +#![warn(unused)] mod backend_comms; @@ -23,5 +24,3 @@ mod global_allocator; // FIXME: get this from postgres headers somehow pub const BLCKSZ: usize = 8192; -// FIXME: get this from postgres headers somehow -pub const SLRU_PAGES_PER_SEGMENT: usize = 32; diff --git a/pgxn/neon/communicator/src/worker_process/main_loop.rs b/pgxn/neon/communicator/src/worker_process/main_loop.rs index e6fb05241c..0b2f9da366 100644 --- a/pgxn/neon/communicator/src/worker_process/main_loop.rs +++ b/pgxn/neon/communicator/src/worker_process/main_loop.rs @@ -439,7 +439,7 @@ impl<'t> CommunicatorWorkerProcessStruct<'t> { .await { Ok(slru_bytes) => { - if let Err(e) = std::fs::write(&file_path, &slru_bytes) { + if let Err(e) = tokio::fs::write(&file_path, &slru_bytes).await { info!("could not write slru segment to file {file_path}: {e}"); return NeonIOResult::Error(e.raw_os_error().unwrap_or(libc::EIO)); } diff --git a/pgxn/neon/communicator_new.c b/pgxn/neon/communicator_new.c index a7225e78e7..9cceafba2f 100644 --- a/pgxn/neon/communicator_new.c +++ b/pgxn/neon/communicator_new.c @@ -178,6 +178,32 @@ assign_request_id(void) return result; } +/* + * Returns the absolute path to the given path. +*/ +static inline char * get_absolute_path(const char *path) +{ + char *abs_path = bounce_buf(); + char cwd[PATH_MAX]; + int size = 0; + + if (path[0] == '/') { + strncpy(abs_path, path, strlen(path)); + return abs_path; + } + + getcwd(cwd, sizeof(cwd)); + + size = snprintf(NULL, 0, "%s/%s", cwd, path); + + if (size < 0 || size >= PATH_MAX) { + return NULL; + } + + snprintf(abs_path, size + 1, "%s/%s", cwd, path); + return abs_path; +} + /**** Initialization functions. These run in postmaster ****/ void @@ -1014,32 +1040,14 @@ communicator_new_read_slru_segment( .request_lsn = request_lsns->request_lsn, } }; + int nblocks = -1; if (path == NULL) { elog(ERROR, "read_slru_segment called with NULL path"); return -1; } - // Scoping should help deallocate the absolute path buffer. - char *abs_path = bounce_buf(); - - if (path[0] != '/') { - char cwd[PATH_MAX]; - getcwd(cwd, sizeof(cwd)); - - const int size = snprintf(NULL, 0, "%s/%s", cwd, path); - - if (size < 0 || size >= PATH_MAX) { - elog(ERROR, "read_slru_segment failed to create an absolute path for \"%s\"", path); - return -1; - } - - snprintf(abs_path, size + 1, "%s/%s", cwd, path); - } else { - strncpy(abs_path, path, sizeof(abs_path)); - } - - request.read_slru_segment.destination_file_path.ptr = abs_path; + request.read_slru_segment.destination_file_path.ptr = (uint8_t *) get_absolute_path(path); elog(DEBUG5, "readslrusegment called for kind=%u, segno=%u, file_path=\"%s\"", kind, segno, request.read_slru_segment.destination_file_path.ptr); @@ -1049,8 +1057,6 @@ communicator_new_read_slru_segment( perform_request(&request, &result); - int nblocks = -1; - switch (result.tag) { case NeonIOResult_ReadSlruSegment: @@ -1381,7 +1387,7 @@ print_neon_io_request(NeonIORequest *request) r->slru_kind, r->segment_number, LSN_FORMAT_ARGS(r->request_lsn), - r->destination_file_path); + r->destination_file_path.ptr); return buf; } case NeonIORequest_PrefetchV: