-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persons table schema migration #6667
Conversation
Note to self: consider https://clickhouse.com/docs/en/engines/table-engines/mergetree-family/versionedcollapsingmergetree/ EDIT: Looked into it, not what we need. I'd have loved cancel rows to take priority over the version, but that's not the case. |
@macobo would appreciate a second pass after our chat. @fuziontech can I get your 👁️ 👁️ in here too? |
Getting a paths test failure. Looked at it and it seems unrelated. Any context @neilkakkar ? |
also friendly ping @fuziontech |
Converted to draft as a safety measure given we first need to merge the changes that send us this version value via Kafka |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will work, but will probably need to be tested for helm chart deploys. This might time out the migration task. This will also require a custom migration for cloud. These select * into migrations are super slow on clickhouse. Migration will probably take 30-60 minutes on cloud.
For the migration task timeout we can just increase it in the command line via |
4e63a76
to
f074cda
Compare
I've tested this pretty extensively now and am comfortable to land it. Landing now and monitoring 👀 |
This reverts commit 54f2349.
Changes
Still WIP as I need to get feedback on this.This is part of the work to ensure CH and Postgres are always in sync.
The approach here is to always increment a version column in Postgres when we make an update (see #6628). This version is then passed to ClickHouse and we'll collapse rows based on this value.
The interesting part comes with
is_deleted
. Initially, I addedis_deleted
to the sort key (ORDER BY
clause). This would ensure that we couldn't possibly collapse all rows withis_deleted
(as has happened before), leaving us with a person that is deleted in Postgres but exists in ClickHouse.The problem here is storage. We'd have to keep around 2x rows for each deleted person. As we'd only ever collapse down to 2 rows: one with
is_deleted=0
and one withis_deleted=1
.The solution here was inspired by what we did with distinct IDs. When reading from Kafka, we can simply assign
version
to the max possibleUInt64
value, ensuring we always keep theis_deleted
row around without having to add it to the sort key. The way this was done also ensures backwards compatibility.Other points/questions
argMax
with_timestamp
but this should be fine. The case where this could be incorrect is if we have equal timestamps before the collapsing happens. The alternative is to change the queries to useversion
, but we'd run into problems when we first migrate. Happy to get some thoughts here._partition
to the table. We currently have_offset
, which is somewhat helpful, but for it to be truly helpful we need the partition number too.How did you test this code?
Added tests for direct insertion
and "kafka insertion" into the new table(removed due to flakiness). Confirmed collapsing works as expected.Also tested manually