common

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 28 Imported by: 0 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.

Documentation

Overview

Package common contains reusable structs and methods for CNPGI plugins.

Index

Constants

View Source
const (
	// DefaultWALSegmentSize is the default size of a single WAL file
	// This must be a power of 2.
	DefaultWALSegmentSize = int64(1 << 24)

	// WALHexOctetRe is a regex to match 8 Hex characters.
	WALHexOctetRe = `([\dA-Fa-f]{8})`

	// WALTimeLineRe is a regex to match the timeline in a WAL filename.
	WALTimeLineRe = WALHexOctetRe

	// WALSegmentNameRe is a regex to match the segment parent log file and segment id.
	WALSegmentNameRe = WALHexOctetRe + WALHexOctetRe
)
View Source
const PgWalVolumePgWalPath = "/var/lib/postgresql/wal/pg_wal"

PgWalVolumePgWalPath is the path of the pg_wal directory inside the WAL volume, used when a separate WAL storage is configured: the restore moves pg_wal there and symlinks it into PGDATA.

Variables

View Source
var (
	// WALRe is the file segment name parser.
	WALRe = regexp.MustCompile(`^` +

		WALTimeLineRe +

		`(?:` +

		WALSegmentNameRe +

		`(?:` +

		`\.[\dA-Fa-f]{8}\.backup` +

		`|` +

		`\.partial` +

		`)?` +

		`|` +

		`\.history` +

		`)$`)

	// WALSegmentRe is the file segment name parser.
	WALSegmentRe = regexp.MustCompile(`^` +

		WALTimeLineRe +

		WALSegmentNameRe +
		`$`)

	// ErrBadWALSegmentName is raised when parsing an invalid segment name.
	ErrBadWALSegmentName = errors.New("invalid WAL segment name")
)
View Source
var ErrEndOfWALStreamReached = status.Error(codes.OutOfRange, "end of WAL reached")

ErrEndOfWALStreamReached is returned when end of WAL is detected in the cloud archive.

View Source
var ErrMissingPermissions = status.Error(codes.FailedPrecondition,
	"backup credentials don't yet have access permissions. Will retry reconciliation loop")

ErrMissingPermissions is returned when the plugin doesn't have the required permissions.

Functions

func AddHealthCheck

func AddHealthCheck(server *grpc.Server)

AddHealthCheck adds a health check service to the gRPC server with the tag 'plugin-pgbackrest'

func IsWALFile

func IsWALFile(name string) bool

IsWALFile check if the passed file name is a regular WAL file. It supports either a full file path or a simple file name.

func WalSegmentsPerFile

func WalSegmentsPerFile(walSegmentSize int64) int32

WalSegmentsPerFile is the number of WAL Segments in a WAL File.

Types

type DestinationCheck added in v0.9.0

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

DestinationCheck remembers the archive destination that the last WAL batch was successfully pushed to. While batches keep succeeding against the same destination, Archive skips CheckWalArchiveDestination, which runs "pgbackrest info" against the repository. A failed batch or a change of the destination brings the check back.

A nil *DestinationCheck remembers nothing, so the check runs for every batch.

type Segment

type Segment struct {
	// Timeline number
	Tli int32

	// Log number
	Log int32

	// Segment number
	Seg int32
}

Segment contains the information inside a WAL segment name.

func MustSegmentFromName

func MustSegmentFromName(name string) Segment

MustSegmentFromName is analogous to SegmentFromName but panics if the segment name is invalid.

func SegmentFromName

func SegmentFromName(name string) (Segment, error)

SegmentFromName retrieves the timeline, log ID and segment ID from the name of a xlog segment, and can also handle a full path or a simple file name.

func (Segment) Name

func (segment Segment) Name() string

Name gets the name of the segment.

func (Segment) NextSegments

func (segment Segment) NextSegments(size int, postgresVersion *int, segmentSize *int64) []Segment

NextSegments generate the list of all possible segment names starting from `segment`, until the specified size is reached. This function will not ever generate timeline changes. If postgresVersion == nil, the latest postgres version is assumed. If segmentSize == nil, wal_segment_size=DefaultWALSegmentSize is assumed.

type WALServiceImplementation

type WALServiceImplementation struct {
	wal.UnimplementedWALServer
	Client         client.Client
	InstanceName   string
	SpoolDirectory string
	PGDataPath     string
	PGWALPath      string
	// DestinationCheck lets Archive skip the repository check while batches keep
	// succeeding. When nil, the repository is checked before every batch.
	DestinationCheck *DestinationCheck
}

WALServiceImplementation is the implementation of the WAL Service

func (WALServiceImplementation) Archive

Archive implements the WALService interface

func (WALServiceImplementation) GetCapabilities

GetCapabilities implements the WALService interface

func (WALServiceImplementation) Restore

Restore implements the WALService interface nolint: gocognit

func (WALServiceImplementation) SetFirstRequired

SetFirstRequired implements the WALService interface

func (WALServiceImplementation) Status

Status implements the WALService interface

Jump to

Keyboard shortcuts

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