Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Ensure portdb selects rows with negative rowids
Browse files Browse the repository at this point in the history
The `backward_select` query uses the `backward_chunk` variable as an
inclusive upper bound on the rowids it selects. It is initially 0 (see
`setup_table`). It is then set to

```
backward_chunk = min(row[0] for row in brows) - 1
```

where `brows` is the result of running the `backwards_select` query.
For this to make sense, we need to ensure that `backwards_select` picks
rows in descending order. Otherwise we'll jump right to the bottom of
the rowids, pick out the lowest batch only and discard everything we
skipped over. This is a Bad Thing.

I've tested this locally with the reproduction case reported in #13191.
Without the patch, I could reproduce the reported failure; with the
patch, the portdb script completes successfully.
  • Loading branch information
David Robertson committed Jul 8, 2022
1 parent fb7d24a commit 21e9fc5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion synapse/_scripts/synapse_port_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,15 @@ async def handle_table(
self.progress.update(table, table_size) # Mark table as done
return

# We sweep over rowids in two directions: one forwards (rowids 1, 2, 3, ...)
# and another backwards (rowids 0, -1, -2, ...).
forward_select = (
"SELECT rowid, * FROM %s WHERE rowid >= ? ORDER BY rowid LIMIT ?" % (table,)
)

backward_select = (
"SELECT rowid, * FROM %s WHERE rowid <= ? ORDER BY rowid LIMIT ?" % (table,)
"SELECT rowid, * FROM %s WHERE rowid <= ? ORDER BY rowid DESC LIMIT ?"
% (table,)
)

do_forward = [True]
Expand Down

0 comments on commit 21e9fc5

Please sign in to comment.