Documentation ¶
Index ¶
- func AgentStatusGC(ctx context.Context, m connect.Client) error
- func CheckTopoForBackup(ctx context.Context, m connect.Client, type_ defs.BackupType) error
- func ClusterTimeFromNodeInfo(info *NodeInfo) (primitive.Timestamp, error)
- func ConfSvrConn(ctx context.Context, cn *mongo.Client) (string, error)
- func GetClusterTime(ctx context.Context, m connect.Client) (primitive.Timestamp, error)
- func GetLastWrite(ctx context.Context, m *mongo.Client, majority bool) (primitive.Timestamp, error)
- func HasConfigShard(ctx context.Context, conn connect.Client) (bool, error)
- func IsWriteMajorityRequested(ctx context.Context, m *mongo.Client, writeConcern *writeconcern.WriteConcern) (bool, error)
- func ListShardedTimeseries(ctx context.Context, conn connect.Client) ([]string, error)
- func NodeSuits(ctx context.Context, m *mongo.Client, inf *NodeInfo) (bool, error)
- func NodeSuitsExt(ctx context.Context, m *mongo.Client, inf *NodeInfo, t defs.BackupType) (bool, error)
- func OpTimeFromNodeInfo(inf *NodeInfo, majority bool) (primitive.Timestamp, error)
- func RemoveAgentStatus(ctx context.Context, m connect.Client, stat AgentStat) error
- func ReplicationLag(ctx context.Context, m *mongo.Client, self string) (int, error)
- func SetAgentStatus(ctx context.Context, m connect.Client, stat *AgentStat) error
- func SetBalancerStatus(ctx context.Context, m connect.Client, mode BalancerMode) error
- type AgentStat
- func GetAgentStatus(ctx context.Context, m connect.Client, rs, node string) (AgentStat, error)
- func ListAgentStatuses(ctx context.Context, m connect.Client) ([]AgentStat, error)
- func ListAgents(ctx context.Context, m connect.Client) ([]AgentStat, error)
- func ListSteadyAgents(ctx context.Context, m connect.Client) ([]AgentStat, error)
- type AuthInfo
- type AuthUser
- type AuthUserRoles
- type BalancerMode
- type BalancerStatus
- type ClusterTime
- type ConfigServerState
- type ConnectionStatus
- type ExternOpts
- type MongoLastWrite
- type MongodOpts
- type MongodOptsSec
- type MongodOptsStorage
- type NodeBrief
- type NodeInfo
- func (i *NodeInfo) IsClusterLeader() bool
- func (i *NodeInfo) IsConfigSrv() bool
- func (i *NodeInfo) IsDelayed() bool
- func (i *NodeInfo) IsLeader() bool
- func (i *NodeInfo) IsMongos() bool
- func (i *NodeInfo) IsSharded() bool
- func (i *NodeInfo) IsStandalone() bool
- func (i *NodeInfo) ReplsetRole() ReplsetRole
- type NodeRole
- type NodeStatus
- type NodeURI
- type OpTime
- type RSConfig
- type RSMember
- type ReplsetName
- type ReplsetRole
- type ReplsetStatus
- type Shard
- type ShardName
- type StatusOpTimes
- type SubsysStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AgentStatusGC ¶
AgentStatusGC cleans up stale agent statuses
func CheckTopoForBackup ¶
func ClusterTimeFromNodeInfo ¶
func GetClusterTime ¶
ClusterTime returns mongo's current cluster time
func GetLastWrite ¶
func HasConfigShard ¶
HasConfigShard return true if configsvr is listened in shards list
func IsWriteMajorityRequested ¶
func IsWriteMajorityRequested( ctx context.Context, m *mongo.Client, writeConcern *writeconcern.WriteConcern, ) (bool, error)
IsWriteMajorityRequested compares cluster wide majority (replSetGetStatus.writeMajorityCount) with WriteConcern requested in connection string and determinates if majority is requested or not
func ListShardedTimeseries ¶
func NodeSuitsExt ¶
func OpTimeFromNodeInfo ¶
func RemoveAgentStatus ¶
func ReplicationLag ¶
ReplicationLag returns node replication lag in seconds
func SetAgentStatus ¶
func SetBalancerStatus ¶
SetBalancerStatus sets balancer status
Types ¶
type AgentStat ¶
type AgentStat struct { // Node is like agent ID. Looks like `rs00:27017` (host:port of direct mongod). Node string `bson:"n"` // RS is the direct node replset name. RS string `bson:"rs"` // State is the mongod state code. State defs.NodeState `bson:"s"` // StateStr is the mongod state string (e.g. PRIMARY, SECONDARY, ARBITER) StateStr string `bson:"str"` // Hidden is set for hidden node. Hidden bool `bson:"hdn"` // Passive is set when node cannot be primary (priority 0). // // Hidden and delayed nodes are always passive. // Arbiter cannot be primary because it is not a data-bearing member (non-writable) // but it is not passive (has 1 election vote). Passive bool `bson:"psv"` // Arbiter is true for argiter node. Arbiter bool `bson:"arb"` // DelaySecs is the node configured replication delay (lag). DelaySecs int32 `bson:"delay"` // Replication lag for mongod. ReplicationLag int `bson:"repl_lag"` // AgentVer has the PBM Agent version (looks like `v2.3.4`) AgentVer string `bson:"v"` // MongoVer is the mongod version (looks like `v7.0.0`) MongoVer string `bson:"mv"` // PerconaVer is the PSMDB version (looks like `v7.0.0-1`). // // Empty for non-PSMDB (e.i MongoDB CE). PerconaVer string `bson:"pv,omitempty"` // PBMStatus is the agent status. PBMStatus SubsysStatus `bson:"pbms"` // NodeStatus is the mongod/connection status. NodeStatus SubsysStatus `bson:"nodes"` // StorageStatus is the remote storage status. StorageStatus SubsysStatus `bson:"stors"` // Heartbeat is agent's last seen cluster time. Heartbeat primitive.Timestamp `bson:"hb"` // Err can be any error. Err string `bson:"e"` }
func GetAgentStatus ¶
GetAgentStatus returns agent status by given node and rs it's up to user how to handle ErrNoDocuments
func ListAgentStatuses ¶
ListAgentStatuses returns list of registered agents
func ListSteadyAgents ¶
ListSteadyAgents returns agents which are in steady state for backup or PITR.
func (*AgentStat) IsStale ¶
IsStale returns true if agent's heartbeat is steal for the give `t` cluster time.
func (*AgentStat) MongoVersion ¶
func (s *AgentStat) MongoVersion() version.MongoVersion
type AuthInfo ¶
type AuthInfo struct { Users []AuthUser `bson:"authenticatedUsers" json:"authenticatedUsers"` UserRoles []AuthUserRoles `bson:"authenticatedUserRoles" json:"authenticatedUserRoles"` }
type AuthUserRoles ¶
type BalancerMode ¶
type BalancerMode string
const ( BalancerModeOn BalancerMode = "full" BalancerModeOff BalancerMode = "off" )
func (BalancerMode) String ¶
func (m BalancerMode) String() string
type BalancerStatus ¶
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 GetBalancerStatus ¶
GetBalancerStatus returns balancer status
func (*BalancerStatus) IsOn ¶
func (b *BalancerStatus) IsOn() bool
type ClusterTime ¶
type ConfigServerState ¶
type ConfigServerState struct {
OpTime *OpTime `bson:"opTime"`
}
type ConnectionStatus ¶
type ConnectionStatus struct {
AuthInfo AuthInfo `bson:"authInfo" json:"authInfo"`
}
type ExternOpts ¶
type ExternOpts map[string]MongodOpts
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 MongodOpts ¶
type MongodOpts struct { Net struct { BindIP string `bson:"bindIp" json:"bindIp" yaml:"bindIp"` Port int `bson:"port" json:"port" yaml:"port"` } `bson:"net" json:"net"` Sharding struct { ClusterRole string `bson:"clusterRole" json:"clusterRole" yaml:"-"` } `bson:"sharding" json:"sharding" yaml:"-"` Storage MongodOptsStorage `bson:"storage" json:"storage" yaml:"storage"` Security *MongodOptsSec `bson:"security,omitempty" json:"security,omitempty" yaml:"security,omitempty"` }
func GetMongodOpts ¶
func GetMongodOpts(ctx context.Context, m *mongo.Client, defaults *MongodOpts) (*MongodOpts, error)
type MongodOptsSec ¶
type MongodOptsSec struct { EnableEncryption *bool `bson:"enableEncryption,omitempty" json:"enableEncryption,omitempty" yaml:"enableEncryption,omitempty"` EncryptionCipherMode *string `bson:"encryptionCipherMode,omitempty" json:"encryptionCipherMode,omitempty" yaml:"encryptionCipherMode,omitempty"` EncryptionKeyFile *string `bson:"encryptionKeyFile,omitempty" json:"encryptionKeyFile,omitempty" yaml:"encryptionKeyFile,omitempty"` RelaxPermChecks *bool `bson:"relaxPermChecks,omitempty" json:"relaxPermChecks,omitempty" yaml:"relaxPermChecks,omitempty"` Vault *struct { ServerName *string `bson:"serverName,omitempty" json:"serverName,omitempty" yaml:"serverName,omitempty"` Port *int `bson:"port,omitempty" json:"port,omitempty" yaml:"port,omitempty"` TokenFile *string `bson:"tokenFile,omitempty" json:"tokenFile,omitempty" yaml:"tokenFile,omitempty"` Secret *string `bson:"secret,omitempty" json:"secret,omitempty" yaml:"secret,omitempty"` ServerCAFile *string `bson:"serverCAFile,omitempty" json:"serverCAFile,omitempty" yaml:"serverCAFile,omitempty"` SecretVersion *uint32 `bson:"secretVersion,omitempty" json:"secretVersion,omitempty" yaml:"secretVersion,omitempty"` DisableTLSForTesting *bool `bson:"disableTLSForTesting,omitempty" json:"disableTLSForTesting,omitempty" yaml:"disableTLSForTesting,omitempty"` } `bson:"vault,omitempty" json:"vault,omitempty" yaml:"vault,omitempty"` KMIP *struct { ServerName *string `bson:"serverName,omitempty" json:"serverName,omitempty" yaml:"serverName,omitempty"` Port *int `bson:"port,omitempty" json:"port,omitempty" yaml:"port,omitempty"` ClientCertificateFile *string `bson:"clientCertificateFile,omitempty" json:"clientCertificateFile,omitempty" yaml:"clientCertificateFile,omitempty"` ClientKeyFile *string `bson:"clientKeyFile,omitempty" json:"clientKeyFile,omitempty" yaml:"clientKeyFile,omitempty"` ServerCAFile *string `bson:"serverCAFile,omitempty" json:"serverCAFile,omitempty" yaml:"serverCAFile,omitempty"` KeyIdentifier *string `bson:"keyIdentifier,omitempty" json:"keyIdentifier,omitempty" yaml:"keyIdentifier,omitempty"` ClientCertificatePassword *string `bson:"clientCertificatePassword,omitempty" json:"-" yaml:"clientCertificatePassword,omitempty"` } `bson:"kmip,omitempty" json:"kmip,omitempty" yaml:"kmip,omitempty"` }
type MongodOptsStorage ¶
type MongodOptsStorage struct { DirectoryPerDB bool `bson:"directoryPerDB" json:"directoryPerDB" yaml:"directoryPerDB"` DBpath string `bson:"dbPath" json:"dbPath" yaml:"dbPath"` WiredTiger struct { EngineConfig struct { JournalCompressor string `bson:"journalCompressor" json:"journalCompressor" yaml:"journalCompressor"` DirectoryForIndexes bool `bson:"directoryForIndexes" json:"directoryForIndexes" yaml:"directoryForIndexes"` } `bson:"engineConfig" json:"engineConfig" yaml:"engineConfig"` CollectionConfig struct { BlockCompressor string `bson:"blockCompressor" json:"blockCompressor" yaml:"blockCompressor"` } `bson:"collectionConfig" json:"collectionConfig" yaml:"collectionConfig"` IndexConfig struct { PrefixCompression bool `bson:"prefixCompression" json:"prefixCompression" yaml:"prefixCompression"` } `bson:"indexConfig" json:"indexConfig" yaml:"indexConfig"` } `bson:"wiredTiger" json:"wiredTiger" yaml:"wiredTiger"` }
func NewMongodOptsStorage ¶
func NewMongodOptsStorage() *MongodOptsStorage
NewMongodOptsStorage return MongodOptsStorage with default settings
func (*MongodOptsStorage) UnmarshalYAML ¶
func (stg *MongodOptsStorage) UnmarshalYAML(unmarshal func(interface{}) error) error
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"` Passive bool `bson:"passive,omitempty"` ArbiterOnly bool `bson:"arbiterOnly"` SecondaryDelayOld int32 `bson:"slaveDelay"` SecondaryDelaySecs int32 `bson:"secondaryDelaySecs"` 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"` Opts MongodOpts `bson:"-"` }
NodeInfo represents the mongo's node info
func GetNodeInfoExt ¶
GetNodeInfoExt returns mongo node info with mongod options
func (*NodeInfo) IsClusterLeader ¶
IsClusterLeader - cluster leader is a primary node on configsrv or just primary node in non-sharded replicaset
func (*NodeInfo) IsConfigSrv ¶
IsConfigSrv returns true if node belongs to the CSRS in a sharded cluster
func (*NodeInfo) IsLeader ¶
IsLeader returns true if node can act as backup leader (it's configsrv or non shareded rs)
func (*NodeInfo) IsStandalone ¶
IsStandalone returns true if node is not a part of replica set
func (*NodeInfo) ReplsetRole ¶
func (i *NodeInfo) ReplsetRole() ReplsetRole
ReplsetRole returns replset role in sharded clister
type NodeStatus ¶
type NodeStatus struct { ID int `bson:"_id" json:"_id"` Name string `bson:"name" json:"name"` Health defs.NodeHealth `bson:"health" json:"health"` // https://github.com/mongodb/mongo/blob/v8.0/src/mongo/db/repl/member_state.h#L52-L109 State defs.NodeState `bson:"state" json:"state"` // https://github.com/mongodb/mongo/blob/v8.0/src/mongo/db/repl/member_state.h#L170-L193 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"` }
func GetNodeStatus ¶
func (*NodeStatus) IsArbiter ¶
func (s *NodeStatus) IsArbiter() bool
type RSConfig ¶
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 RSMember ¶
type RSMember struct { ID int `bson:"_id" json:"_id"` Host string `bson:"host" json:"host"` ArbiterOnly bool `bson:"arbiterOnly" json:"arbiterOnly"` BuildIndexes bool `bson:"buildIndexes" json:"buildIndexes"` Hidden bool `bson:"hidden" json:"hidden"` Priority float64 `bson:"priority" json:"priority"` Tags map[string]string `bson:"tags,omitempty" json:"tags"` SecondaryDelayOld int64 `bson:"slaveDelay,omitempty"` SecondaryDelaySecs int64 `bson:"secondaryDelaySecs,omitempty"` Votes int `bson:"votes" json:"votes"` }
type ReplsetName ¶
type ReplsetName = string
type ReplsetRole ¶
type ReplsetRole string
ReplsetRole is a replicaset role in sharded cluster
const ( RoleUnknown ReplsetRole = "unknown" RoleShard ReplsetRole = "shard" RoleConfigSrv ReplsetRole = "configsrv" )
type ReplsetStatus ¶
type ReplsetStatus struct { Set string `bson:"set" json:"set"` Date time.Time `bson:"date" json:"date"` MyState defs.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"` //nolint:lll 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"` WriteMajorityCount int `bson:"writeMajorityCount,omitempty" json:"writeMajorityCount,omitempty"` }
func GetReplsetStatus ¶
GetReplsetStatus returns `replSetGetStatus` for the given connection
type Shard ¶
type Shard struct { // ID is the shard ID. // // Usual it is the same as replset name. Except for configsvr - it is always `config`. // Can be customized by name param in `addShard` command. // // https://www.mongodb.com/docs/manual/reference/command/addShard/ ID string `bson:"_id"` // RS is the replset name. RS string `bson:"-"` // Host is a node URI. // // Looks like `rs0/rs00:27018` where // - `rs0` is a replset name // - `rs00` is a hostname or IP // - `27018` is a port Host string `bson:"host"` }
Shard represent a config.shard document.
https://docs.mongodb.com/manual/reference/config-database/#config.shards
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 SubsysStatus ¶
type SubsysStatus struct { // OK is false if there is an error. Otherwise true. OK bool `bson:"ok"` // Err is error string. Err string `bson:"e"` }
SubsysStatus is generic status.