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
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
vitessio/vitess | go/vt/key/key.go | ParseKeyRangeParts | func ParseKeyRangeParts(start, end string) (*topodatapb.KeyRange, error) {
s, err := hex.DecodeString(start)
if err != nil {
return nil, err
}
e, err := hex.DecodeString(end)
if err != nil {
return nil, err
}
return &topodatapb.KeyRange{Start: s, End: e}, nil
} | go | func ParseKeyRangeParts(start, end string) (*topodatapb.KeyRange, error) {
s, err := hex.DecodeString(start)
if err != nil {
return nil, err
}
e, err := hex.DecodeString(end)
if err != nil {
return nil, err
}
return &topodatapb.KeyRange{Start: s, End: e}, nil
} | [
"func",
"ParseKeyRangeParts",
"(",
"start",
",",
"end",
"string",
")",
"(",
"*",
"topodatapb",
".",
"KeyRange",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"hex",
".",
"DecodeString",
"(",
"start",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"e",
",",
"err",
":=",
"hex",
".",
"DecodeString",
"(",
"end",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"topodatapb",
".",
"KeyRange",
"{",
"Start",
":",
"s",
",",
"End",
":",
"e",
"}",
",",
"nil",
"\n",
"}"
] | // ParseKeyRangeParts parses a start and end hex values and build a proto KeyRange | [
"ParseKeyRangeParts",
"parses",
"a",
"start",
"and",
"end",
"hex",
"values",
"and",
"build",
"a",
"proto",
"KeyRange"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/key/key.go#L132-L142 | train |
vitessio/vitess | go/vt/key/key.go | KeyRangeString | func KeyRangeString(k *topodatapb.KeyRange) string {
if k == nil {
return "-"
}
return hex.EncodeToString(k.Start) + "-" + hex.EncodeToString(k.End)
} | go | func KeyRangeString(k *topodatapb.KeyRange) string {
if k == nil {
return "-"
}
return hex.EncodeToString(k.Start) + "-" + hex.EncodeToString(k.End)
} | [
"func",
"KeyRangeString",
"(",
"k",
"*",
"topodatapb",
".",
"KeyRange",
")",
"string",
"{",
"if",
"k",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"hex",
".",
"EncodeToString",
"(",
"k",
".",
"Start",
")",
"+",
"\"",
"\"",
"+",
"hex",
".",
"EncodeToString",
"(",
"k",
".",
"End",
")",
"\n",
"}"
] | // KeyRangeString prints a topodatapb.KeyRange | [
"KeyRangeString",
"prints",
"a",
"topodatapb",
".",
"KeyRange"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/key/key.go#L145-L150 | train |
vitessio/vitess | go/vt/key/key.go | KeyRangeIsPartial | func KeyRangeIsPartial(kr *topodatapb.KeyRange) bool {
if kr == nil {
return false
}
return !(len(kr.Start) == 0 && len(kr.End) == 0)
} | go | func KeyRangeIsPartial(kr *topodatapb.KeyRange) bool {
if kr == nil {
return false
}
return !(len(kr.Start) == 0 && len(kr.End) == 0)
} | [
"func",
"KeyRangeIsPartial",
"(",
"kr",
"*",
"topodatapb",
".",
"KeyRange",
")",
"bool",
"{",
"if",
"kr",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"!",
"(",
"len",
"(",
"kr",
".",
"Start",
")",
"==",
"0",
"&&",
"len",
"(",
"kr",
".",
"End",
")",
"==",
"0",
")",
"\n",
"}"
] | // KeyRangeIsPartial returns true if the KeyRange does not cover the entire space. | [
"KeyRangeIsPartial",
"returns",
"true",
"if",
"the",
"KeyRange",
"does",
"not",
"cover",
"the",
"entire",
"space",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/key/key.go#L153-L158 | train |
vitessio/vitess | go/vt/key/key.go | KeyRangeEqual | func KeyRangeEqual(left, right *topodatapb.KeyRange) bool {
if left == nil {
return right == nil || (len(right.Start) == 0 && len(right.End) == 0)
}
if right == nil {
return len(left.Start) == 0 && len(left.End) == 0
}
return bytes.Equal(left.Start, right.Start) &&
bytes.Equal(left.End, right.End)
} | go | func KeyRangeEqual(left, right *topodatapb.KeyRange) bool {
if left == nil {
return right == nil || (len(right.Start) == 0 && len(right.End) == 0)
}
if right == nil {
return len(left.Start) == 0 && len(left.End) == 0
}
return bytes.Equal(left.Start, right.Start) &&
bytes.Equal(left.End, right.End)
} | [
"func",
"KeyRangeEqual",
"(",
"left",
",",
"right",
"*",
"topodatapb",
".",
"KeyRange",
")",
"bool",
"{",
"if",
"left",
"==",
"nil",
"{",
"return",
"right",
"==",
"nil",
"||",
"(",
"len",
"(",
"right",
".",
"Start",
")",
"==",
"0",
"&&",
"len",
"(",
"right",
".",
"End",
")",
"==",
"0",
")",
"\n",
"}",
"\n",
"if",
"right",
"==",
"nil",
"{",
"return",
"len",
"(",
"left",
".",
"Start",
")",
"==",
"0",
"&&",
"len",
"(",
"left",
".",
"End",
")",
"==",
"0",
"\n",
"}",
"\n",
"return",
"bytes",
".",
"Equal",
"(",
"left",
".",
"Start",
",",
"right",
".",
"Start",
")",
"&&",
"bytes",
".",
"Equal",
"(",
"left",
".",
"End",
",",
"right",
".",
"End",
")",
"\n",
"}"
] | // KeyRangeEqual returns true if both key ranges cover the same area | [
"KeyRangeEqual",
"returns",
"true",
"if",
"both",
"key",
"ranges",
"cover",
"the",
"same",
"area"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/key/key.go#L161-L170 | train |
vitessio/vitess | go/vt/key/key.go | KeyRangeStartEqual | func KeyRangeStartEqual(left, right *topodatapb.KeyRange) bool {
if left == nil {
return right == nil || len(right.Start) == 0
}
if right == nil {
return len(left.Start) == 0
}
return bytes.Equal(left.Start, right.Start)
} | go | func KeyRangeStartEqual(left, right *topodatapb.KeyRange) bool {
if left == nil {
return right == nil || len(right.Start) == 0
}
if right == nil {
return len(left.Start) == 0
}
return bytes.Equal(left.Start, right.Start)
} | [
"func",
"KeyRangeStartEqual",
"(",
"left",
",",
"right",
"*",
"topodatapb",
".",
"KeyRange",
")",
"bool",
"{",
"if",
"left",
"==",
"nil",
"{",
"return",
"right",
"==",
"nil",
"||",
"len",
"(",
"right",
".",
"Start",
")",
"==",
"0",
"\n",
"}",
"\n",
"if",
"right",
"==",
"nil",
"{",
"return",
"len",
"(",
"left",
".",
"Start",
")",
"==",
"0",
"\n",
"}",
"\n",
"return",
"bytes",
".",
"Equal",
"(",
"left",
".",
"Start",
",",
"right",
".",
"Start",
")",
"\n",
"}"
] | // KeyRangeStartEqual returns true if both key ranges have the same start | [
"KeyRangeStartEqual",
"returns",
"true",
"if",
"both",
"key",
"ranges",
"have",
"the",
"same",
"start"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/key/key.go#L173-L181 | train |
vitessio/vitess | go/vt/key/key.go | KeyRangeEndEqual | func KeyRangeEndEqual(left, right *topodatapb.KeyRange) bool {
if left == nil {
return right == nil || len(right.End) == 0
}
if right == nil {
return len(left.End) == 0
}
return bytes.Equal(left.End, right.End)
} | go | func KeyRangeEndEqual(left, right *topodatapb.KeyRange) bool {
if left == nil {
return right == nil || len(right.End) == 0
}
if right == nil {
return len(left.End) == 0
}
return bytes.Equal(left.End, right.End)
} | [
"func",
"KeyRangeEndEqual",
"(",
"left",
",",
"right",
"*",
"topodatapb",
".",
"KeyRange",
")",
"bool",
"{",
"if",
"left",
"==",
"nil",
"{",
"return",
"right",
"==",
"nil",
"||",
"len",
"(",
"right",
".",
"End",
")",
"==",
"0",
"\n",
"}",
"\n",
"if",
"right",
"==",
"nil",
"{",
"return",
"len",
"(",
"left",
".",
"End",
")",
"==",
"0",
"\n",
"}",
"\n",
"return",
"bytes",
".",
"Equal",
"(",
"left",
".",
"End",
",",
"right",
".",
"End",
")",
"\n",
"}"
] | // KeyRangeEndEqual returns true if both key ranges have the same end | [
"KeyRangeEndEqual",
"returns",
"true",
"if",
"both",
"key",
"ranges",
"have",
"the",
"same",
"end"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/key/key.go#L184-L192 | train |
vitessio/vitess | go/vt/key/key.go | KeyRangesOverlap | func KeyRangesOverlap(first, second *topodatapb.KeyRange) (*topodatapb.KeyRange, error) {
if !KeyRangesIntersect(first, second) {
return nil, fmt.Errorf("KeyRanges %v and %v don't overlap", first, second)
}
if first == nil {
return second, nil
}
if second == nil {
return first, nil
}
// compute max(c,a) and min(b,d)
// start with (a,b)
result := *first
// if c > a, then use c
if bytes.Compare(second.Start, first.Start) > 0 {
result.Start = second.Start
}
// if b is maxed out, or
// (d is not maxed out and d < b)
// ^ valid test as neither b nor d are max
// then use d
if len(first.End) == 0 || (len(second.End) != 0 && bytes.Compare(second.End, first.End) < 0) {
result.End = second.End
}
return &result, nil
} | go | func KeyRangesOverlap(first, second *topodatapb.KeyRange) (*topodatapb.KeyRange, error) {
if !KeyRangesIntersect(first, second) {
return nil, fmt.Errorf("KeyRanges %v and %v don't overlap", first, second)
}
if first == nil {
return second, nil
}
if second == nil {
return first, nil
}
// compute max(c,a) and min(b,d)
// start with (a,b)
result := *first
// if c > a, then use c
if bytes.Compare(second.Start, first.Start) > 0 {
result.Start = second.Start
}
// if b is maxed out, or
// (d is not maxed out and d < b)
// ^ valid test as neither b nor d are max
// then use d
if len(first.End) == 0 || (len(second.End) != 0 && bytes.Compare(second.End, first.End) < 0) {
result.End = second.End
}
return &result, nil
} | [
"func",
"KeyRangesOverlap",
"(",
"first",
",",
"second",
"*",
"topodatapb",
".",
"KeyRange",
")",
"(",
"*",
"topodatapb",
".",
"KeyRange",
",",
"error",
")",
"{",
"if",
"!",
"KeyRangesIntersect",
"(",
"first",
",",
"second",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"first",
",",
"second",
")",
"\n",
"}",
"\n",
"if",
"first",
"==",
"nil",
"{",
"return",
"second",
",",
"nil",
"\n",
"}",
"\n",
"if",
"second",
"==",
"nil",
"{",
"return",
"first",
",",
"nil",
"\n",
"}",
"\n",
"// compute max(c,a) and min(b,d)",
"// start with (a,b)",
"result",
":=",
"*",
"first",
"\n",
"// if c > a, then use c",
"if",
"bytes",
".",
"Compare",
"(",
"second",
".",
"Start",
",",
"first",
".",
"Start",
")",
">",
"0",
"{",
"result",
".",
"Start",
"=",
"second",
".",
"Start",
"\n",
"}",
"\n",
"// if b is maxed out, or",
"// (d is not maxed out and d < b)",
"// ^ valid test as neither b nor d are max",
"// then use d",
"if",
"len",
"(",
"first",
".",
"End",
")",
"==",
"0",
"||",
"(",
"len",
"(",
"second",
".",
"End",
")",
"!=",
"0",
"&&",
"bytes",
".",
"Compare",
"(",
"second",
".",
"End",
",",
"first",
".",
"End",
")",
"<",
"0",
")",
"{",
"result",
".",
"End",
"=",
"second",
".",
"End",
"\n",
"}",
"\n",
"return",
"&",
"result",
",",
"nil",
"\n",
"}"
] | // KeyRangesOverlap returns the overlap between two KeyRanges.
// They need to overlap, otherwise an error is returned. | [
"KeyRangesOverlap",
"returns",
"the",
"overlap",
"between",
"two",
"KeyRanges",
".",
"They",
"need",
"to",
"overlap",
"otherwise",
"an",
"error",
"is",
"returned",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/key/key.go#L211-L236 | train |
vitessio/vitess | go/vt/key/key.go | KeyRangeIncludes | func KeyRangeIncludes(big, small *topodatapb.KeyRange) bool {
if big == nil {
// The outside one covers everything, we're good.
return true
}
if small == nil {
// The smaller one covers everything, better have the
// bigger one also cover everything.
return len(big.Start) == 0 && len(big.End) == 0
}
// Now we check small.Start >= big.Start, and small.End <= big.End
if len(big.Start) != 0 && bytes.Compare(small.Start, big.Start) < 0 {
return false
}
if len(big.End) != 0 && (len(small.End) == 0 || bytes.Compare(small.End, big.End) > 0) {
return false
}
return true
} | go | func KeyRangeIncludes(big, small *topodatapb.KeyRange) bool {
if big == nil {
// The outside one covers everything, we're good.
return true
}
if small == nil {
// The smaller one covers everything, better have the
// bigger one also cover everything.
return len(big.Start) == 0 && len(big.End) == 0
}
// Now we check small.Start >= big.Start, and small.End <= big.End
if len(big.Start) != 0 && bytes.Compare(small.Start, big.Start) < 0 {
return false
}
if len(big.End) != 0 && (len(small.End) == 0 || bytes.Compare(small.End, big.End) > 0) {
return false
}
return true
} | [
"func",
"KeyRangeIncludes",
"(",
"big",
",",
"small",
"*",
"topodatapb",
".",
"KeyRange",
")",
"bool",
"{",
"if",
"big",
"==",
"nil",
"{",
"// The outside one covers everything, we're good.",
"return",
"true",
"\n",
"}",
"\n",
"if",
"small",
"==",
"nil",
"{",
"// The smaller one covers everything, better have the",
"// bigger one also cover everything.",
"return",
"len",
"(",
"big",
".",
"Start",
")",
"==",
"0",
"&&",
"len",
"(",
"big",
".",
"End",
")",
"==",
"0",
"\n",
"}",
"\n",
"// Now we check small.Start >= big.Start, and small.End <= big.End",
"if",
"len",
"(",
"big",
".",
"Start",
")",
"!=",
"0",
"&&",
"bytes",
".",
"Compare",
"(",
"small",
".",
"Start",
",",
"big",
".",
"Start",
")",
"<",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"len",
"(",
"big",
".",
"End",
")",
"!=",
"0",
"&&",
"(",
"len",
"(",
"small",
".",
"End",
")",
"==",
"0",
"||",
"bytes",
".",
"Compare",
"(",
"small",
".",
"End",
",",
"big",
".",
"End",
")",
">",
"0",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // KeyRangeIncludes returns true if the first provided KeyRange, big,
// contains the second KeyRange, small. If they intersect, but small
// spills out, this returns false. | [
"KeyRangeIncludes",
"returns",
"true",
"if",
"the",
"first",
"provided",
"KeyRange",
"big",
"contains",
"the",
"second",
"KeyRange",
"small",
".",
"If",
"they",
"intersect",
"but",
"small",
"spills",
"out",
"this",
"returns",
"false",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/key/key.go#L241-L259 | train |
vitessio/vitess | go/vt/automation/task_containers.go | NewTaskContainerWithSingleTask | func NewTaskContainerWithSingleTask(taskName string, parameters map[string]string) *automationpb.TaskContainer {
return &automationpb.TaskContainer{
ParallelTasks: []*automationpb.Task{
NewTask(taskName, parameters),
},
}
} | go | func NewTaskContainerWithSingleTask(taskName string, parameters map[string]string) *automationpb.TaskContainer {
return &automationpb.TaskContainer{
ParallelTasks: []*automationpb.Task{
NewTask(taskName, parameters),
},
}
} | [
"func",
"NewTaskContainerWithSingleTask",
"(",
"taskName",
"string",
",",
"parameters",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"automationpb",
".",
"TaskContainer",
"{",
"return",
"&",
"automationpb",
".",
"TaskContainer",
"{",
"ParallelTasks",
":",
"[",
"]",
"*",
"automationpb",
".",
"Task",
"{",
"NewTask",
"(",
"taskName",
",",
"parameters",
")",
",",
"}",
",",
"}",
"\n",
"}"
] | // Helper functions for "TaskContainer" protobuf message.
// NewTaskContainerWithSingleTask creates a new task container with exactly one task. | [
"Helper",
"functions",
"for",
"TaskContainer",
"protobuf",
"message",
".",
"NewTaskContainerWithSingleTask",
"creates",
"a",
"new",
"task",
"container",
"with",
"exactly",
"one",
"task",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/automation/task_containers.go#L26-L32 | train |
vitessio/vitess | go/vt/automation/task_containers.go | AddTask | func AddTask(t *automationpb.TaskContainer, taskName string, parameters map[string]string) {
t.ParallelTasks = append(t.ParallelTasks, NewTask(taskName, parameters))
} | go | func AddTask(t *automationpb.TaskContainer, taskName string, parameters map[string]string) {
t.ParallelTasks = append(t.ParallelTasks, NewTask(taskName, parameters))
} | [
"func",
"AddTask",
"(",
"t",
"*",
"automationpb",
".",
"TaskContainer",
",",
"taskName",
"string",
",",
"parameters",
"map",
"[",
"string",
"]",
"string",
")",
"{",
"t",
".",
"ParallelTasks",
"=",
"append",
"(",
"t",
".",
"ParallelTasks",
",",
"NewTask",
"(",
"taskName",
",",
"parameters",
")",
")",
"\n",
"}"
] | // AddTask adds a new task to an existing task container. | [
"AddTask",
"adds",
"a",
"new",
"task",
"to",
"an",
"existing",
"task",
"container",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/automation/task_containers.go#L42-L44 | train |
vitessio/vitess | go/vt/automation/task_containers.go | AddMissingTaskID | func AddMissingTaskID(tc []*automationpb.TaskContainer, taskIDGenerator *IDGenerator) {
for _, taskContainer := range tc {
for _, task := range taskContainer.ParallelTasks {
if task.Id == "" {
task.Id = taskIDGenerator.GetNextID()
}
}
}
} | go | func AddMissingTaskID(tc []*automationpb.TaskContainer, taskIDGenerator *IDGenerator) {
for _, taskContainer := range tc {
for _, task := range taskContainer.ParallelTasks {
if task.Id == "" {
task.Id = taskIDGenerator.GetNextID()
}
}
}
} | [
"func",
"AddMissingTaskID",
"(",
"tc",
"[",
"]",
"*",
"automationpb",
".",
"TaskContainer",
",",
"taskIDGenerator",
"*",
"IDGenerator",
")",
"{",
"for",
"_",
",",
"taskContainer",
":=",
"range",
"tc",
"{",
"for",
"_",
",",
"task",
":=",
"range",
"taskContainer",
".",
"ParallelTasks",
"{",
"if",
"task",
".",
"Id",
"==",
"\"",
"\"",
"{",
"task",
".",
"Id",
"=",
"taskIDGenerator",
".",
"GetNextID",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // AddMissingTaskID assigns a task id to each task in "tc". | [
"AddMissingTaskID",
"assigns",
"a",
"task",
"id",
"to",
"each",
"task",
"in",
"tc",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/automation/task_containers.go#L47-L55 | train |
vitessio/vitess | go/vt/vtgate/vindexes/hash.go | NewHash | func NewHash(name string, m map[string]string) (Vindex, error) {
return &Hash{name: name}, nil
} | go | func NewHash(name string, m map[string]string) (Vindex, error) {
return &Hash{name: name}, nil
} | [
"func",
"NewHash",
"(",
"name",
"string",
",",
"m",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"Vindex",
",",
"error",
")",
"{",
"return",
"&",
"Hash",
"{",
"name",
":",
"name",
"}",
",",
"nil",
"\n",
"}"
] | // NewHash creates a new Hash. | [
"NewHash",
"creates",
"a",
"new",
"Hash",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/hash.go#L46-L48 | train |
vitessio/vitess | go/vt/worker/restartable_result_reader.go | Next | func (r *RestartableResultReader) Next() (*sqltypes.Result, error) {
result, err := r.output.Recv()
if err != nil && err != io.EOF {
// We start the retries only on the second attempt to avoid the cost
// of starting a timer (for the retry timeout) for every Next() call
// when no error occurs.
alias := topoproto.TabletAliasString(r.tablet.Alias)
statsStreamingQueryErrorsCounters.Add(alias, 1)
log.V(2).Infof("tablet=%v table=%v chunk=%v: Failed to read next rows from active streaming query. Trying to restart stream on the same tablet. Original Error: %v", alias, r.td.Name, r.chunk, err)
result, err = r.nextWithRetries()
}
if result != nil && len(result.Rows) > 0 {
r.lastRow = result.Rows[len(result.Rows)-1]
}
return result, err
} | go | func (r *RestartableResultReader) Next() (*sqltypes.Result, error) {
result, err := r.output.Recv()
if err != nil && err != io.EOF {
// We start the retries only on the second attempt to avoid the cost
// of starting a timer (for the retry timeout) for every Next() call
// when no error occurs.
alias := topoproto.TabletAliasString(r.tablet.Alias)
statsStreamingQueryErrorsCounters.Add(alias, 1)
log.V(2).Infof("tablet=%v table=%v chunk=%v: Failed to read next rows from active streaming query. Trying to restart stream on the same tablet. Original Error: %v", alias, r.td.Name, r.chunk, err)
result, err = r.nextWithRetries()
}
if result != nil && len(result.Rows) > 0 {
r.lastRow = result.Rows[len(result.Rows)-1]
}
return result, err
} | [
"func",
"(",
"r",
"*",
"RestartableResultReader",
")",
"Next",
"(",
")",
"(",
"*",
"sqltypes",
".",
"Result",
",",
"error",
")",
"{",
"result",
",",
"err",
":=",
"r",
".",
"output",
".",
"Recv",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"io",
".",
"EOF",
"{",
"// We start the retries only on the second attempt to avoid the cost",
"// of starting a timer (for the retry timeout) for every Next() call",
"// when no error occurs.",
"alias",
":=",
"topoproto",
".",
"TabletAliasString",
"(",
"r",
".",
"tablet",
".",
"Alias",
")",
"\n",
"statsStreamingQueryErrorsCounters",
".",
"Add",
"(",
"alias",
",",
"1",
")",
"\n",
"log",
".",
"V",
"(",
"2",
")",
".",
"Infof",
"(",
"\"",
"\"",
",",
"alias",
",",
"r",
".",
"td",
".",
"Name",
",",
"r",
".",
"chunk",
",",
"err",
")",
"\n",
"result",
",",
"err",
"=",
"r",
".",
"nextWithRetries",
"(",
")",
"\n",
"}",
"\n",
"if",
"result",
"!=",
"nil",
"&&",
"len",
"(",
"result",
".",
"Rows",
")",
">",
"0",
"{",
"r",
".",
"lastRow",
"=",
"result",
".",
"Rows",
"[",
"len",
"(",
"result",
".",
"Rows",
")",
"-",
"1",
"]",
"\n",
"}",
"\n",
"return",
"result",
",",
"err",
"\n",
"}"
] | // Next returns the next result on the stream. It implements ResultReader. | [
"Next",
"returns",
"the",
"next",
"result",
"on",
"the",
"stream",
".",
"It",
"implements",
"ResultReader",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/worker/restartable_result_reader.go#L209-L224 | train |
vitessio/vitess | go/proc/counting_listener.go | Published | func Published(l net.Listener, countTag, acceptTag string) net.Listener {
return &CountingListener{
Listener: l,
ConnCount: stats.NewGauge(countTag, "Active connections accepted by counting listener"),
ConnAccept: stats.NewCounter(acceptTag, "Count of connections accepted by the counting listener"),
}
} | go | func Published(l net.Listener, countTag, acceptTag string) net.Listener {
return &CountingListener{
Listener: l,
ConnCount: stats.NewGauge(countTag, "Active connections accepted by counting listener"),
ConnAccept: stats.NewCounter(acceptTag, "Count of connections accepted by the counting listener"),
}
} | [
"func",
"Published",
"(",
"l",
"net",
".",
"Listener",
",",
"countTag",
",",
"acceptTag",
"string",
")",
"net",
".",
"Listener",
"{",
"return",
"&",
"CountingListener",
"{",
"Listener",
":",
"l",
",",
"ConnCount",
":",
"stats",
".",
"NewGauge",
"(",
"countTag",
",",
"\"",
"\"",
")",
",",
"ConnAccept",
":",
"stats",
".",
"NewCounter",
"(",
"acceptTag",
",",
"\"",
"\"",
")",
",",
"}",
"\n",
"}"
] | // Published creates a wrapper for net.Listener that
// publishes connection stats. | [
"Published",
"creates",
"a",
"wrapper",
"for",
"net",
".",
"Listener",
"that",
"publishes",
"connection",
"stats",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/proc/counting_listener.go#L38-L44 | train |
vitessio/vitess | go/proc/counting_listener.go | Accept | func (l *CountingListener) Accept() (c net.Conn, err error) {
conn, err := l.Listener.Accept()
if err != nil {
return nil, err
}
l.ConnCount.Add(1)
l.ConnAccept.Add(1)
return &countingConnection{conn, l}, nil
} | go | func (l *CountingListener) Accept() (c net.Conn, err error) {
conn, err := l.Listener.Accept()
if err != nil {
return nil, err
}
l.ConnCount.Add(1)
l.ConnAccept.Add(1)
return &countingConnection{conn, l}, nil
} | [
"func",
"(",
"l",
"*",
"CountingListener",
")",
"Accept",
"(",
")",
"(",
"c",
"net",
".",
"Conn",
",",
"err",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"l",
".",
"Listener",
".",
"Accept",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"l",
".",
"ConnCount",
".",
"Add",
"(",
"1",
")",
"\n",
"l",
".",
"ConnAccept",
".",
"Add",
"(",
"1",
")",
"\n",
"return",
"&",
"countingConnection",
"{",
"conn",
",",
"l",
"}",
",",
"nil",
"\n",
"}"
] | // Accept increments stats counters before returning
// a connection. | [
"Accept",
"increments",
"stats",
"counters",
"before",
"returning",
"a",
"connection",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/proc/counting_listener.go#L48-L56 | train |
vitessio/vitess | go/proc/counting_listener.go | Close | func (c *countingConnection) Close() error {
if c.listener != nil {
c.listener.ConnCount.Add(-1)
c.listener = nil
}
return c.Conn.Close()
} | go | func (c *countingConnection) Close() error {
if c.listener != nil {
c.listener.ConnCount.Add(-1)
c.listener = nil
}
return c.Conn.Close()
} | [
"func",
"(",
"c",
"*",
"countingConnection",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"c",
".",
"listener",
"!=",
"nil",
"{",
"c",
".",
"listener",
".",
"ConnCount",
".",
"Add",
"(",
"-",
"1",
")",
"\n",
"c",
".",
"listener",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"c",
".",
"Conn",
".",
"Close",
"(",
")",
"\n",
"}"
] | // Close decrements the stats counter and
// closes the connection. | [
"Close",
"decrements",
"the",
"stats",
"counter",
"and",
"closes",
"the",
"connection",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/proc/counting_listener.go#L60-L66 | train |
vitessio/vitess | go/vt/throttler/throttlerclient/throttlerclient.go | New | func New(addr string) (Client, error) {
factory, ok := factories[*protocol]
if !ok {
return nil, fmt.Errorf("unknown throttler client protocol: %v", *protocol)
}
return factory(addr)
} | go | func New(addr string) (Client, error) {
factory, ok := factories[*protocol]
if !ok {
return nil, fmt.Errorf("unknown throttler client protocol: %v", *protocol)
}
return factory(addr)
} | [
"func",
"New",
"(",
"addr",
"string",
")",
"(",
"Client",
",",
"error",
")",
"{",
"factory",
",",
"ok",
":=",
"factories",
"[",
"*",
"protocol",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"*",
"protocol",
")",
"\n",
"}",
"\n",
"return",
"factory",
"(",
"addr",
")",
"\n",
"}"
] | // New will return a client for the selected RPC implementation. | [
"New",
"will",
"return",
"a",
"client",
"for",
"the",
"selected",
"RPC",
"implementation",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/throttler/throttlerclient/throttlerclient.go#L82-L88 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/connpool/pool.go | New | func New(
name string,
capacity int,
idleTimeout time.Duration,
checker MySQLChecker) *Pool {
cp := &Pool{
capacity: capacity,
idleTimeout: idleTimeout,
dbaPool: dbconnpool.NewConnectionPool("", 1, idleTimeout, 0),
checker: checker,
}
if name == "" || usedNames[name] {
return cp
}
usedNames[name] = true
stats.NewGaugeFunc(name+"Capacity", "Tablet server conn pool capacity", cp.Capacity)
stats.NewGaugeFunc(name+"Available", "Tablet server conn pool available", cp.Available)
stats.NewGaugeFunc(name+"Active", "Tablet server conn pool active", cp.Active)
stats.NewGaugeFunc(name+"InUse", "Tablet server conn pool in use", cp.InUse)
stats.NewGaugeFunc(name+"MaxCap", "Tablet server conn pool max cap", cp.MaxCap)
stats.NewCounterFunc(name+"WaitCount", "Tablet server conn pool wait count", cp.WaitCount)
stats.NewCounterDurationFunc(name+"WaitTime", "Tablet server wait time", cp.WaitTime)
stats.NewGaugeDurationFunc(name+"IdleTimeout", "Tablet server idle timeout", cp.IdleTimeout)
stats.NewCounterFunc(name+"IdleClosed", "Tablet server conn pool idle closed", cp.IdleClosed)
return cp
} | go | func New(
name string,
capacity int,
idleTimeout time.Duration,
checker MySQLChecker) *Pool {
cp := &Pool{
capacity: capacity,
idleTimeout: idleTimeout,
dbaPool: dbconnpool.NewConnectionPool("", 1, idleTimeout, 0),
checker: checker,
}
if name == "" || usedNames[name] {
return cp
}
usedNames[name] = true
stats.NewGaugeFunc(name+"Capacity", "Tablet server conn pool capacity", cp.Capacity)
stats.NewGaugeFunc(name+"Available", "Tablet server conn pool available", cp.Available)
stats.NewGaugeFunc(name+"Active", "Tablet server conn pool active", cp.Active)
stats.NewGaugeFunc(name+"InUse", "Tablet server conn pool in use", cp.InUse)
stats.NewGaugeFunc(name+"MaxCap", "Tablet server conn pool max cap", cp.MaxCap)
stats.NewCounterFunc(name+"WaitCount", "Tablet server conn pool wait count", cp.WaitCount)
stats.NewCounterDurationFunc(name+"WaitTime", "Tablet server wait time", cp.WaitTime)
stats.NewGaugeDurationFunc(name+"IdleTimeout", "Tablet server idle timeout", cp.IdleTimeout)
stats.NewCounterFunc(name+"IdleClosed", "Tablet server conn pool idle closed", cp.IdleClosed)
return cp
} | [
"func",
"New",
"(",
"name",
"string",
",",
"capacity",
"int",
",",
"idleTimeout",
"time",
".",
"Duration",
",",
"checker",
"MySQLChecker",
")",
"*",
"Pool",
"{",
"cp",
":=",
"&",
"Pool",
"{",
"capacity",
":",
"capacity",
",",
"idleTimeout",
":",
"idleTimeout",
",",
"dbaPool",
":",
"dbconnpool",
".",
"NewConnectionPool",
"(",
"\"",
"\"",
",",
"1",
",",
"idleTimeout",
",",
"0",
")",
",",
"checker",
":",
"checker",
",",
"}",
"\n",
"if",
"name",
"==",
"\"",
"\"",
"||",
"usedNames",
"[",
"name",
"]",
"{",
"return",
"cp",
"\n",
"}",
"\n",
"usedNames",
"[",
"name",
"]",
"=",
"true",
"\n",
"stats",
".",
"NewGaugeFunc",
"(",
"name",
"+",
"\"",
"\"",
",",
"\"",
"\"",
",",
"cp",
".",
"Capacity",
")",
"\n",
"stats",
".",
"NewGaugeFunc",
"(",
"name",
"+",
"\"",
"\"",
",",
"\"",
"\"",
",",
"cp",
".",
"Available",
")",
"\n",
"stats",
".",
"NewGaugeFunc",
"(",
"name",
"+",
"\"",
"\"",
",",
"\"",
"\"",
",",
"cp",
".",
"Active",
")",
"\n",
"stats",
".",
"NewGaugeFunc",
"(",
"name",
"+",
"\"",
"\"",
",",
"\"",
"\"",
",",
"cp",
".",
"InUse",
")",
"\n",
"stats",
".",
"NewGaugeFunc",
"(",
"name",
"+",
"\"",
"\"",
",",
"\"",
"\"",
",",
"cp",
".",
"MaxCap",
")",
"\n",
"stats",
".",
"NewCounterFunc",
"(",
"name",
"+",
"\"",
"\"",
",",
"\"",
"\"",
",",
"cp",
".",
"WaitCount",
")",
"\n",
"stats",
".",
"NewCounterDurationFunc",
"(",
"name",
"+",
"\"",
"\"",
",",
"\"",
"\"",
",",
"cp",
".",
"WaitTime",
")",
"\n",
"stats",
".",
"NewGaugeDurationFunc",
"(",
"name",
"+",
"\"",
"\"",
",",
"\"",
"\"",
",",
"cp",
".",
"IdleTimeout",
")",
"\n",
"stats",
".",
"NewCounterFunc",
"(",
"name",
"+",
"\"",
"\"",
",",
"\"",
"\"",
",",
"cp",
".",
"IdleClosed",
")",
"\n",
"return",
"cp",
"\n",
"}"
] | // New creates a new Pool. The name is used
// to publish stats only. | [
"New",
"creates",
"a",
"new",
"Pool",
".",
"The",
"name",
"is",
"used",
"to",
"publish",
"stats",
"only",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/connpool/pool.go#L71-L96 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/connpool/pool.go | Open | func (cp *Pool) Open(appParams, dbaParams, appDebugParams *mysql.ConnParams) {
cp.mu.Lock()
defer cp.mu.Unlock()
f := func() (pools.Resource, error) {
return NewDBConn(cp, appParams)
}
cp.connections = pools.NewResourcePool(f, cp.capacity, cp.capacity, cp.idleTimeout)
cp.appDebugParams = appDebugParams
cp.dbaPool.Open(dbaParams, tabletenv.MySQLStats)
} | go | func (cp *Pool) Open(appParams, dbaParams, appDebugParams *mysql.ConnParams) {
cp.mu.Lock()
defer cp.mu.Unlock()
f := func() (pools.Resource, error) {
return NewDBConn(cp, appParams)
}
cp.connections = pools.NewResourcePool(f, cp.capacity, cp.capacity, cp.idleTimeout)
cp.appDebugParams = appDebugParams
cp.dbaPool.Open(dbaParams, tabletenv.MySQLStats)
} | [
"func",
"(",
"cp",
"*",
"Pool",
")",
"Open",
"(",
"appParams",
",",
"dbaParams",
",",
"appDebugParams",
"*",
"mysql",
".",
"ConnParams",
")",
"{",
"cp",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cp",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"f",
":=",
"func",
"(",
")",
"(",
"pools",
".",
"Resource",
",",
"error",
")",
"{",
"return",
"NewDBConn",
"(",
"cp",
",",
"appParams",
")",
"\n",
"}",
"\n",
"cp",
".",
"connections",
"=",
"pools",
".",
"NewResourcePool",
"(",
"f",
",",
"cp",
".",
"capacity",
",",
"cp",
".",
"capacity",
",",
"cp",
".",
"idleTimeout",
")",
"\n",
"cp",
".",
"appDebugParams",
"=",
"appDebugParams",
"\n\n",
"cp",
".",
"dbaPool",
".",
"Open",
"(",
"dbaParams",
",",
"tabletenv",
".",
"MySQLStats",
")",
"\n",
"}"
] | // Open must be called before starting to use the pool. | [
"Open",
"must",
"be",
"called",
"before",
"starting",
"to",
"use",
"the",
"pool",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/connpool/pool.go#L106-L117 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/connpool/pool.go | Get | func (cp *Pool) Get(ctx context.Context) (*DBConn, error) {
span, ctx := trace.NewSpan(ctx, "Pool.Get")
defer span.Finish()
if cp.isCallerIDAppDebug(ctx) {
return NewDBConnNoPool(cp.appDebugParams, cp.dbaPool)
}
p := cp.pool()
if p == nil {
return nil, ErrConnPoolClosed
}
span.Annotate("capacity", p.Capacity())
span.Annotate("in_use", p.InUse())
span.Annotate("available", p.Available())
span.Annotate("active", p.Active())
r, err := p.Get(ctx)
if err != nil {
return nil, err
}
return r.(*DBConn), nil
} | go | func (cp *Pool) Get(ctx context.Context) (*DBConn, error) {
span, ctx := trace.NewSpan(ctx, "Pool.Get")
defer span.Finish()
if cp.isCallerIDAppDebug(ctx) {
return NewDBConnNoPool(cp.appDebugParams, cp.dbaPool)
}
p := cp.pool()
if p == nil {
return nil, ErrConnPoolClosed
}
span.Annotate("capacity", p.Capacity())
span.Annotate("in_use", p.InUse())
span.Annotate("available", p.Available())
span.Annotate("active", p.Active())
r, err := p.Get(ctx)
if err != nil {
return nil, err
}
return r.(*DBConn), nil
} | [
"func",
"(",
"cp",
"*",
"Pool",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"DBConn",
",",
"error",
")",
"{",
"span",
",",
"ctx",
":=",
"trace",
".",
"NewSpan",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"if",
"cp",
".",
"isCallerIDAppDebug",
"(",
"ctx",
")",
"{",
"return",
"NewDBConnNoPool",
"(",
"cp",
".",
"appDebugParams",
",",
"cp",
".",
"dbaPool",
")",
"\n",
"}",
"\n",
"p",
":=",
"cp",
".",
"pool",
"(",
")",
"\n",
"if",
"p",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrConnPoolClosed",
"\n",
"}",
"\n",
"span",
".",
"Annotate",
"(",
"\"",
"\"",
",",
"p",
".",
"Capacity",
"(",
")",
")",
"\n",
"span",
".",
"Annotate",
"(",
"\"",
"\"",
",",
"p",
".",
"InUse",
"(",
")",
")",
"\n",
"span",
".",
"Annotate",
"(",
"\"",
"\"",
",",
"p",
".",
"Available",
"(",
")",
")",
"\n",
"span",
".",
"Annotate",
"(",
"\"",
"\"",
",",
"p",
".",
"Active",
"(",
")",
")",
"\n\n",
"r",
",",
"err",
":=",
"p",
".",
"Get",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"r",
".",
"(",
"*",
"DBConn",
")",
",",
"nil",
"\n",
"}"
] | // Get returns a connection.
// You must call Recycle on DBConn once done. | [
"Get",
"returns",
"a",
"connection",
".",
"You",
"must",
"call",
"Recycle",
"on",
"DBConn",
"once",
"done",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/connpool/pool.go#L137-L158 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/connpool/pool.go | StatsJSON | func (cp *Pool) StatsJSON() string {
p := cp.pool()
if p == nil {
return "{}"
}
return p.StatsJSON()
} | go | func (cp *Pool) StatsJSON() string {
p := cp.pool()
if p == nil {
return "{}"
}
return p.StatsJSON()
} | [
"func",
"(",
"cp",
"*",
"Pool",
")",
"StatsJSON",
"(",
")",
"string",
"{",
"p",
":=",
"cp",
".",
"pool",
"(",
")",
"\n",
"if",
"p",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"p",
".",
"StatsJSON",
"(",
")",
"\n",
"}"
] | // StatsJSON returns the pool stats as a JSON object. | [
"StatsJSON",
"returns",
"the",
"pool",
"stats",
"as",
"a",
"JSON",
"object",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/connpool/pool.go#L199-L205 | train |
vitessio/vitess | go/json2/unmarshal.go | Unmarshal | func Unmarshal(data []byte, v interface{}) error {
if pb, ok := v.(proto.Message); ok {
return annotate(data, jsonpb.Unmarshal(bytes.NewBuffer(data), pb))
}
return annotate(data, json.Unmarshal(data, v))
} | go | func Unmarshal(data []byte, v interface{}) error {
if pb, ok := v.(proto.Message); ok {
return annotate(data, jsonpb.Unmarshal(bytes.NewBuffer(data), pb))
}
return annotate(data, json.Unmarshal(data, v))
} | [
"func",
"Unmarshal",
"(",
"data",
"[",
"]",
"byte",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"pb",
",",
"ok",
":=",
"v",
".",
"(",
"proto",
".",
"Message",
")",
";",
"ok",
"{",
"return",
"annotate",
"(",
"data",
",",
"jsonpb",
".",
"Unmarshal",
"(",
"bytes",
".",
"NewBuffer",
"(",
"data",
")",
",",
"pb",
")",
")",
"\n",
"}",
"\n",
"return",
"annotate",
"(",
"data",
",",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"v",
")",
")",
"\n",
"}"
] | // Unmarshal wraps json.Unmarshal, but returns errors that
// also mention the line number. This function is not very
// efficient and should not be used for high QPS operations. | [
"Unmarshal",
"wraps",
"json",
".",
"Unmarshal",
"but",
"returns",
"errors",
"that",
"also",
"mention",
"the",
"line",
"number",
".",
"This",
"function",
"is",
"not",
"very",
"efficient",
"and",
"should",
"not",
"be",
"used",
"for",
"high",
"QPS",
"operations",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/json2/unmarshal.go#L34-L39 | train |
vitessio/vitess | go/sync2/batcher.go | NewBatcher | func NewBatcher(interval time.Duration) *Batcher {
return &Batcher{
interval: interval,
queue: make(chan int),
waiters: NewAtomicInt32(0),
nextID: NewAtomicInt32(0),
after: time.After,
}
} | go | func NewBatcher(interval time.Duration) *Batcher {
return &Batcher{
interval: interval,
queue: make(chan int),
waiters: NewAtomicInt32(0),
nextID: NewAtomicInt32(0),
after: time.After,
}
} | [
"func",
"NewBatcher",
"(",
"interval",
"time",
".",
"Duration",
")",
"*",
"Batcher",
"{",
"return",
"&",
"Batcher",
"{",
"interval",
":",
"interval",
",",
"queue",
":",
"make",
"(",
"chan",
"int",
")",
",",
"waiters",
":",
"NewAtomicInt32",
"(",
"0",
")",
",",
"nextID",
":",
"NewAtomicInt32",
"(",
"0",
")",
",",
"after",
":",
"time",
".",
"After",
",",
"}",
"\n",
"}"
] | // NewBatcher returns a new Batcher | [
"NewBatcher",
"returns",
"a",
"new",
"Batcher"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/sync2/batcher.go#L39-L47 | train |
vitessio/vitess | go/sync2/batcher.go | Wait | func (b *Batcher) Wait() int {
numWaiters := b.waiters.Add(1)
if numWaiters == 1 {
b.newBatch()
}
return <-b.queue
} | go | func (b *Batcher) Wait() int {
numWaiters := b.waiters.Add(1)
if numWaiters == 1 {
b.newBatch()
}
return <-b.queue
} | [
"func",
"(",
"b",
"*",
"Batcher",
")",
"Wait",
"(",
")",
"int",
"{",
"numWaiters",
":=",
"b",
".",
"waiters",
".",
"Add",
"(",
"1",
")",
"\n",
"if",
"numWaiters",
"==",
"1",
"{",
"b",
".",
"newBatch",
"(",
")",
"\n",
"}",
"\n",
"return",
"<-",
"b",
".",
"queue",
"\n",
"}"
] | // Wait adds a new waiter to the queue and blocks until the next batch | [
"Wait",
"adds",
"a",
"new",
"waiter",
"to",
"the",
"queue",
"and",
"blocks",
"until",
"the",
"next",
"batch"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/sync2/batcher.go#L62-L68 | train |
vitessio/vitess | go/sync2/batcher.go | newBatch | func (b *Batcher) newBatch() {
go func() {
<-b.after(b.interval)
id := b.nextID.Add(1)
// Make sure to atomically reset the number of waiters to make
// sure that all incoming requests either make it into the
// current batch or the next one.
waiters := b.waiters.Get()
for !b.waiters.CompareAndSwap(waiters, 0) {
waiters = b.waiters.Get()
}
for i := int32(0); i < waiters; i++ {
b.queue <- int(id)
}
}()
} | go | func (b *Batcher) newBatch() {
go func() {
<-b.after(b.interval)
id := b.nextID.Add(1)
// Make sure to atomically reset the number of waiters to make
// sure that all incoming requests either make it into the
// current batch or the next one.
waiters := b.waiters.Get()
for !b.waiters.CompareAndSwap(waiters, 0) {
waiters = b.waiters.Get()
}
for i := int32(0); i < waiters; i++ {
b.queue <- int(id)
}
}()
} | [
"func",
"(",
"b",
"*",
"Batcher",
")",
"newBatch",
"(",
")",
"{",
"go",
"func",
"(",
")",
"{",
"<-",
"b",
".",
"after",
"(",
"b",
".",
"interval",
")",
"\n\n",
"id",
":=",
"b",
".",
"nextID",
".",
"Add",
"(",
"1",
")",
"\n\n",
"// Make sure to atomically reset the number of waiters to make",
"// sure that all incoming requests either make it into the",
"// current batch or the next one.",
"waiters",
":=",
"b",
".",
"waiters",
".",
"Get",
"(",
")",
"\n",
"for",
"!",
"b",
".",
"waiters",
".",
"CompareAndSwap",
"(",
"waiters",
",",
"0",
")",
"{",
"waiters",
"=",
"b",
".",
"waiters",
".",
"Get",
"(",
")",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"int32",
"(",
"0",
")",
";",
"i",
"<",
"waiters",
";",
"i",
"++",
"{",
"b",
".",
"queue",
"<-",
"int",
"(",
"id",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"}"
] | // newBatch starts a new batch | [
"newBatch",
"starts",
"a",
"new",
"batch"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/sync2/batcher.go#L71-L89 | train |
vitessio/vitess | go/mysql/encoding.go | readBytesCopy | func readBytesCopy(data []byte, pos int, size int) ([]byte, int, bool) {
if pos+size-1 >= len(data) {
return nil, 0, false
}
result := make([]byte, size)
copy(result, data[pos:pos+size])
return result, pos + size, true
} | go | func readBytesCopy(data []byte, pos int, size int) ([]byte, int, bool) {
if pos+size-1 >= len(data) {
return nil, 0, false
}
result := make([]byte, size)
copy(result, data[pos:pos+size])
return result, pos + size, true
} | [
"func",
"readBytesCopy",
"(",
"data",
"[",
"]",
"byte",
",",
"pos",
"int",
",",
"size",
"int",
")",
"(",
"[",
"]",
"byte",
",",
"int",
",",
"bool",
")",
"{",
"if",
"pos",
"+",
"size",
"-",
"1",
">=",
"len",
"(",
"data",
")",
"{",
"return",
"nil",
",",
"0",
",",
"false",
"\n",
"}",
"\n",
"result",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"size",
")",
"\n",
"copy",
"(",
"result",
",",
"data",
"[",
"pos",
":",
"pos",
"+",
"size",
"]",
")",
"\n",
"return",
"result",
",",
"pos",
"+",
"size",
",",
"true",
"\n",
"}"
] | // readBytesCopy returns a copy of the bytes in the packet.
// Useful to remember contents of ephemeral packets. | [
"readBytesCopy",
"returns",
"a",
"copy",
"of",
"the",
"bytes",
"in",
"the",
"packet",
".",
"Useful",
"to",
"remember",
"contents",
"of",
"ephemeral",
"packets",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/encoding.go#L166-L173 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/pullout_subquery.go | newPulloutSubquery | func newPulloutSubquery(opcode engine.PulloutOpcode, sqName, hasValues string, subquery builder) *pulloutSubquery {
return &pulloutSubquery{
subquery: subquery,
eSubquery: &engine.PulloutSubquery{
Opcode: opcode,
SubqueryResult: sqName,
HasValues: hasValues,
},
}
} | go | func newPulloutSubquery(opcode engine.PulloutOpcode, sqName, hasValues string, subquery builder) *pulloutSubquery {
return &pulloutSubquery{
subquery: subquery,
eSubquery: &engine.PulloutSubquery{
Opcode: opcode,
SubqueryResult: sqName,
HasValues: hasValues,
},
}
} | [
"func",
"newPulloutSubquery",
"(",
"opcode",
"engine",
".",
"PulloutOpcode",
",",
"sqName",
",",
"hasValues",
"string",
",",
"subquery",
"builder",
")",
"*",
"pulloutSubquery",
"{",
"return",
"&",
"pulloutSubquery",
"{",
"subquery",
":",
"subquery",
",",
"eSubquery",
":",
"&",
"engine",
".",
"PulloutSubquery",
"{",
"Opcode",
":",
"opcode",
",",
"SubqueryResult",
":",
"sqName",
",",
"HasValues",
":",
"hasValues",
",",
"}",
",",
"}",
"\n",
"}"
] | // newPulloutSubquery builds a new pulloutSubquery. | [
"newPulloutSubquery",
"builds",
"a",
"new",
"pulloutSubquery",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/pullout_subquery.go#L37-L46 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/pullout_subquery.go | setUnderlying | func (ps *pulloutSubquery) setUnderlying(underlying builder) {
ps.underlying = underlying
ps.underlying.Reorder(ps.subquery.Order())
ps.order = ps.underlying.Order() + 1
} | go | func (ps *pulloutSubquery) setUnderlying(underlying builder) {
ps.underlying = underlying
ps.underlying.Reorder(ps.subquery.Order())
ps.order = ps.underlying.Order() + 1
} | [
"func",
"(",
"ps",
"*",
"pulloutSubquery",
")",
"setUnderlying",
"(",
"underlying",
"builder",
")",
"{",
"ps",
".",
"underlying",
"=",
"underlying",
"\n",
"ps",
".",
"underlying",
".",
"Reorder",
"(",
"ps",
".",
"subquery",
".",
"Order",
"(",
")",
")",
"\n",
"ps",
".",
"order",
"=",
"ps",
".",
"underlying",
".",
"Order",
"(",
")",
"+",
"1",
"\n",
"}"
] | // setUnderlying sets the underlying primitive. | [
"setUnderlying",
"sets",
"the",
"underlying",
"primitive",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/pullout_subquery.go#L49-L53 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/pullout_subquery.go | SetUpperLimit | func (ps *pulloutSubquery) SetUpperLimit(count *sqlparser.SQLVal) {
ps.underlying.SetUpperLimit(count)
} | go | func (ps *pulloutSubquery) SetUpperLimit(count *sqlparser.SQLVal) {
ps.underlying.SetUpperLimit(count)
} | [
"func",
"(",
"ps",
"*",
"pulloutSubquery",
")",
"SetUpperLimit",
"(",
"count",
"*",
"sqlparser",
".",
"SQLVal",
")",
"{",
"ps",
".",
"underlying",
".",
"SetUpperLimit",
"(",
"count",
")",
"\n",
"}"
] | // SetUpperLimit satisfies the builder interface.
// This is a no-op because we actually call SetLimit for this primitive.
// In the future, we may have to honor this call for subqueries. | [
"SetUpperLimit",
"satisfies",
"the",
"builder",
"interface",
".",
"This",
"is",
"a",
"no",
"-",
"op",
"because",
"we",
"actually",
"call",
"SetLimit",
"for",
"this",
"primitive",
".",
"In",
"the",
"future",
"we",
"may",
"have",
"to",
"honor",
"this",
"call",
"for",
"subqueries",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/pullout_subquery.go#L107-L109 | train |
vitessio/vitess | go/vt/mysqlctl/tmutils/schema.go | TableDefinitionGetColumn | func TableDefinitionGetColumn(td *tabletmanagerdatapb.TableDefinition, name string) (index int, ok bool) {
lowered := strings.ToLower(name)
for i, n := range td.Columns {
if lowered == strings.ToLower(n) {
return i, true
}
}
return -1, false
} | go | func TableDefinitionGetColumn(td *tabletmanagerdatapb.TableDefinition, name string) (index int, ok bool) {
lowered := strings.ToLower(name)
for i, n := range td.Columns {
if lowered == strings.ToLower(n) {
return i, true
}
}
return -1, false
} | [
"func",
"TableDefinitionGetColumn",
"(",
"td",
"*",
"tabletmanagerdatapb",
".",
"TableDefinition",
",",
"name",
"string",
")",
"(",
"index",
"int",
",",
"ok",
"bool",
")",
"{",
"lowered",
":=",
"strings",
".",
"ToLower",
"(",
"name",
")",
"\n",
"for",
"i",
",",
"n",
":=",
"range",
"td",
".",
"Columns",
"{",
"if",
"lowered",
"==",
"strings",
".",
"ToLower",
"(",
"n",
")",
"{",
"return",
"i",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"-",
"1",
",",
"false",
"\n",
"}"
] | // TableDefinitionGetColumn returns the index of a column inside a
// TableDefinition. | [
"TableDefinitionGetColumn",
"returns",
"the",
"index",
"of",
"a",
"column",
"inside",
"a",
"TableDefinition",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/tmutils/schema.go#L43-L51 | train |
vitessio/vitess | go/vt/mysqlctl/tmutils/schema.go | Swap | func (tds TableDefinitions) Swap(i, j int) {
tds[i], tds[j] = tds[j], tds[i]
} | go | func (tds TableDefinitions) Swap(i, j int) {
tds[i], tds[j] = tds[j], tds[i]
} | [
"func",
"(",
"tds",
"TableDefinitions",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"tds",
"[",
"i",
"]",
",",
"tds",
"[",
"j",
"]",
"=",
"tds",
"[",
"j",
"]",
",",
"tds",
"[",
"i",
"]",
"\n",
"}"
] | // Swap used for sorting TableDefinitions. | [
"Swap",
"used",
"for",
"sorting",
"TableDefinitions",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/tmutils/schema.go#L62-L64 | train |
vitessio/vitess | go/vt/mysqlctl/tmutils/schema.go | GenerateSchemaVersion | func GenerateSchemaVersion(sd *tabletmanagerdatapb.SchemaDefinition) {
hasher := md5.New()
for _, td := range sd.TableDefinitions {
if _, err := hasher.Write([]byte(td.Schema)); err != nil {
panic(err) // extremely unlikely
}
}
sd.Version = hex.EncodeToString(hasher.Sum(nil))
} | go | func GenerateSchemaVersion(sd *tabletmanagerdatapb.SchemaDefinition) {
hasher := md5.New()
for _, td := range sd.TableDefinitions {
if _, err := hasher.Write([]byte(td.Schema)); err != nil {
panic(err) // extremely unlikely
}
}
sd.Version = hex.EncodeToString(hasher.Sum(nil))
} | [
"func",
"GenerateSchemaVersion",
"(",
"sd",
"*",
"tabletmanagerdatapb",
".",
"SchemaDefinition",
")",
"{",
"hasher",
":=",
"md5",
".",
"New",
"(",
")",
"\n",
"for",
"_",
",",
"td",
":=",
"range",
"sd",
".",
"TableDefinitions",
"{",
"if",
"_",
",",
"err",
":=",
"hasher",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"td",
".",
"Schema",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"// extremely unlikely",
"\n",
"}",
"\n",
"}",
"\n",
"sd",
".",
"Version",
"=",
"hex",
".",
"EncodeToString",
"(",
"hasher",
".",
"Sum",
"(",
"nil",
")",
")",
"\n",
"}"
] | // GenerateSchemaVersion return a unique schema version string based on
// its TableDefinitions. | [
"GenerateSchemaVersion",
"return",
"a",
"unique",
"schema",
"version",
"string",
"based",
"on",
"its",
"TableDefinitions",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/tmutils/schema.go#L166-L174 | train |
vitessio/vitess | go/vt/mysqlctl/tmutils/schema.go | SchemaDefinitionGetTable | func SchemaDefinitionGetTable(sd *tabletmanagerdatapb.SchemaDefinition, table string) (td *tabletmanagerdatapb.TableDefinition, ok bool) {
for _, td := range sd.TableDefinitions {
if td.Name == table {
return td, true
}
}
return nil, false
} | go | func SchemaDefinitionGetTable(sd *tabletmanagerdatapb.SchemaDefinition, table string) (td *tabletmanagerdatapb.TableDefinition, ok bool) {
for _, td := range sd.TableDefinitions {
if td.Name == table {
return td, true
}
}
return nil, false
} | [
"func",
"SchemaDefinitionGetTable",
"(",
"sd",
"*",
"tabletmanagerdatapb",
".",
"SchemaDefinition",
",",
"table",
"string",
")",
"(",
"td",
"*",
"tabletmanagerdatapb",
".",
"TableDefinition",
",",
"ok",
"bool",
")",
"{",
"for",
"_",
",",
"td",
":=",
"range",
"sd",
".",
"TableDefinitions",
"{",
"if",
"td",
".",
"Name",
"==",
"table",
"{",
"return",
"td",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"false",
"\n",
"}"
] | // SchemaDefinitionGetTable returns TableDefinition for a given table name. | [
"SchemaDefinitionGetTable",
"returns",
"TableDefinition",
"for",
"a",
"given",
"table",
"name",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/tmutils/schema.go#L177-L184 | train |
vitessio/vitess | go/vt/mysqlctl/tmutils/schema.go | DiffSchema | func DiffSchema(leftName string, left *tabletmanagerdatapb.SchemaDefinition, rightName string, right *tabletmanagerdatapb.SchemaDefinition, er concurrency.ErrorRecorder) {
if left == nil && right == nil {
return
}
if left == nil || right == nil {
er.RecordError(fmt.Errorf("schemas are different:\n%s: %v, %s: %v", leftName, left, rightName, right))
return
}
if left.DatabaseSchema != right.DatabaseSchema {
er.RecordError(fmt.Errorf("schemas are different:\n%s: %v\n differs from:\n%s: %v", leftName, left.DatabaseSchema, rightName, right.DatabaseSchema))
}
leftIndex := 0
rightIndex := 0
for leftIndex < len(left.TableDefinitions) && rightIndex < len(right.TableDefinitions) {
// extra table on the left side
if left.TableDefinitions[leftIndex].Name < right.TableDefinitions[rightIndex].Name {
er.RecordError(fmt.Errorf("%v has an extra table named %v", leftName, left.TableDefinitions[leftIndex].Name))
leftIndex++
continue
}
// extra table on the right side
if left.TableDefinitions[leftIndex].Name > right.TableDefinitions[rightIndex].Name {
er.RecordError(fmt.Errorf("%v has an extra table named %v", rightName, right.TableDefinitions[rightIndex].Name))
rightIndex++
continue
}
// same name, let's see content
if left.TableDefinitions[leftIndex].Schema != right.TableDefinitions[rightIndex].Schema {
er.RecordError(fmt.Errorf("schemas differ on table %v:\n%s: %v\n differs from:\n%s: %v", left.TableDefinitions[leftIndex].Name, leftName, left.TableDefinitions[leftIndex].Schema, rightName, right.TableDefinitions[rightIndex].Schema))
}
if left.TableDefinitions[leftIndex].Type != right.TableDefinitions[rightIndex].Type {
er.RecordError(fmt.Errorf("schemas differ on table type for table %v:\n%s: %v\n differs from:\n%s: %v", left.TableDefinitions[leftIndex].Name, leftName, left.TableDefinitions[leftIndex].Type, rightName, right.TableDefinitions[rightIndex].Type))
}
leftIndex++
rightIndex++
}
for leftIndex < len(left.TableDefinitions) {
if left.TableDefinitions[leftIndex].Type == TableBaseTable {
er.RecordError(fmt.Errorf("%v has an extra table named %v", leftName, left.TableDefinitions[leftIndex].Name))
}
if left.TableDefinitions[leftIndex].Type == TableView {
er.RecordError(fmt.Errorf("%v has an extra view named %v", leftName, left.TableDefinitions[leftIndex].Name))
}
leftIndex++
}
for rightIndex < len(right.TableDefinitions) {
if right.TableDefinitions[rightIndex].Type == TableBaseTable {
er.RecordError(fmt.Errorf("%v has an extra table named %v", rightName, right.TableDefinitions[rightIndex].Name))
}
if right.TableDefinitions[rightIndex].Type == TableView {
er.RecordError(fmt.Errorf("%v has an extra view named %v", rightName, right.TableDefinitions[rightIndex].Name))
}
rightIndex++
}
} | go | func DiffSchema(leftName string, left *tabletmanagerdatapb.SchemaDefinition, rightName string, right *tabletmanagerdatapb.SchemaDefinition, er concurrency.ErrorRecorder) {
if left == nil && right == nil {
return
}
if left == nil || right == nil {
er.RecordError(fmt.Errorf("schemas are different:\n%s: %v, %s: %v", leftName, left, rightName, right))
return
}
if left.DatabaseSchema != right.DatabaseSchema {
er.RecordError(fmt.Errorf("schemas are different:\n%s: %v\n differs from:\n%s: %v", leftName, left.DatabaseSchema, rightName, right.DatabaseSchema))
}
leftIndex := 0
rightIndex := 0
for leftIndex < len(left.TableDefinitions) && rightIndex < len(right.TableDefinitions) {
// extra table on the left side
if left.TableDefinitions[leftIndex].Name < right.TableDefinitions[rightIndex].Name {
er.RecordError(fmt.Errorf("%v has an extra table named %v", leftName, left.TableDefinitions[leftIndex].Name))
leftIndex++
continue
}
// extra table on the right side
if left.TableDefinitions[leftIndex].Name > right.TableDefinitions[rightIndex].Name {
er.RecordError(fmt.Errorf("%v has an extra table named %v", rightName, right.TableDefinitions[rightIndex].Name))
rightIndex++
continue
}
// same name, let's see content
if left.TableDefinitions[leftIndex].Schema != right.TableDefinitions[rightIndex].Schema {
er.RecordError(fmt.Errorf("schemas differ on table %v:\n%s: %v\n differs from:\n%s: %v", left.TableDefinitions[leftIndex].Name, leftName, left.TableDefinitions[leftIndex].Schema, rightName, right.TableDefinitions[rightIndex].Schema))
}
if left.TableDefinitions[leftIndex].Type != right.TableDefinitions[rightIndex].Type {
er.RecordError(fmt.Errorf("schemas differ on table type for table %v:\n%s: %v\n differs from:\n%s: %v", left.TableDefinitions[leftIndex].Name, leftName, left.TableDefinitions[leftIndex].Type, rightName, right.TableDefinitions[rightIndex].Type))
}
leftIndex++
rightIndex++
}
for leftIndex < len(left.TableDefinitions) {
if left.TableDefinitions[leftIndex].Type == TableBaseTable {
er.RecordError(fmt.Errorf("%v has an extra table named %v", leftName, left.TableDefinitions[leftIndex].Name))
}
if left.TableDefinitions[leftIndex].Type == TableView {
er.RecordError(fmt.Errorf("%v has an extra view named %v", leftName, left.TableDefinitions[leftIndex].Name))
}
leftIndex++
}
for rightIndex < len(right.TableDefinitions) {
if right.TableDefinitions[rightIndex].Type == TableBaseTable {
er.RecordError(fmt.Errorf("%v has an extra table named %v", rightName, right.TableDefinitions[rightIndex].Name))
}
if right.TableDefinitions[rightIndex].Type == TableView {
er.RecordError(fmt.Errorf("%v has an extra view named %v", rightName, right.TableDefinitions[rightIndex].Name))
}
rightIndex++
}
} | [
"func",
"DiffSchema",
"(",
"leftName",
"string",
",",
"left",
"*",
"tabletmanagerdatapb",
".",
"SchemaDefinition",
",",
"rightName",
"string",
",",
"right",
"*",
"tabletmanagerdatapb",
".",
"SchemaDefinition",
",",
"er",
"concurrency",
".",
"ErrorRecorder",
")",
"{",
"if",
"left",
"==",
"nil",
"&&",
"right",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"left",
"==",
"nil",
"||",
"right",
"==",
"nil",
"{",
"er",
".",
"RecordError",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"leftName",
",",
"left",
",",
"rightName",
",",
"right",
")",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"left",
".",
"DatabaseSchema",
"!=",
"right",
".",
"DatabaseSchema",
"{",
"er",
".",
"RecordError",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\\n",
"\\n",
"\"",
",",
"leftName",
",",
"left",
".",
"DatabaseSchema",
",",
"rightName",
",",
"right",
".",
"DatabaseSchema",
")",
")",
"\n",
"}",
"\n\n",
"leftIndex",
":=",
"0",
"\n",
"rightIndex",
":=",
"0",
"\n",
"for",
"leftIndex",
"<",
"len",
"(",
"left",
".",
"TableDefinitions",
")",
"&&",
"rightIndex",
"<",
"len",
"(",
"right",
".",
"TableDefinitions",
")",
"{",
"// extra table on the left side",
"if",
"left",
".",
"TableDefinitions",
"[",
"leftIndex",
"]",
".",
"Name",
"<",
"right",
".",
"TableDefinitions",
"[",
"rightIndex",
"]",
".",
"Name",
"{",
"er",
".",
"RecordError",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"leftName",
",",
"left",
".",
"TableDefinitions",
"[",
"leftIndex",
"]",
".",
"Name",
")",
")",
"\n",
"leftIndex",
"++",
"\n",
"continue",
"\n",
"}",
"\n\n",
"// extra table on the right side",
"if",
"left",
".",
"TableDefinitions",
"[",
"leftIndex",
"]",
".",
"Name",
">",
"right",
".",
"TableDefinitions",
"[",
"rightIndex",
"]",
".",
"Name",
"{",
"er",
".",
"RecordError",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rightName",
",",
"right",
".",
"TableDefinitions",
"[",
"rightIndex",
"]",
".",
"Name",
")",
")",
"\n",
"rightIndex",
"++",
"\n",
"continue",
"\n",
"}",
"\n\n",
"// same name, let's see content",
"if",
"left",
".",
"TableDefinitions",
"[",
"leftIndex",
"]",
".",
"Schema",
"!=",
"right",
".",
"TableDefinitions",
"[",
"rightIndex",
"]",
".",
"Schema",
"{",
"er",
".",
"RecordError",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\\n",
"\\n",
"\"",
",",
"left",
".",
"TableDefinitions",
"[",
"leftIndex",
"]",
".",
"Name",
",",
"leftName",
",",
"left",
".",
"TableDefinitions",
"[",
"leftIndex",
"]",
".",
"Schema",
",",
"rightName",
",",
"right",
".",
"TableDefinitions",
"[",
"rightIndex",
"]",
".",
"Schema",
")",
")",
"\n",
"}",
"\n\n",
"if",
"left",
".",
"TableDefinitions",
"[",
"leftIndex",
"]",
".",
"Type",
"!=",
"right",
".",
"TableDefinitions",
"[",
"rightIndex",
"]",
".",
"Type",
"{",
"er",
".",
"RecordError",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\\n",
"\\n",
"\"",
",",
"left",
".",
"TableDefinitions",
"[",
"leftIndex",
"]",
".",
"Name",
",",
"leftName",
",",
"left",
".",
"TableDefinitions",
"[",
"leftIndex",
"]",
".",
"Type",
",",
"rightName",
",",
"right",
".",
"TableDefinitions",
"[",
"rightIndex",
"]",
".",
"Type",
")",
")",
"\n",
"}",
"\n\n",
"leftIndex",
"++",
"\n",
"rightIndex",
"++",
"\n",
"}",
"\n\n",
"for",
"leftIndex",
"<",
"len",
"(",
"left",
".",
"TableDefinitions",
")",
"{",
"if",
"left",
".",
"TableDefinitions",
"[",
"leftIndex",
"]",
".",
"Type",
"==",
"TableBaseTable",
"{",
"er",
".",
"RecordError",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"leftName",
",",
"left",
".",
"TableDefinitions",
"[",
"leftIndex",
"]",
".",
"Name",
")",
")",
"\n",
"}",
"\n",
"if",
"left",
".",
"TableDefinitions",
"[",
"leftIndex",
"]",
".",
"Type",
"==",
"TableView",
"{",
"er",
".",
"RecordError",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"leftName",
",",
"left",
".",
"TableDefinitions",
"[",
"leftIndex",
"]",
".",
"Name",
")",
")",
"\n",
"}",
"\n",
"leftIndex",
"++",
"\n",
"}",
"\n",
"for",
"rightIndex",
"<",
"len",
"(",
"right",
".",
"TableDefinitions",
")",
"{",
"if",
"right",
".",
"TableDefinitions",
"[",
"rightIndex",
"]",
".",
"Type",
"==",
"TableBaseTable",
"{",
"er",
".",
"RecordError",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rightName",
",",
"right",
".",
"TableDefinitions",
"[",
"rightIndex",
"]",
".",
"Name",
")",
")",
"\n",
"}",
"\n",
"if",
"right",
".",
"TableDefinitions",
"[",
"rightIndex",
"]",
".",
"Type",
"==",
"TableView",
"{",
"er",
".",
"RecordError",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rightName",
",",
"right",
".",
"TableDefinitions",
"[",
"rightIndex",
"]",
".",
"Name",
")",
")",
"\n",
"}",
"\n",
"rightIndex",
"++",
"\n",
"}",
"\n",
"}"
] | // DiffSchema generates a report on what's different between two SchemaDefinitions
// including views. | [
"DiffSchema",
"generates",
"a",
"report",
"on",
"what",
"s",
"different",
"between",
"two",
"SchemaDefinitions",
"including",
"views",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/tmutils/schema.go#L214-L274 | train |
vitessio/vitess | go/vt/mysqlctl/tmutils/schema.go | DiffSchemaToArray | func DiffSchemaToArray(leftName string, left *tabletmanagerdatapb.SchemaDefinition, rightName string, right *tabletmanagerdatapb.SchemaDefinition) (result []string) {
er := concurrency.AllErrorRecorder{}
DiffSchema(leftName, left, rightName, right, &er)
if er.HasErrors() {
return er.ErrorStrings()
}
return nil
} | go | func DiffSchemaToArray(leftName string, left *tabletmanagerdatapb.SchemaDefinition, rightName string, right *tabletmanagerdatapb.SchemaDefinition) (result []string) {
er := concurrency.AllErrorRecorder{}
DiffSchema(leftName, left, rightName, right, &er)
if er.HasErrors() {
return er.ErrorStrings()
}
return nil
} | [
"func",
"DiffSchemaToArray",
"(",
"leftName",
"string",
",",
"left",
"*",
"tabletmanagerdatapb",
".",
"SchemaDefinition",
",",
"rightName",
"string",
",",
"right",
"*",
"tabletmanagerdatapb",
".",
"SchemaDefinition",
")",
"(",
"result",
"[",
"]",
"string",
")",
"{",
"er",
":=",
"concurrency",
".",
"AllErrorRecorder",
"{",
"}",
"\n",
"DiffSchema",
"(",
"leftName",
",",
"left",
",",
"rightName",
",",
"right",
",",
"&",
"er",
")",
"\n",
"if",
"er",
".",
"HasErrors",
"(",
")",
"{",
"return",
"er",
".",
"ErrorStrings",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // DiffSchemaToArray diffs two schemas and return the schema diffs if there is any. | [
"DiffSchemaToArray",
"diffs",
"two",
"schemas",
"and",
"return",
"the",
"schema",
"diffs",
"if",
"there",
"is",
"any",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/tmutils/schema.go#L277-L284 | train |
vitessio/vitess | go/vt/mysqlctl/tmutils/schema.go | Equal | func (s *SchemaChange) Equal(s2 *SchemaChange) bool {
return s.SQL == s2.SQL &&
s.Force == s2.Force &&
s.AllowReplication == s2.AllowReplication &&
proto.Equal(s.BeforeSchema, s2.BeforeSchema) &&
proto.Equal(s.AfterSchema, s2.AfterSchema)
} | go | func (s *SchemaChange) Equal(s2 *SchemaChange) bool {
return s.SQL == s2.SQL &&
s.Force == s2.Force &&
s.AllowReplication == s2.AllowReplication &&
proto.Equal(s.BeforeSchema, s2.BeforeSchema) &&
proto.Equal(s.AfterSchema, s2.AfterSchema)
} | [
"func",
"(",
"s",
"*",
"SchemaChange",
")",
"Equal",
"(",
"s2",
"*",
"SchemaChange",
")",
"bool",
"{",
"return",
"s",
".",
"SQL",
"==",
"s2",
".",
"SQL",
"&&",
"s",
".",
"Force",
"==",
"s2",
".",
"Force",
"&&",
"s",
".",
"AllowReplication",
"==",
"s2",
".",
"AllowReplication",
"&&",
"proto",
".",
"Equal",
"(",
"s",
".",
"BeforeSchema",
",",
"s2",
".",
"BeforeSchema",
")",
"&&",
"proto",
".",
"Equal",
"(",
"s",
".",
"AfterSchema",
",",
"s2",
".",
"AfterSchema",
")",
"\n",
"}"
] | // Equal compares two SchemaChange objects. | [
"Equal",
"compares",
"two",
"SchemaChange",
"objects",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/tmutils/schema.go#L297-L303 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/splitquery/utils.go | populateNewBindVariable | func populateNewBindVariable(
bindVariableName string,
bindVariableValue *querypb.BindVariable,
resultBindVariables map[string]*querypb.BindVariable) {
_, alreadyInMap := resultBindVariables[bindVariableName]
if alreadyInMap {
panic(fmt.Sprintf(
"bindVariable %v already exists in map: %v. bindVariableValue given: %v",
bindVariableName,
resultBindVariables,
bindVariableValue))
}
resultBindVariables[bindVariableName] = bindVariableValue
} | go | func populateNewBindVariable(
bindVariableName string,
bindVariableValue *querypb.BindVariable,
resultBindVariables map[string]*querypb.BindVariable) {
_, alreadyInMap := resultBindVariables[bindVariableName]
if alreadyInMap {
panic(fmt.Sprintf(
"bindVariable %v already exists in map: %v. bindVariableValue given: %v",
bindVariableName,
resultBindVariables,
bindVariableValue))
}
resultBindVariables[bindVariableName] = bindVariableValue
} | [
"func",
"populateNewBindVariable",
"(",
"bindVariableName",
"string",
",",
"bindVariableValue",
"*",
"querypb",
".",
"BindVariable",
",",
"resultBindVariables",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
")",
"{",
"_",
",",
"alreadyInMap",
":=",
"resultBindVariables",
"[",
"bindVariableName",
"]",
"\n",
"if",
"alreadyInMap",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"bindVariableName",
",",
"resultBindVariables",
",",
"bindVariableValue",
")",
")",
"\n",
"}",
"\n",
"resultBindVariables",
"[",
"bindVariableName",
"]",
"=",
"bindVariableValue",
"\n",
"}"
] | // populateNewBindVariable inserts 'bindVariableName' with 'bindVariableValue' to the
// 'resultBindVariables' map. Panics if 'bindVariableName' already exists in the map. | [
"populateNewBindVariable",
"inserts",
"bindVariableName",
"with",
"bindVariableValue",
"to",
"the",
"resultBindVariables",
"map",
".",
"Panics",
"if",
"bindVariableName",
"already",
"exists",
"in",
"the",
"map",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/splitquery/utils.go#L31-L44 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/splitquery/utils.go | cloneBindVariables | func cloneBindVariables(bindVariables map[string]*querypb.BindVariable) map[string]*querypb.BindVariable {
result := make(map[string]*querypb.BindVariable)
for key, value := range bindVariables {
result[key] = value
}
return result
} | go | func cloneBindVariables(bindVariables map[string]*querypb.BindVariable) map[string]*querypb.BindVariable {
result := make(map[string]*querypb.BindVariable)
for key, value := range bindVariables {
result[key] = value
}
return result
} | [
"func",
"cloneBindVariables",
"(",
"bindVariables",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
")",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
"{",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
")",
"\n",
"for",
"key",
",",
"value",
":=",
"range",
"bindVariables",
"{",
"result",
"[",
"key",
"]",
"=",
"value",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // cloneBindVariables returns a shallow-copy of the given bindVariables map. | [
"cloneBindVariables",
"returns",
"a",
"shallow",
"-",
"copy",
"of",
"the",
"given",
"bindVariables",
"map",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/splitquery/utils.go#L47-L53 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/tabletenv/logstats.go | ImmediateCaller | func (stats *LogStats) ImmediateCaller() string {
return callerid.GetUsername(callerid.ImmediateCallerIDFromContext(stats.Ctx))
} | go | func (stats *LogStats) ImmediateCaller() string {
return callerid.GetUsername(callerid.ImmediateCallerIDFromContext(stats.Ctx))
} | [
"func",
"(",
"stats",
"*",
"LogStats",
")",
"ImmediateCaller",
"(",
")",
"string",
"{",
"return",
"callerid",
".",
"GetUsername",
"(",
"callerid",
".",
"ImmediateCallerIDFromContext",
"(",
"stats",
".",
"Ctx",
")",
")",
"\n",
"}"
] | // ImmediateCaller returns the immediate caller stored in LogStats.Ctx | [
"ImmediateCaller",
"returns",
"the",
"immediate",
"caller",
"stored",
"in",
"LogStats",
".",
"Ctx"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/tabletenv/logstats.go#L87-L89 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/tabletenv/logstats.go | EffectiveCaller | func (stats *LogStats) EffectiveCaller() string {
return callerid.GetPrincipal(callerid.EffectiveCallerIDFromContext(stats.Ctx))
} | go | func (stats *LogStats) EffectiveCaller() string {
return callerid.GetPrincipal(callerid.EffectiveCallerIDFromContext(stats.Ctx))
} | [
"func",
"(",
"stats",
"*",
"LogStats",
")",
"EffectiveCaller",
"(",
")",
"string",
"{",
"return",
"callerid",
".",
"GetPrincipal",
"(",
"callerid",
".",
"EffectiveCallerIDFromContext",
"(",
"stats",
".",
"Ctx",
")",
")",
"\n",
"}"
] | // EffectiveCaller returns the effective caller stored in LogStats.Ctx | [
"EffectiveCaller",
"returns",
"the",
"effective",
"caller",
"stored",
"in",
"LogStats",
".",
"Ctx"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/tabletenv/logstats.go#L92-L94 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/tabletenv/logstats.go | AddRewrittenSQL | func (stats *LogStats) AddRewrittenSQL(sql string, start time.Time) {
stats.QuerySources |= QuerySourceMySQL
stats.NumberOfQueries++
stats.rewrittenSqls = append(stats.rewrittenSqls, sql)
stats.MysqlResponseTime += time.Since(start)
} | go | func (stats *LogStats) AddRewrittenSQL(sql string, start time.Time) {
stats.QuerySources |= QuerySourceMySQL
stats.NumberOfQueries++
stats.rewrittenSqls = append(stats.rewrittenSqls, sql)
stats.MysqlResponseTime += time.Since(start)
} | [
"func",
"(",
"stats",
"*",
"LogStats",
")",
"AddRewrittenSQL",
"(",
"sql",
"string",
",",
"start",
"time",
".",
"Time",
")",
"{",
"stats",
".",
"QuerySources",
"|=",
"QuerySourceMySQL",
"\n",
"stats",
".",
"NumberOfQueries",
"++",
"\n",
"stats",
".",
"rewrittenSqls",
"=",
"append",
"(",
"stats",
".",
"rewrittenSqls",
",",
"sql",
")",
"\n",
"stats",
".",
"MysqlResponseTime",
"+=",
"time",
".",
"Since",
"(",
"start",
")",
"\n",
"}"
] | // AddRewrittenSQL adds a single sql statement to the rewritten list | [
"AddRewrittenSQL",
"adds",
"a",
"single",
"sql",
"statement",
"to",
"the",
"rewritten",
"list"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/tabletenv/logstats.go#L102-L107 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/tabletenv/logstats.go | TotalTime | func (stats *LogStats) TotalTime() time.Duration {
return stats.EndTime.Sub(stats.StartTime)
} | go | func (stats *LogStats) TotalTime() time.Duration {
return stats.EndTime.Sub(stats.StartTime)
} | [
"func",
"(",
"stats",
"*",
"LogStats",
")",
"TotalTime",
"(",
")",
"time",
".",
"Duration",
"{",
"return",
"stats",
".",
"EndTime",
".",
"Sub",
"(",
"stats",
".",
"StartTime",
")",
"\n",
"}"
] | // TotalTime returns how long this query has been running | [
"TotalTime",
"returns",
"how",
"long",
"this",
"query",
"has",
"been",
"running"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/tabletenv/logstats.go#L110-L112 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/tabletenv/logstats.go | FmtQuerySources | func (stats *LogStats) FmtQuerySources() string {
if stats.QuerySources == 0 {
return "none"
}
sources := make([]string, 2)
n := 0
if stats.QuerySources&QuerySourceMySQL != 0 {
sources[n] = "mysql"
n++
}
if stats.QuerySources&QuerySourceConsolidator != 0 {
sources[n] = "consolidator"
n++
}
return strings.Join(sources[:n], ",")
} | go | func (stats *LogStats) FmtQuerySources() string {
if stats.QuerySources == 0 {
return "none"
}
sources := make([]string, 2)
n := 0
if stats.QuerySources&QuerySourceMySQL != 0 {
sources[n] = "mysql"
n++
}
if stats.QuerySources&QuerySourceConsolidator != 0 {
sources[n] = "consolidator"
n++
}
return strings.Join(sources[:n], ",")
} | [
"func",
"(",
"stats",
"*",
"LogStats",
")",
"FmtQuerySources",
"(",
")",
"string",
"{",
"if",
"stats",
".",
"QuerySources",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"sources",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"2",
")",
"\n",
"n",
":=",
"0",
"\n",
"if",
"stats",
".",
"QuerySources",
"&",
"QuerySourceMySQL",
"!=",
"0",
"{",
"sources",
"[",
"n",
"]",
"=",
"\"",
"\"",
"\n",
"n",
"++",
"\n",
"}",
"\n",
"if",
"stats",
".",
"QuerySources",
"&",
"QuerySourceConsolidator",
"!=",
"0",
"{",
"sources",
"[",
"n",
"]",
"=",
"\"",
"\"",
"\n",
"n",
"++",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"sources",
"[",
":",
"n",
"]",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // FmtQuerySources returns a comma separated list of query
// sources. If there were no query sources, it returns the string
// "none". | [
"FmtQuerySources",
"returns",
"a",
"comma",
"separated",
"list",
"of",
"query",
"sources",
".",
"If",
"there",
"were",
"no",
"query",
"sources",
"it",
"returns",
"the",
"string",
"none",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/tabletenv/logstats.go#L139-L154 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/tabletenv/logstats.go | ErrorStr | func (stats *LogStats) ErrorStr() string {
if stats.Error != nil {
return stats.Error.Error()
}
return ""
} | go | func (stats *LogStats) ErrorStr() string {
if stats.Error != nil {
return stats.Error.Error()
}
return ""
} | [
"func",
"(",
"stats",
"*",
"LogStats",
")",
"ErrorStr",
"(",
")",
"string",
"{",
"if",
"stats",
".",
"Error",
"!=",
"nil",
"{",
"return",
"stats",
".",
"Error",
".",
"Error",
"(",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // ErrorStr returns the error string or "" | [
"ErrorStr",
"returns",
"the",
"error",
"string",
"or"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/tabletenv/logstats.go#L164-L169 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/tabletenv/logstats.go | CallInfo | func (stats *LogStats) CallInfo() (string, string) {
ci, ok := callinfo.FromContext(stats.Ctx)
if !ok {
return "", ""
}
return ci.Text(), ci.Username()
} | go | func (stats *LogStats) CallInfo() (string, string) {
ci, ok := callinfo.FromContext(stats.Ctx)
if !ok {
return "", ""
}
return ci.Text(), ci.Username()
} | [
"func",
"(",
"stats",
"*",
"LogStats",
")",
"CallInfo",
"(",
")",
"(",
"string",
",",
"string",
")",
"{",
"ci",
",",
"ok",
":=",
"callinfo",
".",
"FromContext",
"(",
"stats",
".",
"Ctx",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"ci",
".",
"Text",
"(",
")",
",",
"ci",
".",
"Username",
"(",
")",
"\n",
"}"
] | // CallInfo returns some parts of CallInfo if set | [
"CallInfo",
"returns",
"some",
"parts",
"of",
"CallInfo",
"if",
"set"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/tabletenv/logstats.go#L172-L178 | train |
vitessio/vitess | go/vtbench/vtbench.go | String | func (cp ClientProtocol) String() string {
switch cp {
case MySQL:
return "mysql"
case GRPCVtgate:
return "grpc-vtgate"
case GRPCVttablet:
return "grpc-vttablet"
default:
return fmt.Sprintf("unknown-protocol-%d", cp)
}
} | go | func (cp ClientProtocol) String() string {
switch cp {
case MySQL:
return "mysql"
case GRPCVtgate:
return "grpc-vtgate"
case GRPCVttablet:
return "grpc-vttablet"
default:
return fmt.Sprintf("unknown-protocol-%d", cp)
}
} | [
"func",
"(",
"cp",
"ClientProtocol",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"cp",
"{",
"case",
"MySQL",
":",
"return",
"\"",
"\"",
"\n",
"case",
"GRPCVtgate",
":",
"return",
"\"",
"\"",
"\n",
"case",
"GRPCVttablet",
":",
"return",
"\"",
"\"",
"\n",
"default",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"cp",
")",
"\n",
"}",
"\n",
"}"
] | // ProtocolString returns a string representation of the protocol | [
"ProtocolString",
"returns",
"a",
"string",
"representation",
"of",
"the",
"protocol"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vtbench/vtbench.go#L47-L58 | train |
vitessio/vitess | go/vtbench/vtbench.go | NewBench | func NewBench(threads, count int, cp ConnParams, query string) *Bench {
bench := Bench{
Threads: threads,
Count: count,
ConnParams: cp,
Query: query,
Rows: stats.NewCounter("", ""),
Timings: stats.NewTimings("", "", ""),
}
return &bench
} | go | func NewBench(threads, count int, cp ConnParams, query string) *Bench {
bench := Bench{
Threads: threads,
Count: count,
ConnParams: cp,
Query: query,
Rows: stats.NewCounter("", ""),
Timings: stats.NewTimings("", "", ""),
}
return &bench
} | [
"func",
"NewBench",
"(",
"threads",
",",
"count",
"int",
",",
"cp",
"ConnParams",
",",
"query",
"string",
")",
"*",
"Bench",
"{",
"bench",
":=",
"Bench",
"{",
"Threads",
":",
"threads",
",",
"Count",
":",
"count",
",",
"ConnParams",
":",
"cp",
",",
"Query",
":",
"query",
",",
"Rows",
":",
"stats",
".",
"NewCounter",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"Timings",
":",
"stats",
".",
"NewTimings",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"}",
"\n",
"return",
"&",
"bench",
"\n",
"}"
] | // NewBench creates a new bench test | [
"NewBench",
"creates",
"a",
"new",
"bench",
"test"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vtbench/vtbench.go#L102-L112 | train |
vitessio/vitess | go/vtbench/vtbench.go | Run | func (b *Bench) Run(ctx context.Context) error {
err := b.createConns(ctx)
if err != nil {
return err
}
b.createThreads(ctx)
b.runTest(ctx)
return nil
} | go | func (b *Bench) Run(ctx context.Context) error {
err := b.createConns(ctx)
if err != nil {
return err
}
b.createThreads(ctx)
b.runTest(ctx)
return nil
} | [
"func",
"(",
"b",
"*",
"Bench",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"err",
":=",
"b",
".",
"createConns",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"b",
".",
"createThreads",
"(",
"ctx",
")",
"\n",
"b",
".",
"runTest",
"(",
"ctx",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Run executes the test | [
"Run",
"executes",
"the",
"test"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vtbench/vtbench.go#L115-L124 | train |
vitessio/vitess | go/history/history.go | Add | func (history *History) Add(record interface{}) {
history.mu.Lock()
defer history.mu.Unlock()
history.latest = record
if equiv, ok := record.(Deduplicable); ok && history.length > 0 {
if equiv.IsDuplicate(history.lastAdded) {
return
}
}
history.records[history.next] = record
history.lastAdded = record
if history.length < len(history.records) {
history.length++
}
history.next = (history.next + 1) % len(history.records)
} | go | func (history *History) Add(record interface{}) {
history.mu.Lock()
defer history.mu.Unlock()
history.latest = record
if equiv, ok := record.(Deduplicable); ok && history.length > 0 {
if equiv.IsDuplicate(history.lastAdded) {
return
}
}
history.records[history.next] = record
history.lastAdded = record
if history.length < len(history.records) {
history.length++
}
history.next = (history.next + 1) % len(history.records)
} | [
"func",
"(",
"history",
"*",
"History",
")",
"Add",
"(",
"record",
"interface",
"{",
"}",
")",
"{",
"history",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"history",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"history",
".",
"latest",
"=",
"record",
"\n\n",
"if",
"equiv",
",",
"ok",
":=",
"record",
".",
"(",
"Deduplicable",
")",
";",
"ok",
"&&",
"history",
".",
"length",
">",
"0",
"{",
"if",
"equiv",
".",
"IsDuplicate",
"(",
"history",
".",
"lastAdded",
")",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"history",
".",
"records",
"[",
"history",
".",
"next",
"]",
"=",
"record",
"\n",
"history",
".",
"lastAdded",
"=",
"record",
"\n\n",
"if",
"history",
".",
"length",
"<",
"len",
"(",
"history",
".",
"records",
")",
"{",
"history",
".",
"length",
"++",
"\n",
"}",
"\n\n",
"history",
".",
"next",
"=",
"(",
"history",
".",
"next",
"+",
"1",
")",
"%",
"len",
"(",
"history",
".",
"records",
")",
"\n",
"}"
] | // Add a new record in a threadsafe manner. If record implements
// Deduplicable, and IsDuplicate returns true when called on the last
// previously added record, it will not be added. | [
"Add",
"a",
"new",
"record",
"in",
"a",
"threadsafe",
"manner",
".",
"If",
"record",
"implements",
"Deduplicable",
"and",
"IsDuplicate",
"returns",
"true",
"when",
"called",
"on",
"the",
"last",
"previously",
"added",
"record",
"it",
"will",
"not",
"be",
"added",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/history/history.go#L52-L72 | train |
vitessio/vitess | go/history/history.go | Records | func (history *History) Records() []interface{} {
history.mu.Lock()
defer history.mu.Unlock()
records := make([]interface{}, 0, history.length)
records = append(records, history.records[history.next:history.length]...)
records = append(records, history.records[:history.next]...)
// In place reverse.
for i := 0; i < history.length/2; i++ {
records[i], records[history.length-i-1] = records[history.length-i-1], records[i]
}
return records
} | go | func (history *History) Records() []interface{} {
history.mu.Lock()
defer history.mu.Unlock()
records := make([]interface{}, 0, history.length)
records = append(records, history.records[history.next:history.length]...)
records = append(records, history.records[:history.next]...)
// In place reverse.
for i := 0; i < history.length/2; i++ {
records[i], records[history.length-i-1] = records[history.length-i-1], records[i]
}
return records
} | [
"func",
"(",
"history",
"*",
"History",
")",
"Records",
"(",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"history",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"history",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"records",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"0",
",",
"history",
".",
"length",
")",
"\n",
"records",
"=",
"append",
"(",
"records",
",",
"history",
".",
"records",
"[",
"history",
".",
"next",
":",
"history",
".",
"length",
"]",
"...",
")",
"\n",
"records",
"=",
"append",
"(",
"records",
",",
"history",
".",
"records",
"[",
":",
"history",
".",
"next",
"]",
"...",
")",
"\n\n",
"// In place reverse.",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"history",
".",
"length",
"/",
"2",
";",
"i",
"++",
"{",
"records",
"[",
"i",
"]",
",",
"records",
"[",
"history",
".",
"length",
"-",
"i",
"-",
"1",
"]",
"=",
"records",
"[",
"history",
".",
"length",
"-",
"i",
"-",
"1",
"]",
",",
"records",
"[",
"i",
"]",
"\n",
"}",
"\n\n",
"return",
"records",
"\n",
"}"
] | // Records returns the kept records in reverse chronological order in a
// threadsafe manner. | [
"Records",
"returns",
"the",
"kept",
"records",
"in",
"reverse",
"chronological",
"order",
"in",
"a",
"threadsafe",
"manner",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/history/history.go#L76-L90 | train |
vitessio/vitess | go/vt/vttablet/tabletmanager/rpc_external_reparent.go | TabletExternallyReparented | func (agent *ActionAgent) TabletExternallyReparented(ctx context.Context, externalID string) error {
if err := agent.lock(ctx); err != nil {
return err
}
defer agent.unlock()
startTime := time.Now()
// If there is a finalize step running, wait for it to finish or time out
// before checking the global shard record again.
if agent.finalizeReparentCtx != nil {
select {
case <-agent.finalizeReparentCtx.Done():
agent.finalizeReparentCtx = nil
case <-ctx.Done():
return ctx.Err()
}
}
tablet := agent.Tablet()
// Check the global shard record.
si, err := agent.TopoServer.GetShard(ctx, tablet.Keyspace, tablet.Shard)
if err != nil {
log.Warningf("fastTabletExternallyReparented: failed to read global shard record for %v/%v: %v", tablet.Keyspace, tablet.Shard, err)
return err
}
// The external failover tool told us that we are still the MASTER. Update the
// timestamp to the current time.
agent.setExternallyReparentedTime(startTime)
if topoproto.TabletAliasEqual(si.MasterAlias, tablet.Alias) {
// We may get called on the current master even when nothing has changed.
// If the global shard record is already updated, it means we successfully
// finished a previous reparent to this tablet.
return nil
}
// Create a reusable Reparent event with available info.
ev := &events.Reparent{
ShardInfo: *si,
NewMaster: *tablet,
OldMaster: topodatapb.Tablet{
Alias: si.MasterAlias,
Type: topodatapb.TabletType_MASTER,
},
ExternalID: externalID,
}
defer func() {
if err != nil {
event.DispatchUpdate(ev, "failed: "+err.Error())
}
}()
event.DispatchUpdate(ev, "starting external from tablet (fast)")
// Execute state change to master by force-updating only the local copy of the
// tablet record. The actual record in topo will be updated later.
log.Infof("fastTabletExternallyReparented: executing change callback for state change to MASTER")
newTablet := proto.Clone(tablet).(*topodatapb.Tablet)
newTablet.Type = topodatapb.TabletType_MASTER
// This is where updateState will block for gracePeriod, while it gives
// vtgate a chance to stop sending replica queries.
agent.updateState(ctx, newTablet, "fastTabletExternallyReparented")
// Start the finalize stage with a background context, but connect the trace.
bgCtx, cancel := context.WithTimeout(agent.batchCtx, *finalizeReparentTimeout)
bgCtx = trace.CopySpan(bgCtx, ctx)
agent.finalizeReparentCtx = bgCtx
go func() {
err := agent.finalizeTabletExternallyReparented(bgCtx, si, ev)
cancel()
if err != nil {
log.Warningf("finalizeTabletExternallyReparented error: %v", err)
event.DispatchUpdate(ev, "failed: "+err.Error())
return
}
externalReparentStats.Record("FullRebuild", startTime)
}()
return nil
} | go | func (agent *ActionAgent) TabletExternallyReparented(ctx context.Context, externalID string) error {
if err := agent.lock(ctx); err != nil {
return err
}
defer agent.unlock()
startTime := time.Now()
// If there is a finalize step running, wait for it to finish or time out
// before checking the global shard record again.
if agent.finalizeReparentCtx != nil {
select {
case <-agent.finalizeReparentCtx.Done():
agent.finalizeReparentCtx = nil
case <-ctx.Done():
return ctx.Err()
}
}
tablet := agent.Tablet()
// Check the global shard record.
si, err := agent.TopoServer.GetShard(ctx, tablet.Keyspace, tablet.Shard)
if err != nil {
log.Warningf("fastTabletExternallyReparented: failed to read global shard record for %v/%v: %v", tablet.Keyspace, tablet.Shard, err)
return err
}
// The external failover tool told us that we are still the MASTER. Update the
// timestamp to the current time.
agent.setExternallyReparentedTime(startTime)
if topoproto.TabletAliasEqual(si.MasterAlias, tablet.Alias) {
// We may get called on the current master even when nothing has changed.
// If the global shard record is already updated, it means we successfully
// finished a previous reparent to this tablet.
return nil
}
// Create a reusable Reparent event with available info.
ev := &events.Reparent{
ShardInfo: *si,
NewMaster: *tablet,
OldMaster: topodatapb.Tablet{
Alias: si.MasterAlias,
Type: topodatapb.TabletType_MASTER,
},
ExternalID: externalID,
}
defer func() {
if err != nil {
event.DispatchUpdate(ev, "failed: "+err.Error())
}
}()
event.DispatchUpdate(ev, "starting external from tablet (fast)")
// Execute state change to master by force-updating only the local copy of the
// tablet record. The actual record in topo will be updated later.
log.Infof("fastTabletExternallyReparented: executing change callback for state change to MASTER")
newTablet := proto.Clone(tablet).(*topodatapb.Tablet)
newTablet.Type = topodatapb.TabletType_MASTER
// This is where updateState will block for gracePeriod, while it gives
// vtgate a chance to stop sending replica queries.
agent.updateState(ctx, newTablet, "fastTabletExternallyReparented")
// Start the finalize stage with a background context, but connect the trace.
bgCtx, cancel := context.WithTimeout(agent.batchCtx, *finalizeReparentTimeout)
bgCtx = trace.CopySpan(bgCtx, ctx)
agent.finalizeReparentCtx = bgCtx
go func() {
err := agent.finalizeTabletExternallyReparented(bgCtx, si, ev)
cancel()
if err != nil {
log.Warningf("finalizeTabletExternallyReparented error: %v", err)
event.DispatchUpdate(ev, "failed: "+err.Error())
return
}
externalReparentStats.Record("FullRebuild", startTime)
}()
return nil
} | [
"func",
"(",
"agent",
"*",
"ActionAgent",
")",
"TabletExternallyReparented",
"(",
"ctx",
"context",
".",
"Context",
",",
"externalID",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"agent",
".",
"lock",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"agent",
".",
"unlock",
"(",
")",
"\n\n",
"startTime",
":=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"// If there is a finalize step running, wait for it to finish or time out",
"// before checking the global shard record again.",
"if",
"agent",
".",
"finalizeReparentCtx",
"!=",
"nil",
"{",
"select",
"{",
"case",
"<-",
"agent",
".",
"finalizeReparentCtx",
".",
"Done",
"(",
")",
":",
"agent",
".",
"finalizeReparentCtx",
"=",
"nil",
"\n",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"ctx",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"tablet",
":=",
"agent",
".",
"Tablet",
"(",
")",
"\n\n",
"// Check the global shard record.",
"si",
",",
"err",
":=",
"agent",
".",
"TopoServer",
".",
"GetShard",
"(",
"ctx",
",",
"tablet",
".",
"Keyspace",
",",
"tablet",
".",
"Shard",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"tablet",
".",
"Keyspace",
",",
"tablet",
".",
"Shard",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// The external failover tool told us that we are still the MASTER. Update the",
"// timestamp to the current time.",
"agent",
".",
"setExternallyReparentedTime",
"(",
"startTime",
")",
"\n\n",
"if",
"topoproto",
".",
"TabletAliasEqual",
"(",
"si",
".",
"MasterAlias",
",",
"tablet",
".",
"Alias",
")",
"{",
"// We may get called on the current master even when nothing has changed.",
"// If the global shard record is already updated, it means we successfully",
"// finished a previous reparent to this tablet.",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Create a reusable Reparent event with available info.",
"ev",
":=",
"&",
"events",
".",
"Reparent",
"{",
"ShardInfo",
":",
"*",
"si",
",",
"NewMaster",
":",
"*",
"tablet",
",",
"OldMaster",
":",
"topodatapb",
".",
"Tablet",
"{",
"Alias",
":",
"si",
".",
"MasterAlias",
",",
"Type",
":",
"topodatapb",
".",
"TabletType_MASTER",
",",
"}",
",",
"ExternalID",
":",
"externalID",
",",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"event",
".",
"DispatchUpdate",
"(",
"ev",
",",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"event",
".",
"DispatchUpdate",
"(",
"ev",
",",
"\"",
"\"",
")",
"\n\n",
"// Execute state change to master by force-updating only the local copy of the",
"// tablet record. The actual record in topo will be updated later.",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"newTablet",
":=",
"proto",
".",
"Clone",
"(",
"tablet",
")",
".",
"(",
"*",
"topodatapb",
".",
"Tablet",
")",
"\n",
"newTablet",
".",
"Type",
"=",
"topodatapb",
".",
"TabletType_MASTER",
"\n\n",
"// This is where updateState will block for gracePeriod, while it gives",
"// vtgate a chance to stop sending replica queries.",
"agent",
".",
"updateState",
"(",
"ctx",
",",
"newTablet",
",",
"\"",
"\"",
")",
"\n\n",
"// Start the finalize stage with a background context, but connect the trace.",
"bgCtx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"agent",
".",
"batchCtx",
",",
"*",
"finalizeReparentTimeout",
")",
"\n",
"bgCtx",
"=",
"trace",
".",
"CopySpan",
"(",
"bgCtx",
",",
"ctx",
")",
"\n",
"agent",
".",
"finalizeReparentCtx",
"=",
"bgCtx",
"\n",
"go",
"func",
"(",
")",
"{",
"err",
":=",
"agent",
".",
"finalizeTabletExternallyReparented",
"(",
"bgCtx",
",",
"si",
",",
"ev",
")",
"\n",
"cancel",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"event",
".",
"DispatchUpdate",
"(",
"ev",
",",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"\n",
"}",
"\n",
"externalReparentStats",
".",
"Record",
"(",
"\"",
"\"",
",",
"startTime",
")",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // TabletExternallyReparented updates all topo records so the current
// tablet is the new master for this shard. | [
"TabletExternallyReparented",
"updates",
"all",
"topo",
"records",
"so",
"the",
"current",
"tablet",
"is",
"the",
"new",
"master",
"for",
"this",
"shard",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletmanager/rpc_external_reparent.go#L52-L135 | train |
vitessio/vitess | go/vt/vttablet/tabletmanager/rpc_external_reparent.go | setExternallyReparentedTime | func (agent *ActionAgent) setExternallyReparentedTime(t time.Time) {
agent.mutex.Lock()
defer agent.mutex.Unlock()
agent._tabletExternallyReparentedTime = t
agent._replicationDelay = 0
} | go | func (agent *ActionAgent) setExternallyReparentedTime(t time.Time) {
agent.mutex.Lock()
defer agent.mutex.Unlock()
agent._tabletExternallyReparentedTime = t
agent._replicationDelay = 0
} | [
"func",
"(",
"agent",
"*",
"ActionAgent",
")",
"setExternallyReparentedTime",
"(",
"t",
"time",
".",
"Time",
")",
"{",
"agent",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"agent",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"agent",
".",
"_tabletExternallyReparentedTime",
"=",
"t",
"\n",
"agent",
".",
"_replicationDelay",
"=",
"0",
"\n",
"}"
] | // setExternallyReparentedTime remembers the last time when we were told we're
// the master.
// If another tablet claims to be master and offers a more recent time,
// that tablet will be trusted over us. | [
"setExternallyReparentedTime",
"remembers",
"the",
"last",
"time",
"when",
"we",
"were",
"told",
"we",
"re",
"the",
"master",
".",
"If",
"another",
"tablet",
"claims",
"to",
"be",
"master",
"and",
"offers",
"a",
"more",
"recent",
"time",
"that",
"tablet",
"will",
"be",
"trusted",
"over",
"us",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletmanager/rpc_external_reparent.go#L253-L259 | train |
vitessio/vitess | go/vt/vttablet/tabletmanager/vreplication/vplayer.go | play | func (vp *vplayer) play(ctx context.Context) error {
if !vp.stopPos.IsZero() && vp.startPos.AtLeast(vp.stopPos) {
if vp.saveStop {
return vp.vr.setState(binlogplayer.BlpStopped, fmt.Sprintf("Stop position %v already reached: %v", vp.startPos, vp.stopPos))
}
return nil
}
plan, err := buildReplicatorPlan(vp.vr.source.Filter, vp.vr.tableKeys, vp.copyState)
if err != nil {
return err
}
vp.replicatorPlan = plan
if err := vp.fetchAndApply(ctx); err != nil {
msg := err.Error()
vp.vr.stats.History.Add(&binlogplayer.StatsHistoryRecord{
Time: time.Now(),
Message: msg,
})
if err := vp.vr.setMessage(msg); err != nil {
log.Errorf("Failed to set error state: %v", err)
}
return err
}
return nil
} | go | func (vp *vplayer) play(ctx context.Context) error {
if !vp.stopPos.IsZero() && vp.startPos.AtLeast(vp.stopPos) {
if vp.saveStop {
return vp.vr.setState(binlogplayer.BlpStopped, fmt.Sprintf("Stop position %v already reached: %v", vp.startPos, vp.stopPos))
}
return nil
}
plan, err := buildReplicatorPlan(vp.vr.source.Filter, vp.vr.tableKeys, vp.copyState)
if err != nil {
return err
}
vp.replicatorPlan = plan
if err := vp.fetchAndApply(ctx); err != nil {
msg := err.Error()
vp.vr.stats.History.Add(&binlogplayer.StatsHistoryRecord{
Time: time.Now(),
Message: msg,
})
if err := vp.vr.setMessage(msg); err != nil {
log.Errorf("Failed to set error state: %v", err)
}
return err
}
return nil
} | [
"func",
"(",
"vp",
"*",
"vplayer",
")",
"play",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"!",
"vp",
".",
"stopPos",
".",
"IsZero",
"(",
")",
"&&",
"vp",
".",
"startPos",
".",
"AtLeast",
"(",
"vp",
".",
"stopPos",
")",
"{",
"if",
"vp",
".",
"saveStop",
"{",
"return",
"vp",
".",
"vr",
".",
"setState",
"(",
"binlogplayer",
".",
"BlpStopped",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"vp",
".",
"startPos",
",",
"vp",
".",
"stopPos",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"plan",
",",
"err",
":=",
"buildReplicatorPlan",
"(",
"vp",
".",
"vr",
".",
"source",
".",
"Filter",
",",
"vp",
".",
"vr",
".",
"tableKeys",
",",
"vp",
".",
"copyState",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"vp",
".",
"replicatorPlan",
"=",
"plan",
"\n\n",
"if",
"err",
":=",
"vp",
".",
"fetchAndApply",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"msg",
":=",
"err",
".",
"Error",
"(",
")",
"\n",
"vp",
".",
"vr",
".",
"stats",
".",
"History",
".",
"Add",
"(",
"&",
"binlogplayer",
".",
"StatsHistoryRecord",
"{",
"Time",
":",
"time",
".",
"Now",
"(",
")",
",",
"Message",
":",
"msg",
",",
"}",
")",
"\n",
"if",
"err",
":=",
"vp",
".",
"vr",
".",
"setMessage",
"(",
"msg",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // play is not resumable. If pausePos is set, play returns without updating the vreplication state. | [
"play",
"is",
"not",
"resumable",
".",
"If",
"pausePos",
"is",
"set",
"play",
"returns",
"without",
"updating",
"the",
"vreplication",
"state",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletmanager/vreplication/vplayer.go#L79-L105 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/vindex_func.go | PushFilter | func (vf *vindexFunc) PushFilter(pb *primitiveBuilder, filter sqlparser.Expr, whereType string, _ builder) error {
if vf.eVindexFunc.Opcode != engine.VindexNone {
return errors.New("unsupported: where clause for vindex function must be of the form id = <val> (multiple filters)")
}
// Check LHS.
comparison, ok := filter.(*sqlparser.ComparisonExpr)
if !ok {
return errors.New("unsupported: where clause for vindex function must be of the form id = <val> (not a comparison)")
}
if comparison.Operator != sqlparser.EqualStr {
return errors.New("unsupported: where clause for vindex function must be of the form id = <val> (not equality)")
}
colname, ok := comparison.Left.(*sqlparser.ColName)
if !ok {
return errors.New("unsupported: where clause for vindex function must be of the form id = <val> (lhs is not a column)")
}
if !colname.Name.EqualString("id") {
return errors.New("unsupported: where clause for vindex function must be of the form id = <val> (lhs is not id)")
}
// Check RHS.
// We have to check before calling NewPlanValue because NewPlanValue allows lists also.
if !sqlparser.IsValue(comparison.Right) {
return errors.New("unsupported: where clause for vindex function must be of the form id = <val> (rhs is not a value)")
}
var err error
vf.eVindexFunc.Value, err = sqlparser.NewPlanValue(comparison.Right)
if err != nil {
return fmt.Errorf("unsupported: where clause for vindex function must be of the form id = <val>: %v", err)
}
vf.eVindexFunc.Opcode = engine.VindexMap
return nil
} | go | func (vf *vindexFunc) PushFilter(pb *primitiveBuilder, filter sqlparser.Expr, whereType string, _ builder) error {
if vf.eVindexFunc.Opcode != engine.VindexNone {
return errors.New("unsupported: where clause for vindex function must be of the form id = <val> (multiple filters)")
}
// Check LHS.
comparison, ok := filter.(*sqlparser.ComparisonExpr)
if !ok {
return errors.New("unsupported: where clause for vindex function must be of the form id = <val> (not a comparison)")
}
if comparison.Operator != sqlparser.EqualStr {
return errors.New("unsupported: where clause for vindex function must be of the form id = <val> (not equality)")
}
colname, ok := comparison.Left.(*sqlparser.ColName)
if !ok {
return errors.New("unsupported: where clause for vindex function must be of the form id = <val> (lhs is not a column)")
}
if !colname.Name.EqualString("id") {
return errors.New("unsupported: where clause for vindex function must be of the form id = <val> (lhs is not id)")
}
// Check RHS.
// We have to check before calling NewPlanValue because NewPlanValue allows lists also.
if !sqlparser.IsValue(comparison.Right) {
return errors.New("unsupported: where clause for vindex function must be of the form id = <val> (rhs is not a value)")
}
var err error
vf.eVindexFunc.Value, err = sqlparser.NewPlanValue(comparison.Right)
if err != nil {
return fmt.Errorf("unsupported: where clause for vindex function must be of the form id = <val>: %v", err)
}
vf.eVindexFunc.Opcode = engine.VindexMap
return nil
} | [
"func",
"(",
"vf",
"*",
"vindexFunc",
")",
"PushFilter",
"(",
"pb",
"*",
"primitiveBuilder",
",",
"filter",
"sqlparser",
".",
"Expr",
",",
"whereType",
"string",
",",
"_",
"builder",
")",
"error",
"{",
"if",
"vf",
".",
"eVindexFunc",
".",
"Opcode",
"!=",
"engine",
".",
"VindexNone",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Check LHS.",
"comparison",
",",
"ok",
":=",
"filter",
".",
"(",
"*",
"sqlparser",
".",
"ComparisonExpr",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"comparison",
".",
"Operator",
"!=",
"sqlparser",
".",
"EqualStr",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"colname",
",",
"ok",
":=",
"comparison",
".",
"Left",
".",
"(",
"*",
"sqlparser",
".",
"ColName",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"colname",
".",
"Name",
".",
"EqualString",
"(",
"\"",
"\"",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Check RHS.",
"// We have to check before calling NewPlanValue because NewPlanValue allows lists also.",
"if",
"!",
"sqlparser",
".",
"IsValue",
"(",
"comparison",
".",
"Right",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"err",
"error",
"\n",
"vf",
".",
"eVindexFunc",
".",
"Value",
",",
"err",
"=",
"sqlparser",
".",
"NewPlanValue",
"(",
"comparison",
".",
"Right",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"vf",
".",
"eVindexFunc",
".",
"Opcode",
"=",
"engine",
".",
"VindexMap",
"\n",
"return",
"nil",
"\n",
"}"
] | // PushFilter satisfies the builder interface.
// Only some where clauses are allowed. | [
"PushFilter",
"satisfies",
"the",
"builder",
"interface",
".",
"Only",
"some",
"where",
"clauses",
"are",
"allowed",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/vindex_func.go#L97-L130 | train |
vitessio/vitess | go/vt/vtgate/vindexes/reverse_bits.go | NewReverseBits | func NewReverseBits(name string, m map[string]string) (Vindex, error) {
return &ReverseBits{name: name}, nil
} | go | func NewReverseBits(name string, m map[string]string) (Vindex, error) {
return &ReverseBits{name: name}, nil
} | [
"func",
"NewReverseBits",
"(",
"name",
"string",
",",
"m",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"Vindex",
",",
"error",
")",
"{",
"return",
"&",
"ReverseBits",
"{",
"name",
":",
"name",
"}",
",",
"nil",
"\n",
"}"
] | // NewReverseBits creates a new ReverseBits. | [
"NewReverseBits",
"creates",
"a",
"new",
"ReverseBits",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/reverse_bits.go#L43-L45 | train |
vitessio/vitess | go/vt/vtgate/vindexes/reverse_bits.go | Map | func (vind *ReverseBits) Map(cursor VCursor, ids []sqltypes.Value) ([]key.Destination, error) {
out := make([]key.Destination, len(ids))
for i, id := range ids {
num, err := sqltypes.ToUint64(id)
if err != nil {
out[i] = key.DestinationNone{}
continue
}
out[i] = key.DestinationKeyspaceID(reverse(num))
}
return out, nil
} | go | func (vind *ReverseBits) Map(cursor VCursor, ids []sqltypes.Value) ([]key.Destination, error) {
out := make([]key.Destination, len(ids))
for i, id := range ids {
num, err := sqltypes.ToUint64(id)
if err != nil {
out[i] = key.DestinationNone{}
continue
}
out[i] = key.DestinationKeyspaceID(reverse(num))
}
return out, nil
} | [
"func",
"(",
"vind",
"*",
"ReverseBits",
")",
"Map",
"(",
"cursor",
"VCursor",
",",
"ids",
"[",
"]",
"sqltypes",
".",
"Value",
")",
"(",
"[",
"]",
"key",
".",
"Destination",
",",
"error",
")",
"{",
"out",
":=",
"make",
"(",
"[",
"]",
"key",
".",
"Destination",
",",
"len",
"(",
"ids",
")",
")",
"\n",
"for",
"i",
",",
"id",
":=",
"range",
"ids",
"{",
"num",
",",
"err",
":=",
"sqltypes",
".",
"ToUint64",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"out",
"[",
"i",
"]",
"=",
"key",
".",
"DestinationNone",
"{",
"}",
"\n",
"continue",
"\n",
"}",
"\n",
"out",
"[",
"i",
"]",
"=",
"key",
".",
"DestinationKeyspaceID",
"(",
"reverse",
"(",
"num",
")",
")",
"\n",
"}",
"\n",
"return",
"out",
",",
"nil",
"\n",
"}"
] | // Map returns the corresponding KeyspaceId values for the given ids. | [
"Map",
"returns",
"the",
"corresponding",
"KeyspaceId",
"values",
"for",
"the",
"given",
"ids",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/reverse_bits.go#L68-L79 | train |
vitessio/vitess | go/vt/vtgate/vindexes/reverse_bits.go | ReverseMap | func (vind *ReverseBits) ReverseMap(_ VCursor, ksids [][]byte) ([]sqltypes.Value, error) {
reverseIds := make([]sqltypes.Value, 0, len(ksids))
for _, keyspaceID := range ksids {
val, err := unreverse(keyspaceID)
if err != nil {
return reverseIds, err
}
reverseIds = append(reverseIds, sqltypes.NewUint64(val))
}
return reverseIds, nil
} | go | func (vind *ReverseBits) ReverseMap(_ VCursor, ksids [][]byte) ([]sqltypes.Value, error) {
reverseIds := make([]sqltypes.Value, 0, len(ksids))
for _, keyspaceID := range ksids {
val, err := unreverse(keyspaceID)
if err != nil {
return reverseIds, err
}
reverseIds = append(reverseIds, sqltypes.NewUint64(val))
}
return reverseIds, nil
} | [
"func",
"(",
"vind",
"*",
"ReverseBits",
")",
"ReverseMap",
"(",
"_",
"VCursor",
",",
"ksids",
"[",
"]",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"sqltypes",
".",
"Value",
",",
"error",
")",
"{",
"reverseIds",
":=",
"make",
"(",
"[",
"]",
"sqltypes",
".",
"Value",
",",
"0",
",",
"len",
"(",
"ksids",
")",
")",
"\n",
"for",
"_",
",",
"keyspaceID",
":=",
"range",
"ksids",
"{",
"val",
",",
"err",
":=",
"unreverse",
"(",
"keyspaceID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"reverseIds",
",",
"err",
"\n",
"}",
"\n",
"reverseIds",
"=",
"append",
"(",
"reverseIds",
",",
"sqltypes",
".",
"NewUint64",
"(",
"val",
")",
")",
"\n",
"}",
"\n",
"return",
"reverseIds",
",",
"nil",
"\n",
"}"
] | // ReverseMap returns the ids from ksids. | [
"ReverseMap",
"returns",
"the",
"ids",
"from",
"ksids",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/reverse_bits.go#L95-L105 | train |
vitessio/vitess | go/stats/multidimensional.go | CounterForDimension | func CounterForDimension(mt MultiTracker, dimension string) CountTracker {
for i, lab := range mt.Labels() {
if lab == dimension {
return wrappedCountTracker{
f: func() map[string]int64 {
result := make(map[string]int64)
for k, v := range mt.Counts() {
if k == "All" {
result[k] = v
continue
}
result[strings.Split(k, ".")[i]] += v
}
return result
},
}
}
}
panic(fmt.Sprintf("label %v is not one of %v", dimension, mt.Labels()))
} | go | func CounterForDimension(mt MultiTracker, dimension string) CountTracker {
for i, lab := range mt.Labels() {
if lab == dimension {
return wrappedCountTracker{
f: func() map[string]int64 {
result := make(map[string]int64)
for k, v := range mt.Counts() {
if k == "All" {
result[k] = v
continue
}
result[strings.Split(k, ".")[i]] += v
}
return result
},
}
}
}
panic(fmt.Sprintf("label %v is not one of %v", dimension, mt.Labels()))
} | [
"func",
"CounterForDimension",
"(",
"mt",
"MultiTracker",
",",
"dimension",
"string",
")",
"CountTracker",
"{",
"for",
"i",
",",
"lab",
":=",
"range",
"mt",
".",
"Labels",
"(",
")",
"{",
"if",
"lab",
"==",
"dimension",
"{",
"return",
"wrappedCountTracker",
"{",
"f",
":",
"func",
"(",
")",
"map",
"[",
"string",
"]",
"int64",
"{",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int64",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"mt",
".",
"Counts",
"(",
")",
"{",
"if",
"k",
"==",
"\"",
"\"",
"{",
"result",
"[",
"k",
"]",
"=",
"v",
"\n",
"continue",
"\n",
"}",
"\n",
"result",
"[",
"strings",
".",
"Split",
"(",
"k",
",",
"\"",
"\"",
")",
"[",
"i",
"]",
"]",
"+=",
"v",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}",
",",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"dimension",
",",
"mt",
".",
"Labels",
"(",
")",
")",
")",
"\n",
"}"
] | // CounterForDimension returns a CountTracker for the provided
// dimension. It will panic if the dimension isn't a legal label for
// mt. | [
"CounterForDimension",
"returns",
"a",
"CountTracker",
"for",
"the",
"provided",
"dimension",
".",
"It",
"will",
"panic",
"if",
"the",
"dimension",
"isn",
"t",
"a",
"legal",
"label",
"for",
"mt",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/stats/multidimensional.go#L34-L54 | train |
vitessio/vitess | go/vt/vtctld/tablet_stats_cache.go | StatsUpdate | func (c *tabletStatsCache) StatsUpdate(stats *discovery.TabletStats) {
c.mu.Lock()
defer c.mu.Unlock()
keyspace := stats.Tablet.Keyspace
shard := stats.Tablet.Shard
cell := stats.Tablet.Alias.Cell
tabletType := stats.Tablet.Type
aliasKey := tabletToMapKey(stats)
ts, ok := c.statusesByAlias[aliasKey]
if !stats.Up {
if !ok {
// Tablet doesn't exist and was recently deleted or changed its type. Panic as this is unexpected behavior.
panic(fmt.Sprintf("BUG: tablet (%v) doesn't exist", aliasKey))
}
// The tablet still exists in our cache but was recently deleted or changed its type. Delete it now.
c.statuses[keyspace][shard][cell][tabletType] = remove(c.statuses[keyspace][shard][cell][tabletType], stats.Tablet.Alias)
delete(c.statusesByAlias, aliasKey)
return
}
if !ok {
// Tablet isn't tracked yet so just add it.
_, ok := c.statuses[keyspace]
if !ok {
shards := make(map[string]map[string]map[topodatapb.TabletType][]*discovery.TabletStats)
c.statuses[keyspace] = shards
}
_, ok = c.statuses[keyspace][shard]
if !ok {
cells := make(map[string]map[topodatapb.TabletType][]*discovery.TabletStats)
c.statuses[keyspace][shard] = cells
}
_, ok = c.statuses[keyspace][shard][cell]
if !ok {
types := make(map[topodatapb.TabletType][]*discovery.TabletStats)
c.statuses[keyspace][shard][cell] = types
}
_, ok = c.statuses[keyspace][shard][cell][tabletType]
if !ok {
tablets := make([]*discovery.TabletStats, 0)
c.statuses[keyspace][shard][cell][tabletType] = tablets
}
c.statuses[keyspace][shard][cell][tabletType] = append(c.statuses[keyspace][shard][cell][tabletType], stats)
sort.Sort(byTabletUID(c.statuses[keyspace][shard][cell][tabletType]))
c.statusesByAlias[aliasKey] = stats
return
}
// Tablet already exists so just update it in the cache.
*ts = *stats
} | go | func (c *tabletStatsCache) StatsUpdate(stats *discovery.TabletStats) {
c.mu.Lock()
defer c.mu.Unlock()
keyspace := stats.Tablet.Keyspace
shard := stats.Tablet.Shard
cell := stats.Tablet.Alias.Cell
tabletType := stats.Tablet.Type
aliasKey := tabletToMapKey(stats)
ts, ok := c.statusesByAlias[aliasKey]
if !stats.Up {
if !ok {
// Tablet doesn't exist and was recently deleted or changed its type. Panic as this is unexpected behavior.
panic(fmt.Sprintf("BUG: tablet (%v) doesn't exist", aliasKey))
}
// The tablet still exists in our cache but was recently deleted or changed its type. Delete it now.
c.statuses[keyspace][shard][cell][tabletType] = remove(c.statuses[keyspace][shard][cell][tabletType], stats.Tablet.Alias)
delete(c.statusesByAlias, aliasKey)
return
}
if !ok {
// Tablet isn't tracked yet so just add it.
_, ok := c.statuses[keyspace]
if !ok {
shards := make(map[string]map[string]map[topodatapb.TabletType][]*discovery.TabletStats)
c.statuses[keyspace] = shards
}
_, ok = c.statuses[keyspace][shard]
if !ok {
cells := make(map[string]map[topodatapb.TabletType][]*discovery.TabletStats)
c.statuses[keyspace][shard] = cells
}
_, ok = c.statuses[keyspace][shard][cell]
if !ok {
types := make(map[topodatapb.TabletType][]*discovery.TabletStats)
c.statuses[keyspace][shard][cell] = types
}
_, ok = c.statuses[keyspace][shard][cell][tabletType]
if !ok {
tablets := make([]*discovery.TabletStats, 0)
c.statuses[keyspace][shard][cell][tabletType] = tablets
}
c.statuses[keyspace][shard][cell][tabletType] = append(c.statuses[keyspace][shard][cell][tabletType], stats)
sort.Sort(byTabletUID(c.statuses[keyspace][shard][cell][tabletType]))
c.statusesByAlias[aliasKey] = stats
return
}
// Tablet already exists so just update it in the cache.
*ts = *stats
} | [
"func",
"(",
"c",
"*",
"tabletStatsCache",
")",
"StatsUpdate",
"(",
"stats",
"*",
"discovery",
".",
"TabletStats",
")",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"keyspace",
":=",
"stats",
".",
"Tablet",
".",
"Keyspace",
"\n",
"shard",
":=",
"stats",
".",
"Tablet",
".",
"Shard",
"\n",
"cell",
":=",
"stats",
".",
"Tablet",
".",
"Alias",
".",
"Cell",
"\n",
"tabletType",
":=",
"stats",
".",
"Tablet",
".",
"Type",
"\n\n",
"aliasKey",
":=",
"tabletToMapKey",
"(",
"stats",
")",
"\n",
"ts",
",",
"ok",
":=",
"c",
".",
"statusesByAlias",
"[",
"aliasKey",
"]",
"\n",
"if",
"!",
"stats",
".",
"Up",
"{",
"if",
"!",
"ok",
"{",
"// Tablet doesn't exist and was recently deleted or changed its type. Panic as this is unexpected behavior.",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"aliasKey",
")",
")",
"\n",
"}",
"\n",
"// The tablet still exists in our cache but was recently deleted or changed its type. Delete it now.",
"c",
".",
"statuses",
"[",
"keyspace",
"]",
"[",
"shard",
"]",
"[",
"cell",
"]",
"[",
"tabletType",
"]",
"=",
"remove",
"(",
"c",
".",
"statuses",
"[",
"keyspace",
"]",
"[",
"shard",
"]",
"[",
"cell",
"]",
"[",
"tabletType",
"]",
",",
"stats",
".",
"Tablet",
".",
"Alias",
")",
"\n",
"delete",
"(",
"c",
".",
"statusesByAlias",
",",
"aliasKey",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"!",
"ok",
"{",
"// Tablet isn't tracked yet so just add it.",
"_",
",",
"ok",
":=",
"c",
".",
"statuses",
"[",
"keyspace",
"]",
"\n",
"if",
"!",
"ok",
"{",
"shards",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"map",
"[",
"topodatapb",
".",
"TabletType",
"]",
"[",
"]",
"*",
"discovery",
".",
"TabletStats",
")",
"\n",
"c",
".",
"statuses",
"[",
"keyspace",
"]",
"=",
"shards",
"\n",
"}",
"\n\n",
"_",
",",
"ok",
"=",
"c",
".",
"statuses",
"[",
"keyspace",
"]",
"[",
"shard",
"]",
"\n",
"if",
"!",
"ok",
"{",
"cells",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"topodatapb",
".",
"TabletType",
"]",
"[",
"]",
"*",
"discovery",
".",
"TabletStats",
")",
"\n",
"c",
".",
"statuses",
"[",
"keyspace",
"]",
"[",
"shard",
"]",
"=",
"cells",
"\n",
"}",
"\n\n",
"_",
",",
"ok",
"=",
"c",
".",
"statuses",
"[",
"keyspace",
"]",
"[",
"shard",
"]",
"[",
"cell",
"]",
"\n",
"if",
"!",
"ok",
"{",
"types",
":=",
"make",
"(",
"map",
"[",
"topodatapb",
".",
"TabletType",
"]",
"[",
"]",
"*",
"discovery",
".",
"TabletStats",
")",
"\n",
"c",
".",
"statuses",
"[",
"keyspace",
"]",
"[",
"shard",
"]",
"[",
"cell",
"]",
"=",
"types",
"\n",
"}",
"\n\n",
"_",
",",
"ok",
"=",
"c",
".",
"statuses",
"[",
"keyspace",
"]",
"[",
"shard",
"]",
"[",
"cell",
"]",
"[",
"tabletType",
"]",
"\n",
"if",
"!",
"ok",
"{",
"tablets",
":=",
"make",
"(",
"[",
"]",
"*",
"discovery",
".",
"TabletStats",
",",
"0",
")",
"\n",
"c",
".",
"statuses",
"[",
"keyspace",
"]",
"[",
"shard",
"]",
"[",
"cell",
"]",
"[",
"tabletType",
"]",
"=",
"tablets",
"\n",
"}",
"\n\n",
"c",
".",
"statuses",
"[",
"keyspace",
"]",
"[",
"shard",
"]",
"[",
"cell",
"]",
"[",
"tabletType",
"]",
"=",
"append",
"(",
"c",
".",
"statuses",
"[",
"keyspace",
"]",
"[",
"shard",
"]",
"[",
"cell",
"]",
"[",
"tabletType",
"]",
",",
"stats",
")",
"\n",
"sort",
".",
"Sort",
"(",
"byTabletUID",
"(",
"c",
".",
"statuses",
"[",
"keyspace",
"]",
"[",
"shard",
"]",
"[",
"cell",
"]",
"[",
"tabletType",
"]",
")",
")",
"\n",
"c",
".",
"statusesByAlias",
"[",
"aliasKey",
"]",
"=",
"stats",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Tablet already exists so just update it in the cache.",
"*",
"ts",
"=",
"*",
"stats",
"\n",
"}"
] | // StatsUpdate is part of the discovery.HealthCheckStatsListener interface.
// Upon receiving a new TabletStats, it updates the two maps in tablet_stats_cache. | [
"StatsUpdate",
"is",
"part",
"of",
"the",
"discovery",
".",
"HealthCheckStatsListener",
"interface",
".",
"Upon",
"receiving",
"a",
"new",
"TabletStats",
"it",
"updates",
"the",
"two",
"maps",
"in",
"tablet_stats_cache",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtctld/tablet_stats_cache.go#L110-L166 | train |
vitessio/vitess | go/vt/vtctld/tablet_stats_cache.go | keyspacesLocked | func (c *tabletStatsCache) keyspacesLocked(keyspace string) []string {
if keyspace != "all" {
return []string{keyspace}
}
var keyspaces []string
for ks := range c.statuses {
keyspaces = append(keyspaces, ks)
}
sort.Strings(keyspaces)
return keyspaces
} | go | func (c *tabletStatsCache) keyspacesLocked(keyspace string) []string {
if keyspace != "all" {
return []string{keyspace}
}
var keyspaces []string
for ks := range c.statuses {
keyspaces = append(keyspaces, ks)
}
sort.Strings(keyspaces)
return keyspaces
} | [
"func",
"(",
"c",
"*",
"tabletStatsCache",
")",
"keyspacesLocked",
"(",
"keyspace",
"string",
")",
"[",
"]",
"string",
"{",
"if",
"keyspace",
"!=",
"\"",
"\"",
"{",
"return",
"[",
"]",
"string",
"{",
"keyspace",
"}",
"\n",
"}",
"\n",
"var",
"keyspaces",
"[",
"]",
"string",
"\n",
"for",
"ks",
":=",
"range",
"c",
".",
"statuses",
"{",
"keyspaces",
"=",
"append",
"(",
"keyspaces",
",",
"ks",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"keyspaces",
")",
"\n",
"return",
"keyspaces",
"\n",
"}"
] | // keyspacesLocked returns the keyspaces to be displayed in the heatmap based on the dropdown filters.
// It returns one keyspace if a specific one was chosen or returns all of them if 'all' is chosen.
// This method is used by heatmapData to traverse over desired keyspaces and
// topologyInfo to send all available options for the keyspace dropdown. | [
"keyspacesLocked",
"returns",
"the",
"keyspaces",
"to",
"be",
"displayed",
"in",
"the",
"heatmap",
"based",
"on",
"the",
"dropdown",
"filters",
".",
"It",
"returns",
"one",
"keyspace",
"if",
"a",
"specific",
"one",
"was",
"chosen",
"or",
"returns",
"all",
"of",
"them",
"if",
"all",
"is",
"chosen",
".",
"This",
"method",
"is",
"used",
"by",
"heatmapData",
"to",
"traverse",
"over",
"desired",
"keyspaces",
"and",
"topologyInfo",
"to",
"send",
"all",
"available",
"options",
"for",
"the",
"keyspace",
"dropdown",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtctld/tablet_stats_cache.go#L207-L217 | train |
vitessio/vitess | go/vt/vtctld/tablet_stats_cache.go | cellsLocked | func (c *tabletStatsCache) cellsLocked(keyspace, cell string) []string {
if cell != "all" {
return []string{cell}
}
return c.cellsInTopology(keyspace)
} | go | func (c *tabletStatsCache) cellsLocked(keyspace, cell string) []string {
if cell != "all" {
return []string{cell}
}
return c.cellsInTopology(keyspace)
} | [
"func",
"(",
"c",
"*",
"tabletStatsCache",
")",
"cellsLocked",
"(",
"keyspace",
",",
"cell",
"string",
")",
"[",
"]",
"string",
"{",
"if",
"cell",
"!=",
"\"",
"\"",
"{",
"return",
"[",
"]",
"string",
"{",
"cell",
"}",
"\n",
"}",
"\n",
"return",
"c",
".",
"cellsInTopology",
"(",
"keyspace",
")",
"\n",
"}"
] | // cellsLocked returns the cells needed to be displayed in the heatmap based on the dropdown filters.
// returns one cell if a specific one was chosen or returns all of them if 'all' is chosen.
// This method is used by heatmapData to traverse over the desired cells. | [
"cellsLocked",
"returns",
"the",
"cells",
"needed",
"to",
"be",
"displayed",
"in",
"the",
"heatmap",
"based",
"on",
"the",
"dropdown",
"filters",
".",
"returns",
"one",
"cell",
"if",
"a",
"specific",
"one",
"was",
"chosen",
"or",
"returns",
"all",
"of",
"them",
"if",
"all",
"is",
"chosen",
".",
"This",
"method",
"is",
"used",
"by",
"heatmapData",
"to",
"traverse",
"over",
"the",
"desired",
"cells",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtctld/tablet_stats_cache.go#L222-L227 | train |
vitessio/vitess | go/vt/vtctld/tablet_stats_cache.go | cellsInTopology | func (c *tabletStatsCache) cellsInTopology(keyspace string) []string {
keyspaces := c.keyspacesLocked(keyspace)
cells := make(map[string]bool)
// Going through all shards in each keyspace to get all existing cells
for _, ks := range keyspaces {
shardsPerKeyspace := c.statuses[ks]
for s := range shardsPerKeyspace {
cellsInKeyspace := c.statuses[ks][s]
for cl := range cellsInKeyspace {
cells[cl] = true
}
}
}
var cellList []string
for cell := range cells {
cellList = append(cellList, cell)
}
sort.Strings(cellList)
return cellList
} | go | func (c *tabletStatsCache) cellsInTopology(keyspace string) []string {
keyspaces := c.keyspacesLocked(keyspace)
cells := make(map[string]bool)
// Going through all shards in each keyspace to get all existing cells
for _, ks := range keyspaces {
shardsPerKeyspace := c.statuses[ks]
for s := range shardsPerKeyspace {
cellsInKeyspace := c.statuses[ks][s]
for cl := range cellsInKeyspace {
cells[cl] = true
}
}
}
var cellList []string
for cell := range cells {
cellList = append(cellList, cell)
}
sort.Strings(cellList)
return cellList
} | [
"func",
"(",
"c",
"*",
"tabletStatsCache",
")",
"cellsInTopology",
"(",
"keyspace",
"string",
")",
"[",
"]",
"string",
"{",
"keyspaces",
":=",
"c",
".",
"keyspacesLocked",
"(",
"keyspace",
")",
"\n",
"cells",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"// Going through all shards in each keyspace to get all existing cells",
"for",
"_",
",",
"ks",
":=",
"range",
"keyspaces",
"{",
"shardsPerKeyspace",
":=",
"c",
".",
"statuses",
"[",
"ks",
"]",
"\n",
"for",
"s",
":=",
"range",
"shardsPerKeyspace",
"{",
"cellsInKeyspace",
":=",
"c",
".",
"statuses",
"[",
"ks",
"]",
"[",
"s",
"]",
"\n",
"for",
"cl",
":=",
"range",
"cellsInKeyspace",
"{",
"cells",
"[",
"cl",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"var",
"cellList",
"[",
"]",
"string",
"\n",
"for",
"cell",
":=",
"range",
"cells",
"{",
"cellList",
"=",
"append",
"(",
"cellList",
",",
"cell",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"cellList",
")",
"\n",
"return",
"cellList",
"\n",
"}"
] | // cellsInTopology returns all the cells in the given keyspace.
// If all keyspaces is chosen, it returns the cells from every keyspace.
// This method is used by topologyInfo to send all available options for the cell dropdown | [
"cellsInTopology",
"returns",
"all",
"the",
"cells",
"in",
"the",
"given",
"keyspace",
".",
"If",
"all",
"keyspaces",
"is",
"chosen",
"it",
"returns",
"the",
"cells",
"from",
"every",
"keyspace",
".",
"This",
"method",
"is",
"used",
"by",
"topologyInfo",
"to",
"send",
"all",
"available",
"options",
"for",
"the",
"cell",
"dropdown"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtctld/tablet_stats_cache.go#L243-L262 | train |
vitessio/vitess | go/vt/vtctld/tablet_stats_cache.go | typesInTopology | func (c *tabletStatsCache) typesInTopology(keyspace, cell string) []topodatapb.TabletType {
keyspaces := c.keyspacesLocked(keyspace)
types := make(map[topodatapb.TabletType]bool)
// Going through the shards in every cell in every keyspace to get existing tablet types
for _, ks := range keyspaces {
cellsPerKeyspace := c.cellsLocked(ks, cell)
for _, cl := range cellsPerKeyspace {
shardsPerKeyspace := c.statuses[ks]
for s := range shardsPerKeyspace {
typesPerShard := c.statuses[ks][s][cl]
for t := range typesPerShard {
types[t] = true
if len(types) == len(availableTabletTypes) {
break
}
}
}
}
}
typesList := sortTypes(types)
return typesList
} | go | func (c *tabletStatsCache) typesInTopology(keyspace, cell string) []topodatapb.TabletType {
keyspaces := c.keyspacesLocked(keyspace)
types := make(map[topodatapb.TabletType]bool)
// Going through the shards in every cell in every keyspace to get existing tablet types
for _, ks := range keyspaces {
cellsPerKeyspace := c.cellsLocked(ks, cell)
for _, cl := range cellsPerKeyspace {
shardsPerKeyspace := c.statuses[ks]
for s := range shardsPerKeyspace {
typesPerShard := c.statuses[ks][s][cl]
for t := range typesPerShard {
types[t] = true
if len(types) == len(availableTabletTypes) {
break
}
}
}
}
}
typesList := sortTypes(types)
return typesList
} | [
"func",
"(",
"c",
"*",
"tabletStatsCache",
")",
"typesInTopology",
"(",
"keyspace",
",",
"cell",
"string",
")",
"[",
"]",
"topodatapb",
".",
"TabletType",
"{",
"keyspaces",
":=",
"c",
".",
"keyspacesLocked",
"(",
"keyspace",
")",
"\n",
"types",
":=",
"make",
"(",
"map",
"[",
"topodatapb",
".",
"TabletType",
"]",
"bool",
")",
"\n",
"// Going through the shards in every cell in every keyspace to get existing tablet types",
"for",
"_",
",",
"ks",
":=",
"range",
"keyspaces",
"{",
"cellsPerKeyspace",
":=",
"c",
".",
"cellsLocked",
"(",
"ks",
",",
"cell",
")",
"\n",
"for",
"_",
",",
"cl",
":=",
"range",
"cellsPerKeyspace",
"{",
"shardsPerKeyspace",
":=",
"c",
".",
"statuses",
"[",
"ks",
"]",
"\n",
"for",
"s",
":=",
"range",
"shardsPerKeyspace",
"{",
"typesPerShard",
":=",
"c",
".",
"statuses",
"[",
"ks",
"]",
"[",
"s",
"]",
"[",
"cl",
"]",
"\n",
"for",
"t",
":=",
"range",
"typesPerShard",
"{",
"types",
"[",
"t",
"]",
"=",
"true",
"\n",
"if",
"len",
"(",
"types",
")",
"==",
"len",
"(",
"availableTabletTypes",
")",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"typesList",
":=",
"sortTypes",
"(",
"types",
")",
"\n",
"return",
"typesList",
"\n",
"}"
] | // typesInTopology returns all the types in the given keyspace and cell.
// If all keyspaces and cells is chosen, it returns the types from every cell in every keyspace.
// This method is used by topologyInfo to send all available options for the tablet type dropdown | [
"typesInTopology",
"returns",
"all",
"the",
"types",
"in",
"the",
"given",
"keyspace",
"and",
"cell",
".",
"If",
"all",
"keyspaces",
"and",
"cells",
"is",
"chosen",
"it",
"returns",
"the",
"types",
"from",
"every",
"cell",
"in",
"every",
"keyspace",
".",
"This",
"method",
"is",
"used",
"by",
"topologyInfo",
"to",
"send",
"all",
"available",
"options",
"for",
"the",
"tablet",
"type",
"dropdown"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtctld/tablet_stats_cache.go#L267-L288 | train |
vitessio/vitess | go/vt/logutil/logger.go | EventToBuffer | func EventToBuffer(event *logutilpb.Event, buf *bytes.Buffer) {
// Avoid Fprintf, for speed. The format is so simple that we
// can do it quickly by hand. It's worth about 3X. Fprintf is hard.
// Lmmdd hh:mm:ss.uuuuuu file:line]
switch event.Level {
case logutilpb.Level_INFO:
buf.WriteByte('I')
case logutilpb.Level_WARNING:
buf.WriteByte('W')
case logutilpb.Level_ERROR:
buf.WriteByte('E')
case logutilpb.Level_CONSOLE:
buf.WriteString(event.Value)
return
}
t := ProtoToTime(event.Time)
_, month, day := t.Date()
hour, minute, second := t.Clock()
twoDigits(buf, int(month))
twoDigits(buf, day)
buf.WriteByte(' ')
twoDigits(buf, hour)
buf.WriteByte(':')
twoDigits(buf, minute)
buf.WriteByte(':')
twoDigits(buf, second)
buf.WriteByte('.')
nDigits(buf, 6, t.Nanosecond()/1000, '0')
buf.WriteByte(' ')
buf.WriteString(event.File)
buf.WriteByte(':')
someDigits(buf, event.Line)
buf.WriteByte(']')
buf.WriteByte(' ')
buf.WriteString(event.Value)
} | go | func EventToBuffer(event *logutilpb.Event, buf *bytes.Buffer) {
// Avoid Fprintf, for speed. The format is so simple that we
// can do it quickly by hand. It's worth about 3X. Fprintf is hard.
// Lmmdd hh:mm:ss.uuuuuu file:line]
switch event.Level {
case logutilpb.Level_INFO:
buf.WriteByte('I')
case logutilpb.Level_WARNING:
buf.WriteByte('W')
case logutilpb.Level_ERROR:
buf.WriteByte('E')
case logutilpb.Level_CONSOLE:
buf.WriteString(event.Value)
return
}
t := ProtoToTime(event.Time)
_, month, day := t.Date()
hour, minute, second := t.Clock()
twoDigits(buf, int(month))
twoDigits(buf, day)
buf.WriteByte(' ')
twoDigits(buf, hour)
buf.WriteByte(':')
twoDigits(buf, minute)
buf.WriteByte(':')
twoDigits(buf, second)
buf.WriteByte('.')
nDigits(buf, 6, t.Nanosecond()/1000, '0')
buf.WriteByte(' ')
buf.WriteString(event.File)
buf.WriteByte(':')
someDigits(buf, event.Line)
buf.WriteByte(']')
buf.WriteByte(' ')
buf.WriteString(event.Value)
} | [
"func",
"EventToBuffer",
"(",
"event",
"*",
"logutilpb",
".",
"Event",
",",
"buf",
"*",
"bytes",
".",
"Buffer",
")",
"{",
"// Avoid Fprintf, for speed. The format is so simple that we",
"// can do it quickly by hand. It's worth about 3X. Fprintf is hard.",
"// Lmmdd hh:mm:ss.uuuuuu file:line]",
"switch",
"event",
".",
"Level",
"{",
"case",
"logutilpb",
".",
"Level_INFO",
":",
"buf",
".",
"WriteByte",
"(",
"'I'",
")",
"\n",
"case",
"logutilpb",
".",
"Level_WARNING",
":",
"buf",
".",
"WriteByte",
"(",
"'W'",
")",
"\n",
"case",
"logutilpb",
".",
"Level_ERROR",
":",
"buf",
".",
"WriteByte",
"(",
"'E'",
")",
"\n",
"case",
"logutilpb",
".",
"Level_CONSOLE",
":",
"buf",
".",
"WriteString",
"(",
"event",
".",
"Value",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"t",
":=",
"ProtoToTime",
"(",
"event",
".",
"Time",
")",
"\n",
"_",
",",
"month",
",",
"day",
":=",
"t",
".",
"Date",
"(",
")",
"\n",
"hour",
",",
"minute",
",",
"second",
":=",
"t",
".",
"Clock",
"(",
")",
"\n",
"twoDigits",
"(",
"buf",
",",
"int",
"(",
"month",
")",
")",
"\n",
"twoDigits",
"(",
"buf",
",",
"day",
")",
"\n",
"buf",
".",
"WriteByte",
"(",
"' '",
")",
"\n",
"twoDigits",
"(",
"buf",
",",
"hour",
")",
"\n",
"buf",
".",
"WriteByte",
"(",
"':'",
")",
"\n",
"twoDigits",
"(",
"buf",
",",
"minute",
")",
"\n",
"buf",
".",
"WriteByte",
"(",
"':'",
")",
"\n",
"twoDigits",
"(",
"buf",
",",
"second",
")",
"\n",
"buf",
".",
"WriteByte",
"(",
"'.'",
")",
"\n",
"nDigits",
"(",
"buf",
",",
"6",
",",
"t",
".",
"Nanosecond",
"(",
")",
"/",
"1000",
",",
"'0'",
")",
"\n",
"buf",
".",
"WriteByte",
"(",
"' '",
")",
"\n",
"buf",
".",
"WriteString",
"(",
"event",
".",
"File",
")",
"\n",
"buf",
".",
"WriteByte",
"(",
"':'",
")",
"\n",
"someDigits",
"(",
"buf",
",",
"event",
".",
"Line",
")",
"\n",
"buf",
".",
"WriteByte",
"(",
"']'",
")",
"\n",
"buf",
".",
"WriteByte",
"(",
"' '",
")",
"\n",
"buf",
".",
"WriteString",
"(",
"event",
".",
"Value",
")",
"\n",
"}"
] | // EventToBuffer formats an individual Event into a buffer, without the
// final '\n' | [
"EventToBuffer",
"formats",
"an",
"individual",
"Event",
"into",
"a",
"buffer",
"without",
"the",
"final",
"\\",
"n"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L59-L96 | train |
vitessio/vitess | go/vt/logutil/logger.go | EventString | func EventString(event *logutilpb.Event) string {
buf := new(bytes.Buffer)
EventToBuffer(event, buf)
return buf.String()
} | go | func EventString(event *logutilpb.Event) string {
buf := new(bytes.Buffer)
EventToBuffer(event, buf)
return buf.String()
} | [
"func",
"EventString",
"(",
"event",
"*",
"logutilpb",
".",
"Event",
")",
"string",
"{",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"EventToBuffer",
"(",
"event",
",",
"buf",
")",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}"
] | // EventString returns the line in one string | [
"EventString",
"returns",
"the",
"line",
"in",
"one",
"string"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L99-L103 | train |
vitessio/vitess | go/vt/logutil/logger.go | Warningf | func (cl *CallbackLogger) Warningf(format string, v ...interface{}) {
cl.WarningDepth(1, fmt.Sprintf(format, v...))
} | go | func (cl *CallbackLogger) Warningf(format string, v ...interface{}) {
cl.WarningDepth(1, fmt.Sprintf(format, v...))
} | [
"func",
"(",
"cl",
"*",
"CallbackLogger",
")",
"Warningf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"cl",
".",
"WarningDepth",
"(",
"1",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"v",
"...",
")",
")",
"\n",
"}"
] | // Warningf is part of the Logger interface. | [
"Warningf",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L178-L180 | train |
vitessio/vitess | go/vt/logutil/logger.go | Errorf | func (cl *CallbackLogger) Errorf(format string, v ...interface{}) {
cl.ErrorDepth(1, fmt.Sprintf(format, v...))
} | go | func (cl *CallbackLogger) Errorf(format string, v ...interface{}) {
cl.ErrorDepth(1, fmt.Sprintf(format, v...))
} | [
"func",
"(",
"cl",
"*",
"CallbackLogger",
")",
"Errorf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"cl",
".",
"ErrorDepth",
"(",
"1",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"v",
"...",
")",
")",
"\n",
"}"
] | // Errorf is part of the Logger interface. | [
"Errorf",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L183-L185 | train |
vitessio/vitess | go/vt/logutil/logger.go | Printf | func (cl *CallbackLogger) Printf(format string, v ...interface{}) {
file, line := fileAndLine(2)
cl.f(&logutilpb.Event{
Time: TimeToProto(time.Now()),
Level: logutilpb.Level_CONSOLE,
File: file,
Line: line,
Value: fmt.Sprintf(format, v...),
})
} | go | func (cl *CallbackLogger) Printf(format string, v ...interface{}) {
file, line := fileAndLine(2)
cl.f(&logutilpb.Event{
Time: TimeToProto(time.Now()),
Level: logutilpb.Level_CONSOLE,
File: file,
Line: line,
Value: fmt.Sprintf(format, v...),
})
} | [
"func",
"(",
"cl",
"*",
"CallbackLogger",
")",
"Printf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"file",
",",
"line",
":=",
"fileAndLine",
"(",
"2",
")",
"\n",
"cl",
".",
"f",
"(",
"&",
"logutilpb",
".",
"Event",
"{",
"Time",
":",
"TimeToProto",
"(",
"time",
".",
"Now",
"(",
")",
")",
",",
"Level",
":",
"logutilpb",
".",
"Level_CONSOLE",
",",
"File",
":",
"file",
",",
"Line",
":",
"line",
",",
"Value",
":",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"v",
"...",
")",
",",
"}",
")",
"\n",
"}"
] | // Printf is part of the Logger interface. | [
"Printf",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L198-L207 | train |
vitessio/vitess | go/vt/logutil/logger.go | NewChannelLogger | func NewChannelLogger(size int) *ChannelLogger {
c := make(chan *logutilpb.Event, size)
return &ChannelLogger{
CallbackLogger: CallbackLogger{
f: func(e *logutilpb.Event) {
c <- e
},
},
C: c,
}
} | go | func NewChannelLogger(size int) *ChannelLogger {
c := make(chan *logutilpb.Event, size)
return &ChannelLogger{
CallbackLogger: CallbackLogger{
f: func(e *logutilpb.Event) {
c <- e
},
},
C: c,
}
} | [
"func",
"NewChannelLogger",
"(",
"size",
"int",
")",
"*",
"ChannelLogger",
"{",
"c",
":=",
"make",
"(",
"chan",
"*",
"logutilpb",
".",
"Event",
",",
"size",
")",
"\n",
"return",
"&",
"ChannelLogger",
"{",
"CallbackLogger",
":",
"CallbackLogger",
"{",
"f",
":",
"func",
"(",
"e",
"*",
"logutilpb",
".",
"Event",
")",
"{",
"c",
"<-",
"e",
"\n",
"}",
",",
"}",
",",
"C",
":",
"c",
",",
"}",
"\n",
"}"
] | // NewChannelLogger returns a CallbackLogger which will write the data
// on a channel | [
"NewChannelLogger",
"returns",
"a",
"CallbackLogger",
"which",
"will",
"write",
"the",
"data",
"on",
"a",
"channel"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L218-L228 | train |
vitessio/vitess | go/vt/logutil/logger.go | NewMemoryLogger | func NewMemoryLogger() *MemoryLogger {
ml := &MemoryLogger{}
ml.CallbackLogger.f = func(e *logutilpb.Event) {
ml.mu.Lock()
defer ml.mu.Unlock()
ml.Events = append(ml.Events, e)
}
return ml
} | go | func NewMemoryLogger() *MemoryLogger {
ml := &MemoryLogger{}
ml.CallbackLogger.f = func(e *logutilpb.Event) {
ml.mu.Lock()
defer ml.mu.Unlock()
ml.Events = append(ml.Events, e)
}
return ml
} | [
"func",
"NewMemoryLogger",
"(",
")",
"*",
"MemoryLogger",
"{",
"ml",
":=",
"&",
"MemoryLogger",
"{",
"}",
"\n",
"ml",
".",
"CallbackLogger",
".",
"f",
"=",
"func",
"(",
"e",
"*",
"logutilpb",
".",
"Event",
")",
"{",
"ml",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ml",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"ml",
".",
"Events",
"=",
"append",
"(",
"ml",
".",
"Events",
",",
"e",
")",
"\n",
"}",
"\n",
"return",
"ml",
"\n",
"}"
] | // NewMemoryLogger returns a new MemoryLogger | [
"NewMemoryLogger",
"returns",
"a",
"new",
"MemoryLogger"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L241-L249 | train |
vitessio/vitess | go/vt/logutil/logger.go | String | func (ml *MemoryLogger) String() string {
buf := new(bytes.Buffer)
ml.mu.Lock()
defer ml.mu.Unlock()
for _, event := range ml.Events {
EventToBuffer(event, buf)
buf.WriteByte('\n')
}
return buf.String()
} | go | func (ml *MemoryLogger) String() string {
buf := new(bytes.Buffer)
ml.mu.Lock()
defer ml.mu.Unlock()
for _, event := range ml.Events {
EventToBuffer(event, buf)
buf.WriteByte('\n')
}
return buf.String()
} | [
"func",
"(",
"ml",
"*",
"MemoryLogger",
")",
"String",
"(",
")",
"string",
"{",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"ml",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ml",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"event",
":=",
"range",
"ml",
".",
"Events",
"{",
"EventToBuffer",
"(",
"event",
",",
"buf",
")",
"\n",
"buf",
".",
"WriteByte",
"(",
"'\\n'",
")",
"\n",
"}",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}"
] | // String returns all the lines in one String, separated by '\n' | [
"String",
"returns",
"all",
"the",
"lines",
"in",
"one",
"String",
"separated",
"by",
"\\",
"n"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L252-L261 | train |
vitessio/vitess | go/vt/logutil/logger.go | Clear | func (ml *MemoryLogger) Clear() {
ml.mu.Lock()
ml.Events = nil
ml.mu.Unlock()
} | go | func (ml *MemoryLogger) Clear() {
ml.mu.Lock()
ml.Events = nil
ml.mu.Unlock()
} | [
"func",
"(",
"ml",
"*",
"MemoryLogger",
")",
"Clear",
"(",
")",
"{",
"ml",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"ml",
".",
"Events",
"=",
"nil",
"\n",
"ml",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // Clear clears the logs. | [
"Clear",
"clears",
"the",
"logs",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L264-L268 | train |
vitessio/vitess | go/vt/logutil/logger.go | NewTeeLogger | func NewTeeLogger(one, two Logger) *TeeLogger {
return &TeeLogger{
One: one,
Two: two,
}
} | go | func NewTeeLogger(one, two Logger) *TeeLogger {
return &TeeLogger{
One: one,
Two: two,
}
} | [
"func",
"NewTeeLogger",
"(",
"one",
",",
"two",
"Logger",
")",
"*",
"TeeLogger",
"{",
"return",
"&",
"TeeLogger",
"{",
"One",
":",
"one",
",",
"Two",
":",
"two",
",",
"}",
"\n",
"}"
] | // NewTeeLogger returns a logger that sends its logs to both loggers | [
"NewTeeLogger",
"returns",
"a",
"logger",
"that",
"sends",
"its",
"logs",
"to",
"both",
"loggers"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L297-L302 | train |
vitessio/vitess | go/vt/logutil/logger.go | InfoDepth | func (tl *TeeLogger) InfoDepth(depth int, s string) {
tl.One.InfoDepth(1+depth, s)
tl.Two.InfoDepth(1+depth, s)
} | go | func (tl *TeeLogger) InfoDepth(depth int, s string) {
tl.One.InfoDepth(1+depth, s)
tl.Two.InfoDepth(1+depth, s)
} | [
"func",
"(",
"tl",
"*",
"TeeLogger",
")",
"InfoDepth",
"(",
"depth",
"int",
",",
"s",
"string",
")",
"{",
"tl",
".",
"One",
".",
"InfoDepth",
"(",
"1",
"+",
"depth",
",",
"s",
")",
"\n",
"tl",
".",
"Two",
".",
"InfoDepth",
"(",
"1",
"+",
"depth",
",",
"s",
")",
"\n",
"}"
] | // InfoDepth is part of the Logger interface | [
"InfoDepth",
"is",
"part",
"of",
"the",
"Logger",
"interface"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L305-L308 | train |
vitessio/vitess | go/vt/logutil/logger.go | Warningf | func (tl *TeeLogger) Warningf(format string, v ...interface{}) {
tl.WarningDepth(1, fmt.Sprintf(format, v...))
} | go | func (tl *TeeLogger) Warningf(format string, v ...interface{}) {
tl.WarningDepth(1, fmt.Sprintf(format, v...))
} | [
"func",
"(",
"tl",
"*",
"TeeLogger",
")",
"Warningf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"tl",
".",
"WarningDepth",
"(",
"1",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"v",
"...",
")",
")",
"\n",
"}"
] | // Warningf is part of the Logger interface | [
"Warningf",
"is",
"part",
"of",
"the",
"Logger",
"interface"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L328-L330 | train |
vitessio/vitess | go/vt/logutil/logger.go | Errorf | func (tl *TeeLogger) Errorf(format string, v ...interface{}) {
tl.ErrorDepth(1, fmt.Sprintf(format, v...))
} | go | func (tl *TeeLogger) Errorf(format string, v ...interface{}) {
tl.ErrorDepth(1, fmt.Sprintf(format, v...))
} | [
"func",
"(",
"tl",
"*",
"TeeLogger",
")",
"Errorf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"tl",
".",
"ErrorDepth",
"(",
"1",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"v",
"...",
")",
")",
"\n",
"}"
] | // Errorf is part of the Logger interface | [
"Errorf",
"is",
"part",
"of",
"the",
"Logger",
"interface"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L333-L335 | train |
vitessio/vitess | go/vt/logutil/logger.go | twoDigits | func twoDigits(buf *bytes.Buffer, value int) {
buf.WriteByte(digits[value/10])
buf.WriteByte(digits[value%10])
} | go | func twoDigits(buf *bytes.Buffer, value int) {
buf.WriteByte(digits[value/10])
buf.WriteByte(digits[value%10])
} | [
"func",
"twoDigits",
"(",
"buf",
"*",
"bytes",
".",
"Buffer",
",",
"value",
"int",
")",
"{",
"buf",
".",
"WriteByte",
"(",
"digits",
"[",
"value",
"/",
"10",
"]",
")",
"\n",
"buf",
".",
"WriteByte",
"(",
"digits",
"[",
"value",
"%",
"10",
"]",
")",
"\n",
"}"
] | // twoDigits adds a zero-prefixed two-digit integer to buf | [
"twoDigits",
"adds",
"a",
"zero",
"-",
"prefixed",
"two",
"-",
"digit",
"integer",
"to",
"buf"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L357-L360 | train |
vitessio/vitess | go/vt/logutil/logger.go | nDigits | func nDigits(buf *bytes.Buffer, n, d int, pad byte) {
tmp := make([]byte, n)
j := n - 1
for ; j >= 0 && d > 0; j-- {
tmp[j] = digits[d%10]
d /= 10
}
for ; j >= 0; j-- {
tmp[j] = pad
}
buf.Write(tmp)
} | go | func nDigits(buf *bytes.Buffer, n, d int, pad byte) {
tmp := make([]byte, n)
j := n - 1
for ; j >= 0 && d > 0; j-- {
tmp[j] = digits[d%10]
d /= 10
}
for ; j >= 0; j-- {
tmp[j] = pad
}
buf.Write(tmp)
} | [
"func",
"nDigits",
"(",
"buf",
"*",
"bytes",
".",
"Buffer",
",",
"n",
",",
"d",
"int",
",",
"pad",
"byte",
")",
"{",
"tmp",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"n",
")",
"\n",
"j",
":=",
"n",
"-",
"1",
"\n",
"for",
";",
"j",
">=",
"0",
"&&",
"d",
">",
"0",
";",
"j",
"--",
"{",
"tmp",
"[",
"j",
"]",
"=",
"digits",
"[",
"d",
"%",
"10",
"]",
"\n",
"d",
"/=",
"10",
"\n",
"}",
"\n",
"for",
";",
"j",
">=",
"0",
";",
"j",
"--",
"{",
"tmp",
"[",
"j",
"]",
"=",
"pad",
"\n",
"}",
"\n",
"buf",
".",
"Write",
"(",
"tmp",
")",
"\n",
"}"
] | // nDigits adds an n-digit integer d to buf
// padding with pad on the left.
// It assumes d >= 0. | [
"nDigits",
"adds",
"an",
"n",
"-",
"digit",
"integer",
"d",
"to",
"buf",
"padding",
"with",
"pad",
"on",
"the",
"left",
".",
"It",
"assumes",
"d",
">",
"=",
"0",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L365-L376 | train |
vitessio/vitess | go/vt/logutil/logger.go | someDigits | func someDigits(buf *bytes.Buffer, d int64) {
// Print into the top, then copy down.
tmp := make([]byte, 10)
j := 10
for {
j--
tmp[j] = digits[d%10]
d /= 10
if d == 0 {
break
}
}
buf.Write(tmp[j:])
} | go | func someDigits(buf *bytes.Buffer, d int64) {
// Print into the top, then copy down.
tmp := make([]byte, 10)
j := 10
for {
j--
tmp[j] = digits[d%10]
d /= 10
if d == 0 {
break
}
}
buf.Write(tmp[j:])
} | [
"func",
"someDigits",
"(",
"buf",
"*",
"bytes",
".",
"Buffer",
",",
"d",
"int64",
")",
"{",
"// Print into the top, then copy down.",
"tmp",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"10",
")",
"\n",
"j",
":=",
"10",
"\n",
"for",
"{",
"j",
"--",
"\n",
"tmp",
"[",
"j",
"]",
"=",
"digits",
"[",
"d",
"%",
"10",
"]",
"\n",
"d",
"/=",
"10",
"\n",
"if",
"d",
"==",
"0",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"buf",
".",
"Write",
"(",
"tmp",
"[",
"j",
":",
"]",
")",
"\n",
"}"
] | // someDigits adds a zero-prefixed variable-width integer to buf | [
"someDigits",
"adds",
"a",
"zero",
"-",
"prefixed",
"variable",
"-",
"width",
"integer",
"to",
"buf"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L379-L392 | train |
vitessio/vitess | go/vt/logutil/logger.go | fileAndLine | func fileAndLine(depth int) (string, int64) {
_, file, line, ok := runtime.Caller(depth)
if !ok {
return "???", 1
}
slash := strings.LastIndex(file, "/")
if slash >= 0 {
file = file[slash+1:]
}
return file, int64(line)
} | go | func fileAndLine(depth int) (string, int64) {
_, file, line, ok := runtime.Caller(depth)
if !ok {
return "???", 1
}
slash := strings.LastIndex(file, "/")
if slash >= 0 {
file = file[slash+1:]
}
return file, int64(line)
} | [
"func",
"fileAndLine",
"(",
"depth",
"int",
")",
"(",
"string",
",",
"int64",
")",
"{",
"_",
",",
"file",
",",
"line",
",",
"ok",
":=",
"runtime",
".",
"Caller",
"(",
"depth",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
",",
"1",
"\n",
"}",
"\n\n",
"slash",
":=",
"strings",
".",
"LastIndex",
"(",
"file",
",",
"\"",
"\"",
")",
"\n",
"if",
"slash",
">=",
"0",
"{",
"file",
"=",
"file",
"[",
"slash",
"+",
"1",
":",
"]",
"\n",
"}",
"\n",
"return",
"file",
",",
"int64",
"(",
"line",
")",
"\n",
"}"
] | // fileAndLine returns the caller's file and line 2 levels above | [
"fileAndLine",
"returns",
"the",
"caller",
"s",
"file",
"and",
"line",
"2",
"levels",
"above"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/logger.go#L395-L406 | train |
vitessio/vitess | go/vt/discovery/replicationlag.go | IsReplicationLagHigh | func IsReplicationLagHigh(tabletStats *TabletStats) bool {
return float64(tabletStats.Stats.SecondsBehindMaster) > lowReplicationLag.Seconds()
} | go | func IsReplicationLagHigh(tabletStats *TabletStats) bool {
return float64(tabletStats.Stats.SecondsBehindMaster) > lowReplicationLag.Seconds()
} | [
"func",
"IsReplicationLagHigh",
"(",
"tabletStats",
"*",
"TabletStats",
")",
"bool",
"{",
"return",
"float64",
"(",
"tabletStats",
".",
"Stats",
".",
"SecondsBehindMaster",
")",
">",
"lowReplicationLag",
".",
"Seconds",
"(",
")",
"\n",
"}"
] | // IsReplicationLagHigh verifies that the given TabletStats refers to a tablet with high
// replication lag, i.e. higher than the configured discovery_low_replication_lag flag. | [
"IsReplicationLagHigh",
"verifies",
"that",
"the",
"given",
"TabletStats",
"refers",
"to",
"a",
"tablet",
"with",
"high",
"replication",
"lag",
"i",
".",
"e",
".",
"higher",
"than",
"the",
"configured",
"discovery_low_replication_lag",
"flag",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/discovery/replicationlag.go#L35-L37 | train |
vitessio/vitess | go/vt/discovery/replicationlag.go | IsReplicationLagVeryHigh | func IsReplicationLagVeryHigh(tabletStats *TabletStats) bool {
return float64(tabletStats.Stats.SecondsBehindMaster) > highReplicationLagMinServing.Seconds()
} | go | func IsReplicationLagVeryHigh(tabletStats *TabletStats) bool {
return float64(tabletStats.Stats.SecondsBehindMaster) > highReplicationLagMinServing.Seconds()
} | [
"func",
"IsReplicationLagVeryHigh",
"(",
"tabletStats",
"*",
"TabletStats",
")",
"bool",
"{",
"return",
"float64",
"(",
"tabletStats",
".",
"Stats",
".",
"SecondsBehindMaster",
")",
">",
"highReplicationLagMinServing",
".",
"Seconds",
"(",
")",
"\n",
"}"
] | // IsReplicationLagVeryHigh verifies that the given TabletStats refers to a tablet with very high
// replication lag, i.e. higher than the configured discovery_high_replication_lag_minimum_serving flag. | [
"IsReplicationLagVeryHigh",
"verifies",
"that",
"the",
"given",
"TabletStats",
"refers",
"to",
"a",
"tablet",
"with",
"very",
"high",
"replication",
"lag",
"i",
".",
"e",
".",
"higher",
"than",
"the",
"configured",
"discovery_high_replication_lag_minimum_serving",
"flag",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/discovery/replicationlag.go#L41-L43 | train |
vitessio/vitess | go/vt/discovery/replicationlag.go | mean | func mean(tabletStatsList []*TabletStats, idxExclude int) (uint64, error) {
var sum uint64
var count uint64
for i, ts := range tabletStatsList {
if i == idxExclude {
continue
}
sum = sum + uint64(ts.Stats.SecondsBehindMaster)
count++
}
if count == 0 {
return 0, fmt.Errorf("empty list")
}
return sum / count, nil
} | go | func mean(tabletStatsList []*TabletStats, idxExclude int) (uint64, error) {
var sum uint64
var count uint64
for i, ts := range tabletStatsList {
if i == idxExclude {
continue
}
sum = sum + uint64(ts.Stats.SecondsBehindMaster)
count++
}
if count == 0 {
return 0, fmt.Errorf("empty list")
}
return sum / count, nil
} | [
"func",
"mean",
"(",
"tabletStatsList",
"[",
"]",
"*",
"TabletStats",
",",
"idxExclude",
"int",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"var",
"sum",
"uint64",
"\n",
"var",
"count",
"uint64",
"\n",
"for",
"i",
",",
"ts",
":=",
"range",
"tabletStatsList",
"{",
"if",
"i",
"==",
"idxExclude",
"{",
"continue",
"\n",
"}",
"\n",
"sum",
"=",
"sum",
"+",
"uint64",
"(",
"ts",
".",
"Stats",
".",
"SecondsBehindMaster",
")",
"\n",
"count",
"++",
"\n",
"}",
"\n",
"if",
"count",
"==",
"0",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"sum",
"/",
"count",
",",
"nil",
"\n",
"}"
] | // mean calculates the mean value over the given list,
// while excluding the item with the specified index. | [
"mean",
"calculates",
"the",
"mean",
"value",
"over",
"the",
"given",
"list",
"while",
"excluding",
"the",
"item",
"with",
"the",
"specified",
"index",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/discovery/replicationlag.go#L163-L177 | train |
vitessio/vitess | go/vt/discovery/replicationlag.go | TrivialStatsUpdate | func TrivialStatsUpdate(o, n *TabletStats) bool {
// Skip replag filter when replag remains in the low rep lag range,
// which should be the case majority of the time.
lowRepLag := lowReplicationLag.Seconds()
oldRepLag := float64(o.Stats.SecondsBehindMaster)
newRepLag := float64(n.Stats.SecondsBehindMaster)
if oldRepLag <= lowRepLag && newRepLag <= lowRepLag {
return true
}
// Skip replag filter when replag remains in the high rep lag range,
// and did not change beyond +/- 10%.
// when there is a high rep lag, it takes a long time for it to reduce,
// so it is not necessary to re-calculate every time.
// In that case, we won't save the new record, so we still
// remember the original replication lag.
if oldRepLag > lowRepLag && newRepLag > lowRepLag && newRepLag < oldRepLag*1.1 && newRepLag > oldRepLag*0.9 {
return true
}
return false
} | go | func TrivialStatsUpdate(o, n *TabletStats) bool {
// Skip replag filter when replag remains in the low rep lag range,
// which should be the case majority of the time.
lowRepLag := lowReplicationLag.Seconds()
oldRepLag := float64(o.Stats.SecondsBehindMaster)
newRepLag := float64(n.Stats.SecondsBehindMaster)
if oldRepLag <= lowRepLag && newRepLag <= lowRepLag {
return true
}
// Skip replag filter when replag remains in the high rep lag range,
// and did not change beyond +/- 10%.
// when there is a high rep lag, it takes a long time for it to reduce,
// so it is not necessary to re-calculate every time.
// In that case, we won't save the new record, so we still
// remember the original replication lag.
if oldRepLag > lowRepLag && newRepLag > lowRepLag && newRepLag < oldRepLag*1.1 && newRepLag > oldRepLag*0.9 {
return true
}
return false
} | [
"func",
"TrivialStatsUpdate",
"(",
"o",
",",
"n",
"*",
"TabletStats",
")",
"bool",
"{",
"// Skip replag filter when replag remains in the low rep lag range,",
"// which should be the case majority of the time.",
"lowRepLag",
":=",
"lowReplicationLag",
".",
"Seconds",
"(",
")",
"\n",
"oldRepLag",
":=",
"float64",
"(",
"o",
".",
"Stats",
".",
"SecondsBehindMaster",
")",
"\n",
"newRepLag",
":=",
"float64",
"(",
"n",
".",
"Stats",
".",
"SecondsBehindMaster",
")",
"\n",
"if",
"oldRepLag",
"<=",
"lowRepLag",
"&&",
"newRepLag",
"<=",
"lowRepLag",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"// Skip replag filter when replag remains in the high rep lag range,",
"// and did not change beyond +/- 10%.",
"// when there is a high rep lag, it takes a long time for it to reduce,",
"// so it is not necessary to re-calculate every time.",
"// In that case, we won't save the new record, so we still",
"// remember the original replication lag.",
"if",
"oldRepLag",
">",
"lowRepLag",
"&&",
"newRepLag",
">",
"lowRepLag",
"&&",
"newRepLag",
"<",
"oldRepLag",
"*",
"1.1",
"&&",
"newRepLag",
">",
"oldRepLag",
"*",
"0.9",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // TrivialStatsUpdate returns true iff the old and new TabletStats
// haven't changed enough to warrant re-calling FilterByReplicationLag. | [
"TrivialStatsUpdate",
"returns",
"true",
"iff",
"the",
"old",
"and",
"new",
"TabletStats",
"haven",
"t",
"changed",
"enough",
"to",
"warrant",
"re",
"-",
"calling",
"FilterByReplicationLag",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/discovery/replicationlag.go#L181-L202 | train |
vitessio/vitess | go/vt/logutil/throttled.go | NewThrottledLogger | func NewThrottledLogger(name string, maxInterval time.Duration) *ThrottledLogger {
return &ThrottledLogger{
name: name,
maxInterval: maxInterval,
}
} | go | func NewThrottledLogger(name string, maxInterval time.Duration) *ThrottledLogger {
return &ThrottledLogger{
name: name,
maxInterval: maxInterval,
}
} | [
"func",
"NewThrottledLogger",
"(",
"name",
"string",
",",
"maxInterval",
"time",
".",
"Duration",
")",
"*",
"ThrottledLogger",
"{",
"return",
"&",
"ThrottledLogger",
"{",
"name",
":",
"name",
",",
"maxInterval",
":",
"maxInterval",
",",
"}",
"\n",
"}"
] | // NewThrottledLogger will create a ThrottledLogger with the given
// name and throttling interval. | [
"NewThrottledLogger",
"will",
"create",
"a",
"ThrottledLogger",
"with",
"the",
"given",
"name",
"and",
"throttling",
"interval",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/throttled.go#L42-L47 | train |
vitessio/vitess | go/vt/logutil/throttled.go | Infof | func (tl *ThrottledLogger) Infof(format string, v ...interface{}) {
tl.log(infoDepth, format, v...)
} | go | func (tl *ThrottledLogger) Infof(format string, v ...interface{}) {
tl.log(infoDepth, format, v...)
} | [
"func",
"(",
"tl",
"*",
"ThrottledLogger",
")",
"Infof",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"tl",
".",
"log",
"(",
"infoDepth",
",",
"format",
",",
"v",
"...",
")",
"\n",
"}"
] | // Infof logs an info if not throttled. | [
"Infof",
"logs",
"an",
"info",
"if",
"not",
"throttled",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/throttled.go#L85-L87 | train |
vitessio/vitess | go/vt/logutil/throttled.go | Warningf | func (tl *ThrottledLogger) Warningf(format string, v ...interface{}) {
tl.log(warningDepth, format, v...)
} | go | func (tl *ThrottledLogger) Warningf(format string, v ...interface{}) {
tl.log(warningDepth, format, v...)
} | [
"func",
"(",
"tl",
"*",
"ThrottledLogger",
")",
"Warningf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"tl",
".",
"log",
"(",
"warningDepth",
",",
"format",
",",
"v",
"...",
")",
"\n",
"}"
] | // Warningf logs a warning if not throttled. | [
"Warningf",
"logs",
"a",
"warning",
"if",
"not",
"throttled",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/throttled.go#L90-L92 | train |
vitessio/vitess | go/vt/logutil/throttled.go | Errorf | func (tl *ThrottledLogger) Errorf(format string, v ...interface{}) {
tl.log(errorDepth, format, v...)
} | go | func (tl *ThrottledLogger) Errorf(format string, v ...interface{}) {
tl.log(errorDepth, format, v...)
} | [
"func",
"(",
"tl",
"*",
"ThrottledLogger",
")",
"Errorf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"tl",
".",
"log",
"(",
"errorDepth",
",",
"format",
",",
"v",
"...",
")",
"\n",
"}"
] | // Errorf logs an error if not throttled. | [
"Errorf",
"logs",
"an",
"error",
"if",
"not",
"throttled",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/logutil/throttled.go#L95-L97 | train |
vitessio/vitess | go/vt/vtgate/vschema_manager.go | GetCurrentSrvVschema | func (vm *VSchemaManager) GetCurrentSrvVschema() *vschemapb.SrvVSchema {
vm.mu.Lock()
defer vm.mu.Unlock()
return proto.Clone(vm.currentSrvVschema).(*vschemapb.SrvVSchema)
} | go | func (vm *VSchemaManager) GetCurrentSrvVschema() *vschemapb.SrvVSchema {
vm.mu.Lock()
defer vm.mu.Unlock()
return proto.Clone(vm.currentSrvVschema).(*vschemapb.SrvVSchema)
} | [
"func",
"(",
"vm",
"*",
"VSchemaManager",
")",
"GetCurrentSrvVschema",
"(",
")",
"*",
"vschemapb",
".",
"SrvVSchema",
"{",
"vm",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"vm",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"proto",
".",
"Clone",
"(",
"vm",
".",
"currentSrvVschema",
")",
".",
"(",
"*",
"vschemapb",
".",
"SrvVSchema",
")",
"\n",
"}"
] | // GetCurrentSrvVschema returns a copy of the latest SrvVschema from the
// topo watch | [
"GetCurrentSrvVschema",
"returns",
"a",
"copy",
"of",
"the",
"latest",
"SrvVschema",
"from",
"the",
"topo",
"watch"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vschema_manager.go#L43-L47 | train |
vitessio/vitess | go/vt/vtgate/vschema_manager.go | watchSrvVSchema | func (vm *VSchemaManager) watchSrvVSchema(ctx context.Context, cell string) {
vm.e.serv.WatchSrvVSchema(ctx, cell, func(v *vschemapb.SrvVSchema, err error) {
// Create a closure to save the vschema. If the value
// passed is nil, it means we encountered an error and
// we don't know the real value. In this case, we want
// to use the previous value if it was set, or an
// empty vschema if it wasn't.
switch {
case err == nil:
// Good case, we can try to save that value.
case topo.IsErrType(err, topo.NoNode):
// If the SrvVschema disappears, we need to clear our record.
// Otherwise, keep what we already had before.
v = nil
default:
// Watch error, increment our counters.
if vschemaCounters != nil {
vschemaCounters.Add("WatchError", 1)
}
}
// keep a copy of the latest SrvVschema
vm.mu.Lock()
vm.currentSrvVschema = v
vm.mu.Unlock()
// Transform the provided SrvVSchema into a VSchema.
var vschema *vindexes.VSchema
if v != nil {
vschema, err = vindexes.BuildVSchema(v)
if err != nil {
log.Warningf("Error creating VSchema for cell %v (will try again next update): %v", cell, err)
err = fmt.Errorf("error creating VSchema for cell %v: %v", cell, err)
if vschemaCounters != nil {
vschemaCounters.Add("Parsing", 1)
}
}
}
if v == nil {
// We encountered an error, build an empty vschema.
vschema, _ = vindexes.BuildVSchema(&vschemapb.SrvVSchema{})
}
// Build the display version. At this point, three cases:
// - v is nil, vschema is empty, and err is set:
// 1. when the watch returned an error.
// 2. when BuildVSchema failed.
// - v is set, vschema is full, and err is nil:
// 3. when everything worked.
errorMessage := ""
if err != nil {
errorMessage = err.Error()
}
stats := NewVSchemaStats(vschema, errorMessage)
// save our value. if there was an error, then keep the
// existing vschema instead of overwriting it.
if v == nil && vm.e.vschema != nil {
vschema = vm.e.vschema
}
vm.e.SaveVSchema(vschema, stats)
})
} | go | func (vm *VSchemaManager) watchSrvVSchema(ctx context.Context, cell string) {
vm.e.serv.WatchSrvVSchema(ctx, cell, func(v *vschemapb.SrvVSchema, err error) {
// Create a closure to save the vschema. If the value
// passed is nil, it means we encountered an error and
// we don't know the real value. In this case, we want
// to use the previous value if it was set, or an
// empty vschema if it wasn't.
switch {
case err == nil:
// Good case, we can try to save that value.
case topo.IsErrType(err, topo.NoNode):
// If the SrvVschema disappears, we need to clear our record.
// Otherwise, keep what we already had before.
v = nil
default:
// Watch error, increment our counters.
if vschemaCounters != nil {
vschemaCounters.Add("WatchError", 1)
}
}
// keep a copy of the latest SrvVschema
vm.mu.Lock()
vm.currentSrvVschema = v
vm.mu.Unlock()
// Transform the provided SrvVSchema into a VSchema.
var vschema *vindexes.VSchema
if v != nil {
vschema, err = vindexes.BuildVSchema(v)
if err != nil {
log.Warningf("Error creating VSchema for cell %v (will try again next update): %v", cell, err)
err = fmt.Errorf("error creating VSchema for cell %v: %v", cell, err)
if vschemaCounters != nil {
vschemaCounters.Add("Parsing", 1)
}
}
}
if v == nil {
// We encountered an error, build an empty vschema.
vschema, _ = vindexes.BuildVSchema(&vschemapb.SrvVSchema{})
}
// Build the display version. At this point, three cases:
// - v is nil, vschema is empty, and err is set:
// 1. when the watch returned an error.
// 2. when BuildVSchema failed.
// - v is set, vschema is full, and err is nil:
// 3. when everything worked.
errorMessage := ""
if err != nil {
errorMessage = err.Error()
}
stats := NewVSchemaStats(vschema, errorMessage)
// save our value. if there was an error, then keep the
// existing vschema instead of overwriting it.
if v == nil && vm.e.vschema != nil {
vschema = vm.e.vschema
}
vm.e.SaveVSchema(vschema, stats)
})
} | [
"func",
"(",
"vm",
"*",
"VSchemaManager",
")",
"watchSrvVSchema",
"(",
"ctx",
"context",
".",
"Context",
",",
"cell",
"string",
")",
"{",
"vm",
".",
"e",
".",
"serv",
".",
"WatchSrvVSchema",
"(",
"ctx",
",",
"cell",
",",
"func",
"(",
"v",
"*",
"vschemapb",
".",
"SrvVSchema",
",",
"err",
"error",
")",
"{",
"// Create a closure to save the vschema. If the value",
"// passed is nil, it means we encountered an error and",
"// we don't know the real value. In this case, we want",
"// to use the previous value if it was set, or an",
"// empty vschema if it wasn't.",
"switch",
"{",
"case",
"err",
"==",
"nil",
":",
"// Good case, we can try to save that value.",
"case",
"topo",
".",
"IsErrType",
"(",
"err",
",",
"topo",
".",
"NoNode",
")",
":",
"// If the SrvVschema disappears, we need to clear our record.",
"// Otherwise, keep what we already had before.",
"v",
"=",
"nil",
"\n",
"default",
":",
"// Watch error, increment our counters.",
"if",
"vschemaCounters",
"!=",
"nil",
"{",
"vschemaCounters",
".",
"Add",
"(",
"\"",
"\"",
",",
"1",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// keep a copy of the latest SrvVschema",
"vm",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"vm",
".",
"currentSrvVschema",
"=",
"v",
"\n",
"vm",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Transform the provided SrvVSchema into a VSchema.",
"var",
"vschema",
"*",
"vindexes",
".",
"VSchema",
"\n",
"if",
"v",
"!=",
"nil",
"{",
"vschema",
",",
"err",
"=",
"vindexes",
".",
"BuildVSchema",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"cell",
",",
"err",
")",
"\n",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cell",
",",
"err",
")",
"\n",
"if",
"vschemaCounters",
"!=",
"nil",
"{",
"vschemaCounters",
".",
"Add",
"(",
"\"",
"\"",
",",
"1",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"v",
"==",
"nil",
"{",
"// We encountered an error, build an empty vschema.",
"vschema",
",",
"_",
"=",
"vindexes",
".",
"BuildVSchema",
"(",
"&",
"vschemapb",
".",
"SrvVSchema",
"{",
"}",
")",
"\n",
"}",
"\n\n",
"// Build the display version. At this point, three cases:",
"// - v is nil, vschema is empty, and err is set:",
"// 1. when the watch returned an error.",
"// 2. when BuildVSchema failed.",
"// - v is set, vschema is full, and err is nil:",
"// 3. when everything worked.",
"errorMessage",
":=",
"\"",
"\"",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"errorMessage",
"=",
"err",
".",
"Error",
"(",
")",
"\n",
"}",
"\n",
"stats",
":=",
"NewVSchemaStats",
"(",
"vschema",
",",
"errorMessage",
")",
"\n\n",
"// save our value. if there was an error, then keep the",
"// existing vschema instead of overwriting it.",
"if",
"v",
"==",
"nil",
"&&",
"vm",
".",
"e",
".",
"vschema",
"!=",
"nil",
"{",
"vschema",
"=",
"vm",
".",
"e",
".",
"vschema",
"\n",
"}",
"\n\n",
"vm",
".",
"e",
".",
"SaveVSchema",
"(",
"vschema",
",",
"stats",
")",
"\n",
"}",
")",
"\n",
"}"
] | // watchSrvVSchema watches the SrvVSchema from the topo. The function does
// not return an error. It instead logs warnings on failure.
// The SrvVSchema object is roll-up of all the Keyspace information,
// so when a keyspace is added or removed, it will be properly updated.
//
// This function will wait until the first value has either been processed
// or triggered an error before returning. | [
"watchSrvVSchema",
"watches",
"the",
"SrvVSchema",
"from",
"the",
"topo",
".",
"The",
"function",
"does",
"not",
"return",
"an",
"error",
".",
"It",
"instead",
"logs",
"warnings",
"on",
"failure",
".",
"The",
"SrvVSchema",
"object",
"is",
"roll",
"-",
"up",
"of",
"all",
"the",
"Keyspace",
"information",
"so",
"when",
"a",
"keyspace",
"is",
"added",
"or",
"removed",
"it",
"will",
"be",
"properly",
"updated",
".",
"This",
"function",
"will",
"wait",
"until",
"the",
"first",
"value",
"has",
"either",
"been",
"processed",
"or",
"triggered",
"an",
"error",
"before",
"returning",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vschema_manager.go#L56-L119 | train |
vitessio/vitess | go/vt/vtgate/vschema_manager.go | UpdateVSchema | func (vm *VSchemaManager) UpdateVSchema(ctx context.Context, ksName string, vschema *vschemapb.SrvVSchema) error {
topoServer, err := vm.e.serv.GetTopoServer()
if err != nil {
return err
}
ks := vschema.Keyspaces[ksName]
err = topoServer.SaveVSchema(ctx, ksName, ks)
if err != nil {
return err
}
cells, err := topoServer.GetKnownCells(ctx)
if err != nil {
return err
}
// even if one cell fails, continue to try the others
for _, cell := range cells {
cellErr := topoServer.UpdateSrvVSchema(ctx, cell, vschema)
if cellErr != nil {
err = cellErr
log.Errorf("error updating vschema in cell %s: %v", cell, cellErr)
}
}
return err
} | go | func (vm *VSchemaManager) UpdateVSchema(ctx context.Context, ksName string, vschema *vschemapb.SrvVSchema) error {
topoServer, err := vm.e.serv.GetTopoServer()
if err != nil {
return err
}
ks := vschema.Keyspaces[ksName]
err = topoServer.SaveVSchema(ctx, ksName, ks)
if err != nil {
return err
}
cells, err := topoServer.GetKnownCells(ctx)
if err != nil {
return err
}
// even if one cell fails, continue to try the others
for _, cell := range cells {
cellErr := topoServer.UpdateSrvVSchema(ctx, cell, vschema)
if cellErr != nil {
err = cellErr
log.Errorf("error updating vschema in cell %s: %v", cell, cellErr)
}
}
return err
} | [
"func",
"(",
"vm",
"*",
"VSchemaManager",
")",
"UpdateVSchema",
"(",
"ctx",
"context",
".",
"Context",
",",
"ksName",
"string",
",",
"vschema",
"*",
"vschemapb",
".",
"SrvVSchema",
")",
"error",
"{",
"topoServer",
",",
"err",
":=",
"vm",
".",
"e",
".",
"serv",
".",
"GetTopoServer",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"ks",
":=",
"vschema",
".",
"Keyspaces",
"[",
"ksName",
"]",
"\n",
"err",
"=",
"topoServer",
".",
"SaveVSchema",
"(",
"ctx",
",",
"ksName",
",",
"ks",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"cells",
",",
"err",
":=",
"topoServer",
".",
"GetKnownCells",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// even if one cell fails, continue to try the others",
"for",
"_",
",",
"cell",
":=",
"range",
"cells",
"{",
"cellErr",
":=",
"topoServer",
".",
"UpdateSrvVSchema",
"(",
"ctx",
",",
"cell",
",",
"vschema",
")",
"\n",
"if",
"cellErr",
"!=",
"nil",
"{",
"err",
"=",
"cellErr",
"\n",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cell",
",",
"cellErr",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // UpdateVSchema propagates the updated vschema to the topo. The entry for
// the given keyspace is updated in the global topo, and the full SrvVSchema
// is updated in all known cells. | [
"UpdateVSchema",
"propagates",
"the",
"updated",
"vschema",
"to",
"the",
"topo",
".",
"The",
"entry",
"for",
"the",
"given",
"keyspace",
"is",
"updated",
"in",
"the",
"global",
"topo",
"and",
"the",
"full",
"SrvVSchema",
"is",
"updated",
"in",
"all",
"known",
"cells",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vschema_manager.go#L124-L151 | train |
vitessio/vitess | go/mysql/flavor.go | MasterPosition | func (c *Conn) MasterPosition() (Position, error) {
gtidSet, err := c.flavor.masterGTIDSet(c)
if err != nil {
return Position{}, err
}
return Position{
GTIDSet: gtidSet,
}, nil
} | go | func (c *Conn) MasterPosition() (Position, error) {
gtidSet, err := c.flavor.masterGTIDSet(c)
if err != nil {
return Position{}, err
}
return Position{
GTIDSet: gtidSet,
}, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"MasterPosition",
"(",
")",
"(",
"Position",
",",
"error",
")",
"{",
"gtidSet",
",",
"err",
":=",
"c",
".",
"flavor",
".",
"masterGTIDSet",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Position",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"Position",
"{",
"GTIDSet",
":",
"gtidSet",
",",
"}",
",",
"nil",
"\n",
"}"
] | // MasterPosition returns the current master replication position. | [
"MasterPosition",
"returns",
"the",
"current",
"master",
"replication",
"position",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/flavor.go#L141-L149 | train |
vitessio/vitess | go/mysql/flavor.go | StartSlaveUntilAfterCommand | func (c *Conn) StartSlaveUntilAfterCommand(pos Position) string {
return c.flavor.startSlaveUntilAfter(pos)
} | go | func (c *Conn) StartSlaveUntilAfterCommand(pos Position) string {
return c.flavor.startSlaveUntilAfter(pos)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"StartSlaveUntilAfterCommand",
"(",
"pos",
"Position",
")",
"string",
"{",
"return",
"c",
".",
"flavor",
".",
"startSlaveUntilAfter",
"(",
"pos",
")",
"\n",
"}"
] | // StartSlaveUntilAfterCommand returns the command to start the slave. | [
"StartSlaveUntilAfterCommand",
"returns",
"the",
"command",
"to",
"start",
"the",
"slave",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/flavor.go#L157-L159 | train |
vitessio/vitess | go/mysql/flavor.go | SendBinlogDumpCommand | func (c *Conn) SendBinlogDumpCommand(slaveID uint32, startPos Position) error {
return c.flavor.sendBinlogDumpCommand(c, slaveID, startPos)
} | go | func (c *Conn) SendBinlogDumpCommand(slaveID uint32, startPos Position) error {
return c.flavor.sendBinlogDumpCommand(c, slaveID, startPos)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SendBinlogDumpCommand",
"(",
"slaveID",
"uint32",
",",
"startPos",
"Position",
")",
"error",
"{",
"return",
"c",
".",
"flavor",
".",
"sendBinlogDumpCommand",
"(",
"c",
",",
"slaveID",
",",
"startPos",
")",
"\n",
"}"
] | // SendBinlogDumpCommand sends the flavor-specific version of
// the COM_BINLOG_DUMP command to start dumping raw binlog
// events over a slave connection, starting at a given GTID. | [
"SendBinlogDumpCommand",
"sends",
"the",
"flavor",
"-",
"specific",
"version",
"of",
"the",
"COM_BINLOG_DUMP",
"command",
"to",
"start",
"dumping",
"raw",
"binlog",
"events",
"over",
"a",
"slave",
"connection",
"starting",
"at",
"a",
"given",
"GTID",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/flavor.go#L169-L171 | train |
vitessio/vitess | go/mysql/flavor.go | SetSlavePositionCommands | func (c *Conn) SetSlavePositionCommands(pos Position) []string {
return c.flavor.setSlavePositionCommands(pos)
} | go | func (c *Conn) SetSlavePositionCommands(pos Position) []string {
return c.flavor.setSlavePositionCommands(pos)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SetSlavePositionCommands",
"(",
"pos",
"Position",
")",
"[",
"]",
"string",
"{",
"return",
"c",
".",
"flavor",
".",
"setSlavePositionCommands",
"(",
"pos",
")",
"\n",
"}"
] | // SetSlavePositionCommands returns the commands to set the
// replication position at which the slave will resume
// when it is later reparented with SetMasterCommands. | [
"SetSlavePositionCommands",
"returns",
"the",
"commands",
"to",
"set",
"the",
"replication",
"position",
"at",
"which",
"the",
"slave",
"will",
"resume",
"when",
"it",
"is",
"later",
"reparented",
"with",
"SetMasterCommands",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/flavor.go#L188-L190 | train |
vitessio/vitess | go/mysql/flavor.go | resultToMap | func resultToMap(qr *sqltypes.Result) (map[string]string, error) {
if len(qr.Rows) == 0 {
// The query succeeded, but there is no data.
return nil, nil
}
if len(qr.Rows) > 1 {
return nil, vterrors.Errorf(vtrpc.Code_INTERNAL, "query returned %d rows, expected 1", len(qr.Rows))
}
if len(qr.Fields) != len(qr.Rows[0]) {
return nil, vterrors.Errorf(vtrpc.Code_INTERNAL, "query returned %d column names, expected %d", len(qr.Fields), len(qr.Rows[0]))
}
result := make(map[string]string, len(qr.Fields))
for i, field := range qr.Fields {
result[field.Name] = qr.Rows[0][i].ToString()
}
return result, nil
} | go | func resultToMap(qr *sqltypes.Result) (map[string]string, error) {
if len(qr.Rows) == 0 {
// The query succeeded, but there is no data.
return nil, nil
}
if len(qr.Rows) > 1 {
return nil, vterrors.Errorf(vtrpc.Code_INTERNAL, "query returned %d rows, expected 1", len(qr.Rows))
}
if len(qr.Fields) != len(qr.Rows[0]) {
return nil, vterrors.Errorf(vtrpc.Code_INTERNAL, "query returned %d column names, expected %d", len(qr.Fields), len(qr.Rows[0]))
}
result := make(map[string]string, len(qr.Fields))
for i, field := range qr.Fields {
result[field.Name] = qr.Rows[0][i].ToString()
}
return result, nil
} | [
"func",
"resultToMap",
"(",
"qr",
"*",
"sqltypes",
".",
"Result",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"if",
"len",
"(",
"qr",
".",
"Rows",
")",
"==",
"0",
"{",
"// The query succeeded, but there is no data.",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"if",
"len",
"(",
"qr",
".",
"Rows",
")",
">",
"1",
"{",
"return",
"nil",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_INTERNAL",
",",
"\"",
"\"",
",",
"len",
"(",
"qr",
".",
"Rows",
")",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"qr",
".",
"Fields",
")",
"!=",
"len",
"(",
"qr",
".",
"Rows",
"[",
"0",
"]",
")",
"{",
"return",
"nil",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_INTERNAL",
",",
"\"",
"\"",
",",
"len",
"(",
"qr",
".",
"Fields",
")",
",",
"len",
"(",
"qr",
".",
"Rows",
"[",
"0",
"]",
")",
")",
"\n",
"}",
"\n\n",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"len",
"(",
"qr",
".",
"Fields",
")",
")",
"\n",
"for",
"i",
",",
"field",
":=",
"range",
"qr",
".",
"Fields",
"{",
"result",
"[",
"field",
".",
"Name",
"]",
"=",
"qr",
".",
"Rows",
"[",
"0",
"]",
"[",
"i",
"]",
".",
"ToString",
"(",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // resultToMap is a helper function used by ShowSlaveStatus. | [
"resultToMap",
"is",
"a",
"helper",
"function",
"used",
"by",
"ShowSlaveStatus",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/flavor.go#L224-L241 | train |
vitessio/vitess | go/mysql/flavor.go | parseSlaveStatus | func parseSlaveStatus(fields map[string]string) SlaveStatus {
status := SlaveStatus{
MasterHost: fields["Master_Host"],
SlaveIORunning: fields["Slave_IO_Running"] == "Yes",
SlaveSQLRunning: fields["Slave_SQL_Running"] == "Yes",
}
parseInt, _ := strconv.ParseInt(fields["Master_Port"], 10, 0)
status.MasterPort = int(parseInt)
parseInt, _ = strconv.ParseInt(fields["Connect_Retry"], 10, 0)
status.MasterConnectRetry = int(parseInt)
parseUint, _ := strconv.ParseUint(fields["Seconds_Behind_Master"], 10, 0)
status.SecondsBehindMaster = uint(parseUint)
return status
} | go | func parseSlaveStatus(fields map[string]string) SlaveStatus {
status := SlaveStatus{
MasterHost: fields["Master_Host"],
SlaveIORunning: fields["Slave_IO_Running"] == "Yes",
SlaveSQLRunning: fields["Slave_SQL_Running"] == "Yes",
}
parseInt, _ := strconv.ParseInt(fields["Master_Port"], 10, 0)
status.MasterPort = int(parseInt)
parseInt, _ = strconv.ParseInt(fields["Connect_Retry"], 10, 0)
status.MasterConnectRetry = int(parseInt)
parseUint, _ := strconv.ParseUint(fields["Seconds_Behind_Master"], 10, 0)
status.SecondsBehindMaster = uint(parseUint)
return status
} | [
"func",
"parseSlaveStatus",
"(",
"fields",
"map",
"[",
"string",
"]",
"string",
")",
"SlaveStatus",
"{",
"status",
":=",
"SlaveStatus",
"{",
"MasterHost",
":",
"fields",
"[",
"\"",
"\"",
"]",
",",
"SlaveIORunning",
":",
"fields",
"[",
"\"",
"\"",
"]",
"==",
"\"",
"\"",
",",
"SlaveSQLRunning",
":",
"fields",
"[",
"\"",
"\"",
"]",
"==",
"\"",
"\"",
",",
"}",
"\n",
"parseInt",
",",
"_",
":=",
"strconv",
".",
"ParseInt",
"(",
"fields",
"[",
"\"",
"\"",
"]",
",",
"10",
",",
"0",
")",
"\n",
"status",
".",
"MasterPort",
"=",
"int",
"(",
"parseInt",
")",
"\n",
"parseInt",
",",
"_",
"=",
"strconv",
".",
"ParseInt",
"(",
"fields",
"[",
"\"",
"\"",
"]",
",",
"10",
",",
"0",
")",
"\n",
"status",
".",
"MasterConnectRetry",
"=",
"int",
"(",
"parseInt",
")",
"\n",
"parseUint",
",",
"_",
":=",
"strconv",
".",
"ParseUint",
"(",
"fields",
"[",
"\"",
"\"",
"]",
",",
"10",
",",
"0",
")",
"\n",
"status",
".",
"SecondsBehindMaster",
"=",
"uint",
"(",
"parseUint",
")",
"\n",
"return",
"status",
"\n",
"}"
] | // parseSlaveStatus parses the common fields of SHOW SLAVE STATUS. | [
"parseSlaveStatus",
"parses",
"the",
"common",
"fields",
"of",
"SHOW",
"SLAVE",
"STATUS",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/flavor.go#L244-L257 | train |
vitessio/vitess | go/mysql/flavor.go | WaitUntilPositionCommand | func (c *Conn) WaitUntilPositionCommand(ctx context.Context, pos Position) (string, error) {
return c.flavor.waitUntilPositionCommand(ctx, pos)
} | go | func (c *Conn) WaitUntilPositionCommand(ctx context.Context, pos Position) (string, error) {
return c.flavor.waitUntilPositionCommand(ctx, pos)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"WaitUntilPositionCommand",
"(",
"ctx",
"context",
".",
"Context",
",",
"pos",
"Position",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"c",
".",
"flavor",
".",
"waitUntilPositionCommand",
"(",
"ctx",
",",
"pos",
")",
"\n",
"}"
] | // WaitUntilPositionCommand returns the SQL command to issue
// to wait until the given position, until the context
// expires. The command returns -1 if it times out. It
// returns NULL if GTIDs are not enabled. | [
"WaitUntilPositionCommand",
"returns",
"the",
"SQL",
"command",
"to",
"issue",
"to",
"wait",
"until",
"the",
"given",
"position",
"until",
"the",
"context",
"expires",
".",
"The",
"command",
"returns",
"-",
"1",
"if",
"it",
"times",
"out",
".",
"It",
"returns",
"NULL",
"if",
"GTIDs",
"are",
"not",
"enabled",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/flavor.go#L269-L271 | train |
vitessio/vitess | go/vt/topotools/events/migrate_syslog.go | Syslog | func (ev *MigrateServedFrom) Syslog() (syslog.Priority, string) {
var format string
if ev.Reverse {
format = "%s [migrate served-from %s/%s <- %s/%s] %s"
} else {
format = "%s [migrate served-from %s/%s -> %s/%s] %s"
}
return syslog.LOG_INFO, fmt.Sprintf(format,
ev.KeyspaceName,
ev.SourceShard.Keyspace(), ev.SourceShard.ShardName(),
ev.DestinationShard.Keyspace(), ev.DestinationShard.ShardName(),
ev.Status)
} | go | func (ev *MigrateServedFrom) Syslog() (syslog.Priority, string) {
var format string
if ev.Reverse {
format = "%s [migrate served-from %s/%s <- %s/%s] %s"
} else {
format = "%s [migrate served-from %s/%s -> %s/%s] %s"
}
return syslog.LOG_INFO, fmt.Sprintf(format,
ev.KeyspaceName,
ev.SourceShard.Keyspace(), ev.SourceShard.ShardName(),
ev.DestinationShard.Keyspace(), ev.DestinationShard.ShardName(),
ev.Status)
} | [
"func",
"(",
"ev",
"*",
"MigrateServedFrom",
")",
"Syslog",
"(",
")",
"(",
"syslog",
".",
"Priority",
",",
"string",
")",
"{",
"var",
"format",
"string",
"\n",
"if",
"ev",
".",
"Reverse",
"{",
"format",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"format",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"syslog",
".",
"LOG_INFO",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"ev",
".",
"KeyspaceName",
",",
"ev",
".",
"SourceShard",
".",
"Keyspace",
"(",
")",
",",
"ev",
".",
"SourceShard",
".",
"ShardName",
"(",
")",
",",
"ev",
".",
"DestinationShard",
".",
"Keyspace",
"(",
")",
",",
"ev",
".",
"DestinationShard",
".",
"ShardName",
"(",
")",
",",
"ev",
".",
"Status",
")",
"\n",
"}"
] | // Syslog writes a MigrateServedFrom event to syslog. | [
"Syslog",
"writes",
"a",
"MigrateServedFrom",
"event",
"to",
"syslog",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topotools/events/migrate_syslog.go#L28-L40 | train |
vitessio/vitess | go/vt/topotools/events/migrate_syslog.go | Syslog | func (ev *MigrateServedTypes) Syslog() (syslog.Priority, string) {
var format string
if ev.Reverse {
format = "%s [migrate served-types {%v} <- {%v}] %s"
} else {
format = "%s [migrate served-types {%v} -> {%v}] %s"
}
sourceShards := make([]string, len(ev.SourceShards))
for i, shard := range ev.SourceShards {
if shard == nil {
continue
}
sourceShards[i] = shard.ShardName()
}
destShards := make([]string, len(ev.DestinationShards))
for i, shard := range ev.DestinationShards {
if shard == nil {
continue
}
destShards[i] = shard.ShardName()
}
return syslog.LOG_INFO, fmt.Sprintf(format,
ev.KeyspaceName, strings.Join(sourceShards, ", "),
strings.Join(destShards, ", "), ev.Status)
} | go | func (ev *MigrateServedTypes) Syslog() (syslog.Priority, string) {
var format string
if ev.Reverse {
format = "%s [migrate served-types {%v} <- {%v}] %s"
} else {
format = "%s [migrate served-types {%v} -> {%v}] %s"
}
sourceShards := make([]string, len(ev.SourceShards))
for i, shard := range ev.SourceShards {
if shard == nil {
continue
}
sourceShards[i] = shard.ShardName()
}
destShards := make([]string, len(ev.DestinationShards))
for i, shard := range ev.DestinationShards {
if shard == nil {
continue
}
destShards[i] = shard.ShardName()
}
return syslog.LOG_INFO, fmt.Sprintf(format,
ev.KeyspaceName, strings.Join(sourceShards, ", "),
strings.Join(destShards, ", "), ev.Status)
} | [
"func",
"(",
"ev",
"*",
"MigrateServedTypes",
")",
"Syslog",
"(",
")",
"(",
"syslog",
".",
"Priority",
",",
"string",
")",
"{",
"var",
"format",
"string",
"\n",
"if",
"ev",
".",
"Reverse",
"{",
"format",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"format",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"sourceShards",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"ev",
".",
"SourceShards",
")",
")",
"\n",
"for",
"i",
",",
"shard",
":=",
"range",
"ev",
".",
"SourceShards",
"{",
"if",
"shard",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"sourceShards",
"[",
"i",
"]",
"=",
"shard",
".",
"ShardName",
"(",
")",
"\n",
"}",
"\n",
"destShards",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"ev",
".",
"DestinationShards",
")",
")",
"\n",
"for",
"i",
",",
"shard",
":=",
"range",
"ev",
".",
"DestinationShards",
"{",
"if",
"shard",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"destShards",
"[",
"i",
"]",
"=",
"shard",
".",
"ShardName",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"syslog",
".",
"LOG_INFO",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"ev",
".",
"KeyspaceName",
",",
"strings",
".",
"Join",
"(",
"sourceShards",
",",
"\"",
"\"",
")",
",",
"strings",
".",
"Join",
"(",
"destShards",
",",
"\"",
"\"",
")",
",",
"ev",
".",
"Status",
")",
"\n",
"}"
] | // Syslog writes a MigrateServedTypes event to syslog. | [
"Syslog",
"writes",
"a",
"MigrateServedTypes",
"event",
"to",
"syslog",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topotools/events/migrate_syslog.go#L45-L71 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.