src

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectDb

func ConnectDb(uri string) *mongo.Client

func Copy

func Copy(cfg *RootConfig, dbc *DBConnector, cmd *cobra.Command)

func CopyHandler

func CopyHandler(cmd *cobra.Command, args []string)

func DocExistsAndMatch

func DocExistsAndMatch(dst *mongo.Collection, doc bson.D) (bool, bool)

func Execute

func Execute()

func GenerateConfig

func GenerateConfig(cmd *cobra.Command, sourceUri string, destinationUri string)

func SaveConfig

func SaveConfig(cfg RootConfig)

func StatusWorker

func StatusWorker(c *Counters, quit chan bool, refresh_rate int, state *WorkerState, cfg *RootConfig)

Types

type ColConfig

type ColConfig struct {
	Name                  string `yaml:"name"`
	RenameTo              string `yaml:"rename_to"`
	BatchSize             int    `yaml:"batch_size"`
	Enabled               bool   `yaml:"enabled"`
	SourceBatchSize       int    `yaml:"source_batch_size"`
	UseSeparateConnection bool   `yaml:"use_separate_connection"`
	UseMultipleWorkers    bool   `yaml:"use_multiple_workers"`
	WorkerCount           int    `yaml:"worker_count"`
	MaxDocsInMemory       int    `yaml:"max_docs_in_memory"`
	NoFind                bool   `yaml:"no_find"`
	DateFilterField       string `yaml:"filter_field"`
	DateFilterFrom        string `yaml:"filter_from"` // format: 2006-01-02 15:04:05
	DateFilterEnabled     bool   `yaml:"filter_enabled"`
}

func GenerateColConfig

func GenerateColConfig(colName string, dbName string, conn *mongo.Client) ColConfig

func GetBaseColConfig

func GetBaseColConfig() ColConfig

type ColCopyWorker

type ColCopyWorker struct {
	SRC         *mongo.Collection
	Clients     []*mongo.Client
	SRCDocCount int64
	DST         *mongo.Collection
	DBName      string
	ColName     string
	Done        bool
	Logs        []string
	Config      *ColConfig
	BatchSize   int
	Errors      []interface{}
}

func (*ColCopyWorker) ColCopyWorker

func (cw *ColCopyWorker) ColCopyWorker()

func (*ColCopyWorker) Copy

func (cw *ColCopyWorker) Copy(c *Counters)

func (*ColCopyWorker) CopyMultiThread

func (cw *ColCopyWorker) CopyMultiThread(c *Counters, cur *mongo.Cursor)

func (*ColCopyWorker) CopyMultiWorker

func (cw *ColCopyWorker) CopyMultiWorker(c *Counters, q *goconcurrentqueue.FixedFIFO, done chan bool, processingContext context.Context)

func (*ColCopyWorker) CopySingleThread

func (cw *ColCopyWorker) CopySingleThread(c *Counters, cur *mongo.Cursor)

Copy but, only the one slow thread. Fast enough for most small DBs

func (*ColCopyWorker) GetDocCount

func (cw *ColCopyWorker) GetDocCount(db *mongo.Database) int64

GetDocCount is bugged and not really working

type Counters

type Counters struct {
	DBs          *int64
	Collections  *int64
	InMemItems   *int64
	SourceItems  *int64
	CopyingItems *int64
	CopiedItems  *int64
	Indexes      *int64
}

type DBConfig

type DBConfig struct {
	Name                  string       `yaml:"name"`
	RenameTo              string       `yaml:"rename_to"`
	BatchSize             int          `yaml:"batch_size"`
	Enabled               bool         `yaml:"enabled"`
	NoFind                bool         `yaml:"no_find"`
	UseSeparateConnection bool         `yaml:"use_separate_connection"`
	Collections           []*ColConfig `yaml:"collections"`
}

func GenerateDBConfig

func GenerateDBConfig(dbName string, conn *mongo.Client) DBConfig

func GetBaseDBConfig

func GetBaseDBConfig() DBConfig

type DBConnector

type DBConnector struct {
	SourceURI string
	DestURI   string
	// contains filtered or unexported fields
}

type RootConfig

type RootConfig struct {
	Source                  string      `yaml:"source"`
	Destination             string      `yaml:"destination"`
	ParalellCollectionCount int         `yaml:"parallel_collection_count"`
	BatchSize               int         `yaml:"batch_size"`
	RefreshRate             int         `yaml:"refresh_rate"`
	NoFind                  bool        `yaml:"no_find"`
	Databases               []*DBConfig `yaml:"databases"`
}

func GenerateAllConfig

func GenerateAllConfig(cmd *cobra.Command, sourceUri string, destinationUri string) RootConfig

func GetBaseConfig

func GetBaseConfig() RootConfig

func ReadAndParseConfig

func ReadAndParseConfig(path string) RootConfig

type WorkerQueue

type WorkerQueue struct {
	Workers  []*ColCopyWorker
	Current  int // index of current worker
	State    *WorkerState
	Counters *Counters
	Done     chan bool
}

func (*WorkerQueue) GetNextWorker

func (wq *WorkerQueue) GetNextWorker() *ColCopyWorker

func (*WorkerQueue) Run

func (wq *WorkerQueue) Run(cfg *RootConfig)

func (*WorkerQueue) RunWorker

func (wq *WorkerQueue) RunWorker(w *ColCopyWorker, c *Counters)

type WorkerState

type WorkerState struct {
	Active int
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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