client

package
v0.0.0-...-86c6960 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OplogAppModes = map[OplogAppMode]struct{}{
		OplogAppModeInitSync:   {},
		OplogAppModeRecovering: {},
		OplogAppModeSecondary:  {},
	}
)

Functions

func WaitForBecomePrimary

func WaitForBecomePrimary(ctx context.Context, mc *MongoClient, checkTimeout time.Duration) error

WaitForBecomePrimary waits until mongo client connection node becomes primary

Types

type ApplyOplog

type ApplyOplog struct {
	Operation  string            `bson:"op"`
	Namespace  string            `bson:"ns"`
	Object     bson.D            `bson:"o"`
	Query      bson.D            `bson:"o2,omitempty"`
	UI         *primitive.Binary `bson:"ui,omitempty"`
	LSID       bson.Raw          `bson:"lsid,omitempty"`
	TxnNumber  *int64            `bson:"txnNumber,omitempty"`
	PrevOpTime bson.Raw          `bson:"prevOpTime,omitempty"`
}

ApplyOplog is used to replay oplog entry.

type BsonCursor

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

BsonCursor implements OplogCursor with source io.reader

func NewBsonCursor

func NewBsonCursor(r io.Reader) *BsonCursor

NewMongoOplogCursor builds MongoOplogCursor.

func (*BsonCursor) Close

func (b *BsonCursor) Close(ctx context.Context) error

Close closes this cursor.

func (*BsonCursor) Data

func (b *BsonCursor) Data() []byte

Data returns current cursor document.

func (*BsonCursor) Err

func (b *BsonCursor) Err() error

Err returns the last error.

func (*BsonCursor) Next

func (b *BsonCursor) Next(ctx context.Context) bool

Next gets the next document for this cursor, returns true if there were no errors.

func (*BsonCursor) Push

func (b *BsonCursor) Push(data []byte) error

Push returns document back to cursor

type CmdResponse

type CmdResponse struct {
	Ok     int    `bson:"ok"`
	ErrMsg string `bson:"errmsg, omitempty"`
}

CmdResponse is used to unmarshal mongodb cmd responses

type IndexDocument

type IndexDocument struct {
	Options                 bson.M `bson:",inline"`
	Key                     bson.D `bson:"key"`
	PartialFilterExpression bson.D `bson:"partialFilterExpression,omitempty"`
}

IndexDocument holds information about a collection's index.

type IsMaster

type IsMaster struct {
	IsMaster  bool              `bson:"ismaster"`
	LastWrite IsMasterLastWrite `bson:"lastWrite"`
}

IsMaster is used to unmarshal results of IsMaster command

type IsMasterLastWrite

type IsMasterLastWrite struct {
	OpTime         OpTime `bson:"opTime"`
	MajorityOpTime OpTime `bson:"majorityOpTime"`
}

IsMasterLastWrite ...

type MongoClient

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

MongoClient implements MongoDriver

func NewMongoClient

func NewMongoClient(ctx context.Context, uri string, setters ...Option) (*MongoClient, error)

NewMongoClient builds MongoClient

func (*MongoClient) ApplyOp

func (mc *MongoClient) ApplyOp(ctx context.Context, dbop db.Oplog) error

ApplyOp calls applyOps and check response

func (*MongoClient) Close

func (mc *MongoClient) Close(ctx context.Context) error

Close disconnects from mongodb

func (*MongoClient) CreateIndexes

func (mc *MongoClient) CreateIndexes(ctx context.Context, dbName, collName string, indexes []IndexDocument) error

func (*MongoClient) EnsureIsMaster

func (mc *MongoClient) EnsureIsMaster(ctx context.Context) error

func (*MongoClient) IsMaster

func (mc *MongoClient) IsMaster(ctx context.Context) (models.IsMaster, error)

func (*MongoClient) LastWriteTS

func (mc *MongoClient) LastWriteTS(ctx context.Context) (lastTS, lastMajTS models.Timestamp, err error)

LastWriteTS fetches timestamps with last write TODO: support non-replset setups

func (*MongoClient) TailOplogFrom

func (mc *MongoClient) TailOplogFrom(ctx context.Context, from models.Timestamp) (OplogCursor, error)

TailOplogFrom gives OplogCursor to tail oplog from

type MongoDriver

type MongoDriver interface {
	CreateIndexes(ctx context.Context, dbName, collName string, indexes []IndexDocument) error
	EnsureIsMaster(ctx context.Context) error
	IsMaster(ctx context.Context) (models.IsMaster, error)
	LastWriteTS(ctx context.Context) (lastTS, lastMajTS models.Timestamp, err error)
	TailOplogFrom(ctx context.Context, from models.Timestamp) (OplogCursor, error)
	ApplyOp(ctx context.Context, op db.Oplog) error
	Close(ctx context.Context) error
}

MongoDriver defines methods to work with mongodb.

type MongoOplogCursor

type MongoOplogCursor struct {
	*mongo.Cursor
	// contains filtered or unexported fields
}

MongoOplogCursor implements OplogCursor.

func NewMongoOplogCursor

func NewMongoOplogCursor(c *mongo.Cursor) *MongoOplogCursor

NewMongoOplogCursor builds MongoOplogCursor.

func (*MongoOplogCursor) Data

func (m *MongoOplogCursor) Data() []byte

Data returns current cursor document

func (*MongoOplogCursor) Next

func (m *MongoOplogCursor) Next(ctx context.Context) bool

Next fills Current by next document, returns true if there were no errors and the cursor has not been exhausted.

func (*MongoOplogCursor) Push

func (m *MongoOplogCursor) Push(data []byte) error

Push returns document back to cursor

type OpTime

type OpTime struct {
	TS   primitive.Timestamp `bson:"ts" json:"ts"`
	Term int64               `bson:"t" json:"t"`
}

Optime ...

type OplogAppMode

type OplogAppMode string
const (
	OplogAppModeInitSync   OplogAppMode = "InitialSync"
	OplogAppModeRecovering OplogAppMode = "Recovering"
	OplogAppModeSecondary  OplogAppMode = "Secondary"
)

type OplogCursor

type OplogCursor interface {
	Close(ctx context.Context) error
	Data() []byte
	Err() error
	Next(context.Context) bool
	Push([]byte) error
}

OplogCursor defines methods to work with mongodb cursor.

type Option

type Option func(*Options)

func OplogAlwaysUpsert

func OplogAlwaysUpsert(alwaysUpsert bool) Option

OplogAlwaysUpsert sets applyOps argument alwaysUpsert

func OplogApplicationMode

func OplogApplicationMode(mode OplogAppMode) Option

OplogAlwaysUpsert sets applyOps argument oplogApplicationMode

type Options

type Options struct {
	OplogApplicationMode *OplogAppMode
	OplogAlwaysUpsert    *bool
}

Options defines mongo client options

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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