service

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Copyright © 2020 Marvin

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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

This section is empty.

Variables

View Source
var (
	Version   = "None"
	BuildTS   = "None"
	GitHash   = "None"
	GitBranch = "None"
)

版本信息

View Source
var (
	// Oracle/Mysql 对于 'NULL' 统一字符 NULL 处理,查询出来转成 NULL,所以需要判断处理
	// 查询字段值 NULL
	// 如果字段值 = NULLABLE 则表示值是 NULL
	// 如果字段值 = "" 则表示值是空字符串
	// 如果字段值 = 'NULL' 则表示值是 NULL 字符串
	// 如果字段值 = 'null' 则表示值是 null 字符串
	IsNull = "NULLABLE"
)
View Source
var Logger *zap.Logger

Functions

func GetAppVersion

func GetAppVersion(version bool)

func NewZapLogger

func NewZapLogger(cfg *CfgFile) (err error)

初始化日志 logger

func Query

func Query(db *sql.DB, querySQL string) ([]string, []map[string]string, error)

查询返回表字段列和对应的字段行数据

func RecordAppVersion

func RecordAppVersion(app string, logger *zap.Logger, cfg *CfgFile)

版本信息输出重定向到日志

Types

type AllConfig

type AllConfig struct {
	LogminerQueryTimeout int `toml:"logminer-query-timeout" json:"logminer-query-timeout"`
	FilterThreads        int `toml:"filter-threads" json:"filter-threads"`
	ApplyThreads         int `toml:"apply-threads" json:"apply-threads"`
	WorkerQueue          int `toml:"worker-queue" json:"worker-queue"`
	WorkerThreads        int `toml:"worker-threads" json:"worker-threads"`
}

type AppConfig

type AppConfig struct {
	InsertBatchSize  int `toml:"insert-batch-size" json:"insert-batch-size"`
	SlowlogThreshold int `toml:"slowlog-threshold" json:"slowlog-threshold"`
	Threads          int `toml:"threads" json:"threads"`
}

type CfgFile

type CfgFile struct {
	AppConfig    AppConfig    `toml:"app" json:"app"`
	FullConfig   FullConfig   `toml:"full" json:"full"`
	DiffConfig   DiffConfig   `toml:"diff" json:"diff"`
	AllConfig    AllConfig    `toml:"all" json:"all"`
	SourceConfig SourceConfig `toml:"source" json:"source"`
	TargetConfig TargetConfig `toml:"target" json:"target"`
	LogConfig    LogConfig    `toml:"log" json:"log"`
}

程序配置文件

func ReadConfigFile

func ReadConfigFile(file string) (*CfgFile, error)

读取配置文件

func (*CfgFile) GenerateTables

func (c *CfgFile) GenerateTables(engine *Engine) ([]string, error)

根据配置文件获取表列表

func (*CfgFile) String

func (c *CfgFile) String() string

type CustomSchemaColumnTypeMap

type CustomSchemaColumnTypeMap struct {
	ID               uint       `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SourceSchemaName string     `gorm:"not null;index:unique_schema_col,unique;comment:'源端库 schema'" json:"source_schema_name"`
	SourceColumnType string     `gorm:"not null;index:unique_schema_col,unique;comment:'源端表字段类型'" json:"source_column_type"`
	TargetColumnType string     `gorm:"not null;index:unique_schema_col,unique;comment:'目标表字段类型'" json:"target_column_type"`
	CreatedAt        *time.Time `gorm:"type:timestamp;not null;default:current_timestamp;comment:'创建时间'" json:"createdAt"`
	UpdatedAt        *time.Time `gorm:"type:timestamp;not null on update current_timestamp;default:current_timestamp;comment:'更新时间'" json:"updatedAt"`
}

自定义表结构字段类型转换规则 - schema 级别

func (*CustomSchemaColumnTypeMap) GetCustomSchemaColumnType

func (c *CustomSchemaColumnTypeMap) GetCustomSchemaColumnType() string

type CustomTableColumnTypeMap

type CustomTableColumnTypeMap struct {
	ID               uint       `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SourceSchemaName string     `gorm:"not null;index:unique_schema_table_col,unique;comment:'源端库 schema'" json:"source_schema_name"`
	SourceTableName  string     `gorm:"not null;index:unique_schema_table_col,unique;comment:'源端表名'" json:"source_table_name"`
	SourceColumnType string     `gorm:"not null;index:unique_schema_table_col,unique;comment:'源端表字段类型'" json:"source_column_type"`
	TargetColumnType string     `gorm:"not null;index:unique_schema_table_col,unique;comment:'目标表字段类型'" json:"target_column_type"`
	CreatedAt        *time.Time `gorm:"type:timestamp;not null;default:current_timestamp;comment:'创建时间'" json:"createdAt"`
	UpdatedAt        *time.Time `gorm:"type:timestamp;not null on update current_timestamp;default:current_timestamp;comment:'更新时间'" json:"updatedAt"`
}

自定义表结构字段类型转换规则 - table 级别 如果同步表未单独配置 table 级别字段类型映射规则,并且未单独配置 schema 级别字段类型映射规则,则采用程序内置规则转换 优先级: table > schema > internal

func (*CustomTableColumnTypeMap) GetCustomTableColumnType

func (c *CustomTableColumnTypeMap) GetCustomTableColumnType(tableName string) string

type CustomTableNameMap

type CustomTableNameMap struct {
	ID               uint       `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SourceSchemaName string     `gorm:"not null;index:unique_schema_table,unique;comment:'源端库 schema'" json:"source_schema_name"`
	SourceTableName  string     `gorm:"not null;index:unique_schema_table,unique;comment:'源端表名'" json:"source_table_name"`
	TargetTableName  string     `gorm:"not null;index:unique_schema_table,unique;comment:'目标表名'" json:"target_table_name"`
	CreatedAt        *time.Time `gorm:"type:timestamp;not null;default:current_timestamp;comment:'创建时间'" json:"createdAt"`
	UpdatedAt        *time.Time `gorm:"type:timestamp;not null on update current_timestamp;default:current_timestamp;comment:'更新时间'" json:"updatedAt"`
}
上下游字段类型映射表

自定义表结构名称转换规则 - table 级别 如果同步表未单独配置表结构名称转换规则 ,则采用源表默认

type DiffConfig

type DiffConfig struct {
	ChunkSize     int    `toml:"chunk-size" json:"chunk-size"`
	CheckThreads  int    `toml:"check-threads" json:"check-threads"`
	UseChecksum   bool   `toml:"use-checksum" json:"use-checksum"`
	UseCheckpoint bool   `toml:"use-checkpoint" json:"use-checkpoint"`
	FixSQLFile    string `toml:"fix-sql-file" json:"fix-sql-file"`
	Range         string `toml:"range" json:"range"`
}

type Engine

type Engine struct {
	OracleDB *sql.DB
	MysqlDB  *sql.DB
	GormDB   *gorm.DB
}

定义数据库引擎

func (*Engine) AddOracleLogminerlogFile

func (e *Engine) AddOracleLogminerlogFile(logFile string) error

func (*Engine) AdjustFullStageMySQLTableMetaRecord

func (e *Engine) AdjustFullStageMySQLTableMetaRecord(schemaName string, tableMetas []TableMeta) (bool, []string, []string, error)

该函数只应用于全量同步模式或者 ALL 同步模式 1、断点续传判断,判断是否可进行断点续传 2、判断是否存在未初始化元信息的表

func (*Engine) ClearMySQLTableMetaRecord

func (e *Engine) ClearMySQLTableMetaRecord(metaSchemaName, sourceSchemaName string) error

func (*Engine) EndOracleLogminerStoredProcedure

func (e *Engine) EndOracleLogminerStoredProcedure() error

func (*Engine) FilterDifferenceOracleTable

func (e *Engine) FilterDifferenceOracleTable(schemaName string, excludeTables []string) ([]string, error)

func (*Engine) FilterIntersectionMySQLTable

func (e *Engine) FilterIntersectionMySQLTable(schemaName string, includeTables []string) ([]string, error)

func (*Engine) FilterOraclePartitionTable

func (e *Engine) FilterOraclePartitionTable(schemaName string, tableSlice []string) ([]string, error)

func (*Engine) GetCustomSchemaColumnTypeMap

func (e *Engine) GetCustomSchemaColumnTypeMap(schemaName string) ([]CustomSchemaColumnTypeMap, error)

func (*Engine) GetCustomTableColumnTypeMap

func (e *Engine) GetCustomTableColumnTypeMap(schemaName string) ([]CustomTableColumnTypeMap, error)

func (*Engine) GetCustomTableNameMap

func (e *Engine) GetCustomTableNameMap(schemaName string) ([]CustomTableNameMap, error)

func (*Engine) GetMySQLDBServerCharacterSet

func (e *Engine) GetMySQLDBServerCharacterSet() (string, error)

MySQL

func (*Engine) GetMySQLDBServerCollation

func (e *Engine) GetMySQLDBServerCollation() (string, error)

func (*Engine) GetMySQLDBVersion

func (e *Engine) GetMySQLDBVersion() (string, error)

func (*Engine) GetMySQLPartitionTableINFO

func (e *Engine) GetMySQLPartitionTableINFO(schemaName, tableName string) ([]map[string]string, error)

func (*Engine) GetMySQLTableCharacterSetAndCollation

func (e *Engine) GetMySQLTableCharacterSetAndCollation(schemaName, tableName string) (string, string, error)

func (*Engine) GetMySQLTableCheckKey

func (e *Engine) GetMySQLTableCheckKey(schemaName, tableName string) ([]map[string]string, error)

func (*Engine) GetMySQLTableColumn

func (e *Engine) GetMySQLTableColumn(schemaName, tableName string) ([]map[string]string, error)

func (*Engine) GetMySQLTableComment

func (e *Engine) GetMySQLTableComment(schemaName, tableName string) (string, error)

func (*Engine) GetMySQLTableForeignKey

func (e *Engine) GetMySQLTableForeignKey(schemaName, tableName string) ([]map[string]string, error)

func (*Engine) GetMySQLTableFullMetaRowIDRecord

func (e *Engine) GetMySQLTableFullMetaRowIDRecord(schemaName, tableName string) ([]string, error)

func (*Engine) GetMySQLTableFullMetaSchemaTableRecord

func (e *Engine) GetMySQLTableFullMetaSchemaTableRecord(schemaName string) ([]string, error)

func (*Engine) GetMySQLTableIncrementMetaMinGlobalSCNTime

func (e *Engine) GetMySQLTableIncrementMetaMinGlobalSCNTime(sourceSchemaName string) (int, error)

func (*Engine) GetMySQLTableIncrementMetaMinSourceTableSCNTime

func (e *Engine) GetMySQLTableIncrementMetaMinSourceTableSCNTime(sourceSchemaName string) (int, error)

func (*Engine) GetMySQLTableIncrementMetaRecord

func (e *Engine) GetMySQLTableIncrementMetaRecord(sourceSchemaName string) ([]string, map[string]int, error)

func (*Engine) GetMySQLTableIndex

func (e *Engine) GetMySQLTableIndex(schemaName, tableName string) ([]map[string]string, error)

func (*Engine) GetMySQLTableMetaRecord

func (e *Engine) GetMySQLTableMetaRecord(schemaName string) ([]TableMeta, []string, error)

func (*Engine) GetMySQLTablePrimaryAndUniqueKey

func (e *Engine) GetMySQLTablePrimaryAndUniqueKey(schemaName, tableName string) ([]map[string]string, error)

func (*Engine) GetOracleALLRedoLogFile

func (e *Engine) GetOracleALLRedoLogFile() ([]string, error)

func (*Engine) GetOracleArchivedLogFile

func (e *Engine) GetOracleArchivedLogFile(scn string) ([]map[string]string, error)

func (*Engine) GetOracleArchivedLogSCN

func (e *Engine) GetOracleArchivedLogSCN(scn string) (int, error)

func (*Engine) GetOracleAvgRowLength

func (e *Engine) GetOracleAvgRowLength(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleCodeObject

func (e *Engine) GetOracleCodeObject(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleColumnTypeAndMaxLength

func (e *Engine) GetOracleColumnTypeAndMaxLength(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleConstraintType

func (e *Engine) GetOracleConstraintType(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleCurrentRedoMaxSCN

func (e *Engine) GetOracleCurrentRedoMaxSCN() (int, int, string, error)

func (*Engine) GetOracleCurrentSnapshotSCN

func (e *Engine) GetOracleCurrentSnapshotSCN() (int, error)

func (*Engine) GetOracleDBCharacterSet

func (e *Engine) GetOracleDBCharacterSet() (string, error)

Oracle

func (*Engine) GetOracleDBName

func (e *Engine) GetOracleDBName() (string, string, string, error)

func (*Engine) GetOracleDataTotal

func (e *Engine) GetOracleDataTotal() (string, error)

func (*Engine) GetOracleGlobalName

func (e *Engine) GetOracleGlobalName() (string, error)

func (*Engine) GetOracleIndexType

func (e *Engine) GetOracleIndexType(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleInstance

func (e *Engine) GetOracleInstance() ([]map[string]string, error)

func (*Engine) GetOracleLogminerContentToMySQL

func (e *Engine) GetOracleLogminerContentToMySQL(schemaName string, sourceTableNameList string, lastCheckpoint string, logminerQueryTimeout int) ([]LogminerContent, error)

func (*Engine) GetOracleMemoryGB

func (e *Engine) GetOracleMemoryGB() (string, error)

func (*Engine) GetOracleNumCPU

func (e *Engine) GetOracleNumCPU() (string, error)

func (*Engine) GetOracleObjectTypeOverview

func (e *Engine) GetOracleObjectTypeOverview(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleParameters

func (e *Engine) GetOracleParameters() (string, string, string, string, error)

func (*Engine) GetOraclePartitionObjectType

func (e *Engine) GetOraclePartitionObjectType(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOraclePartitionTableINFO

func (e *Engine) GetOraclePartitionTableINFO(schemaName, tableName string) ([]map[string]string, error)

func (*Engine) GetOraclePartitionTableOver1024

func (e *Engine) GetOraclePartitionTableOver1024(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleRedoLogFile

func (e *Engine) GetOracleRedoLogFile(scn string) ([]map[string]string, error)

func (*Engine) GetOracleRedoLogSCN

func (e *Engine) GetOracleRedoLogSCN(scn string) (int, error)

func (*Engine) GetOracleSchemaOverview

func (e *Engine) GetOracleSchemaOverview(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleSchemaTableRowsTOP

func (e *Engine) GetOracleSchemaTableRowsTOP(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleSynonymObjectType

func (e *Engine) GetOracleSynonymObjectType(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleTable

func (e *Engine) GetOracleTable(schemaName string) ([]string, error)

func (*Engine) GetOracleTableCheckKey

func (e *Engine) GetOracleTableCheckKey(schemaName string, tableName string) ([]map[string]string, error)

func (*Engine) GetOracleTableColumn

func (e *Engine) GetOracleTableColumn(schemaName string, tableName string) ([]map[string]string, error)

func (*Engine) GetOracleTableColumnCountsOver512

func (e *Engine) GetOracleTableColumnCountsOver512(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleTableColumnNameLength

func (e *Engine) GetOracleTableColumnNameLength(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleTableComment

func (e *Engine) GetOracleTableComment(schemaName string, tableName string) ([]map[string]string, error)

func (*Engine) GetOracleTableForeignKey

func (e *Engine) GetOracleTableForeignKey(schemaName string, tableName string) ([]map[string]string, error)

func (*Engine) GetOracleTableIndex

func (e *Engine) GetOracleTableIndex(schemaName string, tableName string) ([]map[string]string, error)

func (*Engine) GetOracleTableIndexCountsOver64

func (e *Engine) GetOracleTableIndexCountsOver64(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleTableIndexLengthOver3072

func (e *Engine) GetOracleTableIndexLengthOver3072(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleTableIndexNameLength

func (e *Engine) GetOracleTableIndexNameLength(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleTableNameLength

func (e *Engine) GetOracleTableNameLength(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleTableNumberTypeCheck

func (e *Engine) GetOracleTableNumberTypeCheck(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleTablePrimaryKey

func (e *Engine) GetOracleTablePrimaryKey(schemaName string, tableName string) ([]map[string]string, error)

func (*Engine) GetOracleTableRecordByRowIDSQL

func (e *Engine) GetOracleTableRecordByRowIDSQL(sql string) ([]string, []string, error)

func (*Engine) GetOracleTableRowLengthOver6M

func (e *Engine) GetOracleTableRowLengthOver6M(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleTableSequenceNameLength

func (e *Engine) GetOracleTableSequenceNameLength(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleTableUniqueKey

func (e *Engine) GetOracleTableUniqueKey(schemaName string, tableName string) ([]map[string]string, error)

func (*Engine) GetOracleTableViewNameLength

func (e *Engine) GetOracleTableViewNameLength(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleTemporaryTable

func (e *Engine) GetOracleTemporaryTable(schemaName []string) ([]map[string]string, error)

func (*Engine) GetOracleUsernameLength

func (e *Engine) GetOracleUsernameLength(schemaName []string) ([]map[string]string, error)

func (*Engine) InitMySQLTableFullMeta

func (e *Engine) InitMySQLTableFullMeta(schemaName, tableName string, globalSCN int, extractorBatch, insertBatchSize int) error

func (*Engine) InitMySQLTableIncrementMeta

func (e *Engine) InitMySQLTableIncrementMeta(schemaName, tableName string, globalSCN int) error

func (*Engine) InitMySQLTableMetaRecord

func (e *Engine) InitMySQLTableMetaRecord(schemaName string, tableName []string) error

func (*Engine) InitMysqlEngineDB

func (e *Engine) InitMysqlEngineDB() error

初始化同步表结构

func (*Engine) IsExistMySQLSchema

func (e *Engine) IsExistMySQLSchema(schemaName string) (bool, error)

func (*Engine) IsExistMySQLTable

func (e *Engine) IsExistMySQLTable(schemaName, tableName string) (bool, error)

func (*Engine) IsExistMySQLTableCharacterSetAndCollation

func (e *Engine) IsExistMySQLTableCharacterSetAndCollation(schemaName, tableName string) (bool, error)

func (*Engine) IsExistMysqlIndex

func (e *Engine) IsExistMysqlIndex(schemaName, tableName, indexName string) bool

func (*Engine) IsExistOracleSchema

func (e *Engine) IsExistOracleSchema(schemaName string) error

func (*Engine) IsExistOracleTable

func (e *Engine) IsExistOracleTable(schemaName string, includeTables []string) error

func (*Engine) IsMySQLPartitionTable

func (e *Engine) IsMySQLPartitionTable(schemaName, tableName string) (bool, error)

func (*Engine) IsNotExistMySQLTableIncrementMetaRecord

func (e *Engine) IsNotExistMySQLTableIncrementMetaRecord() (bool, error)

func (*Engine) IsOraclePartitionTable

func (e *Engine) IsOraclePartitionTable(schemaName, tableName string) (bool, error)

func (*Engine) ModifyMySQLTableMetaRecord

func (e *Engine) ModifyMySQLTableMetaRecord(metaSchemaName, sourceSchemaName, sourceTableName, rowidSQL string) error

清理并更新同步任务元数据表 1、全量每成功同步一张表记录,再清理记录 2、更新同步数据表元信息

func (*Engine) QueryFormatOracleRows

func (e *Engine) QueryFormatOracleRows(querySQL string) ([]string, []string, error)

查询 Oracle 数据并按行返回对应字段以及行数据 -> 按字段类型返回行数据 用于拼接 batch

func (*Engine) RenameMySQLTableName

func (e *Engine) RenameMySQLTableName(schemaName string, tableName string) error

func (*Engine) StartOracleLogminerStoredProcedure

func (e *Engine) StartOracleLogminerStoredProcedure(scn string) error

func (*Engine) TruncateMySQLTableFullMetaRecord

func (e *Engine) TruncateMySQLTableFullMetaRecord(metaSchemaName string) error

清理全量同步任务元数据表

func (*Engine) TruncateMySQLTableRecord

func (e *Engine) TruncateMySQLTableRecord(targetSchemaName string, tableMetas []TableMeta) error

func (*Engine) UpdateMySQLTableMetaRecord

func (e *Engine) UpdateMySQLTableMetaRecord(schemaName, tableName string, rowCounts, globalSCN int) error

func (*Engine) UpdateSingleTableIncrementMetaSCNByArchivedLog

func (e *Engine) UpdateSingleTableIncrementMetaSCNByArchivedLog(
	sourceSchemaName string, logFileEndSCN int, transferTableSlice []string) error

func (*Engine) UpdateSingleTableIncrementMetaSCNByCurrentRedo

func (e *Engine) UpdateSingleTableIncrementMetaSCNByCurrentRedo(
	sourceSchemaName string, lastRedoLogMaxSCN, logFileStartSCN, logFileEndSCN int) error

func (*Engine) UpdateSingleTableIncrementMetaSCNByNonCurrentRedo

func (e *Engine) UpdateSingleTableIncrementMetaSCNByNonCurrentRedo(
	sourceSchemaName string, lastRedoLogMaxSCN, logFileStartSCN, logFileEndSCN int, transferTableSlice []string) error

func (*Engine) UpdateTableIncrementMetaALLSCNRecord

func (e *Engine) UpdateTableIncrementMetaALLSCNRecord(sourceSchemaName, sourceTableName, operationType string, globalSCN, sourceTableSCN int) error

type FullConfig

type FullConfig struct {
	WorkerBatch      int  `toml:"worker-batch" json:"worker-batch"`
	WorkerThreads    int  `toml:"worker-threads" json:"worker-threads"`
	TableThreads     int  `toml:"table-threads" json:"table-threads"`
	EnableCheckpoint bool `toml:"enable-checkpoint" json:"enable-checkpoint"`
}

type GormLogger

type GormLogger struct {
	ZapLogger        *zap.Logger
	LogLevel         gormLogger.LogLevel
	SlowThreshold    time.Duration
	SkipCallerLookup bool
	Colorful         bool
}

func NewGormLogger

func NewGormLogger(zapLogger *zap.Logger, slowThreshold time.Duration) GormLogger

func (GormLogger) Error

func (l GormLogger) Error(ctx context.Context, str string, args ...interface{})

func (GormLogger) Info

func (l GormLogger) Info(ctx context.Context, str string, args ...interface{})

func (GormLogger) LogMode

func (GormLogger) SetAsDefault

func (l GormLogger) SetAsDefault()

func (GormLogger) Trace

func (l GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

func (GormLogger) Warn

func (l GormLogger) Warn(ctx context.Context, str string, args ...interface{})

type LogConfig

type LogConfig struct {
	LogLevel   string `toml:"log-level" json:"log-level"`
	LogFile    string `toml:"log-file" json:"log-file"`
	MaxSize    int    `toml:"max-size" json:"max-size"`
	MaxDays    int    `toml:"max-days" json:"max-days"`
	MaxBackups int    `toml:"max-backups" json:"max-backups"`
}

type LogminerContent

type LogminerContent struct {
	SCN       int
	SegOwner  string
	TableName string
	SQLRedo   string
	SQLUndo   string
	Operation string
}

获取 Oracle logminer 日志内容并过滤筛选已提交的 INSERT/DELETE/UPDATE 事务语句 考虑异构数据库 MySQL,只同步 INSERT/DELETE/UPDATE 事务语句以及 TRUNCATE TABLE/DROP TABLE DDL 语句,其他类型 SQL 不同步 V$LOGMNR_CONTENTS 字段解释参考链接 https://docs.oracle.com/en/database/oracle/oracle-database/21/refrn/V-LOGMNR_CONTENTS.html#GUID-B9196942-07BF-4935-B603-FA875064F5C3

type SourceConfig

type SourceConfig struct {
	Username      string   `toml:"username" json:"username"`
	Password      string   `toml:"password" json:"password"`
	ConnectString string   `toml:"connect-string",json:"connect-string"`
	SessionParams []string `toml:"session-params" json:"session-params"`
	Timezone      string   `toml:"timezone" json:"timezone"`
	SchemaName    string   `toml:"schema-name",json:"schema-name"`
	IncludeTable  []string `toml:"include-table",json:"include-table"`
	ExcludeTable  []string `toml:"exclude-table",json:"exclude-table"`
}

type TableFullMeta

type TableFullMeta struct {
	ID               uint       `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SourceSchemaName string     `gorm:"not null;index:idx_schema_table_rowid;comment:'源端 schema'" json:"source_schema_name"`
	SourceTableName  string     `gorm:"not null;index:idx_schema_table_rowid;comment:'源端表名'" json:"source_table_name"`
	GlobalSCN        int        `gorm:"comment:'全局 SCN'" json:"global_scn"`
	RowidSQL         string     `gorm:"not null;index:idx_schema_table_rowid;comment:'表 rowid 切分SQL'" json:"rowid_sql"`
	IsPartition      string     `gorm:"comment:'是否是分区表'" json:"is_partition"` // 同步转换统一转换成非分区表,此处只做标志
	CreatedAt        *time.Time `gorm:"type:timestamp;not null;default:current_timestamp;comment:'创建时间'" json:"createdAt"`
	UpdatedAt        *time.Time `gorm:"type:timestamp;not null on update current_timestamp;default:current_timestamp;comment:'更新时间'" json:"updatedAt"`
}

全量同步元数据表

func (*TableFullMeta) GetTableFullMetaRecordCounts

func (f *TableFullMeta) GetTableFullMetaRecordCounts(schemaName, tableName string, engine *Engine) (int, error)

type TableIncrementMeta

type TableIncrementMeta struct {
	ID               uint       `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	GlobalSCN        int        `gorm:"comment:'全局 SCN'" json:"global_scn"`
	SourceSchemaName string     `gorm:"not null;index:unique_schema_table,unique;comment:'源端 schema'" json:"source_schema_name"`
	SourceTableName  string     `gorm:"not null;index:unique_schema_table,unique;comment:'源端表名'" json:"source_table_name"`
	SourceTableSCN   int        `gorm:"comment:'表同步 SCN'" json:"source_table_scn"`
	CreatedAt        *time.Time `gorm:"type:timestamp;not null;default:current_timestamp;comment:'创建时间'" json:"createdAt"`
	UpdatedAt        *time.Time `gorm:"type:timestamp;not null on update current_timestamp;default:current_timestamp;comment:'更新时间'" json:"updatedAt"`
}

增量同步元数据表

func (*TableIncrementMeta) GetTableIncrementMetaRowCounts

func (i *TableIncrementMeta) GetTableIncrementMetaRowCounts(engine *Engine) (int, error)

type TableMeta

type TableMeta struct {
	ID               uint       `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SourceSchemaName string     `gorm:"not null;index:idx_schema_table,unique;comment:'源端 schema'" json:"source_schema_name"`
	SourceTableName  string     `gorm:"not null;index:idx_schema_table,unique;comment:'源端表名'" json:"source_table_name"`
	FullGlobalSCN    int        `gorm:"comment:'全量全局 SCN'" json:"full_global_scn"`
	FullSplitTimes   int        `gorm:"comment:'全量任务切分 SQL 次数'" json:"full_split_times"`
	CreatedAt        *time.Time `gorm:"type:timestamp;not null;default:current_timestamp;comment:'创建时间'" json:"createdAt"`
	UpdatedAt        *time.Time `gorm:"type:timestamp;not null on update current_timestamp;default:current_timestamp;comment:'更新时间'" json:"updatedAt"`
}

同步元数据表

type TargetConfig

type TargetConfig struct {
	Username      string `toml:"username" json:"username"`
	Password      string `toml:"password" json:"password"`
	Host          string `toml:"host" json:"host"`
	Port          int    `toml:"port" json:"port"`
	ConnectParams string `toml:"connect-params" json:"connect-params"`
	MetaSchema    string `toml:"meta-schema" json:"meta-schema"`
	SchemaName    string `toml:"schema-name",json:"schema-name"`
	Overwrite     bool   `toml:"overwrite" json:"overwrite"`
}

Jump to

Keyboard shortcuts

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