pbm

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2022 License: Apache-2.0 Imports: 29 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// DB is a name of the PBM database
	DB = "admin"
	// LogCollection is the name of the mongo collection that contains PBM logs
	LogCollection = "pbmLog"
	// ConfigCollection is the name of the mongo collection that contains PBM configs
	ConfigCollection = "pbmConfig"
	// LockCollection is the name of the mongo collection that is used
	// by agents to coordinate mutually exclusive operations (e.g. backup/restore)
	LockCollection = "pbmLock"
	// LockOpCollection is the name of the mongo collection that is used
	// by agents to coordinate operations that doesn't need to be
	// mutually exclusive to other operation types (e.g. backup-delete)
	LockOpCollection = "pbmLockOp"
	// BcpCollection is a collection for backups metadata
	BcpCollection = "pbmBackups"
	// BcpOldCollection contains a backup of backups metadata
	BcpOldCollection = "pbmBackups.old"
	// RestoresCollection is a collection for restores metadata
	RestoresCollection = "pbmRestores"
	// CmdStreamCollection is the name of the mongo collection that contains backup/restore commands stream
	CmdStreamCollection = "pbmCmd"
	// PITRChunksCollection contains index metadata of PITR chunks
	PITRChunksCollection = "pbmPITRChunks"
	// PITRChunksOldCollection contains archived index metadata of PITR chunks
	PITRChunksOldCollection = "pbmPITRChunks.old"
	// PBMOpLogCollection contains log of acquired locks (hence run ops)
	PBMOpLogCollection = "pbmOpLog"
	// AgentsStatusCollection is an agents registry with its status/health checks
	AgentsStatusCollection = "pbmAgents"

	// MetadataFileSuffix is a suffix for the metadata file on a storage
	MetadataFileSuffix = ".pbm.json"
)
View Source
const (
	PITRcheckRange       = time.Second * 15
	AgentsStatCheckRange = time.Second * 5
)
View Source
const (
	// PITRdefaultSpan oplog slicing time span
	PITRdefaultSpan = time.Minute * 10
	// PITRfsPrefix is a prefix (folder) for PITR chunks on the storage
	PITRfsPrefix = "pbmPitr"
)
View Source
const (
	StorInitFile    = ".pbm.init"
	PhysRestoresDir = ".pbm.restore"
)
View Source
const StaleFrameSec uint32 = 30

Variables

View Source
var (
	WaitActionStart = time.Second * 15
	WaitBackupStart = WaitActionStart + PITRcheckRange*12/10
)
View Source
var ErrNotFound = errors.New("not found")

ErrNotFound - object not found

View Source
var ErrStorageUndefined = errors.New("storage undefined")

ErrStorageUndefined is an error for undefined storage

Functions

func CopyColl added in v1.5.0

func CopyColl(ctx context.Context, from, to *mongo.Collection, filter interface{}) (n int, err error)

CopyColl copy documents matching the given filter and return number of copied documents

func DropTMPcoll added in v1.5.0

func DropTMPcoll(ctx context.Context, cn *mongo.Client) error

func LastWrite added in v1.5.0

func LastWrite(cn *mongo.Client, majority bool) (primitive.Timestamp, error)

func ValidateConfigKey added in v1.1.0

func ValidateConfigKey(k string) bool

ValidateConfigKey checks if a config key valid

Types

type AgentStat added in v1.4.0

type AgentStat struct {
	Node          string              `bson:"n"`
	RS            string              `bson:"rs"`
	State         NodeState           `bson:"s"`
	StateStr      string              `bson:"str"`
	Hidden        bool                `bson:"hdn"`
	Passive       bool                `bson:"psv"`
	Ver           string              `bson:"v"`
	PBMStatus     SubsysStatus        `bson:"pbms"`
	NodeStatus    SubsysStatus        `bson:"nodes"`
	StorageStatus SubsysStatus        `bson:"stors"`
	Heartbeat     primitive.Timestamp `bson:"hb"`
	Err           string              `bson:"e"`
}

func (*AgentStat) OK added in v1.4.0

func (s *AgentStat) OK() (ok bool, errs []string)

type AuthInfo added in v1.1.3

type AuthInfo struct {
	Users     []AuthUser      `bson:"authenticatedUsers" json:"authenticatedUsers"`
	UserRoles []AuthUserRoles `bson:"authenticatedUserRoles" json:"authenticatedUserRoles"`
}

type AuthUser added in v1.1.3

type AuthUser struct {
	User string `bson:"user" json:"user"`
	DB   string `bson:"db" json:"db"`
}

type AuthUserRoles added in v1.1.3

type AuthUserRoles struct {
	Role string `bson:"role" json:"role"`
	DB   string `bson:"db" json:"db"`
}

type BackupCmd

type BackupCmd struct {
	Type             BackupType      `bson:"type"`
	Name             string          `bson:"name"`
	Compression      CompressionType `bson:"compression"`
	CompressionLevel *int            `bson:"level,omitempty"`
}

func (BackupCmd) String added in v1.3.2

func (b BackupCmd) String() string

type BackupConf added in v1.5.0

type BackupConf struct {
	Priority         map[string]float64 `bson:"priority,omitempty" json:"priority,omitempty" yaml:"priority,omitempty"`
	Compression      CompressionType    `bson:"compression,omitempty" json:"compression,omitempty" yaml:"compression,omitempty"`
	CompressionLevel *int               `bson:"compressionLevel,omitempty" json:"compressionLevel,omitempty" yaml:"compressionLevel,omitempty"`
}

type BackupMeta

type BackupMeta struct {
	Type             BackupType           `bson:"type" json:"type"`
	OPID             string               `bson:"opid" json:"opid"`
	Name             string               `bson:"name" json:"name"`
	Replsets         []BackupReplset      `bson:"replsets" json:"replsets"`
	Compression      CompressionType      `bson:"compression" json:"compression"`
	Store            StorageConf          `bson:"store" json:"store"`
	MongoVersion     string               `bson:"mongodb_version" json:"mongodb_version,omitempty"`
	StartTS          int64                `bson:"start_ts" json:"start_ts"`
	LastTransitionTS int64                `bson:"last_transition_ts" json:"last_transition_ts"`
	FirstWriteTS     primitive.Timestamp  `bson:"first_write_ts" json:"first_write_ts"`
	LastWriteTS      primitive.Timestamp  `bson:"last_write_ts" json:"last_write_ts"`
	Hb               primitive.Timestamp  `bson:"hb" json:"hb"`
	Status           Status               `bson:"status" json:"status"`
	Conditions       []Condition          `bson:"conditions" json:"conditions"`
	Nomination       []BackupRsNomination `bson:"n" json:"n"`
	Err              string               `bson:"error,omitempty" json:"error,omitempty"`
	PBMVersion       string               `bson:"pbm_version,omitempty" json:"pbm_version,omitempty"`
	BalancerStatus   BalancerMode         `bson:"balancer" json:"balancer"`
	// contains filtered or unexported fields
}

BackupMeta is a backup's metadata

func (*BackupMeta) Error

func (b *BackupMeta) Error() error

func (*BackupMeta) RS added in v1.3.0

func (b *BackupMeta) RS(name string) *BackupReplset

RS returns the metada of the replset with given name. It returns nil if no replsent found.

func (*BackupMeta) SetRuntimeError added in v1.8.0

func (b *BackupMeta) SetRuntimeError(err error)

type BackupReplset

type BackupReplset struct {
	Name             string              `bson:"name" json:"name"`
	Files            []File              `bson:"files,omitempty" json:"files,omitempty" `
	DumpName         string              `bson:"dump_name,omitempty" json:"backup_name,omitempty" `
	OplogName        string              `bson:"oplog_name,omitempty" json:"oplog_name,omitempty"`
	StartTS          int64               `bson:"start_ts" json:"start_ts"`
	Status           Status              `bson:"status" json:"status"`
	LastTransitionTS int64               `bson:"last_transition_ts" json:"last_transition_ts"`
	FirstWriteTS     primitive.Timestamp `bson:"first_write_ts" json:"first_write_ts"`
	LastWriteTS      primitive.Timestamp `bson:"last_write_ts" json:"last_write_ts"`
	Error            string              `bson:"error,omitempty" json:"error,omitempty"`
	Conditions       []Condition         `bson:"conditions" json:"conditions"`
}

type BackupRsNomination added in v1.5.0

type BackupRsNomination struct {
	RS    string   `bson:"rs" json:"rs"`
	Nodes []string `bson:"n" json:"n"`
	Ack   string   `bson:"ack" json:"ack"`
}

BackupRsNomination is used to choose (nominate and elect) nodes for the backup within a replica set

type BackupType added in v1.7.0

type BackupType string
const (
	PhysicalBackup BackupType = "physical"
	LogicalBackup  BackupType = "logical"
)

type BalancerMode added in v1.5.0

type BalancerMode string
const (
	BalancerModeOn  BalancerMode = "full"
	BalancerModeOff BalancerMode = "off"
)

func (BalancerMode) String added in v1.6.1

func (m BalancerMode) String() string

type BalancerStatus added in v1.5.0

type BalancerStatus struct {
	Mode              BalancerMode `bson:"mode" json:"mode"`
	InBalancerRound   bool         `bson:"inBalancerRound" json:"inBalancerRound"`
	NumBalancerRounds int64        `bson:"numBalancerRounds" json:"numBalancerRounds"`
	Ok                int          `bson:"ok" json:"ok"`
}

func (*BalancerStatus) IsOn added in v1.5.0

func (b *BalancerStatus) IsOn() bool

type ClusterTime

type ClusterTime struct {
	ClusterTime primitive.Timestamp `bson:"clusterTime"`
	Signature   struct {
		Hash  primitive.Binary `bson:"hash"`
		KeyID int64            `bson:"keyId"`
	} `bson:"signature"`
}

type Cmd

type Cmd struct {
	Cmd        Command         `bson:"cmd"`
	Backup     BackupCmd       `bson:"backup,omitempty"`
	Restore    RestoreCmd      `bson:"restore,omitempty"`
	Replay     ReplayCmd       `bson:"replay,omitempty"`
	PITRestore PITRestoreCmd   `bson:"pitrestore,omitempty"`
	Delete     DeleteBackupCmd `bson:"delete,omitempty"`
	DeletePITR DeletePITRCmd   `bson:"deletePitr,omitempty"`
	TS         int64           `bson:"ts"`
	OPID       OPID            `bson:"-"`
}

func (Cmd) String added in v1.3.2

func (c Cmd) String() string

type Command

type Command string

Command represents actions that could be done on behalf of the client by the agents

const (
	CmdUndefined    Command = ""
	CmdBackup       Command = "backup"
	CmdRestore      Command = "restore"
	CmdReplay       Command = "replay"
	CmdCancelBackup Command = "cancelBackup"
	CmdResync       Command = "resync"
	CmdPITR         Command = "pitr"
	CmdPITRestore   Command = "pitrestore"
	CmdDeleteBackup Command = "delete"
	CmdDeletePITR   Command = "deletePitr"
)

func (Command) String added in v1.4.0

func (c Command) String() string

type CompressionType

type CompressionType string
const (
	CompressionTypeNone      CompressionType = "none"
	CompressionTypeGZIP      CompressionType = "gzip"
	CompressionTypePGZIP     CompressionType = "pgzip"
	CompressionTypeSNAPPY    CompressionType = "snappy"
	CompressionTypeLZ4       CompressionType = "lz4"
	CompressionTypeS2        CompressionType = "s2"
	CompressionTypeZstandard CompressionType = "zstd"
)

func FileCompression added in v1.3.0

func FileCompression(ext string) CompressionType

FileCompression return compression alg based on given file extension

func (CompressionType) Suffix added in v1.7.0

func (c CompressionType) Suffix() string

type Condition added in v1.1.0

type Condition struct {
	Timestamp int64  `bson:"timestamp" json:"timestamp"`
	Status    Status `bson:"status" json:"status"`
	Error     string `bson:"error,omitempty" json:"error,omitempty"`
}

type Config added in v1.1.0

type Config struct {
	PITR    PITRConf            `bson:"pitr" json:"pitr" yaml:"pitr"`
	Storage StorageConf         `bson:"storage" json:"storage" yaml:"storage"`
	Restore RestoreConf         `bson:"restore" json:"restore,omitempty" yaml:"restore,omitempty"`
	Backup  BackupConf          `bson:"backup" json:"backup,omitempty" yaml:"backup,omitempty"`
	Epoch   primitive.Timestamp `bson:"epoch" json:"-" yaml:"-"`
}

Config is a pbm config

func (Config) String added in v1.6.0

func (c Config) String() string

type ConfigServerState

type ConfigServerState struct {
	OpTime *OpTime `bson:"opTime"`
}

type ConnectionStatus added in v1.1.3

type ConnectionStatus struct {
	AuthInfo AuthInfo `bson:"authInfo" json:"authInfo"`
}

type DeleteBackupCmd added in v1.3.2

type DeleteBackupCmd struct {
	Backup    string `bson:"backup"`
	OlderThan int64  `bson:"olderthan"`
}

func (DeleteBackupCmd) String added in v1.3.2

func (d DeleteBackupCmd) String() string

type DeletePITRCmd added in v1.6.0

type DeletePITRCmd struct {
	OlderThan int64 `bson:"olderthan"`
}

type Epoch added in v1.4.0

type Epoch primitive.Timestamp

func (Epoch) TS added in v1.4.0

func (e Epoch) TS() primitive.Timestamp

type ErrConcurrentOp added in v1.1.0

type ErrConcurrentOp struct {
	Lock LockHeader
}

ErrConcurrentOp means lock was already acquired by another node

func (ErrConcurrentOp) Error added in v1.1.0

func (e ErrConcurrentOp) Error() string

type ErrDuplicateOp added in v1.4.0

type ErrDuplicateOp struct {
	Lock LockHeader
}

ErrDuplicateOp means the operation with the same ID alredy had been running

func (ErrDuplicateOp) Error added in v1.4.0

func (e ErrDuplicateOp) Error() string

type ErrWasStaleLock added in v1.3.0

type ErrWasStaleLock struct {
	Lock LockHeader
}

ErrWasStaleLock - the lock was already got but the operation seems to be staled (no hb from the node)

func (ErrWasStaleLock) Error added in v1.3.0

func (e ErrWasStaleLock) Error() string

type ErrorCursor

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

func (ErrorCursor) Error

func (c ErrorCursor) Error() string

type File added in v1.7.0

type File struct {
	Name    string      `bson:"filename" json:"filename"`
	Size    int64       `bson:"fileSize" json:"fileSize"`
	StgSize int64       `bson:"stgSize" json:"stgSize"`
	Fmode   os.FileMode `bson:"fmode" json:"fmode"`
}

type Lock

type Lock struct {
	LockData
	// contains filtered or unexported fields
}

Lock is a lock for the PBM operation (e.g. backup, restore)

func (*Lock) Acquire added in v1.1.0

func (l *Lock) Acquire() (bool, error)

Acquire tries to acquire the lock. It returns true in case of success and false if a lock already acquired by another process or some error happened. In case of concurrent lock exists is stale it will be deleted and ErrWasStaleLock gonna be returned. A client shell mark respective operation as stale and retry if it needs to

func (*Lock) Release added in v1.1.0

func (l *Lock) Release() error

Release the lock

func (*Lock) Rewrite added in v1.6.1

func (l *Lock) Rewrite(old *LockHeader) (bool, error)

Rewrite tries to acquire the lock instead the `old` one. It returns true in case of success and false if a lock already acquired by another process or some error happened. In case of concurrent lock exists is stale it will be deleted and ErrWasStaleLock gonna be returned. A client shell mark respective operation as stale and retry if it needs to

type LockData added in v1.1.0

type LockData struct {
	LockHeader `bson:",inline"`
	Heartbeat  primitive.Timestamp `bson:"hb"` // separated in order the lock can be searchable by the header
}

type LockHeader added in v1.1.0

type LockHeader struct {
	Type    Command `bson:"type,omitempty" json:"type,omitempty"`
	Replset string  `bson:"replset,omitempty" json:"replset,omitempty"`
	Node    string  `bson:"node,omitempty" json:"node,omitempty"`
	OPID    string  `bson:"opid,omitempty" json:"opid,omitempty"`
	// should be a pointer so mongo find with empty epoch would work
	// otherwise it always set it at least to "epoch":{"$timestamp":{"t":0,"i":0}}
	Epoch *primitive.Timestamp `bson:"epoch,omitempty" json:"epoch,omitempty"`
}

LockHeader describes the lock. This data will be serialased into the mongo document.

type MongoLastWrite added in v1.3.0

type MongoLastWrite struct {
	OpTime            OpTime    `bson:"opTime"`
	LastWriteDate     time.Time `bson:"lastWriteDate"`
	MajorityOpTime    OpTime    `bson:"majorityOpTime"`
	MajorityWriteDate time.Time `bson:"majorityWriteDate"`
}

MongoLastWrite represents the last write to the MongoDB server

type MongoVersion

type MongoVersion struct {
	VersionString string `bson:"version"`
	Version       []int  `bson:"versionArray"`
}

type MongodOpts added in v1.7.0

type MongodOpts struct {
	Net struct {
		BindIp string `bson:"bindIp" json:"bindIp"`
		Port   int    `bson:"port" json:"port"`
	} `bson:"net" json:"net"`
	Storage struct {
		DBpath string `bson:"dbPath" json:"dbPath"`
	} `bson:"storage" json:"storage"`
}

type Node

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

func NewNode

func NewNode(ctx context.Context, curi string, dumpConns int) (*Node, error)

func (*Node) ConnURI

func (n *Node) ConnURI() string

func (*Node) Connect added in v1.1.3

func (n *Node) Connect() error

func (*Node) CopyUsersNRolles added in v1.5.0

func (n *Node) CopyUsersNRolles() (lastWrite primitive.Timestamp, err error)

func (*Node) CurrentUser added in v1.1.3

func (n *Node) CurrentUser() (*AuthInfo, error)

func (*Node) DropTMPcoll added in v1.3.4

func (n *Node) DropTMPcoll() error

func (*Node) DumpConns added in v1.4.0

func (n *Node) DumpConns() int

func (*Node) GetInfo added in v1.3.0

func (n *Node) GetInfo() (*NodeInfo, error)

func (*Node) GetMongoVersion

func (n *Node) GetMongoVersion() (*MongoVersion, error)

func (*Node) GetOpts added in v1.7.0

func (n *Node) GetOpts() (*MongodOpts, error)

func (*Node) GetRSconf added in v1.7.0

func (n *Node) GetRSconf() (*RSConfig, error)

func (*Node) GetReplsetStatus

func (n *Node) GetReplsetStatus() (*ReplsetStatus, error)

func (*Node) ID added in v1.3.0

func (n *Node) ID() string

ID returns node ID

func (*Node) IsSharded

func (n *Node) IsSharded() (bool, error)

IsSharded return true if node is part of the sharded cluster (in shard or configsrv replset).

func (*Node) Name

func (n *Node) Name() string

Name returns node name

func (*Node) OplogStartTime added in v1.7.0

func (n *Node) OplogStartTime() (primitive.Timestamp, error)

OplogStartTime returns either the oldest active transaction timestamp or the current oplog time if there are no active transactions. taken from https://github.com/mongodb/mongo-tools/blob/1b496c4a8ff7415abc07b9621166d8e1fac00c91/mongodump/oplog_dump.go#L68

func (*Node) RS added in v1.3.0

func (n *Node) RS() string

RS return replicaset name node belongs to

func (*Node) ReplicationLag

func (n *Node) ReplicationLag() (int, error)

ReplicationLag returns node replication lag in seconds

func (*Node) Session

func (n *Node) Session() *mongo.Client

func (*Node) Shutdown added in v1.7.0

func (n *Node) Shutdown() error

func (*Node) SizeDBs added in v1.3.2

func (n *Node) SizeDBs() (int, error)

SizeDBs returns the total size in bytes of all databases' files on disk on replicaset

func (*Node) Status

func (n *Node) Status() (*NodeStatus, error)

func (*Node) WaitForWrite added in v1.5.0

func (n *Node) WaitForWrite(ts primitive.Timestamp) (err error)

type NodeHealth

type NodeHealth int
const (
	NodeHealthDown NodeHealth = iota
	NodeHealthUp
)

type NodeInfo added in v1.3.0

type NodeInfo struct {
	Hosts                        []string             `bson:"hosts,omitempty"`
	Msg                          string               `bson:"msg"`
	MaxBsonObjectSise            int64                `bson:"maxBsonObjectSize"`
	MaxMessageSizeBytes          int64                `bson:"maxMessageSizeBytes"`
	MaxWriteBatchSize            int64                `bson:"maxWriteBatchSize"`
	LocalTime                    time.Time            `bson:"localTime"`
	LogicalSessionTimeoutMinutes int64                `bson:"logicalSessionTimeoutMinutes"`
	MaxWireVersion               int64                `bson:"maxWireVersion"`
	MinWireVersion               int64                `bson:"minWireVersion"`
	OK                           int                  `bson:"ok"`
	SetName                      string               `bson:"setName,omitempty"`
	Primary                      string               `bson:"primary,omitempty"`
	SetVersion                   int32                `bson:"setVersion,omitempty"`
	IsPrimary                    bool                 `bson:"ismaster"`
	Secondary                    bool                 `bson:"secondary,omitempty"`
	Hidden                       bool                 `bson:"hidden,omitempty"`
	Passive                      bool                 `bson:"passive,omitempty"`
	ConfigSvr                    int                  `bson:"configsvr,omitempty"`
	Me                           string               `bson:"me"`
	LastWrite                    MongoLastWrite       `bson:"lastWrite"`
	ClusterTime                  *ClusterTime         `bson:"$clusterTime,omitempty"`
	ConfigServerState            *ConfigServerState   `bson:"$configServerState,omitempty"`
	OperationTime                *primitive.Timestamp `bson:"operationTime,omitempty"`
}

NodeInfo represents the mongo's node info

func (*NodeInfo) IsClusterLeader added in v1.5.0

func (i *NodeInfo) IsClusterLeader() bool

IsClusterLeader - cluster leader is a primary node on configsrv or just primary node in non-sharded replicaset

func (*NodeInfo) IsConfigSrv added in v1.7.0

func (i *NodeInfo) IsConfigSrv() bool

IsConfigSrv returns true if node belongs to the CSRS in a sharded cluster

func (*NodeInfo) IsLeader added in v1.3.0

func (i *NodeInfo) IsLeader() bool

IsLeader returns true if node can act as backup leader (it's configsrv or non shareded rs)

func (*NodeInfo) IsSharded added in v1.3.0

func (i *NodeInfo) IsSharded() bool

IsSharded returns true is replset is part sharded cluster

func (*NodeInfo) IsStandalone added in v1.3.0

func (i *NodeInfo) IsStandalone() bool

IsStandalone returns true if node is not a part of replica set

func (*NodeInfo) ReplsetRole added in v1.3.0

func (i *NodeInfo) ReplsetRole() ReplsetRole

ReplsetRole returns replset role in sharded clister

type NodeState

type NodeState int
const (
	NodeStateStartup NodeState = iota
	NodeStatePrimary
	NodeStateSecondary
	NodeStateRecovering
	NodeStateStartup2
	NodeStateUnknown
	NodeStateArbiter
	NodeStateDown
	NodeStateRollback
	NodeStateRemoved
)

type NodeStatus

type NodeStatus struct {
	ID                int                 `bson:"_id" json:"_id"`
	Name              string              `bson:"name" json:"name"`
	Health            NodeHealth          `bson:"health" json:"health"`
	State             NodeState           `bson:"state" json:"state"`
	StateStr          string              `bson:"stateStr" json:"stateStr"`
	Uptime            int64               `bson:"uptime" json:"uptime"`
	Optime            *OpTime             `bson:"optime" json:"optime"`
	OptimeDate        time.Time           `bson:"optimeDate" json:"optimeDate"`
	ConfigVersion     int                 `bson:"configVersion" json:"configVersion"`
	ElectionTime      primitive.Timestamp `bson:"electionTime,omitempty" json:"electionTime,omitempty"`
	ElectionDate      time.Time           `bson:"electionDate,omitempty" json:"electionDate,omitempty"`
	InfoMessage       string              `bson:"infoMessage,omitempty" json:"infoMessage,omitempty"`
	OptimeDurable     *OpTime             `bson:"optimeDurable,omitempty" json:"optimeDurable,omitempty"`
	OptimeDurableDate time.Time           `bson:"optimeDurableDate,omitempty" json:"optimeDurableDate,omitempty"`
	LastHeartbeat     time.Time           `bson:"lastHeartbeat,omitempty" json:"lastHeartbeat,omitempty"`
	LastHeartbeatRecv time.Time           `bson:"lastHeartbeatRecv,omitempty" json:"lastHeartbeatRecv,omitempty"`
	PingMs            int64               `bson:"pingMs,omitempty" json:"pingMs,omitempty"`
	Self              bool                `bson:"self,omitempty" json:"self,omitempty"`
	SyncingTo         string              `bson:"syncingTo,omitempty" json:"syncingTo,omitempty"`
}

type NodesPriority added in v1.5.0

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

NodesPriority groups nodes by priority according to provided scores. Basically nodes are grouped and sorted by descending order by score

func NewNodesPriority added in v1.5.0

func NewNodesPriority() *NodesPriority

func (*NodesPriority) Add added in v1.5.0

func (n *NodesPriority) Add(rs, node string, sc float64)

Add node with its score

func (*NodesPriority) RS added in v1.5.0

func (n *NodesPriority) RS(rs string) [][]string

RS returns nodes `group and sort desc by score` for given replset

type OPID added in v1.4.0

type OPID primitive.ObjectID

func NilOPID added in v1.4.0

func NilOPID() OPID

func OPIDfromStr added in v1.4.0

func OPIDfromStr(s string) (OPID, error)

func (OPID) Obj added in v1.4.0

func (o OPID) Obj() primitive.ObjectID

func (OPID) String added in v1.4.0

func (o OPID) String() string

type OpLog added in v1.4.0

type OpLog struct {
	LockHeader `bson:",inline" json:",inline"`
}

OpLog represents log of started operation. Operation progress can be get from logs by OPID. Basically it is a log of all ever taken locks. With the uniqueness by rs + opid

type OpTime

type OpTime struct {
	TS   primitive.Timestamp `bson:"ts" json:"ts"`
	Term int64               `bson:"t" json:"t"`
}

type Operation

type Operation string
const (
	OperationInsert  Operation = "i"
	OperationNoop    Operation = "n"
	OperationUpdate  Operation = "u"
	OperationDelete  Operation = "d"
	OperationCommand Operation = "c"
)

type OplogChunk added in v1.7.0

type OplogChunk struct {
	RS          string              `bson:"rs"`
	FName       string              `bson:"fname"`
	Compression CompressionType     `bson:"compression"`
	StartTS     primitive.Timestamp `bson:"start_ts"`
	EndTS       primitive.Timestamp `bson:"end_ts"`
	// contains filtered or unexported fields
}

OplogChunk is index metadata for the oplog chunks

func PITRmetaFromFName added in v1.3.0

func PITRmetaFromFName(f string) *OplogChunk

PITRmetaFromFName parses given file name and returns PITRChunk metadata it returns nil if file wasn't parse successfully (e.g. wrong format) current fromat is 20200715155939-0.20200715160029-1.oplog.snappy

!!! should be agreed with pbm/pitr.chunkPath()

type PBM

type PBM struct {
	Conn *mongo.Client
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, uri, appName string) (*PBM, error)

New creates a new PBM object. In the sharded cluster both agents and ctls should have a connection to ConfigServer replica set in order to communicate via PBM collections. If agent's or ctl's local node is not a member of CongigServer, after discovering current topology connection will be established to ConfigServer.

func (*PBM) AddRSMeta added in v1.1.0

func (p *PBM) AddRSMeta(bcpName string, rs BackupReplset) error

func (*PBM) AddRestoreRSMeta added in v1.1.2

func (p *PBM) AddRestoreRSMeta(name string, rs RestoreReplset) error

func (*PBM) AgentStatusGC added in v1.4.0

func (p *PBM) AgentStatusGC() error

AgentStatusGC cleans up stale agent statuses

func (*PBM) AgentsStatus added in v1.5.0

func (p *PBM) AgentsStatus() (agents []AgentStat, err error)

AgentsStatus returns list of registered agents

func (*PBM) AllOplogRSNames added in v1.8.0

func (p *PBM) AllOplogRSNames(ctx context.Context, from, to primitive.Timestamp) ([]string, error)

func (*PBM) BackupGetNext added in v1.3.0

func (p *PBM) BackupGetNext(backup *BackupMeta) (*BackupMeta, error)

func (*PBM) BackupHB added in v1.1.2

func (p *PBM) BackupHB(bcpName string) error

func (*PBM) BackupsDoneList added in v1.6.0

func (p *PBM) BackupsDoneList(after *primitive.Timestamp, limit int64, order int) ([]BackupMeta, error)

func (*PBM) BackupsList

func (p *PBM) BackupsList(limit int64) ([]BackupMeta, error)

func (*PBM) BcpNodesPriority added in v1.5.0

func (p *PBM) BcpNodesPriority() (*NodesPriority, error)

BcpNodesPriority returns list nodes grouped by backup preferences in descended order. First are nodes with the highest priority.

func (*PBM) ChangeBackupState added in v1.1.0

func (p *PBM) ChangeBackupState(bcpName string, s Status, msg string) error

func (*PBM) ChangeBackupStateOPID added in v1.4.0

func (p *PBM) ChangeBackupStateOPID(opid string, s Status, msg string) error

func (*PBM) ChangeRSState added in v1.1.0

func (p *PBM) ChangeRSState(bcpName string, rsName string, s Status, msg string) error

func (*PBM) ChangeRestoreRSState added in v1.1.2

func (p *PBM) ChangeRestoreRSState(name string, rsName string, s Status, msg string) error

func (*PBM) ChangeRestoreState added in v1.1.2

func (p *PBM) ChangeRestoreState(name string, s Status, msg string) error

func (*PBM) ChangeRestoreStateOPID added in v1.4.0

func (p *PBM) ChangeRestoreStateOPID(opid string, s Status, msg string) error

func (*PBM) ClusterMembers added in v1.4.1

func (p *PBM) ClusterMembers() ([]Shard, error)

ClusterMembers returns list of replicasets current cluster consists of (shards + configserver). The list would consist of on rs if cluster is a non-sharded rs.

func (*PBM) ClusterTime added in v1.1.0

func (p *PBM) ClusterTime() (primitive.Timestamp, error)

ClusterTime returns mongo's current cluster time

func (*PBM) Context

func (p *PBM) Context() context.Context

Context returns object context

func (*PBM) DeleteBackup added in v1.2.0

func (p *PBM) DeleteBackup(name string, l *log.Event) error

DeleteBackup deletes backup with the given name from the current storage and pbm database

func (*PBM) DeleteBackupFiles added in v1.2.0

func (p *PBM) DeleteBackupFiles(meta *BackupMeta, stg storage.Storage) (err error)

DeleteBackupFiles removes backup's artifacts from storage

func (*PBM) DeleteConfigVar added in v1.7.0

func (p *PBM) DeleteConfigVar(key string) error

func (*PBM) DeleteOlderThan added in v1.2.0

func (p *PBM) DeleteOlderThan(t time.Time, l *log.Event) error

DeleteOlderThan deletes backups which older than given Time

func (*PBM) DeletePITR added in v1.6.0

func (p *PBM) DeletePITR(until *time.Time, l *log.Event) error

DeletePITR deletes backups which older than given `until` Time. It will round `until` down to the last write of the closest preceding backup in order not to make gaps. So usually it gonna leave some extra chunks. E.g. if `until = 13` and the last write of the closest preceding backup is `10` it will leave `11` and `12` chunks as well since `13` won't be restorable without `11` and `12` (contiguous timeline from the backup). It deletes all chunks if `until` is nil.

func (*PBM) GetAgentStatus added in v1.4.0

func (p *PBM) GetAgentStatus(rs, node string) (s AgentStat, err error)

GetAgentStatus returns agent status by given node and rs it's up to user how to handle ErrNoDocuments

func (*PBM) GetBackupByOPID added in v1.4.0

func (p *PBM) GetBackupByOPID(opid string) (*BackupMeta, error)

func (*PBM) GetBackupMeta

func (p *PBM) GetBackupMeta(name string) (*BackupMeta, error)

func (*PBM) GetBalancerStatus added in v1.5.0

func (p *PBM) GetBalancerStatus() (*BalancerStatus, error)

GetBalancerStatus returns balancer status

func (*PBM) GetConfig added in v1.1.0

func (p *PBM) GetConfig() (Config, error)

func (*PBM) GetConfigVar added in v1.1.0

func (p *PBM) GetConfigVar(key string) (interface{}, error)

GetConfigVar returns value of given config vaiable

func (*PBM) GetConfigYaml added in v1.1.0

func (p *PBM) GetConfigYaml(fieldRedaction bool) ([]byte, error)

func (*PBM) GetEpoch added in v1.4.0

func (p *PBM) GetEpoch() (Epoch, error)

func (*PBM) GetFirstBackup added in v1.3.0

func (p *PBM) GetFirstBackup(after *primitive.Timestamp) (*BackupMeta, error)

func (*PBM) GetLastBackup added in v1.3.0

func (p *PBM) GetLastBackup(before *primitive.Timestamp) (*BackupMeta, error)

GetLastBackup returns last successfully finished backup or nil if there is no such backup yet. If ts isn't nil it will search for the most recent backup that finished before specified timestamp

func (*PBM) GetLastRestore added in v1.3.0

func (p *PBM) GetLastRestore() (*RestoreMeta, error)

GetLastRestore returns last successfully finished restore and nil if there is no such restore yet.

func (*PBM) GetLockData added in v1.1.0

func (p *PBM) GetLockData(lh *LockHeader) (LockData, error)

func (*PBM) GetLocks added in v1.1.0

func (p *PBM) GetLocks(lh *LockHeader) ([]LockData, error)

func (*PBM) GetNodeInfo added in v1.3.0

func (p *PBM) GetNodeInfo() (*NodeInfo, error)

GetNodeInfo returns mongo node info

func (*PBM) GetOpLockData added in v1.4.0

func (p *PBM) GetOpLockData(lh *LockHeader) (LockData, error)

func (*PBM) GetOpLocks added in v1.4.0

func (p *PBM) GetOpLocks(lh *LockHeader) ([]LockData, error)

func (*PBM) GetRSNominees added in v1.5.0

func (p *PBM) GetRSNominees(bcpName, rsName string) (*BackupRsNomination, error)

func (*PBM) GetReplsetStatus added in v1.5.0

func (p *PBM) GetReplsetStatus() (*ReplsetStatus, error)

GetReplsetStatus returns `replSetGetStatus` for the replset or config server in case of sharded cluster

func (*PBM) GetRestoreMeta added in v1.1.2

func (p *PBM) GetRestoreMeta(name string) (*RestoreMeta, error)

func (*PBM) GetRestoreMetaByOPID added in v1.4.0

func (p *PBM) GetRestoreMetaByOPID(opid string) (*RestoreMeta, error)

func (*PBM) GetShards

func (p *PBM) GetShards() ([]Shard, error)

GetShards gets list of shards

func (*PBM) GetStorage

func (p *PBM) GetStorage(l *log.Event) (storage.Storage, error)

GetStorage reads current storage config and creates and returns respective storage.Storage object

func (*PBM) InitLogger added in v1.4.0

func (p *PBM) InitLogger(rs, node string)

func (*PBM) IsPITR added in v1.3.0

func (p *PBM) IsPITR() (bool, error)

IsPITR checks if PITR is enabled

func (*PBM) ListenCmd

func (p *PBM) ListenCmd(cl <-chan struct{}) (<-chan Cmd, <-chan error)

func (*PBM) LogGet added in v1.3.0

func (p *PBM) LogGet(r *log.LogRequest, limit int64) (*log.Entries, error)

func (*PBM) LogGetExactSeverity added in v1.4.0

func (p *PBM) LogGetExactSeverity(r *log.LogRequest, limit int64) (*log.Entries, error)

func (*PBM) Logger added in v1.4.0

func (p *PBM) Logger() *log.Logger

func (*PBM) MarkBcpStale added in v1.3.0

func (p *PBM) MarkBcpStale(opid string) error

func (*PBM) MarkRestoreStale added in v1.3.0

func (p *PBM) MarkRestoreStale(opid string) error

func (*PBM) NewLock added in v1.1.0

func (p *PBM) NewLock(h LockHeader) *Lock

NewLock creates a new Lock object from geven header. Returned lock has no state. So Acquire() and Release() methods should be called.

func (*PBM) NewLockCol added in v1.3.2

func (p *PBM) NewLockCol(h LockHeader, collection string) *Lock

NewLockCol creates a new Lock object from geven header in given collection. Returned lock has no state. So Acquire() and Release() methods should be called.

func (*PBM) PITRAddChunk added in v1.3.0

func (p *PBM) PITRAddChunk(c OplogChunk) error

PITRAddChunk stores PITR chunk metadata

func (*PBM) PITRFirstChunkMeta added in v1.3.0

func (p *PBM) PITRFirstChunkMeta(rs string) (*OplogChunk, error)

PITRFirstChunkMeta returns the oldest PITR chunk for the given Replset

func (*PBM) PITRGetChunkStarts added in v1.3.0

func (p *PBM) PITRGetChunkStarts(rs string, ts primitive.Timestamp) (*OplogChunk, error)

PITRGetChunkStarts returns a pitr slice chunk that belongs to the given replica set and start from the given timestamp

func (*PBM) PITRGetChunksSlice added in v1.3.0

func (p *PBM) PITRGetChunksSlice(rs string, from, to primitive.Timestamp) ([]OplogChunk, error)

PITRGetChunksSlice returns slice of PITR oplog chunks which Start TS lies in a given time frame. Returns all chunks if `to` is 0.

func (*PBM) PITRGetChunksSliceUntil added in v1.6.0

func (p *PBM) PITRGetChunksSliceUntil(rs string, t primitive.Timestamp) ([]OplogChunk, error)

PITRGetChunksSliceUntil returns slice of PITR oplog chunks that starts up until timestamp (exclusively)

func (*PBM) PITRGetValidTimelines added in v1.3.0

func (p *PBM) PITRGetValidTimelines(rs string, until primitive.Timestamp, flist map[string]int64) (tlines []Timeline, err error)

PITRGetValidTimelines returns time ranges valid for PITR restore for the given replicaset. We don't check for any "restore intrusions" or other integrity issues since it's guaranteed be the slicer that any saved chunk already belongs to some valid timeline, the slice wouldn't be done otherwise. `flist` is a cache of chunk sizes.

func (*PBM) PITRLastChunkMeta added in v1.3.0

func (p *PBM) PITRLastChunkMeta(rs string) (*OplogChunk, error)

PITRLastChunkMeta returns the most recent PITR chunk for the given Replset

func (*PBM) PITRTimelines added in v1.6.0

func (p *PBM) PITRTimelines() (tlines []Timeline, err error)

PITRTimelines returns cluster-wide time ranges valid for PITR restore

func (*PBM) PITRrun added in v1.5.0

func (p *PBM) PITRrun() (bool, error)

PITRrun checks if PITR slicing is running. It looks for PITR locks and returns true if there is at least one not stale.

func (*PBM) RSSetPhyFiles added in v1.7.0

func (p *PBM) RSSetPhyFiles(bcpName string, rsName string, f []File) error

func (*PBM) ResetEpoch added in v1.4.0

func (p *PBM) ResetEpoch() (Epoch, error)

func (*PBM) RestoreHB added in v1.1.2

func (p *PBM) RestoreHB(name string) error

func (*PBM) RestoreSetRSTxn added in v1.7.0

func (p *PBM) RestoreSetRSTxn(name string, rsName string, txn RestoreTxn) error

func (*PBM) RestoresList added in v1.1.2

func (p *PBM) RestoresList(limit int64) ([]RestoreMeta, error)

func (*PBM) ResyncStorage added in v1.3.0

func (p *PBM) ResyncStorage(l *log.Event) error

ResyncStorage updates PBM metadata (snapshots and pitr) according to the data in the storage

func (*PBM) RmAgentStatus added in v1.4.0

func (p *PBM) RmAgentStatus(stat AgentStat) error

func (*PBM) SendCmd

func (p *PBM) SendCmd(cmd Cmd) error

func (*PBM) SetAgentStatus added in v1.4.0

func (p *PBM) SetAgentStatus(stat AgentStat) error

func (*PBM) SetBackupMeta added in v1.1.0

func (p *PBM) SetBackupMeta(m *BackupMeta) error

func (*PBM) SetBalancerStatus added in v1.5.0

func (p *PBM) SetBalancerStatus(m BalancerMode) error

SetBalancerStatus sets balancer status

func (*PBM) SetConfig added in v1.1.0

func (p *PBM) SetConfig(cfg Config) error

func (*PBM) SetConfigByte added in v1.1.0

func (p *PBM) SetConfigByte(buf []byte) error

func (*PBM) SetConfigVar added in v1.1.0

func (p *PBM) SetConfigVar(key, val string) error

func (*PBM) SetCurrentOp added in v1.7.0

func (p *PBM) SetCurrentOp(name string, rsName string, ts primitive.Timestamp) error

func (*PBM) SetFirstWrite added in v1.6.0

func (p *PBM) SetFirstWrite(bcpName string, first primitive.Timestamp) error

func (*PBM) SetLastWrite added in v1.1.0

func (p *PBM) SetLastWrite(bcpName string, last primitive.Timestamp) error

func (*PBM) SetOplogTimestamps added in v1.7.0

func (p *PBM) SetOplogTimestamps(name string, start, end int64) error

func (*PBM) SetRSLastWrite added in v1.1.0

func (p *PBM) SetRSLastWrite(bcpName string, rsName string, ts primitive.Timestamp) error

func (*PBM) SetRSNomination added in v1.5.0

func (p *PBM) SetRSNomination(bcpName, rs string) error

func (*PBM) SetRSNomineeACK added in v1.5.0

func (p *PBM) SetRSNomineeACK(bcpName, rsName, node string) error

func (*PBM) SetRSNominees added in v1.5.0

func (p *PBM) SetRSNominees(bcpName, rsName string, nodes []string) error

func (*PBM) SetRestoreBackup added in v1.3.0

func (p *PBM) SetRestoreBackup(name, backupName string) error

func (*PBM) SetRestoreMeta added in v1.1.2

func (p *PBM) SetRestoreMeta(m *RestoreMeta) error

type PITRConf added in v1.3.0

type PITRConf struct {
	Enabled          bool            `bson:"enabled" json:"enabled" yaml:"enabled"`
	OplogSpanMin     float64         `bson:"oplogSpanMin" json:"oplogSpanMin" yaml:"oplogSpanMin"`
	OplogOnly        bool            `bson:"oplogOnly,omitempty" json:"oplogOnly,omitempty" yaml:"oplogOnly,omitempty"`
	Compression      CompressionType `bson:"compression,omitempty" json:"compression,omitempty" yaml:"compression,omitempty"`
	CompressionLevel *int            `bson:"compressionLevel,omitempty" json:"compressionLevel,omitempty" yaml:"compressionLevel,omitempty"`
}

PITRConf is a Point-In-Time Recovery options

func (*PITRConf) Cast added in v1.7.0

func (c *PITRConf) Cast() error

type PITRestoreCmd added in v1.3.0

type PITRestoreCmd struct {
	Name  string            `bson:"name"`
	TS    int64             `bson:"ts"`
	I     int64             `bson:"i"`
	Bcp   string            `bson:"bcp"`
	RSMap map[string]string `bson:"rsMap,omitempty"`
}

func (PITRestoreCmd) String added in v1.3.2

func (p PITRestoreCmd) String() string

type RSConfig added in v1.7.0

type RSConfig struct {
	ID                      string     `bson:"_id" json:"_id"`
	CSRS                    bool       `bson:"configsvr,omitempty" json:"configsvr"`
	Protocol                int64      `bson:"protocolVersion,omitempty" json:"protocolVersion"`
	Version                 int        `bson:"version" json:"version"`
	Members                 []RSMember `bson:"members" json:"members"`
	WConcernMajorityJournal bool       `bson:"writeConcernMajorityJournalDefault,omitempty" json:"writeConcernMajorityJournalDefault"`
	Settings                struct {
		ChainingAllowed         bool `bson:"chainingAllowed,omitempty" json:"chainingAllowed"`
		HeartbeatIntervalMillis int  `bson:"heartbeatIntervalMillis,omitempty" json:"heartbeatIntervalMillis"`
		HeartbeatTimeoutSecs    int  `bson:"heartbeatTimeoutSecs,omitempty" json:"heartbeatTimeoutSecs"`
		ElectionTimeoutMillis   int  `bson:"electionTimeoutMillis,omitempty" json:"electionTimeoutMillis"`
		CatchUpTimeoutMillis    int  `bson:"catchUpTimeoutMillis,omitempty" json:"catchUpTimeoutMillis"`
	} `bson:"settings,omitempty" json:"settings"`
}

type RSMapFunc added in v1.8.0

type RSMapFunc func(string) string

func MakeRSMapFunc added in v1.8.0

func MakeRSMapFunc(m map[string]string) RSMapFunc

func MakeReverseRSMapFunc added in v1.8.0

func MakeReverseRSMapFunc(m map[string]string) RSMapFunc

type RSMember added in v1.7.0

type RSMember struct {
	ID           int               `bson:"_id" json:"_id"`
	Host         string            `bson:"host" json:"host"`
	ArbiterOnly  bool              `bson:"arbiterOnly,omitempty" json:"arbiterOnly"`
	BuildIndexes bool              `bson:"buildIndexes,omitempty" json:"buildIndexes"`
	Hidden       bool              `bson:"hidden,omitempty" json:"hidden"`
	Priority     float64           `bson:"priority,omitempty" json:"priority"`
	Tags         map[string]string `bson:"tags,omitempty" json:"tags"`
}

type ReplayCmd added in v1.7.0

type ReplayCmd struct {
	Name  string              `bson:"name"`
	Start primitive.Timestamp `bson:"start,omitempty"`
	End   primitive.Timestamp `bson:"end,omitempty"`
	RSMap map[string]string   `bson:"rsMap,omitempty"`
}

func (ReplayCmd) String added in v1.7.0

func (c ReplayCmd) String() string

type ReplsetRole added in v1.7.0

type ReplsetRole string

ReplsetRole is a replicaset role in sharded cluster

const (
	RoleUnknown   ReplsetRole = "unknown"
	RoleShard     ReplsetRole = "shard"
	RoleConfigSrv ReplsetRole = "configsrv"

	// TmpUsersCollection and TmpRoles are tmp collections used to avoid
	// user related issues while resoring on new cluster and preserving UUID
	// See https://jira.percona.com/browse/PBM-425, https://jira.percona.com/browse/PBM-636
	TmpUsersCollection = `pbmRUsers`
	TmpRolesCollection = `pbmRRoles`
)

type ReplsetStatus

type ReplsetStatus struct {
	Set                     string               `bson:"set" json:"set"`
	Date                    time.Time            `bson:"date" json:"date"`
	MyState                 NodeState            `bson:"myState" json:"myState"`
	Members                 []NodeStatus         `bson:"members" json:"members"`
	Term                    int64                `bson:"term,omitempty" json:"term,omitempty"`
	HeartbeatIntervalMillis int64                `bson:"heartbeatIntervalMillis,omitempty" json:"heartbeatIntervalMillis,omitempty"`
	Optimes                 *StatusOpTimes       `bson:"optimes,omitempty" json:"optimes,omitempty"`
	Errmsg                  string               `bson:"errmsg,omitempty" json:"errmsg,omitempty"`
	Ok                      int                  `bson:"ok" json:"ok"`
	ClusterTime             *ClusterTime         `bson:"$clusterTime,omitempty" json:"$clusterTime,omitempty"`
	ConfigServerState       *ConfigServerState   `bson:"$configServerState,omitempty" json:"$configServerState,omitempty"`
	OperationTime           *primitive.Timestamp `bson:"operationTime,omitempty" json:"operationTime,omitempty"`
}

func GetReplsetStatus added in v1.5.0

func GetReplsetStatus(ctx context.Context, cn *mongo.Client) (*ReplsetStatus, error)

GetReplsetStatus returns `replSetGetStatus` for the given connection

type RestoreCmd

type RestoreCmd struct {
	Name       string            `bson:"name"`
	BackupName string            `bson:"backupName"`
	RSMap      map[string]string `bson:"rsMap,omitempty"`
}

func (RestoreCmd) String added in v1.3.2

func (r RestoreCmd) String() string

type RestoreConf added in v1.3.2

type RestoreConf struct {
	BatchSize           int `bson:"batchSize" json:"batchSize,omitempty" yaml:"batchSize,omitempty"` // num of documents to buffer
	NumInsertionWorkers int `bson:"numInsertionWorkers" json:"numInsertionWorkers,omitempty" yaml:"numInsertionWorkers,omitempty"`
}

RestoreConf is config options for the restore

type RestoreMeta added in v1.1.2

type RestoreMeta struct {
	Status           Status              `bson:"status" json:"status"`
	Error            string              `bson:"error,omitempty" json:"error,omitempty"`
	Name             string              `bson:"name" json:"name"`
	OPID             string              `bson:"opid" json:"opid"`
	Backup           string              `bson:"backup" json:"backup"`
	StartPITR        int64               `bson:"start_pitr" json:"start_pitr"`
	PITR             int64               `bson:"pitr" json:"pitr"`
	Replsets         []RestoreReplset    `bson:"replsets" json:"replsets"`
	Hb               primitive.Timestamp `bson:"hb" json:"hb"`
	StartTS          int64               `bson:"start_ts" json:"start_ts"`
	LastTransitionTS int64               `bson:"last_transition_ts" json:"last_transition_ts"`
	Conditions       []Condition         `bson:"conditions" json:"conditions"`
	Type             BackupType          `bson:"type" json:"type"`
	Leader           string              `bson:"l,omitempty" json:"l,omitempty"`
}

type RestoreNode added in v1.7.0

type RestoreNode struct {
	Name             string      `bson:"name" json:"name"`
	Status           Status      `bson:"status" json:"status"`
	LastTransitionTS int64       `bson:"last_transition_ts" json:"last_transition_ts"`
	Error            string      `bson:"error,omitempty" json:"error,omitempty"`
	Conditions       []Condition `bson:"conditions" json:"conditions"`
}

type RestoreReplset added in v1.1.2

type RestoreReplset struct {
	Name             string              `bson:"name" json:"name"`
	StartTS          int64               `bson:"start_ts" json:"start_ts"`
	Status           Status              `bson:"status" json:"status"`
	Txn              RestoreTxn          `bson:"txn" json:"txn"`
	CurrentOp        primitive.Timestamp `bson:"op" json:"op"`
	LastTransitionTS int64               `bson:"last_transition_ts" json:"last_transition_ts"`
	LastWriteTS      primitive.Timestamp `bson:"last_write_ts" json:"last_write_ts"`
	Nodes            []RestoreNode       `bson:"nodes,omitempty" json:"nodes,omitempty"`
	Error            string              `bson:"error,omitempty" json:"error,omitempty"`
	Conditions       []Condition         `bson:"conditions" json:"conditions"`
	Hb               primitive.Timestamp `bson:"hb" json:"hb"`
}

type RestoreTxn added in v1.7.0

type RestoreTxn struct {
	ID    string              `bson:"id" json:"id"`
	Ctime primitive.Timestamp `bson:"ts" json:"ts"` // commit timestamp of the transaction
	State TxnState            `bson:"state" json:"state"`
}

func (RestoreTxn) String added in v1.7.0

func (t RestoreTxn) String() string

type Shard

type Shard struct {
	ID   string `bson:"_id"`
	RS   string `bson:"-"`
	Host string `bson:"host"`
}

Shard represent config.shard https://docs.mongodb.com/manual/reference/config-database/#config.shards _id may differ from the rs name, so extract rs name from the host (format like "rs2/localhost:27017") see https://jira.percona.com/browse/PBM-595

type Status

type Status string

Status is a backup current status

const (
	StatusInit  Status = "init"
	StatusReady Status = "ready"

	StatusStarting  Status = "starting"
	StatusRunning   Status = "running"
	StatusDumpDone  Status = "dumpDone"
	StatusDone      Status = "done"
	StatusCancelled Status = "canceled"
	StatusError     Status = "error"
)

type StatusOpTimes

type StatusOpTimes struct {
	LastCommittedOpTime       *OpTime `bson:"lastCommittedOpTime" json:"lastCommittedOpTime"`
	ReadConcernMajorityOpTime *OpTime `bson:"readConcernMajorityOpTime" json:"readConcernMajorityOpTime"`
	AppliedOpTime             *OpTime `bson:"appliedOpTime" json:"appliedOpTime"`
	DurableOptime             *OpTime `bson:"durableOpTime" json:"durableOpTime"`
}

type StorageConf added in v1.2.0

type StorageConf struct {
	Type       StorageType `bson:"type" json:"type" yaml:"type"`
	S3         s3.Conf     `bson:"s3,omitempty" json:"s3,omitempty" yaml:"s3,omitempty"`
	Azure      azure.Conf  `bson:"azure,omitempty" json:"azure,omitempty" yaml:"azure,omitempty"`
	Filesystem fs.Conf     `bson:"filesystem,omitempty" json:"filesystem,omitempty" yaml:"filesystem,omitempty"`
}

StorageConf is a configuration of the backup storage

func (*StorageConf) Path added in v1.5.0

func (s *StorageConf) Path() string

func (*StorageConf) Typ added in v1.5.0

func (s *StorageConf) Typ() string

type StorageType

type StorageType string

StorageType represents a type of the destination storage for backups

const (
	StorageUndef      StorageType = ""
	StorageS3         StorageType = "s3"
	StorageAzure      StorageType = "azure"
	StorageFilesystem StorageType = "filesystem"
	StorageBlackHole  StorageType = "blackhole"
)

type SubsysStatus added in v1.4.0

type SubsysStatus struct {
	OK  bool   `bson:"ok"`
	Err string `bson:"e"`
}

type Timeline added in v1.3.0

type Timeline struct {
	Start uint32 `json:"start"`
	End   uint32 `json:"end"`
	Size  int64  `json:"-"`
}

func MergeTimelines added in v1.3.0

func MergeTimelines(tlns ...[]Timeline) []Timeline

MergeTimelines merges overlapping sets on timelines it presumes timelines are sorted and don't start from 0

func (Timeline) String added in v1.3.0

func (t Timeline) String() string

type TxnState added in v1.7.0

type TxnState string
const (
	TxnCommit  TxnState = "commit"
	TxnPrepare TxnState = "prepare"
	TxnAbort   TxnState = "abort"
	TxnUnknown TxnState = ""
)

Directories

Path Synopsis
fs
s3

Jump to

Keyboard shortcuts

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