pbm

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2020 License: Apache-2.0 Imports: 21 Imported by: 4

Documentation

Index

Constants

View Source
const (
	ReplRoleUnknown   = "unknown"
	ReplRoleShard     = "shard"
	ReplRoleConfigSrv = "configsrv"
)
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 operations (e.g. locks)
	LockCollection = "pbmLock"
	// 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"

	// NoReplset is the name of a virtual replica set of the standalone node
	NoReplset = "pbmnoreplicaset"

	// MetadataFileSuffix is a suffix for the metadata file on a storage
	MetadataFileSuffix = ".pbm.json"
)
View Source
const StaleFrameSec uint32 = 30

Variables

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

ErrStorageUndefined is an error for undefined storage

View Source
var WaitActionStart = time.Second * 15

Functions

func ConfKeys added in v1.1.0

func ConfKeys() []string

ConfKeys returns valid config keys (option names)

func ValidateConfigKey added in v1.1.0

func ValidateConfigKey(k string) bool

ValidateConfigKey checks if a config key valid

Types

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 {
	Name        string          `bson:"name"`
	Compression CompressionType `bson:"compression"`
}

type BackupMeta

type BackupMeta struct {
	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"`
}

BackupMeta is a backup's metadata

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"`
	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"`
	TS      int64      `bson:"ts"`
}

type Command

type Command string
const (
	CmdUndefined        Command = ""
	CmdBackup           Command = "backup"
	CmdRestore          Command = "restore"
	CmdCancelBackup     Command = "cancelBackup"
	CmdResyncBackupList Command = "resyncBcpList"
)

type CompressionType

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

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 {
	Storage StorageConf `bson:"storage" json:"storage" yaml:"storage"`
}

Config is a pbm config

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 ErrConcurrentOp added in v1.1.0

type ErrConcurrentOp struct {
	Lock LockHeader
}

func (ErrConcurrentOp) Error added in v1.1.0

func (e ErrConcurrentOp) Error() string

type ErrorCursor

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

func (ErrorCursor) Error

func (c ErrorCursor) Error() string

type IsMaster

type IsMaster 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"`
	IsMaster                     bool               `bson:"ismaster"`
	Secondary                    bool               `bson:"secondary,omitempty"`
	Hidden                       bool               `bson:"hidden,omitempty"`
	ConfigSvr                    int                `bson:"configsvr,omitempty"`
	Me                           string             `bson:"me"`
	LastWrite                    IsMasterLastWrite  `bson:"lastWrite"`
	ClusterTime                  *ClusterTime       `bson:"$clusterTime,omitempty"`
	ConfigServerState            *ConfigServerState `bson:"$configServerState,omitempty"`
	// GleStats                     *GleStats            `bson:"$gleStats,omitempty"`
	OperationTime *primitive.Timestamp `bson:"operationTime,omitempty"`
}

IsMaster represents the document returned by db.runCommand( { isMaster: 1 } )

func (*IsMaster) IsLeader added in v1.1.0

func (im *IsMaster) IsLeader() bool

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

func (*IsMaster) IsSharded

func (im *IsMaster) IsSharded() bool

IsSharded returns true is replset is part sharded cluster

func (*IsMaster) IsStandalone added in v1.1.0

func (im *IsMaster) IsStandalone() bool

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

func (*IsMaster) ReplsetRole

func (im *IsMaster) ReplsetRole() ReplRole

ReplsetRole returns replset role in sharded clister

type IsMasterLastWrite

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

IsMasterLastWrite represents the last write to the MongoDB server

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 there is lock already acquired by another process or some error happened. In case there is already concurrent lock exists, it checks if the concurrent lock isn't stale and clear the rot and tries again if it's happened to be so.

func (*Lock) Release added in v1.1.0

func (l *Lock) Release() error

Release the lock

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"`
	Replset    string  `bson:"replset,omitempty"`
	Node       string  `bson:"node,omitempty"`
	BackupName string  `bson:"backup,omitempty"`
}

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

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, name string, curi string) (*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) CurrentUser added in v1.1.3

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

func (*Node) GetIsMaster

func (n *Node) GetIsMaster() (*IsMaster, error)

func (*Node) GetMongoVersion

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

func (*Node) GetReplsetStatus

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

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, error)

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

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

type NodeHealth

type NodeHealth int
const (
	NodeHealthDown NodeHealth = iota
	NodeHealthUp
)

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 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 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) BackupHB added in v1.1.2

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

func (*PBM) BackupsList

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

func (*PBM) ChangeBackupState added in v1.1.0

func (p *PBM) ChangeBackupState(bcpName 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) 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) 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 artefacts from storage

func (*PBM) DeleteOlderThan added in v1.2.0

func (p *PBM) DeleteOlderThan(t time.Time) error

DeleteOlderThan deletes backups which older than Time

func (*PBM) GetBackupMeta

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

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) (string, 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) GetIsMaster

func (p *PBM) GetIsMaster() (*IsMaster, error)

GetIsMaster returns IsMaster object encapsulating respective MongoDB structure

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) GetRestoreMeta added in v1.1.2

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

func (*PBM) GetShards

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

GetShards gets list of shards

func (*PBM) GetStorage

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

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

func (*PBM) ListenCmd

func (p *PBM) ListenCmd() (<-chan Cmd, <-chan error, 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) RestoreHB added in v1.1.2

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

func (*PBM) RestoresList added in v1.1.2

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

func (*PBM) ResyncBackupList added in v1.1.0

func (p *PBM) ResyncBackupList() error

func (*PBM) SendCmd

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

func (*PBM) SetBackupMeta added in v1.1.0

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

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) SetLastWrite added in v1.1.0

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

func (*PBM) SetRSLastWrite added in v1.1.0

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

func (*PBM) SetRestoreMeta added in v1.1.2

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

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"`
	// GleStats                *GleStats            `bson:"$gleStats,omitempty" json:"$gleStats,omitempty"`
	OperationTime *primitive.Timestamp `bson:"operationTime,omitempty" json:"operationTime,omitempty"`
}

type RestoreCmd

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

type RestoreMeta added in v1.1.2

type RestoreMeta struct {
	Name             string              `bson:"name" json:"name"`
	Backup           string              `bson:"backup" json:"backup"`
	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 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"`
	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"`
	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 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"`
	Filesystem fs.Conf     `bson:"filesystem,omitempty" json:"filesystem,omitempty" yaml:"filesystem,omitempty"`
}

type StorageType

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

Directories

Path Synopsis
fs
s3

Jump to

Keyboard shortcuts

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