From e1039597f6272e66f0633fee81bcc0f853cede00 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Fri, 5 Aug 2022 15:06:47 +0200 Subject: [PATCH] cliflags: deprecate using without `--sql-addr` Release note (backward-incompatible change): Using a single TCP port listener for both RPC (node-node) and SQL client connections is now deprecated. This capability will be removed in the next version of CockroachDB. Deployments are invited to perform either one of the following changes: - (preferred:) keep port 26257 for SQL, and allocate a new port, e.g. 36257, for node-node RPC connections. For example: --listen-addr=:36257 --sql-addr=:26257 \ --join=othernode:36257,othernode:26257 This will become the default configuration in the next version of CockroachDB. When using this mode of operation, care should be taken to use a `--join` flag that include both the old and new port numbers for other nodes, so that no network partition occurs during the upgrade. - (optional:) keep port 26257 for RPC, and allocate a new port, e.g. 36257, for SQL connections. For example: --listen-addr=:26257 --sql-addr=:36257 When using this mode of operation, the `--join` flags do not need to be modified. However, SQL client apps or the SQL load balancer configuration (when in use) should be updated to use the new SQL port number. --- pkg/cli/cliflags/flags.go | 23 +++++++++++++++++------ pkg/cli/flags.go | 2 +- pkg/cli/start.go | 12 +++++++++--- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/pkg/cli/cliflags/flags.go b/pkg/cli/cliflags/flags.go index 653374eb2a5c..d4283a200011 100644 --- a/pkg/cli/cliflags/flags.go +++ b/pkg/cli/cliflags/flags.go @@ -443,8 +443,6 @@ in a later version.`, The address/hostname and port to listen on for intra-cluster communication, for example --listen-addr=myhost:26257 or --listen-addr=:26257 (listen on all interfaces). -Unless --sql-addr is also specified, this address is also -used to accept SQL client connections.
 
 
@@ -462,7 +460,15 @@ example [::1]:26257 or [fe80::f6f2:::]:26257. If --advertise-addr is left unspecified, the node will also announce this address for use by other nodes. It is strongly recommended to use --advertise-addr in cloud and container deployments or any setup where -NAT is present between cluster nodes.`, +NAT is present between cluster nodes. +
+
+
+Unless --sql-addr is also specified, this address is also +used to accept SQL client connections. Using --listen-addr +to specify the SQL address without --sql-addr is a deprecated +feature. +`, } ServerHost = FlagInfo{ @@ -515,8 +521,6 @@ forwarding is set up on an intermediate firewall/router.`, Description: ` The hostname or IP address to bind to for SQL clients, for example --sql-addr=myhost:26257 or --sql-addr=:26257 (listen on all interfaces). -If left unspecified, the address specified by --listen-addr will be -used for both RPC and SQL connections.
 
 
@@ -536,7 +540,14 @@ to use the same port number but separate host addresses. An IPv6 address can also be specified with the notation [...], for -example [::1]:26257 or [fe80::f6f2:::]:26257.`, +example [::1]:26257 or [fe80::f6f2:::]:26257. +
+
+
+If --sql-addr is left unspecified, the address specified by +--listen-addr will be used for both RPC and SQL connections. +This default behavior is deprecated; we recommend always +setting --sql-addr.`, } SQLAdvertiseAddr = FlagInfo{ diff --git a/pkg/cli/flags.go b/pkg/cli/flags.go index 878cb818e3df..55819e1ac9ff 100644 --- a/pkg/cli/flags.go +++ b/pkg/cli/flags.go @@ -1046,7 +1046,7 @@ func extraServerFlagInit(cmd *cobra.Command) error { serverSQLPort = serverListenPort } serverCfg.SQLAddr = net.JoinHostPort(serverSQLAddr, serverSQLPort) - serverCfg.SplitListenSQL = fs.Lookup(cliflags.ListenSQLAddr.Name).Changed + serverCfg.SplitListenSQL = changed(fs, cliflags.ListenSQLAddr.Name) // Fill in the defaults for --advertise-sql-addr, if the flag exists on `cmd`. advSpecified := changed(fs, cliflags.AdvertiseAddr.Name) || diff --git a/pkg/cli/start.go b/pkg/cli/start.go index ba2efbce5b16..008ee15ba502 100644 --- a/pkg/cli/start.go +++ b/pkg/cli/start.go @@ -1076,17 +1076,23 @@ func expandTabsInRedactableBytes(s redact.RedactableBytes) (redact.RedactableByt func hintServerCmdFlags(ctx context.Context, cmd *cobra.Command) { pf := cliflagcfg.FlagSetForCmd(cmd) + sqlAddrSpecified := pf.Lookup(cliflags.ListenSQLAddr.Name).Changed + if !sqlAddrSpecified { + log.Ops.Shoutf(ctx, severity.WARNING, + "Running a server without --sql-addr, with a combined RPC/SQL listener, is deprecated.\n"+ + "This feature will be removed in the next version of CockroachDB.") + } + listenAddrSpecified := pf.Lookup(cliflags.ListenAddr.Name).Changed || pf.Lookup(cliflags.ServerHost.Name).Changed advAddrSpecified := pf.Lookup(cliflags.AdvertiseAddr.Name).Changed || pf.Lookup(cliflags.AdvertiseHost.Name).Changed - if !listenAddrSpecified && !advAddrSpecified { host, _, _ := net.SplitHostPort(serverCfg.AdvertiseAddr) log.Ops.Shoutf(ctx, severity.WARNING, "neither --listen-addr nor --advertise-addr was specified.\n"+ "The server will advertise %q to other nodes, is this routable?\n\n"+ "Consider using:\n"+ - "- for local-only servers: --listen-addr=localhost\n"+ - "- for multi-node clusters: --advertise-addr=\n", host) + "- for local-only servers: --listen-addr=localhost:26258 --sql-addr=localhost:26257\n"+ + "- for multi-node clusters: --listen-addr=:26258 --sql-addr=:26257 --advertise-addr=\n", host) } }