-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
externalconn, streamingccl: support external connections as replicati…
…on sources This PR adds support for creating external connections with the postgresql scheme and using them in a `CREATE TENANT ... FROM REPLICATION OF external://name` statement. Among other benefits, this lets users validate their postgresql connection strings before creating the job, as creating the external connection will ping the source DB. Release note (enterprise change): Added support for `CREATE EXTERNAL CONNECTION ... AS "postgresql://"` or `"postgres://"`. These external connections may be specified as the source in streaming replication.
- Loading branch information
Showing
11 changed files
with
113 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package streamingest | ||
|
||
import ( | ||
"context" | ||
"net/url" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/ccl/streamingccl/streamclient" | ||
"github.com/cockroachdb/cockroach/pkg/cloud/externalconn" | ||
"github.com/cockroachdb/cockroach/pkg/cloud/externalconn/connectionpb" | ||
"github.com/cockroachdb/cockroach/pkg/security/username" | ||
) | ||
|
||
// The canonical PostgreSQL URL scheme is "postgresql", however our | ||
// own client commands also accept "postgres". | ||
func postgresSchemes() [2]string { | ||
return [2]string{"postgres", "postgresql"} | ||
} | ||
|
||
func validatePostgresConnectionURI( | ||
ctx context.Context, execCfg interface{}, user username.SQLUsername, uri string, | ||
) error { | ||
parsedURI, err := url.Parse(uri) | ||
if err != nil { | ||
return err | ||
} | ||
conn, err := streamclient.NewPartitionedStreamClient(ctx, parsedURI) | ||
if err != nil { | ||
return err | ||
} | ||
if err = conn.Dial(ctx); err != nil { | ||
return err | ||
} | ||
return conn.Close(ctx) | ||
} | ||
|
||
func init() { | ||
for _, scheme := range postgresSchemes() { | ||
externalconn.RegisterConnectionDetailsFromURIFactory( | ||
scheme, | ||
connectionpb.ConnectionProvider_sql, | ||
externalconn.SimpleURIFactory, | ||
) | ||
|
||
externalconn.RegisterDefaultValidation(scheme, validatePostgresConnectionURI) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters