2023-07-29 08:51:30 +00:00
|
|
|
|
// Timestamp to versionstamp tests
|
|
|
|
|
// This translation mechanism is currently used by the garbage collector to determine which change feed entries to delete.
|
|
|
|
|
//
|
|
|
|
|
// FAQ:
|
|
|
|
|
// Q: What’s the difference between database TS and database VS?
|
|
|
|
|
// A: Timestamps are basically seconds since the unix epoch.
|
|
|
|
|
// Versionstamps can be anything that is provided by our TSO.
|
|
|
|
|
// Q: Why do we need to translate timestamps to versionstamps?
|
|
|
|
|
// A: The garbage collector needs to know which change feed entries to delete.
|
|
|
|
|
// However our SQL syntax `DEFINE DATABASE foo CHANGEFEED 1h` let the user specify the expiration in a duration, not a delta in the versionstamp.
|
|
|
|
|
// We need to translate the timestamp to the versionstamp due to that; `now - 1h` to a key suffixed by the versionstamp.
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
#[serial]
|
2023-08-20 08:45:03 +00:00
|
|
|
|
#[ignore]
|
2023-07-29 08:51:30 +00:00
|
|
|
|
async fn timestamp_to_versionstamp() {
|
|
|
|
|
// Create a new datastore
|
2023-08-19 09:01:37 +00:00
|
|
|
|
let ds = new_ds(Uuid::parse_str("A905CA25-56ED-49FB-B759-696AEA87C342").unwrap()).await;
|
2023-07-29 08:51:30 +00:00
|
|
|
|
// Give the current versionstamp a timestamp of 0
|
|
|
|
|
let mut tx = ds.transaction(true, false).await.unwrap();
|
|
|
|
|
tx.set_timestamp_for_versionstamp(0, "myns", "mydb", true).await.unwrap();
|
|
|
|
|
let vs1 = tx.get_versionstamp_from_timestamp(0, "myns", "mydb", true).await.unwrap().unwrap();
|
|
|
|
|
tx.commit().await.unwrap();
|
|
|
|
|
// Give the current versionstamp a timestamp of 1
|
|
|
|
|
let mut tx = ds.transaction(true, false).await.unwrap();
|
|
|
|
|
tx.set_timestamp_for_versionstamp(1, "myns", "mydb", true).await.unwrap();
|
|
|
|
|
let vs2 = tx.get_versionstamp_from_timestamp(1, "myns", "mydb", true).await.unwrap().unwrap();
|
|
|
|
|
tx.commit().await.unwrap();
|
|
|
|
|
// Give the current versionstamp a timestamp of 2
|
|
|
|
|
let mut tx = ds.transaction(true, false).await.unwrap();
|
|
|
|
|
tx.set_timestamp_for_versionstamp(2, "myns", "mydb", true).await.unwrap();
|
|
|
|
|
let vs3 = tx.get_versionstamp_from_timestamp(2, "myns", "mydb", true).await.unwrap().unwrap();
|
|
|
|
|
tx.commit().await.unwrap();
|
|
|
|
|
assert!(vs1 < vs2);
|
|
|
|
|
assert!(vs2 < vs3);
|
|
|
|
|
}
|