Documentation ¶
Index ¶
- Constants
- Variables
- func GetClusterID(session *mgo.Session) (*bson.ObjectId, error)
- func GetConfigsvrShards(session *mgo.Session) ([]*mdbstructs.Shard, error)
- func GetListShards(session *mgo.Session) (*mdbstructs.ListShards, error)
- func GetMongosRouters(session *mgo.Session) ([]*mdbstructs.Mongos, error)
- func HasReplsetMemberTags(member *mdbstructs.ReplsetConfigMember, tags map[string]string) bool
- type Balancer
- func (b *Balancer) GetStatus() (*mdbstructs.BalancerStatus, error)
- func (b *Balancer) IsEnabled() (bool, error)
- func (b *Balancer) IsRunning() (bool, error)
- func (b *Balancer) RestoreState() error
- func (b *Balancer) Start() error
- func (b *Balancer) Stop() error
- func (b *Balancer) StopAndWait(retries int, retryInterval time.Duration) error
- type IsMaster
- type Replset
- func (r *Replset) BackupSource(replsetTags map[string]string) (string, error)
- func (r *Replset) Config() *mdbstructs.ReplsetConfig
- func (r *Replset) GetStatusMember(host string) *mdbstructs.ReplsetStatusMember
- func (r *Replset) GetStatusPrimary() *mdbstructs.ReplsetStatusMember
- func (r *Replset) ID() *bson.ObjectId
- func (r *Replset) Name() string
- func (r *Replset) RefreshState() error
- func (r *Replset) Status() *mdbstructs.ReplsetStatus
- type ReplsetScorer
- type ReplsetScoringMember
- type ReplsetScoringMsg
- type Shard
- type ShardingState
Constants ¶
const ( NodeTypeUndefined = iota NodeTypeMongod NodeTypeMongodReplicaset NodeTypeMongodShardSvr NodeTypeMongodConfigSvr NodeTypeMongos )
Variables ¶
var BalancerCmdTimeoutMs = 60000
BalancerCmdTimeoutMs is the amount of time in milliseconds to wait for a balancer command to run. 60sec is the same default used in the 'mongo' shell
Functions ¶
func GetClusterID ¶
GetClusterID returns the cluster ID using the 'config.version' collection. This will only succeed on a mongos or config server, use .GetClusterIDShard instead on shard servers
func GetConfigsvrShards ¶
func GetConfigsvrShards(session *mgo.Session) ([]*mdbstructs.Shard, error)
Return shards within a sharded cluster using the 'config.shards' collection on a config server. This is needed because config servers do not have the 'listShards' command. Use .GetListShards() to get shards from a mongos instead.
https://docs.mongodb.com/manual/reference/config-database/#config.shards
func GetListShards ¶
func GetListShards(session *mgo.Session) (*mdbstructs.ListShards, error)
Return shards within a sharded cluster using the MongoDB 'listShards' server command. This command will only succeed on a mongos, use .GetConfigsvrShards() to get shards from a config server.
https://docs.mongodb.com/manual/reference/command/listShards/
func GetMongosRouters ¶
func GetMongosRouters(session *mgo.Session) ([]*mdbstructs.Mongos, error)
GetMongoRouters returns a slice of Mongos instances with a recent "ping" time, sorted by the "ping" time to prefer healthy instances. This will only succeed on a cluster config server or mongos instance Sometimes, usually after a restore, there is a period of time where querying configMongosColl returns nothing, even if there are mongoS. That's why there we are retrying.
func HasReplsetMemberTags ¶
func HasReplsetMemberTags(member *mdbstructs.ReplsetConfigMember, tags map[string]string) bool
HasReplsetMemberTags returns a boolean reflecting whether or not a replica set config member matches a list of replica set tags
https://docs.mongodb.com/manual/reference/replica-configuration/#rsconf.members[n].tags
Types ¶
type Balancer ¶
type Balancer struct {
// contains filtered or unexported fields
}
func (*Balancer) GetStatus ¶ added in v0.5.0
func (b *Balancer) GetStatus() (*mdbstructs.BalancerStatus, error)
getStatus returns a struct representing the result of the MongoDB 'balancerStatus' command. This command will only succeed on a session to a mongos process (as of MongoDB 3.6)
https://docs.mongodb.com/manual/reference/command/balancerStatus/
func (*Balancer) IsRunning ¶
IsRunning returns a boolean reflecting if the balancer is currently running
func (*Balancer) RestoreState ¶
RestoreState ensures the balancer is restored to its original state
func (*Balancer) Start ¶
Start performs a 'balancerStart' server command on the provided session
https://docs.mongodb.com/manual/reference/command/balancerStart/
func (*Balancer) Stop ¶
Stop performs a 'balancerStop' server command on the provided session
https://docs.mongodb.com/manual/reference/command/balancerStop/
type IsMaster ¶
type IsMaster struct {
// contains filtered or unexported fields
}
func NewIsMaster ¶
NewIsMaster returns a struct for handling the output of the MongoDB 'isMaster' server command.
func (*IsMaster) IsConfigServer ¶
Use the undocumented 'configsvr' field to determine a node is a config server. This node must have replication enabled. For unexplained reasons the value of 'configsvr' must be an int equal to '2'.
https://github.com/mongodb/mongo/blob/v3.6/src/mongo/db/repl/replication_info.cpp#L355-L358
func (*IsMaster) IsMasterDoc ¶
func (i *IsMaster) IsMasterDoc() *mdbstructs.IsMaster
IsMasterDoc returns the raw response from the MongoDB 'isMaster' server command.
func (*IsMaster) IsMongos ¶
Use a combination of the 'isMaster', 'SetName' and 'Msg' field to determine a node is a mongos. A mongos will always have 'isMaster' equal to true, no 'SetName' defined and 'Msg' set to 'isdbgrid'.
https://github.com/mongodb/mongo/blob/v3.6/src/mongo/s/commands/cluster_is_master_cmd.cpp#L112-L113
func (*IsMaster) IsReplset ¶
Use the 'SetName' field to determine if a node is a member of replication. If 'SetName' is defined the node is a valid member.
func (*IsMaster) IsShardServer ¶
Use the existence of the '$configServerState' field to determine if a node is a mongod with the 'shardsvr' cluster role.
func (*IsMaster) IsShardedCluster ¶
The isMaster struct is from a Sharded Cluster if the seed host is a valid mongos, config server or shard server.
func (*IsMaster) LastWrite ¶
func (i *IsMaster) LastWrite() bson.MongoTimestamp
LastWrite returns the last write to the MongoDB database as a bson.MongoTimestamp
type Replset ¶
func (*Replset) BackupSource ¶
func (*Replset) Config ¶
func (r *Replset) Config() *mdbstructs.ReplsetConfig
Config returns the replica set status
func (*Replset) GetStatusMember ¶
func (r *Replset) GetStatusMember(host string) *mdbstructs.ReplsetStatusMember
GetStatusMember returns the status for a replica set member, by host name using the output of the MongoDB 'replSetGetStatus' server command
func (*Replset) GetStatusPrimary ¶
func (r *Replset) GetStatusPrimary() *mdbstructs.ReplsetStatusMember
GetStatusPrimary returns the status for the replica set Primary using the output of the MongoDB 'replSetGetStatus' server command
func (*Replset) RefreshState ¶
RefreshState updates the replica set state
func (*Replset) Status ¶
func (r *Replset) Status() *mdbstructs.ReplsetStatus
Status returns the replica set config
type ReplsetScorer ¶
type ReplsetScorer struct {
// contains filtered or unexported fields
}
type ReplsetScoringMember ¶
type ReplsetScoringMember struct {
// contains filtered or unexported fields
}
func (*ReplsetScoringMember) MultiplyScore ¶
func (m *ReplsetScoringMember) MultiplyScore(multiplier float64, msg ReplsetScoringMsg)
func (*ReplsetScoringMember) Name ¶
func (m *ReplsetScoringMember) Name() string
func (*ReplsetScoringMember) Score ¶
func (m *ReplsetScoringMember) Score() int
func (*ReplsetScoringMember) Skip ¶
func (m *ReplsetScoringMember) Skip(msg ReplsetScoringMsg)
type ReplsetScoringMsg ¶
type ReplsetScoringMsg string
type Shard ¶
type Shard struct {
// contains filtered or unexported fields
}
func NewShard ¶
func NewShard(shard *mdbstructs.Shard) *Shard
type ShardingState ¶
type ShardingState struct {
// contains filtered or unexported fields
}
func NewShardingState ¶
func NewShardingState(session *mgo.Session) (*ShardingState, error)
NewShardingState returns a struct reflecting the output of the 'shardingState' server command. This command should be ran on a shard mongod
https://docs.mongodb.com/manual/reference/command/shardingState/
TODO: Do we need this or can we just use GetClusterID?
func (*ShardingState) ClusterID ¶
func (s *ShardingState) ClusterID() *bson.ObjectId
ClusterID returns the cluster ID using the result of the 'balancerState' server command