-
Notifications
You must be signed in to change notification settings - Fork 39
Speed up Vector Clock selection #1272
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
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
Route
|
| CREATE TRIGGER gateway_latest_upd | ||
| AFTER INSERT ON gateway_envelopes | ||
| FOR EACH ROW EXECUTE FUNCTION update_latest_envelope(); |
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.
Doing this for every row seems kind of heavy. Is there a way to do this once for each transaction from the app?
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.
by definition every insert is always the newest. Out-of-order inserts would be a problem. There are multiple app backend services that might be doing inserts to their corresponding originator_id.
| SET originator_sequence_id = EXCLUDED.originator_sequence_id, | ||
| gateway_time = EXCLUDED.gateway_time; |
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.
These can move backward. Probably want greatest(OLD.gateway_time, EXCLUDED.gateway_time) to enforce that they only move forward.
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.
valid. There is no application path that would move backwards. All inserts are inserted in sequenceID order in all cases. Otherwise last_seen and vectors break.
It can not move even in an HA case because we have
-- name: InsertGatewayEnvelope :execrows
INSERT INTO gateway_envelopes(
originator_node_id,
originator_sequence_id,
topic,
originator_envelope,
payer_id,
gateway_time,
expiry
)
VALUES (
@originator_node_id,
@originator_sequence_id,
@topic,
@originator_envelope,
@payer_id,
COALESCE(@gateway_time, NOW()),
@expiry
) ON CONFLICT DO NOTHING;
so DO NOTHING won't trigger the helper table in HA cases.
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.
I added WHERE EXCLUDED.originator_sequence_id > g.originator_sequence_id; to be defensive.
SelectVectorClocknever finishes. Even with a proper secondary index, the query is just too complicated. I've played around with a few alternatives and having a dedicated table that contains exactly 1 record seems like the best way forward.The trigger keeps the table updated and transactional.
The time went down to sub 100ms.
If the best attempt fails, the consequence is that the
publish workerwill have to do some useless work when spinning up.