Remove gen_random_uuid() as it fails in replication environments

Description

gen_random_uuid() creates a different UUID in each node of a replicated PostgreSQL environment.
This has been reported for mod-configuration and Pgpool-II replication in #sys-ops on Slack yesterday. From the Pgpool-II manual:
https://www.pgpool.net/docs/latest/en/html/restrictions.html

Functions, etc. In Native Replication mode

There is no guarantee that any data provided using a context-dependent mechanism (e.g. random number, transaction ID, OID, SERIAL, sequence), will be replicated correctly on multiple backends. For SERIAL, enabling insert_lock will help replicating data. insert_lock also helps SELECT setval() and SELECT nextval().

mod-configuration is special in that it lets the database create a new UUID that always overwrites any provided UUID for the primary key _id:

https://github.com/folio-org/mod-configuration/blob/v5.0.1/mod-configuration-server/src/main/java/org/folio/rest/impl/ConfigAPI.java#L159
https://github.com/folio-org/mod-configuration/blob/v5.0.1/mod-configuration-server/src/main/resources/templates/db_scripts/schema.json#L14-L15
https://github.com/folio-org/raml-module-builder/blob/v23.11.0/domain-models-runtime/src/main/resources/templates/db_scripts/main.ftl#L53

Most other modules never overwrite a primary key UUID _id provided by the caller of the POST API. And if no such primary key is provided they create a new one in Java code so that all replicated nodes receive the same _id. The suggested implementation in PgUtil.post also works this way:
https://github.com/folio-org/raml-module-builder/blob/v23.11.0/domain-models-runtime/src/main/java/org/folio/rest/persist/PgUtil.java#L358
https://github.com/folio-org/raml-module-builder/blob/v23.11.0/domain-models-runtime/src/main/java/org/folio/rest/persist/PgUtil.java#L305

How to fix:

If there is a consensus about https://folio-org.atlassian.net/browse/RMB-277 (default name for primary key name) that should also be implemented at the same time (= removing the schema.json option "pkColumnName").

CSP Request Details

None

CSP Rejection Details

None

Potential Workaround

None

Checklist

hide

TestRail: Results

Activity

Show:

Eric Valuk May 1, 2019 at 5:02 PM
Edited

Moved this back into code review due to having finished a unit test and integration test for the code

Ingolf Kuss March 22, 2019 at 4:18 PM

Can we add label sysops_mgt to this issue ?

Oleksii Popov March 20, 2019 at 2:42 PM

Please update description and set to OPEN, so it can be picked into development.
FYI

Done

Details

Assignee

Reporter

Priority

Story Points

Sprint

Development Team

Core: Platform

Fix versions

TestRail: Cases

Open TestRail: Cases

TestRail: Runs

Open TestRail: Runs

Created March 20, 2019 at 9:36 AM
Updated February 5, 2020 at 5:35 PM
Resolved May 2, 2019 at 6:42 PM
TestRail: Cases
TestRail: Runs