mask

package
v0.0.0-...-8b6b441 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaskFuncMap = map[string]MaskFunc{
	"workload-sim": {"For workload simulation project", funcs.WorkloadSimMask},
	"debug":        {"Replace every constant with its inferred type, for debug usage", funcs.DebugMask},
	"debug-color":  {"Like `debug`, but in ANSI color", funcs.DebugMaskColor},
	"identical":    {"Dry-run baseline", funcs.IdenticalMask},
}

All mask functions

Functions

func ConvertAndMask

func ConvertAndMask(sc *stmtctx.StatementContext, datum types.Datum, toType *types.FieldType, maskFunc MaskFunc) (types.Datum, *types.FieldType, error)

Convert `datum` to `toType` and then mask using `maskFunc`, returns new datum and its coresponding type

func NewDefaultDictionary

func NewDefaultDictionary() *dict.Dictionary

Types

type CastGraph

type CastGraph struct {
	Adj map[Node]([]Node)
}

func NewGraph

func NewGraph() *CastGraph

func (*CastGraph) Add

func (g *CastGraph) Add(a Expr, b Expr) bool

Add a relationship to this graph

func (*CastGraph) InferType

func (g *CastGraph) InferType(c *expression.Constant) *InferredType

type CastGraphBuilder

type CastGraphBuilder struct {
	Constants []*expression.Constant
	Columns   []*expression.Column
	Handles   []kv.Handle
	Graph     *CastGraph
}

A visitor for physical plans, which extract sconstants for masking, and builds a `CastGraph` for inferring types

func NewCastGraphBuilder

func NewCastGraphBuilder() *CastGraphBuilder

func (*CastGraphBuilder) Build

func (b *CastGraphBuilder) Build(plan plannercore.Plan) error

type CastNode

type CastNode struct {
	Node
	// contains filtered or unexported fields
}

type EventWorker

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

func NewEventWorker

func NewEventWorker(db *tidb.Context, maskFunc MaskFunc, ignoreIntPK bool, nameMap *NameMap) *EventWorker

Create a mask worker for MySQL Events

func (*EventWorker) MaskOne

func (w *EventWorker) MaskOne(ev event.MySQLEvent) (event.MySQLEvent, error)

func (*EventWorker) MaskOneExecute

func (w *EventWorker) MaskOneExecute(stmtID uint64, params []interface{}) ([]interface{}, error)

For type `StmtExecute`, lookup prepared analysis from `w.preparedStmts` and mask parameters

func (*EventWorker) PrepareOne

func (w *EventWorker) PrepareOne(stmtID uint64, sql string) (string, error)

For type `StmtPrepare`, do not evaluate but only analyze it and store into `w.preparedStmts`

type Expr

type Expr = expression.Expression

type ExprMap

type ExprMap = map[ReplaceMarker]*driver.ValueExpr

type ExprOffsetMap

type ExprOffsetMap = map[ReplaceMarker]int

type InferredType

type InferredType struct {
	Ft *types.FieldType
}

func NewInferredType

func NewInferredType(ft *types.FieldType) *InferredType

func NewIntHandleInferredType

func NewIntHandleInferredType() *InferredType

func (InferredType) IsPrimaryKey

func (it InferredType) IsPrimaryKey() bool

type MaskFunc

type MaskFunc struct {
	Description string
	// contains filtered or unexported fields
}

type NameMap

type NameMap struct {
	DBs     map[string]string `json:"dbs"`
	Tables  map[string]string `json:"tables"`
	Columns map[string]string `json:"columns"`
	// contains filtered or unexported fields
}

func NewGlobalNameMap

func NewGlobalNameMap(columns map[string]string) *NameMap

func NewLocalNameMap

func NewLocalNameMap(global *NameMap, columnsSubSet []*expression.Column, currentDB string) (*NameMap, error)

func (*NameMap) ColumnName

func (m *NameMap) ColumnName(name *ast.ColumnName) *ast.ColumnName

func (*NameMap) DB

func (m *NameMap) DB(from string) string

func (*NameMap) TableName

func (m *NameMap) TableName(name *ast.TableName) *ast.TableName

type Node

type Node interface {
}

type NormalNode

type NormalNode struct {
	Node
	// contains filtered or unexported fields
}

type Prepared

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

type PreparedMap

type PreparedMap = map[uint64]Prepared

type ReplaceMarker

type ReplaceMarker int64

func (ReplaceMarker) IntValue

func (m ReplaceMarker) IntValue() int64

type ReplaceMode

type ReplaceMode int
const (
	ReplaceModeValue ReplaceMode = iota
	ReplaceModeParamMarker
)

type ReplaceVisitor

type ReplaceVisitor struct {
	OriginExprs ExprMap
	Offsets     ExprOffsetMap
	// contains filtered or unexported fields
}

Replace constants with disjoint numbers as `ReplaceMarker`s.

For normal statements, replace values with `Value` mode. For handling `PREPARE` statements internally, we may replace values with `ParamMarker` mode.

func NewReplaceVisitor

func NewReplaceVisitor(mode ReplaceMode) *ReplaceVisitor

func (*ReplaceVisitor) Enter

func (v *ReplaceVisitor) Enter(in ast.Node) (node ast.Node, skipChilren bool)

func (*ReplaceVisitor) Leave

func (v *ReplaceVisitor) Leave(in ast.Node) (node ast.Node, ok bool)

type RestoreMode

type RestoreMode int
const (
	RestoreModeNameValue RestoreMode = iota
	RestoreModeNameOnly
)

type RestoreVisitor

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

In replace phase, we replace constants with disjoint numbers as `ReplaceMarker`s in order to infer types of them and construct a `TypeMap`.

`RestoreVisitor` will traverse the AST, restoring and masking constants based on information from `ExprMap` and `TypeMap`. Also in restore phase, names may need to be masked if `nameMap` is given.

Note that for `?` in PREPARE statements, there's neither way nor need to restore them, so an option of `RestoreMode` with two variants `NameValue` and `NameOnly` is provided.

func NewNameOnlyRestoreVisitor

func NewNameOnlyRestoreVisitor(nameMap *NameMap) *RestoreVisitor

Create a `RestoreVisitor` with mode `NameOnly`, which ignores restoring of constant values

func NewRestoreVisitor

func NewRestoreVisitor(originExprs ExprMap, inferredTypes TypeMap, maskFunc MaskFunc, nameMap *NameMap, ignoreIntPK bool) *RestoreVisitor

Create a `RestoreVisitor` with mode `NameValue`

func (*RestoreVisitor) Enter

func (v *RestoreVisitor) Enter(in ast.Node) (_ ast.Node, skipChilren bool)

func (*RestoreVisitor) Leave

func (v *RestoreVisitor) Leave(in ast.Node) (_ ast.Node, ok bool)

type SQLWorker

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

func NewSQLWorker

func NewSQLWorker(db *tidb.Context, maskFunc MaskFunc, ignoreIntPK bool, nameMap *NameMap) *SQLWorker

func (*SQLWorker) MaskOne

func (w *SQLWorker) MaskOne(sql string) (string, error)

type Stats

type Stats struct {
	All         uint64
	Problematic uint64
	Success     uint64
}

func (Stats) Failed

func (s Stats) Failed() uint64

func (*Stats) Merge

func (s *Stats) Merge(other Stats)

func (Stats) PrintSummary

func (s Stats) PrintSummary()

func (Stats) String

func (s Stats) String() string

type TypeMap

type TypeMap = map[ReplaceMarker]*InferredType

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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