Documentation
¶
Overview ¶
Package utils contains some common utilities used by all other packages.
Index ¶
- Constants
- func AuxTableName(tableName, suffix string) string
- func CheckpointTableName(tableName string) string
- func CloseAndLog(closer Closer)
- func CloseAndLogWithContext(ctx context.Context, closer ContextCloser)
- func HashKey(key []any) string
- func NewTableName(tableName string) string
- func OldTableName(tableName string) string
- func OldTableNameWithTimestamp(tableName, timestamp string) string
- func TruncateTableName(tableName string, suffixLength int) string
- func UnhashKeyToString(key string) string
- type Closer
- type ContextCloser
Constants ¶
const ( PrimaryKeySeparator = "-#-" // used to hash a composite primary key // MaxTableNameLength is the maximum table name length in MySQL. MaxTableNameLength = 64 )
const ( // NameFormatTimestamp is the time.Format layout used in the timestamped // _<table>_old_<timestamp> name when SkipDropAfterCutover is set. NameFormatTimestamp = "20060102_150405" )
Variables ¶
This section is empty.
Functions ¶
func AuxTableName ¶ added in v0.13.0
AuxTableName builds a deterministic auxiliary table name for the given original table name and suffix (e.g. "_chkpnt", "_new", "_old"). The returned name is `_<table><suffix>`, with the table-name portion deterministically truncated when needed and the result hard-capped at MySQL's 64-character identifier limit (a defensive guard against an abusively long suffix; in practice callers pass small suffixes).
Truncation is deterministic: the same (tableName, suffix) input always produces the same output. Two distinct table names that share a long common prefix can collide; callers must record the original table name out-of-band (e.g. in the checkpoint) so collisions can be detected.
func CheckpointTableName ¶ added in v0.13.0
CheckpointTableName returns the auxiliary checkpoint table name for the given original table.
func CloseAndLog ¶ added in v0.10.2
func CloseAndLog(closer Closer)
CloseAndLog closes a resource and logs any error. This is useful for defer statements where the error cannot be meaningfully handled except by logging. Example: defer utils.CloseAndLog(db)
func CloseAndLogWithContext ¶ added in v0.10.2
func CloseAndLogWithContext(ctx context.Context, closer ContextCloser)
CloseAndLogWithContext closes a resource that requires context and logs any error. This is useful for defer statements on resources like table locks. Example: defer utils.CloseAndLogWithContext(ctx, lock)
func HashKey ¶
HashKey is used to convert a composite key into a string so that it can be placed in a map.
func NewTableName ¶ added in v0.13.0
NewTableName returns the auxiliary _new table name for the given original table.
func OldTableName ¶ added in v0.13.0
OldTableName returns the auxiliary _old table name for the given original table.
func OldTableNameWithTimestamp ¶ added in v0.13.0
OldTableNameWithTimestamp returns the auxiliary _old_<timestamp> table name for the given original table and timestamp string. Used when SkipDropAfterCutover is set so the renamed-away table is preserved with a unique name across multiple migrations.
func TruncateTableName ¶ added in v0.13.0
TruncateTableName truncates a table name to fit within MySQL's 64-character limit, reserving space for a suffix of the given length. If the table name already fits, it is returned unchanged.
func UnhashKeyToString ¶
UnhashKeyToString converts a hashed key to a string that can be used in a query.
Types ¶
type Closer ¶ added in v0.10.2
type Closer interface {
Close() error
}
Closer is an interface for types that have a Close() method. This is compatible with io.Closer and many other types in the codebase.
type ContextCloser ¶ added in v0.10.2
ContextCloser is an interface for types that have a Close(context.Context) method. This is used for resources like table locks that need context for cleanup.