gcpspanner

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 55 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Cloud Spanner

Parity grade: B · SDK cloud.google.com/go/spanner@v1.96.1 · last audited 2026-11-21 (364908f83)

Coverage

Metric Value
PARITY entries audited 38 (37 ok, 1 partial)
Feature families 4 (1 ok, 3 partial)
Known gaps 1
Deferred items 0
Resource leaks clean
Known gaps
  • Without a container runtime DDL folding does not type-check column types, DEFAULT / generated-column / ON UPDATE / CHECK expressions, foreign key bodies beyond name resolution, or view queries: that needs the GoogleSQL and PostgreSQL analyzers, which only the emulator holds. ALTER COLUMN ... ALTER IDENTITY, ALTER SEARCH INDEX, ALTER VECTOR INDEX, ALTER PROPERTY GRAPH, PostgreSQL ALTER INDEX SET options, RENAME WITH SYNONYM and ADD ROW DELETION POLICY in PostgreSQL are still kept as verbatim statements (the printed form of their grammar was not available from the DDL reference pages).

More

Documentation

Index

Constants

View Source
const (
	// DefaultPort is the dedicated gRPC and REST listener's default TCP port.
	DefaultPort = 8135
	// EngineAuto runs the Cloud Spanner emulator container when a container runtime is reachable.
	EngineAuto = "auto"
	// EngineNone never starts a container: instances and databases are metadata only.
	EngineNone = "none"
	// DefaultImage is the pinned Google Cloud Spanner emulator image.
	DefaultImage = "gcr.io/cloud-spanner-emulator/emulator:1.5.40"
	// DefaultStartupTimeout bounds how long the emulator may take to pull its image and accept calls.
	DefaultStartupTimeout = 5 * time.Minute
)

Variables

View Source
var ErrNilAppContext = errors.New("gcpspanner: nil app context")

ErrNilAppContext is returned when Init is called with a nil AppContext.

View Source
var (

	// ErrRuntimeUnavailable is returned by a launcher when no container runtime can be reached.
	ErrRuntimeUnavailable = errors.New("container runtime unavailable")
)

Functions

This section is empty.

Types

type API

type API struct {
	Instances instancepb.InstanceAdminServer
	Databases databasepb.DatabaseAdminServer
}

API groups the Spanner admin services for in-process callers (dashboard proxy).

type ConfigProvider

type ConfigProvider interface {
	GetGCPSpannerSettings() Settings
}

ConfigProvider extracts Cloud Spanner configuration from the AppContext Config.

type Handler

type Handler struct {
	Backend *InMemoryBackend

	Port int
	// contains filtered or unexported fields
}

Handler serves the Cloud Spanner instance and database admin APIs and, through the emulator, the data plane on a dedicated gRPC and REST listener.

func NewHandler

func NewHandler(backend *InMemoryBackend) *Handler

NewHandler creates a Handler; callers override Port from Settings.

func (*Handler) API

func (h *Handler) API() *API

API exposes the instance and database admin services.

func (*Handler) Addr

func (h *Handler) Addr() string

Addr returns the bound listener address, or "" before StartWorker.

func (*Handler) ExtractOperation

func (h *Handler) ExtractOperation(*echo.Context) string

ExtractOperation is unused: requests never reach the shared router.

func (*Handler) ExtractResource

func (h *Handler) ExtractResource(*echo.Context) string

ExtractResource is unused: requests never reach the shared router.

func (*Handler) GetSupportedOperations

func (h *Handler) GetSupportedOperations() []string

GetSupportedOperations lists the operations the backend answers itself; every other Spanner and DatabaseAdmin method is proxied to the emulator.

func (*Handler) Handler

func (h *Handler) Handler() echo.HandlerFunc

Handler returns a 404 handler; the real API is on the dedicated port.

func (*Handler) MatchPriority

func (h *Handler) MatchPriority() int

MatchPriority is irrelevant because RouteMatcher never matches.

func (*Handler) Name

func (h *Handler) Name() string

Name returns the service name.

func (*Handler) Reset

func (h *Handler) Reset()

Reset clears all state and stops the emulator.

func (*Handler) Restore

func (h *Handler) Restore(ctx context.Context, data []byte) error

Restore implements persistence.Persistable by delegating to the backend.

func (*Handler) RouteMatcher

func (h *Handler) RouteMatcher() service.Matcher

RouteMatcher never matches: Cloud Spanner runs on its own listener.

func (*Handler) Shutdown

func (h *Handler) Shutdown(ctx context.Context)

Shutdown stops the listener and the emulator, forcing a close after a short grace period.

func (*Handler) Snapshot

func (h *Handler) Snapshot(ctx context.Context) []byte

Snapshot implements persistence.Persistable by delegating to the backend.

func (*Handler) StartWorker

func (h *Handler) StartWorker(ctx context.Context) error

StartWorker binds the dedicated listener synchronously so a port conflict is returned to the caller.

type InMemoryBackend

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

InMemoryBackend holds all Cloud Spanner admin state under one lock. The data plane lives in the emulator.

func NewInMemoryBackend

func NewInMemoryBackend() *InMemoryBackend

NewInMemoryBackend creates an empty backend with no data plane; see SetLauncher.

func (*InMemoryBackend) Close

func (b *InMemoryBackend) Close()

Close stops the emulator and waits for background work.

func (*InMemoryBackend) CopyBackup

CopyBackup copies a READY backup, possibly into another instance of the same project.

func (*InMemoryBackend) CreateBackup

CreateBackup records a backup of a database and captures its schema and rows in the background.

func (*InMemoryBackend) CreateDatabase

CreateDatabase creates a database, executing its DDL in the emulator when one is available.

func (*InMemoryBackend) CreateInstance

CreateInstance starts creating an instance; the operation completes once the data plane has it too.

func (*InMemoryBackend) CreateInstanceConfig

CreateInstanceConfig creates a user-managed configuration from a Google-managed base.

func (*InMemoryBackend) CreateInstancePartition

CreateInstancePartition creates a partition in an instance.

func (*InMemoryBackend) DeleteBackup

func (b *InMemoryBackend) DeleteBackup(name string) (*emptypb.Empty, error)

DeleteBackup deletes a backup that no restored database or copy still refers to.

func (*InMemoryBackend) DeleteInstance

func (b *InMemoryBackend) DeleteInstance(name string) (*emptypb.Empty, error)

DeleteInstance deletes an instance together with its databases.

func (*InMemoryBackend) DeleteInstanceConfig

func (b *InMemoryBackend) DeleteInstanceConfig(in *instancepb.DeleteInstanceConfigRequest) (*emptypb.Empty, error)

DeleteInstanceConfig deletes a user-managed configuration that no instance uses.

func (*InMemoryBackend) DeleteInstancePartition

func (b *InMemoryBackend) DeleteInstancePartition(
	in *instancepb.DeleteInstancePartitionRequest,
) (*emptypb.Empty, error)

DeleteInstancePartition deletes a partition.

func (*InMemoryBackend) DropDatabase

func (b *InMemoryBackend) DropDatabase(ctx context.Context, name string) (*emptypb.Empty, error)

DropDatabase deletes a database unless drop protection is on.

func (*InMemoryBackend) GetBackup

func (b *InMemoryBackend) GetBackup(name string) (*databasepb.Backup, error)

GetBackup returns a backup.

func (*InMemoryBackend) GetDatabase

func (b *InMemoryBackend) GetDatabase(name string) (*databasepb.Database, error)

GetDatabase returns a database.

func (*InMemoryBackend) GetDatabaseDdl

func (b *InMemoryBackend) GetDatabaseDdl(name string) (*databasepb.GetDatabaseDdlResponse, error)

GetDatabaseDdl returns the DDL statements of a database.

func (*InMemoryBackend) GetIamPolicy

func (b *InMemoryBackend) GetIamPolicy(resource string, version int32) (*iampb.Policy, error)

GetIamPolicy returns the policy of an instance at the requested version.

func (*InMemoryBackend) GetInstance

func (b *InMemoryBackend) GetInstance(name string) (*instancepb.Instance, error)

GetInstance returns an instance.

func (*InMemoryBackend) GetInstanceConfig

func (b *InMemoryBackend) GetInstanceConfig(name string) (*instancepb.InstanceConfig, error)

GetInstanceConfig returns one configuration.

func (*InMemoryBackend) GetInstancePartition

func (b *InMemoryBackend) GetInstancePartition(name string) (*instancepb.InstancePartition, error)

GetInstancePartition returns a partition.

func (*InMemoryBackend) ListBackupOperations

ListBackupOperations lists the CreateBackup and CopyBackup operations of an instance, newest first.

func (*InMemoryBackend) ListBackups

ListBackups lists the backups of an instance in name order.

func (*InMemoryBackend) ListDatabaseOperations

ListDatabaseOperations lists the operations of the databases of an instance.

func (*InMemoryBackend) ListDatabases

ListDatabases lists the databases of an instance.

func (*InMemoryBackend) ListInstanceConfigOperations

ListInstanceConfigOperations lists the operations of user-managed configurations of a project.

func (*InMemoryBackend) ListInstanceConfigs

ListInstanceConfigs lists the Google-managed configurations of a project.

func (*InMemoryBackend) ListInstancePartitionOperations

ListInstancePartitionOperations lists the partition operations of an instance.

func (*InMemoryBackend) ListInstancePartitions

ListInstancePartitions lists the partitions of an instance, or of every instance with instances/-.

func (*InMemoryBackend) ListInstances

ListInstances lists the instances of a project.

func (*InMemoryBackend) MoveInstance

MoveInstance moves an instance to another configuration.

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset stops the emulator and clears all state.

func (*InMemoryBackend) Restore

func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error

Restore loads a snapshot. Instances caught mid-creation are dropped; the emulator starts empty on first use and is rebuilt from the restored schema.

func (*InMemoryBackend) RestoreDatabase

RestoreDatabase creates a database from a backup: its schema and rows as captured, in the emulator when a data plane is available. The database stays READY_OPTIMIZING, and the backup referenced, until the optimize operation finishes.

func (*InMemoryBackend) SetIamPolicy

func (b *InMemoryBackend) SetIamPolicy(in *iampb.SetIamPolicyRequest) (*iampb.Policy, error)

SetIamPolicy replaces the policy of an instance; a stale etag aborts the call.

func (*InMemoryBackend) SetKeyChecker

func (b *InMemoryBackend) SetKeyChecker(c cmek.Checker)

SetKeyChecker validates database encryption keys against Cloud KMS; without one, encryption_config is UNIMPLEMENTED.

func (*InMemoryBackend) SetLauncher

func (b *InMemoryBackend) SetLauncher(l launcher)

SetLauncher connects the data plane to an emulator launcher; nil leaves the backend metadata only.

func (*InMemoryBackend) Snapshot

func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte

Snapshot serialises instances, policies, databases, their DDL and, from a running emulator, the rows of every GoogleSQL table (bounded by maxPersistRows and maxPersistBytes). A fresh emulator replays both on first use.

func (*InMemoryBackend) TestIamPermissions

TestIamPermissions reports the requested Spanner permissions as granted: the emulator authorises all callers.

func (*InMemoryBackend) UpdateBackup

UpdateBackup changes the expire_time of a READY backup.

func (*InMemoryBackend) UpdateDatabase

UpdateDatabase updates enable_drop_protection, the only mutable database field.

func (*InMemoryBackend) UpdateDatabaseDdl

UpdateDatabaseDdl applies DDL statements, in the emulator when one is available.

func (*InMemoryBackend) UpdateInstance

UpdateInstance applies the masked fields of the instance.

func (*InMemoryBackend) UpdateInstanceConfig

UpdateInstanceConfig changes display_name and labels of a user-managed configuration.

func (*InMemoryBackend) UpdateInstancePartition

UpdateInstancePartition applies display_name, node_count, processing_units and autoscaling_config.

type Provider

type Provider struct{}

Provider implements service.Provider for Google Cloud Spanner. It serves gRPC and REST on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.

func (*Provider) Init

Init creates the backend and handler; the port is bound in StartWorker.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the service provider name.

type Settings

type Settings struct {
	Engine string `` //nolint:lll // config struct tags are intentionally verbose
	/* 267-byte string literal not displayed */
	Image string `` //nolint:lll // config struct tags are intentionally verbose
	/* 228-byte string literal not displayed */
	Port int `` //nolint:lll // config struct tags are intentionally verbose
	/* 265-byte string literal not displayed */
	StartupTimeout time.Duration `` //nolint:lll // config struct tags are intentionally verbose
	/* 235-byte string literal not displayed */
}

Settings holds service-level configuration, embedded in the root CLI command as CLI.GCPSpanner.

func DefaultSettings

func DefaultSettings() Settings

DefaultSettings returns the settings used when no ConfigProvider is available.

Jump to

Keyboard shortcuts

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