Change 'relsize_inc' signature to be a bit nicer.

Don't add 1 to the argument in the function, the callers must do it now.
And don't accept None argument, pass 0 instead for an empty relation.
This commit is contained in:
Heikki Linnakangas
2021-04-20 19:10:37 +03:00
parent fa5d31056b
commit 2c5fb6d6c8
3 changed files with 13 additions and 11 deletions

View File

@@ -597,17 +597,19 @@ impl PageCache {
}
}
// FIXME: Shouldn't relation size also be tracked with an LSN?
// If a replica is lagging behind, it needs to get the size as it was on
// the replica's current replay LSN.
pub fn relsize_inc(&self, rel: &RelTag, to: Option<u32>) {
/// Remember a relation's size in blocks.
///
/// If 'to' is larger than the previously remembered size, the remembered size is increased to 'to'.
/// But if it's smaller, there is no change.
pub fn relsize_inc(&self, rel: &RelTag, to: u32) {
// FIXME: Shouldn't relation size also be tracked with an LSN?
// If a replica is lagging behind, it needs to get the size as it was on
// the replica's current replay LSN.
let mut shared = self.shared.lock().unwrap();
let entry = shared.relsize_cache.entry(*rel).or_insert(0);
if let Some(to) = to {
if to >= *entry {
*entry = to + 1;
}
if to >= *entry {
*entry = to;
}
}

View File

@@ -600,7 +600,7 @@ impl Connection {
forknum: req.forknum,
};
pcache.relsize_inc(&tag, None);
pcache.relsize_inc(&tag, 0);
self.write_message(&BeMessage::ZenithStatusResponse(ZenithStatusResponse {
ok: true,
@@ -616,7 +616,7 @@ impl Connection {
forknum: req.forknum,
};
pcache.relsize_inc(&tag, Some(req.blkno));
pcache.relsize_inc(&tag, req.blkno + 1);
self.write_message(&BeMessage::ZenithStatusResponse(ZenithStatusResponse {
ok: true,

View File

@@ -333,7 +333,7 @@ async fn slurp_base_file(
pcache.put_page_image(tag, parsed.lsn, bytes.copy_to_bytes(8192));
pcache.relsize_inc(&reltag, Some(blknum));
pcache.relsize_inc(&reltag, blknum + 1);
blknum += 1;
}
}