id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
157,900 | vitessio/vitess | go/vt/sqlparser/ast.go | replaceExprs | func replaceExprs(from, to Expr, exprs ...*Expr) bool {
for _, expr := range exprs {
if *expr == nil {
continue
}
if *expr == from {
*expr = to
return true
}
if (*expr).replace(from, to) {
return true
}
}
return false
} | go | func replaceExprs(from, to Expr, exprs ...*Expr) bool {
for _, expr := range exprs {
if *expr == nil {
continue
}
if *expr == from {
*expr = to
return true
}
if (*expr).replace(from, to) {
return true
}
}
return false
} | [
"func",
"replaceExprs",
"(",
"from",
",",
"to",
"Expr",
",",
"exprs",
"...",
"*",
"Expr",
")",
"bool",
"{",
"for",
"_",
",",
"expr",
":=",
"range",
"exprs",
"{",
"if",
"*",
"expr",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"*",
"expr",
"==",
"from",
"{",
"*",
"expr",
"=",
"to",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"if",
"(",
"*",
"expr",
")",
".",
"replace",
"(",
"from",
",",
"to",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // replaceExprs is a convenience function used by implementors
// of the replace method. | [
"replaceExprs",
"is",
"a",
"convenience",
"function",
"used",
"by",
"implementors",
"of",
"the",
"replace",
"method",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/ast.go#L2207-L2221 |
157,901 | vitessio/vitess | go/vt/sqlparser/ast.go | IsImpossible | func (node *ComparisonExpr) IsImpossible() bool {
var left, right *SQLVal
var ok bool
if left, ok = node.Left.(*SQLVal); !ok {
return false
}
if right, ok = node.Right.(*SQLVal); !ok {
return false
}
if node.Operator == NotEqualStr && left.Type == right.Type {
if len(left.Val) != len(right.Val) {
return false
}
for i := range left.Val {
if left.Val[i] != right.Val[i] {
return false
}
}
return true
}
return false
} | go | func (node *ComparisonExpr) IsImpossible() bool {
var left, right *SQLVal
var ok bool
if left, ok = node.Left.(*SQLVal); !ok {
return false
}
if right, ok = node.Right.(*SQLVal); !ok {
return false
}
if node.Operator == NotEqualStr && left.Type == right.Type {
if len(left.Val) != len(right.Val) {
return false
}
for i := range left.Val {
if left.Val[i] != right.Val[i] {
return false
}
}
return true
}
return false
} | [
"func",
"(",
"node",
"*",
"ComparisonExpr",
")",
"IsImpossible",
"(",
")",
"bool",
"{",
"var",
"left",
",",
"right",
"*",
"SQLVal",
"\n",
"var",
"ok",
"bool",
"\n",
"if",
"left",
",",
"ok",
"=",
"node",
".",
"Left",
".",
"(",
"*",
"SQLVal",
")",
";",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"right",
",",
"ok",
"=",
"node",
".",
"Right",
".",
"(",
"*",
"SQLVal",
")",
";",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"node",
".",
"Operator",
"==",
"NotEqualStr",
"&&",
"left",
".",
"Type",
"==",
"right",
".",
"Type",
"{",
"if",
"len",
"(",
"left",
".",
"Val",
")",
"!=",
"len",
"(",
"right",
".",
"Val",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"left",
".",
"Val",
"{",
"if",
"left",
".",
"Val",
"[",
"i",
"]",
"!=",
"right",
".",
"Val",
"[",
"i",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsImpossible returns true if the comparison in the expression can never evaluate to true.
// Note that this is not currently exhaustive to ALL impossible comparisons. | [
"IsImpossible",
"returns",
"true",
"if",
"the",
"comparison",
"in",
"the",
"expression",
"can",
"never",
"evaluate",
"to",
"true",
".",
"Note",
"that",
"this",
"is",
"not",
"currently",
"exhaustive",
"to",
"ALL",
"impossible",
"comparisons",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/ast.go#L2395-L2417 |
157,902 | vitessio/vitess | go/vt/sqlparser/ast.go | HexDecode | func (node *SQLVal) HexDecode() ([]byte, error) {
dst := make([]byte, hex.DecodedLen(len([]byte(node.Val))))
_, err := hex.Decode(dst, []byte(node.Val))
if err != nil {
return nil, err
}
return dst, err
} | go | func (node *SQLVal) HexDecode() ([]byte, error) {
dst := make([]byte, hex.DecodedLen(len([]byte(node.Val))))
_, err := hex.Decode(dst, []byte(node.Val))
if err != nil {
return nil, err
}
return dst, err
} | [
"func",
"(",
"node",
"*",
"SQLVal",
")",
"HexDecode",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"dst",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"hex",
".",
"DecodedLen",
"(",
"len",
"(",
"[",
"]",
"byte",
"(",
"node",
".",
"Val",
")",
")",
")",
")",
"\n",
"_",
",",
"err",
":=",
"hex",
".",
"Decode",
"(",
"dst",
",",
"[",
"]",
"byte",
"(",
"node",
".",
"Val",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"dst",
",",
"err",
"\n",
"}"
] | // HexDecode decodes the hexval into bytes. | [
"HexDecode",
"decodes",
"the",
"hexval",
"into",
"bytes",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/ast.go#L2616-L2623 |
157,903 | vitessio/vitess | go/vt/sqlparser/ast.go | Equal | func (node *ColName) Equal(c *ColName) bool {
// Failsafe: ColName should not be empty.
if node == nil || c == nil {
return false
}
return node.Name.Equal(c.Name) && node.Qualifier == c.Qualifier
} | go | func (node *ColName) Equal(c *ColName) bool {
// Failsafe: ColName should not be empty.
if node == nil || c == nil {
return false
}
return node.Name.Equal(c.Name) && node.Qualifier == c.Qualifier
} | [
"func",
"(",
"node",
"*",
"ColName",
")",
"Equal",
"(",
"c",
"*",
"ColName",
")",
"bool",
"{",
"// Failsafe: ColName should not be empty.",
"if",
"node",
"==",
"nil",
"||",
"c",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"node",
".",
"Name",
".",
"Equal",
"(",
"c",
".",
"Name",
")",
"&&",
"node",
".",
"Qualifier",
"==",
"c",
".",
"Qualifier",
"\n",
"}"
] | // Equal returns true if the column names match. | [
"Equal",
"returns",
"true",
"if",
"the",
"column",
"names",
"match",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/ast.go#L2696-L2702 |
157,904 | vitessio/vitess | go/vt/sqlparser/ast.go | Lowered | func (node ColIdent) Lowered() string {
if node.val == "" {
return ""
}
if node.lowered == "" {
node.lowered = strings.ToLower(node.val)
}
return node.lowered
} | go | func (node ColIdent) Lowered() string {
if node.val == "" {
return ""
}
if node.lowered == "" {
node.lowered = strings.ToLower(node.val)
}
return node.lowered
} | [
"func",
"(",
"node",
"ColIdent",
")",
"Lowered",
"(",
")",
"string",
"{",
"if",
"node",
".",
"val",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"node",
".",
"lowered",
"==",
"\"",
"\"",
"{",
"node",
".",
"lowered",
"=",
"strings",
".",
"ToLower",
"(",
"node",
".",
"val",
")",
"\n",
"}",
"\n",
"return",
"node",
".",
"lowered",
"\n",
"}"
] | // Lowered returns a lower-cased column name.
// This function should generally be used only for optimizing
// comparisons. | [
"Lowered",
"returns",
"a",
"lower",
"-",
"cased",
"column",
"name",
".",
"This",
"function",
"should",
"generally",
"be",
"used",
"only",
"for",
"optimizing",
"comparisons",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/ast.go#L3669-L3677 |
157,905 | vitessio/vitess | go/vt/sqlparser/ast.go | Equal | func (node ColIdent) Equal(in ColIdent) bool {
return node.Lowered() == in.Lowered()
} | go | func (node ColIdent) Equal(in ColIdent) bool {
return node.Lowered() == in.Lowered()
} | [
"func",
"(",
"node",
"ColIdent",
")",
"Equal",
"(",
"in",
"ColIdent",
")",
"bool",
"{",
"return",
"node",
".",
"Lowered",
"(",
")",
"==",
"in",
".",
"Lowered",
"(",
")",
"\n",
"}"
] | // Equal performs a case-insensitive compare. | [
"Equal",
"performs",
"a",
"case",
"-",
"insensitive",
"compare",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/ast.go#L3680-L3682 |
157,906 | vitessio/vitess | go/vt/sqlparser/ast.go | EqualString | func (node ColIdent) EqualString(str string) bool {
return node.Lowered() == strings.ToLower(str)
} | go | func (node ColIdent) EqualString(str string) bool {
return node.Lowered() == strings.ToLower(str)
} | [
"func",
"(",
"node",
"ColIdent",
")",
"EqualString",
"(",
"str",
"string",
")",
"bool",
"{",
"return",
"node",
".",
"Lowered",
"(",
")",
"==",
"strings",
".",
"ToLower",
"(",
"str",
")",
"\n",
"}"
] | // EqualString performs a case-insensitive compare with str. | [
"EqualString",
"performs",
"a",
"case",
"-",
"insensitive",
"compare",
"with",
"str",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/ast.go#L3685-L3687 |
157,907 | vitessio/vitess | go/vt/workflow/resharding/workflow.go | validateWorkflow | func validateWorkflow(m *workflow.Manager, keyspace string, vtworkers, sourceShards, destinationShards []string, minHealthyRdonlyTablets string) error {
if len(sourceShards) == 0 || len(destinationShards) == 0 {
return fmt.Errorf("invalid source or destination shards")
}
if len(vtworkers) != len(destinationShards) {
return fmt.Errorf("there are %v vtworkers, %v destination shards: the number should be same", len(vtworkers), len(destinationShards))
}
splitRatio := len(destinationShards) / len(sourceShards)
if minHealthyRdonlyTabletsVal, err := strconv.Atoi(minHealthyRdonlyTablets); err != nil || minHealthyRdonlyTabletsVal < splitRatio {
return fmt.Errorf("there are not enough rdonly tablets in source shards. You need at least %v, it got: %v", splitRatio, minHealthyRdonlyTablets)
}
// find the OverlappingShards in the keyspace
osList, err := topotools.FindOverlappingShards(context.Background(), m.TopoServer(), keyspace)
if err != nil {
return fmt.Errorf("cannot FindOverlappingShards in %v: %v", keyspace, err)
}
// find the shard we mentioned in there, if any
os := topotools.OverlappingShardsForShard(osList, sourceShards[0])
if os == nil {
return fmt.Errorf("the specified source shard %v/%v is not in any overlapping shard", keyspace, sourceShards[0])
}
for _, sourceShard := range sourceShards {
if !os.ContainsShard(sourceShard) {
return fmt.Errorf("the specified source shard %v/%v is not in any overlapping shard", keyspace, sourceShard)
}
}
for _, destinationShard := range destinationShards {
if !os.ContainsShard(destinationShard) {
return fmt.Errorf("the specified destination shard %v/%v is not in any overlapping shard", keyspace, destinationShard)
}
}
return nil
} | go | func validateWorkflow(m *workflow.Manager, keyspace string, vtworkers, sourceShards, destinationShards []string, minHealthyRdonlyTablets string) error {
if len(sourceShards) == 0 || len(destinationShards) == 0 {
return fmt.Errorf("invalid source or destination shards")
}
if len(vtworkers) != len(destinationShards) {
return fmt.Errorf("there are %v vtworkers, %v destination shards: the number should be same", len(vtworkers), len(destinationShards))
}
splitRatio := len(destinationShards) / len(sourceShards)
if minHealthyRdonlyTabletsVal, err := strconv.Atoi(minHealthyRdonlyTablets); err != nil || minHealthyRdonlyTabletsVal < splitRatio {
return fmt.Errorf("there are not enough rdonly tablets in source shards. You need at least %v, it got: %v", splitRatio, minHealthyRdonlyTablets)
}
// find the OverlappingShards in the keyspace
osList, err := topotools.FindOverlappingShards(context.Background(), m.TopoServer(), keyspace)
if err != nil {
return fmt.Errorf("cannot FindOverlappingShards in %v: %v", keyspace, err)
}
// find the shard we mentioned in there, if any
os := topotools.OverlappingShardsForShard(osList, sourceShards[0])
if os == nil {
return fmt.Errorf("the specified source shard %v/%v is not in any overlapping shard", keyspace, sourceShards[0])
}
for _, sourceShard := range sourceShards {
if !os.ContainsShard(sourceShard) {
return fmt.Errorf("the specified source shard %v/%v is not in any overlapping shard", keyspace, sourceShard)
}
}
for _, destinationShard := range destinationShards {
if !os.ContainsShard(destinationShard) {
return fmt.Errorf("the specified destination shard %v/%v is not in any overlapping shard", keyspace, destinationShard)
}
}
return nil
} | [
"func",
"validateWorkflow",
"(",
"m",
"*",
"workflow",
".",
"Manager",
",",
"keyspace",
"string",
",",
"vtworkers",
",",
"sourceShards",
",",
"destinationShards",
"[",
"]",
"string",
",",
"minHealthyRdonlyTablets",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"sourceShards",
")",
"==",
"0",
"||",
"len",
"(",
"destinationShards",
")",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"vtworkers",
")",
"!=",
"len",
"(",
"destinationShards",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"vtworkers",
")",
",",
"len",
"(",
"destinationShards",
")",
")",
"\n",
"}",
"\n\n",
"splitRatio",
":=",
"len",
"(",
"destinationShards",
")",
"/",
"len",
"(",
"sourceShards",
")",
"\n",
"if",
"minHealthyRdonlyTabletsVal",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"minHealthyRdonlyTablets",
")",
";",
"err",
"!=",
"nil",
"||",
"minHealthyRdonlyTabletsVal",
"<",
"splitRatio",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"splitRatio",
",",
"minHealthyRdonlyTablets",
")",
"\n",
"}",
"\n\n",
"// find the OverlappingShards in the keyspace",
"osList",
",",
"err",
":=",
"topotools",
".",
"FindOverlappingShards",
"(",
"context",
".",
"Background",
"(",
")",
",",
"m",
".",
"TopoServer",
"(",
")",
",",
"keyspace",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyspace",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// find the shard we mentioned in there, if any",
"os",
":=",
"topotools",
".",
"OverlappingShardsForShard",
"(",
"osList",
",",
"sourceShards",
"[",
"0",
"]",
")",
"\n",
"if",
"os",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyspace",
",",
"sourceShards",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"sourceShard",
":=",
"range",
"sourceShards",
"{",
"if",
"!",
"os",
".",
"ContainsShard",
"(",
"sourceShard",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyspace",
",",
"sourceShard",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"destinationShard",
":=",
"range",
"destinationShards",
"{",
"if",
"!",
"os",
".",
"ContainsShard",
"(",
"destinationShard",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyspace",
",",
"destinationShard",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // validateWorkflow validates that workflow has valid input parameters. | [
"validateWorkflow",
"validates",
"that",
"workflow",
"has",
"valid",
"input",
"parameters",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/workflow/resharding/workflow.go#L229-L264 |
157,908 | vitessio/vitess | go/vt/workflow/resharding/workflow.go | initCheckpoint | func initCheckpoint(keyspace string, vtworkers, sourceShards, destinationShards []string, minHealthyRdonlyTablets, splitCmd, splitDiffDestTabletType string) (*workflowpb.WorkflowCheckpoint, error) {
tasks := make(map[string]*workflowpb.Task)
initTasks(tasks, phaseCopySchema, destinationShards, func(i int, shard string) map[string]string {
return map[string]string{
"keyspace": keyspace,
"source_shard": sourceShards[0],
"destination_shard": shard,
}
})
initTasks(tasks, phaseClone, sourceShards, func(i int, shard string) map[string]string {
return map[string]string{
"keyspace": keyspace,
"source_shard": shard,
"min_healthy_rdonly_tablets": minHealthyRdonlyTablets,
"split_cmd": splitCmd,
"vtworker": vtworkers[i],
}
})
initTasks(tasks, phaseWaitForFilteredReplication, destinationShards, func(i int, shard string) map[string]string {
return map[string]string{
"keyspace": keyspace,
"destination_shard": shard,
}
})
initTasks(tasks, phaseDiff, destinationShards, func(i int, shard string) map[string]string {
return map[string]string{
"keyspace": keyspace,
"destination_shard": shard,
"dest_tablet_type": splitDiffDestTabletType,
"vtworker": vtworkers[i],
}
})
initTasks(tasks, phaseMigrateRdonly, sourceShards, func(i int, shard string) map[string]string {
return map[string]string{
"keyspace": keyspace,
"source_shard": shard,
"served_type": topodatapb.TabletType_RDONLY.String(),
}
})
initTasks(tasks, phaseMigrateReplica, sourceShards, func(i int, shard string) map[string]string {
return map[string]string{
"keyspace": keyspace,
"source_shard": shard,
"served_type": topodatapb.TabletType_REPLICA.String(),
}
})
initTasks(tasks, phaseMigrateMaster, sourceShards, func(i int, shard string) map[string]string {
return map[string]string{
"keyspace": keyspace,
"source_shard": shard,
"served_type": topodatapb.TabletType_MASTER.String(),
}
})
return &workflowpb.WorkflowCheckpoint{
CodeVersion: codeVersion,
Tasks: tasks,
Settings: map[string]string{
"source_shards": strings.Join(sourceShards, ","),
"destination_shards": strings.Join(destinationShards, ","),
},
}, nil
} | go | func initCheckpoint(keyspace string, vtworkers, sourceShards, destinationShards []string, minHealthyRdonlyTablets, splitCmd, splitDiffDestTabletType string) (*workflowpb.WorkflowCheckpoint, error) {
tasks := make(map[string]*workflowpb.Task)
initTasks(tasks, phaseCopySchema, destinationShards, func(i int, shard string) map[string]string {
return map[string]string{
"keyspace": keyspace,
"source_shard": sourceShards[0],
"destination_shard": shard,
}
})
initTasks(tasks, phaseClone, sourceShards, func(i int, shard string) map[string]string {
return map[string]string{
"keyspace": keyspace,
"source_shard": shard,
"min_healthy_rdonly_tablets": minHealthyRdonlyTablets,
"split_cmd": splitCmd,
"vtworker": vtworkers[i],
}
})
initTasks(tasks, phaseWaitForFilteredReplication, destinationShards, func(i int, shard string) map[string]string {
return map[string]string{
"keyspace": keyspace,
"destination_shard": shard,
}
})
initTasks(tasks, phaseDiff, destinationShards, func(i int, shard string) map[string]string {
return map[string]string{
"keyspace": keyspace,
"destination_shard": shard,
"dest_tablet_type": splitDiffDestTabletType,
"vtworker": vtworkers[i],
}
})
initTasks(tasks, phaseMigrateRdonly, sourceShards, func(i int, shard string) map[string]string {
return map[string]string{
"keyspace": keyspace,
"source_shard": shard,
"served_type": topodatapb.TabletType_RDONLY.String(),
}
})
initTasks(tasks, phaseMigrateReplica, sourceShards, func(i int, shard string) map[string]string {
return map[string]string{
"keyspace": keyspace,
"source_shard": shard,
"served_type": topodatapb.TabletType_REPLICA.String(),
}
})
initTasks(tasks, phaseMigrateMaster, sourceShards, func(i int, shard string) map[string]string {
return map[string]string{
"keyspace": keyspace,
"source_shard": shard,
"served_type": topodatapb.TabletType_MASTER.String(),
}
})
return &workflowpb.WorkflowCheckpoint{
CodeVersion: codeVersion,
Tasks: tasks,
Settings: map[string]string{
"source_shards": strings.Join(sourceShards, ","),
"destination_shards": strings.Join(destinationShards, ","),
},
}, nil
} | [
"func",
"initCheckpoint",
"(",
"keyspace",
"string",
",",
"vtworkers",
",",
"sourceShards",
",",
"destinationShards",
"[",
"]",
"string",
",",
"minHealthyRdonlyTablets",
",",
"splitCmd",
",",
"splitDiffDestTabletType",
"string",
")",
"(",
"*",
"workflowpb",
".",
"WorkflowCheckpoint",
",",
"error",
")",
"{",
"tasks",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"workflowpb",
".",
"Task",
")",
"\n",
"initTasks",
"(",
"tasks",
",",
"phaseCopySchema",
",",
"destinationShards",
",",
"func",
"(",
"i",
"int",
",",
"shard",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"return",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"keyspace",
",",
"\"",
"\"",
":",
"sourceShards",
"[",
"0",
"]",
",",
"\"",
"\"",
":",
"shard",
",",
"}",
"\n",
"}",
")",
"\n",
"initTasks",
"(",
"tasks",
",",
"phaseClone",
",",
"sourceShards",
",",
"func",
"(",
"i",
"int",
",",
"shard",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"return",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"keyspace",
",",
"\"",
"\"",
":",
"shard",
",",
"\"",
"\"",
":",
"minHealthyRdonlyTablets",
",",
"\"",
"\"",
":",
"splitCmd",
",",
"\"",
"\"",
":",
"vtworkers",
"[",
"i",
"]",
",",
"}",
"\n",
"}",
")",
"\n",
"initTasks",
"(",
"tasks",
",",
"phaseWaitForFilteredReplication",
",",
"destinationShards",
",",
"func",
"(",
"i",
"int",
",",
"shard",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"return",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"keyspace",
",",
"\"",
"\"",
":",
"shard",
",",
"}",
"\n",
"}",
")",
"\n",
"initTasks",
"(",
"tasks",
",",
"phaseDiff",
",",
"destinationShards",
",",
"func",
"(",
"i",
"int",
",",
"shard",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"return",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"keyspace",
",",
"\"",
"\"",
":",
"shard",
",",
"\"",
"\"",
":",
"splitDiffDestTabletType",
",",
"\"",
"\"",
":",
"vtworkers",
"[",
"i",
"]",
",",
"}",
"\n",
"}",
")",
"\n",
"initTasks",
"(",
"tasks",
",",
"phaseMigrateRdonly",
",",
"sourceShards",
",",
"func",
"(",
"i",
"int",
",",
"shard",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"return",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"keyspace",
",",
"\"",
"\"",
":",
"shard",
",",
"\"",
"\"",
":",
"topodatapb",
".",
"TabletType_RDONLY",
".",
"String",
"(",
")",
",",
"}",
"\n",
"}",
")",
"\n",
"initTasks",
"(",
"tasks",
",",
"phaseMigrateReplica",
",",
"sourceShards",
",",
"func",
"(",
"i",
"int",
",",
"shard",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"return",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"keyspace",
",",
"\"",
"\"",
":",
"shard",
",",
"\"",
"\"",
":",
"topodatapb",
".",
"TabletType_REPLICA",
".",
"String",
"(",
")",
",",
"}",
"\n",
"}",
")",
"\n",
"initTasks",
"(",
"tasks",
",",
"phaseMigrateMaster",
",",
"sourceShards",
",",
"func",
"(",
"i",
"int",
",",
"shard",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"return",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"keyspace",
",",
"\"",
"\"",
":",
"shard",
",",
"\"",
"\"",
":",
"topodatapb",
".",
"TabletType_MASTER",
".",
"String",
"(",
")",
",",
"}",
"\n",
"}",
")",
"\n\n",
"return",
"&",
"workflowpb",
".",
"WorkflowCheckpoint",
"{",
"CodeVersion",
":",
"codeVersion",
",",
"Tasks",
":",
"tasks",
",",
"Settings",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"strings",
".",
"Join",
"(",
"sourceShards",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
":",
"strings",
".",
"Join",
"(",
"destinationShards",
",",
"\"",
"\"",
")",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // initCheckpoint initialize the checkpoint for the horizontal workflow. | [
"initCheckpoint",
"initialize",
"the",
"checkpoint",
"for",
"the",
"horizontal",
"workflow",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/workflow/resharding/workflow.go#L267-L329 |
157,909 | vitessio/vitess | go/vt/workflow/resharding/workflow.go | Run | func (hw *horizontalReshardingWorkflow) Run(ctx context.Context, manager *workflow.Manager, wi *topo.WorkflowInfo) error {
hw.ctx = ctx
hw.wi = wi
hw.checkpointWriter = workflow.NewCheckpointWriter(hw.topoServer, hw.checkpoint, hw.wi)
hw.rootUINode.Display = workflow.NodeDisplayDeterminate
hw.rootUINode.BroadcastChanges(true /* updateChildren */)
if err := hw.runWorkflow(); err != nil {
return err
}
hw.setUIMessage(fmt.Sprintf("Horizontal Resharding is finished sucessfully."))
return nil
} | go | func (hw *horizontalReshardingWorkflow) Run(ctx context.Context, manager *workflow.Manager, wi *topo.WorkflowInfo) error {
hw.ctx = ctx
hw.wi = wi
hw.checkpointWriter = workflow.NewCheckpointWriter(hw.topoServer, hw.checkpoint, hw.wi)
hw.rootUINode.Display = workflow.NodeDisplayDeterminate
hw.rootUINode.BroadcastChanges(true /* updateChildren */)
if err := hw.runWorkflow(); err != nil {
return err
}
hw.setUIMessage(fmt.Sprintf("Horizontal Resharding is finished sucessfully."))
return nil
} | [
"func",
"(",
"hw",
"*",
"horizontalReshardingWorkflow",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
",",
"manager",
"*",
"workflow",
".",
"Manager",
",",
"wi",
"*",
"topo",
".",
"WorkflowInfo",
")",
"error",
"{",
"hw",
".",
"ctx",
"=",
"ctx",
"\n",
"hw",
".",
"wi",
"=",
"wi",
"\n",
"hw",
".",
"checkpointWriter",
"=",
"workflow",
".",
"NewCheckpointWriter",
"(",
"hw",
".",
"topoServer",
",",
"hw",
".",
"checkpoint",
",",
"hw",
".",
"wi",
")",
"\n",
"hw",
".",
"rootUINode",
".",
"Display",
"=",
"workflow",
".",
"NodeDisplayDeterminate",
"\n",
"hw",
".",
"rootUINode",
".",
"BroadcastChanges",
"(",
"true",
"/* updateChildren */",
")",
"\n\n",
"if",
"err",
":=",
"hw",
".",
"runWorkflow",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"hw",
".",
"setUIMessage",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Run executes the horizontal resharding process.
// It implements the workflow.Workflow interface. | [
"Run",
"executes",
"the",
"horizontal",
"resharding",
"process",
".",
"It",
"implements",
"the",
"workflow",
".",
"Workflow",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/workflow/resharding/workflow.go#L364-L376 |
157,910 | vitessio/vitess | go/vt/workflow/resharding/workflow.go | WorkflowPhases | func WorkflowPhases() []string {
return []string{
string(phaseCopySchema),
string(phaseClone),
string(phaseWaitForFilteredReplication),
string(phaseDiff),
string(phaseMigrateReplica),
string(phaseMigrateRdonly),
string(phaseMigrateMaster),
}
} | go | func WorkflowPhases() []string {
return []string{
string(phaseCopySchema),
string(phaseClone),
string(phaseWaitForFilteredReplication),
string(phaseDiff),
string(phaseMigrateReplica),
string(phaseMigrateRdonly),
string(phaseMigrateMaster),
}
} | [
"func",
"WorkflowPhases",
"(",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"string",
"(",
"phaseCopySchema",
")",
",",
"string",
"(",
"phaseClone",
")",
",",
"string",
"(",
"phaseWaitForFilteredReplication",
")",
",",
"string",
"(",
"phaseDiff",
")",
",",
"string",
"(",
"phaseMigrateReplica",
")",
",",
"string",
"(",
"phaseMigrateRdonly",
")",
",",
"string",
"(",
"phaseMigrateMaster",
")",
",",
"}",
"\n",
"}"
] | // WorkflowPhases returns phases for resharding workflow | [
"WorkflowPhases",
"returns",
"phases",
"for",
"resharding",
"workflow"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/workflow/resharding/workflow.go#L429-L439 |
157,911 | vitessio/vitess | go/vt/vitessdriver/streaming_rows.go | newStreamingRows | func newStreamingRows(stream sqltypes.ResultStream, conv *converter) driver.Rows {
return &streamingRows{
stream: stream,
convert: conv,
}
} | go | func newStreamingRows(stream sqltypes.ResultStream, conv *converter) driver.Rows {
return &streamingRows{
stream: stream,
convert: conv,
}
} | [
"func",
"newStreamingRows",
"(",
"stream",
"sqltypes",
".",
"ResultStream",
",",
"conv",
"*",
"converter",
")",
"driver",
".",
"Rows",
"{",
"return",
"&",
"streamingRows",
"{",
"stream",
":",
"stream",
",",
"convert",
":",
"conv",
",",
"}",
"\n",
"}"
] | // newStreamingRows creates a new streamingRows from stream. | [
"newStreamingRows",
"creates",
"a",
"new",
"streamingRows",
"from",
"stream",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vitessdriver/streaming_rows.go#L40-L45 |
157,912 | vitessio/vitess | go/vt/vitessdriver/streaming_rows.go | checkFields | func (ri *streamingRows) checkFields() error {
if ri.fields != nil {
return nil
}
qr, err := ri.stream.Recv()
if err != nil {
return err
}
ri.fields = qr.Fields
if ri.fields == nil {
return errors.New("first packet did not return fields")
}
return nil
} | go | func (ri *streamingRows) checkFields() error {
if ri.fields != nil {
return nil
}
qr, err := ri.stream.Recv()
if err != nil {
return err
}
ri.fields = qr.Fields
if ri.fields == nil {
return errors.New("first packet did not return fields")
}
return nil
} | [
"func",
"(",
"ri",
"*",
"streamingRows",
")",
"checkFields",
"(",
")",
"error",
"{",
"if",
"ri",
".",
"fields",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"qr",
",",
"err",
":=",
"ri",
".",
"stream",
".",
"Recv",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ri",
".",
"fields",
"=",
"qr",
".",
"Fields",
"\n",
"if",
"ri",
".",
"fields",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // checkFields fetches the first packet from the channel, which
// should contain the field info. | [
"checkFields",
"fetches",
"the",
"first",
"packet",
"from",
"the",
"channel",
"which",
"should",
"contain",
"the",
"field",
"info",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vitessdriver/streaming_rows.go#L92-L105 |
157,913 | vitessio/vitess | go/vt/mysqlctl/filebackupstorage/file.go | AddFile | func (fbh *FileBackupHandle) AddFile(ctx context.Context, filename string, filesize int64) (io.WriteCloser, error) {
if fbh.readOnly {
return nil, fmt.Errorf("AddFile cannot be called on read-only backup")
}
p := path.Join(*FileBackupStorageRoot, fbh.dir, fbh.name, filename)
return os.Create(p)
} | go | func (fbh *FileBackupHandle) AddFile(ctx context.Context, filename string, filesize int64) (io.WriteCloser, error) {
if fbh.readOnly {
return nil, fmt.Errorf("AddFile cannot be called on read-only backup")
}
p := path.Join(*FileBackupStorageRoot, fbh.dir, fbh.name, filename)
return os.Create(p)
} | [
"func",
"(",
"fbh",
"*",
"FileBackupHandle",
")",
"AddFile",
"(",
"ctx",
"context",
".",
"Context",
",",
"filename",
"string",
",",
"filesize",
"int64",
")",
"(",
"io",
".",
"WriteCloser",
",",
"error",
")",
"{",
"if",
"fbh",
".",
"readOnly",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"p",
":=",
"path",
".",
"Join",
"(",
"*",
"FileBackupStorageRoot",
",",
"fbh",
".",
"dir",
",",
"fbh",
".",
"name",
",",
"filename",
")",
"\n",
"return",
"os",
".",
"Create",
"(",
"p",
")",
"\n",
"}"
] | // AddFile is part of the BackupHandle interface | [
"AddFile",
"is",
"part",
"of",
"the",
"BackupHandle",
"interface"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/filebackupstorage/file.go#L59-L65 |
157,914 | vitessio/vitess | go/vt/mysqlctl/filebackupstorage/file.go | EndBackup | func (fbh *FileBackupHandle) EndBackup(ctx context.Context) error {
if fbh.readOnly {
return fmt.Errorf("EndBackup cannot be called on read-only backup")
}
return nil
} | go | func (fbh *FileBackupHandle) EndBackup(ctx context.Context) error {
if fbh.readOnly {
return fmt.Errorf("EndBackup cannot be called on read-only backup")
}
return nil
} | [
"func",
"(",
"fbh",
"*",
"FileBackupHandle",
")",
"EndBackup",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"fbh",
".",
"readOnly",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // EndBackup is part of the BackupHandle interface | [
"EndBackup",
"is",
"part",
"of",
"the",
"BackupHandle",
"interface"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/filebackupstorage/file.go#L68-L73 |
157,915 | vitessio/vitess | go/vt/mysqlctl/filebackupstorage/file.go | AbortBackup | func (fbh *FileBackupHandle) AbortBackup(ctx context.Context) error {
if fbh.readOnly {
return fmt.Errorf("AbortBackup cannot be called on read-only backup")
}
return fbh.fbs.RemoveBackup(ctx, fbh.dir, fbh.name)
} | go | func (fbh *FileBackupHandle) AbortBackup(ctx context.Context) error {
if fbh.readOnly {
return fmt.Errorf("AbortBackup cannot be called on read-only backup")
}
return fbh.fbs.RemoveBackup(ctx, fbh.dir, fbh.name)
} | [
"func",
"(",
"fbh",
"*",
"FileBackupHandle",
")",
"AbortBackup",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"fbh",
".",
"readOnly",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"fbh",
".",
"fbs",
".",
"RemoveBackup",
"(",
"ctx",
",",
"fbh",
".",
"dir",
",",
"fbh",
".",
"name",
")",
"\n",
"}"
] | // AbortBackup is part of the BackupHandle interface | [
"AbortBackup",
"is",
"part",
"of",
"the",
"BackupHandle",
"interface"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/filebackupstorage/file.go#L76-L81 |
157,916 | vitessio/vitess | go/vt/mysqlctl/filebackupstorage/file.go | ReadFile | func (fbh *FileBackupHandle) ReadFile(ctx context.Context, filename string) (io.ReadCloser, error) {
if !fbh.readOnly {
return nil, fmt.Errorf("ReadFile cannot be called on read-write backup")
}
p := path.Join(*FileBackupStorageRoot, fbh.dir, fbh.name, filename)
return os.Open(p)
} | go | func (fbh *FileBackupHandle) ReadFile(ctx context.Context, filename string) (io.ReadCloser, error) {
if !fbh.readOnly {
return nil, fmt.Errorf("ReadFile cannot be called on read-write backup")
}
p := path.Join(*FileBackupStorageRoot, fbh.dir, fbh.name, filename)
return os.Open(p)
} | [
"func",
"(",
"fbh",
"*",
"FileBackupHandle",
")",
"ReadFile",
"(",
"ctx",
"context",
".",
"Context",
",",
"filename",
"string",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"if",
"!",
"fbh",
".",
"readOnly",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"p",
":=",
"path",
".",
"Join",
"(",
"*",
"FileBackupStorageRoot",
",",
"fbh",
".",
"dir",
",",
"fbh",
".",
"name",
",",
"filename",
")",
"\n",
"return",
"os",
".",
"Open",
"(",
"p",
")",
"\n",
"}"
] | // ReadFile is part of the BackupHandle interface | [
"ReadFile",
"is",
"part",
"of",
"the",
"BackupHandle",
"interface"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/filebackupstorage/file.go#L84-L90 |
157,917 | vitessio/vitess | go/vt/mysqlctl/filebackupstorage/file.go | ListBackups | func (fbs *FileBackupStorage) ListBackups(ctx context.Context, dir string) ([]backupstorage.BackupHandle, error) {
// ReadDir already sorts the results
p := path.Join(*FileBackupStorageRoot, dir)
fi, err := ioutil.ReadDir(p)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}
result := make([]backupstorage.BackupHandle, 0, len(fi))
for _, info := range fi {
if !info.IsDir() {
continue
}
if info.Name() == "." || info.Name() == ".." {
continue
}
result = append(result, &FileBackupHandle{
fbs: fbs,
dir: dir,
name: info.Name(),
readOnly: true,
})
}
return result, nil
} | go | func (fbs *FileBackupStorage) ListBackups(ctx context.Context, dir string) ([]backupstorage.BackupHandle, error) {
// ReadDir already sorts the results
p := path.Join(*FileBackupStorageRoot, dir)
fi, err := ioutil.ReadDir(p)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}
result := make([]backupstorage.BackupHandle, 0, len(fi))
for _, info := range fi {
if !info.IsDir() {
continue
}
if info.Name() == "." || info.Name() == ".." {
continue
}
result = append(result, &FileBackupHandle{
fbs: fbs,
dir: dir,
name: info.Name(),
readOnly: true,
})
}
return result, nil
} | [
"func",
"(",
"fbs",
"*",
"FileBackupStorage",
")",
"ListBackups",
"(",
"ctx",
"context",
".",
"Context",
",",
"dir",
"string",
")",
"(",
"[",
"]",
"backupstorage",
".",
"BackupHandle",
",",
"error",
")",
"{",
"// ReadDir already sorts the results",
"p",
":=",
"path",
".",
"Join",
"(",
"*",
"FileBackupStorageRoot",
",",
"dir",
")",
"\n",
"fi",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"result",
":=",
"make",
"(",
"[",
"]",
"backupstorage",
".",
"BackupHandle",
",",
"0",
",",
"len",
"(",
"fi",
")",
")",
"\n",
"for",
"_",
",",
"info",
":=",
"range",
"fi",
"{",
"if",
"!",
"info",
".",
"IsDir",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"info",
".",
"Name",
"(",
")",
"==",
"\"",
"\"",
"||",
"info",
".",
"Name",
"(",
")",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n",
"result",
"=",
"append",
"(",
"result",
",",
"&",
"FileBackupHandle",
"{",
"fbs",
":",
"fbs",
",",
"dir",
":",
"dir",
",",
"name",
":",
"info",
".",
"Name",
"(",
")",
",",
"readOnly",
":",
"true",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // ListBackups is part of the BackupStorage interface | [
"ListBackups",
"is",
"part",
"of",
"the",
"BackupStorage",
"interface"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/filebackupstorage/file.go#L96-L123 |
157,918 | vitessio/vitess | go/vt/mysqlctl/filebackupstorage/file.go | StartBackup | func (fbs *FileBackupStorage) StartBackup(ctx context.Context, dir, name string) (backupstorage.BackupHandle, error) {
// Make sure the directory exists.
p := path.Join(*FileBackupStorageRoot, dir)
if err := os.MkdirAll(p, os.ModePerm); err != nil {
return nil, err
}
// Create the subdirectory for this named backup.
p = path.Join(p, name)
if err := os.Mkdir(p, os.ModePerm); err != nil {
return nil, err
}
return &FileBackupHandle{
fbs: fbs,
dir: dir,
name: name,
readOnly: false,
}, nil
} | go | func (fbs *FileBackupStorage) StartBackup(ctx context.Context, dir, name string) (backupstorage.BackupHandle, error) {
// Make sure the directory exists.
p := path.Join(*FileBackupStorageRoot, dir)
if err := os.MkdirAll(p, os.ModePerm); err != nil {
return nil, err
}
// Create the subdirectory for this named backup.
p = path.Join(p, name)
if err := os.Mkdir(p, os.ModePerm); err != nil {
return nil, err
}
return &FileBackupHandle{
fbs: fbs,
dir: dir,
name: name,
readOnly: false,
}, nil
} | [
"func",
"(",
"fbs",
"*",
"FileBackupStorage",
")",
"StartBackup",
"(",
"ctx",
"context",
".",
"Context",
",",
"dir",
",",
"name",
"string",
")",
"(",
"backupstorage",
".",
"BackupHandle",
",",
"error",
")",
"{",
"// Make sure the directory exists.",
"p",
":=",
"path",
".",
"Join",
"(",
"*",
"FileBackupStorageRoot",
",",
"dir",
")",
"\n",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"p",
",",
"os",
".",
"ModePerm",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Create the subdirectory for this named backup.",
"p",
"=",
"path",
".",
"Join",
"(",
"p",
",",
"name",
")",
"\n",
"if",
"err",
":=",
"os",
".",
"Mkdir",
"(",
"p",
",",
"os",
".",
"ModePerm",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"FileBackupHandle",
"{",
"fbs",
":",
"fbs",
",",
"dir",
":",
"dir",
",",
"name",
":",
"name",
",",
"readOnly",
":",
"false",
",",
"}",
",",
"nil",
"\n",
"}"
] | // StartBackup is part of the BackupStorage interface | [
"StartBackup",
"is",
"part",
"of",
"the",
"BackupStorage",
"interface"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/filebackupstorage/file.go#L126-L145 |
157,919 | vitessio/vitess | go/vt/mysqlctl/filebackupstorage/file.go | RemoveBackup | func (fbs *FileBackupStorage) RemoveBackup(ctx context.Context, dir, name string) error {
p := path.Join(*FileBackupStorageRoot, dir, name)
return os.RemoveAll(p)
} | go | func (fbs *FileBackupStorage) RemoveBackup(ctx context.Context, dir, name string) error {
p := path.Join(*FileBackupStorageRoot, dir, name)
return os.RemoveAll(p)
} | [
"func",
"(",
"fbs",
"*",
"FileBackupStorage",
")",
"RemoveBackup",
"(",
"ctx",
"context",
".",
"Context",
",",
"dir",
",",
"name",
"string",
")",
"error",
"{",
"p",
":=",
"path",
".",
"Join",
"(",
"*",
"FileBackupStorageRoot",
",",
"dir",
",",
"name",
")",
"\n",
"return",
"os",
".",
"RemoveAll",
"(",
"p",
")",
"\n",
"}"
] | // RemoveBackup is part of the BackupStorage interface | [
"RemoveBackup",
"is",
"part",
"of",
"the",
"BackupStorage",
"interface"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/filebackupstorage/file.go#L148-L151 |
157,920 | vitessio/vitess | go/sync2/atomic.go | Set | func (s *AtomicString) Set(str string) {
s.mu.Lock()
s.str = str
s.mu.Unlock()
} | go | func (s *AtomicString) Set(str string) {
s.mu.Lock()
s.str = str
s.mu.Unlock()
} | [
"func",
"(",
"s",
"*",
"AtomicString",
")",
"Set",
"(",
"str",
"string",
")",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"s",
".",
"str",
"=",
"str",
"\n",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // Set atomically sets str as new value. | [
"Set",
"atomically",
"sets",
"str",
"as",
"new",
"value",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/sync2/atomic.go#L163-L167 |
157,921 | vitessio/vitess | go/sync2/atomic.go | Get | func (s *AtomicString) Get() string {
s.mu.Lock()
str := s.str
s.mu.Unlock()
return str
} | go | func (s *AtomicString) Get() string {
s.mu.Lock()
str := s.str
s.mu.Unlock()
return str
} | [
"func",
"(",
"s",
"*",
"AtomicString",
")",
"Get",
"(",
")",
"string",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"str",
":=",
"s",
".",
"str",
"\n",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"str",
"\n",
"}"
] | // Get atomically returns the current value. | [
"Get",
"atomically",
"returns",
"the",
"current",
"value",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/sync2/atomic.go#L170-L175 |
157,922 | vitessio/vitess | go/vt/vtgate/vindexes/unicodeloosemd5.go | NewUnicodeLooseMD5 | func NewUnicodeLooseMD5(name string, _ map[string]string) (Vindex, error) {
return &UnicodeLooseMD5{name: name}, nil
} | go | func NewUnicodeLooseMD5(name string, _ map[string]string) (Vindex, error) {
return &UnicodeLooseMD5{name: name}, nil
} | [
"func",
"NewUnicodeLooseMD5",
"(",
"name",
"string",
",",
"_",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"Vindex",
",",
"error",
")",
"{",
"return",
"&",
"UnicodeLooseMD5",
"{",
"name",
":",
"name",
"}",
",",
"nil",
"\n",
"}"
] | // NewUnicodeLooseMD5 creates a new UnicodeLooseMD5. | [
"NewUnicodeLooseMD5",
"creates",
"a",
"new",
"UnicodeLooseMD5",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/unicodeloosemd5.go#L46-L48 |
157,923 | vitessio/vitess | go/vt/sqlparser/analyzer.go | StmtType | func StmtType(stmtType int) string {
switch stmtType {
case StmtSelect:
return "SELECT"
case StmtStream:
return "STREAM"
case StmtInsert:
return "INSERT"
case StmtReplace:
return "REPLACE"
case StmtUpdate:
return "UPDATE"
case StmtDelete:
return "DELETE"
case StmtDDL:
return "DDL"
case StmtBegin:
return "BEGIN"
case StmtCommit:
return "COMMIT"
case StmtRollback:
return "ROLLBACK"
case StmtSet:
return "SET"
case StmtShow:
return "SHOW"
case StmtUse:
return "USE"
case StmtOther:
return "OTHER"
default:
return "UNKNOWN"
}
} | go | func StmtType(stmtType int) string {
switch stmtType {
case StmtSelect:
return "SELECT"
case StmtStream:
return "STREAM"
case StmtInsert:
return "INSERT"
case StmtReplace:
return "REPLACE"
case StmtUpdate:
return "UPDATE"
case StmtDelete:
return "DELETE"
case StmtDDL:
return "DDL"
case StmtBegin:
return "BEGIN"
case StmtCommit:
return "COMMIT"
case StmtRollback:
return "ROLLBACK"
case StmtSet:
return "SET"
case StmtShow:
return "SHOW"
case StmtUse:
return "USE"
case StmtOther:
return "OTHER"
default:
return "UNKNOWN"
}
} | [
"func",
"StmtType",
"(",
"stmtType",
"int",
")",
"string",
"{",
"switch",
"stmtType",
"{",
"case",
"StmtSelect",
":",
"return",
"\"",
"\"",
"\n",
"case",
"StmtStream",
":",
"return",
"\"",
"\"",
"\n",
"case",
"StmtInsert",
":",
"return",
"\"",
"\"",
"\n",
"case",
"StmtReplace",
":",
"return",
"\"",
"\"",
"\n",
"case",
"StmtUpdate",
":",
"return",
"\"",
"\"",
"\n",
"case",
"StmtDelete",
":",
"return",
"\"",
"\"",
"\n",
"case",
"StmtDDL",
":",
"return",
"\"",
"\"",
"\n",
"case",
"StmtBegin",
":",
"return",
"\"",
"\"",
"\n",
"case",
"StmtCommit",
":",
"return",
"\"",
"\"",
"\n",
"case",
"StmtRollback",
":",
"return",
"\"",
"\"",
"\n",
"case",
"StmtSet",
":",
"return",
"\"",
"\"",
"\n",
"case",
"StmtShow",
":",
"return",
"\"",
"\"",
"\n",
"case",
"StmtUse",
":",
"return",
"\"",
"\"",
"\n",
"case",
"StmtOther",
":",
"return",
"\"",
"\"",
"\n",
"default",
":",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"}"
] | // StmtType returns the statement type as a string | [
"StmtType",
"returns",
"the",
"statement",
"type",
"as",
"a",
"string"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/analyzer.go#L113-L146 |
157,924 | vitessio/vitess | go/vt/sqlparser/analyzer.go | IsDML | func IsDML(sql string) bool {
switch Preview(sql) {
case StmtInsert, StmtReplace, StmtUpdate, StmtDelete:
return true
}
return false
} | go | func IsDML(sql string) bool {
switch Preview(sql) {
case StmtInsert, StmtReplace, StmtUpdate, StmtDelete:
return true
}
return false
} | [
"func",
"IsDML",
"(",
"sql",
"string",
")",
"bool",
"{",
"switch",
"Preview",
"(",
"sql",
")",
"{",
"case",
"StmtInsert",
",",
"StmtReplace",
",",
"StmtUpdate",
",",
"StmtDelete",
":",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsDML returns true if the query is an INSERT, UPDATE or DELETE statement. | [
"IsDML",
"returns",
"true",
"if",
"the",
"query",
"is",
"an",
"INSERT",
"UPDATE",
"or",
"DELETE",
"statement",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/analyzer.go#L149-L155 |
157,925 | vitessio/vitess | go/vt/sqlparser/analyzer.go | GetTableName | func GetTableName(node SimpleTableExpr) TableIdent {
if n, ok := node.(TableName); ok && n.Qualifier.IsEmpty() {
return n.Name
}
// sub-select or '.' expression
return NewTableIdent("")
} | go | func GetTableName(node SimpleTableExpr) TableIdent {
if n, ok := node.(TableName); ok && n.Qualifier.IsEmpty() {
return n.Name
}
// sub-select or '.' expression
return NewTableIdent("")
} | [
"func",
"GetTableName",
"(",
"node",
"SimpleTableExpr",
")",
"TableIdent",
"{",
"if",
"n",
",",
"ok",
":=",
"node",
".",
"(",
"TableName",
")",
";",
"ok",
"&&",
"n",
".",
"Qualifier",
".",
"IsEmpty",
"(",
")",
"{",
"return",
"n",
".",
"Name",
"\n",
"}",
"\n",
"// sub-select or '.' expression",
"return",
"NewTableIdent",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // GetTableName returns the table name from the SimpleTableExpr
// only if it's a simple expression. Otherwise, it returns "". | [
"GetTableName",
"returns",
"the",
"table",
"name",
"from",
"the",
"SimpleTableExpr",
"only",
"if",
"it",
"s",
"a",
"simple",
"expression",
".",
"Otherwise",
"it",
"returns",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/analyzer.go#L159-L165 |
157,926 | vitessio/vitess | go/vt/sqlparser/analyzer.go | IsValue | func IsValue(node Expr) bool {
switch v := node.(type) {
case *SQLVal:
switch v.Type {
case StrVal, HexVal, IntVal, ValArg:
return true
}
}
return false
} | go | func IsValue(node Expr) bool {
switch v := node.(type) {
case *SQLVal:
switch v.Type {
case StrVal, HexVal, IntVal, ValArg:
return true
}
}
return false
} | [
"func",
"IsValue",
"(",
"node",
"Expr",
")",
"bool",
"{",
"switch",
"v",
":=",
"node",
".",
"(",
"type",
")",
"{",
"case",
"*",
"SQLVal",
":",
"switch",
"v",
".",
"Type",
"{",
"case",
"StrVal",
",",
"HexVal",
",",
"IntVal",
",",
"ValArg",
":",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsValue returns true if the Expr is a string, integral or value arg.
// NULL is not considered to be a value. | [
"IsValue",
"returns",
"true",
"if",
"the",
"Expr",
"is",
"a",
"string",
"integral",
"or",
"value",
"arg",
".",
"NULL",
"is",
"not",
"considered",
"to",
"be",
"a",
"value",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/analyzer.go#L175-L184 |
157,927 | vitessio/vitess | go/vt/sqlparser/analyzer.go | IsSimpleTuple | func IsSimpleTuple(node Expr) bool {
switch vals := node.(type) {
case ValTuple:
for _, n := range vals {
if !IsValue(n) {
return false
}
}
return true
case ListArg:
return true
}
// It's a subquery
return false
} | go | func IsSimpleTuple(node Expr) bool {
switch vals := node.(type) {
case ValTuple:
for _, n := range vals {
if !IsValue(n) {
return false
}
}
return true
case ListArg:
return true
}
// It's a subquery
return false
} | [
"func",
"IsSimpleTuple",
"(",
"node",
"Expr",
")",
"bool",
"{",
"switch",
"vals",
":=",
"node",
".",
"(",
"type",
")",
"{",
"case",
"ValTuple",
":",
"for",
"_",
",",
"n",
":=",
"range",
"vals",
"{",
"if",
"!",
"IsValue",
"(",
"n",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"case",
"ListArg",
":",
"return",
"true",
"\n",
"}",
"\n",
"// It's a subquery",
"return",
"false",
"\n",
"}"
] | // IsSimpleTuple returns true if the Expr is a ValTuple that
// contains simple values or if it's a list arg. | [
"IsSimpleTuple",
"returns",
"true",
"if",
"the",
"Expr",
"is",
"a",
"ValTuple",
"that",
"contains",
"simple",
"values",
"or",
"if",
"it",
"s",
"a",
"list",
"arg",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/analyzer.go#L197-L211 |
157,928 | vitessio/vitess | go/vt/sqlparser/analyzer.go | ExtractSetValues | func ExtractSetValues(sql string) (keyValues map[SetKey]interface{}, scope string, err error) {
stmt, err := Parse(sql)
if err != nil {
return nil, "", err
}
setStmt, ok := stmt.(*Set)
if !ok {
return nil, "", fmt.Errorf("ast did not yield *sqlparser.Set: %T", stmt)
}
result := make(map[SetKey]interface{})
for _, expr := range setStmt.Exprs {
scope := ImplicitStr
key := expr.Name.Lowered()
switch {
case strings.HasPrefix(key, "@@global."):
scope = GlobalStr
key = strings.TrimPrefix(key, "@@global.")
case strings.HasPrefix(key, "@@session."):
scope = SessionStr
key = strings.TrimPrefix(key, "@@session.")
case strings.HasPrefix(key, "@@"):
key = strings.TrimPrefix(key, "@@")
}
if strings.HasPrefix(expr.Name.Lowered(), "@@") {
if setStmt.Scope != "" && scope != "" {
return nil, "", fmt.Errorf("unsupported in set: mixed using of variable scope")
}
_, out := NewStringTokenizer(key).Scan()
key = string(out)
}
setKey := SetKey{
Key: key,
Scope: scope,
}
switch expr := expr.Expr.(type) {
case *SQLVal:
switch expr.Type {
case StrVal:
result[setKey] = strings.ToLower(string(expr.Val))
case IntVal:
num, err := strconv.ParseInt(string(expr.Val), 0, 64)
if err != nil {
return nil, "", err
}
result[setKey] = num
default:
return nil, "", fmt.Errorf("invalid value type: %v", String(expr))
}
case BoolVal:
var val int64
if expr {
val = 1
}
result[setKey] = val
case *ColName:
result[setKey] = expr.Name.String()
case *NullVal:
result[setKey] = nil
case *Default:
result[setKey] = "default"
default:
return nil, "", fmt.Errorf("invalid syntax: %s", String(expr))
}
}
return result, strings.ToLower(setStmt.Scope), nil
} | go | func ExtractSetValues(sql string) (keyValues map[SetKey]interface{}, scope string, err error) {
stmt, err := Parse(sql)
if err != nil {
return nil, "", err
}
setStmt, ok := stmt.(*Set)
if !ok {
return nil, "", fmt.Errorf("ast did not yield *sqlparser.Set: %T", stmt)
}
result := make(map[SetKey]interface{})
for _, expr := range setStmt.Exprs {
scope := ImplicitStr
key := expr.Name.Lowered()
switch {
case strings.HasPrefix(key, "@@global."):
scope = GlobalStr
key = strings.TrimPrefix(key, "@@global.")
case strings.HasPrefix(key, "@@session."):
scope = SessionStr
key = strings.TrimPrefix(key, "@@session.")
case strings.HasPrefix(key, "@@"):
key = strings.TrimPrefix(key, "@@")
}
if strings.HasPrefix(expr.Name.Lowered(), "@@") {
if setStmt.Scope != "" && scope != "" {
return nil, "", fmt.Errorf("unsupported in set: mixed using of variable scope")
}
_, out := NewStringTokenizer(key).Scan()
key = string(out)
}
setKey := SetKey{
Key: key,
Scope: scope,
}
switch expr := expr.Expr.(type) {
case *SQLVal:
switch expr.Type {
case StrVal:
result[setKey] = strings.ToLower(string(expr.Val))
case IntVal:
num, err := strconv.ParseInt(string(expr.Val), 0, 64)
if err != nil {
return nil, "", err
}
result[setKey] = num
default:
return nil, "", fmt.Errorf("invalid value type: %v", String(expr))
}
case BoolVal:
var val int64
if expr {
val = 1
}
result[setKey] = val
case *ColName:
result[setKey] = expr.Name.String()
case *NullVal:
result[setKey] = nil
case *Default:
result[setKey] = "default"
default:
return nil, "", fmt.Errorf("invalid syntax: %s", String(expr))
}
}
return result, strings.ToLower(setStmt.Scope), nil
} | [
"func",
"ExtractSetValues",
"(",
"sql",
"string",
")",
"(",
"keyValues",
"map",
"[",
"SetKey",
"]",
"interface",
"{",
"}",
",",
"scope",
"string",
",",
"err",
"error",
")",
"{",
"stmt",
",",
"err",
":=",
"Parse",
"(",
"sql",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"setStmt",
",",
"ok",
":=",
"stmt",
".",
"(",
"*",
"Set",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"stmt",
")",
"\n",
"}",
"\n",
"result",
":=",
"make",
"(",
"map",
"[",
"SetKey",
"]",
"interface",
"{",
"}",
")",
"\n",
"for",
"_",
",",
"expr",
":=",
"range",
"setStmt",
".",
"Exprs",
"{",
"scope",
":=",
"ImplicitStr",
"\n",
"key",
":=",
"expr",
".",
"Name",
".",
"Lowered",
"(",
")",
"\n",
"switch",
"{",
"case",
"strings",
".",
"HasPrefix",
"(",
"key",
",",
"\"",
"\"",
")",
":",
"scope",
"=",
"GlobalStr",
"\n",
"key",
"=",
"strings",
".",
"TrimPrefix",
"(",
"key",
",",
"\"",
"\"",
")",
"\n",
"case",
"strings",
".",
"HasPrefix",
"(",
"key",
",",
"\"",
"\"",
")",
":",
"scope",
"=",
"SessionStr",
"\n",
"key",
"=",
"strings",
".",
"TrimPrefix",
"(",
"key",
",",
"\"",
"\"",
")",
"\n",
"case",
"strings",
".",
"HasPrefix",
"(",
"key",
",",
"\"",
"\"",
")",
":",
"key",
"=",
"strings",
".",
"TrimPrefix",
"(",
"key",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"expr",
".",
"Name",
".",
"Lowered",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"if",
"setStmt",
".",
"Scope",
"!=",
"\"",
"\"",
"&&",
"scope",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"_",
",",
"out",
":=",
"NewStringTokenizer",
"(",
"key",
")",
".",
"Scan",
"(",
")",
"\n",
"key",
"=",
"string",
"(",
"out",
")",
"\n",
"}",
"\n\n",
"setKey",
":=",
"SetKey",
"{",
"Key",
":",
"key",
",",
"Scope",
":",
"scope",
",",
"}",
"\n\n",
"switch",
"expr",
":=",
"expr",
".",
"Expr",
".",
"(",
"type",
")",
"{",
"case",
"*",
"SQLVal",
":",
"switch",
"expr",
".",
"Type",
"{",
"case",
"StrVal",
":",
"result",
"[",
"setKey",
"]",
"=",
"strings",
".",
"ToLower",
"(",
"string",
"(",
"expr",
".",
"Val",
")",
")",
"\n",
"case",
"IntVal",
":",
"num",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"string",
"(",
"expr",
".",
"Val",
")",
",",
"0",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"result",
"[",
"setKey",
"]",
"=",
"num",
"\n",
"default",
":",
"return",
"nil",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"String",
"(",
"expr",
")",
")",
"\n",
"}",
"\n",
"case",
"BoolVal",
":",
"var",
"val",
"int64",
"\n",
"if",
"expr",
"{",
"val",
"=",
"1",
"\n",
"}",
"\n",
"result",
"[",
"setKey",
"]",
"=",
"val",
"\n",
"case",
"*",
"ColName",
":",
"result",
"[",
"setKey",
"]",
"=",
"expr",
".",
"Name",
".",
"String",
"(",
")",
"\n",
"case",
"*",
"NullVal",
":",
"result",
"[",
"setKey",
"]",
"=",
"nil",
"\n",
"case",
"*",
"Default",
":",
"result",
"[",
"setKey",
"]",
"=",
"\"",
"\"",
"\n",
"default",
":",
"return",
"nil",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"String",
"(",
"expr",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"strings",
".",
"ToLower",
"(",
"setStmt",
".",
"Scope",
")",
",",
"nil",
"\n",
"}"
] | // ExtractSetValues returns a map of key-value pairs
// if the query is a SET statement. Values can be bool, int64 or string.
// Since set variable names are case insensitive, all keys are returned
// as lower case. | [
"ExtractSetValues",
"returns",
"a",
"map",
"of",
"key",
"-",
"value",
"pairs",
"if",
"the",
"query",
"is",
"a",
"SET",
"statement",
".",
"Values",
"can",
"be",
"bool",
"int64",
"or",
"string",
".",
"Since",
"set",
"variable",
"names",
"are",
"case",
"insensitive",
"all",
"keys",
"are",
"returned",
"as",
"lower",
"case",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/analyzer.go#L268-L336 |
157,929 | vitessio/vitess | go/vt/vtgate/planbuilder/route_option.go | canMergeOnFilter | func (ro *routeOption) canMergeOnFilter(pb *primitiveBuilder, rro *routeOption, filter sqlparser.Expr) bool {
filter = skipParenthesis(filter)
comparison, ok := filter.(*sqlparser.ComparisonExpr)
if !ok {
return false
}
if comparison.Operator != sqlparser.EqualStr {
return false
}
left := comparison.Left
right := comparison.Right
lVindex := ro.FindVindex(pb, left)
if lVindex == nil {
left, right = right, left
lVindex = ro.FindVindex(pb, left)
}
if lVindex == nil || !lVindex.IsUnique() {
return false
}
rVindex := rro.FindVindex(pb, right)
if rVindex == nil {
return false
}
return rVindex == lVindex
} | go | func (ro *routeOption) canMergeOnFilter(pb *primitiveBuilder, rro *routeOption, filter sqlparser.Expr) bool {
filter = skipParenthesis(filter)
comparison, ok := filter.(*sqlparser.ComparisonExpr)
if !ok {
return false
}
if comparison.Operator != sqlparser.EqualStr {
return false
}
left := comparison.Left
right := comparison.Right
lVindex := ro.FindVindex(pb, left)
if lVindex == nil {
left, right = right, left
lVindex = ro.FindVindex(pb, left)
}
if lVindex == nil || !lVindex.IsUnique() {
return false
}
rVindex := rro.FindVindex(pb, right)
if rVindex == nil {
return false
}
return rVindex == lVindex
} | [
"func",
"(",
"ro",
"*",
"routeOption",
")",
"canMergeOnFilter",
"(",
"pb",
"*",
"primitiveBuilder",
",",
"rro",
"*",
"routeOption",
",",
"filter",
"sqlparser",
".",
"Expr",
")",
"bool",
"{",
"filter",
"=",
"skipParenthesis",
"(",
"filter",
")",
"\n",
"comparison",
",",
"ok",
":=",
"filter",
".",
"(",
"*",
"sqlparser",
".",
"ComparisonExpr",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"comparison",
".",
"Operator",
"!=",
"sqlparser",
".",
"EqualStr",
"{",
"return",
"false",
"\n",
"}",
"\n",
"left",
":=",
"comparison",
".",
"Left",
"\n",
"right",
":=",
"comparison",
".",
"Right",
"\n",
"lVindex",
":=",
"ro",
".",
"FindVindex",
"(",
"pb",
",",
"left",
")",
"\n",
"if",
"lVindex",
"==",
"nil",
"{",
"left",
",",
"right",
"=",
"right",
",",
"left",
"\n",
"lVindex",
"=",
"ro",
".",
"FindVindex",
"(",
"pb",
",",
"left",
")",
"\n",
"}",
"\n",
"if",
"lVindex",
"==",
"nil",
"||",
"!",
"lVindex",
".",
"IsUnique",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"rVindex",
":=",
"rro",
".",
"FindVindex",
"(",
"pb",
",",
"right",
")",
"\n",
"if",
"rVindex",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"rVindex",
"==",
"lVindex",
"\n",
"}"
] | // canMergeOnFilter returns true if the join constraint makes the routes
// mergeable by unique vindex. The constraint has to be an equality
// like a.id = b.id where both columns have the same unique vindex. | [
"canMergeOnFilter",
"returns",
"true",
"if",
"the",
"join",
"constraint",
"makes",
"the",
"routes",
"mergeable",
"by",
"unique",
"vindex",
".",
"The",
"constraint",
"has",
"to",
"be",
"an",
"equality",
"like",
"a",
".",
"id",
"=",
"b",
".",
"id",
"where",
"both",
"columns",
"have",
"the",
"same",
"unique",
"vindex",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route_option.go#L167-L191 |
157,930 | vitessio/vitess | go/vt/vtgate/planbuilder/route_option.go | UpdatePlan | func (ro *routeOption) UpdatePlan(pb *primitiveBuilder, filter sqlparser.Expr) {
switch ro.eroute.Opcode {
case engine.SelectUnsharded, engine.SelectNext, engine.SelectDBA, engine.SelectReference:
return
}
opcode, vindex, values := ro.computePlan(pb, filter)
if opcode == engine.SelectScatter {
return
}
switch ro.eroute.Opcode {
case engine.SelectEqualUnique:
if opcode == engine.SelectEqualUnique && vindex.Cost() < ro.eroute.Vindex.Cost() {
ro.updateRoute(opcode, vindex, values)
}
case engine.SelectEqual:
switch opcode {
case engine.SelectEqualUnique:
ro.updateRoute(opcode, vindex, values)
case engine.SelectEqual:
if vindex.Cost() < ro.eroute.Vindex.Cost() {
ro.updateRoute(opcode, vindex, values)
}
}
case engine.SelectIN:
switch opcode {
case engine.SelectEqualUnique, engine.SelectEqual:
ro.updateRoute(opcode, vindex, values)
case engine.SelectIN:
if vindex.Cost() < ro.eroute.Vindex.Cost() {
ro.updateRoute(opcode, vindex, values)
}
}
case engine.SelectScatter:
switch opcode {
case engine.SelectEqualUnique, engine.SelectEqual, engine.SelectIN:
ro.updateRoute(opcode, vindex, values)
}
}
} | go | func (ro *routeOption) UpdatePlan(pb *primitiveBuilder, filter sqlparser.Expr) {
switch ro.eroute.Opcode {
case engine.SelectUnsharded, engine.SelectNext, engine.SelectDBA, engine.SelectReference:
return
}
opcode, vindex, values := ro.computePlan(pb, filter)
if opcode == engine.SelectScatter {
return
}
switch ro.eroute.Opcode {
case engine.SelectEqualUnique:
if opcode == engine.SelectEqualUnique && vindex.Cost() < ro.eroute.Vindex.Cost() {
ro.updateRoute(opcode, vindex, values)
}
case engine.SelectEqual:
switch opcode {
case engine.SelectEqualUnique:
ro.updateRoute(opcode, vindex, values)
case engine.SelectEqual:
if vindex.Cost() < ro.eroute.Vindex.Cost() {
ro.updateRoute(opcode, vindex, values)
}
}
case engine.SelectIN:
switch opcode {
case engine.SelectEqualUnique, engine.SelectEqual:
ro.updateRoute(opcode, vindex, values)
case engine.SelectIN:
if vindex.Cost() < ro.eroute.Vindex.Cost() {
ro.updateRoute(opcode, vindex, values)
}
}
case engine.SelectScatter:
switch opcode {
case engine.SelectEqualUnique, engine.SelectEqual, engine.SelectIN:
ro.updateRoute(opcode, vindex, values)
}
}
} | [
"func",
"(",
"ro",
"*",
"routeOption",
")",
"UpdatePlan",
"(",
"pb",
"*",
"primitiveBuilder",
",",
"filter",
"sqlparser",
".",
"Expr",
")",
"{",
"switch",
"ro",
".",
"eroute",
".",
"Opcode",
"{",
"case",
"engine",
".",
"SelectUnsharded",
",",
"engine",
".",
"SelectNext",
",",
"engine",
".",
"SelectDBA",
",",
"engine",
".",
"SelectReference",
":",
"return",
"\n",
"}",
"\n",
"opcode",
",",
"vindex",
",",
"values",
":=",
"ro",
".",
"computePlan",
"(",
"pb",
",",
"filter",
")",
"\n",
"if",
"opcode",
"==",
"engine",
".",
"SelectScatter",
"{",
"return",
"\n",
"}",
"\n",
"switch",
"ro",
".",
"eroute",
".",
"Opcode",
"{",
"case",
"engine",
".",
"SelectEqualUnique",
":",
"if",
"opcode",
"==",
"engine",
".",
"SelectEqualUnique",
"&&",
"vindex",
".",
"Cost",
"(",
")",
"<",
"ro",
".",
"eroute",
".",
"Vindex",
".",
"Cost",
"(",
")",
"{",
"ro",
".",
"updateRoute",
"(",
"opcode",
",",
"vindex",
",",
"values",
")",
"\n",
"}",
"\n",
"case",
"engine",
".",
"SelectEqual",
":",
"switch",
"opcode",
"{",
"case",
"engine",
".",
"SelectEqualUnique",
":",
"ro",
".",
"updateRoute",
"(",
"opcode",
",",
"vindex",
",",
"values",
")",
"\n",
"case",
"engine",
".",
"SelectEqual",
":",
"if",
"vindex",
".",
"Cost",
"(",
")",
"<",
"ro",
".",
"eroute",
".",
"Vindex",
".",
"Cost",
"(",
")",
"{",
"ro",
".",
"updateRoute",
"(",
"opcode",
",",
"vindex",
",",
"values",
")",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"engine",
".",
"SelectIN",
":",
"switch",
"opcode",
"{",
"case",
"engine",
".",
"SelectEqualUnique",
",",
"engine",
".",
"SelectEqual",
":",
"ro",
".",
"updateRoute",
"(",
"opcode",
",",
"vindex",
",",
"values",
")",
"\n",
"case",
"engine",
".",
"SelectIN",
":",
"if",
"vindex",
".",
"Cost",
"(",
")",
"<",
"ro",
".",
"eroute",
".",
"Vindex",
".",
"Cost",
"(",
")",
"{",
"ro",
".",
"updateRoute",
"(",
"opcode",
",",
"vindex",
",",
"values",
")",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"engine",
".",
"SelectScatter",
":",
"switch",
"opcode",
"{",
"case",
"engine",
".",
"SelectEqualUnique",
",",
"engine",
".",
"SelectEqual",
",",
"engine",
".",
"SelectIN",
":",
"ro",
".",
"updateRoute",
"(",
"opcode",
",",
"vindex",
",",
"values",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // UpdatePlan evaluates the primitive against the specified
// filter. If it's an improvement, the primitive is updated.
// We assume that the filter has already been pushed into
// the route. | [
"UpdatePlan",
"evaluates",
"the",
"primitive",
"against",
"the",
"specified",
"filter",
".",
"If",
"it",
"s",
"an",
"improvement",
"the",
"primitive",
"is",
"updated",
".",
"We",
"assume",
"that",
"the",
"filter",
"has",
"already",
"been",
"pushed",
"into",
"the",
"route",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route_option.go#L197-L235 |
157,931 | vitessio/vitess | go/vt/vtgate/planbuilder/route_option.go | computePlan | func (ro *routeOption) computePlan(pb *primitiveBuilder, filter sqlparser.Expr) (opcode engine.RouteOpcode, vindex vindexes.Vindex, condition sqlparser.Expr) {
switch node := filter.(type) {
case *sqlparser.ComparisonExpr:
switch node.Operator {
case sqlparser.EqualStr:
return ro.computeEqualPlan(pb, node)
case sqlparser.InStr:
return ro.computeINPlan(pb, node)
}
case *sqlparser.ParenExpr:
return ro.computePlan(pb, node.Expr)
}
return engine.SelectScatter, nil, nil
} | go | func (ro *routeOption) computePlan(pb *primitiveBuilder, filter sqlparser.Expr) (opcode engine.RouteOpcode, vindex vindexes.Vindex, condition sqlparser.Expr) {
switch node := filter.(type) {
case *sqlparser.ComparisonExpr:
switch node.Operator {
case sqlparser.EqualStr:
return ro.computeEqualPlan(pb, node)
case sqlparser.InStr:
return ro.computeINPlan(pb, node)
}
case *sqlparser.ParenExpr:
return ro.computePlan(pb, node.Expr)
}
return engine.SelectScatter, nil, nil
} | [
"func",
"(",
"ro",
"*",
"routeOption",
")",
"computePlan",
"(",
"pb",
"*",
"primitiveBuilder",
",",
"filter",
"sqlparser",
".",
"Expr",
")",
"(",
"opcode",
"engine",
".",
"RouteOpcode",
",",
"vindex",
"vindexes",
".",
"Vindex",
",",
"condition",
"sqlparser",
".",
"Expr",
")",
"{",
"switch",
"node",
":=",
"filter",
".",
"(",
"type",
")",
"{",
"case",
"*",
"sqlparser",
".",
"ComparisonExpr",
":",
"switch",
"node",
".",
"Operator",
"{",
"case",
"sqlparser",
".",
"EqualStr",
":",
"return",
"ro",
".",
"computeEqualPlan",
"(",
"pb",
",",
"node",
")",
"\n",
"case",
"sqlparser",
".",
"InStr",
":",
"return",
"ro",
".",
"computeINPlan",
"(",
"pb",
",",
"node",
")",
"\n",
"}",
"\n",
"case",
"*",
"sqlparser",
".",
"ParenExpr",
":",
"return",
"ro",
".",
"computePlan",
"(",
"pb",
",",
"node",
".",
"Expr",
")",
"\n",
"}",
"\n",
"return",
"engine",
".",
"SelectScatter",
",",
"nil",
",",
"nil",
"\n",
"}"
] | // computePlan computes the plan for the specified filter. | [
"computePlan",
"computes",
"the",
"plan",
"for",
"the",
"specified",
"filter",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route_option.go#L244-L257 |
157,932 | vitessio/vitess | go/vt/vtgate/planbuilder/route_option.go | computeEqualPlan | func (ro *routeOption) computeEqualPlan(pb *primitiveBuilder, comparison *sqlparser.ComparisonExpr) (opcode engine.RouteOpcode, vindex vindexes.Vindex, condition sqlparser.Expr) {
left := comparison.Left
right := comparison.Right
vindex = ro.FindVindex(pb, left)
if vindex == nil {
left, right = right, left
vindex = ro.FindVindex(pb, left)
if vindex == nil {
return engine.SelectScatter, nil, nil
}
}
if !ro.exprIsValue(right) {
return engine.SelectScatter, nil, nil
}
if vindex.IsUnique() {
return engine.SelectEqualUnique, vindex, right
}
return engine.SelectEqual, vindex, right
} | go | func (ro *routeOption) computeEqualPlan(pb *primitiveBuilder, comparison *sqlparser.ComparisonExpr) (opcode engine.RouteOpcode, vindex vindexes.Vindex, condition sqlparser.Expr) {
left := comparison.Left
right := comparison.Right
vindex = ro.FindVindex(pb, left)
if vindex == nil {
left, right = right, left
vindex = ro.FindVindex(pb, left)
if vindex == nil {
return engine.SelectScatter, nil, nil
}
}
if !ro.exprIsValue(right) {
return engine.SelectScatter, nil, nil
}
if vindex.IsUnique() {
return engine.SelectEqualUnique, vindex, right
}
return engine.SelectEqual, vindex, right
} | [
"func",
"(",
"ro",
"*",
"routeOption",
")",
"computeEqualPlan",
"(",
"pb",
"*",
"primitiveBuilder",
",",
"comparison",
"*",
"sqlparser",
".",
"ComparisonExpr",
")",
"(",
"opcode",
"engine",
".",
"RouteOpcode",
",",
"vindex",
"vindexes",
".",
"Vindex",
",",
"condition",
"sqlparser",
".",
"Expr",
")",
"{",
"left",
":=",
"comparison",
".",
"Left",
"\n",
"right",
":=",
"comparison",
".",
"Right",
"\n",
"vindex",
"=",
"ro",
".",
"FindVindex",
"(",
"pb",
",",
"left",
")",
"\n",
"if",
"vindex",
"==",
"nil",
"{",
"left",
",",
"right",
"=",
"right",
",",
"left",
"\n",
"vindex",
"=",
"ro",
".",
"FindVindex",
"(",
"pb",
",",
"left",
")",
"\n",
"if",
"vindex",
"==",
"nil",
"{",
"return",
"engine",
".",
"SelectScatter",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"ro",
".",
"exprIsValue",
"(",
"right",
")",
"{",
"return",
"engine",
".",
"SelectScatter",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"if",
"vindex",
".",
"IsUnique",
"(",
")",
"{",
"return",
"engine",
".",
"SelectEqualUnique",
",",
"vindex",
",",
"right",
"\n",
"}",
"\n",
"return",
"engine",
".",
"SelectEqual",
",",
"vindex",
",",
"right",
"\n",
"}"
] | // computeEqualPlan computes the plan for an equality constraint. | [
"computeEqualPlan",
"computes",
"the",
"plan",
"for",
"an",
"equality",
"constraint",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route_option.go#L260-L278 |
157,933 | vitessio/vitess | go/vt/vtgate/planbuilder/route_option.go | computeINPlan | func (ro *routeOption) computeINPlan(pb *primitiveBuilder, comparison *sqlparser.ComparisonExpr) (opcode engine.RouteOpcode, vindex vindexes.Vindex, condition sqlparser.Expr) {
vindex = ro.FindVindex(pb, comparison.Left)
if vindex == nil {
return engine.SelectScatter, nil, nil
}
switch node := comparison.Right.(type) {
case sqlparser.ValTuple:
for _, n := range node {
if !ro.exprIsValue(n) {
return engine.SelectScatter, nil, nil
}
}
return engine.SelectIN, vindex, comparison
case sqlparser.ListArg:
return engine.SelectIN, vindex, comparison
}
return engine.SelectScatter, nil, nil
} | go | func (ro *routeOption) computeINPlan(pb *primitiveBuilder, comparison *sqlparser.ComparisonExpr) (opcode engine.RouteOpcode, vindex vindexes.Vindex, condition sqlparser.Expr) {
vindex = ro.FindVindex(pb, comparison.Left)
if vindex == nil {
return engine.SelectScatter, nil, nil
}
switch node := comparison.Right.(type) {
case sqlparser.ValTuple:
for _, n := range node {
if !ro.exprIsValue(n) {
return engine.SelectScatter, nil, nil
}
}
return engine.SelectIN, vindex, comparison
case sqlparser.ListArg:
return engine.SelectIN, vindex, comparison
}
return engine.SelectScatter, nil, nil
} | [
"func",
"(",
"ro",
"*",
"routeOption",
")",
"computeINPlan",
"(",
"pb",
"*",
"primitiveBuilder",
",",
"comparison",
"*",
"sqlparser",
".",
"ComparisonExpr",
")",
"(",
"opcode",
"engine",
".",
"RouteOpcode",
",",
"vindex",
"vindexes",
".",
"Vindex",
",",
"condition",
"sqlparser",
".",
"Expr",
")",
"{",
"vindex",
"=",
"ro",
".",
"FindVindex",
"(",
"pb",
",",
"comparison",
".",
"Left",
")",
"\n",
"if",
"vindex",
"==",
"nil",
"{",
"return",
"engine",
".",
"SelectScatter",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"switch",
"node",
":=",
"comparison",
".",
"Right",
".",
"(",
"type",
")",
"{",
"case",
"sqlparser",
".",
"ValTuple",
":",
"for",
"_",
",",
"n",
":=",
"range",
"node",
"{",
"if",
"!",
"ro",
".",
"exprIsValue",
"(",
"n",
")",
"{",
"return",
"engine",
".",
"SelectScatter",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"engine",
".",
"SelectIN",
",",
"vindex",
",",
"comparison",
"\n",
"case",
"sqlparser",
".",
"ListArg",
":",
"return",
"engine",
".",
"SelectIN",
",",
"vindex",
",",
"comparison",
"\n",
"}",
"\n",
"return",
"engine",
".",
"SelectScatter",
",",
"nil",
",",
"nil",
"\n",
"}"
] | // computeINPlan computes the plan for an IN constraint. | [
"computeINPlan",
"computes",
"the",
"plan",
"for",
"an",
"IN",
"constraint",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route_option.go#L281-L298 |
157,934 | vitessio/vitess | go/vt/vtgate/planbuilder/route_option.go | exprIsValue | func (ro *routeOption) exprIsValue(expr sqlparser.Expr) bool {
if node, ok := expr.(*sqlparser.ColName); ok {
return node.Metadata.(*column).Origin() != ro.rb
}
return sqlparser.IsValue(expr)
} | go | func (ro *routeOption) exprIsValue(expr sqlparser.Expr) bool {
if node, ok := expr.(*sqlparser.ColName); ok {
return node.Metadata.(*column).Origin() != ro.rb
}
return sqlparser.IsValue(expr)
} | [
"func",
"(",
"ro",
"*",
"routeOption",
")",
"exprIsValue",
"(",
"expr",
"sqlparser",
".",
"Expr",
")",
"bool",
"{",
"if",
"node",
",",
"ok",
":=",
"expr",
".",
"(",
"*",
"sqlparser",
".",
"ColName",
")",
";",
"ok",
"{",
"return",
"node",
".",
"Metadata",
".",
"(",
"*",
"column",
")",
".",
"Origin",
"(",
")",
"!=",
"ro",
".",
"rb",
"\n",
"}",
"\n",
"return",
"sqlparser",
".",
"IsValue",
"(",
"expr",
")",
"\n",
"}"
] | // exprIsValue returns true if the expression can be treated as a value
// for the routeOption. External references are treated as value. | [
"exprIsValue",
"returns",
"true",
"if",
"the",
"expression",
"can",
"be",
"treated",
"as",
"a",
"value",
"for",
"the",
"routeOption",
".",
"External",
"references",
"are",
"treated",
"as",
"value",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route_option.go#L346-L351 |
157,935 | vitessio/vitess | go/vt/mysqlctl/mycnf_gen.go | NewMycnf | func NewMycnf(tabletUID uint32, mysqlPort int32) *Mycnf {
cnf := new(Mycnf)
cnf.path = MycnfFile(tabletUID)
tabletDir := TabletDir(tabletUID)
cnf.ServerID = tabletUID
cnf.MysqlPort = mysqlPort
cnf.DataDir = path.Join(tabletDir, dataDir)
cnf.InnodbDataHomeDir = path.Join(tabletDir, innodbDataSubdir)
cnf.InnodbLogGroupHomeDir = path.Join(tabletDir, innodbLogSubdir)
cnf.SocketFile = path.Join(tabletDir, "mysql.sock")
cnf.GeneralLogPath = path.Join(tabletDir, "general.log")
cnf.ErrorLogPath = path.Join(tabletDir, "error.log")
cnf.SlowLogPath = path.Join(tabletDir, "slow-query.log")
cnf.RelayLogPath = path.Join(tabletDir, relayLogDir,
fmt.Sprintf("vt-%010d-relay-bin", tabletUID))
cnf.RelayLogIndexPath = cnf.RelayLogPath + ".index"
cnf.RelayLogInfoPath = path.Join(tabletDir, relayLogDir, "relay-log.info")
cnf.BinLogPath = path.Join(tabletDir, binLogDir,
fmt.Sprintf("vt-%010d-bin", tabletUID))
cnf.MasterInfoFile = path.Join(tabletDir, "master.info")
cnf.PidFile = path.Join(tabletDir, "mysql.pid")
cnf.TmpDir = path.Join(tabletDir, "tmp")
cnf.SlaveLoadTmpDir = cnf.TmpDir
return cnf
} | go | func NewMycnf(tabletUID uint32, mysqlPort int32) *Mycnf {
cnf := new(Mycnf)
cnf.path = MycnfFile(tabletUID)
tabletDir := TabletDir(tabletUID)
cnf.ServerID = tabletUID
cnf.MysqlPort = mysqlPort
cnf.DataDir = path.Join(tabletDir, dataDir)
cnf.InnodbDataHomeDir = path.Join(tabletDir, innodbDataSubdir)
cnf.InnodbLogGroupHomeDir = path.Join(tabletDir, innodbLogSubdir)
cnf.SocketFile = path.Join(tabletDir, "mysql.sock")
cnf.GeneralLogPath = path.Join(tabletDir, "general.log")
cnf.ErrorLogPath = path.Join(tabletDir, "error.log")
cnf.SlowLogPath = path.Join(tabletDir, "slow-query.log")
cnf.RelayLogPath = path.Join(tabletDir, relayLogDir,
fmt.Sprintf("vt-%010d-relay-bin", tabletUID))
cnf.RelayLogIndexPath = cnf.RelayLogPath + ".index"
cnf.RelayLogInfoPath = path.Join(tabletDir, relayLogDir, "relay-log.info")
cnf.BinLogPath = path.Join(tabletDir, binLogDir,
fmt.Sprintf("vt-%010d-bin", tabletUID))
cnf.MasterInfoFile = path.Join(tabletDir, "master.info")
cnf.PidFile = path.Join(tabletDir, "mysql.pid")
cnf.TmpDir = path.Join(tabletDir, "tmp")
cnf.SlaveLoadTmpDir = cnf.TmpDir
return cnf
} | [
"func",
"NewMycnf",
"(",
"tabletUID",
"uint32",
",",
"mysqlPort",
"int32",
")",
"*",
"Mycnf",
"{",
"cnf",
":=",
"new",
"(",
"Mycnf",
")",
"\n",
"cnf",
".",
"path",
"=",
"MycnfFile",
"(",
"tabletUID",
")",
"\n",
"tabletDir",
":=",
"TabletDir",
"(",
"tabletUID",
")",
"\n",
"cnf",
".",
"ServerID",
"=",
"tabletUID",
"\n",
"cnf",
".",
"MysqlPort",
"=",
"mysqlPort",
"\n",
"cnf",
".",
"DataDir",
"=",
"path",
".",
"Join",
"(",
"tabletDir",
",",
"dataDir",
")",
"\n",
"cnf",
".",
"InnodbDataHomeDir",
"=",
"path",
".",
"Join",
"(",
"tabletDir",
",",
"innodbDataSubdir",
")",
"\n",
"cnf",
".",
"InnodbLogGroupHomeDir",
"=",
"path",
".",
"Join",
"(",
"tabletDir",
",",
"innodbLogSubdir",
")",
"\n",
"cnf",
".",
"SocketFile",
"=",
"path",
".",
"Join",
"(",
"tabletDir",
",",
"\"",
"\"",
")",
"\n",
"cnf",
".",
"GeneralLogPath",
"=",
"path",
".",
"Join",
"(",
"tabletDir",
",",
"\"",
"\"",
")",
"\n",
"cnf",
".",
"ErrorLogPath",
"=",
"path",
".",
"Join",
"(",
"tabletDir",
",",
"\"",
"\"",
")",
"\n",
"cnf",
".",
"SlowLogPath",
"=",
"path",
".",
"Join",
"(",
"tabletDir",
",",
"\"",
"\"",
")",
"\n",
"cnf",
".",
"RelayLogPath",
"=",
"path",
".",
"Join",
"(",
"tabletDir",
",",
"relayLogDir",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"tabletUID",
")",
")",
"\n",
"cnf",
".",
"RelayLogIndexPath",
"=",
"cnf",
".",
"RelayLogPath",
"+",
"\"",
"\"",
"\n",
"cnf",
".",
"RelayLogInfoPath",
"=",
"path",
".",
"Join",
"(",
"tabletDir",
",",
"relayLogDir",
",",
"\"",
"\"",
")",
"\n",
"cnf",
".",
"BinLogPath",
"=",
"path",
".",
"Join",
"(",
"tabletDir",
",",
"binLogDir",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"tabletUID",
")",
")",
"\n",
"cnf",
".",
"MasterInfoFile",
"=",
"path",
".",
"Join",
"(",
"tabletDir",
",",
"\"",
"\"",
")",
"\n",
"cnf",
".",
"PidFile",
"=",
"path",
".",
"Join",
"(",
"tabletDir",
",",
"\"",
"\"",
")",
"\n",
"cnf",
".",
"TmpDir",
"=",
"path",
".",
"Join",
"(",
"tabletDir",
",",
"\"",
"\"",
")",
"\n",
"cnf",
".",
"SlaveLoadTmpDir",
"=",
"cnf",
".",
"TmpDir",
"\n",
"return",
"cnf",
"\n",
"}"
] | // NewMycnf fills the Mycnf structure with vt root paths and derived values.
// This is used to fill out the cnfTemplate values and generate my.cnf.
// uid is a unique id for a particular tablet - it must be unique within the
// tabletservers deployed within a keyspace, lest there be collisions on disk.
// mysqldPort needs to be unique per instance per machine. | [
"NewMycnf",
"fills",
"the",
"Mycnf",
"structure",
"with",
"vt",
"root",
"paths",
"and",
"derived",
"values",
".",
"This",
"is",
"used",
"to",
"fill",
"out",
"the",
"cnfTemplate",
"values",
"and",
"generate",
"my",
".",
"cnf",
".",
"uid",
"is",
"a",
"unique",
"id",
"for",
"a",
"particular",
"tablet",
"-",
"it",
"must",
"be",
"unique",
"within",
"the",
"tabletservers",
"deployed",
"within",
"a",
"keyspace",
"lest",
"there",
"be",
"collisions",
"on",
"disk",
".",
"mysqldPort",
"needs",
"to",
"be",
"unique",
"per",
"instance",
"per",
"machine",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/mycnf_gen.go#L66-L90 |
157,936 | vitessio/vitess | go/vt/mysqlctl/mycnf_gen.go | TabletDir | func TabletDir(uid uint32) string {
if *tabletDir != "" {
return fmt.Sprintf("%s/%s", env.VtDataRoot(), *tabletDir)
}
return fmt.Sprintf("%s/vt_%010d", env.VtDataRoot(), uid)
} | go | func TabletDir(uid uint32) string {
if *tabletDir != "" {
return fmt.Sprintf("%s/%s", env.VtDataRoot(), *tabletDir)
}
return fmt.Sprintf("%s/vt_%010d", env.VtDataRoot(), uid)
} | [
"func",
"TabletDir",
"(",
"uid",
"uint32",
")",
"string",
"{",
"if",
"*",
"tabletDir",
"!=",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"env",
".",
"VtDataRoot",
"(",
")",
",",
"*",
"tabletDir",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"env",
".",
"VtDataRoot",
"(",
")",
",",
"uid",
")",
"\n",
"}"
] | // TabletDir returns the default directory for a tablet | [
"TabletDir",
"returns",
"the",
"default",
"directory",
"for",
"a",
"tablet"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/mycnf_gen.go#L93-L98 |
157,937 | vitessio/vitess | go/vt/mysqlctl/mycnf_gen.go | directoryList | func (cnf *Mycnf) directoryList() []string {
return []string{
cnf.DataDir,
cnf.InnodbDataHomeDir,
cnf.InnodbLogGroupHomeDir,
cnf.TmpDir,
path.Dir(cnf.RelayLogPath),
path.Dir(cnf.BinLogPath),
}
} | go | func (cnf *Mycnf) directoryList() []string {
return []string{
cnf.DataDir,
cnf.InnodbDataHomeDir,
cnf.InnodbLogGroupHomeDir,
cnf.TmpDir,
path.Dir(cnf.RelayLogPath),
path.Dir(cnf.BinLogPath),
}
} | [
"func",
"(",
"cnf",
"*",
"Mycnf",
")",
"directoryList",
"(",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"cnf",
".",
"DataDir",
",",
"cnf",
".",
"InnodbDataHomeDir",
",",
"cnf",
".",
"InnodbLogGroupHomeDir",
",",
"cnf",
".",
"TmpDir",
",",
"path",
".",
"Dir",
"(",
"cnf",
".",
"RelayLogPath",
")",
",",
"path",
".",
"Dir",
"(",
"cnf",
".",
"BinLogPath",
")",
",",
"}",
"\n",
"}"
] | // directoryList returns the list of directories to create in an empty
// mysql instance. | [
"directoryList",
"returns",
"the",
"list",
"of",
"directories",
"to",
"create",
"in",
"an",
"empty",
"mysql",
"instance",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/mycnf_gen.go#L113-L122 |
157,938 | vitessio/vitess | go/vt/mysqlctl/mycnf_gen.go | makeMycnf | func (cnf *Mycnf) makeMycnf(cnfFiles []string) (string, error) {
myTemplateSource := new(bytes.Buffer)
myTemplateSource.WriteString("[mysqld]\n")
for _, path := range cnfFiles {
data, dataErr := ioutil.ReadFile(path)
if dataErr != nil {
return "", dataErr
}
myTemplateSource.WriteString("## " + path + "\n")
myTemplateSource.Write(data)
}
return cnf.fillMycnfTemplate(myTemplateSource.String())
} | go | func (cnf *Mycnf) makeMycnf(cnfFiles []string) (string, error) {
myTemplateSource := new(bytes.Buffer)
myTemplateSource.WriteString("[mysqld]\n")
for _, path := range cnfFiles {
data, dataErr := ioutil.ReadFile(path)
if dataErr != nil {
return "", dataErr
}
myTemplateSource.WriteString("## " + path + "\n")
myTemplateSource.Write(data)
}
return cnf.fillMycnfTemplate(myTemplateSource.String())
} | [
"func",
"(",
"cnf",
"*",
"Mycnf",
")",
"makeMycnf",
"(",
"cnfFiles",
"[",
"]",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"myTemplateSource",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"myTemplateSource",
".",
"WriteString",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"for",
"_",
",",
"path",
":=",
"range",
"cnfFiles",
"{",
"data",
",",
"dataErr",
":=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"if",
"dataErr",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"dataErr",
"\n",
"}",
"\n",
"myTemplateSource",
".",
"WriteString",
"(",
"\"",
"\"",
"+",
"path",
"+",
"\"",
"\\n",
"\"",
")",
"\n",
"myTemplateSource",
".",
"Write",
"(",
"data",
")",
"\n",
"}",
"\n",
"return",
"cnf",
".",
"fillMycnfTemplate",
"(",
"myTemplateSource",
".",
"String",
"(",
")",
")",
"\n",
"}"
] | // makeMycnf will join cnf files cnfPaths and substitute in the right values. | [
"makeMycnf",
"will",
"join",
"cnf",
"files",
"cnfPaths",
"and",
"substitute",
"in",
"the",
"right",
"values",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/mycnf_gen.go#L125-L137 |
157,939 | vitessio/vitess | go/vt/mysqlctl/mycnf_gen.go | fillMycnfTemplate | func (cnf *Mycnf) fillMycnfTemplate(tmplSrc string) (string, error) {
myTemplate, err := template.New("").Parse(tmplSrc)
if err != nil {
return "", err
}
mycnfData := new(bytes.Buffer)
err = myTemplate.Execute(mycnfData, cnf)
if err != nil {
return "", err
}
return mycnfData.String(), nil
} | go | func (cnf *Mycnf) fillMycnfTemplate(tmplSrc string) (string, error) {
myTemplate, err := template.New("").Parse(tmplSrc)
if err != nil {
return "", err
}
mycnfData := new(bytes.Buffer)
err = myTemplate.Execute(mycnfData, cnf)
if err != nil {
return "", err
}
return mycnfData.String(), nil
} | [
"func",
"(",
"cnf",
"*",
"Mycnf",
")",
"fillMycnfTemplate",
"(",
"tmplSrc",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"myTemplate",
",",
"err",
":=",
"template",
".",
"New",
"(",
"\"",
"\"",
")",
".",
"Parse",
"(",
"tmplSrc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"mycnfData",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"err",
"=",
"myTemplate",
".",
"Execute",
"(",
"mycnfData",
",",
"cnf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"mycnfData",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
] | // fillMycnfTemplate will fill in the passed in template with the values
// from Mycnf | [
"fillMycnfTemplate",
"will",
"fill",
"in",
"the",
"passed",
"in",
"template",
"with",
"the",
"values",
"from",
"Mycnf"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/mycnf_gen.go#L141-L152 |
157,940 | vitessio/vitess | go/jsonutil/json.go | MarshalNoEscape | func MarshalNoEscape(v interface{}) ([]byte, error) {
buf := bytes.Buffer{}
enc := json.NewEncoder(&buf)
enc.SetEscapeHTML(false)
err := enc.Encode(v)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
} | go | func MarshalNoEscape(v interface{}) ([]byte, error) {
buf := bytes.Buffer{}
enc := json.NewEncoder(&buf)
enc.SetEscapeHTML(false)
err := enc.Encode(v)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
} | [
"func",
"MarshalNoEscape",
"(",
"v",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buf",
":=",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"enc",
":=",
"json",
".",
"NewEncoder",
"(",
"&",
"buf",
")",
"\n",
"enc",
".",
"SetEscapeHTML",
"(",
"false",
")",
"\n",
"err",
":=",
"enc",
".",
"Encode",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"buf",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] | // MarshalNoEscape is the same functionality as json.Marshal but
// with HTML escaping disabled | [
"MarshalNoEscape",
"is",
"the",
"same",
"functionality",
"as",
"json",
".",
"Marshal",
"but",
"with",
"HTML",
"escaping",
"disabled"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/jsonutil/json.go#L27-L36 |
157,941 | vitessio/vitess | go/jsonutil/json.go | MarshalIndentNoEscape | func MarshalIndentNoEscape(v interface{}, prefix, indent string) ([]byte, error) {
buf := bytes.Buffer{}
enc := json.NewEncoder(&buf)
enc.SetEscapeHTML(false)
enc.SetIndent(prefix, indent)
err := enc.Encode(v)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
} | go | func MarshalIndentNoEscape(v interface{}, prefix, indent string) ([]byte, error) {
buf := bytes.Buffer{}
enc := json.NewEncoder(&buf)
enc.SetEscapeHTML(false)
enc.SetIndent(prefix, indent)
err := enc.Encode(v)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
} | [
"func",
"MarshalIndentNoEscape",
"(",
"v",
"interface",
"{",
"}",
",",
"prefix",
",",
"indent",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buf",
":=",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"enc",
":=",
"json",
".",
"NewEncoder",
"(",
"&",
"buf",
")",
"\n",
"enc",
".",
"SetEscapeHTML",
"(",
"false",
")",
"\n",
"enc",
".",
"SetIndent",
"(",
"prefix",
",",
"indent",
")",
"\n",
"err",
":=",
"enc",
".",
"Encode",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"buf",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] | // MarshalIndentNoEscape is the same functionality as json.MarshalIndent but with HTML escaping
// disabled | [
"MarshalIndentNoEscape",
"is",
"the",
"same",
"functionality",
"as",
"json",
".",
"MarshalIndent",
"but",
"with",
"HTML",
"escaping",
"disabled"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/jsonutil/json.go#L40-L50 |
157,942 | vitessio/vitess | go/bucketpool/bucketpool.go | Put | func (p *Pool) Put(b *[]byte) {
sp := p.findPool(cap(*b))
if sp == nil {
return
}
*b = (*b)[:cap(*b)]
sp.pool.Put(b)
} | go | func (p *Pool) Put(b *[]byte) {
sp := p.findPool(cap(*b))
if sp == nil {
return
}
*b = (*b)[:cap(*b)]
sp.pool.Put(b)
} | [
"func",
"(",
"p",
"*",
"Pool",
")",
"Put",
"(",
"b",
"*",
"[",
"]",
"byte",
")",
"{",
"sp",
":=",
"p",
".",
"findPool",
"(",
"cap",
"(",
"*",
"b",
")",
")",
"\n",
"if",
"sp",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"*",
"b",
"=",
"(",
"*",
"b",
")",
"[",
":",
"cap",
"(",
"*",
"b",
")",
"]",
"\n",
"sp",
".",
"pool",
".",
"Put",
"(",
"b",
")",
"\n",
"}"
] | // Put returns pointer to slice to some bucket. Discards slice for which there is no bucket | [
"Put",
"returns",
"pointer",
"to",
"slice",
"to",
"some",
"bucket",
".",
"Discards",
"slice",
"for",
"which",
"there",
"is",
"no",
"bucket"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/bucketpool/bucketpool.go#L95-L102 |
157,943 | vitessio/vitess | go/sqltypes/bind_variables.go | ValueBindVariable | func ValueBindVariable(v Value) *querypb.BindVariable {
return &querypb.BindVariable{Type: v.typ, Value: v.val}
} | go | func ValueBindVariable(v Value) *querypb.BindVariable {
return &querypb.BindVariable{Type: v.typ, Value: v.val}
} | [
"func",
"ValueBindVariable",
"(",
"v",
"Value",
")",
"*",
"querypb",
".",
"BindVariable",
"{",
"return",
"&",
"querypb",
".",
"BindVariable",
"{",
"Type",
":",
"v",
".",
"typ",
",",
"Value",
":",
"v",
".",
"val",
"}",
"\n",
"}"
] | // ValueBindVariable converts a Value to a bind var. | [
"ValueBindVariable",
"converts",
"a",
"Value",
"to",
"a",
"bind",
"var",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/sqltypes/bind_variables.go#L96-L98 |
157,944 | vitessio/vitess | go/sqltypes/bind_variables.go | ValidateBindVariable | func ValidateBindVariable(bv *querypb.BindVariable) error {
if bv == nil {
return errors.New("bind variable is nil")
}
if bv.Type == querypb.Type_TUPLE {
if len(bv.Values) == 0 {
return errors.New("empty tuple is not allowed")
}
for _, val := range bv.Values {
if val.Type == querypb.Type_TUPLE {
return errors.New("tuple not allowed inside another tuple")
}
if err := ValidateBindVariable(&querypb.BindVariable{Type: val.Type, Value: val.Value}); err != nil {
return err
}
}
return nil
}
// If NewValue succeeds, the value is valid.
_, err := NewValue(bv.Type, bv.Value)
return err
} | go | func ValidateBindVariable(bv *querypb.BindVariable) error {
if bv == nil {
return errors.New("bind variable is nil")
}
if bv.Type == querypb.Type_TUPLE {
if len(bv.Values) == 0 {
return errors.New("empty tuple is not allowed")
}
for _, val := range bv.Values {
if val.Type == querypb.Type_TUPLE {
return errors.New("tuple not allowed inside another tuple")
}
if err := ValidateBindVariable(&querypb.BindVariable{Type: val.Type, Value: val.Value}); err != nil {
return err
}
}
return nil
}
// If NewValue succeeds, the value is valid.
_, err := NewValue(bv.Type, bv.Value)
return err
} | [
"func",
"ValidateBindVariable",
"(",
"bv",
"*",
"querypb",
".",
"BindVariable",
")",
"error",
"{",
"if",
"bv",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"bv",
".",
"Type",
"==",
"querypb",
".",
"Type_TUPLE",
"{",
"if",
"len",
"(",
"bv",
".",
"Values",
")",
"==",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"bv",
".",
"Values",
"{",
"if",
"val",
".",
"Type",
"==",
"querypb",
".",
"Type_TUPLE",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"ValidateBindVariable",
"(",
"&",
"querypb",
".",
"BindVariable",
"{",
"Type",
":",
"val",
".",
"Type",
",",
"Value",
":",
"val",
".",
"Value",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"// If NewValue succeeds, the value is valid.",
"_",
",",
"err",
":=",
"NewValue",
"(",
"bv",
".",
"Type",
",",
"bv",
".",
"Value",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // ValidateBindVariable returns an error if the bind variable has inconsistent
// fields. | [
"ValidateBindVariable",
"returns",
"an",
"error",
"if",
"the",
"bind",
"variable",
"has",
"inconsistent",
"fields",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/sqltypes/bind_variables.go#L233-L256 |
157,945 | vitessio/vitess | go/sqltypes/bind_variables.go | BindVariableToValue | func BindVariableToValue(bv *querypb.BindVariable) (Value, error) {
if bv.Type == querypb.Type_TUPLE {
return NULL, errors.New("cannot convert a TUPLE bind var into a value")
}
return MakeTrusted(bv.Type, bv.Value), nil
} | go | func BindVariableToValue(bv *querypb.BindVariable) (Value, error) {
if bv.Type == querypb.Type_TUPLE {
return NULL, errors.New("cannot convert a TUPLE bind var into a value")
}
return MakeTrusted(bv.Type, bv.Value), nil
} | [
"func",
"BindVariableToValue",
"(",
"bv",
"*",
"querypb",
".",
"BindVariable",
")",
"(",
"Value",
",",
"error",
")",
"{",
"if",
"bv",
".",
"Type",
"==",
"querypb",
".",
"Type_TUPLE",
"{",
"return",
"NULL",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"MakeTrusted",
"(",
"bv",
".",
"Type",
",",
"bv",
".",
"Value",
")",
",",
"nil",
"\n",
"}"
] | // BindVariableToValue converts a bind var into a Value. | [
"BindVariableToValue",
"converts",
"a",
"bind",
"var",
"into",
"a",
"Value",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/sqltypes/bind_variables.go#L259-L264 |
157,946 | vitessio/vitess | go/sqltypes/bind_variables.go | BindVariablesEqual | func BindVariablesEqual(x, y map[string]*querypb.BindVariable) bool {
return proto.Equal(&querypb.BoundQuery{BindVariables: x}, &querypb.BoundQuery{BindVariables: y})
} | go | func BindVariablesEqual(x, y map[string]*querypb.BindVariable) bool {
return proto.Equal(&querypb.BoundQuery{BindVariables: x}, &querypb.BoundQuery{BindVariables: y})
} | [
"func",
"BindVariablesEqual",
"(",
"x",
",",
"y",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
")",
"bool",
"{",
"return",
"proto",
".",
"Equal",
"(",
"&",
"querypb",
".",
"BoundQuery",
"{",
"BindVariables",
":",
"x",
"}",
",",
"&",
"querypb",
".",
"BoundQuery",
"{",
"BindVariables",
":",
"y",
"}",
")",
"\n",
"}"
] | // BindVariablesEqual compares two maps of bind variables.
// For protobuf messages we have to use "proto.Equal". | [
"BindVariablesEqual",
"compares",
"two",
"maps",
"of",
"bind",
"variables",
".",
"For",
"protobuf",
"messages",
"we",
"have",
"to",
"use",
"proto",
".",
"Equal",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/sqltypes/bind_variables.go#L268-L270 |
157,947 | vitessio/vitess | go/sqltypes/bind_variables.go | CopyBindVariables | func CopyBindVariables(bindVariables map[string]*querypb.BindVariable) map[string]*querypb.BindVariable {
result := make(map[string]*querypb.BindVariable, len(bindVariables))
for key, value := range bindVariables {
result[key] = value
}
return result
} | go | func CopyBindVariables(bindVariables map[string]*querypb.BindVariable) map[string]*querypb.BindVariable {
result := make(map[string]*querypb.BindVariable, len(bindVariables))
for key, value := range bindVariables {
result[key] = value
}
return result
} | [
"func",
"CopyBindVariables",
"(",
"bindVariables",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
")",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
"{",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
",",
"len",
"(",
"bindVariables",
")",
")",
"\n",
"for",
"key",
",",
"value",
":=",
"range",
"bindVariables",
"{",
"result",
"[",
"key",
"]",
"=",
"value",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // CopyBindVariables returns a shallow-copy of the given bindVariables map. | [
"CopyBindVariables",
"returns",
"a",
"shallow",
"-",
"copy",
"of",
"the",
"given",
"bindVariables",
"map",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/sqltypes/bind_variables.go#L273-L279 |
157,948 | vitessio/vitess | go/sqltypes/bind_variables.go | FormatBindVariables | func FormatBindVariables(bindVariables map[string]*querypb.BindVariable, full, asJSON bool) string {
var out map[string]*querypb.BindVariable
if full {
out = bindVariables
} else {
// NOTE(szopa): I am getting rid of potentially large bind
// variables.
out = make(map[string]*querypb.BindVariable)
for k, v := range bindVariables {
if IsIntegral(v.Type) || IsFloat(v.Type) {
out[k] = v
} else if v.Type == querypb.Type_TUPLE {
out[k] = StringBindVariable(fmt.Sprintf("%v items", len(v.Values)))
} else {
out[k] = StringBindVariable(fmt.Sprintf("%v bytes", len(v.Value)))
}
}
}
if asJSON {
var buf bytes.Buffer
buf.WriteString("{")
first := true
for k, v := range out {
if !first {
buf.WriteString(", ")
} else {
first = false
}
if IsIntegral(v.Type) || IsFloat(v.Type) {
fmt.Fprintf(&buf, "%q: {\"type\": %q, \"value\": %v}", k, v.Type, string(v.Value))
} else {
fmt.Fprintf(&buf, "%q: {\"type\": %q, \"value\": %q}", k, v.Type, string(v.Value))
}
}
buf.WriteString("}")
return buf.String()
}
return fmt.Sprintf("%v", out)
} | go | func FormatBindVariables(bindVariables map[string]*querypb.BindVariable, full, asJSON bool) string {
var out map[string]*querypb.BindVariable
if full {
out = bindVariables
} else {
// NOTE(szopa): I am getting rid of potentially large bind
// variables.
out = make(map[string]*querypb.BindVariable)
for k, v := range bindVariables {
if IsIntegral(v.Type) || IsFloat(v.Type) {
out[k] = v
} else if v.Type == querypb.Type_TUPLE {
out[k] = StringBindVariable(fmt.Sprintf("%v items", len(v.Values)))
} else {
out[k] = StringBindVariable(fmt.Sprintf("%v bytes", len(v.Value)))
}
}
}
if asJSON {
var buf bytes.Buffer
buf.WriteString("{")
first := true
for k, v := range out {
if !first {
buf.WriteString(", ")
} else {
first = false
}
if IsIntegral(v.Type) || IsFloat(v.Type) {
fmt.Fprintf(&buf, "%q: {\"type\": %q, \"value\": %v}", k, v.Type, string(v.Value))
} else {
fmt.Fprintf(&buf, "%q: {\"type\": %q, \"value\": %q}", k, v.Type, string(v.Value))
}
}
buf.WriteString("}")
return buf.String()
}
return fmt.Sprintf("%v", out)
} | [
"func",
"FormatBindVariables",
"(",
"bindVariables",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
",",
"full",
",",
"asJSON",
"bool",
")",
"string",
"{",
"var",
"out",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
"\n",
"if",
"full",
"{",
"out",
"=",
"bindVariables",
"\n",
"}",
"else",
"{",
"// NOTE(szopa): I am getting rid of potentially large bind",
"// variables.",
"out",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"bindVariables",
"{",
"if",
"IsIntegral",
"(",
"v",
".",
"Type",
")",
"||",
"IsFloat",
"(",
"v",
".",
"Type",
")",
"{",
"out",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"else",
"if",
"v",
".",
"Type",
"==",
"querypb",
".",
"Type_TUPLE",
"{",
"out",
"[",
"k",
"]",
"=",
"StringBindVariable",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"len",
"(",
"v",
".",
"Values",
")",
")",
")",
"\n",
"}",
"else",
"{",
"out",
"[",
"k",
"]",
"=",
"StringBindVariable",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"len",
"(",
"v",
".",
"Value",
")",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"asJSON",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"first",
":=",
"true",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"out",
"{",
"if",
"!",
"first",
"{",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"first",
"=",
"false",
"\n",
"}",
"\n",
"if",
"IsIntegral",
"(",
"v",
".",
"Type",
")",
"||",
"IsFloat",
"(",
"v",
".",
"Type",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"&",
"buf",
",",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\"",
",",
"k",
",",
"v",
".",
"Type",
",",
"string",
"(",
"v",
".",
"Value",
")",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Fprintf",
"(",
"&",
"buf",
",",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\"",
",",
"k",
",",
"v",
".",
"Type",
",",
"string",
"(",
"v",
".",
"Value",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"out",
")",
"\n",
"}"
] | // FormatBindVariables returns a string representation of the
// bind variables.
//
// If full is false, then large string or tuple values are truncated
// to only print the lengths.
//
// If asJson is true, then the resulting string is a valid JSON
// representation, otherwise it is the golang printed map representation. | [
"FormatBindVariables",
"returns",
"a",
"string",
"representation",
"of",
"the",
"bind",
"variables",
".",
"If",
"full",
"is",
"false",
"then",
"large",
"string",
"or",
"tuple",
"values",
"are",
"truncated",
"to",
"only",
"print",
"the",
"lengths",
".",
"If",
"asJson",
"is",
"true",
"then",
"the",
"resulting",
"string",
"is",
"a",
"valid",
"JSON",
"representation",
"otherwise",
"it",
"is",
"the",
"golang",
"printed",
"map",
"representation",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/sqltypes/bind_variables.go#L289-L329 |
157,949 | vitessio/vitess | go/stats/kebab_case_converter.go | toKebabCase | func toKebabCase(name string) (hyphenated string) {
memoizer.Lock()
defer memoizer.Unlock()
if hyphenated = memoizer.memo[name]; hyphenated != "" {
return hyphenated
}
hyphenated = name
for _, converter := range kebabConverters {
hyphenated = converter.re.ReplaceAllString(hyphenated, converter.repl)
}
hyphenated = strings.ToLower(hyphenated)
memoizer.memo[name] = hyphenated
return
} | go | func toKebabCase(name string) (hyphenated string) {
memoizer.Lock()
defer memoizer.Unlock()
if hyphenated = memoizer.memo[name]; hyphenated != "" {
return hyphenated
}
hyphenated = name
for _, converter := range kebabConverters {
hyphenated = converter.re.ReplaceAllString(hyphenated, converter.repl)
}
hyphenated = strings.ToLower(hyphenated)
memoizer.memo[name] = hyphenated
return
} | [
"func",
"toKebabCase",
"(",
"name",
"string",
")",
"(",
"hyphenated",
"string",
")",
"{",
"memoizer",
".",
"Lock",
"(",
")",
"\n",
"defer",
"memoizer",
".",
"Unlock",
"(",
")",
"\n",
"if",
"hyphenated",
"=",
"memoizer",
".",
"memo",
"[",
"name",
"]",
";",
"hyphenated",
"!=",
"\"",
"\"",
"{",
"return",
"hyphenated",
"\n",
"}",
"\n",
"hyphenated",
"=",
"name",
"\n",
"for",
"_",
",",
"converter",
":=",
"range",
"kebabConverters",
"{",
"hyphenated",
"=",
"converter",
".",
"re",
".",
"ReplaceAllString",
"(",
"hyphenated",
",",
"converter",
".",
"repl",
")",
"\n",
"}",
"\n",
"hyphenated",
"=",
"strings",
".",
"ToLower",
"(",
"hyphenated",
")",
"\n",
"memoizer",
".",
"memo",
"[",
"name",
"]",
"=",
"hyphenated",
"\n",
"return",
"\n",
"}"
] | // toKebabCase produces a monitoring compliant name from the
// original. It converts CamelCase to camel-case,
// and CAMEL_CASE to camel-case. For numbers, it
// converts 0.5 to v0_5. | [
"toKebabCase",
"produces",
"a",
"monitoring",
"compliant",
"name",
"from",
"the",
"original",
".",
"It",
"converts",
"CamelCase",
"to",
"camel",
"-",
"case",
"and",
"CAMEL_CASE",
"to",
"camel",
"-",
"case",
".",
"For",
"numbers",
"it",
"converts",
"0",
".",
"5",
"to",
"v0_5",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/stats/kebab_case_converter.go#L29-L42 |
157,950 | vitessio/vitess | go/vt/vttablet/tabletserver/splitquery/full_scan_algorithm.go | NewFullScanAlgorithm | func NewFullScanAlgorithm(
splitParams *SplitParams, sqlExecuter SQLExecuter) (*FullScanAlgorithm, error) {
if !splitParams.areSplitColumnsPrimaryKey() {
return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT,
"Using the FULL_SCAN algorithm requires split columns to be"+
" the primary key. Got: %+v", splitParams)
}
result := &FullScanAlgorithm{
splitParams: splitParams,
sqlExecuter: sqlExecuter,
prevBindVariableNames: buildPrevBindVariableNames(splitParams.splitColumns),
}
result.initialQuery = buildInitialQuery(splitParams)
result.noninitialQuery = buildNoninitialQuery(splitParams, result.prevBindVariableNames)
return result, nil
} | go | func NewFullScanAlgorithm(
splitParams *SplitParams, sqlExecuter SQLExecuter) (*FullScanAlgorithm, error) {
if !splitParams.areSplitColumnsPrimaryKey() {
return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT,
"Using the FULL_SCAN algorithm requires split columns to be"+
" the primary key. Got: %+v", splitParams)
}
result := &FullScanAlgorithm{
splitParams: splitParams,
sqlExecuter: sqlExecuter,
prevBindVariableNames: buildPrevBindVariableNames(splitParams.splitColumns),
}
result.initialQuery = buildInitialQuery(splitParams)
result.noninitialQuery = buildNoninitialQuery(splitParams, result.prevBindVariableNames)
return result, nil
} | [
"func",
"NewFullScanAlgorithm",
"(",
"splitParams",
"*",
"SplitParams",
",",
"sqlExecuter",
"SQLExecuter",
")",
"(",
"*",
"FullScanAlgorithm",
",",
"error",
")",
"{",
"if",
"!",
"splitParams",
".",
"areSplitColumnsPrimaryKey",
"(",
")",
"{",
"return",
"nil",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpcpb",
".",
"Code_INVALID_ARGUMENT",
",",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"splitParams",
")",
"\n",
"}",
"\n",
"result",
":=",
"&",
"FullScanAlgorithm",
"{",
"splitParams",
":",
"splitParams",
",",
"sqlExecuter",
":",
"sqlExecuter",
",",
"prevBindVariableNames",
":",
"buildPrevBindVariableNames",
"(",
"splitParams",
".",
"splitColumns",
")",
",",
"}",
"\n",
"result",
".",
"initialQuery",
"=",
"buildInitialQuery",
"(",
"splitParams",
")",
"\n",
"result",
".",
"noninitialQuery",
"=",
"buildNoninitialQuery",
"(",
"splitParams",
",",
"result",
".",
"prevBindVariableNames",
")",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // NewFullScanAlgorithm constructs a new FullScanAlgorithm. | [
"NewFullScanAlgorithm",
"constructs",
"a",
"new",
"FullScanAlgorithm",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/splitquery/full_scan_algorithm.go#L67-L83 |
157,951 | vitessio/vitess | go/vt/topo/zk2topo/server.go | hasObservers | func hasObservers(serverAddr string) (string, string, bool) {
if i := strings.Index(serverAddr, "|"); i != -1 {
return serverAddr[:i], serverAddr[i+1:], true
}
return "", "", false
} | go | func hasObservers(serverAddr string) (string, string, bool) {
if i := strings.Index(serverAddr, "|"); i != -1 {
return serverAddr[:i], serverAddr[i+1:], true
}
return "", "", false
} | [
"func",
"hasObservers",
"(",
"serverAddr",
"string",
")",
"(",
"string",
",",
"string",
",",
"bool",
")",
"{",
"if",
"i",
":=",
"strings",
".",
"Index",
"(",
"serverAddr",
",",
"\"",
"\"",
")",
";",
"i",
"!=",
"-",
"1",
"{",
"return",
"serverAddr",
"[",
":",
"i",
"]",
",",
"serverAddr",
"[",
"i",
"+",
"1",
":",
"]",
",",
"true",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"false",
"\n",
"}"
] | // hasObservers checks the provided address to see if it has observers.
// If so, it returns the voting server address, the observer address, and true.
// Otherwise, it returns false. | [
"hasObservers",
"checks",
"the",
"provided",
"address",
"to",
"see",
"if",
"it",
"has",
"observers",
".",
"If",
"so",
"it",
"returns",
"the",
"voting",
"server",
"address",
"the",
"observer",
"address",
"and",
"true",
".",
"Otherwise",
"it",
"returns",
"false",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/zk2topo/server.go#L37-L42 |
157,952 | vitessio/vitess | go/vt/topo/zk2topo/server.go | NewServer | func NewServer(serverAddr, root string) *Server {
return &Server{
root: root,
conn: Connect(serverAddr),
}
} | go | func NewServer(serverAddr, root string) *Server {
return &Server{
root: root,
conn: Connect(serverAddr),
}
} | [
"func",
"NewServer",
"(",
"serverAddr",
",",
"root",
"string",
")",
"*",
"Server",
"{",
"return",
"&",
"Server",
"{",
"root",
":",
"root",
",",
"conn",
":",
"Connect",
"(",
"serverAddr",
")",
",",
"}",
"\n",
"}"
] | // NewServer returns a topo.Conn connecting to real Zookeeper processes. | [
"NewServer",
"returns",
"a",
"topo",
".",
"Conn",
"connecting",
"to",
"real",
"Zookeeper",
"processes",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/zk2topo/server.go#L86-L91 |
157,953 | vitessio/vitess | go/vt/vtgate/queryz.go | ShardQueriesPQ | func (qzs *queryzRow) ShardQueriesPQ() string {
val := float64(qzs.ShardQueries) / float64(qzs.Count)
return fmt.Sprintf("%.6f", val)
} | go | func (qzs *queryzRow) ShardQueriesPQ() string {
val := float64(qzs.ShardQueries) / float64(qzs.Count)
return fmt.Sprintf("%.6f", val)
} | [
"func",
"(",
"qzs",
"*",
"queryzRow",
")",
"ShardQueriesPQ",
"(",
")",
"string",
"{",
"val",
":=",
"float64",
"(",
"qzs",
".",
"ShardQueries",
")",
"/",
"float64",
"(",
"qzs",
".",
"Count",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"val",
")",
"\n",
"}"
] | // ShardQueriesPQ returns the shard query count per query as a string. | [
"ShardQueriesPQ",
"returns",
"the",
"shard",
"query",
"count",
"per",
"query",
"as",
"a",
"string",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/queryz.go#L93-L96 |
157,954 | vitessio/vitess | go/vt/vttablet/sandboxconn/sandboxconn.go | NewSandboxConn | func NewSandboxConn(t *topodatapb.Tablet) *SandboxConn {
return &SandboxConn{
tablet: t,
MustFailCodes: make(map[vtrpcpb.Code]int),
}
} | go | func NewSandboxConn(t *topodatapb.Tablet) *SandboxConn {
return &SandboxConn{
tablet: t,
MustFailCodes: make(map[vtrpcpb.Code]int),
}
} | [
"func",
"NewSandboxConn",
"(",
"t",
"*",
"topodatapb",
".",
"Tablet",
")",
"*",
"SandboxConn",
"{",
"return",
"&",
"SandboxConn",
"{",
"tablet",
":",
"t",
",",
"MustFailCodes",
":",
"make",
"(",
"map",
"[",
"vtrpcpb",
".",
"Code",
"]",
"int",
")",
",",
"}",
"\n",
"}"
] | // NewSandboxConn returns a new SandboxConn targeted to the provided tablet. | [
"NewSandboxConn",
"returns",
"a",
"new",
"SandboxConn",
"targeted",
"to",
"the",
"provided",
"tablet",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/sandboxconn/sandboxconn.go#L96-L101 |
157,955 | vitessio/vitess | go/vt/vttablet/sandboxconn/sandboxconn.go | Commit | func (sbc *SandboxConn) Commit(ctx context.Context, target *querypb.Target, transactionID int64) error {
sbc.CommitCount.Add(1)
return sbc.getError()
} | go | func (sbc *SandboxConn) Commit(ctx context.Context, target *querypb.Target, transactionID int64) error {
sbc.CommitCount.Add(1)
return sbc.getError()
} | [
"func",
"(",
"sbc",
"*",
"SandboxConn",
")",
"Commit",
"(",
"ctx",
"context",
".",
"Context",
",",
"target",
"*",
"querypb",
".",
"Target",
",",
"transactionID",
"int64",
")",
"error",
"{",
"sbc",
".",
"CommitCount",
".",
"Add",
"(",
"1",
")",
"\n",
"return",
"sbc",
".",
"getError",
"(",
")",
"\n",
"}"
] | // Commit is part of the QueryService interface. | [
"Commit",
"is",
"part",
"of",
"the",
"QueryService",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/sandboxconn/sandboxconn.go#L185-L188 |
157,956 | vitessio/vitess | go/vt/vttablet/sandboxconn/sandboxconn.go | CommitPrepared | func (sbc *SandboxConn) CommitPrepared(ctx context.Context, target *querypb.Target, dtid string) (err error) {
sbc.CommitPreparedCount.Add(1)
if sbc.MustFailCommitPrepared > 0 {
sbc.MustFailCommitPrepared--
return vterrors.New(vtrpcpb.Code_FAILED_PRECONDITION, "error: err")
}
return sbc.getError()
} | go | func (sbc *SandboxConn) CommitPrepared(ctx context.Context, target *querypb.Target, dtid string) (err error) {
sbc.CommitPreparedCount.Add(1)
if sbc.MustFailCommitPrepared > 0 {
sbc.MustFailCommitPrepared--
return vterrors.New(vtrpcpb.Code_FAILED_PRECONDITION, "error: err")
}
return sbc.getError()
} | [
"func",
"(",
"sbc",
"*",
"SandboxConn",
")",
"CommitPrepared",
"(",
"ctx",
"context",
".",
"Context",
",",
"target",
"*",
"querypb",
".",
"Target",
",",
"dtid",
"string",
")",
"(",
"err",
"error",
")",
"{",
"sbc",
".",
"CommitPreparedCount",
".",
"Add",
"(",
"1",
")",
"\n",
"if",
"sbc",
".",
"MustFailCommitPrepared",
">",
"0",
"{",
"sbc",
".",
"MustFailCommitPrepared",
"--",
"\n",
"return",
"vterrors",
".",
"New",
"(",
"vtrpcpb",
".",
"Code_FAILED_PRECONDITION",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"sbc",
".",
"getError",
"(",
")",
"\n",
"}"
] | // CommitPrepared commits the prepared transaction. | [
"CommitPrepared",
"commits",
"the",
"prepared",
"transaction",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/sandboxconn/sandboxconn.go#L207-L214 |
157,957 | vitessio/vitess | go/vt/vttablet/sandboxconn/sandboxconn.go | RollbackPrepared | func (sbc *SandboxConn) RollbackPrepared(ctx context.Context, target *querypb.Target, dtid string, originalID int64) (err error) {
sbc.RollbackPreparedCount.Add(1)
if sbc.MustFailRollbackPrepared > 0 {
sbc.MustFailRollbackPrepared--
return vterrors.New(vtrpcpb.Code_FAILED_PRECONDITION, "error: err")
}
return sbc.getError()
} | go | func (sbc *SandboxConn) RollbackPrepared(ctx context.Context, target *querypb.Target, dtid string, originalID int64) (err error) {
sbc.RollbackPreparedCount.Add(1)
if sbc.MustFailRollbackPrepared > 0 {
sbc.MustFailRollbackPrepared--
return vterrors.New(vtrpcpb.Code_FAILED_PRECONDITION, "error: err")
}
return sbc.getError()
} | [
"func",
"(",
"sbc",
"*",
"SandboxConn",
")",
"RollbackPrepared",
"(",
"ctx",
"context",
".",
"Context",
",",
"target",
"*",
"querypb",
".",
"Target",
",",
"dtid",
"string",
",",
"originalID",
"int64",
")",
"(",
"err",
"error",
")",
"{",
"sbc",
".",
"RollbackPreparedCount",
".",
"Add",
"(",
"1",
")",
"\n",
"if",
"sbc",
".",
"MustFailRollbackPrepared",
">",
"0",
"{",
"sbc",
".",
"MustFailRollbackPrepared",
"--",
"\n",
"return",
"vterrors",
".",
"New",
"(",
"vtrpcpb",
".",
"Code_FAILED_PRECONDITION",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"sbc",
".",
"getError",
"(",
")",
"\n",
"}"
] | // RollbackPrepared rolls back the prepared transaction. | [
"RollbackPrepared",
"rolls",
"back",
"the",
"prepared",
"transaction",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/sandboxconn/sandboxconn.go#L217-L224 |
157,958 | vitessio/vitess | go/vt/vttablet/sandboxconn/sandboxconn.go | CreateTransaction | func (sbc *SandboxConn) CreateTransaction(ctx context.Context, target *querypb.Target, dtid string, participants []*querypb.Target) (err error) {
sbc.CreateTransactionCount.Add(1)
if sbc.MustFailCreateTransaction > 0 {
sbc.MustFailCreateTransaction--
return vterrors.New(vtrpcpb.Code_FAILED_PRECONDITION, "error: err")
}
return sbc.getError()
} | go | func (sbc *SandboxConn) CreateTransaction(ctx context.Context, target *querypb.Target, dtid string, participants []*querypb.Target) (err error) {
sbc.CreateTransactionCount.Add(1)
if sbc.MustFailCreateTransaction > 0 {
sbc.MustFailCreateTransaction--
return vterrors.New(vtrpcpb.Code_FAILED_PRECONDITION, "error: err")
}
return sbc.getError()
} | [
"func",
"(",
"sbc",
"*",
"SandboxConn",
")",
"CreateTransaction",
"(",
"ctx",
"context",
".",
"Context",
",",
"target",
"*",
"querypb",
".",
"Target",
",",
"dtid",
"string",
",",
"participants",
"[",
"]",
"*",
"querypb",
".",
"Target",
")",
"(",
"err",
"error",
")",
"{",
"sbc",
".",
"CreateTransactionCount",
".",
"Add",
"(",
"1",
")",
"\n",
"if",
"sbc",
".",
"MustFailCreateTransaction",
">",
"0",
"{",
"sbc",
".",
"MustFailCreateTransaction",
"--",
"\n",
"return",
"vterrors",
".",
"New",
"(",
"vtrpcpb",
".",
"Code_FAILED_PRECONDITION",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"sbc",
".",
"getError",
"(",
")",
"\n",
"}"
] | // CreateTransaction creates the metadata for a 2PC transaction. | [
"CreateTransaction",
"creates",
"the",
"metadata",
"for",
"a",
"2PC",
"transaction",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/sandboxconn/sandboxconn.go#L227-L234 |
157,959 | vitessio/vitess | go/vt/vttablet/sandboxconn/sandboxconn.go | SetRollback | func (sbc *SandboxConn) SetRollback(ctx context.Context, target *querypb.Target, dtid string, transactionID int64) (err error) {
sbc.SetRollbackCount.Add(1)
if sbc.MustFailSetRollback > 0 {
sbc.MustFailSetRollback--
return vterrors.New(vtrpcpb.Code_FAILED_PRECONDITION, "error: err")
}
return sbc.getError()
} | go | func (sbc *SandboxConn) SetRollback(ctx context.Context, target *querypb.Target, dtid string, transactionID int64) (err error) {
sbc.SetRollbackCount.Add(1)
if sbc.MustFailSetRollback > 0 {
sbc.MustFailSetRollback--
return vterrors.New(vtrpcpb.Code_FAILED_PRECONDITION, "error: err")
}
return sbc.getError()
} | [
"func",
"(",
"sbc",
"*",
"SandboxConn",
")",
"SetRollback",
"(",
"ctx",
"context",
".",
"Context",
",",
"target",
"*",
"querypb",
".",
"Target",
",",
"dtid",
"string",
",",
"transactionID",
"int64",
")",
"(",
"err",
"error",
")",
"{",
"sbc",
".",
"SetRollbackCount",
".",
"Add",
"(",
"1",
")",
"\n",
"if",
"sbc",
".",
"MustFailSetRollback",
">",
"0",
"{",
"sbc",
".",
"MustFailSetRollback",
"--",
"\n",
"return",
"vterrors",
".",
"New",
"(",
"vtrpcpb",
".",
"Code_FAILED_PRECONDITION",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"sbc",
".",
"getError",
"(",
")",
"\n",
"}"
] | // SetRollback transitions the 2pc transaction to the Rollback state.
// If a transaction id is provided, that transaction is also rolled back. | [
"SetRollback",
"transitions",
"the",
"2pc",
"transaction",
"to",
"the",
"Rollback",
"state",
".",
"If",
"a",
"transaction",
"id",
"is",
"provided",
"that",
"transaction",
"is",
"also",
"rolled",
"back",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/sandboxconn/sandboxconn.go#L249-L256 |
157,960 | vitessio/vitess | go/vt/vttablet/sandboxconn/sandboxconn.go | BeginExecute | func (sbc *SandboxConn) BeginExecute(ctx context.Context, target *querypb.Target, query string, bindVars map[string]*querypb.BindVariable, options *querypb.ExecuteOptions) (*sqltypes.Result, int64, error) {
transactionID, err := sbc.Begin(ctx, target, options)
if err != nil {
return nil, 0, err
}
result, err := sbc.Execute(ctx, target, query, bindVars, transactionID, options)
return result, transactionID, err
} | go | func (sbc *SandboxConn) BeginExecute(ctx context.Context, target *querypb.Target, query string, bindVars map[string]*querypb.BindVariable, options *querypb.ExecuteOptions) (*sqltypes.Result, int64, error) {
transactionID, err := sbc.Begin(ctx, target, options)
if err != nil {
return nil, 0, err
}
result, err := sbc.Execute(ctx, target, query, bindVars, transactionID, options)
return result, transactionID, err
} | [
"func",
"(",
"sbc",
"*",
"SandboxConn",
")",
"BeginExecute",
"(",
"ctx",
"context",
".",
"Context",
",",
"target",
"*",
"querypb",
".",
"Target",
",",
"query",
"string",
",",
"bindVars",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
",",
"options",
"*",
"querypb",
".",
"ExecuteOptions",
")",
"(",
"*",
"sqltypes",
".",
"Result",
",",
"int64",
",",
"error",
")",
"{",
"transactionID",
",",
"err",
":=",
"sbc",
".",
"Begin",
"(",
"ctx",
",",
"target",
",",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"0",
",",
"err",
"\n",
"}",
"\n",
"result",
",",
"err",
":=",
"sbc",
".",
"Execute",
"(",
"ctx",
",",
"target",
",",
"query",
",",
"bindVars",
",",
"transactionID",
",",
"options",
")",
"\n",
"return",
"result",
",",
"transactionID",
",",
"err",
"\n",
"}"
] | // BeginExecute is part of the QueryService interface. | [
"BeginExecute",
"is",
"part",
"of",
"the",
"QueryService",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/sandboxconn/sandboxconn.go#L284-L291 |
157,961 | vitessio/vitess | go/vt/vttablet/sandboxconn/sandboxconn.go | MessageStream | func (sbc *SandboxConn) MessageStream(ctx context.Context, target *querypb.Target, name string, callback func(*sqltypes.Result) error) (err error) {
if err := sbc.getError(); err != nil {
return err
}
r := sbc.getNextResult()
if r == nil {
return nil
}
callback(r)
return nil
} | go | func (sbc *SandboxConn) MessageStream(ctx context.Context, target *querypb.Target, name string, callback func(*sqltypes.Result) error) (err error) {
if err := sbc.getError(); err != nil {
return err
}
r := sbc.getNextResult()
if r == nil {
return nil
}
callback(r)
return nil
} | [
"func",
"(",
"sbc",
"*",
"SandboxConn",
")",
"MessageStream",
"(",
"ctx",
"context",
".",
"Context",
",",
"target",
"*",
"querypb",
".",
"Target",
",",
"name",
"string",
",",
"callback",
"func",
"(",
"*",
"sqltypes",
".",
"Result",
")",
"error",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"sbc",
".",
"getError",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"r",
":=",
"sbc",
".",
"getNextResult",
"(",
")",
"\n",
"if",
"r",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"callback",
"(",
"r",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // MessageStream is part of the QueryService interface. | [
"MessageStream",
"is",
"part",
"of",
"the",
"QueryService",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/sandboxconn/sandboxconn.go#L304-L314 |
157,962 | vitessio/vitess | go/vt/vttablet/sandboxconn/sandboxconn.go | MessageAck | func (sbc *SandboxConn) MessageAck(ctx context.Context, target *querypb.Target, name string, ids []*querypb.Value) (count int64, err error) {
sbc.MessageIDs = ids
return int64(len(ids)), nil
} | go | func (sbc *SandboxConn) MessageAck(ctx context.Context, target *querypb.Target, name string, ids []*querypb.Value) (count int64, err error) {
sbc.MessageIDs = ids
return int64(len(ids)), nil
} | [
"func",
"(",
"sbc",
"*",
"SandboxConn",
")",
"MessageAck",
"(",
"ctx",
"context",
".",
"Context",
",",
"target",
"*",
"querypb",
".",
"Target",
",",
"name",
"string",
",",
"ids",
"[",
"]",
"*",
"querypb",
".",
"Value",
")",
"(",
"count",
"int64",
",",
"err",
"error",
")",
"{",
"sbc",
".",
"MessageIDs",
"=",
"ids",
"\n",
"return",
"int64",
"(",
"len",
"(",
"ids",
")",
")",
",",
"nil",
"\n",
"}"
] | // MessageAck is part of the QueryService interface. | [
"MessageAck",
"is",
"part",
"of",
"the",
"QueryService",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/sandboxconn/sandboxconn.go#L317-L320 |
157,963 | vitessio/vitess | go/vt/vttablet/sandboxconn/sandboxconn.go | SplitQuery | func (sbc *SandboxConn) SplitQuery(
ctx context.Context,
target *querypb.Target,
query *querypb.BoundQuery,
splitColumns []string,
splitCount int64,
numRowsPerQueryPart int64,
algorithm querypb.SplitQueryRequest_Algorithm) ([]*querypb.QuerySplit, error) {
err := sbc.getError()
if err != nil {
return nil, err
}
splits := []*querypb.QuerySplit{
{
Query: &querypb.BoundQuery{
Sql: fmt.Sprintf(
"query:%v, splitColumns:%v, splitCount:%v,"+
" numRowsPerQueryPart:%v, algorithm:%v, shard:%v",
query, splitColumns, splitCount, numRowsPerQueryPart, algorithm, sbc.tablet.Shard),
},
},
}
return splits, nil
} | go | func (sbc *SandboxConn) SplitQuery(
ctx context.Context,
target *querypb.Target,
query *querypb.BoundQuery,
splitColumns []string,
splitCount int64,
numRowsPerQueryPart int64,
algorithm querypb.SplitQueryRequest_Algorithm) ([]*querypb.QuerySplit, error) {
err := sbc.getError()
if err != nil {
return nil, err
}
splits := []*querypb.QuerySplit{
{
Query: &querypb.BoundQuery{
Sql: fmt.Sprintf(
"query:%v, splitColumns:%v, splitCount:%v,"+
" numRowsPerQueryPart:%v, algorithm:%v, shard:%v",
query, splitColumns, splitCount, numRowsPerQueryPart, algorithm, sbc.tablet.Shard),
},
},
}
return splits, nil
} | [
"func",
"(",
"sbc",
"*",
"SandboxConn",
")",
"SplitQuery",
"(",
"ctx",
"context",
".",
"Context",
",",
"target",
"*",
"querypb",
".",
"Target",
",",
"query",
"*",
"querypb",
".",
"BoundQuery",
",",
"splitColumns",
"[",
"]",
"string",
",",
"splitCount",
"int64",
",",
"numRowsPerQueryPart",
"int64",
",",
"algorithm",
"querypb",
".",
"SplitQueryRequest_Algorithm",
")",
"(",
"[",
"]",
"*",
"querypb",
".",
"QuerySplit",
",",
"error",
")",
"{",
"err",
":=",
"sbc",
".",
"getError",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"splits",
":=",
"[",
"]",
"*",
"querypb",
".",
"QuerySplit",
"{",
"{",
"Query",
":",
"&",
"querypb",
".",
"BoundQuery",
"{",
"Sql",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"query",
",",
"splitColumns",
",",
"splitCount",
",",
"numRowsPerQueryPart",
",",
"algorithm",
",",
"sbc",
".",
"tablet",
".",
"Shard",
")",
",",
"}",
",",
"}",
",",
"}",
"\n",
"return",
"splits",
",",
"nil",
"\n",
"}"
] | // SplitQuery returns a single QuerySplit whose 'sql' field describes the received arguments. | [
"SplitQuery",
"returns",
"a",
"single",
"QuerySplit",
"whose",
"sql",
"field",
"describes",
"the",
"received",
"arguments",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/sandboxconn/sandboxconn.go#L326-L349 |
157,964 | vitessio/vitess | go/vt/vttablet/sandboxconn/sandboxconn.go | StreamHealth | func (sbc *SandboxConn) StreamHealth(ctx context.Context, callback func(*querypb.StreamHealthResponse) error) error {
return fmt.Errorf("not implemented in test")
} | go | func (sbc *SandboxConn) StreamHealth(ctx context.Context, callback func(*querypb.StreamHealthResponse) error) error {
return fmt.Errorf("not implemented in test")
} | [
"func",
"(",
"sbc",
"*",
"SandboxConn",
")",
"StreamHealth",
"(",
"ctx",
"context",
".",
"Context",
",",
"callback",
"func",
"(",
"*",
"querypb",
".",
"StreamHealthResponse",
")",
"error",
")",
"error",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // StreamHealth is not implemented. | [
"StreamHealth",
"is",
"not",
"implemented",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/sandboxconn/sandboxconn.go#L352-L354 |
157,965 | vitessio/vitess | go/vt/vttablet/sandboxconn/sandboxconn.go | UpdateStream | func (sbc *SandboxConn) UpdateStream(ctx context.Context, target *querypb.Target, position string, timestamp int64, callback func(*querypb.StreamEvent) error) error {
return fmt.Errorf("not implemented in test")
} | go | func (sbc *SandboxConn) UpdateStream(ctx context.Context, target *querypb.Target, position string, timestamp int64, callback func(*querypb.StreamEvent) error) error {
return fmt.Errorf("not implemented in test")
} | [
"func",
"(",
"sbc",
"*",
"SandboxConn",
")",
"UpdateStream",
"(",
"ctx",
"context",
".",
"Context",
",",
"target",
"*",
"querypb",
".",
"Target",
",",
"position",
"string",
",",
"timestamp",
"int64",
",",
"callback",
"func",
"(",
"*",
"querypb",
".",
"StreamEvent",
")",
"error",
")",
"error",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // UpdateStream is part of the QueryService interface. | [
"UpdateStream",
"is",
"part",
"of",
"the",
"QueryService",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/sandboxconn/sandboxconn.go#L357-L359 |
157,966 | vitessio/vitess | go/vt/vttablet/sandboxconn/sandboxconn.go | VStream | func (sbc *SandboxConn) VStream(ctx context.Context, target *querypb.Target, startPos string, filter *binlogdatapb.Filter, send func([]*binlogdatapb.VEvent) error) error {
return fmt.Errorf("not implemented in test")
} | go | func (sbc *SandboxConn) VStream(ctx context.Context, target *querypb.Target, startPos string, filter *binlogdatapb.Filter, send func([]*binlogdatapb.VEvent) error) error {
return fmt.Errorf("not implemented in test")
} | [
"func",
"(",
"sbc",
"*",
"SandboxConn",
")",
"VStream",
"(",
"ctx",
"context",
".",
"Context",
",",
"target",
"*",
"querypb",
".",
"Target",
",",
"startPos",
"string",
",",
"filter",
"*",
"binlogdatapb",
".",
"Filter",
",",
"send",
"func",
"(",
"[",
"]",
"*",
"binlogdatapb",
".",
"VEvent",
")",
"error",
")",
"error",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // VStream is part of the QueryService interface. | [
"VStream",
"is",
"part",
"of",
"the",
"QueryService",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/sandboxconn/sandboxconn.go#L362-L364 |
157,967 | vitessio/vitess | go/mysql/charset.go | ExecuteFetchMap | func ExecuteFetchMap(conn *Conn, query string) (map[string]string, error) {
qr, err := conn.ExecuteFetch(query, 1, true)
if err != nil {
return nil, err
}
if len(qr.Rows) != 1 {
return nil, vterrors.Errorf(vtrpc.Code_OUT_OF_RANGE, "query %#v returned %d rows, expected 1", query, len(qr.Rows))
}
if len(qr.Fields) != len(qr.Rows[0]) {
return nil, vterrors.Errorf(vtrpc.Code_INTERNAL, "query %#v returned %d column names, expected %d", query, len(qr.Fields), len(qr.Rows[0]))
}
rowMap := make(map[string]string)
for i, value := range qr.Rows[0] {
rowMap[qr.Fields[i].Name] = value.ToString()
}
return rowMap, nil
} | go | func ExecuteFetchMap(conn *Conn, query string) (map[string]string, error) {
qr, err := conn.ExecuteFetch(query, 1, true)
if err != nil {
return nil, err
}
if len(qr.Rows) != 1 {
return nil, vterrors.Errorf(vtrpc.Code_OUT_OF_RANGE, "query %#v returned %d rows, expected 1", query, len(qr.Rows))
}
if len(qr.Fields) != len(qr.Rows[0]) {
return nil, vterrors.Errorf(vtrpc.Code_INTERNAL, "query %#v returned %d column names, expected %d", query, len(qr.Fields), len(qr.Rows[0]))
}
rowMap := make(map[string]string)
for i, value := range qr.Rows[0] {
rowMap[qr.Fields[i].Name] = value.ToString()
}
return rowMap, nil
} | [
"func",
"ExecuteFetchMap",
"(",
"conn",
"*",
"Conn",
",",
"query",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"qr",
",",
"err",
":=",
"conn",
".",
"ExecuteFetch",
"(",
"query",
",",
"1",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"qr",
".",
"Rows",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_OUT_OF_RANGE",
",",
"\"",
"\"",
",",
"query",
",",
"len",
"(",
"qr",
".",
"Rows",
")",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"qr",
".",
"Fields",
")",
"!=",
"len",
"(",
"qr",
".",
"Rows",
"[",
"0",
"]",
")",
"{",
"return",
"nil",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_INTERNAL",
",",
"\"",
"\"",
",",
"query",
",",
"len",
"(",
"qr",
".",
"Fields",
")",
",",
"len",
"(",
"qr",
".",
"Rows",
"[",
"0",
"]",
")",
")",
"\n",
"}",
"\n\n",
"rowMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"for",
"i",
",",
"value",
":=",
"range",
"qr",
".",
"Rows",
"[",
"0",
"]",
"{",
"rowMap",
"[",
"qr",
".",
"Fields",
"[",
"i",
"]",
".",
"Name",
"]",
"=",
"value",
".",
"ToString",
"(",
")",
"\n",
"}",
"\n",
"return",
"rowMap",
",",
"nil",
"\n",
"}"
] | // This file contains utility methods for Conn objects. Only useful on the client
// side.
// ExecuteFetchMap returns a map from column names to cell data for a query
// that should return exactly 1 row. | [
"This",
"file",
"contains",
"utility",
"methods",
"for",
"Conn",
"objects",
".",
"Only",
"useful",
"on",
"the",
"client",
"side",
".",
"ExecuteFetchMap",
"returns",
"a",
"map",
"from",
"column",
"names",
"to",
"cell",
"data",
"for",
"a",
"query",
"that",
"should",
"return",
"exactly",
"1",
"row",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/charset.go#L33-L50 |
157,968 | vitessio/vitess | go/mysql/charset.go | GetCharset | func GetCharset(conn *Conn) (*binlogdatapb.Charset, error) {
// character_set_client
row, err := ExecuteFetchMap(conn, "SHOW COLLATION WHERE `charset`=@@session.character_set_client AND `default`='Yes'")
if err != nil {
return nil, err
}
client, err := strconv.ParseInt(row["Id"], 10, 16)
if err != nil {
return nil, err
}
// collation_connection
row, err = ExecuteFetchMap(conn, "SHOW COLLATION WHERE `collation`=@@session.collation_connection")
if err != nil {
return nil, err
}
connection, err := strconv.ParseInt(row["Id"], 10, 16)
if err != nil {
return nil, err
}
// collation_server
row, err = ExecuteFetchMap(conn, "SHOW COLLATION WHERE `collation`=@@session.collation_server")
if err != nil {
return nil, err
}
server, err := strconv.ParseInt(row["Id"], 10, 16)
if err != nil {
return nil, err
}
return &binlogdatapb.Charset{
Client: int32(client),
Conn: int32(connection),
Server: int32(server),
}, nil
} | go | func GetCharset(conn *Conn) (*binlogdatapb.Charset, error) {
// character_set_client
row, err := ExecuteFetchMap(conn, "SHOW COLLATION WHERE `charset`=@@session.character_set_client AND `default`='Yes'")
if err != nil {
return nil, err
}
client, err := strconv.ParseInt(row["Id"], 10, 16)
if err != nil {
return nil, err
}
// collation_connection
row, err = ExecuteFetchMap(conn, "SHOW COLLATION WHERE `collation`=@@session.collation_connection")
if err != nil {
return nil, err
}
connection, err := strconv.ParseInt(row["Id"], 10, 16)
if err != nil {
return nil, err
}
// collation_server
row, err = ExecuteFetchMap(conn, "SHOW COLLATION WHERE `collation`=@@session.collation_server")
if err != nil {
return nil, err
}
server, err := strconv.ParseInt(row["Id"], 10, 16)
if err != nil {
return nil, err
}
return &binlogdatapb.Charset{
Client: int32(client),
Conn: int32(connection),
Server: int32(server),
}, nil
} | [
"func",
"GetCharset",
"(",
"conn",
"*",
"Conn",
")",
"(",
"*",
"binlogdatapb",
".",
"Charset",
",",
"error",
")",
"{",
"// character_set_client",
"row",
",",
"err",
":=",
"ExecuteFetchMap",
"(",
"conn",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"client",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"row",
"[",
"\"",
"\"",
"]",
",",
"10",
",",
"16",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// collation_connection",
"row",
",",
"err",
"=",
"ExecuteFetchMap",
"(",
"conn",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"connection",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"row",
"[",
"\"",
"\"",
"]",
",",
"10",
",",
"16",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// collation_server",
"row",
",",
"err",
"=",
"ExecuteFetchMap",
"(",
"conn",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"server",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"row",
"[",
"\"",
"\"",
"]",
",",
"10",
",",
"16",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"binlogdatapb",
".",
"Charset",
"{",
"Client",
":",
"int32",
"(",
"client",
")",
",",
"Conn",
":",
"int32",
"(",
"connection",
")",
",",
"Server",
":",
"int32",
"(",
"server",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // GetCharset returns the current numerical values of the per-session character
// set variables. | [
"GetCharset",
"returns",
"the",
"current",
"numerical",
"values",
"of",
"the",
"per",
"-",
"session",
"character",
"set",
"variables",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/charset.go#L54-L90 |
157,969 | vitessio/vitess | go/mysql/charset.go | SetCharset | func SetCharset(conn *Conn, cs *binlogdatapb.Charset) error {
sql := fmt.Sprintf(
"SET @@session.character_set_client=%d, @@session.collation_connection=%d, @@session.collation_server=%d",
cs.Client, cs.Conn, cs.Server)
_, err := conn.ExecuteFetch(sql, 1, false)
return err
} | go | func SetCharset(conn *Conn, cs *binlogdatapb.Charset) error {
sql := fmt.Sprintf(
"SET @@session.character_set_client=%d, @@session.collation_connection=%d, @@session.collation_server=%d",
cs.Client, cs.Conn, cs.Server)
_, err := conn.ExecuteFetch(sql, 1, false)
return err
} | [
"func",
"SetCharset",
"(",
"conn",
"*",
"Conn",
",",
"cs",
"*",
"binlogdatapb",
".",
"Charset",
")",
"error",
"{",
"sql",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"cs",
".",
"Client",
",",
"cs",
".",
"Conn",
",",
"cs",
".",
"Server",
")",
"\n",
"_",
",",
"err",
":=",
"conn",
".",
"ExecuteFetch",
"(",
"sql",
",",
"1",
",",
"false",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // SetCharset changes the per-session character set variables. | [
"SetCharset",
"changes",
"the",
"per",
"-",
"session",
"character",
"set",
"variables",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/charset.go#L93-L99 |
157,970 | vitessio/vitess | go/vt/mysqlctl/builtinbackupengine.go | isDbDir | func isDbDir(p string) bool {
// db.opt is there
if _, err := os.Stat(path.Join(p, "db.opt")); err == nil {
return true
}
// Look for at least one database file
fis, err := ioutil.ReadDir(p)
if err != nil {
return false
}
for _, fi := range fis {
if strings.HasSuffix(fi.Name(), ".frm") {
return true
}
// the MyRocks engine stores data in RocksDB .sst files
// https://github.com/facebook/rocksdb/wiki/Rocksdb-BlockBasedTable-Format
if strings.HasSuffix(fi.Name(), ".sst") {
return true
}
// .frm files were removed in MySQL 8, so we need to check for two other file types
// https://dev.mysql.com/doc/refman/8.0/en/data-dictionary-file-removal.html
if strings.HasSuffix(fi.Name(), ".ibd") {
return true
}
// https://dev.mysql.com/doc/refman/8.0/en/serialized-dictionary-information.html
if strings.HasSuffix(fi.Name(), ".sdi") {
return true
}
}
return false
} | go | func isDbDir(p string) bool {
// db.opt is there
if _, err := os.Stat(path.Join(p, "db.opt")); err == nil {
return true
}
// Look for at least one database file
fis, err := ioutil.ReadDir(p)
if err != nil {
return false
}
for _, fi := range fis {
if strings.HasSuffix(fi.Name(), ".frm") {
return true
}
// the MyRocks engine stores data in RocksDB .sst files
// https://github.com/facebook/rocksdb/wiki/Rocksdb-BlockBasedTable-Format
if strings.HasSuffix(fi.Name(), ".sst") {
return true
}
// .frm files were removed in MySQL 8, so we need to check for two other file types
// https://dev.mysql.com/doc/refman/8.0/en/data-dictionary-file-removal.html
if strings.HasSuffix(fi.Name(), ".ibd") {
return true
}
// https://dev.mysql.com/doc/refman/8.0/en/serialized-dictionary-information.html
if strings.HasSuffix(fi.Name(), ".sdi") {
return true
}
}
return false
} | [
"func",
"isDbDir",
"(",
"p",
"string",
")",
"bool",
"{",
"// db.opt is there",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"path",
".",
"Join",
"(",
"p",
",",
"\"",
"\"",
")",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"// Look for at least one database file",
"fis",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"_",
",",
"fi",
":=",
"range",
"fis",
"{",
"if",
"strings",
".",
"HasSuffix",
"(",
"fi",
".",
"Name",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"// the MyRocks engine stores data in RocksDB .sst files",
"// https://github.com/facebook/rocksdb/wiki/Rocksdb-BlockBasedTable-Format",
"if",
"strings",
".",
"HasSuffix",
"(",
"fi",
".",
"Name",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"// .frm files were removed in MySQL 8, so we need to check for two other file types",
"// https://dev.mysql.com/doc/refman/8.0/en/data-dictionary-file-removal.html",
"if",
"strings",
".",
"HasSuffix",
"(",
"fi",
".",
"Name",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"// https://dev.mysql.com/doc/refman/8.0/en/serialized-dictionary-information.html",
"if",
"strings",
".",
"HasSuffix",
"(",
"fi",
".",
"Name",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // isDbDir returns true if the given directory contains a DB | [
"isDbDir",
"returns",
"true",
"if",
"the",
"given",
"directory",
"contains",
"a",
"DB"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/builtinbackupengine.go#L128-L162 |
157,971 | vitessio/vitess | go/vt/mysqlctl/builtinbackupengine.go | backupFiles | func (be *BuiltinBackupEngine) backupFiles(ctx context.Context, cnf *Mycnf, mysqld MysqlDaemon, logger logutil.Logger, bh backupstorage.BackupHandle, replicationPosition mysql.Position, backupConcurrency int, hookExtraEnv map[string]string) (err error) {
// Get the files to backup.
fes, err := findFilesToBackup(cnf)
if err != nil {
return vterrors.Wrap(err, "can't find files to backup")
}
logger.Infof("found %v files to backup", len(fes))
// Backup with the provided concurrency.
sema := sync2.NewSemaphore(backupConcurrency, 0)
rec := concurrency.AllErrorRecorder{}
wg := sync.WaitGroup{}
for i := range fes {
wg.Add(1)
go func(i int) {
defer wg.Done()
// Wait until we are ready to go, skip if we already
// encountered an error.
sema.Acquire()
defer sema.Release()
if rec.HasErrors() {
return
}
// Backup the individual file.
name := fmt.Sprintf("%v", i)
rec.RecordError(be.backupFile(ctx, cnf, mysqld, logger, bh, &fes[i], name, hookExtraEnv))
}(i)
}
wg.Wait()
if rec.HasErrors() {
return rec.Error()
}
// open the MANIFEST
wc, err := bh.AddFile(ctx, backupManifest, 0)
if err != nil {
return vterrors.Wrapf(err, "cannot add %v to backup", backupManifest)
}
defer func() {
if closeErr := wc.Close(); err == nil {
err = closeErr
}
}()
// JSON-encode and write the MANIFEST
bm := &builtinBackupManifest{
FileEntries: fes,
Position: replicationPosition,
TransformHook: *backupStorageHook,
SkipCompress: !*backupStorageCompress,
}
data, err := json.MarshalIndent(bm, "", " ")
if err != nil {
return vterrors.Wrapf(err, "cannot JSON encode %v", backupManifest)
}
if _, err := wc.Write([]byte(data)); err != nil {
return vterrors.Wrapf(err, "cannot write %v", backupManifest)
}
return nil
} | go | func (be *BuiltinBackupEngine) backupFiles(ctx context.Context, cnf *Mycnf, mysqld MysqlDaemon, logger logutil.Logger, bh backupstorage.BackupHandle, replicationPosition mysql.Position, backupConcurrency int, hookExtraEnv map[string]string) (err error) {
// Get the files to backup.
fes, err := findFilesToBackup(cnf)
if err != nil {
return vterrors.Wrap(err, "can't find files to backup")
}
logger.Infof("found %v files to backup", len(fes))
// Backup with the provided concurrency.
sema := sync2.NewSemaphore(backupConcurrency, 0)
rec := concurrency.AllErrorRecorder{}
wg := sync.WaitGroup{}
for i := range fes {
wg.Add(1)
go func(i int) {
defer wg.Done()
// Wait until we are ready to go, skip if we already
// encountered an error.
sema.Acquire()
defer sema.Release()
if rec.HasErrors() {
return
}
// Backup the individual file.
name := fmt.Sprintf("%v", i)
rec.RecordError(be.backupFile(ctx, cnf, mysqld, logger, bh, &fes[i], name, hookExtraEnv))
}(i)
}
wg.Wait()
if rec.HasErrors() {
return rec.Error()
}
// open the MANIFEST
wc, err := bh.AddFile(ctx, backupManifest, 0)
if err != nil {
return vterrors.Wrapf(err, "cannot add %v to backup", backupManifest)
}
defer func() {
if closeErr := wc.Close(); err == nil {
err = closeErr
}
}()
// JSON-encode and write the MANIFEST
bm := &builtinBackupManifest{
FileEntries: fes,
Position: replicationPosition,
TransformHook: *backupStorageHook,
SkipCompress: !*backupStorageCompress,
}
data, err := json.MarshalIndent(bm, "", " ")
if err != nil {
return vterrors.Wrapf(err, "cannot JSON encode %v", backupManifest)
}
if _, err := wc.Write([]byte(data)); err != nil {
return vterrors.Wrapf(err, "cannot write %v", backupManifest)
}
return nil
} | [
"func",
"(",
"be",
"*",
"BuiltinBackupEngine",
")",
"backupFiles",
"(",
"ctx",
"context",
".",
"Context",
",",
"cnf",
"*",
"Mycnf",
",",
"mysqld",
"MysqlDaemon",
",",
"logger",
"logutil",
".",
"Logger",
",",
"bh",
"backupstorage",
".",
"BackupHandle",
",",
"replicationPosition",
"mysql",
".",
"Position",
",",
"backupConcurrency",
"int",
",",
"hookExtraEnv",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"err",
"error",
")",
"{",
"// Get the files to backup.",
"fes",
",",
"err",
":=",
"findFilesToBackup",
"(",
"cnf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"vterrors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"len",
"(",
"fes",
")",
")",
"\n\n",
"// Backup with the provided concurrency.",
"sema",
":=",
"sync2",
".",
"NewSemaphore",
"(",
"backupConcurrency",
",",
"0",
")",
"\n",
"rec",
":=",
"concurrency",
".",
"AllErrorRecorder",
"{",
"}",
"\n",
"wg",
":=",
"sync",
".",
"WaitGroup",
"{",
"}",
"\n",
"for",
"i",
":=",
"range",
"fes",
"{",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
"i",
"int",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n\n",
"// Wait until we are ready to go, skip if we already",
"// encountered an error.",
"sema",
".",
"Acquire",
"(",
")",
"\n",
"defer",
"sema",
".",
"Release",
"(",
")",
"\n",
"if",
"rec",
".",
"HasErrors",
"(",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"// Backup the individual file.",
"name",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
")",
"\n",
"rec",
".",
"RecordError",
"(",
"be",
".",
"backupFile",
"(",
"ctx",
",",
"cnf",
",",
"mysqld",
",",
"logger",
",",
"bh",
",",
"&",
"fes",
"[",
"i",
"]",
",",
"name",
",",
"hookExtraEnv",
")",
")",
"\n",
"}",
"(",
"i",
")",
"\n",
"}",
"\n\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"if",
"rec",
".",
"HasErrors",
"(",
")",
"{",
"return",
"rec",
".",
"Error",
"(",
")",
"\n",
"}",
"\n\n",
"// open the MANIFEST",
"wc",
",",
"err",
":=",
"bh",
".",
"AddFile",
"(",
"ctx",
",",
"backupManifest",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"vterrors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"backupManifest",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"closeErr",
":=",
"wc",
".",
"Close",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"err",
"=",
"closeErr",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"// JSON-encode and write the MANIFEST",
"bm",
":=",
"&",
"builtinBackupManifest",
"{",
"FileEntries",
":",
"fes",
",",
"Position",
":",
"replicationPosition",
",",
"TransformHook",
":",
"*",
"backupStorageHook",
",",
"SkipCompress",
":",
"!",
"*",
"backupStorageCompress",
",",
"}",
"\n",
"data",
",",
"err",
":=",
"json",
".",
"MarshalIndent",
"(",
"bm",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"vterrors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"backupManifest",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"wc",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"data",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"vterrors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"backupManifest",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // backupFiles finds the list of files to backup, and creates the backup. | [
"backupFiles",
"finds",
"the",
"list",
"of",
"files",
"to",
"backup",
"and",
"creates",
"the",
"backup",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/builtinbackupengine.go#L343-L406 |
157,972 | vitessio/vitess | go/vt/mysqlctl/builtinbackupengine.go | ExecuteRestore | func (be *BuiltinBackupEngine) ExecuteRestore(
ctx context.Context,
cnf *Mycnf,
mysqld MysqlDaemon,
logger logutil.Logger,
dir string,
bhs []backupstorage.BackupHandle,
restoreConcurrency int,
hookExtraEnv map[string]string) (mysql.Position, error) {
var bh backupstorage.BackupHandle
var bm builtinBackupManifest
var toRestore int
for toRestore = len(bhs) - 1; toRestore >= 0; toRestore-- {
bh = bhs[toRestore]
rc, err := bh.ReadFile(ctx, backupManifest)
if err != nil {
log.Warningf("Possibly incomplete backup %v in directory %v on BackupStorage: can't read MANIFEST: %v)", bh.Name(), dir, err)
continue
}
err = json.NewDecoder(rc).Decode(&bm)
rc.Close()
if err != nil {
log.Warningf("Possibly incomplete backup %v in directory %v on BackupStorage (cannot JSON decode MANIFEST: %v)", bh.Name(), dir, err)
continue
}
logger.Infof("Restore: found backup %v %v to restore with %v files", bh.Directory(), bh.Name(), len(bm.FileEntries))
break
}
if toRestore < 0 {
// There is at least one attempted backup, but none could be read.
// This implies there is data we ought to have, so it's not safe to start
// up empty.
return mysql.Position{}, errors.New("backup(s) found but none could be read, unsafe to start up empty, restart to retry restore")
}
// Starting from here we won't be able to recover if we get stopped by a cancelled
// context. Thus we use the background context to get through to the finish.
logger.Infof("Restore: shutdown mysqld")
err := mysqld.Shutdown(context.Background(), cnf, true)
if err != nil {
return mysql.Position{}, err
}
logger.Infof("Restore: deleting existing files")
if err := removeExistingFiles(cnf); err != nil {
return mysql.Position{}, err
}
logger.Infof("Restore: reinit config file")
err = mysqld.ReinitConfig(context.Background(), cnf)
if err != nil {
return mysql.Position{}, err
}
logger.Infof("Restore: copying all files")
if err := be.restoreFiles(context.Background(), cnf, bh, bm.FileEntries, bm.TransformHook, !bm.SkipCompress, restoreConcurrency, hookExtraEnv); err != nil {
return mysql.Position{}, err
}
return bm.Position, nil
} | go | func (be *BuiltinBackupEngine) ExecuteRestore(
ctx context.Context,
cnf *Mycnf,
mysqld MysqlDaemon,
logger logutil.Logger,
dir string,
bhs []backupstorage.BackupHandle,
restoreConcurrency int,
hookExtraEnv map[string]string) (mysql.Position, error) {
var bh backupstorage.BackupHandle
var bm builtinBackupManifest
var toRestore int
for toRestore = len(bhs) - 1; toRestore >= 0; toRestore-- {
bh = bhs[toRestore]
rc, err := bh.ReadFile(ctx, backupManifest)
if err != nil {
log.Warningf("Possibly incomplete backup %v in directory %v on BackupStorage: can't read MANIFEST: %v)", bh.Name(), dir, err)
continue
}
err = json.NewDecoder(rc).Decode(&bm)
rc.Close()
if err != nil {
log.Warningf("Possibly incomplete backup %v in directory %v on BackupStorage (cannot JSON decode MANIFEST: %v)", bh.Name(), dir, err)
continue
}
logger.Infof("Restore: found backup %v %v to restore with %v files", bh.Directory(), bh.Name(), len(bm.FileEntries))
break
}
if toRestore < 0 {
// There is at least one attempted backup, but none could be read.
// This implies there is data we ought to have, so it's not safe to start
// up empty.
return mysql.Position{}, errors.New("backup(s) found but none could be read, unsafe to start up empty, restart to retry restore")
}
// Starting from here we won't be able to recover if we get stopped by a cancelled
// context. Thus we use the background context to get through to the finish.
logger.Infof("Restore: shutdown mysqld")
err := mysqld.Shutdown(context.Background(), cnf, true)
if err != nil {
return mysql.Position{}, err
}
logger.Infof("Restore: deleting existing files")
if err := removeExistingFiles(cnf); err != nil {
return mysql.Position{}, err
}
logger.Infof("Restore: reinit config file")
err = mysqld.ReinitConfig(context.Background(), cnf)
if err != nil {
return mysql.Position{}, err
}
logger.Infof("Restore: copying all files")
if err := be.restoreFiles(context.Background(), cnf, bh, bm.FileEntries, bm.TransformHook, !bm.SkipCompress, restoreConcurrency, hookExtraEnv); err != nil {
return mysql.Position{}, err
}
return bm.Position, nil
} | [
"func",
"(",
"be",
"*",
"BuiltinBackupEngine",
")",
"ExecuteRestore",
"(",
"ctx",
"context",
".",
"Context",
",",
"cnf",
"*",
"Mycnf",
",",
"mysqld",
"MysqlDaemon",
",",
"logger",
"logutil",
".",
"Logger",
",",
"dir",
"string",
",",
"bhs",
"[",
"]",
"backupstorage",
".",
"BackupHandle",
",",
"restoreConcurrency",
"int",
",",
"hookExtraEnv",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"mysql",
".",
"Position",
",",
"error",
")",
"{",
"var",
"bh",
"backupstorage",
".",
"BackupHandle",
"\n",
"var",
"bm",
"builtinBackupManifest",
"\n",
"var",
"toRestore",
"int",
"\n\n",
"for",
"toRestore",
"=",
"len",
"(",
"bhs",
")",
"-",
"1",
";",
"toRestore",
">=",
"0",
";",
"toRestore",
"--",
"{",
"bh",
"=",
"bhs",
"[",
"toRestore",
"]",
"\n",
"rc",
",",
"err",
":=",
"bh",
".",
"ReadFile",
"(",
"ctx",
",",
"backupManifest",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"bh",
".",
"Name",
"(",
")",
",",
"dir",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"err",
"=",
"json",
".",
"NewDecoder",
"(",
"rc",
")",
".",
"Decode",
"(",
"&",
"bm",
")",
"\n",
"rc",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"bh",
".",
"Name",
"(",
")",
",",
"dir",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"bh",
".",
"Directory",
"(",
")",
",",
"bh",
".",
"Name",
"(",
")",
",",
"len",
"(",
"bm",
".",
"FileEntries",
")",
")",
"\n",
"break",
"\n",
"}",
"\n",
"if",
"toRestore",
"<",
"0",
"{",
"// There is at least one attempted backup, but none could be read.",
"// This implies there is data we ought to have, so it's not safe to start",
"// up empty.",
"return",
"mysql",
".",
"Position",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Starting from here we won't be able to recover if we get stopped by a cancelled",
"// context. Thus we use the background context to get through to the finish.",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"err",
":=",
"mysqld",
".",
"Shutdown",
"(",
"context",
".",
"Background",
"(",
")",
",",
"cnf",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"mysql",
".",
"Position",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
":=",
"removeExistingFiles",
"(",
"cnf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"mysql",
".",
"Position",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"err",
"=",
"mysqld",
".",
"ReinitConfig",
"(",
"context",
".",
"Background",
"(",
")",
",",
"cnf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"mysql",
".",
"Position",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
":=",
"be",
".",
"restoreFiles",
"(",
"context",
".",
"Background",
"(",
")",
",",
"cnf",
",",
"bh",
",",
"bm",
".",
"FileEntries",
",",
"bm",
".",
"TransformHook",
",",
"!",
"bm",
".",
"SkipCompress",
",",
"restoreConcurrency",
",",
"hookExtraEnv",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"mysql",
".",
"Position",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"bm",
".",
"Position",
",",
"nil",
"\n",
"}"
] | // ExecuteRestore restores from a backup. If the restore is successful
// we return the position from which replication should start
// otherwise an error is returned | [
"ExecuteRestore",
"restores",
"from",
"a",
"backup",
".",
"If",
"the",
"restore",
"is",
"successful",
"we",
"return",
"the",
"position",
"from",
"which",
"replication",
"should",
"start",
"otherwise",
"an",
"error",
"is",
"returned"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/builtinbackupengine.go#L510-L575 |
157,973 | vitessio/vitess | go/vt/mysqlctl/builtinbackupengine.go | restoreFiles | func (be *BuiltinBackupEngine) restoreFiles(ctx context.Context, cnf *Mycnf, bh backupstorage.BackupHandle, fes []FileEntry, transformHook string, compress bool, restoreConcurrency int, hookExtraEnv map[string]string) error {
sema := sync2.NewSemaphore(restoreConcurrency, 0)
rec := concurrency.AllErrorRecorder{}
wg := sync.WaitGroup{}
for i := range fes {
wg.Add(1)
go func(i int) {
defer wg.Done()
// Wait until we are ready to go, skip if we already
// encountered an error.
sema.Acquire()
defer sema.Release()
if rec.HasErrors() {
return
}
// And restore the file.
name := fmt.Sprintf("%v", i)
rec.RecordError(be.restoreFile(ctx, cnf, bh, &fes[i], transformHook, compress, name, hookExtraEnv))
}(i)
}
wg.Wait()
return rec.Error()
} | go | func (be *BuiltinBackupEngine) restoreFiles(ctx context.Context, cnf *Mycnf, bh backupstorage.BackupHandle, fes []FileEntry, transformHook string, compress bool, restoreConcurrency int, hookExtraEnv map[string]string) error {
sema := sync2.NewSemaphore(restoreConcurrency, 0)
rec := concurrency.AllErrorRecorder{}
wg := sync.WaitGroup{}
for i := range fes {
wg.Add(1)
go func(i int) {
defer wg.Done()
// Wait until we are ready to go, skip if we already
// encountered an error.
sema.Acquire()
defer sema.Release()
if rec.HasErrors() {
return
}
// And restore the file.
name := fmt.Sprintf("%v", i)
rec.RecordError(be.restoreFile(ctx, cnf, bh, &fes[i], transformHook, compress, name, hookExtraEnv))
}(i)
}
wg.Wait()
return rec.Error()
} | [
"func",
"(",
"be",
"*",
"BuiltinBackupEngine",
")",
"restoreFiles",
"(",
"ctx",
"context",
".",
"Context",
",",
"cnf",
"*",
"Mycnf",
",",
"bh",
"backupstorage",
".",
"BackupHandle",
",",
"fes",
"[",
"]",
"FileEntry",
",",
"transformHook",
"string",
",",
"compress",
"bool",
",",
"restoreConcurrency",
"int",
",",
"hookExtraEnv",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"sema",
":=",
"sync2",
".",
"NewSemaphore",
"(",
"restoreConcurrency",
",",
"0",
")",
"\n",
"rec",
":=",
"concurrency",
".",
"AllErrorRecorder",
"{",
"}",
"\n",
"wg",
":=",
"sync",
".",
"WaitGroup",
"{",
"}",
"\n",
"for",
"i",
":=",
"range",
"fes",
"{",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
"i",
"int",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n\n",
"// Wait until we are ready to go, skip if we already",
"// encountered an error.",
"sema",
".",
"Acquire",
"(",
")",
"\n",
"defer",
"sema",
".",
"Release",
"(",
")",
"\n",
"if",
"rec",
".",
"HasErrors",
"(",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"// And restore the file.",
"name",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
")",
"\n",
"rec",
".",
"RecordError",
"(",
"be",
".",
"restoreFile",
"(",
"ctx",
",",
"cnf",
",",
"bh",
",",
"&",
"fes",
"[",
"i",
"]",
",",
"transformHook",
",",
"compress",
",",
"name",
",",
"hookExtraEnv",
")",
")",
"\n",
"}",
"(",
"i",
")",
"\n",
"}",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"return",
"rec",
".",
"Error",
"(",
")",
"\n",
"}"
] | // restoreFiles will copy all the files from the BackupStorage to the
// right place. | [
"restoreFiles",
"will",
"copy",
"all",
"the",
"files",
"from",
"the",
"BackupStorage",
"to",
"the",
"right",
"place",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/builtinbackupengine.go#L579-L603 |
157,974 | vitessio/vitess | go/vt/worker/grpcvtworkerserver/server.go | ExecuteVtworkerCommand | func (s *VtworkerServer) ExecuteVtworkerCommand(args *vtworkerdatapb.ExecuteVtworkerCommandRequest, stream vtworkerservicepb.Vtworker_ExecuteVtworkerCommandServer) (err error) {
// Please note that this panic handler catches only panics occuring in the code below.
// The actual execution of the vtworker command takes place in a new go routine
// (started in Instance.setAndStartWorker()) which has its own panic handler.
defer servenv.HandlePanic("vtworker", &err)
// Stream everything back what the Wrangler is logging.
// We may execute this in parallel (inside multiple go routines),
// but the stream.Send() method is not thread safe in gRPC.
// So use a mutex to protect it.
mu := sync.Mutex{}
logstream := logutil.NewCallbackLogger(func(e *logutilpb.Event) {
mu.Lock()
stream.Send(&vtworkerdatapb.ExecuteVtworkerCommandResponse{
Event: e,
})
mu.Unlock()
})
// Let the Wrangler also log everything to the console (and thereby
// effectively to a logfile) to make sure that any information or errors
// is preserved in the logs in case the RPC or vtworker crashes.
logger := logutil.NewTeeLogger(logstream, logutil.NewConsoleLogger())
wr := s.wi.CreateWrangler(logger)
// Run the command as long as the RPC Context is valid.
worker, done, err := s.wi.RunCommand(stream.Context(), args.Args, wr, false /*runFromCli*/)
if err == nil && worker != nil && done != nil {
err = s.wi.WaitForCommand(worker, done)
}
return vterrors.ToGRPC(err)
} | go | func (s *VtworkerServer) ExecuteVtworkerCommand(args *vtworkerdatapb.ExecuteVtworkerCommandRequest, stream vtworkerservicepb.Vtworker_ExecuteVtworkerCommandServer) (err error) {
// Please note that this panic handler catches only panics occuring in the code below.
// The actual execution of the vtworker command takes place in a new go routine
// (started in Instance.setAndStartWorker()) which has its own panic handler.
defer servenv.HandlePanic("vtworker", &err)
// Stream everything back what the Wrangler is logging.
// We may execute this in parallel (inside multiple go routines),
// but the stream.Send() method is not thread safe in gRPC.
// So use a mutex to protect it.
mu := sync.Mutex{}
logstream := logutil.NewCallbackLogger(func(e *logutilpb.Event) {
mu.Lock()
stream.Send(&vtworkerdatapb.ExecuteVtworkerCommandResponse{
Event: e,
})
mu.Unlock()
})
// Let the Wrangler also log everything to the console (and thereby
// effectively to a logfile) to make sure that any information or errors
// is preserved in the logs in case the RPC or vtworker crashes.
logger := logutil.NewTeeLogger(logstream, logutil.NewConsoleLogger())
wr := s.wi.CreateWrangler(logger)
// Run the command as long as the RPC Context is valid.
worker, done, err := s.wi.RunCommand(stream.Context(), args.Args, wr, false /*runFromCli*/)
if err == nil && worker != nil && done != nil {
err = s.wi.WaitForCommand(worker, done)
}
return vterrors.ToGRPC(err)
} | [
"func",
"(",
"s",
"*",
"VtworkerServer",
")",
"ExecuteVtworkerCommand",
"(",
"args",
"*",
"vtworkerdatapb",
".",
"ExecuteVtworkerCommandRequest",
",",
"stream",
"vtworkerservicepb",
".",
"Vtworker_ExecuteVtworkerCommandServer",
")",
"(",
"err",
"error",
")",
"{",
"// Please note that this panic handler catches only panics occuring in the code below.",
"// The actual execution of the vtworker command takes place in a new go routine",
"// (started in Instance.setAndStartWorker()) which has its own panic handler.",
"defer",
"servenv",
".",
"HandlePanic",
"(",
"\"",
"\"",
",",
"&",
"err",
")",
"\n\n",
"// Stream everything back what the Wrangler is logging.",
"// We may execute this in parallel (inside multiple go routines),",
"// but the stream.Send() method is not thread safe in gRPC.",
"// So use a mutex to protect it.",
"mu",
":=",
"sync",
".",
"Mutex",
"{",
"}",
"\n",
"logstream",
":=",
"logutil",
".",
"NewCallbackLogger",
"(",
"func",
"(",
"e",
"*",
"logutilpb",
".",
"Event",
")",
"{",
"mu",
".",
"Lock",
"(",
")",
"\n",
"stream",
".",
"Send",
"(",
"&",
"vtworkerdatapb",
".",
"ExecuteVtworkerCommandResponse",
"{",
"Event",
":",
"e",
",",
"}",
")",
"\n",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}",
")",
"\n",
"// Let the Wrangler also log everything to the console (and thereby",
"// effectively to a logfile) to make sure that any information or errors",
"// is preserved in the logs in case the RPC or vtworker crashes.",
"logger",
":=",
"logutil",
".",
"NewTeeLogger",
"(",
"logstream",
",",
"logutil",
".",
"NewConsoleLogger",
"(",
")",
")",
"\n\n",
"wr",
":=",
"s",
".",
"wi",
".",
"CreateWrangler",
"(",
"logger",
")",
"\n\n",
"// Run the command as long as the RPC Context is valid.",
"worker",
",",
"done",
",",
"err",
":=",
"s",
".",
"wi",
".",
"RunCommand",
"(",
"stream",
".",
"Context",
"(",
")",
",",
"args",
".",
"Args",
",",
"wr",
",",
"false",
"/*runFromCli*/",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"worker",
"!=",
"nil",
"&&",
"done",
"!=",
"nil",
"{",
"err",
"=",
"s",
".",
"wi",
".",
"WaitForCommand",
"(",
"worker",
",",
"done",
")",
"\n",
"}",
"\n\n",
"return",
"vterrors",
".",
"ToGRPC",
"(",
"err",
")",
"\n",
"}"
] | // ExecuteVtworkerCommand is part of the vtworkerdatapb.VtworkerServer interface | [
"ExecuteVtworkerCommand",
"is",
"part",
"of",
"the",
"vtworkerdatapb",
".",
"VtworkerServer",
"interface"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/worker/grpcvtworkerserver/server.go#L49-L81 |
157,975 | vitessio/vitess | go/vt/worker/grpcvtworkerserver/server.go | StartServer | func StartServer(s *grpc.Server, wi *worker.Instance) {
vtworkerservicepb.RegisterVtworkerServer(s, NewVtworkerServer(wi))
} | go | func StartServer(s *grpc.Server, wi *worker.Instance) {
vtworkerservicepb.RegisterVtworkerServer(s, NewVtworkerServer(wi))
} | [
"func",
"StartServer",
"(",
"s",
"*",
"grpc",
".",
"Server",
",",
"wi",
"*",
"worker",
".",
"Instance",
")",
"{",
"vtworkerservicepb",
".",
"RegisterVtworkerServer",
"(",
"s",
",",
"NewVtworkerServer",
"(",
"wi",
")",
")",
"\n",
"}"
] | // StartServer registers the VtworkerServer for RPCs | [
"StartServer",
"registers",
"the",
"VtworkerServer",
"for",
"RPCs"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/worker/grpcvtworkerserver/server.go#L84-L86 |
157,976 | vitessio/vitess | go/vt/sqlparser/token.go | NewStringTokenizer | func NewStringTokenizer(sql string) *Tokenizer {
buf := []byte(sql)
return &Tokenizer{
buf: buf,
bufSize: len(buf),
}
} | go | func NewStringTokenizer(sql string) *Tokenizer {
buf := []byte(sql)
return &Tokenizer{
buf: buf,
bufSize: len(buf),
}
} | [
"func",
"NewStringTokenizer",
"(",
"sql",
"string",
")",
"*",
"Tokenizer",
"{",
"buf",
":=",
"[",
"]",
"byte",
"(",
"sql",
")",
"\n",
"return",
"&",
"Tokenizer",
"{",
"buf",
":",
"buf",
",",
"bufSize",
":",
"len",
"(",
"buf",
")",
",",
"}",
"\n",
"}"
] | // NewStringTokenizer creates a new Tokenizer for the
// sql string. | [
"NewStringTokenizer",
"creates",
"a",
"new",
"Tokenizer",
"for",
"the",
"sql",
"string",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/token.go#L59-L65 |
157,977 | vitessio/vitess | go/vt/sqlparser/token.go | NewTokenizer | func NewTokenizer(r io.Reader) *Tokenizer {
return &Tokenizer{
InStream: r,
buf: make([]byte, defaultBufSize),
}
} | go | func NewTokenizer(r io.Reader) *Tokenizer {
return &Tokenizer{
InStream: r,
buf: make([]byte, defaultBufSize),
}
} | [
"func",
"NewTokenizer",
"(",
"r",
"io",
".",
"Reader",
")",
"*",
"Tokenizer",
"{",
"return",
"&",
"Tokenizer",
"{",
"InStream",
":",
"r",
",",
"buf",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"defaultBufSize",
")",
",",
"}",
"\n",
"}"
] | // NewTokenizer creates a new Tokenizer reading a sql
// string from the io.Reader. | [
"NewTokenizer",
"creates",
"a",
"new",
"Tokenizer",
"reading",
"a",
"sql",
"string",
"from",
"the",
"io",
".",
"Reader",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/token.go#L69-L74 |
157,978 | vitessio/vitess | go/vt/sqlparser/token.go | KeywordString | func KeywordString(id int) string {
str, ok := keywordStrings[id]
if !ok {
return ""
}
return str
} | go | func KeywordString(id int) string {
str, ok := keywordStrings[id]
if !ok {
return ""
}
return str
} | [
"func",
"KeywordString",
"(",
"id",
"int",
")",
"string",
"{",
"str",
",",
"ok",
":=",
"keywordStrings",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"str",
"\n",
"}"
] | // KeywordString returns the string corresponding to the given keyword | [
"KeywordString",
"returns",
"the",
"string",
"corresponding",
"to",
"the",
"given",
"keyword"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/token.go#L425-L431 |
157,979 | vitessio/vitess | go/vt/sqlparser/token.go | Lex | func (tkn *Tokenizer) Lex(lval *yySymType) int {
if tkn.SkipToEnd {
return tkn.skipStatement()
}
typ, val := tkn.Scan()
for typ == COMMENT {
if tkn.AllowComments {
break
}
typ, val = tkn.Scan()
}
if typ == 0 || typ == ';' || typ == LEX_ERROR {
// If encounter end of statement or invalid token,
// we should not accept partially parsed DDLs. They
// should instead result in parser errors. See the
// Parse function to see how this is handled.
tkn.partialDDL = nil
}
lval.bytes = val
tkn.lastToken = val
return typ
} | go | func (tkn *Tokenizer) Lex(lval *yySymType) int {
if tkn.SkipToEnd {
return tkn.skipStatement()
}
typ, val := tkn.Scan()
for typ == COMMENT {
if tkn.AllowComments {
break
}
typ, val = tkn.Scan()
}
if typ == 0 || typ == ';' || typ == LEX_ERROR {
// If encounter end of statement or invalid token,
// we should not accept partially parsed DDLs. They
// should instead result in parser errors. See the
// Parse function to see how this is handled.
tkn.partialDDL = nil
}
lval.bytes = val
tkn.lastToken = val
return typ
} | [
"func",
"(",
"tkn",
"*",
"Tokenizer",
")",
"Lex",
"(",
"lval",
"*",
"yySymType",
")",
"int",
"{",
"if",
"tkn",
".",
"SkipToEnd",
"{",
"return",
"tkn",
".",
"skipStatement",
"(",
")",
"\n",
"}",
"\n\n",
"typ",
",",
"val",
":=",
"tkn",
".",
"Scan",
"(",
")",
"\n",
"for",
"typ",
"==",
"COMMENT",
"{",
"if",
"tkn",
".",
"AllowComments",
"{",
"break",
"\n",
"}",
"\n",
"typ",
",",
"val",
"=",
"tkn",
".",
"Scan",
"(",
")",
"\n",
"}",
"\n",
"if",
"typ",
"==",
"0",
"||",
"typ",
"==",
"';'",
"||",
"typ",
"==",
"LEX_ERROR",
"{",
"// If encounter end of statement or invalid token,",
"// we should not accept partially parsed DDLs. They",
"// should instead result in parser errors. See the",
"// Parse function to see how this is handled.",
"tkn",
".",
"partialDDL",
"=",
"nil",
"\n",
"}",
"\n",
"lval",
".",
"bytes",
"=",
"val",
"\n",
"tkn",
".",
"lastToken",
"=",
"val",
"\n",
"return",
"typ",
"\n",
"}"
] | // Lex returns the next token form the Tokenizer.
// This function is used by go yacc. | [
"Lex",
"returns",
"the",
"next",
"token",
"form",
"the",
"Tokenizer",
".",
"This",
"function",
"is",
"used",
"by",
"go",
"yacc",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/token.go#L435-L457 |
157,980 | vitessio/vitess | go/vt/sqlparser/token.go | Error | func (tkn *Tokenizer) Error(err string) {
buf := &bytes2.Buffer{}
if tkn.lastToken != nil {
fmt.Fprintf(buf, "%s at position %v near '%s'", err, tkn.Position, tkn.lastToken)
} else {
fmt.Fprintf(buf, "%s at position %v", err, tkn.Position)
}
tkn.LastError = errors.New(buf.String())
// Try and re-sync to the next statement
tkn.skipStatement()
} | go | func (tkn *Tokenizer) Error(err string) {
buf := &bytes2.Buffer{}
if tkn.lastToken != nil {
fmt.Fprintf(buf, "%s at position %v near '%s'", err, tkn.Position, tkn.lastToken)
} else {
fmt.Fprintf(buf, "%s at position %v", err, tkn.Position)
}
tkn.LastError = errors.New(buf.String())
// Try and re-sync to the next statement
tkn.skipStatement()
} | [
"func",
"(",
"tkn",
"*",
"Tokenizer",
")",
"Error",
"(",
"err",
"string",
")",
"{",
"buf",
":=",
"&",
"bytes2",
".",
"Buffer",
"{",
"}",
"\n",
"if",
"tkn",
".",
"lastToken",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintf",
"(",
"buf",
",",
"\"",
"\"",
",",
"err",
",",
"tkn",
".",
"Position",
",",
"tkn",
".",
"lastToken",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Fprintf",
"(",
"buf",
",",
"\"",
"\"",
",",
"err",
",",
"tkn",
".",
"Position",
")",
"\n",
"}",
"\n",
"tkn",
".",
"LastError",
"=",
"errors",
".",
"New",
"(",
"buf",
".",
"String",
"(",
")",
")",
"\n\n",
"// Try and re-sync to the next statement",
"tkn",
".",
"skipStatement",
"(",
")",
"\n",
"}"
] | // Error is called by go yacc if there's a parsing error. | [
"Error",
"is",
"called",
"by",
"go",
"yacc",
"if",
"there",
"s",
"a",
"parsing",
"error",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/token.go#L460-L471 |
157,981 | vitessio/vitess | go/vt/sqlparser/token.go | skipStatement | func (tkn *Tokenizer) skipStatement() int {
tkn.SkipToEnd = false
for {
typ, _ := tkn.Scan()
if typ == 0 || typ == ';' || typ == LEX_ERROR {
return typ
}
}
} | go | func (tkn *Tokenizer) skipStatement() int {
tkn.SkipToEnd = false
for {
typ, _ := tkn.Scan()
if typ == 0 || typ == ';' || typ == LEX_ERROR {
return typ
}
}
} | [
"func",
"(",
"tkn",
"*",
"Tokenizer",
")",
"skipStatement",
"(",
")",
"int",
"{",
"tkn",
".",
"SkipToEnd",
"=",
"false",
"\n",
"for",
"{",
"typ",
",",
"_",
":=",
"tkn",
".",
"Scan",
"(",
")",
"\n",
"if",
"typ",
"==",
"0",
"||",
"typ",
"==",
"';'",
"||",
"typ",
"==",
"LEX_ERROR",
"{",
"return",
"typ",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // skipStatement scans until end of statement. | [
"skipStatement",
"scans",
"until",
"end",
"of",
"statement",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/token.go#L633-L641 |
157,982 | vitessio/vitess | go/vt/vtctl/vtctlclient/wrapper.go | RunCommandAndWait | func RunCommandAndWait(ctx context.Context, server string, args []string, recv func(*logutilpb.Event)) error {
if recv == nil {
return errors.New("no function closure for Event stream specified")
}
// create the client
client, err := New(server)
if err != nil {
return fmt.Errorf("cannot dial to server %v: %v", server, err)
}
defer client.Close()
// run the command ( get the timeout from the context )
timeout := defaultTimeout
deadline, ok := ctx.Deadline()
if ok {
timeout = time.Until(deadline)
}
stream, err := client.ExecuteVtctlCommand(ctx, args, timeout)
if err != nil {
return fmt.Errorf("cannot execute remote command: %v", err)
}
// stream the result
for {
e, err := stream.Recv()
switch err {
case nil:
recv(e)
case io.EOF:
return nil
default:
return fmt.Errorf("remote error: %v", err)
}
}
} | go | func RunCommandAndWait(ctx context.Context, server string, args []string, recv func(*logutilpb.Event)) error {
if recv == nil {
return errors.New("no function closure for Event stream specified")
}
// create the client
client, err := New(server)
if err != nil {
return fmt.Errorf("cannot dial to server %v: %v", server, err)
}
defer client.Close()
// run the command ( get the timeout from the context )
timeout := defaultTimeout
deadline, ok := ctx.Deadline()
if ok {
timeout = time.Until(deadline)
}
stream, err := client.ExecuteVtctlCommand(ctx, args, timeout)
if err != nil {
return fmt.Errorf("cannot execute remote command: %v", err)
}
// stream the result
for {
e, err := stream.Recv()
switch err {
case nil:
recv(e)
case io.EOF:
return nil
default:
return fmt.Errorf("remote error: %v", err)
}
}
} | [
"func",
"RunCommandAndWait",
"(",
"ctx",
"context",
".",
"Context",
",",
"server",
"string",
",",
"args",
"[",
"]",
"string",
",",
"recv",
"func",
"(",
"*",
"logutilpb",
".",
"Event",
")",
")",
"error",
"{",
"if",
"recv",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// create the client",
"client",
",",
"err",
":=",
"New",
"(",
"server",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"server",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"client",
".",
"Close",
"(",
")",
"\n\n",
"// run the command ( get the timeout from the context )",
"timeout",
":=",
"defaultTimeout",
"\n",
"deadline",
",",
"ok",
":=",
"ctx",
".",
"Deadline",
"(",
")",
"\n",
"if",
"ok",
"{",
"timeout",
"=",
"time",
".",
"Until",
"(",
"deadline",
")",
"\n",
"}",
"\n",
"stream",
",",
"err",
":=",
"client",
".",
"ExecuteVtctlCommand",
"(",
"ctx",
",",
"args",
",",
"timeout",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// stream the result",
"for",
"{",
"e",
",",
"err",
":=",
"stream",
".",
"Recv",
"(",
")",
"\n",
"switch",
"err",
"{",
"case",
"nil",
":",
"recv",
"(",
"e",
")",
"\n",
"case",
"io",
".",
"EOF",
":",
"return",
"nil",
"\n",
"default",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // RunCommandAndWait executes a single command on a given vtctld and blocks until the command did return or timed out.
// Output from vtctld is streamed as logutilpb.Event messages which
// have to be consumed by the caller who has to specify a "recv" function. | [
"RunCommandAndWait",
"executes",
"a",
"single",
"command",
"on",
"a",
"given",
"vtctld",
"and",
"blocks",
"until",
"the",
"command",
"did",
"return",
"or",
"timed",
"out",
".",
"Output",
"from",
"vtctld",
"is",
"streamed",
"as",
"logutilpb",
".",
"Event",
"messages",
"which",
"have",
"to",
"be",
"consumed",
"by",
"the",
"caller",
"who",
"has",
"to",
"specify",
"a",
"recv",
"function",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtctl/vtctlclient/wrapper.go#L37-L71 |
157,983 | vitessio/vitess | go/vt/wrangler/hook.go | ExecuteHook | func (wr *Wrangler) ExecuteHook(ctx context.Context, tabletAlias *topodatapb.TabletAlias, hook *hk.Hook) (hookResult *hk.HookResult, err error) {
if strings.Contains(hook.Name, "/") {
return nil, fmt.Errorf("hook name cannot have a '/' in it")
}
ti, err := wr.ts.GetTablet(ctx, tabletAlias)
if err != nil {
return nil, err
}
return wr.ExecuteTabletHook(ctx, ti.Tablet, hook)
} | go | func (wr *Wrangler) ExecuteHook(ctx context.Context, tabletAlias *topodatapb.TabletAlias, hook *hk.Hook) (hookResult *hk.HookResult, err error) {
if strings.Contains(hook.Name, "/") {
return nil, fmt.Errorf("hook name cannot have a '/' in it")
}
ti, err := wr.ts.GetTablet(ctx, tabletAlias)
if err != nil {
return nil, err
}
return wr.ExecuteTabletHook(ctx, ti.Tablet, hook)
} | [
"func",
"(",
"wr",
"*",
"Wrangler",
")",
"ExecuteHook",
"(",
"ctx",
"context",
".",
"Context",
",",
"tabletAlias",
"*",
"topodatapb",
".",
"TabletAlias",
",",
"hook",
"*",
"hk",
".",
"Hook",
")",
"(",
"hookResult",
"*",
"hk",
".",
"HookResult",
",",
"err",
"error",
")",
"{",
"if",
"strings",
".",
"Contains",
"(",
"hook",
".",
"Name",
",",
"\"",
"\"",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ti",
",",
"err",
":=",
"wr",
".",
"ts",
".",
"GetTablet",
"(",
"ctx",
",",
"tabletAlias",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"wr",
".",
"ExecuteTabletHook",
"(",
"ctx",
",",
"ti",
".",
"Tablet",
",",
"hook",
")",
"\n",
"}"
] | // ExecuteHook will run the hook on the tablet | [
"ExecuteHook",
"will",
"run",
"the",
"hook",
"on",
"the",
"tablet"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/wrangler/hook.go#L30-L39 |
157,984 | vitessio/vitess | go/vt/wrangler/hook.go | ExecuteTabletHook | func (wr *Wrangler) ExecuteTabletHook(ctx context.Context, tablet *topodatapb.Tablet, hook *hk.Hook) (hookResult *hk.HookResult, err error) {
return wr.tmc.ExecuteHook(ctx, tablet, hook)
} | go | func (wr *Wrangler) ExecuteTabletHook(ctx context.Context, tablet *topodatapb.Tablet, hook *hk.Hook) (hookResult *hk.HookResult, err error) {
return wr.tmc.ExecuteHook(ctx, tablet, hook)
} | [
"func",
"(",
"wr",
"*",
"Wrangler",
")",
"ExecuteTabletHook",
"(",
"ctx",
"context",
".",
"Context",
",",
"tablet",
"*",
"topodatapb",
".",
"Tablet",
",",
"hook",
"*",
"hk",
".",
"Hook",
")",
"(",
"hookResult",
"*",
"hk",
".",
"HookResult",
",",
"err",
"error",
")",
"{",
"return",
"wr",
".",
"tmc",
".",
"ExecuteHook",
"(",
"ctx",
",",
"tablet",
",",
"hook",
")",
"\n",
"}"
] | // ExecuteTabletHook will run the hook on the provided tablet. | [
"ExecuteTabletHook",
"will",
"run",
"the",
"hook",
"on",
"the",
"provided",
"tablet",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/wrangler/hook.go#L42-L44 |
157,985 | vitessio/vitess | go/vt/worker/panic.go | NewPanicWorker | func NewPanicWorker(wr *wrangler.Wrangler) (Worker, error) {
return &PanicWorker{
StatusWorker: NewStatusWorker(),
wr: wr,
}, nil
} | go | func NewPanicWorker(wr *wrangler.Wrangler) (Worker, error) {
return &PanicWorker{
StatusWorker: NewStatusWorker(),
wr: wr,
}, nil
} | [
"func",
"NewPanicWorker",
"(",
"wr",
"*",
"wrangler",
".",
"Wrangler",
")",
"(",
"Worker",
",",
"error",
")",
"{",
"return",
"&",
"PanicWorker",
"{",
"StatusWorker",
":",
"NewStatusWorker",
"(",
")",
",",
"wr",
":",
"wr",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewPanicWorker returns a new PanicWorker object. | [
"NewPanicWorker",
"returns",
"a",
"new",
"PanicWorker",
"object",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/worker/panic.go#L36-L41 |
157,986 | vitessio/vitess | go/sqltypes/query_response.go | QueryResponsesEqual | func QueryResponsesEqual(r1, r2 []QueryResponse) bool {
if len(r1) != len(r2) {
return false
}
for i, r := range r1 {
if !r.QueryResult.Equal(r2[i].QueryResult) {
return false
}
if !vterrors.Equals(r.QueryError, r2[i].QueryError) {
return false
}
}
return true
} | go | func QueryResponsesEqual(r1, r2 []QueryResponse) bool {
if len(r1) != len(r2) {
return false
}
for i, r := range r1 {
if !r.QueryResult.Equal(r2[i].QueryResult) {
return false
}
if !vterrors.Equals(r.QueryError, r2[i].QueryError) {
return false
}
}
return true
} | [
"func",
"QueryResponsesEqual",
"(",
"r1",
",",
"r2",
"[",
"]",
"QueryResponse",
")",
"bool",
"{",
"if",
"len",
"(",
"r1",
")",
"!=",
"len",
"(",
"r2",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"i",
",",
"r",
":=",
"range",
"r1",
"{",
"if",
"!",
"r",
".",
"QueryResult",
".",
"Equal",
"(",
"r2",
"[",
"i",
"]",
".",
"QueryResult",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"vterrors",
".",
"Equals",
"(",
"r",
".",
"QueryError",
",",
"r2",
"[",
"i",
"]",
".",
"QueryError",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // QueryResponsesEqual compares two arrays of QueryResponse.
// They contain protos, so we cannot use reflect.DeepEqual. | [
"QueryResponsesEqual",
"compares",
"two",
"arrays",
"of",
"QueryResponse",
".",
"They",
"contain",
"protos",
"so",
"we",
"cannot",
"use",
"reflect",
".",
"DeepEqual",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/sqltypes/query_response.go#L31-L44 |
157,987 | vitessio/vitess | go/vt/worker/vtworkerclient/wrapper.go | RunCommandAndWait | func RunCommandAndWait(ctx context.Context, server string, args []string, recv func(*logutilpb.Event)) error {
if recv == nil {
panic("no function closure for Event stream specified")
}
// create the client
client, err := New(server)
if err != nil {
return vterrors.Wrapf(err, "cannot dial to server %v", server)
}
defer client.Close()
// run the command
stream, err := client.ExecuteVtworkerCommand(ctx, args)
if err != nil {
return vterrors.Wrap(err, "cannot execute remote command")
}
for {
e, err := stream.Recv()
switch err {
case nil:
recv(e)
case io.EOF:
return nil
default:
return vterrors.Wrap(err, "stream error")
}
}
} | go | func RunCommandAndWait(ctx context.Context, server string, args []string, recv func(*logutilpb.Event)) error {
if recv == nil {
panic("no function closure for Event stream specified")
}
// create the client
client, err := New(server)
if err != nil {
return vterrors.Wrapf(err, "cannot dial to server %v", server)
}
defer client.Close()
// run the command
stream, err := client.ExecuteVtworkerCommand(ctx, args)
if err != nil {
return vterrors.Wrap(err, "cannot execute remote command")
}
for {
e, err := stream.Recv()
switch err {
case nil:
recv(e)
case io.EOF:
return nil
default:
return vterrors.Wrap(err, "stream error")
}
}
} | [
"func",
"RunCommandAndWait",
"(",
"ctx",
"context",
".",
"Context",
",",
"server",
"string",
",",
"args",
"[",
"]",
"string",
",",
"recv",
"func",
"(",
"*",
"logutilpb",
".",
"Event",
")",
")",
"error",
"{",
"if",
"recv",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// create the client",
"client",
",",
"err",
":=",
"New",
"(",
"server",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"vterrors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"server",
")",
"\n",
"}",
"\n",
"defer",
"client",
".",
"Close",
"(",
")",
"\n\n",
"// run the command",
"stream",
",",
"err",
":=",
"client",
".",
"ExecuteVtworkerCommand",
"(",
"ctx",
",",
"args",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"vterrors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"{",
"e",
",",
"err",
":=",
"stream",
".",
"Recv",
"(",
")",
"\n",
"switch",
"err",
"{",
"case",
"nil",
":",
"recv",
"(",
"e",
")",
"\n",
"case",
"io",
".",
"EOF",
":",
"return",
"nil",
"\n",
"default",
":",
"return",
"vterrors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // RunCommandAndWait executes a single command on a given vtworker and blocks until the command did return or timed out.
// Output from vtworker is streamed as logutil.Event messages which
// have to be consumed by the caller who has to specify a "recv" function. | [
"RunCommandAndWait",
"executes",
"a",
"single",
"command",
"on",
"a",
"given",
"vtworker",
"and",
"blocks",
"until",
"the",
"command",
"did",
"return",
"or",
"timed",
"out",
".",
"Output",
"from",
"vtworker",
"is",
"streamed",
"as",
"logutil",
".",
"Event",
"messages",
"which",
"have",
"to",
"be",
"consumed",
"by",
"the",
"caller",
"who",
"has",
"to",
"specify",
"a",
"recv",
"function",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/worker/vtworkerclient/wrapper.go#L32-L60 |
157,988 | vitessio/vitess | go/vt/vttablet/tabletconn/grpc_error.go | ErrorFromGRPC | func ErrorFromGRPC(err error) error {
// io.EOF is end of stream. Don't treat it as an error.
if err == nil || err == io.EOF {
return nil
}
code := codes.Unknown
if s, ok := status.FromError(err); ok {
code = s.Code()
}
return vterrors.Errorf(vtrpcpb.Code(code), "vttablet: %v", err)
} | go | func ErrorFromGRPC(err error) error {
// io.EOF is end of stream. Don't treat it as an error.
if err == nil || err == io.EOF {
return nil
}
code := codes.Unknown
if s, ok := status.FromError(err); ok {
code = s.Code()
}
return vterrors.Errorf(vtrpcpb.Code(code), "vttablet: %v", err)
} | [
"func",
"ErrorFromGRPC",
"(",
"err",
"error",
")",
"error",
"{",
"// io.EOF is end of stream. Don't treat it as an error.",
"if",
"err",
"==",
"nil",
"||",
"err",
"==",
"io",
".",
"EOF",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"code",
":=",
"codes",
".",
"Unknown",
"\n",
"if",
"s",
",",
"ok",
":=",
"status",
".",
"FromError",
"(",
"err",
")",
";",
"ok",
"{",
"code",
"=",
"s",
".",
"Code",
"(",
")",
"\n",
"}",
"\n",
"return",
"vterrors",
".",
"Errorf",
"(",
"vtrpcpb",
".",
"Code",
"(",
"code",
")",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}"
] | // ErrorFromGRPC converts a GRPC error to vtError for
// tabletserver calls. | [
"ErrorFromGRPC",
"converts",
"a",
"GRPC",
"error",
"to",
"vtError",
"for",
"tabletserver",
"calls",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletconn/grpc_error.go#L31-L41 |
157,989 | vitessio/vitess | go/vt/vttablet/endtoend/framework/debugvars.go | FetchJSON | func FetchJSON(urlPath string) map[string]interface{} {
out := map[string]interface{}{}
response, err := http.Get(fmt.Sprintf("%s%s", ServerAddress, urlPath))
if err != nil {
return out
}
defer response.Body.Close()
_ = json.NewDecoder(response.Body).Decode(&out)
return out
} | go | func FetchJSON(urlPath string) map[string]interface{} {
out := map[string]interface{}{}
response, err := http.Get(fmt.Sprintf("%s%s", ServerAddress, urlPath))
if err != nil {
return out
}
defer response.Body.Close()
_ = json.NewDecoder(response.Body).Decode(&out)
return out
} | [
"func",
"FetchJSON",
"(",
"urlPath",
"string",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"out",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"response",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ServerAddress",
",",
"urlPath",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"out",
"\n",
"}",
"\n",
"defer",
"response",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"_",
"=",
"json",
".",
"NewDecoder",
"(",
"response",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // FetchJSON fetches JSON content from the specified URL path and returns it
// as a map. The function returns an empty map on error. | [
"FetchJSON",
"fetches",
"JSON",
"content",
"from",
"the",
"specified",
"URL",
"path",
"and",
"returns",
"it",
"as",
"a",
"map",
".",
"The",
"function",
"returns",
"an",
"empty",
"map",
"on",
"error",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/endtoend/framework/debugvars.go#L29-L38 |
157,990 | vitessio/vitess | go/vt/vttablet/endtoend/framework/debugvars.go | FetchInt | func FetchInt(vars map[string]interface{}, tags string) int {
val, _ := FetchVal(vars, tags).(float64)
return int(val)
} | go | func FetchInt(vars map[string]interface{}, tags string) int {
val, _ := FetchVal(vars, tags).(float64)
return int(val)
} | [
"func",
"FetchInt",
"(",
"vars",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"tags",
"string",
")",
"int",
"{",
"val",
",",
"_",
":=",
"FetchVal",
"(",
"vars",
",",
"tags",
")",
".",
"(",
"float64",
")",
"\n",
"return",
"int",
"(",
"val",
")",
"\n",
"}"
] | // FetchInt fetches the specified slash-separated tag and returns the
// value as an int. It returns 0 on error, or if not found. | [
"FetchInt",
"fetches",
"the",
"specified",
"slash",
"-",
"separated",
"tag",
"and",
"returns",
"the",
"value",
"as",
"an",
"int",
".",
"It",
"returns",
"0",
"on",
"error",
"or",
"if",
"not",
"found",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/endtoend/framework/debugvars.go#L48-L51 |
157,991 | vitessio/vitess | go/vt/vttablet/endtoend/framework/debugvars.go | FetchVal | func FetchVal(vars map[string]interface{}, tags string) interface{} {
splitTags := strings.Split(tags, "/")
if len(tags) == 0 {
return nil
}
current := vars
for _, tag := range splitTags[:len(splitTags)-1] {
icur, ok := current[tag]
if !ok {
return nil
}
current, ok = icur.(map[string]interface{})
if !ok {
return nil
}
}
return current[splitTags[len(splitTags)-1]]
} | go | func FetchVal(vars map[string]interface{}, tags string) interface{} {
splitTags := strings.Split(tags, "/")
if len(tags) == 0 {
return nil
}
current := vars
for _, tag := range splitTags[:len(splitTags)-1] {
icur, ok := current[tag]
if !ok {
return nil
}
current, ok = icur.(map[string]interface{})
if !ok {
return nil
}
}
return current[splitTags[len(splitTags)-1]]
} | [
"func",
"FetchVal",
"(",
"vars",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"tags",
"string",
")",
"interface",
"{",
"}",
"{",
"splitTags",
":=",
"strings",
".",
"Split",
"(",
"tags",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"tags",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"current",
":=",
"vars",
"\n",
"for",
"_",
",",
"tag",
":=",
"range",
"splitTags",
"[",
":",
"len",
"(",
"splitTags",
")",
"-",
"1",
"]",
"{",
"icur",
",",
"ok",
":=",
"current",
"[",
"tag",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"current",
",",
"ok",
"=",
"icur",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"current",
"[",
"splitTags",
"[",
"len",
"(",
"splitTags",
")",
"-",
"1",
"]",
"]",
"\n",
"}"
] | // FetchVal fetches the specified slash-separated tag and returns the
// value as an interface. It returns nil on error, or if not found. | [
"FetchVal",
"fetches",
"the",
"specified",
"slash",
"-",
"separated",
"tag",
"and",
"returns",
"the",
"value",
"as",
"an",
"interface",
".",
"It",
"returns",
"nil",
"on",
"error",
"or",
"if",
"not",
"found",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/endtoend/framework/debugvars.go#L55-L72 |
157,992 | vitessio/vitess | go/vt/vttablet/endtoend/framework/debugvars.go | FetchURL | func FetchURL(urlPath string) string {
response, err := http.Get(fmt.Sprintf("%s%s", ServerAddress, urlPath))
if err != nil {
return ""
}
defer response.Body.Close()
b, err := ioutil.ReadAll(response.Body)
if err != nil {
return ""
}
return string(b)
} | go | func FetchURL(urlPath string) string {
response, err := http.Get(fmt.Sprintf("%s%s", ServerAddress, urlPath))
if err != nil {
return ""
}
defer response.Body.Close()
b, err := ioutil.ReadAll(response.Body)
if err != nil {
return ""
}
return string(b)
} | [
"func",
"FetchURL",
"(",
"urlPath",
"string",
")",
"string",
"{",
"response",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ServerAddress",
",",
"urlPath",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"defer",
"response",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"response",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"string",
"(",
"b",
")",
"\n",
"}"
] | // FetchURL fetches the content from the specified URL path and returns it
// as a string. The function returns an empty string on error. | [
"FetchURL",
"fetches",
"the",
"content",
"from",
"the",
"specified",
"URL",
"path",
"and",
"returns",
"it",
"as",
"a",
"string",
".",
"The",
"function",
"returns",
"an",
"empty",
"string",
"on",
"error",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/endtoend/framework/debugvars.go#L76-L87 |
157,993 | vitessio/vitess | go/vt/vttablet/tabletserver/codex.go | buildValueList | func buildValueList(table *schema.Table, pkValues []sqltypes.PlanValue, bindVars map[string]*querypb.BindVariable) ([][]sqltypes.Value, error) {
rows, err := sqltypes.ResolveRows(pkValues, bindVars)
if err != nil {
return nil, err
}
// Iterate by columns.
for j := range pkValues {
typ := table.GetPKColumn(j).Type
for i := range rows {
rows[i][j], err = sqltypes.Cast(rows[i][j], typ)
if err != nil {
return nil, err
}
}
}
return rows, nil
} | go | func buildValueList(table *schema.Table, pkValues []sqltypes.PlanValue, bindVars map[string]*querypb.BindVariable) ([][]sqltypes.Value, error) {
rows, err := sqltypes.ResolveRows(pkValues, bindVars)
if err != nil {
return nil, err
}
// Iterate by columns.
for j := range pkValues {
typ := table.GetPKColumn(j).Type
for i := range rows {
rows[i][j], err = sqltypes.Cast(rows[i][j], typ)
if err != nil {
return nil, err
}
}
}
return rows, nil
} | [
"func",
"buildValueList",
"(",
"table",
"*",
"schema",
".",
"Table",
",",
"pkValues",
"[",
"]",
"sqltypes",
".",
"PlanValue",
",",
"bindVars",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
")",
"(",
"[",
"]",
"[",
"]",
"sqltypes",
".",
"Value",
",",
"error",
")",
"{",
"rows",
",",
"err",
":=",
"sqltypes",
".",
"ResolveRows",
"(",
"pkValues",
",",
"bindVars",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// Iterate by columns.",
"for",
"j",
":=",
"range",
"pkValues",
"{",
"typ",
":=",
"table",
".",
"GetPKColumn",
"(",
"j",
")",
".",
"Type",
"\n",
"for",
"i",
":=",
"range",
"rows",
"{",
"rows",
"[",
"i",
"]",
"[",
"j",
"]",
",",
"err",
"=",
"sqltypes",
".",
"Cast",
"(",
"rows",
"[",
"i",
"]",
"[",
"j",
"]",
",",
"typ",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"rows",
",",
"nil",
"\n",
"}"
] | // buildValueList builds the set of PK reference rows used to drive the next query.
// It uses the PK values supplied in the original query and bind variables.
// The generated reference rows are validated for type match against the PK of the table. | [
"buildValueList",
"builds",
"the",
"set",
"of",
"PK",
"reference",
"rows",
"used",
"to",
"drive",
"the",
"next",
"query",
".",
"It",
"uses",
"the",
"PK",
"values",
"supplied",
"in",
"the",
"original",
"query",
"and",
"bind",
"variables",
".",
"The",
"generated",
"reference",
"rows",
"are",
"validated",
"for",
"type",
"match",
"against",
"the",
"PK",
"of",
"the",
"table",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/codex.go#L32-L48 |
157,994 | vitessio/vitess | go/vt/vttablet/tabletserver/codex.go | buildSecondaryList | func buildSecondaryList(table *schema.Table, pkList [][]sqltypes.Value, secondaryList []sqltypes.PlanValue, bindVars map[string]*querypb.BindVariable) ([][]sqltypes.Value, error) {
if secondaryList == nil {
return nil, nil
}
secondaryRows, err := sqltypes.ResolveRows(secondaryList, bindVars)
if err != nil {
return nil, err
}
rows := make([][]sqltypes.Value, len(pkList))
for i, row := range pkList {
// If secondaryRows has only one row, then that
// row should be duplicated for every row in pkList.
// Otherwise, we use the individual values.
var changedValues []sqltypes.Value
if len(secondaryRows) == 1 {
changedValues = secondaryRows[0]
} else {
changedValues = secondaryRows[i]
}
rows[i] = make([]sqltypes.Value, len(row))
for j, value := range row {
if changedValues[j].IsNull() {
rows[i][j] = value
} else {
rows[i][j] = changedValues[j]
}
}
}
return rows, nil
} | go | func buildSecondaryList(table *schema.Table, pkList [][]sqltypes.Value, secondaryList []sqltypes.PlanValue, bindVars map[string]*querypb.BindVariable) ([][]sqltypes.Value, error) {
if secondaryList == nil {
return nil, nil
}
secondaryRows, err := sqltypes.ResolveRows(secondaryList, bindVars)
if err != nil {
return nil, err
}
rows := make([][]sqltypes.Value, len(pkList))
for i, row := range pkList {
// If secondaryRows has only one row, then that
// row should be duplicated for every row in pkList.
// Otherwise, we use the individual values.
var changedValues []sqltypes.Value
if len(secondaryRows) == 1 {
changedValues = secondaryRows[0]
} else {
changedValues = secondaryRows[i]
}
rows[i] = make([]sqltypes.Value, len(row))
for j, value := range row {
if changedValues[j].IsNull() {
rows[i][j] = value
} else {
rows[i][j] = changedValues[j]
}
}
}
return rows, nil
} | [
"func",
"buildSecondaryList",
"(",
"table",
"*",
"schema",
".",
"Table",
",",
"pkList",
"[",
"]",
"[",
"]",
"sqltypes",
".",
"Value",
",",
"secondaryList",
"[",
"]",
"sqltypes",
".",
"PlanValue",
",",
"bindVars",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
")",
"(",
"[",
"]",
"[",
"]",
"sqltypes",
".",
"Value",
",",
"error",
")",
"{",
"if",
"secondaryList",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"secondaryRows",
",",
"err",
":=",
"sqltypes",
".",
"ResolveRows",
"(",
"secondaryList",
",",
"bindVars",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"rows",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"sqltypes",
".",
"Value",
",",
"len",
"(",
"pkList",
")",
")",
"\n",
"for",
"i",
",",
"row",
":=",
"range",
"pkList",
"{",
"// If secondaryRows has only one row, then that",
"// row should be duplicated for every row in pkList.",
"// Otherwise, we use the individual values.",
"var",
"changedValues",
"[",
"]",
"sqltypes",
".",
"Value",
"\n",
"if",
"len",
"(",
"secondaryRows",
")",
"==",
"1",
"{",
"changedValues",
"=",
"secondaryRows",
"[",
"0",
"]",
"\n",
"}",
"else",
"{",
"changedValues",
"=",
"secondaryRows",
"[",
"i",
"]",
"\n",
"}",
"\n",
"rows",
"[",
"i",
"]",
"=",
"make",
"(",
"[",
"]",
"sqltypes",
".",
"Value",
",",
"len",
"(",
"row",
")",
")",
"\n",
"for",
"j",
",",
"value",
":=",
"range",
"row",
"{",
"if",
"changedValues",
"[",
"j",
"]",
".",
"IsNull",
"(",
")",
"{",
"rows",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"value",
"\n",
"}",
"else",
"{",
"rows",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"changedValues",
"[",
"j",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"rows",
",",
"nil",
"\n",
"}"
] | // buildSecondaryList is used for handling ON DUPLICATE DMLs, or those that change the PK. | [
"buildSecondaryList",
"is",
"used",
"for",
"handling",
"ON",
"DUPLICATE",
"DMLs",
"or",
"those",
"that",
"change",
"the",
"PK",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/codex.go#L51-L80 |
157,995 | vitessio/vitess | go/vt/vttablet/tabletserver/codex.go | resolveNumber | func resolveNumber(pv sqltypes.PlanValue, bindVars map[string]*querypb.BindVariable) (int64, error) {
v, err := pv.ResolveValue(bindVars)
if err != nil {
return 0, err
}
ret, err := sqltypes.ToInt64(v)
if err != nil {
return 0, err
}
return ret, nil
} | go | func resolveNumber(pv sqltypes.PlanValue, bindVars map[string]*querypb.BindVariable) (int64, error) {
v, err := pv.ResolveValue(bindVars)
if err != nil {
return 0, err
}
ret, err := sqltypes.ToInt64(v)
if err != nil {
return 0, err
}
return ret, nil
} | [
"func",
"resolveNumber",
"(",
"pv",
"sqltypes",
".",
"PlanValue",
",",
"bindVars",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
")",
"(",
"int64",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"pv",
".",
"ResolveValue",
"(",
"bindVars",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"ret",
",",
"err",
":=",
"sqltypes",
".",
"ToInt64",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"ret",
",",
"nil",
"\n",
"}"
] | // resolveNumber extracts a number from a bind variable or sql value. | [
"resolveNumber",
"extracts",
"a",
"number",
"from",
"a",
"bind",
"variable",
"or",
"sql",
"value",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/codex.go#L83-L93 |
157,996 | vitessio/vitess | go/vt/vttablet/tabletserver/codex.go | unicoded | func unicoded(in string) (out string) {
for i, v := range in {
if v == 0xFFFD {
return in[:i]
}
}
return in
} | go | func unicoded(in string) (out string) {
for i, v := range in {
if v == 0xFFFD {
return in[:i]
}
}
return in
} | [
"func",
"unicoded",
"(",
"in",
"string",
")",
"(",
"out",
"string",
")",
"{",
"for",
"i",
",",
"v",
":=",
"range",
"in",
"{",
"if",
"v",
"==",
"0xFFFD",
"{",
"return",
"in",
"[",
":",
"i",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"in",
"\n",
"}"
] | // unicoded returns a valid UTF-8 string that json won't reject | [
"unicoded",
"returns",
"a",
"valid",
"UTF",
"-",
"8",
"string",
"that",
"json",
"won",
"t",
"reject"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/codex.go#L162-L169 |
157,997 | vitessio/vitess | go/vt/vtgate/planbuilder/jointab.go | newJointab | func newJointab(bindvars map[string]struct{}) *jointab {
return &jointab{
refs: make(map[*column]string),
vars: bindvars,
}
} | go | func newJointab(bindvars map[string]struct{}) *jointab {
return &jointab{
refs: make(map[*column]string),
vars: bindvars,
}
} | [
"func",
"newJointab",
"(",
"bindvars",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
")",
"*",
"jointab",
"{",
"return",
"&",
"jointab",
"{",
"refs",
":",
"make",
"(",
"map",
"[",
"*",
"column",
"]",
"string",
")",
",",
"vars",
":",
"bindvars",
",",
"}",
"\n",
"}"
] | // newJointab creates a new jointab for the current plan
// being built. It also needs the current list of bind vars
// used in the original query to make sure that the names
// it generates don't collide with those already in use. | [
"newJointab",
"creates",
"a",
"new",
"jointab",
"for",
"the",
"current",
"plan",
"being",
"built",
".",
"It",
"also",
"needs",
"the",
"current",
"list",
"of",
"bind",
"vars",
"used",
"in",
"the",
"original",
"query",
"to",
"make",
"sure",
"that",
"the",
"names",
"it",
"generates",
"don",
"t",
"collide",
"with",
"those",
"already",
"in",
"use",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/jointab.go#L37-L42 |
157,998 | vitessio/vitess | go/vt/vtgate/planbuilder/jointab.go | Procure | func (jt *jointab) Procure(bldr builder, col *sqlparser.ColName, to int) string {
from, joinVar := jt.Lookup(col)
// If joinVar is empty, generate a unique name.
if joinVar == "" {
suffix := ""
i := 0
for {
if !col.Qualifier.IsEmpty() {
joinVar = col.Qualifier.Name.CompliantName() + "_" + col.Name.CompliantName() + suffix
} else {
joinVar = col.Name.CompliantName() + suffix
}
if _, ok := jt.vars[joinVar]; !ok {
break
}
i++
suffix = strconv.Itoa(i)
}
jt.vars[joinVar] = struct{}{}
jt.refs[col.Metadata.(*column)] = joinVar
}
bldr.SupplyVar(from, to, col, joinVar)
return joinVar
} | go | func (jt *jointab) Procure(bldr builder, col *sqlparser.ColName, to int) string {
from, joinVar := jt.Lookup(col)
// If joinVar is empty, generate a unique name.
if joinVar == "" {
suffix := ""
i := 0
for {
if !col.Qualifier.IsEmpty() {
joinVar = col.Qualifier.Name.CompliantName() + "_" + col.Name.CompliantName() + suffix
} else {
joinVar = col.Name.CompliantName() + suffix
}
if _, ok := jt.vars[joinVar]; !ok {
break
}
i++
suffix = strconv.Itoa(i)
}
jt.vars[joinVar] = struct{}{}
jt.refs[col.Metadata.(*column)] = joinVar
}
bldr.SupplyVar(from, to, col, joinVar)
return joinVar
} | [
"func",
"(",
"jt",
"*",
"jointab",
")",
"Procure",
"(",
"bldr",
"builder",
",",
"col",
"*",
"sqlparser",
".",
"ColName",
",",
"to",
"int",
")",
"string",
"{",
"from",
",",
"joinVar",
":=",
"jt",
".",
"Lookup",
"(",
"col",
")",
"\n",
"// If joinVar is empty, generate a unique name.",
"if",
"joinVar",
"==",
"\"",
"\"",
"{",
"suffix",
":=",
"\"",
"\"",
"\n",
"i",
":=",
"0",
"\n",
"for",
"{",
"if",
"!",
"col",
".",
"Qualifier",
".",
"IsEmpty",
"(",
")",
"{",
"joinVar",
"=",
"col",
".",
"Qualifier",
".",
"Name",
".",
"CompliantName",
"(",
")",
"+",
"\"",
"\"",
"+",
"col",
".",
"Name",
".",
"CompliantName",
"(",
")",
"+",
"suffix",
"\n",
"}",
"else",
"{",
"joinVar",
"=",
"col",
".",
"Name",
".",
"CompliantName",
"(",
")",
"+",
"suffix",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"jt",
".",
"vars",
"[",
"joinVar",
"]",
";",
"!",
"ok",
"{",
"break",
"\n",
"}",
"\n",
"i",
"++",
"\n",
"suffix",
"=",
"strconv",
".",
"Itoa",
"(",
"i",
")",
"\n",
"}",
"\n",
"jt",
".",
"vars",
"[",
"joinVar",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"jt",
".",
"refs",
"[",
"col",
".",
"Metadata",
".",
"(",
"*",
"column",
")",
"]",
"=",
"joinVar",
"\n",
"}",
"\n",
"bldr",
".",
"SupplyVar",
"(",
"from",
",",
"to",
",",
"col",
",",
"joinVar",
")",
"\n",
"return",
"joinVar",
"\n",
"}"
] | // Procure requests for the specified column from the plan
// and returns the join var name for it. | [
"Procure",
"requests",
"for",
"the",
"specified",
"column",
"from",
"the",
"plan",
"and",
"returns",
"the",
"join",
"var",
"name",
"for",
"it",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/jointab.go#L46-L69 |
157,999 | vitessio/vitess | go/vt/vtgate/planbuilder/jointab.go | Lookup | func (jt *jointab) Lookup(col *sqlparser.ColName) (order int, joinVar string) {
c := col.Metadata.(*column)
return c.Origin().Order(), jt.refs[c]
} | go | func (jt *jointab) Lookup(col *sqlparser.ColName) (order int, joinVar string) {
c := col.Metadata.(*column)
return c.Origin().Order(), jt.refs[c]
} | [
"func",
"(",
"jt",
"*",
"jointab",
")",
"Lookup",
"(",
"col",
"*",
"sqlparser",
".",
"ColName",
")",
"(",
"order",
"int",
",",
"joinVar",
"string",
")",
"{",
"c",
":=",
"col",
".",
"Metadata",
".",
"(",
"*",
"column",
")",
"\n",
"return",
"c",
".",
"Origin",
"(",
")",
".",
"Order",
"(",
")",
",",
"jt",
".",
"refs",
"[",
"c",
"]",
"\n",
"}"
] | // Lookup returns the order of the route that supplies the column and
// the join var name if one has already been assigned for it. | [
"Lookup",
"returns",
"the",
"order",
"of",
"the",
"route",
"that",
"supplies",
"the",
"column",
"and",
"the",
"join",
"var",
"name",
"if",
"one",
"has",
"already",
"been",
"assigned",
"for",
"it",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/jointab.go#L100-L103 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.