pgbackrest.git / summary / log / commit / refs
commit 0fe7bb2ec4d6ba10af8f2a6fd736e2c4cbdb2af2
Author: David Steele <david@pgmasters.net>
Date: Thu Jan 09 19:20:13 2020 +0000
Improve code that updates/removes pg options passed to a remote.
The prior code was updating/removing hard-coded options but new options are added all the time and there was no indication that this code needed to be updated. For example, dc1e7ca2 added the pg-user option but this code was not updated.
Instead find the options to update/remove dynamically. The new code uses prefixes, which is not perfect, but the patterns for pg options are pretty well established and this seems safer than the existing code.
src/protocol/helper.c | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/src/protocol/helper.c b/src/protocol/helper.c
index 0a35df109..db1649545 100644
--- a/src/protocol/helper.c
+++ b/src/protocol/helper.c
@@ -265,24 +265,29 @@ protocolRemoteParam(ProtocolStorageType protocolStorageType, unsigned int protoc
optionReplace, VARSTR(CFGOPT_CONFIG_PATH_STR),
cfgOptionSource(optConfigPath) != cfgSourceDefault ? cfgOption(optConfigPath) : NULL);
- // Copy pg options to index 0 since that's what the remote will be expecting
- if (hostIdx != 0)
- {
- kvPut(optionReplace, VARSTR(CFGOPT_PG1_PATH_STR), cfgOption(cfgOptPgPath + hostIdx));
- kvPut(
- optionReplace, VARSTR(CFGOPT_PG1_SOCKET_PATH_STR),
- cfgOptionSource(cfgOptPgSocketPath + hostIdx) != cfgSourceDefault ? cfgOption(cfgOptPgSocketPath + hostIdx) : NULL);
- kvPut(
- optionReplace, VARSTR(CFGOPT_PG1_PORT_STR),
- cfgOptionSource(cfgOptPgPort + hostIdx) != cfgSourceDefault ? cfgOption(cfgOptPgPort + hostIdx) : NULL);
- }
+ // Update/remove pg options that are sent to the remote
+ const String *pgHostPrefix = STR(cfgDefOptionName(cfgDefOptPgHost));
+ const String *pgPrefix = strNewFmt("%s-", PROTOCOL_REMOTE_TYPE_PG);
- // Remove pg options that are not needed on the remote. This is to reduce clustter and make debugging options easier.
- for (unsigned int pgIdx = 1; pgIdx < cfgOptionIndexTotal(cfgOptPgPath); pgIdx++)
+ for (ConfigOption optionId = 0; optionId < CFG_OPTION_TOTAL; optionId++)
{
- kvPut(optionReplace, VARSTRZ(cfgOptionName(cfgOptPgPath + pgIdx)), NULL);
- kvPut(optionReplace, VARSTRZ(cfgOptionName(cfgOptPgSocketPath + pgIdx)), NULL);
- kvPut(optionReplace, VARSTRZ(cfgOptionName(cfgOptPgPort + pgIdx)), NULL);
+ const String *optionDefName = STR(cfgDefOptionName(cfgOptionDefIdFromId(optionId)));
+
+ if (strBeginsWith(optionDefName, pgPrefix) && !strBeginsWith(optionDefName, pgHostPrefix) && cfgOptionIndex(optionId) > 0)
+ {
+ // If the option index matches the host-id then this is a pg option that the remote needs. Since the remote expects to
+ // find pg options in index 0 copy the option to index 0.
+ if (cfgOptionIndex(optionId) == hostIdx)
+ {
+ kvPut(
+ optionReplace, VARSTRZ(cfgOptionName(optionId - hostIdx)),
+ cfgOptionSource(optionId) != cfgSourceDefault ? cfgOption(optionId) : NULL);
+ }
+
+ // Remove pg options that are not needed on the remote. The remote is only going to look at index 0 so the options in
+ // higher indexes will not be used and just add clutter which makes debugging harder.
+ kvPut(optionReplace, VARSTRZ(cfgOptionName(optionId)), NULL);
+ }
}
// Add the command option (or use the current command option if it is valid)
[parent: 4c8653fc8bc6]