Skip to content

Commit

Permalink
cliflags: deprecate using without --sql-addr
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
knz committed Aug 9, 2022
1 parent d687b14 commit e103959
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
23 changes: 17 additions & 6 deletions pkg/cli/cliflags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
<PRE>
</PRE>
Expand All @@ -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.
<PRE>
</PRE>
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{
Expand Down Expand Up @@ -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.
<PRE>
</PRE>
Expand All @@ -536,7 +540,14 @@ to use the same port number but separate host addresses.
</PRE>
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.
<PRE>
</PRE>
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{
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down
12 changes: 9 additions & 3 deletions pkg/cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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=<host/IP 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=<host/IP addr>\n", host)
}
}

Expand Down

0 comments on commit e103959

Please sign in to comment.