helpers

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2021 License: Apache-2.0 Imports: 33 Imported by: 1

Documentation

Index

Constants

View Source
const (
	LocalDB   = "local"
	OplogColl = "oplog.rs"
	AdminDB   = "admin"
)
View Source
const (
	S3PORT = 9000
)

Variables

View Source
var Docker *client.Client
View Source
var (
	SystemDatabases = []string{"local", "config", "admin"}
)

Functions

func BackupNameFromCreate

func BackupNameFromCreate(output string) string

func BackupNamesFromListing

func BackupNamesFromListing(output string) []string

func BuildImage

func BuildImage(ctx context.Context, tag string, path string) error

func ContainerWithPrefix

func ContainerWithPrefix(containers []types.Container, name string) (*types.Container, error)

func CreateNet

func CreateNet(ctx context.Context, netName string) error

func DockerContainer

func DockerContainer(ctx context.Context, prefix string) (*types.Container, error)

func ExposedHostPort

func ExposedHostPort(ctx context.Context, fqdn string, port int) (string, int, error)

func ExposedPort

func ExposedPort(container types.Container, port int) (string, int, error)

func FetchAllDocs

func FetchAllDocs(ctx context.Context, cur *mongo.Cursor) ([]bson.M, error)

func FetchNsDocs

func FetchNsDocs(ctx context.Context, conn *mongo.Client, database, table string) ([]bson.M, error)

func LessTS

func LessTS(ots1, ots2 OpTimestamp) bool

func ListCollections

func ListCollections(ctx context.Context, conn *mongo.Client, database string) ([]bson.M, error)

func ListNets

func ListNets(ctx context.Context, name string) ([]types.NetworkResource, error)

func ListNsIndexes

func ListNsIndexes(ctx context.Context, conn *mongo.Client, database, table string) ([]bson.M, error)

func RemoveNet

func RemoveNet(ctx context.Context, netName string) error

func Retry

func Retry(ctx context.Context, maxRetries uint64, op func() error) error

func TimeInContainer

func TimeInContainer(ctx context.Context, container string) (time.Time, error)

Types

type Archive

type Archive struct {
	StartTS OpTimestamp
	EndTS   OpTimestamp
}

type AuthCreds

type AuthCreds struct {
	Username string
	Password string
	Database string
}

AuthCreds ...

func AdminCredsFromEnv

func AdminCredsFromEnv(env map[string]string) AuthCreds

type BackupMeta

type BackupMeta struct {
	Before NodeMeta `json:"Before,omitempty"`
	After  NodeMeta `json:"After,omitempty"`
}

type BaseImage

type BaseImage struct {
	Path string
	Tag  string
}

type CmdResponse

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

type DatabaseRecord

type DatabaseRecord struct {
	Timestamp int64
	IntNum    int
	Str       string
}

type ExecResult

type ExecResult struct {
	ExitCode int
	// contains filtered or unexported fields
}

func RunCommand

func RunCommand(ctx context.Context,
	container string, cmd []string, setters ...RunOption) (ExecResult, error)

func RunCommandStrict

func RunCommandStrict(ctx context.Context, container string, command []string) (ExecResult, error)

func (*ExecResult) Combined

func (res *ExecResult) Combined() string

func (*ExecResult) Stderr

func (res *ExecResult) Stderr() string

func (*ExecResult) Stdout

func (res *ExecResult) Stdout() string

func (*ExecResult) String

func (res *ExecResult) String() string

type Infra

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

func NewInfra

func NewInfra(ctx context.Context,
	config string, env map[string]string, net string, base BaseImage) *Infra

func (*Infra) RecreateContainers

func (inf *Infra) RecreateContainers() error

func (*Infra) Setup

func (inf *Infra) Setup() error

func (*Infra) Shutdown

func (inf *Infra) Shutdown() error

type IsMaster

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

IsMaster ...

type IsMasterLastWrite

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

IsMasterLastWrite ...

type MongoCtl

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

func NewMongoCtl

func NewMongoCtl(ctx context.Context, host string, setters ...MongoCtlOpt) (*MongoCtl, error)

func (*MongoCtl) AdminConnect

func (mc *MongoCtl) AdminConnect() (*mongo.Client, error)

func (*MongoCtl) Connect

func (mc *MongoCtl) Connect(creds *AuthCreds) (*mongo.Client, error)

func (*MongoCtl) EnableAuth

func (mc *MongoCtl) EnableAuth() error

func (*MongoCtl) InitReplSet

func (mc *MongoCtl) InitReplSet() error

func (*MongoCtl) IsMaster

func (mc *MongoCtl) IsMaster() (bool, error)

func (*MongoCtl) LastMajTS

func (mc *MongoCtl) LastMajTS() (OpTimestamp, error)

func (*MongoCtl) LastTS

func (mc *MongoCtl) LastTS() (OpTimestamp, error)

func (*MongoCtl) PurgeDatadir

func (mc *MongoCtl) PurgeDatadir() error

func (*MongoCtl) Snapshot

func (mc *MongoCtl) Snapshot() ([]NsSnapshot, error)

func (*MongoCtl) WriteTestData

func (mc *MongoCtl) WriteTestData(mark string, dbCount, tablesCount, docsCount int) error

type MongoCtlOpt

type MongoCtlOpt func(*MongoCtl)

func AdminCreds

func AdminCreds(creds AuthCreds) MongoCtlOpt

func Port

func Port(port int) MongoCtlOpt

type NodeMeta

type NodeMeta struct {
	LastTS    OpTimestamp `json:"LastTS,omitempty"`
	LastMajTS OpTimestamp `json:"LastMajTS,omitempty"`
}

type NsSnapshot

type NsSnapshot struct {
	NS      string
	Type    string
	Options bson.M
	IdIndex bson.M
	Docs    []bson.M
	Indexes []bson.M
}

type OpTime

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

Optime ...

type OpTimestamp

type OpTimestamp struct {
	TS  uint32
	Inc uint32
}

func TimestampFromStr

func TimestampFromStr(s string) (OpTimestamp, error)

func (OpTimestamp) String

func (ots OpTimestamp) String() string

type RedisCtl added in v1.1.1

type RedisCtl struct {
	*redis.Client
	// contains filtered or unexported fields
}

func NewRedisCtl added in v1.1.1

func NewRedisCtl(ctx context.Context, host string, port int, password, binPath, confPath string) (*RedisCtl, error)

func (*RedisCtl) Addr added in v1.1.1

func (rc *RedisCtl) Addr() string

func (*RedisCtl) Host added in v1.1.1

func (rc *RedisCtl) Host() string

func (*RedisCtl) PurgeRetain added in v1.1.1

func (rc *RedisCtl) PurgeRetain(keepNumber int) error

func (*RedisCtl) PushBackup added in v1.1.1

func (rc *RedisCtl) PushBackup() (string, error)

func (*RedisCtl) WriteTestData added in v1.1.1

func (rc *RedisCtl) WriteTestData(mark string, docsCount int) error

type RunOption

type RunOption func(*RunOptions)

func User

func User(user string) RunOption

type RunOptions

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

type S3Client

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

func NewS3Client

func NewS3Client(conf aws.Config, bucket string) (*S3Client, error)

func (*S3Client) FileContents

func (cl *S3Client) FileContents(key string) ([]byte, error)

func (*S3Client) List

func (cl *S3Client) List(path string) ([]string, error)

type S3Storage

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

func NewS3Storage

func NewS3Storage(ctx context.Context, host, bucket, access, secret string) *S3Storage

func (*S3Storage) ArchTsExists

func (s *S3Storage) ArchTsExists(ts OpTimestamp) (bool, error)

func (*S3Storage) Archives

func (s *S3Storage) Archives() ([]Archive, error)

func (*S3Storage) Client

func (s *S3Storage) Client() (*S3Client, error)

func (*S3Storage) InitMinio

func (s *S3Storage) InitMinio() error

type Sentinel

type Sentinel struct {
	StartLocalTime  time.Time   `json:"StartLocalTime,omitempty"`
	FinishLocalTime time.Time   `json:"FinishLocalTime,omitempty"`
	UserData        interface{} `json:"UserData,omitempty"`
	MongoMeta       BackupMeta  `json:"MongoMeta,omitempty"`
}

type Strings added in v1.1.1

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

type WalgUtil

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

func NewWalgUtil

func NewWalgUtil(ctx context.Context, host, cliPath, confPath, mongoMaj string) *WalgUtil

func (*WalgUtil) BackupMeta

func (w *WalgUtil) BackupMeta(backupNum int) (Sentinel, error)

func (*WalgUtil) Backups

func (w *WalgUtil) Backups() ([]string, error)

func (*WalgUtil) DeleteBackup added in v0.2.17

func (w *WalgUtil) DeleteBackup(backupName string) error

func (*WalgUtil) FetchBackupByNum

func (w *WalgUtil) FetchBackupByNum(backupNum int) error

func (*WalgUtil) OplogPurge added in v0.2.17

func (w *WalgUtil) OplogPurge() error

func (*WalgUtil) OplogPush

func (w *WalgUtil) OplogPush() error

func (*WalgUtil) OplogReplay

func (w *WalgUtil) OplogReplay(from, until OpTimestamp) error

func (*WalgUtil) PurgeRetain

func (w *WalgUtil) PurgeRetain(keepNumber int) error

func (*WalgUtil) PushBackup

func (w *WalgUtil) PushBackup() (string, error)

Jump to

Keyboard shortcuts

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