Skip to content

Commit 60de424

Browse files
committed
fix test case
1 parent bae000e commit 60de424

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

src/query/service/src/sessions/query_ctx.rs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,27 +1528,38 @@ impl TableContext for QueryContext {
15281528
previous_snapshot: Option<Arc<TableSnapshot>>,
15291529
) -> Result<TableMetaTimestamps> {
15301530
let table_id = table.get_id();
1531-
//{
1532-
// // Defensively check that:
1533-
// // For each table, the previous_snapshot's timestamp passed in is strictly increasing,
1534-
// // Or put it another way, caller should always pass in the same or newer snapshot of the same table.
1535-
// let table_snapshot_timestamp_history =
1536-
// self.shared.get_table_snapshot_timestamp_history();
1537-
// let mut history = table_snapshot_timestamp_history.lock();
1538-
// let previous_snapshot_timestamp = previous_snapshot.as_ref().and_then(|s| s.timestamp);
1539-
// if let Some(last_accessed) = history.get(&table_id) {
1540-
// if last_accessed > &previous_snapshot_timestamp {
1541-
// return Err(ErrorCode::Internal(
1542-
// format!(
1543-
// "[QUERY-CTX] Generating new table meta timestamps failed: table_id = {}, previous_snapshot_timestamp {:?} is lesser than the snapshot timestamp accessed last time {:?}",
1544-
// table_id, previous_snapshot_timestamp, last_accessed
1545-
// )
1546-
// ));
1547-
// }
1548-
// }
1549-
// history.insert(table_id, previous_snapshot_timestamp);
1550-
// drop(history)
1551-
//}
1531+
1532+
// Defensively check that:
1533+
// For each table, the previous_snapshot's timestamp passed in is strictly increasing,
1534+
// Or put it another way, caller should always pass in the same or newer snapshot of the same table.
1535+
{
1536+
let table_snapshot_timestamp_history =
1537+
self.shared.get_table_snapshot_timestamp_history();
1538+
let previous_snapshot_timestamp = previous_snapshot.as_ref().and_then(|s| s.timestamp);
1539+
let mut valid_access = true;
1540+
let mut last_accessed_ts = None;
1541+
{
1542+
let mut history = table_snapshot_timestamp_history.lock();
1543+
if let Some(last_accessed) = history.get(&table_id) {
1544+
if last_accessed > &previous_snapshot_timestamp {
1545+
valid_access = false;
1546+
last_accessed_ts = last_accessed.clone();
1547+
}
1548+
}
1549+
if valid_access {
1550+
history.insert(table_id, previous_snapshot_timestamp);
1551+
}
1552+
}
1553+
1554+
if !valid_access {
1555+
return Err(ErrorCode::Internal(
1556+
format!(
1557+
"[QUERY-CTX] Generating new table meta timestamps failed: table_id = {}, previous_snapshot_timestamp {:?} is lesser than the snapshot timestamp accessed last time {:?}",
1558+
table_id, previous_snapshot_timestamp, last_accessed_ts
1559+
)
1560+
));
1561+
}
1562+
}
15521563

15531564
let delta = {
15541565
let fuse_table = FuseTable::try_from_table(table)?;
@@ -1576,8 +1587,6 @@ impl TableContext for QueryContext {
15761587
})?
15771588
};
15781589

1579-
// TODO Add defensive check that in auto-commit mode, table meta timestamps of this table
1580-
// has not be generated before, or get it from a cache.
15811590
let table_meta_timestamps = TableMetaTimestamps::new(previous_snapshot, delta);
15821591
{
15831592
let txn_mgr_ref = self.txn_mgr();

tests/sqllogictests/suites/base/issues/issue_18214.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ insert into t values(2);
2424
statement ok
2525
abort;
2626

27-
statement ok
27+
query T
2828
select * from t;
2929
----
3030
1

0 commit comments

Comments
 (0)