cluster

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NodeTypeUndefined = iota
	NodeTypeMongod
	NodeTypeMongodReplicaset
	NodeTypeMongodShardSvr
	NodeTypeMongodConfigSvr
	NodeTypeMongos
)

Variables

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

func GetClusterID(session *mgo.Session) (*bson.ObjectId, error)

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 NewBalancer

func NewBalancer(session *mgo.Session) (*Balancer, error)

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

func (b *Balancer) IsEnabled() (bool, error)

IsEnabled returns a boolean reflecting if the balancer is enabled

func (*Balancer) IsRunning

func (b *Balancer) IsRunning() (bool, error)

IsRunning returns a boolean reflecting if the balancer is currently running

func (*Balancer) RestoreState

func (b *Balancer) RestoreState() error

RestoreState ensures the balancer is restored to its original state

func (*Balancer) Start

func (b *Balancer) Start() error

Start performs a 'balancerStart' server command on the provided session

https://docs.mongodb.com/manual/reference/command/balancerStart/

func (*Balancer) Stop

func (b *Balancer) Stop() error

Stop performs a 'balancerStop' server command on the provided session

https://docs.mongodb.com/manual/reference/command/balancerStop/

func (*Balancer) StopAndWait

func (b *Balancer) StopAndWait(retries int, retryInterval time.Duration) error

StopAndWait performs a Stop and then waits for the balancer to stop running any balancer operations

type IsMaster

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

func NewIsMaster

func NewIsMaster(session *mgo.Session) (*IsMaster, error)

NewIsMaster returns a struct for handling the output of the MongoDB 'isMaster' server command.

https://docs.mongodb.com/manual/reference/command/isMaster/

func (*IsMaster) IsConfigServer

func (i *IsMaster) IsConfigServer() bool

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

func (i *IsMaster) IsMongos() bool

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

func (i *IsMaster) IsReplset() bool

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

func (i *IsMaster) IsShardServer() bool

Use the existence of the '$configServerState' field to determine if a node is a mongod with the 'shardsvr' cluster role.

func (*IsMaster) IsShardedCluster

func (i *IsMaster) IsShardedCluster() bool

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

type Replset struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewReplset

func NewReplset(session *mgo.Session) (*Replset, error)

func (*Replset) BackupSource

func (r *Replset) BackupSource(replsetTags map[string]string) (string, error)

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

func (r *Replset) ID() *bson.ObjectId

ID returns the replica set ID as a bson.ObjectId

func (*Replset) Name

func (r *Replset) Name() string

Name returns the replica set name as a string

func (*Replset) RefreshState

func (r *Replset) RefreshState() error

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

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

Jump to

Keyboard shortcuts

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