common

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package common contains reusable structs and methods for CNPGI plugins.

Index

Constants

View Source
const (
	// ScratchDataDirectory is the directory to be used for scratch data.
	ScratchDataDirectory = "/controller"

	// CertificatesDir location to store the certificates.
	CertificatesDir = ScratchDataDirectory + "/certificates/"

	// BarmanBackupEndpointCACertificateLocation is the location where the barman endpoint
	// CA certificate is stored.
	BarmanBackupEndpointCACertificateLocation = CertificatesDir + BarmanBackupEndpointCACertificateFileName

	// BarmanBackupEndpointCACertificateFileName is the name of the file in which the barman endpoint
	// CA certificate for backups is stored.
	BarmanBackupEndpointCACertificateFileName = "backup-" + BarmanEndpointCACertificateFileName

	// BarmanRestoreEndpointCACertificateFileName is the name of the file in which the barman endpoint
	// CA certificate for restores is stored.
	BarmanRestoreEndpointCACertificateFileName = "restore-" + BarmanEndpointCACertificateFileName

	// BarmanEndpointCACertificateFileName is the name of the file in which the barman endpoint
	// CA certificate is stored.
	BarmanEndpointCACertificateFileName = "barman-ca.crt"
)

TODO: refactor.

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
)

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 = errors.New("end of WAL reached")

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

Functions

func AddHealthCheck

func AddHealthCheck(server *grpc.Server)

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

func GetRestoreCABundleEnv

func GetRestoreCABundleEnv(configuration *barmanapi.BarmanObjectStoreConfiguration) []string

GetRestoreCABundleEnv gets the enveronment variables to be used when custom Object Store CA is present

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 MergeEnv

func MergeEnv(env []string, incomingEnv []string) []string

MergeEnv merges all the values inside incomingEnv into env.

func WalSegmentsPerFile

func WalSegmentsPerFile(walSegmentSize int64) int32

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

Types

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
}

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