Documentation ¶
Index ¶
Constants ¶
const Unknown = 0
Unknown is an unknown server or topology kind.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SelectedServer ¶
type SelectedServer struct { Server Kind TopologyKind }
SelectedServer augments the Server type by also including the TopologyKind of the topology that includes the server. This type should be used to track the state of a server that was selected to perform an operation.
type Server ¶
type Server struct { Addr address.Address Arbiters []string AverageRTT time.Duration AverageRTTSet bool Compression []string // compression methods returned by server CanonicalAddr address.Address ElectionID primitive.ObjectID HeartbeatInterval time.Duration HelloOK bool Hosts []string LastError error LastUpdateTime time.Time LastWriteTime time.Time MaxBatchCount uint32 MaxDocumentSize uint32 MaxMessageSize uint32 Members []address.Address Passives []string Passive bool Primary address.Address ReadOnly bool ServiceID *primitive.ObjectID // Only set for servers that are deployed behind a load balancer. SessionTimeoutMinutes uint32 SetName string SetVersion uint32 Tags tag.Set TopologyVersion *TopologyVersion Kind ServerKind WireVersion *VersionRange }
Server contains information about a node in a cluster. This is created from hello command responses. If the value of the Kind field is LoadBalancer, only the Addr and Kind fields will be set. All other fields will be set to the zero value of the field's type.
func NewDefaultServer ¶
NewDefaultServer creates a new unknown server description with the given address.
func NewServerFromError ¶
func NewServerFromError(addr address.Address, err error, tv *TopologyVersion) Server
NewServerFromError creates a new unknown server description with the given parameters.
func (Server) DataBearing ¶
DataBearing returns true if the server is a data bearing server.
func (Server) LoadBalanced ¶ added in v1.6.0
LoadBalanced returns true if the server is a load balancer or is behind a load balancer.
func (Server) SetAverageRTT ¶
SetAverageRTT sets the average round trip time for this server description.
type ServerKind ¶
type ServerKind uint32
ServerKind represents the type of a single server in a topology.
const ( Standalone ServerKind = 1 RSMember ServerKind = 2 RSPrimary ServerKind = 4 + RSMember RSSecondary ServerKind = 8 + RSMember RSArbiter ServerKind = 16 + RSMember RSGhost ServerKind = 32 + RSMember Mongos ServerKind = 256 LoadBalancer ServerKind = 512 )
These constants are the possible types of servers.
func (ServerKind) String ¶
func (kind ServerKind) String() string
String returns a stringified version of the kind or "Unknown" if the kind is invalid.
type ServerSelector ¶
ServerSelector is an interface implemented by types that can perform server selection given a topology description and list of candidate servers. The selector should filter the provided candidates list and return a subset that matches some criteria.
func CompositeSelector ¶
func CompositeSelector(selectors []ServerSelector) ServerSelector
CompositeSelector combines multiple selectors into a single selector by applying them in order to the candidates list.
For example, if the initial candidates list is [s0, s1, s2, s3] and two selectors are provided where the first matches s0 and s1 and the second matches s1 and s2, the following would occur during server selection:
1. firstSelector([s0, s1, s2, s3]) -> [s0, s1] 2. secondSelector([s0, s1]) -> [s1]
The final list of candidates returned by the composite selector would be [s1].
func LatencySelector ¶
func LatencySelector(latency time.Duration) ServerSelector
LatencySelector creates a ServerSelector which selects servers based on their average RTT values.
func OutputAggregateSelector ¶ added in v1.8.0
func OutputAggregateSelector(rp *readpref.ReadPref) ServerSelector
OutputAggregateSelector selects servers based on the provided read preference given that the underlying operation is aggregate with an output stage.
func ReadPrefSelector ¶
func ReadPrefSelector(rp *readpref.ReadPref) ServerSelector
ReadPrefSelector selects servers based on the provided read preference.
func WriteSelector ¶
func WriteSelector() ServerSelector
WriteSelector selects all the writable servers.
type ServerSelectorFunc ¶
ServerSelectorFunc is a function that can be used as a ServerSelector.
func (ServerSelectorFunc) SelectServer ¶
func (ssf ServerSelectorFunc) SelectServer(t Topology, s []Server) ([]Server, error)
SelectServer implements the ServerSelector interface.
type Topology ¶
type Topology struct { Servers []Server SetName string Kind TopologyKind SessionTimeoutMinutes uint32 CompatibilityErr error }
Topology contains information about a MongoDB cluster.
func (Topology) Equal ¶
Equal compares two topology descriptions and returns true if they are equal.
func (Topology) HasReadableServer ¶
HasReadableServer returns true if the topology contains a server suitable for reading.
If the Topology's kind is Single or Sharded, the mode parameter is ignored and the function contains true if any of the servers in the Topology are of a known type.
For replica sets, the function returns true if the cluster contains a server that matches the provided read preference mode.
func (Topology) HasWritableServer ¶
HasWritableServer returns true if a topology has a server available for writing.
If the Topology's kind is Single or Sharded, this function returns true if any of the servers in the Topology are of a known type.
For replica sets, the function returns true if the replica set contains a primary.
type TopologyKind ¶
type TopologyKind uint32
TopologyKind represents a specific topology configuration.
const ( Single TopologyKind = 1 ReplicaSet TopologyKind = 2 ReplicaSetNoPrimary TopologyKind = 4 + ReplicaSet ReplicaSetWithPrimary TopologyKind = 8 + ReplicaSet Sharded TopologyKind = 256 LoadBalanced TopologyKind = 512 )
These constants are the available topology configurations.
func (TopologyKind) String ¶
func (kind TopologyKind) String() string
String implements the fmt.Stringer interface.
type TopologyVersion ¶
TopologyVersion represents a software version.
func NewTopologyVersion ¶
func NewTopologyVersion(doc bson.Raw) (*TopologyVersion, error)
NewTopologyVersion creates a TopologyVersion based on doc
func (*TopologyVersion) CompareToIncoming ¶
func (tv *TopologyVersion) CompareToIncoming(responseTV *TopologyVersion) int
CompareToIncoming compares the receiver, which represents the currently known TopologyVersion for a server, to an incoming TopologyVersion extracted from a server command response.
This returns -1 if the receiver version is less than the response, 0 if the versions are equal, and 1 if the receiver version is greater than the response. This comparison is not commutative.
type VersionRange ¶
VersionRange represents a range of versions.
func NewVersionRange ¶
func NewVersionRange(min, max int32) VersionRange
NewVersionRange creates a new VersionRange given a min and a max.
func (*VersionRange) Equals ¶
func (vr *VersionRange) Equals(other *VersionRange) bool
Equals returns a bool indicating whether the supplied VersionRange is equal.
func (VersionRange) Includes ¶
func (vr VersionRange) Includes(v int32) bool
Includes returns a bool indicating whether the supplied integer is included in the range.
func (VersionRange) String ¶
func (vr VersionRange) String() string
String implements the fmt.Stringer interface.