Documentation ¶
Index ¶
- Variables
- func WaitForBecomePrimary(ctx context.Context, mc *MongoClient, checkTimeout time.Duration) error
- type ApplyOplog
- type BsonCursor
- type CmdResponse
- type IndexDocument
- type IsMaster
- type IsMasterLastWrite
- type MongoClient
- func (mc *MongoClient) ApplyOp(ctx context.Context, dbop db.Oplog) error
- func (mc *MongoClient) Close(ctx context.Context) error
- func (mc *MongoClient) CreateIndexes(ctx context.Context, dbName, collName string, indexes []IndexDocument) error
- func (mc *MongoClient) EnsureIsMaster(ctx context.Context) error
- func (mc *MongoClient) IsMaster(ctx context.Context) (models.IsMaster, error)
- func (mc *MongoClient) LastWriteTS(ctx context.Context) (lastTS, lastMajTS models.Timestamp, err error)
- func (mc *MongoClient) TailOplogFrom(ctx context.Context, from models.Timestamp) (OplogCursor, error)
- type MongoDriver
- type MongoOplogCursor
- type OpTime
- type OplogAppMode
- type OplogCursor
- type Option
- type Options
Constants ¶
This section is empty.
Variables ¶
var ( OplogAppModes = map[OplogAppMode]struct{}{ OplogAppModeInitSync: {}, OplogAppModeRecovering: {}, OplogAppModeSecondary: {}, } )
Functions ¶
func WaitForBecomePrimary ¶
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) 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 ¶
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 ¶
NewMongoClient builds MongoClient
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) 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 ¶
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 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 ¶
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