From 7db3a9e7d9e587f63699cb3ac1335a90c6d16b5e Mon Sep 17 00:00:00 2001 From: Patrick Insinger Date: Wed, 22 Sep 2021 15:56:20 -0700 Subject: [PATCH] walredo - don't use RefCell on stdin/stdout --- pageserver/src/walredo.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/pageserver/src/walredo.rs b/pageserver/src/walredo.rs index f1399c4eec..fbb1984859 100644 --- a/pageserver/src/walredo.rs +++ b/pageserver/src/walredo.rs @@ -23,7 +23,6 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use lazy_static::lazy_static; use log::*; use serde::{Deserialize, Serialize}; -use std::cell::RefCell; use std::fs; use std::fs::OpenOptions; use std::io::prelude::*; @@ -206,7 +205,7 @@ impl WalRedoManager for PostgresRedoManager { .block_on(PostgresRedoProcess::launch(self.conf, &self.tenantid))?; *process_guard = Some(p); } - let process = (*process_guard).as_ref().unwrap(); + let process = process_guard.as_mut().unwrap(); self.runtime .block_on(self.handle_apply_request(process, &request)) @@ -247,7 +246,7 @@ impl PostgresRedoManager { /// async fn handle_apply_request( &self, - process: &PostgresRedoProcess, + process: &mut PostgresRedoProcess, request: &WalRedoRequest, ) -> Result { let rel = request.rel; @@ -438,8 +437,8 @@ impl PostgresRedoManager { /// Handle to the Postgres WAL redo process /// struct PostgresRedoProcess { - stdin: RefCell, - stdout: RefCell, + stdin: ChildStdin, + stdout: ChildStdout, } impl PostgresRedoProcess { @@ -532,10 +531,7 @@ impl PostgresRedoProcess { }; tokio::spawn(f_stderr); - Ok(PostgresRedoProcess { - stdin: RefCell::new(stdin), - stdout: RefCell::new(stdout), - }) + Ok(PostgresRedoProcess { stdin, stdout }) } // @@ -543,13 +539,13 @@ impl PostgresRedoProcess { // new page image. // async fn apply_wal_records( - &self, + &mut self, tag: BufferTag, base_img: Option, records: &[WALRecord], ) -> Result { - let mut stdin = self.stdin.borrow_mut(); - let mut stdout = self.stdout.borrow_mut(); + let stdin = &mut self.stdin; + let stdout = &mut self.stdout; // We do three things simultaneously: send the old base image and WAL records to // the child process's stdin, read the result from child's stdout, and forward any logging