Compare commits

...

1 Commits

Author SHA1 Message Date
Konstantin Knizhnik
23f410a481 Create rel_dir when database is created from WAL 2024-02-09 23:05:32 +02:00
3 changed files with 35 additions and 3 deletions

View File

@@ -989,6 +989,17 @@ impl<'a> DatadirModification<'a> {
Ok(())
}
pub async fn create_rel_dir(&mut self, spcnode: Oid, dbnode: Oid) -> anyhow::Result<()> {
let buf = RelDirectory::ser(&RelDirectory {
rels: HashSet::new(),
})?;
self.put(
rel_dir_to_key(spcnode, dbnode),
Value::Image(Bytes::from(buf)),
);
Ok(())
}
/// Store a relmapper file (pg_filenode.map) in the repository
pub async fn put_relmap_file(
&mut self,
@@ -1171,9 +1182,6 @@ impl<'a> DatadirModification<'a> {
// Update relation size cache
self.tline.set_cached_rel_size(rel, self.lsn, nblocks);
// Update relation size cache
self.tline.set_cached_rel_size(rel, self.lsn, nblocks);
// Update logical database size.
self.pending_nblocks -= old_size as i64 - nblocks as i64;
}

View File

@@ -156,6 +156,10 @@ impl WalIngest {
}
} else if pg_version == 15 {
if info == postgres_ffi::v15::bindings::XLOG_DBASE_CREATE_WAL_LOG {
let createdb = XlCreateDatabaseFromWal::decode(&mut buf);
modification
.create_rel_dir(createdb.tablespace_id, createdb.db_id)
.await?;
debug!("XLOG_DBASE_CREATE_WAL_LOG: noop");
} else if info == postgres_ffi::v15::bindings::XLOG_DBASE_CREATE_FILE_COPY {
// The XLOG record was renamed between v14 and v15,
@@ -176,6 +180,10 @@ impl WalIngest {
}
} else if pg_version == 16 {
if info == postgres_ffi::v16::bindings::XLOG_DBASE_CREATE_WAL_LOG {
let createdb = XlCreateDatabaseFromWal::decode(&mut buf);
modification
.create_rel_dir(createdb.tablespace_id, createdb.db_id)
.await?;
debug!("XLOG_DBASE_CREATE_WAL_LOG: noop");
} else if info == postgres_ffi::v16::bindings::XLOG_DBASE_CREATE_FILE_COPY {
// The XLOG record was renamed between v14 and v15,

View File

@@ -521,6 +521,22 @@ impl XlCreateDatabase {
}
}
#[repr(C)]
#[derive(Debug)]
pub struct XlCreateDatabaseFromWal {
pub db_id: Oid,
pub tablespace_id: Oid,
}
impl XlCreateDatabaseFromWal {
pub fn decode(buf: &mut Bytes) -> XlCreateDatabaseFromWal {
XlCreateDatabaseFromWal {
db_id: buf.get_u32_le(),
tablespace_id: buf.get_u32_le(),
}
}
}
#[repr(C)]
#[derive(Debug)]
pub struct XlDropDatabase {