mongo

package
v0.0.0-...-3d827b6 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCollectionName     = "masterlock"
	DefaultHeartbeatFrequency = time.Second * 5

	MgoSessionRefreshFreq = time.Minute * 5
	DefaultPoolLimit      = 4
)
View Source
const MasterInfoID = "there-is-only-one-of-these"

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoBackend

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

func New

func (*MongoBackend) Connect

func (m *MongoBackend) Connect() error

func (*MongoBackend) Lock

func (m *MongoBackend) Lock(info *backend.MasterInfo) error

Achieve a lock to become the master. If lock is successful, the provided MasterInfo will be filled out and recorded. The MasterInfo passed in will be filled out with the remaining details.

func (*MongoBackend) Status

func (m *MongoBackend) Status() (*backend.MasterInfo, error)

Get the current master status. Provides the MasterInfo of the current master.

func (*MongoBackend) UnLock

func (m *MongoBackend) UnLock(masterID string) error

Release the lock to relinquish the master role. This will not succeed if the provided masterID does not match the ID of the current master.

func (*MongoBackend) WriteHeartbeat

func (m *MongoBackend) WriteHeartbeat(info *backend.MasterInfo) error

Write a heartbeat to ensure that the master role is not lost. If successful, the last heartbeat time is written to the passed MasterInfo

type MongoBackendConfig

type MongoBackendConfig struct {
	// Optional: What collection will the lock be stored in (default: "masterlock")
	CollectionName string

	// Required: Mongo connection config
	ConnectConfig *MongoConnectConfig

	// Optional: Frequency of master heartbeat write
	HeartBeatFreq time.Duration

	// Optional: Logger for the mongo backend to use (default: new logrus shim will be created)
	Logger log.Logger
}

type MongoConnectConfig

type MongoConnectConfig struct {
	Hosts         []string
	Name          string
	ReplicaSet    string
	Source        string
	User          string
	Password      string
	Timeout       time.Duration
	UseSSL        bool
	PoolLimit     int
	MaxIdleTimeMS int
}

type MongoMasterInfo

type MongoMasterInfo struct {
	ID            string    `bson:"_id"`
	MasterID      string    `bson:"master_id"`
	Version       string    `bson:"version"`
	StartedAt     time.Time `bson:"started_at"`
	LastHeartbeat time.Time `bson:"last_heartbeat"`
}

type RWLocker

type RWLocker interface {
	RLock()
	RUnlock()
	Lock()
	Unlock()
}

type SmartCollection

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

func (*SmartCollection) Collection

func (s *SmartCollection) Collection() *mgo.Collection

func (*SmartCollection) EnsureIndexes

func (s *SmartCollection) EnsureIndexes(idxs []*mgo.Index) error

func (*SmartCollection) StartMongoDatastoreSegment

func (s *SmartCollection) StartMongoDatastoreSegment(txn newrelic.Transaction, op string, query map[string]interface{}) *newrelic.DatastoreSegment

func (*SmartCollection) UpsertIndex

func (s *SmartCollection) UpsertIndex(idx *mgo.Index) error

Ensure new index. If index already exists with same options, remove it and add new one.

Jump to

Keyboard shortcuts

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