Documentation ¶
Index ¶
- Constants
- Variables
- func CreateRole(ctx context.Context, client *mongo.Client, role string, ...) error
- func CreateUser(ctx context.Context, client *mongo.Client, user, pwd string, ...) error
- func DropUser(ctx context.Context, client *mongo.Client, userName string) error
- func NewCommands() engines.ClusterCommands
- func NewLocalUnauthClient(ctx context.Context) (*mongo.Client, error)
- func NewManager(properties engines.Properties) (engines.DBManager, error)
- func NewMongodbClient(ctx context.Context, config *Config) (*mongo.Client, error)
- func NewMongosClient(ctx context.Context, hosts []string) (*mongo.Client, error)
- func NewReplSetClient(ctx context.Context, hosts []string) (*mongo.Client, error)
- func NewStandaloneClient(ctx context.Context, host string) (*mongo.Client, error)
- func SetReplSetConfig(ctx context.Context, rsClient *mongo.Client, cfg *RSConfig) error
- func UpdateRole(ctx context.Context, client *mongo.Client, role 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
- type BalancerStatus
- type BuildInfo
- type Commands
- type Config
- type ConfigMember
- type ConfigMembers
- type DBList
- type FCV
- type IsMasterResp
- type LockResp
- type Manager
- func (mgr *Manager) CreateRoot(ctx context.Context) error
- func (mgr *Manager) Demote(context.Context) error
- func (mgr *Manager) Follow(ctx context.Context, cluster *dcs.Cluster) error
- func (mgr *Manager) GetHealthiestMember(cluster *dcs.Cluster, candidate string) *dcs.Member
- func (mgr *Manager) GetLeaderClient(ctx context.Context, cluster *dcs.Cluster) (*mongo.Client, error)
- func (mgr *Manager) GetMemberAddrs(ctx context.Context, cluster *dcs.Cluster) []string
- func (mgr *Manager) GetMemberAddrsFromRSConfig(rsConfig *RSConfig) []string
- func (mgr *Manager) GetMemberState(ctx context.Context) (string, error)
- func (mgr *Manager) GetReplSetClient(ctx context.Context, cluster *dcs.Cluster) (*mongo.Client, error)
- func (mgr *Manager) GetReplSetClientWithHosts(ctx context.Context, hosts []string) (*mongo.Client, error)
- func (mgr *Manager) GetReplSetConfig(ctx context.Context) (*RSConfig, error)
- func (mgr *Manager) GetReplSetStatus(ctx context.Context) (*ReplSetStatus, error)
- func (mgr *Manager) GetReplicaRole(ctx context.Context, cluster *dcs.Cluster) (string, error)
- func (mgr *Manager) HasOtherHealthyLeader(ctx context.Context, cluster *dcs.Cluster) *dcs.Member
- func (mgr *Manager) HasOtherHealthyMembers(ctx context.Context, cluster *dcs.Cluster, leader string) []*dcs.Member
- func (mgr *Manager) InitializeCluster(ctx context.Context, cluster *dcs.Cluster) error
- func (mgr *Manager) InitiateReplSet(ctx context.Context, cluster *dcs.Cluster) error
- func (mgr *Manager) IsClusterHealthy(ctx context.Context, cluster *dcs.Cluster) bool
- func (mgr *Manager) IsClusterInitialized(ctx context.Context, cluster *dcs.Cluster) (bool, error)
- func (mgr *Manager) IsCurrentMemberHealthy(ctx context.Context, cluster *dcs.Cluster) bool
- func (mgr *Manager) IsCurrentMemberInCluster(ctx context.Context, cluster *dcs.Cluster) bool
- func (mgr *Manager) IsDBStartupReady() bool
- func (mgr *Manager) IsLeader(ctx context.Context, cluster *dcs.Cluster) (bool, error)
- func (mgr *Manager) IsLeaderMember(ctx context.Context, cluster *dcs.Cluster, dcsMember *dcs.Member) (bool, error)
- func (mgr *Manager) IsMemberHealthy(ctx context.Context, cluster *dcs.Cluster, member *dcs.Member) bool
- func (mgr *Manager) IsPromoted(ctx context.Context) bool
- func (mgr *Manager) IsRootCreated(ctx context.Context) (bool, error)
- func (mgr *Manager) IsRunning() bool
- func (mgr *Manager) JoinCurrentMemberToCluster(ctx context.Context, cluster *dcs.Cluster) error
- func (mgr *Manager) LeaveMemberFromCluster(ctx context.Context, cluster *dcs.Cluster, memberName string) error
- func (mgr *Manager) Lock(ctx context.Context, reason string) error
- func (mgr *Manager) Promote(ctx context.Context, cluster *dcs.Cluster) error
- func (mgr *Manager) Recover(context.Context) error
- func (mgr *Manager) Unlock(ctx context.Context) error
- type Member
- type MemberHealth
- type MemberState
- type OKResponse
- type Optime
- type RSConfig
- type ReplSetGetConfig
- type ReplSetStatus
- type ReplsetTags
- type Role
- type RoleInfo
- type RolePrivilege
- type Settings
- type ShardList
- type ShardRemoveResp
- type StatusOptimes
- type User
- type UsersInfo
- type WriteConcern
Constants ¶
const ( PrimaryPriority = 2 SecondaryPriority = 1 ServiceType = "mongodb" )
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 ¶
func CreateUser ¶
func NewCommands ¶
func NewCommands() engines.ClusterCommands
func NewManager ¶
func NewManager(properties engines.Properties) (engines.DBManager, error)
func NewMongodbClient ¶
func NewMongosClient ¶
func NewReplSetClient ¶
func NewStandaloneClient ¶
func SetReplSetConfig ¶
func UpdateRole ¶
func UpdateUserPass ¶
UpdateUserPass updates user's password
Types ¶
type BalancerStatus ¶
type BalancerStatus struct { Mode string `json:"mode"` OKResponse `bson:",inline"` }
type BuildInfo ¶
type BuildInfo struct { Version string `json:"version" bson:"version"` OKResponse `bson:",inline"` }
BuildInfo contains information about mongod build params
type Commands ¶
type Commands struct {
// contains filtered or unexported fields
}
func (Commands) ConnectCommand ¶
func (Commands) ConnectExample ¶
func (r Commands) ConnectExample(info *engines.ConnectionInfo, client string) string
type Config ¶
type ConfigMember ¶
type ConfigMember struct { ID int `bson:"_id" json:"_id"` Host string `bson:"host" json:"host"` ArbiterOnly *bool `bson:"arbiterOnly,omitempty" json:"arbiterOnly,omitempty"` BuildIndexes *bool `bson:"buildIndexes,omitempty" json:"buildIndexes,omitempty"` Hidden *bool `bson:"hidden,omitempty" json:"hidden,omitempty"` Priority int `bson:"priority,omitempty" json:"priority,omitempty"` 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,omitempty" json:"votes,omitempty"` }
ConfigMember document from 'replSetGetConfig': https://docs.mongodb.com/manual/reference/command/replSetGetConfig/#dbcmd.replSetGetConfig
type ConfigMembers ¶
type ConfigMembers []ConfigMember
type DBList ¶
type DBList struct { DBs []struct { Name string `bson:"name" json:"name"` } `bson:"databases" json:"databases"` OKResponse `bson:",inline"` }
type FCV ¶
type FCV struct { FCV struct { Version string `json:"version" bson:"version"` } `json:"featureCompatibilityVersion" bson:"featureCompatibilityVersion"` OKResponse `bson:",inline"` }
type IsMasterResp ¶
type LockResp ¶
type LockResp struct { Info string `bson:"info" json:"info"` LockCount int64 `bson:"lockCount" json:"lockCount"` OKResponse `bson:",inline"` }
type Manager ¶
var Mgr *Manager
func (*Manager) GetHealthiestMember ¶
func (*Manager) GetLeaderClient ¶
func (*Manager) GetMemberAddrs ¶
func (*Manager) GetMemberAddrsFromRSConfig ¶
func (*Manager) GetMemberState ¶
func (*Manager) GetReplSetClient ¶
func (*Manager) GetReplSetClientWithHosts ¶
func (*Manager) GetReplSetConfig ¶
func (*Manager) GetReplSetStatus ¶
func (mgr *Manager) GetReplSetStatus(ctx context.Context) (*ReplSetStatus, error)
func (*Manager) GetReplicaRole ¶
func (*Manager) HasOtherHealthyLeader ¶
func (*Manager) HasOtherHealthyMembers ¶
func (mgr *Manager) HasOtherHealthyMembers(ctx context.Context, cluster *dcs.Cluster, leader string) []*dcs.Member
HasOtherHealthyMembers Are there any healthy members other than the leader?
func (*Manager) InitializeCluster ¶
func (*Manager) InitiateReplSet ¶
InitiateReplSet is a method to create MongoDB cluster
func (*Manager) IsClusterHealthy ¶
func (*Manager) IsClusterInitialized ¶
IsClusterInitialized is a method to check if cluster is initialized or not
func (*Manager) IsCurrentMemberHealthy ¶
func (*Manager) IsCurrentMemberInCluster ¶
func (*Manager) IsDBStartupReady ¶
func (*Manager) IsLeaderMember ¶
func (*Manager) IsMemberHealthy ¶
func (*Manager) IsRootCreated ¶
func (*Manager) JoinCurrentMemberToCluster ¶
func (*Manager) LeaveMemberFromCluster ¶
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 ¶
type MemberHealth int
type MemberState ¶
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,omitempty" json:"_id,omitempty"` Version int `bson:"version,omitempty" json:"version,omitempty"` 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:"-" 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"` }
ReplSetGetConfig Response document from 'replSetGetConfig': https://docs.mongodb.com/manual/reference/command/replSetGetConfig/#dbcmd.replSetGetConfig
type ReplSetStatus ¶
type ReplSetStatus 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 GetReplSetStatus ¶
func (*ReplSetStatus) GetMembersByState ¶
func (s *ReplSetStatus) GetMembersByState(state MemberState, limit int) []*Member
func (*ReplSetStatus) GetSelf ¶
func (s *ReplSetStatus) GetSelf() *Member
func (*ReplSetStatus) Primary ¶
func (s *ReplSetStatus) Primary() *Member
type ReplsetTags ¶
ReplsetTags Set tags: https://docs.mongodb.com/manual/tutorial/configure-replica-set-tag-sets/#add-tag-sets-to-a-replica-set
type Role ¶
type Role struct { Role string `bson:"role" json:"role"` DB string `bson:"db" json:"db"` IsBuiltin string `bson:"isBuiltin" json:"isBuiltin"` Roles []map[string]interface{} `bson:"roles" json:"roles"` Privileges []RolePrivilege `bson:"privileges" json:"privileges"` }
type RoleInfo ¶
type RoleInfo struct { Roles []Role `bson:"roles" json:"roles"` OKResponse `bson:",inline"` }
type RolePrivilege ¶
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 ¶
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 ¶
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"` }
type StatusOptimes ¶
type User ¶
type UsersInfo ¶
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/