fix: make checkout_latest force a reload (#1064)

#1002 accidentally changed `checkout_latest` to do nothing if the table
was already in latest mode. This PR makes sure it forces a reload of the
table (if there is a newer version).
This commit is contained in:
Will Jones
2024-03-05 11:51:47 -08:00
committed by GitHub
parent d1983602c2
commit 722fe1836c
2 changed files with 9 additions and 1 deletions

View File

@@ -636,9 +636,14 @@ impl NativeTable {
})
}
/// Checkout the latest version of this [NativeTable].
///
/// This will force the table to be reloaded from disk, regardless of the
/// `read_consistency_interval` set.
pub async fn checkout_latest(&self) -> Result<Self> {
let mut dataset = self.dataset.duplicate().await;
dataset.as_latest(self.read_consistency_interval).await?;
dataset.reload().await?;
Ok(Self {
dataset,
..self.clone()
@@ -1943,6 +1948,9 @@ mod tests {
match interval {
None => {
assert_eq!(table2.count_rows(None).await.unwrap(), 0);
let table2_native =
table2.as_native().unwrap().checkout_latest().await.unwrap();
assert_eq!(table2_native.count_rows(None).await.unwrap(), 1);
}
Some(0) => {
assert_eq!(table2.count_rows(None).await.unwrap(), 1);

View File

@@ -156,7 +156,7 @@ impl DatasetConsistencyWrapper {
self.0.write().await.set_latest(dataset);
}
async fn reload(&self) -> Result<()> {
pub async fn reload(&self) -> Result<()> {
self.0.write().await.reload().await
}