Skip to content

Allow to control the order of shared_preload_libraries (citus) #3530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions internal/patroni/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"path"
"strings"

"golang.org/x/exp/slices"

corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/yaml"

Expand Down Expand Up @@ -231,10 +233,34 @@ func DynamicConfiguration(
// shared_preload_libraries is a comma separated list that can have
// other values appended in addition to the mandatory values. Below,
// any values provided in the CRD are appended after the mandatory
// values.
// values unless unless a mandatory value appear in the other list.
// The order defined by the shared_preload_libraries list is preserved
// (and leading when there is intersection with the mandatory values.)
// for example:
// v = "lib1, lib2, lib3"
// s = "lib4, lib5, lib6"
// => "lib1, lib2, lib3, lib4, lib5, lib6"
// v = "lib1, lib2, lib3"
// s = "lib4, lib1, lib6"
// => "lib2, lib3, lib1, lib5, lib6"
// v = "lib1, lib2, lib3"
// s = "lib3, lib1, lib2"
// => "lib3, lib1, lib2"

s, ok := parameters[k].(string)
if k == "shared_preload_libraries" && ok {
parameters[k] = v + "," + s
mandatoryLibraries := strings.Split(strings.ReplaceAll(v, " ", ""), ",")
definedlibraries := strings.Split(strings.ReplaceAll(s, " ", ""), ",")

nonDefinedMandatoryLibraries := make([]string, 0)

for _, value := range mandatoryLibraries {
if !slices.Contains(definedlibraries, value) {
nonDefinedMandatoryLibraries = append(nonDefinedMandatoryLibraries, value)
}
}

parameters[k] = strings.Join(append(nonDefinedMandatoryLibraries, definedlibraries...), ", ")
} else {
parameters[k] = v
}
Expand Down
54 changes: 54 additions & 0 deletions internal/patroni/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,60 @@ func TestDynamicConfiguration(t *testing.T) {
"use_slots": false,
},
},
{
name: "postgresql.parameters: mandatory shared_preload_libraries containing a mandatory",
input: map[string]interface{}{
"postgresql": map[string]interface{}{
"parameters": map[string]interface{}{
"shared_preload_libraries": "given1, mandatory1, given2",
},
},
},
params: postgres.Parameters{
Mandatory: parameters(map[string]string{
"shared_preload_libraries": "mandatory1, mandatory2, mandatory3",
}),
},
expected: map[string]interface{}{
"loop_wait": int32(10),
"ttl": int32(30),
"postgresql": map[string]interface{}{
"parameters": map[string]interface{}{
"shared_preload_libraries": "mandatory2, mandatory3, given1, mandatory1, given2",
},
"pg_hba": []string{},
"use_pg_rewind": true,
"use_slots": false,
},
},
},
{
name: "postgresql.parameters: mandatory shared_preload_libraries order from shared_preload_libraries, no duplicates",
input: map[string]interface{}{
"postgresql": map[string]interface{}{
"parameters": map[string]interface{}{
"shared_preload_libraries": "mandatory2, mandatory3, mandatory1",
},
},
},
params: postgres.Parameters{
Mandatory: parameters(map[string]string{
"shared_preload_libraries": "mandatory1, mandatory2, mandatory3",
}),
},
expected: map[string]interface{}{
"loop_wait": int32(10),
"ttl": int32(30),
"postgresql": map[string]interface{}{
"parameters": map[string]interface{}{
"shared_preload_libraries": "mandatory2, mandatory3, mandatory1",
},
"pg_hba": []string{},
"use_pg_rewind": true,
"use_slots": false,
},
},
},
},
{
name: "postgresql.pg_hba: wrong-type is ignored",
Expand Down