replicaset

package
v0.0.0-...-65247a5 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2014 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StartupState = iota
	PrimaryState
	SecondaryState
	RecoveringState
	FatalState
	Startup2State
	UnknownState
	ArbiterState
	DownState
	RollbackState
	ShunnedState
)
View Source
const MaxPeers = 7

MaxPeers defines the maximum number of peers that mongo supports.

Variables

This section is empty.

Functions

func Add

func Add(session *mgo.Session, members ...Member) error

Add adds the given members to the session's replica set. Duplicates of existing replicas will be ignored.

Members will have their Ids set automatically if they are not already > 0

func Initiate

func Initiate(session *mgo.Session, address, name string) error

Initiate sets up a replica set with the given replica set name with the single given member. It need be called only once for a given mongo replica set.

Note that you must set DialWithInfo and set Direct = true when dialing into a specific non-initiated mongo server. The session will be set to Monotonic mode.

See http://docs.mongodb.org/manual/reference/method/rs.initiate/ for more details.

func Remove

func Remove(session *mgo.Session, addrs ...string) error

Remove removes members with the given addresses from the replica set. It is not an error to remove addresses of non-existent replica set members.

func Set

func Set(session *mgo.Session, members []Member) error

Set changes the current set of replica set members. Members will have their ids set automatically if their ids are not already > 0.

Types

type Config

type Config struct {
	Name    string   `bson:"_id"`
	Version int      `bson:"version"`
	Members []Member `bson:"members"`
}

Config is the document stored in mongodb that defines the servers in the replica set

func CurrentConfig

func CurrentConfig(session *mgo.Session) (*Config, error)

CurrentConfig returns the Config for the given session's replica set.

type IsMasterResults

type IsMasterResults struct {
	// The following fields hold information about the specific mongodb node.
	IsMaster  bool      `bson:"ismaster"`
	Secondary bool      `bson:"secondary"`
	Arbiter   bool      `bson:"arbiterOnly"`
	Address   string    `bson:"me"`
	LocalTime time.Time `bson:"localTime"`

	// The following fields hold information about the replica set.
	ReplicaSetName string   `bson:"setName"`
	Addresses      []string `bson:"hosts"`
	Arbiters       []string `bson:"arbiters"`
	PrimaryAddress string   `bson:"primary"`
}

Config reports information about the configuration of a given mongo node

func IsMaster

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

IsMaster returns information about the configuration of the node that the given session is connected to.

type Member

type Member struct {
	// Id is a unique id for a member in a set.
	Id int `bson:"_id"`

	// Address holds the network address of the member,
	// in the form hostname:port.
	Address string `bson:"host"`

	// Arbiter holds whether the member is an arbiter only.
	// This value is optional; it defaults to false.
	Arbiter *bool `bson:"arbiterOnly,omitempty"`

	// BuildIndexes determines whether the mongod builds indexes on this member.
	// This value is optional; it defaults to true.
	BuildIndexes *bool `bson:"buildIndexes,omitempty"`

	// Hidden determines whether the replica set hides this member from
	// the output of IsMaster.
	// This value is optional; it defaults to false.
	Hidden *bool `bson:"hidden,omitempty"`

	// Priority determines eligibility of a member to become primary.
	// This value is optional; it defaults to 1.
	Priority *float64 `bson:"priority,omitempty"`

	// Tags store additional information about a replica member, often used for
	// customizing read preferences and write concern.
	Tags map[string]string `bson:"tags,omitempty"`

	// SlaveDelay describes the number of seconds behind the master that this
	// replica set member should lag rounded up to the nearest second.
	// This value is optional; it defaults to 0.
	SlaveDelay *time.Duration `bson:"slaveDelay,omitempty"`

	// Votes controls the number of votes a server has in a replica set election.
	// This value is optional; it defaults to 1.
	Votes *int `bson:"votes,omitempty"`
}

Member holds configuration information for a replica set member.

See http://docs.mongodb.org/manual/reference/replica-configuration/ for more details

func CurrentMembers

func CurrentMembers(session *mgo.Session) ([]Member, error)

CurrentMembers returns the current members of the replica set.

type MemberState

type MemberState int

MemberState represents the state of a replica set member. See http://docs.mongodb.org/manual/reference/replica-states/

func (MemberState) String

func (state MemberState) String() string

String returns a string describing the state.

type MemberStatus

type MemberStatus struct {
	// Id holds the replica set id of the member that the status is describing.
	Id int `bson:"_id"`

	// Address holds address of the member that the status is describing.
	Address string `bson:"name"`

	// Self holds whether this is the status for the member that
	// the session is connected to.
	Self bool `bson:"self"`

	// ErrMsg holds the most recent error or status message received
	// from the member.
	ErrMsg string `bson:"errmsg"`

	// Healthy reports whether the member is up. It is true for the
	// member that the request was made to.
	Healthy bool `bson:"health"`

	// State describes the current state of the member.
	State MemberState `bson:"state"`

	// Uptime describes how long the member has been online.
	Uptime time.Duration `bson:"uptime"`

	// Ping describes the length of time a round-trip packet takes to travel
	// between the remote member and the local instance.  It is zero for the
	// member that the session is connected to.
	Ping time.Duration `bson:"pingMS"`
}

Status holds the status of a replica set member returned from replSetGetStatus.

type Status

type Status struct {
	Name    string         `bson:"set"`
	Members []MemberStatus `bson:"members"`
}

Status holds data about the status of members of the replica set returned from replSetGetStatus

See http://docs.mongodb.org/manual/reference/command/replSetGetStatus/#dbcmd.replSetGetStatus

func CurrentStatus

func CurrentStatus(session *mgo.Session) (*Status, error)

CurrentStatus returns the status of the replica set for the given session.

Jump to

Keyboard shortcuts

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