mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-26 09:30:37 +00:00
Refactor put_wal_record() so that it doesn't need to be marked 'async'.
It was only marked as async because it calls relsize_get(), but relsize_get() will in fact never block when it's called with the max LSN value, like put_wal_record() does. Refactor to avoid marking put_wal_record() as 'async'.
This commit is contained in:
@@ -634,9 +634,13 @@ impl PageCache {
|
||||
// Adds a relation-wide WAL record (like truncate) to the page cache,
|
||||
// associating it with all pages started with specified block number
|
||||
//
|
||||
pub async fn put_rel_wal_record(&self, tag: BufferTag, rec: WALRecord) -> anyhow::Result<()> {
|
||||
pub fn put_rel_wal_record(&self, tag: BufferTag, rec: WALRecord) -> anyhow::Result<()> {
|
||||
let mut key = CacheKey { tag, lsn: rec.lsn };
|
||||
let old_rel_size = self.relsize_get(&tag.rel, u64::MAX).await?;
|
||||
|
||||
// What was the size of the relation before this record?
|
||||
let last_lsn = self.last_valid_lsn.load(Ordering::Acquire);
|
||||
let old_rel_size = self.relsize_get_nowait(&tag.rel, last_lsn)?;
|
||||
|
||||
let content = CacheEntryContent {
|
||||
page_image: None,
|
||||
wal_record: Some(rec),
|
||||
@@ -762,11 +766,14 @@ impl PageCache {
|
||||
shared.last_record_lsn
|
||||
}
|
||||
|
||||
pub async fn relsize_get(&self, rel: &RelTag, req_lsn: u64) -> anyhow::Result<u32> {
|
||||
let mut lsn = req_lsn;
|
||||
if lsn != u64::MAX {
|
||||
lsn = self.wait_lsn(lsn).await?;
|
||||
}
|
||||
pub async fn relsize_get(&self, rel: &RelTag, lsn: u64) -> anyhow::Result<u32> {
|
||||
self.wait_lsn(lsn).await?;
|
||||
self.relsize_get_nowait(rel, lsn)
|
||||
}
|
||||
|
||||
fn relsize_get_nowait(&self, rel: &RelTag, lsn: u64) -> anyhow::Result<u32> {
|
||||
|
||||
assert!(lsn <= self.last_valid_lsn.load(Ordering::Acquire));
|
||||
|
||||
let mut key = CacheKey {
|
||||
tag: BufferTag {
|
||||
|
||||
@@ -266,7 +266,7 @@ async fn walreceiver_main(
|
||||
rec: recdata.clone(),
|
||||
main_data_offset: decoded.main_data_offset as u32,
|
||||
};
|
||||
pcache.put_rel_wal_record(tag, rec).await?;
|
||||
pcache.put_rel_wal_record(tag, rec)?;
|
||||
}
|
||||
} else if decoded.xl_rmid == pg_constants::RM_DBASE_ID
|
||||
&& (decoded.xl_info & pg_constants::XLR_RMGR_INFO_MASK)
|
||||
|
||||
Reference in New Issue
Block a user