Skip to content

Commit fc99e77

Browse files
authored
fix: fetch messages shouldn't read the current timestamp's notif (#577)
and remove the manual sortkey_timestamp filtering which is no longer necessary w/ the row range reading (and it covered up this bug) also fix flakey hello_again tests (connected_at should be in the past) Issue: SYNC-4068
1 parent 09fe7ac commit fc99e77

3 files changed

Lines changed: 17 additions & 37 deletions

File tree

autoconnect/autoconnect-common/src/test_support.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use uuid::Uuid;
22

3-
use autopush_common::db::{mock::MockDbClient, User};
3+
use autopush_common::{
4+
db::{mock::MockDbClient, User},
5+
util::timing::ms_since_epoch,
6+
};
47

58
pub const UA: &str =
69
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/110.0";
@@ -33,6 +36,8 @@ pub fn hello_again_db(uaid: Uuid) -> MockDbClient {
3336
db.expect_get_user().times(1).return_once(move |_| {
3437
Ok(Some(User {
3538
uaid,
39+
// Last connected 10 minutes ago
40+
connected_at: ms_since_epoch() - (10 * 60 * 1000),
3641
current_month: Some(CURRENT_MONTH.to_owned()),
3742
..Default::default()
3843
}))

autopush-common/src/db/bigtable/bigtable_client/merge.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ impl RowMerger {
376376
/// Iterate through all the returned chunks and compile them into a hash of finished cells indexed by row_key
377377
pub async fn process_chunks(
378378
mut stream: ClientSStreamReceiver<ReadRowsResponse>,
379-
timestamp_filter: Option<u64>,
380379
limit: Option<usize>,
381380
) -> Result<BTreeMap<RowKey, Row>, BigTableError> {
382381
// Work object
@@ -440,28 +439,7 @@ impl RowMerger {
440439
}
441440
if merger.state == ReadState::RowComplete {
442441
debug! {"🟧 row complete"};
443-
// Check to see if we can add this row, or if it's blocked by the timestamp filter.
444442
let finished_row = merger.row_complete(&mut chunk)?;
445-
if let Some(timestamp) = timestamp_filter {
446-
if let Some(sk_ts) = finished_row.clone().take_cell("sortkey_timestamp") {
447-
let ts_val = crate::db::bigtable::bigtable_client::to_u64(
448-
sk_ts.value,
449-
"sortkey_timestamp",
450-
)
451-
.map_err(|_| {
452-
BigTableError::InvalidChunk("Invalid timestamp".to_owned())
453-
})?;
454-
if ts_val <= timestamp {
455-
trace!(
456-
"⚖ {}: Skipping {} <= {}",
457-
&finished_row.row_key,
458-
ts_val,
459-
timestamp
460-
);
461-
continue;
462-
}
463-
}
464-
}
465443
rows.insert(finished_row.row_key.clone(), finished_row);
466444
} else if chunk.has_commit_row() {
467445
return Err(BigTableError::InvalidChunk(format!(

autopush-common/src/db/bigtable/bigtable_client/mod.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,10 @@ impl BigTableClientImpl {
156156
}
157157

158158
/// Read a given row from the row key.
159-
async fn read_row(
160-
&self,
161-
row_key: &str,
162-
timestamp_filter: Option<u64>,
163-
) -> Result<Option<row::Row>, error::BigTableError> {
159+
async fn read_row(&self, row_key: &str) -> Result<Option<row::Row>, error::BigTableError> {
164160
debug!("🉑 Row key: {}", row_key);
165161
let req = self.read_row_request(row_key);
166-
let mut rows = self.read_rows(req, timestamp_filter, None).await?;
162+
let mut rows = self.read_rows(req, None).await?;
167163
Ok(rows.remove(row_key))
168164
}
169165

@@ -227,15 +223,14 @@ impl BigTableClientImpl {
227223
async fn read_rows(
228224
&self,
229225
req: ReadRowsRequest,
230-
sortkey_filter: Option<u64>,
231226
limit: Option<usize>,
232227
) -> Result<BTreeMap<RowKey, row::Row>, error::BigTableError> {
233228
let bigtable = self.pool.get().await?;
234229
let resp = bigtable
235230
.conn
236231
.read_rows(&req)
237232
.map_err(error::BigTableError::Read)?;
238-
merge::RowMerger::process_chunks(resp, sortkey_filter, limit).await
233+
merge::RowMerger::process_chunks(resp, limit).await
239234
}
240235

241236
/// write a given row.
@@ -684,7 +679,7 @@ impl DbClient for BigTableClientImpl {
684679
..Default::default()
685680
};
686681

687-
if let Some(mut record) = self.read_row(&row_key, None).await? {
682+
if let Some(mut record) = self.read_row(&row_key).await? {
688683
trace!("🉑 Found a record for that user");
689684
if let Some(mut cells) = record.take_cells("connected_at") {
690685
if let Some(cell) = cells.pop() {
@@ -854,7 +849,7 @@ impl DbClient for BigTableClientImpl {
854849
filter.set_chain(filter_chain);
855850
req.set_filter(filter);
856851

857-
let mut rows = self.read_rows(req, None, None).await?;
852+
let mut rows = self.read_rows(req, None).await?;
858853
let mut result = HashSet::new();
859854
if let Some(record) = rows.remove(&row_key) {
860855
for mut cells in record.cells.into_values() {
@@ -1100,7 +1095,7 @@ impl DbClient for BigTableClientImpl {
11001095
req.set_rows_limit(limit as i64);
11011096
}
11021097
// */
1103-
let rows = self.read_rows(req, None, Some(limit)).await?;
1098+
let rows = self.read_rows(req, Some(limit)).await?;
11041099
debug!(
11051100
"🉑 Fetch Topic Messages. Found {} row(s) of {}",
11061101
rows.len(),
@@ -1124,7 +1119,9 @@ impl DbClient for BigTableClientImpl {
11241119
let mut row_range = data::RowRange::default();
11251120

11261121
let start_key = if let Some(ts) = timestamp {
1127-
format!("{}#02:{}", uaid.simple(), ts)
1122+
// Fetch everything after the last message with timestamp: the "z"
1123+
// moves past the last message's channel_id's 1st hex digit
1124+
format!("{}#02:{}z", uaid.simple(), ts)
11281125
} else {
11291126
format!("{}#02:", uaid.simple())
11301127
};
@@ -1159,7 +1156,7 @@ impl DbClient for BigTableClientImpl {
11591156
req.set_rows_limit(limit as i64);
11601157
}
11611158
// */
1162-
let rows = self.read_rows(req, timestamp, Some(limit)).await?;
1159+
let rows = self.read_rows(req, Some(limit)).await?;
11631160
debug!(
11641161
"🉑 Fetch Timestamp Messages ({:?}) Found {} row(s) of {}",
11651162
timestamp,
@@ -1491,7 +1488,7 @@ mod tests {
14911488
}],
14921489
);
14931490
client.write_row(row).await.unwrap();
1494-
let Some(row) = client.read_row(&row_key, None).await.unwrap() else {
1491+
let Some(row) = client.read_row(&row_key).await.unwrap() else {
14951492
panic!("Expected row");
14961493
};
14971494
assert_eq!(row.cells.len(), 1);

0 commit comments

Comments
 (0)