Documentation ¶
Index ¶
- Constants
- Variables
- func AddShard(ctx context.Context, client *mongo.Client, rsName, host string) error
- func CreateRole(ctx context.Context, client *mongo.Client, role string, ...) error
- func CreateUser(ctx context.Context, client *mongo.Client, user, pwd string, ...) error
- func Dial(conf *Config) (*mongo.Client, error)
- func GetFCV(ctx context.Context, client *mongo.Client) (string, error)
- func IsBalancerRunning(ctx context.Context, client *mongo.Client) (bool, error)
- func SetDefaultRWConcern(ctx context.Context, client *mongo.Client, readConcern, writeConcern string) error
- func SetFCV(ctx context.Context, client *mongo.Client, version string) error
- func StartBalancer(ctx context.Context, client *mongo.Client) error
- func StepDown(ctx context.Context, client *mongo.Client, force bool) error
- func StopBalancer(ctx context.Context, client *mongo.Client) error
- func UpdateRole(ctx context.Context, client *mongo.Client, role string, ...) error
- func UpdateUser(ctx context.Context, client *mongo.Client, currName, newName, pass string) error
- func UpdateUserPass(ctx context.Context, client *mongo.Client, name, pass string) error
- func UpdateUserRoles(ctx context.Context, client *mongo.Client, username string, ...) error
- func WriteConfig(ctx context.Context, client *mongo.Client, cfg RSConfig) error
- type BalancerStatus
- type BuildInfo
- type Config
- type ConfigMember
- type ConfigMembers
- func (m *ConfigMembers) AddNew(from ConfigMembers) bool
- func (m *ConfigMembers) ExternalNodesChanged(compareWith ConfigMembers) bool
- func (m *ConfigMembers) FixHosts(compareWith ConfigMembers) (changes bool)
- func (m *ConfigMembers) FixTags(compareWith ConfigMembers) (changes bool)
- func (m *ConfigMembers) RemoveOld(compareWith ConfigMembers) bool
- func (m *ConfigMembers) SetVotes(unsafePSA bool)
- type DBList
- type FCV
- type IsMasterResp
- type Member
- type MemberHealth
- type MemberState
- type OKResponse
- type Optime
- type RSConfig
- type ReplSetGetConfig
- type ReplsetTags
- type Role
- type RoleInfo
- type RolePrivilege
- type Settings
- type ShardList
- type ShardRemoveResp
- type Status
- type StatusOptimes
- type User
- type UsersInfo
- type WriteConcern
Constants ¶
const ( MinVotingMembers = 1 MaxVotingMembers = 7 MaxMembers = 50 DefaultPriority = 2 DefaultVotes = 1 DefaultReadConcern = "majority" DefaultWriteConcern = "majority" )
const ( MemberHealthDown MemberHealth = iota MemberHealthUp MemberStateStartup MemberState = 0 MemberStatePrimary MemberState = 1 MemberStateSecondary MemberState = 2 MemberStateRecovering MemberState = 3 MemberStateStartup2 MemberState = 5 MemberStateUnknown MemberState = 6 MemberStateArbiter MemberState = 7 MemberStateDown MemberState = 8 MemberStateRollback MemberState = 9 MemberStateRemoved MemberState = 10 )
const ShardRemoveCompleted string = "completed"
Variables ¶
var MemberStateStrings = map[MemberState]string{ MemberStateStartup: "STARTUP", MemberStatePrimary: "PRIMARY", MemberStateSecondary: "SECONDARY", MemberStateRecovering: "RECOVERING", MemberStateStartup2: "STARTUP2", MemberStateUnknown: "UNKNOWN", MemberStateArbiter: "ARBITER", MemberStateDown: "DOWN", MemberStateRollback: "ROLLBACK", MemberStateRemoved: "REMOVED", }
Functions ¶
func CreateRole ¶ added in v1.8.0
func CreateUser ¶ added in v1.8.0
func IsBalancerRunning ¶ added in v1.6.0
func SetDefaultRWConcern ¶ added in v1.13.0
func StartBalancer ¶ added in v1.6.0
func StopBalancer ¶ added in v1.6.0
func UpdateRole ¶ added in v1.12.0
func UpdateUser ¶ added in v1.5.0
UpdateUser recreates user with new name and password should be used only when username was changed
func UpdateUserPass ¶ added in v1.5.0
UpdateUserPass updates user's password
func UpdateUserRoles ¶ added in v1.12.0
Types ¶
type BalancerStatus ¶ added in v1.6.0
type BalancerStatus struct { Mode string `json:"mode"` OKResponse `bson:",inline"` }
type BuildInfo ¶ added in v1.5.0
type BuildInfo struct { Version string `json:"version" bson:"version"` OKResponse `bson:",inline"` }
BuildInfo contains information about mongod build params
type ConfigMember ¶ added in v1.5.0
type ConfigMember 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 int `bson:"priority" json:"priority"` Tags ReplsetTags `bson:"tags,omitempty" json:"tags,omitempty"` SlaveDelay *int64 `bson:"slaveDelay,omitempty" json:"slaveDelay,omitempty"` SecondaryDelaySecs *int64 `bson:"secondaryDelaySecs,omitempty" json:"secondaryDelaySecs,omitempty"` Votes int `bson:"votes" json:"votes"` }
RSMember document from 'replSetGetConfig': https://docs.mongodb.com/manual/reference/command/replSetGetConfig/#dbcmd.replSetGetConfig
func (ConfigMember) String ¶ added in v1.5.0
func (m ConfigMember) String() string
type ConfigMembers ¶ added in v1.5.0
type ConfigMembers []ConfigMember
func (*ConfigMembers) AddNew ¶ added in v1.5.0
func (m *ConfigMembers) AddNew(from ConfigMembers) bool
AddNew adds a new member from given list to the config. It adds only one at a time. Returns true if it adds any member.
func (*ConfigMembers) ExternalNodesChanged ¶ added in v1.10.0
func (m *ConfigMembers) ExternalNodesChanged(compareWith ConfigMembers) bool
ExternalNodesChanged checks if votes or priority fields changed for external nodes
func (*ConfigMembers) FixHosts ¶ added in v1.12.0
func (m *ConfigMembers) FixHosts(compareWith ConfigMembers) (changes bool)
func (*ConfigMembers) FixTags ¶ added in v1.10.0
func (m *ConfigMembers) FixTags(compareWith ConfigMembers) (changes bool)
FixTags corrects the tags of any member if they changed. Especially the "external" tag can change if cluster is switched from unmanaged to managed.
func (*ConfigMembers) RemoveOld ¶ added in v1.5.0
func (m *ConfigMembers) RemoveOld(compareWith ConfigMembers) bool
RemoveOld removes from the list those members which are not present in the given list. It always should leave at least one element. The config won't be valid for mongo otherwise. Better, if the last element has the smallest ID in order not to produce defragmentation when the next element will be added (ID = maxID + 1). Mongo replica set member ID must be between 0 and 255, so it matters.
func (*ConfigMembers) SetVotes ¶ added in v1.5.0
func (m *ConfigMembers) SetVotes(unsafePSA bool)
SetVotes sets voting parameters for members list
type DBList ¶ added in v1.7.0
type DBList struct { DBs []struct { Name string `bson:"name" json:"name"` } `bson:"databases" json:"databases"` OKResponse `bson:",inline"` }
type FCV ¶ added in v1.8.0
type FCV struct { FCV struct { Version string `json:"version" bson:"version"` } `json:"featureCompatibilityVersion" bson:"featureCompatibilityVersion"` OKResponse `bson:",inline"` }
type IsMasterResp ¶ added in v1.10.0
type IsMasterResp struct { IsMaster bool `bson:"ismaster" json:"ismaster"` IsArbiter bool `bson:"arbiterOnly" json:"arbiterOnly"` Msg string `bson:"msg" json:"msg"` OKResponse `bson:",inline"` }
type Member ¶
type Member struct { Id int `bson:"_id" json:"_id"` Name string `bson:"name" json:"name"` Health MemberHealth `bson:"health" json:"health"` State MemberState `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 MemberHealth ¶ added in v1.5.0
type MemberHealth int
type MemberState ¶ added in v1.5.0
type MemberState int
type OKResponse ¶
type OKResponse struct { Errmsg string `bson:"errmsg,omitempty" json:"errmsg,omitempty"` OK int `bson:"ok" json:"ok"` }
OKResponse is a standard MongoDB response
type RSConfig ¶
type RSConfig struct { ID string `bson:"_id" json:"_id"` Version int `bson:"version" json:"version"` Members ConfigMembers `bson:"members" json:"members"` Configsvr bool `bson:"configsvr,omitempty" json:"configsvr,omitempty"` ProtocolVersion int `bson:"protocolVersion,omitempty" json:"protocolVersion,omitempty"` Settings Settings `bson:"settings,omitempty" json:"settings,omitempty"` WriteConcernMajorityJournalDefault bool `bson:"writeConcernMajorityJournalDefault,omitempty" json:"writeConcernMajorityJournalDefault,omitempty"` }
type ReplSetGetConfig ¶
type ReplSetGetConfig struct { Config *RSConfig `bson:"config" json:"config"` OKResponse `bson:",inline"` }
Response document from 'replSetGetConfig': https://docs.mongodb.com/manual/reference/command/replSetGetConfig/#dbcmd.replSetGetConfig
type ReplsetTags ¶
Replica Set tags: https://docs.mongodb.com/manual/tutorial/configure-replica-set-tag-sets/#add-tag-sets-to-a-replica-set
type Role ¶ added in v1.12.0
type Role struct { Role string `bson:"role" json:"role"` Roles []map[string]interface{} `bson:"roles" json:"roles"` Privileges []RolePrivilege `bson:"privileges" json:"privileges"` }
type RoleInfo ¶ added in v1.12.0
type RoleInfo struct { Roles []Role `bson:"roles" json:"roles"` OKResponse `bson:",inline"` }
type RolePrivilege ¶ added in v1.12.0
type Settings ¶
type Settings struct { ChainingAllowed bool `bson:"chainingAllowed,omitempty" json:"chainingAllowed,omitempty"` HeartbeatIntervalMillis int64 `bson:"heartbeatIntervalMillis,omitempty" json:"heartbeatIntervalMillis,omitempty"` HeartbeatTimeoutSecs int `bson:"heartbeatTimeoutSecs,omitempty" json:"heartbeatTimeoutSecs,omitempty"` ElectionTimeoutMillis int64 `bson:"electionTimeoutMillis,omitempty" json:"electionTimeoutMillis,omitempty"` CatchUpTimeoutMillis int64 `bson:"catchUpTimeoutMillis,omitempty" json:"catchUpTimeoutMillis,omitempty"` GetLastErrorModes map[string]ReplsetTags `bson:"getLastErrorModes,omitempty" json:"getLastErrorModes,omitempty"` GetLastErrorDefaults WriteConcern `bson:"getLastErrorDefaults,omitempty" json:"getLastErrorDefaults,omitempty"` ReplicaSetID primitive.ObjectID `bson:"replicaSetId,omitempty" json:"replicaSetId,omitempty"` }
Settings document from 'replSetGetConfig': https://docs.mongodb.com/manual/reference/command/replSetGetConfig/#dbcmd.replSetGetConfig
type ShardList ¶ added in v1.6.0
type ShardList struct { Shards []struct { ID string `json:"_id" bson:"_id"` Host string `json:"host" bson:"host"` State int `json:"state" bson:"state"` } `json:"shards" bson:"shards"` OKResponse `bson:",inline"` }
type ShardRemoveResp ¶ added in v1.7.0
type ShardRemoveResp struct { Msg string `json:"msg" bson:"msg"` State string `json:"state" bson:"state"` Remaining struct { Chunks int `json:"chunks" bson:"chunks"` JumboChunks int `json:"jumboChunks" bson:"jumboChunks"` } `json:"remaining" bson:"remaining"` OKResponse `bson:",inline"` }
func RemoveShard ¶ added in v1.7.0
type Status ¶ added in v1.5.0
type Status struct { Set string `bson:"set" json:"set"` Date time.Time `bson:"date" json:"date"` MyState MemberState `bson:"myState" json:"myState"` Members []*Member `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"` OKResponse `bson:",inline"` }
func (*Status) GetMembersByState ¶ added in v1.5.0
func (s *Status) GetMembersByState(state MemberState, limit int) []*Member
type StatusOptimes ¶ added in v1.5.0
type User ¶ added in v1.12.0
type User struct {
Roles []map[string]interface{} `bson:"roles" json:"roles"`
}
type UsersInfo ¶ added in v1.12.0
type UsersInfo struct { Users []User `bson:"users" json:"users"` OKResponse `bson:",inline"` }
type WriteConcern ¶
type WriteConcern struct { WriteConcern interface{} `bson:"w" json:"w"` WriteTimeout int `bson:"wtimeout" json:"wtimeout"` Journal bool `bson:"j,omitempty" json:"j,omitempty"` }
WriteConcern document: https://docs.mongodb.com/manual/reference/write-concern/