Skip to content
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

Feature/zero config pg autoctl #576

Merged
merged 10 commits into from
Feb 18, 2021
Merged

Conversation

DimCitus
Copy link
Collaborator

@DimCitus DimCitus commented Feb 2, 2021

Implement support for --monitor option and PG_AUTOCTL_MONITOR environment variable in many commands that don't need to have a local node already created. Those commands are:

pg_autoctl create formation
pg_autoctl drop formation

pg_autoctl get|set formation settings
pg_autoctl get|set formation number-sync-standbys
pg_autoctl get|set node replication-quorum
pg_autoctl get|set node candidate-priority

pg_autoctl show uri
pg_autoctl show events
pg_autoctl show state
pg_autoctl show settings
pg_autoctl show standby-names

pg_autoctl perform failover
pg_autoctl perform switchover
pg_autoctl perform promotion

The make cluster is also changed to use the PG_AUTOCTL_MONITOR environment variable rather than the monitor's PGDATA in the interactive terminal/session.

Fixes #437.

@DimCitus DimCitus added enhancement New feature or request Size:M Effort Estimate: Medium labels Feb 2, 2021
@DimCitus DimCitus added this to the Sprint 2021 W4 W5 milestone Feb 2, 2021
@DimCitus DimCitus requested a review from JelteF February 2, 2021 15:39
@DimCitus DimCitus self-assigned this Feb 2, 2021
Copy link
Contributor

@JelteF JelteF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played around with this a bit. Some issues:

  1. The --monitor argument doesn't actually seem to work (setting PG_AUTOCTL_MONITOR does work):
pg_autoctl show state --monitor 'postgres://autoctl_node@localhost:5500/pg_auto_failover?sslmode=prefer'
  1. When using --pgdata you still see this error in the output:
12:02:39 14800 ERROR Failed to get value for environment variable 'PG_AUTOCTL_MONITOR', which is unset
  1. When not specifying either --pgdata or --monitor the final fatal log should include something about --monitor and PG_AUTOCTL_MONITOR too:
11:55:49 4723 ERROR Failed to get value for environment variable 'PG_AUTOCTL_MONITOR', which is unset
11:55:49 4723 ERROR Failed to get value for environment variable 'PGDATA', which is unset
11:55:49 4723 FATAL Failed to set PGDATA either from the environment or from --pgdata

src/bin/pg_autoctl/cli_do_tmux.c Show resolved Hide resolved
src/bin/pg_autoctl/cli_formation.c Show resolved Hide resolved
src/bin/pg_autoctl/cli_formation.c Show resolved Hide resolved
src/bin/pg_autoctl/cli_perform.c Show resolved Hide resolved
src/bin/pg_autoctl/cli_show.c Outdated Show resolved Hide resolved
@DimCitus DimCitus force-pushed the feature/zero-config-pg_autoctl branch 2 times, most recently from 8fe3f61 to 1cd9bd2 Compare February 12, 2021 12:17
Copy link
Contributor

@JelteF JelteF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more issues:
1.

PG_AUTOCTL_MONITOR='postgres://autoctl_node@localhost:5500/pg_auto_failover?sslmode=require' pg_autoctl create formation --formation 'test' --kind pgsql
13:48:11 24106 ERROR BUG: keeper_config_set_pathnames_from_pgdata: empty pgdata
pg_autoctl create formation --formation 'test' --kind pgsql
13:51:00 30894 ERROR BUG: keeper_config_set_pathnames_from_pgdata: empty pgdata
pg_autoctl create formation --formation 'test' --kind pgsql --monitor 'postgres://autoctl_node@localhost:5500/pg_auto_failover?sslmode=require'
13:51:37 32484 ERROR Failed to get value for environment variable 'PGDATA', which is unset
13:51:37 32484 FATAL Failed to set PGDATA either from the environment or from --pgdata
  1. drop formation doesn't say it can use --monitor in the error message if you supply neither --monitor or --pgdata.
PG_AUTOCTL_MONITOR='postgres://autoctl_node@localhost:5500/pg_auto_failover?sslmode=require' pg_autoctl drop formation --formation 'test'
13:53:27 3635 ERROR Failed to get value for environment variable 'PGDATA', which is unset
13:53:27 3635 FATAL Failed to set PGDATA either from the environment or from --pgdata
  1. show standby-names --group 5 does not error when there's no group 5 (might be the case on master too)

Comment on lines +732 to +739
else if (streq(key, "sslcert"))
{
strlcpy(ssl->serverCert, val, sizeof(ssl->serverCert));
}
else if (streq(key, "sslkey"))
{
strlcpy(ssl->serverKey, val, sizeof(ssl->serverKey));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These ones are not necessary. These are postgresql.conf options, not connection options.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean. But in case we would reuse the function parse_pguri_ssl_settings ini other parts of the code I think it makes sense to still correctly parse those connection string parameters. After all those parameters are listed in https://www.postgresql.org/docs/current/libpq-connect.html.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you are totally right. My mistake, I forgot these are used for TLS user certs.

@DimCitus
Copy link
Collaborator Author

Some more issues:

I have changed the way the --monitor and --pgdata and PG_AUTOCTL_MONITOR and PGDATA are understood in many places except for the formation code path, that I had done first. Sorry about that. I have now updated the code to match our current expectations.

  1. show standby-names --group 5 does not error when there's no group 5 (might be the case on master too)

Yeah, so the server-side function was returning NULL, which we didn't test against in parseSingleValueResult. So I have added an explicit PQgetisnull check in there, and also changed the server-side function to report an error in the case where we find zero nodes.

@DimCitus DimCitus requested a review from JelteF February 12, 2021 16:22
This allows creating a formation from a node that's not been created yet.
    pg_autoctl get|set formation settings
	pg_autoctl get|set formation number-sync-standbys
	pg_autoctl get|set node replication-quorum
	pg_autoctl get|set node candidate-priority

    pg_autoctl show uri
    pg_autoctl show events
    pg_autoctl show state
    pg_autoctl show settings
    pg_autoctl show standby-names

	pg_autoctl perform failover
	pg_autoctl perform switchover
	pg_autoctl perform promotion
In particular, export PG_AUTOCT_MONITOR in the tmux session, and use
pg_autoctl show uri --formation monitor now.
The new command is pg_autoctl show uri --formation monitor.
@DimCitus DimCitus force-pushed the feature/zero-config-pg_autoctl branch from 0e41b9b to c3a7a2a Compare February 12, 2021 16:33
Copy link
Contributor

@JelteF JelteF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well now

@DimCitus DimCitus merged commit 5ef1078 into master Feb 18, 2021
@DimCitus DimCitus deleted the feature/zero-config-pg_autoctl branch February 18, 2021 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Size:M Effort Estimate: Medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How create formation before keeper node creation?
2 participants