pgadapter

package module
v0.0.0-...-e6f305a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ConnectToEmulator specifies whether PGAdapter should connect to the Cloud Spanner emulator,
	// or whether it should connect to real Cloud Spanner.
	// Setting this option to true will force the use of Docker as the ExecutionEnvironment, and all
	// other configuration options will be ignored.
	ConnectToEmulator bool

	// ExecutionEnvironment determines the execution environment that is used to start
	// PGAdapter.
	//
	// Java starts PGAdapter on localhost as a Java application. This requires Java to be
	// installed on the local system. See for example https://adoptium.net/installation/
	// for information on how to install an open-source Java distribution on your system.
	//
	// Java is the recommended setting for production environments, as it means that your
	// application and PGAdapter are both running on the same host, and the network traffic
	// does not need to pass over the host-to-Docker network bridge. Note that it is perfectly
	// OK to run both your application and PGAdapter in the same Docker container.
	//
	// The Java process is automatically shut down when your application shuts down.
	//
	// Docker starts PGAdapter in a test container instance. This is recommended for testing
	// and development, but not for production, as it means that the network communication
	// between your application and PGAdapter crosses the host-to-Docker network bridge.
	// This network interface is slow compared to network communication directly on localhost.
	//
	// This variable must be set.
	ExecutionEnvironment ExecutionEnvironment

	// Project specifies the Google Cloud project that PGAdapter should connect to.
	// This value is optional. If it is not set, clients that connect to the PGAdapter
	// instance must use a fully qualified database name when connecting.
	Project string
	// Instance specifies the Google Cloud Spanner instance that PGAdapter should
	// connect to. This value is optional. If it is not set, clients that connect
	// to the PGAdapter instance must use a fully qualified database name when connecting.
	Instance string
	// Database specifies the Google Cloud Spanner database that PGAdapter should
	// connect to. This value is optional. If it is set, any database name in the
	// connection URL of a PostgreSQL client will be ignored, and PGAdapter will always
	// connect to this specific database.
	// If Database is not set, then PGAdapter will use the database name from the
	// PostgreSQL connection URL.
	Database string
	// CredentialsFile is the user account or service account key file that PGAdapter
	// should use to connect to Cloud Spanner.
	// This value is optional. If it is not set, PGAdapter will use the default
	// credentials in the runtime environment.
	CredentialsFile string
	// Set RequireAuthentication to instruct PGAdapter to require PostgreSQL clients
	// to authenticate when connecting. When enabled, clients must supply the Google
	// Cloud credentials that should be used in the password field of the startup
	// message. See https://github.com/GoogleCloudPlatform/pgadapter/docs/authentication.md
	// for more information.
	RequireAuthentication bool

	// MinSessions is the minimum number of Cloud Spanner sessions in the internal
	// session pool of PGAdapter. These sessions are created directly when PGAdapter
	// is started.
	MinSessions int
	// MaxSessions is the maximum number of Cloud Spanner sessions in the internal
	// session pool of PGAdapter. The maximum number of sessions should be set to
	// the maximum number of concurrent transactions that your application might
	// execute.
	MaxSessions int
	// NumChannels is the number of gRPC channels that PGAdapter creates and uses
	// to communicate with Cloud Spanner.
	NumChannels int
	// DatabaseRole specifies the fine-grained access control role that PGAdapter
	// should use when connecting to Cloud Spanner.
	DatabaseRole string

	// Port is the host TCP port where PGAdapter should listen for incoming connections.
	// The port must not be in use by any other process.
	// Use port 0 to dynamically assign an available port to PGAdapter.
	//
	// The port must be 0 (dynamic assignment) for execution environment Docker.
	Port int

	// Version is the PGAdapter version that should be started.
	// Leave this string empty to use the most recent version.
	Version string
}

type Docker

type Docker struct {
	// Set AlwaysPullImage to true to ensure that the latest image of PGAdapter is
	// pulled before it is started.
	AlwaysPullImage bool
	// Set KeepContainer to keep the container after it has stopped. The Docker
	// container is started with the '--rm' option by default, unless this option
	// is set.
	KeepContainer bool
}

Docker contains the specific configuration for running PGAdapter in a test Docker container. This Docker execution environment can be used for tests and development. You should however not use this Docker execution environment in production, as it uses a test container. Instead, you should package both your application and PGAdapter in the same Docker container if you want to use Docker in production, or set up PGAdapter as a side-car process in your Kubernetes cluster.

func (*Docker) Command

func (docker *Docker) Command(config Config) (string, error)

type DownloadSettings

type DownloadSettings struct {
	// DownloadLocation specifies the location where the PGAdapter jar should be
	// stored. It will use the directory that is returned by os.UserCacheDirectory()
	// if no location is specified.
	DownloadLocation string

	// DisableAutomaticDownload can be used to disable the automatic download of the
	// PGAdapter jar. Set this if you do not want this wrapper to automatically download
	// the PGAdapter jar, for example if the machine does not have permission to write
	// to the local file system.
	DisableAutomaticDownload bool
}

DownloadSettings determines where the PGAdapter jar will be downloaded.

type ExecutionEnvironment

type ExecutionEnvironment interface {
	// Command returns the command and arguments that is the equivalent of
	// this ExecutionEnvironment. Use the output of this command to get the
	// equivalent command for starting PGAdapter manually.
	//
	// Example return value for Java:
	//
	// java -jar pgadapter.jar -p my-project -i my-instance -d my-database -c /path/to/credentials.json
	//
	// Example return value for Docker:
	//
	// docker run
	// 	 -d \
	//   -p 5432 \
	//   gcr.io/cloud-spanner-pg-adapter/pgadapter \
	//   -p my-project -i my-instance -d my-database \
	//   -c /credentials.json -x
	Command(config Config) (string, error)
	// contains filtered or unexported methods
}

ExecutionEnvironment is the common interface for the supported execution environments for PGAdapter. Currently, Java and Docker are supported.

type Java

type Java struct {
	DownloadSettings DownloadSettings
}

Java holds the specific configuration for running PGAdapter as a Java application.

func (*Java) Command

func (java *Java) Command(config Config) (string, error)

type PGAdapter

type PGAdapter struct {
	// contains filtered or unexported fields
}

func Start

func Start(ctx context.Context, config Config) (pgadapter *PGAdapter, err error)

Start starts a PGAdapter instance using the specified Config and returns a reference to a PGAdapter instance.

The PGAdapter instance is started either as a Docker container or a Java application, depending on the ExecutionEnvironment that is set in the config. If no ExecutionEnvironment has been set, it will default to Java if that is available on this system, and otherwise fall back to Docker.

The PGAdapter instance will automatically shut down when your application shuts down gracefully. It is not guaranteed that PGAdapter will be shut down if your application is killed or crashes. You can manually stop PGAdapter by calling Stop() on the returned instance.

Call GetHostPort() to get the port where PGAdapter is listening for incoming connections.

func (*PGAdapter) GetHostPort

func (pgadapter *PGAdapter) GetHostPort() (int, error)

GetHostPort returns the port on the current host machine where PGAdapter is listening for incoming PostgreSQL connections. Call this method to get the port number that was dynamically assigned to PGAdapter if you use dynamic port assignment.

func (*PGAdapter) Stop

func (pgadapter *PGAdapter) Stop(ctx context.Context) error

Stop stops the PGAdapter instance.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL