Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 750eff9

Browse files
committed
Comment fixes, cmd touching replicas planned description.
1 parent f532cf5 commit 750eff9

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

pg_shardman--0.0.1.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ END $$ LANGUAGE plpgsql STRICT;
152152
-- this is expected to be called on server/um params change. We use dedicated
153153
-- server for each partition because we plan to use multiple hosts/ports in
154154
-- connstrings for transient fallback to replica if server with main partition
155-
-- fails. FDW server, user mapping, foreign table and (obviously) parent partition must
156-
-- exist when called.
155+
-- fails. FDW server, user mapping, foreign table and (obviously) parent partition
156+
-- must exist when called.
157157
CREATE FUNCTION update_fdw_server(part partitions) RETURNS void AS $$
158158
DECLARE
159159
connstring text;

src/shard.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
*
4545
* General copy partition implementation:
4646
* - Disable subscription on destination, otherwise we can't drop rep slot on
47-
source.
47+
* source.
4848
* - Idempotently create publication and repl slot on source.
4949
* - Idempotently create table and async subscription on destination.
5050
* We use async subscription, because sync would block table while copy is
@@ -65,6 +65,44 @@
6565
* etc), we have to start everything from the ground if master reboots. This
6666
* is arguably fine.
6767
*
68+
* Short description of all tasks:
69+
* move_primary:
70+
* copy part, update metadata
71+
* On metadata update:
72+
* on src node, drop lr copy stuff, create foreign table and replace
73+
* table with it, drop table. Drop primary lr stuff.
74+
* on dst node, replace foreign table with fresh copy (lock it until
75+
* sync_standby_names updated?), drop the former. drop lr copy stuff.
76+
* Create primary lr stuff (including sync_standby_names)
77+
* On node with replica (if exists) alter sub and alter fdw server.
78+
* on others, alter fdw server.
79+
*
80+
* About fdws on replicas: we have to keep partition of parent table as fdw,
81+
* because otherwise we would not be able to write anything to it. On the
82+
* other hand, keeping the whole list of replicas is a bit excessive and
83+
* slower in case of primary failure: we need actually only primary and
84+
* ourself.
85+
*
86+
* add_replica:
87+
* copy part from the last replica (because only the last replica knows
88+
* when it has created sync lr channel and can make table writable again).
89+
* Make dst table read-only for non-replica role, update metadata.
90+
* On metadata update:
91+
* on (old) last replica, alter cp lr channel to make it sync (and rename),
92+
* make table writable.
93+
* on node with fresh replica, rename lr channel, alter fdw server.
94+
* on others, alter fdw server.
95+
*
96+
* move_replica:
97+
* copy part. Make dst table read-only for non-replica role, update
98+
* metadata.
99+
* On metadata update:
100+
* On src, drop lr copy stuff, alter fdw server. Drop lr pub (if any) and
101+
* sub stuff. Drop table.
102+
* On dst, drop lr copy stuff, create lr pub & sync sub, alter fdw server.
103+
* On previous part node, alter lr channel
104+
* On following part node (if any), recreate sub.
105+
*
68106
* -------------------------------------------------------------------------
69107
*/
70108
#include "postgres.h"
@@ -334,7 +372,7 @@ move_primary(Cmd *cmd)
334372

335373
/*
336374
* Fill CopyPartState, retrieving needed data. If something goes wrong, we
337-
* don't bother to fill the rest of fields.
375+
* don't bother to fill the rest of fields and mark task as failed.
338376
*/
339377
void
340378
init_cp_state(CopyPartState *cps, const char *part_name, int32 dst_node)
@@ -390,6 +428,7 @@ init_cp_state(CopyPartState *cps, const char *part_name, int32 dst_node)
390428
cps->logname, cps->logname, cps->part_name, cps->logname
391429
);
392430
cps->relation = get_partition_relation(part_name);
431+
Assert(cps->relation != NULL);
393432
cps->dst_create_tab_and_sub_sql = psprintf(
394433
"drop table if exists %s cascade;"
395434
/*
@@ -474,6 +513,7 @@ exec_tasks(CopyPartState **tasks, int ntasks)
474513
shmn_elog(FATAL, "clock_gettime failed, %s", strerror(e));
475514
for (i = 0; i < ntasks; i++)
476515
{
516+
/* TODO: make sure one part is touched only by one task */
477517
if (tasks[i]->res != TASK_FAILED)
478518
{
479519
CopyPartStateNode *cps_node = palloc(sizeof(CopyPartStateNode));

0 commit comments

Comments
 (0)