versions

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	T_any           = "ANY"
	T_bool          = "BOOL"
	T_bit           = "BIT"
	T_int8          = "TINYINT"
	T_int16         = "SMALLINT"
	T_int32         = "INT"
	T_int64         = "BIGINT"
	T_uint8         = "TINYINT UNSIGNED"
	T_uint16        = "SMALLINT UNSIGNED"
	T_uint32        = "INT UNSIGNED"
	T_uint64        = "BIGINT UNSIGNED"
	T_float32       = "FLOAT"
	T_float64       = "DOUBLE"
	T_date          = "DATE"
	T_datetime      = "DATETIME"
	T_time          = "TIME"
	T_timestamp     = "TIMESTAMP"
	T_char          = "CHAR"
	T_varchar       = "VARCHAR"
	T_binary        = "BINARY"
	T_varbinary     = "VARBINARY"
	T_json          = "JSON"
	T_tuple         = "TUPLE"
	T_decimal64     = "DECIMAL64"
	T_decimal128    = "DECIMAL128"
	T_decimal256    = "DECIMAL256"
	T_blob          = "BLOB"
	T_text          = "TEXT"
	T_TS            = "TRANSACTION TIMESTAMP"
	T_Rowid         = "ROWID"
	T_uuid          = "UUID"
	T_Blockid       = "BLOCKID"
	T_interval      = "INTERVAL"
	T_array_float32 = "VECF32"
	T_array_float64 = "VECF64"
	T_enum          = "ENUM"
)

Variables

View Source
var (
	No  = int32(0)
	Yes = int32(1)
)
View Source
var (
	StateCreated         = int32(0)
	StateUpgradingTenant = int32(1)
	StateReady           = int32(2)
)
View Source
var (
	FrameworkInitSQLs = []string{
		fmt.Sprintf(`create table %s.%s (
			version             varchar(50) not null,
		    version_offset      int unsigned default 0,
			state               int,
			create_at           timestamp not null,
			update_at           timestamp not null,
			primary key(version, version_offset)
		)`, catalog.MO_CATALOG, catalog.MOVersionTable),

		fmt.Sprintf(`create table %s.%s (
			id                   bigint unsigned not null primary key auto_increment,
			from_version         varchar(50) not null,
			to_version           varchar(50) not null,
			final_version        varchar(50) not null,
            final_version_offset int unsigned default 0,
			state                int,
			upgrade_cluster      int,
			upgrade_tenant       int,
			upgrade_order        int,
			total_tenant         int,
			ready_tenant         int,
			create_at            timestamp not null,
			update_at            timestamp not null
		)`, catalog.MO_CATALOG, catalog.MOUpgradeTable),

		fmt.Sprintf(`create table %s.%s (
			id                  bigint unsigned not null primary key auto_increment,
			upgrade_id		    bigint unsigned not null,
			target_version      varchar(50) not null,
			from_account_id     int not null,
			to_account_id       int not null,
			ready               int,
			create_at           timestamp not null,
			update_at           timestamp not null
		)`, catalog.MO_CATALOG, catalog.MOUpgradeTenantTable),

		"alter table `mo_account` add column `create_version` varchar(50) default '1.1.0' after suspended_time",
	}
)

Functions

func AddUpgradeTenantTask

func AddUpgradeTenantTask(
	upgradeID uint64,
	version string,
	fromAccountID int32,
	toAccountID int32,
	txn executor.TxnExecutor) error

func AddVersion

func AddVersion(
	version string,
	versionOffset uint32,
	state int32,
	txn executor.TxnExecutor) error

func AddVersionUpgrades

func AddVersionUpgrades(
	values []VersionUpgrade,
	txn executor.TxnExecutor) error

func CheckDatabaseDefinition

func CheckDatabaseDefinition(txn executor.TxnExecutor, accountId uint32, schema string) (bool, error)

CheckDatabaseDefinition This function is used to check if the database definition exists. If it exists, return true; otherwise, return false.

func CheckIndexDefinition

func CheckIndexDefinition(txn executor.TxnExecutor, accountId uint32, schema string, tableName string, indexName string) (bool, error)

CheckIndexDefinition Used to check if a certain index is defined in the table This function executes the given SQL query, returns true if the result set is not empty, otherwise returns false.

func CheckTableComment added in v1.2.1

func CheckTableComment(txn executor.TxnExecutor, accountId uint32, schema string, tableName string) (bool, string, error)

CheckTableComment is used to check if the specified table definition exists in the specified database. If it exists, return true; otherwise, return false.

func CheckTableDataExist

func CheckTableDataExist(txn executor.TxnExecutor, accountId uint32, sql string) (bool, error)

CheckTableDataExist Used to checks whether a table contains specific data This function executes the given SQL query, returns true if the result set is not empty, otherwise returns false.

func CheckTableDefinition

func CheckTableDefinition(txn executor.TxnExecutor, accountId uint32, schema string, tableName string) (bool, error)

CheckTableDefinition is used to check if the specified table definition exists in the specified database. If it exists, return true; otherwise, return false.

func CheckViewDefinition

func CheckViewDefinition(txn executor.TxnExecutor, accountId uint32, schema string, viewName string) (bool, string, error)

CheckViewDefinition Check if the view exists, if so, return true and return the view definition

func Compare

func Compare(v1, v2 string) int

func FetchAllTenants

func FetchAllTenants(txn executor.TxnExecutor) ([]int32, error)

FetchAllTenants get all tenantIDs in mo system, including system tenants

func GetTenantCreateVersionForUpdate

func GetTenantCreateVersionForUpdate(
	tenantID int32,
	txn executor.TxnExecutor) (string, error)

func GetTenantVersion

func GetTenantVersion(
	tenantID int32,
	txn executor.TxnExecutor) (string, error)

func GetUpgradeTenantTasks

func GetUpgradeTenantTasks(
	upgradeID uint64,
	txn executor.TxnExecutor) (uint64, []int32, []string, error)

func GetVersionState

func GetVersionState(
	version string,
	versionOffset uint32,
	txn executor.TxnExecutor,
	forUpdate bool) (int32, bool, error)

func GetVersionUpgradeSQL

func GetVersionUpgradeSQL(v VersionUpgrade) string

func IsFrameworkTablesCreated

func IsFrameworkTablesCreated(txn executor.TxnExecutor) (bool, error)

func MustGetLatestReadyVersion

func MustGetLatestReadyVersion(
	txn executor.TxnExecutor) (string, error)

func UpdateUpgradeTenantTaskState

func UpdateUpgradeTenantTaskState(
	taskID uint64,
	state int32,
	txn executor.TxnExecutor) error

func UpdateVersionState

func UpdateVersionState(
	version string,
	versionOffset uint32,
	state int32,
	txn executor.TxnExecutor) error

func UpdateVersionUpgradeState

func UpdateVersionUpgradeState(
	upgrade VersionUpgrade,
	state int32,
	txn executor.TxnExecutor) error

func UpdateVersionUpgradeTasks

func UpdateVersionUpgradeTasks(
	upgrade VersionUpgrade,
	txn executor.TxnExecutor) error

func UpgradeTenantVersion

func UpgradeTenantVersion(
	tenantID int32,
	version string,
	txn executor.TxnExecutor) error

Types

type ColumnInfo

type ColumnInfo struct {
	IsExits    bool
	Name       string
	Nullable   bool
	ColType    string
	ChatLength int64
	Precision  int64
	Scale      int64

	Position int32
	Default  string
	Extra    string
	Comment  string
	// contains filtered or unexported fields
}

ColumnInfo Describe the detailed information of the table column

func CheckTableColumn

func CheckTableColumn(txn executor.TxnExecutor,
	accountId uint32,
	schema string,
	tableName string,
	columnName string) (ColumnInfo, error)

CheckTableColumn Check if the columns in the table exist, and if so, return the detailed information of the column

type UpgradeEntry

type UpgradeEntry struct {
	Schema    string
	TableName string
	// UpgType declare the type of upgrade
	UpgType UpgradeType
	// UpgSql is used to perform upgrade operations
	UpgSql string
	// CheckFunc was used to check whether an upgrade is required
	// return true if the system is already in the final state and does not need to be upgraded,
	// otherwise return false
	CheckFunc func(txn executor.TxnExecutor, accountId uint32) (bool, error)
	PreSql    string
	PostSql   string
}

UpgradeEntry is used to designate a specific upgrade entity. Users must provide `UpgSql` and `CheckFunc` implementations

func (*UpgradeEntry) String

func (u *UpgradeEntry) String() string

func (*UpgradeEntry) Upgrade

func (u *UpgradeEntry) Upgrade(txn executor.TxnExecutor, accountId uint32) error

Upgrade entity execution upgrade entrance

type UpgradeType

type UpgradeType int8
const (
	// alter table structure
	ADD_COLUMN UpgradeType = iota
	DROP_COLUMN
	CHANGE_COLUMN
	MODIFY_COLUMN
	RENAME_COLUMN
	ALTER_COLUMN_DEFAULT
	MODIFY_TABLE_COMMENT
	ADD_INDEX
	DROP_INDEX
	ALTER_INDEX_VISIBLE
	ADD_CONSTRAINT_UNIQUE_INDEX
	ADD_CONSTRAINT_PRIMARY_KEY
	ADD_CONSTRAINT_FOREIGN_KEY
	DROP_CONSTRAINT
	DROP_PRIMARY_KEY
	DROP_FOREIGN_KEY
	CREATE_NEW_TABLE

	// alter view definition
	MODIFY_VIEW
	CREATE_VIEW
	DROP_VIEW

	CREATE_DATABASE
	MODIFY_METADATA
)

type Version

type Version struct {
	// Version version string, like 1.0.0
	Version string
	// State.
	State int32
	// MinUpgradeVersion the min version that can be directly upgraded to current version
	MinUpgradeVersion string
	// UpgradeCluster upgrade cluster or not.
	UpgradeCluster int32
	// UpgradeTenant tenant need upgrade. The upgrade framework is responsible for upgrading
	// all tenants in parallel.
	UpgradeTenant int32
	// Tenant upgrade version upgrade Offset location
	VersionOffset uint32
}

func GetLatestUpgradeVersion

func GetLatestUpgradeVersion(txn executor.TxnExecutor) (Version, error)

func GetLatestVersion

func GetLatestVersion(txn executor.TxnExecutor) (Version, error)

func (Version) CanDirectUpgrade

func (v Version) CanDirectUpgrade(version string) bool

func (Version) GetInitVersionSQL

func (v Version) GetInitVersionSQL(state int32) string

func (Version) IsReady

func (v Version) IsReady() bool

func (Version) IsUpgradingTenant

func (v Version) IsUpgradingTenant() bool

func (Version) NeedUpgradeCluster

func (v Version) NeedUpgradeCluster() bool

func (Version) NeedUpgradeTenant

func (v Version) NeedUpgradeTenant() bool

type VersionUpgrade

type VersionUpgrade struct {
	// ID upgrade id
	ID uint64
	// FromVersion from version
	FromVersion string
	// ToVersion to version
	ToVersion string
	// FinalVersion upgrade final version
	FinalVersion string
	// FinalVersionOffset upgrade final version
	FinalVersionOffset uint32
	// State.
	State int32
	// UpgradeOrder upgrade order
	UpgradeOrder int32
	// UpgradeCluster upgrade cluster or not.
	UpgradeCluster int32
	// UpgradeTenant tenant need upgrade. The upgrade framework is responsible for upgrading
	// all tenants in parallel.
	UpgradeTenant int32
	// TotalTenant total tenant need upgrade
	TotalTenant int32
	// ReadyTenant ready tenant count
	ReadyTenant int32
}

func GetUpgradeVersionForUpdateByID

func GetUpgradeVersionForUpdateByID(
	id uint64,
	txn executor.TxnExecutor) (VersionUpgrade, error)

func GetUpgradeVersions

func GetUpgradeVersions(
	finalVersion string,
	finalVersionOffset uint32,
	txn executor.TxnExecutor,
	forUpdate bool,
	mustHave bool) ([]VersionUpgrade, error)

func GetUpgradeVersionsByOrder

func GetUpgradeVersionsByOrder(
	finalVersion string,
	order int32,
	txn executor.TxnExecutor) ([]VersionUpgrade, error)

func GetUpgradingTenantVersion

func GetUpgradingTenantVersion(txn executor.TxnExecutor) (VersionUpgrade, bool, error)

func (VersionUpgrade) String

func (v VersionUpgrade) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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