Documentation
¶
Overview ¶
Package common contains reusable structs and methods for CNPGI plugins.
Index ¶
- Constants
- Variables
- func AddHealthCheck(server *grpc.Server)
- func IsWALFile(name string) bool
- func WalSegmentsPerFile(walSegmentSize int64) int32
- type DestinationCheck
- type Segment
- type WALServiceImplementation
- func (w WALServiceImplementation) Archive(ctx context.Context, request *wal.WALArchiveRequest) (*wal.WALArchiveResult, error)
- func (w WALServiceImplementation) GetCapabilities(_ context.Context, _ *wal.WALCapabilitiesRequest) (*wal.WALCapabilitiesResult, error)
- func (w WALServiceImplementation) Restore(ctx context.Context, request *wal.WALRestoreRequest) (*wal.WALRestoreResult, error)
- func (w WALServiceImplementation) SetFirstRequired(_ context.Context, _ *wal.SetFirstRequiredRequest) (*wal.SetFirstRequiredResult, error)
- func (w WALServiceImplementation) Status(ctx context.Context, request *wal.WALStatusRequest) (*wal.WALStatusResult, error)
Constants ¶
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 )
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 ¶
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") )
var ErrEndOfWALStreamReached = status.Error(codes.OutOfRange, "end of WAL reached")
ErrEndOfWALStreamReached is returned when end of WAL is detected in the cloud archive.
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 ¶
AddHealthCheck adds a health check service to the gRPC server with the tag 'plugin-pgbackrest'
func IsWALFile ¶
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 ¶
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 ¶
MustSegmentFromName is analogous to SegmentFromName but panics if the segment name is invalid.
func SegmentFromName ¶
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) NextSegments ¶
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 ¶
func (w WALServiceImplementation) Archive( ctx context.Context, request *wal.WALArchiveRequest, ) (*wal.WALArchiveResult, error)
Archive implements the WALService interface
func (WALServiceImplementation) GetCapabilities ¶
func (w WALServiceImplementation) GetCapabilities( _ context.Context, _ *wal.WALCapabilitiesRequest, ) (*wal.WALCapabilitiesResult, error)
GetCapabilities implements the WALService interface
func (WALServiceImplementation) Restore ¶
func (w WALServiceImplementation) Restore( ctx context.Context, request *wal.WALRestoreRequest, ) (*wal.WALRestoreResult, error)
Restore implements the WALService interface nolint: gocognit
func (WALServiceImplementation) SetFirstRequired ¶
func (w WALServiceImplementation) SetFirstRequired( _ context.Context, _ *wal.SetFirstRequiredRequest, ) (*wal.SetFirstRequiredResult, error)
SetFirstRequired implements the WALService interface
func (WALServiceImplementation) Status ¶
func (w WALServiceImplementation) Status( ctx context.Context, request *wal.WALStatusRequest, ) (*wal.WALStatusResult, error)
Status implements the WALService interface