Coordinator as a worker is not automatically related to groupid=0
- Dominant language
- C
- Stars
- 12.8k
- Forks
- 794
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 31
Description
Have been discussing this with @SaitTalhaNisanci.
There are some checks that rely on coordinator having groupid = 0. Right now, to add the coordinator as a worker node we run this:
``` SQL
SELECT master_add_node(':master_host', :master_port, groupid := 0);
```
Better APIs are suggested in #4185 . Coordinator however can be added even without specifying the groupid, and in that case the groupid will never be 0. This could cause complications. We should get an error when trying to assign a groupid other than 0 to the coordinator. Moreover, `shouldhaveshards` will be true as soon as coordinator is added.
``` SQL
$ SELECT master_add_node(':master_host', :master_port);
master_add_node
-----------------
1
(1 row)
$ SELECT groupid, nodename, nodeport, shouldhaveshards FROM pg_dist_node;
groupid | nodename | nodeport | shouldhaveshards
---------+--------------+--------------+------------------
1 | :master_host | :master_port | t
(1 row)
```
Also, right now it is allowed to add a worker node which is not the coordinator with groupid = 0. And of course, if we try to add the coordinator with groupid = 0 afterwards, we get an error as shown below.
``` SQL
-- let's first remove the coordinator that we added above
$ SELECT master_remove_node(':master_host', :master_port);
master_remove_node
--------------------
(1 row)
$ SELECT master_add_node(':worker_host', :worker_port, groupid := 0);
master_add_node
-----------------
2
(1 row)
$ SELECT master_add_node(':master_host', :master_port, groupid := 0);
ERROR: group 0 already has a primary node
```
We got to the conclusion that it's best to program this _if and only if_ relationship. :)
**a worker node has groupid 0** <=> **it is the coordinator as a worker**
Contributor guide
Assessment
This issue has not been assessed yet.