Idempotency key for DDL operations
Company or project name
No response
Use case
Retries after network connection errors are really complex in distributed systems.
There are many operations that are quite risky to be retried such as EXCHANGE TABLE and we do not have easy way to check that previous operation succeeded or not for example, when disconnect was result of completely disappearing node and we have query log local to this node.
Describe the solution you'd like
- Add optional query setting
idempotency_keythat can be passed from a client with a query similar toinsert_deduplication_token. - When it is passed operations that change state(or go through keeper) will commit the
idempotency_keyto a special node in keeper. - idempotency_key work the same way as insert_deduplication_token - it will be cleaned up with the similar window logic.
- Client libraries can set this key automatically and retry on network error preserving
idempotency_key. It will make most retries completely safe. - Server will check if key exists before running query and also include it during operation commit to keeper. This way you can also cancel one of 2 parallel EXCHANGE TABELS so only one will succeed.
Describe alternatives you've considered
Other option is to pass some key similar to query_if from a client and on error check that this query was not running before. Saving this information somehow to keeper with operations that change metadata in keeper will allow to later check if we had one already finished. But we do not have guarantee that there is none inflight with unreachable node, that is still connected to keeper. So it will add more complexity if we can not store a tombstone saying this operation should not succeed after you checked.
Additional context
Language clients suffer a lot of disconnects as sometimes there is a race for connections to be not closed for up to 5 minutes: https://github.com/ClickHouse/ClickHouse/issues/92046
They can't easily detect if this case was there i.e. no bytes were sent from client and just ordinary disconnect when network is bad.
Source: ClickHouse/ClickHouse