citusdata / citus

Distributed PostgreSQL as an extension
https://www.citusdata.com
GNU Affero General Public License v3.0
10.57k stars 670 forks source link

Enable shard replication in MX #1033

Closed marcocitus closed 2 years ago

marcocitus commented 7 years ago

We currently use shard resource locks on the coordinator node to guarantee replicas remain consistent and to prevent deadlock that could result from running concurrent multi-shard commands. However, having these locks on the coordinator prevents us from performing replicated (reference table) writes or multi-shard commands from workers on MX tables, including writes to reference tables and INSERT..SELECT commands, which harms the MX experience. It also causes issue #925.

A way to resolve this would be to move those locks to the workers that store the shards, either by introducing a UDF for taking the advisory lock or by using explicit table locks on the shards. These would be sent prior to issuing the multi-shard command. The locks need to be obtained sequentially and in a consistent order to avoid distributed deadlocks, after which the actual commands can be sent in parallel.

An alternative approach is to always route unsupported commands through the coordinator. This could also work for DDL commands. The workers will have to obtain a coordinator endpoint to which to send the commands.

onderkalaci commented 3 years ago

Supporting replicated tables on MX is almost similar to supporting reference tables on MX. We always use 2PC, serialize modifications and make sure that citus_disable/activate_node() UDFs gracefully handles replicated tables.

To support replicated tables on MX, I suggest the following:

onderkalaci commented 2 years ago

I feel confident enough to close the issue. The involved PRs are: #5379, #5380, #5381, #5386, #5392, #5405, #5476, #5469, #5470 and #5486.

For the remaining improvements, we could track via individual issues