utils

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Copyright (c) YugabyteDB, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) YugabyteDB, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) YugabyteDB, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) YugabyteDB, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) YugabyteDB, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	TABLE_MIGRATION_NOT_STARTED = iota
	TABLE_MIGRATION_IN_PROGRESS
	TABLE_MIGRATION_DONE
	TABLE_MIGRATION_COMPLETED
	YB_VOYAGER_NULL_STRING = "__YBV_NULL__"
)
View Source
const (
	SNAPSHOT_ONLY        = "snapshot-only"
	SNAPSHOT_AND_CHANGES = "snapshot-and-changes"
	CHANGES_ONLY         = "changes-only"
)
View Source
const (
	// This constant must be updated on every release.
	YB_VOYAGER_VERSION = "1.7.0"

	// @Refer: https://icinga.com/blog/2022/05/25/embedding-git-commit-information-in-go-binaries/
	GIT_COMMIT_HASH = "$Format:%H$"
)

Variables

View Source
var DoNotPrompt bool
View Source
var TableMetadataStatusMap = map[int]string{
	0: "NOT-STARTED",
	1: "EXPORTING",
	2: "DONE",
	3: "DONE",
}
View Source
var WaitChannel = make(chan int)
View Source
var WaitGroup sync.WaitGroup

Functions

func AskPrompt

func AskPrompt(args ...string) bool

func BytesToGB added in v1.7.0

func BytesToGB(sizeInBytes float64) float64

BytesToGB function converts the size of the source object from bytes to GB as it is required for further calculation Parameters:

sizeInBytes: size of source object in bytes

Returns:

sizeInGB: size of source object in gigabytes

func CleanDir

func CleanDir(dir string)

func ConnectToSqliteDatabase added in v1.7.0

func ConnectToSqliteDatabase(dbPath string) (*sql.DB, error)

func ContainsAnySubstringFromSlice added in v1.6.2

func ContainsAnySubstringFromSlice(slice []string, s string) bool

func ContainsString added in v1.6.0

func ContainsString(list []string, str string) bool

func ConvertStringSliceToInterface added in v1.7.0

func ConvertStringSliceToInterface(slice []string) []interface{}

func CsvStringToSlice

func CsvStringToSlice(str string) []string

func ErrExit

func ErrExit(formatString string, args ...interface{})

func FileOrFolderExists

func FileOrFolderExists(path string) bool

func FileOrFolderExistsWithGlobPattern added in v1.6.0

func FileOrFolderExistsWithGlobPattern(path string) bool

func ForEachLineInFile added in v1.5.0

func ForEachLineInFile(filePath string, callback func(line string) bool) error

func ForEachMatchingLineInFile added in v1.5.0

func ForEachMatchingLineInFile(filePath string, re *regexp.Regexp, callback func(matches []string) bool) error

func GenerateRandomString added in v1.4.0

func GenerateRandomString(length int) string

https://yourbasic.org/golang/generate-random-string/

func GetEnvAsInt added in v1.5.0

func GetEnvAsInt(key string, fallback int) int

func GetExportSchemaObjectList added in v1.6.0

func GetExportSchemaObjectList(sourceDBType string) []string

func GetFSUtilizationPercentage added in v1.5.0

func GetFSUtilizationPercentage(path string) (int, error)

func GetLogMiningFlushTableName added in v1.7.0

func GetLogMiningFlushTableName(migrationUUID uuid.UUID) string

func GetMapKeysSorted added in v1.5.0

func GetMapKeysSorted(m map[string]*string) []string

func GetObjectDirPath

func GetObjectDirPath(schemaDirPath string, objType string) string

func GetObjectFileName

func GetObjectFileName(schemaDirPath string, objType string) string

func GetObjectFilePath

func GetObjectFilePath(schemaDirPath string, objType string) string

func GetObjectNameListFromReport

func GetObjectNameListFromReport(report SchemaReport, objType string) []string

func GetRedactedURLs added in v0.81.0

func GetRedactedURLs(urlList []string) []string

func GetRelativePathFromCwd added in v1.7.0

func GetRelativePathFromCwd(fullPath string) string

func GetSchemaObjectList

func GetSchemaObjectList(sourceDBType string) []string

func GetSortedKeys

func GetSortedKeys(tablesProgressMetadata map[string]*TableProgressMetadata) []string

func GetSqlStmtToPrint added in v0.83.0

func GetSqlStmtToPrint(stmt string) string

func GitCommitHash

func GitCommitHash() string

func HumanReadableByteCount added in v1.4.0

func HumanReadableByteCount(bytes int64) string

func IsDirectoryEmpty

func IsDirectoryEmpty(pathPattern string) bool

func IsQuotedString

func IsQuotedString(str string) bool

func LookupIP

func LookupIP(name string) []string

func PrettifyHtmlString

func PrettifyHtmlString(htmlStr string) string

func PrettifyJsonString

func PrettifyJsonString(jsonStr string) string

func PrintAndLog

func PrintAndLog(formatString string, args ...interface{})

func PrintIfTrue

func PrintIfTrue(message string, args ...bool)

func PrintSqlStmtIfDDL added in v0.83.0

func PrintSqlStmtIfDDL(stmt string, fileName string)

func ReadTableNameListFromFile added in v1.6.0

func ReadTableNameListFromFile(filePath string) ([]string, error)

read the file and return slice of csv

func Readline

func Readline(r *bufio.Reader) (string, error)

func SetDifference added in v0.81.0

func SetDifference(includeList []string, excludeList []string) []string

func ToCaseInsensitiveNames added in v0.81.0

func ToCaseInsensitiveNames(names []string) []string

func Wait

func Wait(args ...string)

func WaitForLineInLogFile added in v1.7.0

func WaitForLineInLogFile(filePath string, message string, timeoutDuration time.Duration) error

Types

type BoolStr added in v1.6.0

type BoolStr bool

func (*BoolStr) Set added in v1.6.0

func (b *BoolStr) Set(s string) error

func (*BoolStr) String added in v1.6.0

func (b *BoolStr) String() string

func (*BoolStr) Type added in v1.6.0

func (b *BoolStr) Type() string

type DBObject

type DBObject struct {
	ObjectType   string `json:"ObjectType"`
	TotalCount   int    `json:"TotalCount"`
	InvalidCount int    `json:"InvalidCount,omitempty"`
	ObjectNames  string `json:"ObjectNames"`
	Details      string `json:"Details,omitempty"`
}

type IndexInfo added in v1.6.0

type IndexInfo struct {
	// TODO: ADD SchemaName string `json:"SchemaName"`
	IndexName string   `json:"IndexName"`
	IndexType string   `json:"IndexType"`
	TableName string   `json:"TableName"`
	Columns   []string `json:"Columns"`
}

type Issue

type Issue struct {
	ObjectType   string `json:"ObjectType"`
	ObjectName   string `json:"ObjectName"`
	Reason       string `json:"Reason"`
	SqlStatement string `json:"SqlStatement,omitempty"`
	FilePath     string `json:"FilePath"`
	Suggestion   string `json:"Suggestion"`
	GH           string `json:"GH"`
}

type Keyer added in v1.7.0

type Keyer interface {
	// Key returns a string representation of the object that is used as a key in the map.
	// Note that every instance of the object should have a unique value for the Key()
	Key() string
}

Keyer is an interface that should be implemented by custom objects that are used as keys in the map data structure.

type SchemaReport added in v1.7.0

type SchemaReport struct {
	SchemaSummary SchemaSummary `json:"Summary"`
	Issues        []Issue       `json:"Issues"`
}

type SchemaSummary added in v1.7.0

type SchemaSummary struct {
	DBName      string     `json:"DbName,omitempty"`
	SchemaNames []string   `json:"SchemaNames,omitempty"`
	DBVersion   string     `json:"DbVersion,omitempty"`
	Notes       []string   `json:"Notes,omitempty"`
	DBObjects   []DBObject `json:"DatabaseObjects"`
}

type Segment added in v1.6.0

type Segment struct {
	Num      int
	FilePath string
}

================== Segment ==============================

type StructMap added in v1.7.0

type StructMap[K Keyer, V any] struct {
	// contains filtered or unexported fields
}

Map is a generic map data structure that allows using custom objects as keys. Note that every instance of the object should have a unique value for the Key()

func NewStructMap added in v1.7.0

func NewStructMap[K Keyer, V any]() *StructMap[K, V]

NewMap creates a new Map data structure.

func (*StructMap[K, V]) Clear added in v1.7.0

func (m *StructMap[K, V]) Clear()

func (*StructMap[K, V]) Delete added in v1.7.0

func (m *StructMap[K, V]) Delete(key K)

Delete deletes the value for the given key in the map.

func (*StructMap[K, V]) Get added in v1.7.0

func (m *StructMap[K, V]) Get(key K) (V, bool)

Get returns the value for the given key in the map.

func (*StructMap[K, V]) IterKV added in v1.7.0

func (m *StructMap[K, V]) IterKV(f func(key K, value V) (bool, error)) error

IterKV iterates over the key-value pairs of the map and calls the given function for each pair. The function should return false to stop the iteration.

func (*StructMap[K, V]) Keys added in v1.7.0

func (m *StructMap[K, V]) Keys() []string

func (*StructMap[K, V]) Put added in v1.7.0

func (m *StructMap[K, V]) Put(key K, value V)

Put sets the value for the given key in the map.

type TableColumnsDataTypes added in v1.7.0

type TableColumnsDataTypes struct {
	SchemaName string `json:"SchemaName"`
	TableName  string `json:"TableName"`
	ColumnName string `json:"ColumnName"`
	DataType   string `json:"DataType"`
}

type TableProgressMetadata

type TableProgressMetadata struct {
	TableName            sqlname.NameTuple
	InProgressFilePath   string
	FinalFilePath        string
	Status               int //(0: NOT-STARTED, 1: IN-PROGRESS, 2: DONE, 3: COMPLETED)
	CountLiveRows        int64
	CountTotalRows       int64
	FileOffsetToContinue int64 // This might be removed later
	IsPartition          bool
	ParentTable          string
}

type TailReader added in v1.2.0

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

func NewTailReader added in v1.2.0

func NewTailReader(r io.Reader, getLastValidOffsetFn func() (int64, error)) *TailReader

func (*TailReader) Read added in v1.2.0

func (t *TailReader) Read(p []byte) (n int, err error)

Read the underlying io.Reader and return the contents. If the underlying reader returns io.EOF, keep on retrying until some data is available.

Directories

Path Synopsis
Package csv reads and writes comma-separated values (CSV) files.
Package csv reads and writes comma-separated values (CSV) files.

Jump to

Keyboard shortcuts

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