pbm

package
v1.14.4 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReplRoleUnknown   = "unknown"
	ReplRoleShard     = "shard"
	ReplRoleConfigSrv = "configsrv"

	// TmpUsersCollection and TmpRoles are tmp collections used to avoid
	// user related issues while resoring on new cluster.
	// See https://jira.percona.com/browse/PBM-425
	//
	// Backup should ensure abscense of this collection to avoid
	// restore conflicts. See https://jira.percona.com/browse/PBM-460
	TmpUsersCollection = `pbmRUsers`
	TmpRolesCollection = `pbmRRoles`
)
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"
	// PITRCollection represents current incremental backups state
	PITRCollection = "pbmPITRState"
	//PITRChunksCollection contains index metadata of PITR chunks
	PITRChunksCollection = "pbmPITRChunks"
	//PITRChunksOldCollection contains archived index metadata of PITR chunks
	PITRChunksOldCollection = "pbmPITRChunks.old"
	// StatusCollection stores pbm status
	StatusCollection = "pbmStatus"
	// PBMOpLogCollection contains log of aquired locks (hence run ops)
	PBMOpLogCollection = "pbmOpLog"
	// AgentsStatusCollection is a 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 StaleFrameSec uint32 = 30
View Source
const StorInitFile = ".pbm.init"

Variables

View Source
var (
	WaitActionStart = time.Second * 15
	WaitBackupStart = WaitActionStart + PITRcheckRange*12/10
)
View Source
var ErrStorageUndefined = errors.New("storage undefined")

ErrStorageUndefined is an error for undefined storage

Functions

func ValidateConfigKey

func ValidateConfigKey(k string) bool

ValidateConfigKey checks if a config key valid

Types

type AgentStat

type AgentStat struct {
	Node          string              `bson:"n"`
	RS            string              `bson:"rs"`
	Ver           string              `bson:"v"`
	PBMStatus     SubsysStatus        `bson:"pbms"`
	NodeStatus    SubsysStatus        `bson:"nodes"`
	StorageStatus SubsysStatus        `bson:"stors"`
	Heartbeat     primitive.Timestamp `bson:"hb"`
}

func (*AgentStat) OK

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

type AuthInfo

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

type AuthUser

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

type AuthUserRoles

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

type BackupCmd

type BackupCmd struct {
	Name        string          `bson:"name"`
	Compression CompressionType `bson:"compression"`
}

func (BackupCmd) String

func (b BackupCmd) String() string

type BackupMeta

type BackupMeta struct {
	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"`
	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"`
	Error            string              `bson:"error,omitempty" json:"error,omitempty"`
	PBMVersion       string              `bson:"pbm_version,omitempty" json:"pbm_version,omitempty"`
}

BackupMeta is a backup's metadata

func (*BackupMeta) RS

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

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

type BackupReplset

type BackupReplset struct {
	Name             string              `bson:"name" json:"name"`
	DumpName         string              `bson:"dump_name" json:"backup_name" `
	OplogName        string              `bson:"oplog_name" json:"oplog_name"`
	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 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"`
	PITRestore PITRestoreCmd   `bson:"pitrestore,omitempty"`
	Delete     DeleteBackupCmd `bson:"delete,omitempty"`
	TS         int64           `bson:"ts"`
	OPID       OPID            `bson:"-"`
}

func (Cmd) String

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"
	CmdCancelBackup     Command = "cancelBackup"
	CmdResyncBackupList Command = "resyncBcpList"
	CmdPITR             Command = "pitr"
	CmdPITRestore       Command = "pitrestore"
	CmdDeleteBackup     Command = "delete"
)

func (Command) String

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"
)

func FileCompression

func FileCompression(ext string) CompressionType

FileCompression return compression alg based on given file extention

type Condition

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

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"`
	Epoch   primitive.Timestamp `bson:"epoch" json:"-" yaml:"-"`
}

Config is a pbm config

type ConfigServerState

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

type ConnectionStatus

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

type DeleteBackupCmd

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

func (DeleteBackupCmd) String

func (d DeleteBackupCmd) String() string

type Epoch

type Epoch primitive.Timestamp

func (Epoch) TS

func (e Epoch) TS() primitive.Timestamp

type ErrConcurrentOp

type ErrConcurrentOp struct {
	Lock LockHeader
}

ErrConcurrentOp means lock was already aquired by another node

func (ErrConcurrentOp) Error

func (e ErrConcurrentOp) Error() string

type ErrDuplicateOp

type ErrDuplicateOp struct {
	Lock LockHeader
}

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

func (ErrDuplicateOp) Error

func (e ErrDuplicateOp) Error() string

type ErrWasStaleLock

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

func (e ErrWasStaleLock) Error() string

type ErrorCursor

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

func (ErrorCursor) Error

func (c ErrorCursor) Error() string

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

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

func (l *Lock) Release() error

Release the lock

type LockData

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

type LockHeader

type LockHeader struct {
	Type    Command `bson:"type,omitempty"`
	Replset string  `bson:"replset,omitempty"`
	Node    string  `bson:"node,omitempty"`
	OPID    string  `bson:"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"`
}

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

type MongoLastWrite

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 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

func (n *Node) Connect() error

func (*Node) CurrentUser

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

func (*Node) DropTMPcoll

func (n *Node) DropTMPcoll() error

func (*Node) DumpConns

func (n *Node) DumpConns() int

func (*Node) EnsureNoTMPcoll

func (n *Node) EnsureNoTMPcoll() error

func (*Node) GetInfo

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

func (*Node) GetMongoVersion

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

func (*Node) GetReplsetStatus

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

func (*Node) ID

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) RS

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) SizeDBs

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)

type NodeHealth

type NodeHealth int
const (
	NodeHealthDown NodeHealth = iota
	NodeHealthUp
)

type NodeInfo

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"`
	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) IsLeader

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

func (i *NodeInfo) IsSharded() bool

IsSharded returns true is replset is part sharded cluster

func (*NodeInfo) IsStandalone

func (i *NodeInfo) IsStandalone() bool

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

func (*NodeInfo) ReplsetRole

func (i *NodeInfo) ReplsetRole() ReplRole

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 OPID

type OPID primitive.ObjectID

func NilOPID

func NilOPID() OPID

func OPIDfromStr

func OPIDfromStr(s string) (OPID, error)

func (OPID) Obj

func (o OPID) Obj() primitive.ObjectID

func (OPID) String

func (o OPID) String() string

type OpLog

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 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

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

func (*PBM) AddRestoreRSMeta

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

func (*PBM) AgentStatusGC

func (p *PBM) AgentStatusGC() error

AgentStatusGC cleans up stale agent statuses

func (*PBM) BackupGetNext

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

func (*PBM) BackupHB

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

func (*PBM) BackupsList

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

func (*PBM) ChangeBackupState

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

func (*PBM) ChangeBackupStateOPID

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

func (*PBM) ChangeRSState

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

func (*PBM) ChangeRestoreRSState

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

func (*PBM) ChangeRestoreState

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

func (*PBM) ChangeRestoreStateOPID

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

func (*PBM) ClusterMembers

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

ClusterMembers returns list of replicasets current cluster consts of (shards + configserver). The list would consist of on rs if cluster is a non-sharded rs. If `inf` is nil, method would request mongo to define it.

func (*PBM) ClusterTime

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

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

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

DeleteBackupFiles removes backup's artefacts from storage

func (*PBM) DeleteOlderThan

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

DeleteOlderThan deletes backups which older than given Time

func (*PBM) GetAgentStatus

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

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

func (*PBM) GetBackupMeta

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

func (*PBM) GetConfig

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

func (*PBM) GetConfigVar

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

GetConfigVar returns value of given config vaiable

func (*PBM) GetConfigYaml

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

func (*PBM) GetEpoch

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

func (*PBM) GetFirstBackup

func (p *PBM) GetFirstBackup() (*BackupMeta, error)

GetFirstBackup returns first successfully finished backup

func (*PBM) GetLastBackup

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

GetLastBackup returns last successfully finished backup and 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

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

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

func (*PBM) GetLockData

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

func (*PBM) GetLocks

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

func (*PBM) GetNodeInfo

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

GetNodeInfo returns mongo node info

func (*PBM) GetOpLockData

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

func (*PBM) GetOpLocks

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

func (*PBM) GetRestoreMeta

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

func (*PBM) GetRestoreMetaByOPID

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

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

func (*PBM) IsPITR

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

IsPITR checks if PITR is enabled

func (*PBM) ListenCmd

func (p *PBM) ListenCmd() (<-chan Cmd, <-chan error, error)

func (*PBM) LogGet

func (p *PBM) LogGet(r *log.LogRequest, limit int64) ([]log.LogEntry, error)

func (*PBM) LogGetExactSeverity

func (p *PBM) LogGetExactSeverity(r *log.LogRequest, limit int64) ([]log.LogEntry, error)

func (*PBM) Logger

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

func (*PBM) MarkBcpStale

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

func (*PBM) MarkRestoreStale

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

func (*PBM) NewLock

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

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

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

PITRAddChunk stores PITR chunk metadata

func (*PBM) PITRFirstChunkMeta

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

PITRFirstChunkMeta returns the oldest PITR chunk for the given Replset

func (*PBM) PITRGetChunkContains

func (p *PBM) PITRGetChunkContains(rs string, ts primitive.Timestamp) (*PITRChunk, error)

PITRGetChunkContains returns a pitr slice chunk that belongs to the given replica set and contains the given timestamp

func (*PBM) PITRGetChunkStarts

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

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

func (*PBM) PITRGetChunksSlice

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

PITRGetChunksSlice returns slice of PITR oplog chunks which Start TS lies in a given time frame

func (*PBM) PITRGetValidTimelines

func (p *PBM) PITRGetValidTimelines(rs string, until int64, 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

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

PITRLastChunkMeta returns the most recent PITR chunk for the given Replset

func (*PBM) ResetEpoch

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

func (*PBM) RestoreHB

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

func (*PBM) RestoresList

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

func (*PBM) ResyncStorage

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

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

func (*PBM) SendCmd

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

func (*PBM) SetAgentStatus

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

func (*PBM) SetBackupMeta

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

func (*PBM) SetConfig

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

func (*PBM) SetConfigByte

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

func (*PBM) SetConfigVar

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

func (*PBM) SetLastWrite

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

func (*PBM) SetRSFirstWrite

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

func (*PBM) SetRSLastWrite

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

func (*PBM) SetRestoreBackup

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

func (*PBM) SetRestoreMeta

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

func (*PBM) SetRestorePITR

func (p *PBM) SetRestorePITR(name string, ts int64) error

type PITRChunk

type PITRChunk 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
}

PITRChunk is index metadata for the oplog chunks

func PITRmetaFromFName

func PITRmetaFromFName(f string) *PITRChunk

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 PITRConf

type PITRConf struct {
	Enabled bool `bson:"enabled" json:"enabled" yaml:"enabled"`
}

PITRConf is a Point-In-Time Recovery options

type PITRestoreCmd

type PITRestoreCmd struct {
	Name string `bson:"name"`
	TS   int64  `bson:"ts"`
}

func (PITRestoreCmd) String

func (p PITRestoreCmd) String() string

type ReplRole

type ReplRole string

ReplRole is a replicaset role in sharded cluster

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"`
}

type RestoreCmd

type RestoreCmd struct {
	Name       string `bson:"name"`
	BackupName string `bson:"backupName"`
}

func (RestoreCmd) String

func (r RestoreCmd) String() string

type RestoreConf

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

type RestoreMeta struct {
	OPID             string              `bson:"opid" json:"opid"`
	Name             string              `bson:"name" json:"name"`
	Backup           string              `bson:"backup" json:"backup"`
	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"`
	Status           Status              `bson:"status" json:"status"`
	Conditions       []Condition         `bson:"conditions" json:"conditions"`
	Error            string              `bson:"error,omitempty" json:"error,omitempty"`
}

type RestoreReplset

type RestoreReplset struct {
	Name             string              `bson:"name" json:"name"`
	StartTS          int64               `bson:"start_ts" json:"start_ts"`
	Status           Status              `bson:"status" json:"status"`
	LastTransitionTS int64               `bson:"last_transition_ts" json:"last_transition_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 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

type Status

type Status string

Status is a backup current status

const (
	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

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

StorageConf is a configuration of the backup storage

type StorageType

type StorageType string

StorageType represents a type of the destination storage for backups

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

type SubsysStatus

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

type Timeline

type Timeline struct {
	Start uint32
	End   uint32
	Size  int64
}

func MergeTimelines

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

MergeTimelines merges overlapping sets on timelines it preresumes timelines already sorted and don't start from 0

func (Timeline) String

func (t Timeline) String() string

Directories

Path Synopsis
fs
s3

Jump to

Keyboard shortcuts

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