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/vtgate/safe_session.go | SetAutocommitable | func (session *SafeSession) SetAutocommitable(flag bool) {
session.mu.Lock()
defer session.mu.Unlock()
if session.autocommitState == autocommitted {
panic("BUG: SetAutocommitable: unexpected autocommit state")
}
if flag {
session.autocommitState = autocommittable
} else {
session.autocommitState = notAutocommittable
}
} | go | func (session *SafeSession) SetAutocommitable(flag bool) {
session.mu.Lock()
defer session.mu.Unlock()
if session.autocommitState == autocommitted {
panic("BUG: SetAutocommitable: unexpected autocommit state")
}
if flag {
session.autocommitState = autocommittable
} else {
session.autocommitState = notAutocommittable
}
} | [
"func",
"(",
"session",
"*",
"SafeSession",
")",
"SetAutocommitable",
"(",
"flag",
"bool",
")",
"{",
"session",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"session",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"session",
".",
"autocommitState",
"==",
"autocommitted",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"flag",
"{",
"session",
".",
"autocommitState",
"=",
"autocommittable",
"\n",
"}",
"else",
"{",
"session",
".",
"autocommitState",
"=",
"notAutocommittable",
"\n",
"}",
"\n",
"}"
] | // SetAutocommitable sets the state to autocommitable if true.
// Otherwise, it's notAutocommitable. | [
"SetAutocommitable",
"sets",
"the",
"state",
"to",
"autocommitable",
"if",
"true",
".",
"Otherwise",
"it",
"s",
"notAutocommitable",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/safe_session.go#L83-L96 | train |
vitessio/vitess | go/vt/vtgate/safe_session.go | AutocommitApproval | func (session *SafeSession) AutocommitApproval() bool {
session.mu.Lock()
defer session.mu.Unlock()
if session.autocommitState == autocommitted {
panic("BUG: AutocommitToken: unexpected autocommit state")
}
if session.autocommitState == autocommittable && len(session.ShardSessions) == 0 {
session.autocommitState = autocommitted
return true
}
return false
} | go | func (session *SafeSession) AutocommitApproval() bool {
session.mu.Lock()
defer session.mu.Unlock()
if session.autocommitState == autocommitted {
panic("BUG: AutocommitToken: unexpected autocommit state")
}
if session.autocommitState == autocommittable && len(session.ShardSessions) == 0 {
session.autocommitState = autocommitted
return true
}
return false
} | [
"func",
"(",
"session",
"*",
"SafeSession",
")",
"AutocommitApproval",
"(",
")",
"bool",
"{",
"session",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"session",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"session",
".",
"autocommitState",
"==",
"autocommitted",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"session",
".",
"autocommitState",
"==",
"autocommittable",
"&&",
"len",
"(",
"session",
".",
"ShardSessions",
")",
"==",
"0",
"{",
"session",
".",
"autocommitState",
"=",
"autocommitted",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // AutocommitApproval returns true if we can perform a single round-trip
// autocommit. If so, the caller is responsible for committing their
// transaction. | [
"AutocommitApproval",
"returns",
"true",
"if",
"we",
"can",
"perform",
"a",
"single",
"round",
"-",
"trip",
"autocommit",
".",
"If",
"so",
"the",
"caller",
"is",
"responsible",
"for",
"committing",
"their",
"transaction",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/safe_session.go#L101-L114 | train |
vitessio/vitess | go/vt/vtgate/safe_session.go | InTransaction | func (session *SafeSession) InTransaction() bool {
if session == nil || session.Session == nil {
return false
}
session.mu.Lock()
defer session.mu.Unlock()
return session.Session.InTransaction
} | go | func (session *SafeSession) InTransaction() bool {
if session == nil || session.Session == nil {
return false
}
session.mu.Lock()
defer session.mu.Unlock()
return session.Session.InTransaction
} | [
"func",
"(",
"session",
"*",
"SafeSession",
")",
"InTransaction",
"(",
")",
"bool",
"{",
"if",
"session",
"==",
"nil",
"||",
"session",
".",
"Session",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"session",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"session",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"session",
".",
"Session",
".",
"InTransaction",
"\n",
"}"
] | // InTransaction returns true if we are in a transaction | [
"InTransaction",
"returns",
"true",
"if",
"we",
"are",
"in",
"a",
"transaction"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/safe_session.go#L117-L124 | train |
vitessio/vitess | go/vt/vtgate/safe_session.go | Find | func (session *SafeSession) Find(keyspace, shard string, tabletType topodatapb.TabletType) int64 {
if session == nil {
return 0
}
session.mu.Lock()
defer session.mu.Unlock()
for _, shardSession := range session.ShardSessions {
if keyspace == shardSession.Target.Keyspace && tabletType == shardSession.Target.TabletType && shard == shardSession.Target.Shard {
return shardSession.TransactionId
}
}
return 0
} | go | func (session *SafeSession) Find(keyspace, shard string, tabletType topodatapb.TabletType) int64 {
if session == nil {
return 0
}
session.mu.Lock()
defer session.mu.Unlock()
for _, shardSession := range session.ShardSessions {
if keyspace == shardSession.Target.Keyspace && tabletType == shardSession.Target.TabletType && shard == shardSession.Target.Shard {
return shardSession.TransactionId
}
}
return 0
} | [
"func",
"(",
"session",
"*",
"SafeSession",
")",
"Find",
"(",
"keyspace",
",",
"shard",
"string",
",",
"tabletType",
"topodatapb",
".",
"TabletType",
")",
"int64",
"{",
"if",
"session",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"session",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"session",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"shardSession",
":=",
"range",
"session",
".",
"ShardSessions",
"{",
"if",
"keyspace",
"==",
"shardSession",
".",
"Target",
".",
"Keyspace",
"&&",
"tabletType",
"==",
"shardSession",
".",
"Target",
".",
"TabletType",
"&&",
"shard",
"==",
"shardSession",
".",
"Target",
".",
"Shard",
"{",
"return",
"shardSession",
".",
"TransactionId",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}"
] | // Find returns the transactionId, if any, for a session | [
"Find",
"returns",
"the",
"transactionId",
"if",
"any",
"for",
"a",
"session"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/safe_session.go#L127-L139 | train |
vitessio/vitess | go/vt/vtgate/safe_session.go | Append | func (session *SafeSession) Append(shardSession *vtgatepb.Session_ShardSession, txMode vtgatepb.TransactionMode) error {
session.mu.Lock()
defer session.mu.Unlock()
if session.autocommitState == autocommitted {
panic("BUG: SafeSession.Append: unexpected autocommit state")
}
// Always append, in order for rollback to succeed.
session.ShardSessions = append(session.ShardSessions, shardSession)
if session.isSingleDB(txMode) && len(session.ShardSessions) > 1 {
session.mustRollback = true
return vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "multi-db transaction attempted: %v", session.ShardSessions)
}
return nil
} | go | func (session *SafeSession) Append(shardSession *vtgatepb.Session_ShardSession, txMode vtgatepb.TransactionMode) error {
session.mu.Lock()
defer session.mu.Unlock()
if session.autocommitState == autocommitted {
panic("BUG: SafeSession.Append: unexpected autocommit state")
}
// Always append, in order for rollback to succeed.
session.ShardSessions = append(session.ShardSessions, shardSession)
if session.isSingleDB(txMode) && len(session.ShardSessions) > 1 {
session.mustRollback = true
return vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "multi-db transaction attempted: %v", session.ShardSessions)
}
return nil
} | [
"func",
"(",
"session",
"*",
"SafeSession",
")",
"Append",
"(",
"shardSession",
"*",
"vtgatepb",
".",
"Session_ShardSession",
",",
"txMode",
"vtgatepb",
".",
"TransactionMode",
")",
"error",
"{",
"session",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"session",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"session",
".",
"autocommitState",
"==",
"autocommitted",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Always append, in order for rollback to succeed.",
"session",
".",
"ShardSessions",
"=",
"append",
"(",
"session",
".",
"ShardSessions",
",",
"shardSession",
")",
"\n",
"if",
"session",
".",
"isSingleDB",
"(",
"txMode",
")",
"&&",
"len",
"(",
"session",
".",
"ShardSessions",
")",
">",
"1",
"{",
"session",
".",
"mustRollback",
"=",
"true",
"\n",
"return",
"vterrors",
".",
"Errorf",
"(",
"vtrpcpb",
".",
"Code_INVALID_ARGUMENT",
",",
"\"",
"\"",
",",
"session",
".",
"ShardSessions",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Append adds a new ShardSession | [
"Append",
"adds",
"a",
"new",
"ShardSession"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/safe_session.go#L142-L157 | train |
vitessio/vitess | go/vt/vtgate/safe_session.go | SetRollback | func (session *SafeSession) SetRollback() {
if session == nil || session.Session == nil || !session.Session.InTransaction {
return
}
session.mu.Lock()
defer session.mu.Unlock()
session.mustRollback = true
} | go | func (session *SafeSession) SetRollback() {
if session == nil || session.Session == nil || !session.Session.InTransaction {
return
}
session.mu.Lock()
defer session.mu.Unlock()
session.mustRollback = true
} | [
"func",
"(",
"session",
"*",
"SafeSession",
")",
"SetRollback",
"(",
")",
"{",
"if",
"session",
"==",
"nil",
"||",
"session",
".",
"Session",
"==",
"nil",
"||",
"!",
"session",
".",
"Session",
".",
"InTransaction",
"{",
"return",
"\n",
"}",
"\n",
"session",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"session",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"session",
".",
"mustRollback",
"=",
"true",
"\n",
"}"
] | // SetRollback sets the flag indicating that the transaction must be rolled back.
// The call is a no-op if the session is not in a transaction. | [
"SetRollback",
"sets",
"the",
"flag",
"indicating",
"that",
"the",
"transaction",
"must",
"be",
"rolled",
"back",
".",
"The",
"call",
"is",
"a",
"no",
"-",
"op",
"if",
"the",
"session",
"is",
"not",
"in",
"a",
"transaction",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/safe_session.go#L167-L174 | train |
vitessio/vitess | go/vt/vtgate/safe_session.go | MustRollback | func (session *SafeSession) MustRollback() bool {
if session == nil {
return false
}
session.mu.Lock()
defer session.mu.Unlock()
return session.mustRollback
} | go | func (session *SafeSession) MustRollback() bool {
if session == nil {
return false
}
session.mu.Lock()
defer session.mu.Unlock()
return session.mustRollback
} | [
"func",
"(",
"session",
"*",
"SafeSession",
")",
"MustRollback",
"(",
")",
"bool",
"{",
"if",
"session",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"session",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"session",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"session",
".",
"mustRollback",
"\n",
"}"
] | // MustRollback returns true if the transaction must be rolled back. | [
"MustRollback",
"returns",
"true",
"if",
"the",
"transaction",
"must",
"be",
"rolled",
"back",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/safe_session.go#L177-L184 | train |
vitessio/vitess | go/vt/vtgate/safe_session.go | RecordWarning | func (session *SafeSession) RecordWarning(warning *querypb.QueryWarning) {
session.mu.Lock()
defer session.mu.Unlock()
session.Session.Warnings = append(session.Session.Warnings, warning)
} | go | func (session *SafeSession) RecordWarning(warning *querypb.QueryWarning) {
session.mu.Lock()
defer session.mu.Unlock()
session.Session.Warnings = append(session.Session.Warnings, warning)
} | [
"func",
"(",
"session",
"*",
"SafeSession",
")",
"RecordWarning",
"(",
"warning",
"*",
"querypb",
".",
"QueryWarning",
")",
"{",
"session",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"session",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"session",
".",
"Session",
".",
"Warnings",
"=",
"append",
"(",
"session",
".",
"Session",
".",
"Warnings",
",",
"warning",
")",
"\n",
"}"
] | // RecordWarning stores the given warning in the session | [
"RecordWarning",
"stores",
"the",
"given",
"warning",
"in",
"the",
"session"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/safe_session.go#L187-L191 | train |
vitessio/vitess | go/vt/vtgate/safe_session.go | ClearWarnings | func (session *SafeSession) ClearWarnings() {
session.mu.Lock()
defer session.mu.Unlock()
session.Session.Warnings = nil
} | go | func (session *SafeSession) ClearWarnings() {
session.mu.Lock()
defer session.mu.Unlock()
session.Session.Warnings = nil
} | [
"func",
"(",
"session",
"*",
"SafeSession",
")",
"ClearWarnings",
"(",
")",
"{",
"session",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"session",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"session",
".",
"Session",
".",
"Warnings",
"=",
"nil",
"\n",
"}"
] | // ClearWarnings removes all the warnings from the session | [
"ClearWarnings",
"removes",
"all",
"the",
"warnings",
"from",
"the",
"session"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/safe_session.go#L194-L198 | train |
vitessio/vitess | go/vt/vtgate/safe_session.go | Reset | func (session *SafeSession) Reset() {
if session == nil || session.Session == nil {
return
}
session.mu.Lock()
defer session.mu.Unlock()
session.mustRollback = false
session.autocommitState = notAutocommittable
session.Session.InTransaction = false
session.SingleDb = false
session.ShardSessions = nil
} | go | func (session *SafeSession) Reset() {
if session == nil || session.Session == nil {
return
}
session.mu.Lock()
defer session.mu.Unlock()
session.mustRollback = false
session.autocommitState = notAutocommittable
session.Session.InTransaction = false
session.SingleDb = false
session.ShardSessions = nil
} | [
"func",
"(",
"session",
"*",
"SafeSession",
")",
"Reset",
"(",
")",
"{",
"if",
"session",
"==",
"nil",
"||",
"session",
".",
"Session",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"session",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"session",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"session",
".",
"mustRollback",
"=",
"false",
"\n",
"session",
".",
"autocommitState",
"=",
"notAutocommittable",
"\n",
"session",
".",
"Session",
".",
"InTransaction",
"=",
"false",
"\n",
"session",
".",
"SingleDb",
"=",
"false",
"\n",
"session",
".",
"ShardSessions",
"=",
"nil",
"\n",
"}"
] | // Reset clears the session | [
"Reset",
"clears",
"the",
"session"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/safe_session.go#L201-L212 | train |
vitessio/vitess | go/vt/topo/srv_vschema.go | WatchSrvVSchema | func (ts *Server) WatchSrvVSchema(ctx context.Context, cell string) (*WatchSrvVSchemaData, <-chan *WatchSrvVSchemaData, CancelFunc) {
conn, err := ts.ConnForCell(ctx, cell)
if err != nil {
return &WatchSrvVSchemaData{Err: err}, nil, nil
}
current, wdChannel, cancel := conn.Watch(ctx, SrvVSchemaFile)
if current.Err != nil {
return &WatchSrvVSchemaData{Err: current.Err}, nil, nil
}
value := &vschemapb.SrvVSchema{}
if err := proto.Unmarshal(current.Contents, value); err != nil {
// Cancel the watch, drain channel.
cancel()
for range wdChannel {
}
return &WatchSrvVSchemaData{Err: vterrors.Wrapf(err, "error unpacking initial SrvVSchema object")}, nil, nil
}
changes := make(chan *WatchSrvVSchemaData, 10)
// The background routine reads any event from the watch channel,
// translates it, and sends it to the caller.
// If cancel() is called, the underlying Watch() code will
// send an ErrInterrupted and then close the channel. We'll
// just propagate that back to our caller.
go func() {
defer close(changes)
for wd := range wdChannel {
if wd.Err != nil {
// Last error value, we're done.
// wdChannel will be closed right after
// this, no need to do anything.
changes <- &WatchSrvVSchemaData{Err: wd.Err}
return
}
value := &vschemapb.SrvVSchema{}
if err := proto.Unmarshal(wd.Contents, value); err != nil {
cancel()
for range wdChannel {
}
changes <- &WatchSrvVSchemaData{Err: vterrors.Wrapf(err, "error unpacking SrvVSchema object")}
return
}
changes <- &WatchSrvVSchemaData{Value: value}
}
}()
return &WatchSrvVSchemaData{Value: value}, changes, cancel
} | go | func (ts *Server) WatchSrvVSchema(ctx context.Context, cell string) (*WatchSrvVSchemaData, <-chan *WatchSrvVSchemaData, CancelFunc) {
conn, err := ts.ConnForCell(ctx, cell)
if err != nil {
return &WatchSrvVSchemaData{Err: err}, nil, nil
}
current, wdChannel, cancel := conn.Watch(ctx, SrvVSchemaFile)
if current.Err != nil {
return &WatchSrvVSchemaData{Err: current.Err}, nil, nil
}
value := &vschemapb.SrvVSchema{}
if err := proto.Unmarshal(current.Contents, value); err != nil {
// Cancel the watch, drain channel.
cancel()
for range wdChannel {
}
return &WatchSrvVSchemaData{Err: vterrors.Wrapf(err, "error unpacking initial SrvVSchema object")}, nil, nil
}
changes := make(chan *WatchSrvVSchemaData, 10)
// The background routine reads any event from the watch channel,
// translates it, and sends it to the caller.
// If cancel() is called, the underlying Watch() code will
// send an ErrInterrupted and then close the channel. We'll
// just propagate that back to our caller.
go func() {
defer close(changes)
for wd := range wdChannel {
if wd.Err != nil {
// Last error value, we're done.
// wdChannel will be closed right after
// this, no need to do anything.
changes <- &WatchSrvVSchemaData{Err: wd.Err}
return
}
value := &vschemapb.SrvVSchema{}
if err := proto.Unmarshal(wd.Contents, value); err != nil {
cancel()
for range wdChannel {
}
changes <- &WatchSrvVSchemaData{Err: vterrors.Wrapf(err, "error unpacking SrvVSchema object")}
return
}
changes <- &WatchSrvVSchemaData{Value: value}
}
}()
return &WatchSrvVSchemaData{Value: value}, changes, cancel
} | [
"func",
"(",
"ts",
"*",
"Server",
")",
"WatchSrvVSchema",
"(",
"ctx",
"context",
".",
"Context",
",",
"cell",
"string",
")",
"(",
"*",
"WatchSrvVSchemaData",
",",
"<-",
"chan",
"*",
"WatchSrvVSchemaData",
",",
"CancelFunc",
")",
"{",
"conn",
",",
"err",
":=",
"ts",
".",
"ConnForCell",
"(",
"ctx",
",",
"cell",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"&",
"WatchSrvVSchemaData",
"{",
"Err",
":",
"err",
"}",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"current",
",",
"wdChannel",
",",
"cancel",
":=",
"conn",
".",
"Watch",
"(",
"ctx",
",",
"SrvVSchemaFile",
")",
"\n",
"if",
"current",
".",
"Err",
"!=",
"nil",
"{",
"return",
"&",
"WatchSrvVSchemaData",
"{",
"Err",
":",
"current",
".",
"Err",
"}",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"value",
":=",
"&",
"vschemapb",
".",
"SrvVSchema",
"{",
"}",
"\n",
"if",
"err",
":=",
"proto",
".",
"Unmarshal",
"(",
"current",
".",
"Contents",
",",
"value",
")",
";",
"err",
"!=",
"nil",
"{",
"// Cancel the watch, drain channel.",
"cancel",
"(",
")",
"\n",
"for",
"range",
"wdChannel",
"{",
"}",
"\n",
"return",
"&",
"WatchSrvVSchemaData",
"{",
"Err",
":",
"vterrors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"}",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"changes",
":=",
"make",
"(",
"chan",
"*",
"WatchSrvVSchemaData",
",",
"10",
")",
"\n\n",
"// The background routine reads any event from the watch channel,",
"// translates it, and sends it to the caller.",
"// If cancel() is called, the underlying Watch() code will",
"// send an ErrInterrupted and then close the channel. We'll",
"// just propagate that back to our caller.",
"go",
"func",
"(",
")",
"{",
"defer",
"close",
"(",
"changes",
")",
"\n\n",
"for",
"wd",
":=",
"range",
"wdChannel",
"{",
"if",
"wd",
".",
"Err",
"!=",
"nil",
"{",
"// Last error value, we're done.",
"// wdChannel will be closed right after",
"// this, no need to do anything.",
"changes",
"<-",
"&",
"WatchSrvVSchemaData",
"{",
"Err",
":",
"wd",
".",
"Err",
"}",
"\n",
"return",
"\n",
"}",
"\n\n",
"value",
":=",
"&",
"vschemapb",
".",
"SrvVSchema",
"{",
"}",
"\n",
"if",
"err",
":=",
"proto",
".",
"Unmarshal",
"(",
"wd",
".",
"Contents",
",",
"value",
")",
";",
"err",
"!=",
"nil",
"{",
"cancel",
"(",
")",
"\n",
"for",
"range",
"wdChannel",
"{",
"}",
"\n",
"changes",
"<-",
"&",
"WatchSrvVSchemaData",
"{",
"Err",
":",
"vterrors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"changes",
"<-",
"&",
"WatchSrvVSchemaData",
"{",
"Value",
":",
"value",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"&",
"WatchSrvVSchemaData",
"{",
"Value",
":",
"value",
"}",
",",
"changes",
",",
"cancel",
"\n",
"}"
] | // WatchSrvVSchema will set a watch on the SrvVSchema object.
// It has the same contract as Conn.Watch, but it also unpacks the
// contents into a SrvVSchema object. | [
"WatchSrvVSchema",
"will",
"set",
"a",
"watch",
"on",
"the",
"SrvVSchema",
"object",
".",
"It",
"has",
"the",
"same",
"contract",
"as",
"Conn",
".",
"Watch",
"but",
"it",
"also",
"unpacks",
"the",
"contents",
"into",
"a",
"SrvVSchema",
"object",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/srv_vschema.go#L39-L90 | train |
vitessio/vitess | go/vt/topo/srv_vschema.go | UpdateSrvVSchema | func (ts *Server) UpdateSrvVSchema(ctx context.Context, cell string, srvVSchema *vschemapb.SrvVSchema) error {
conn, err := ts.ConnForCell(ctx, cell)
if err != nil {
return err
}
nodePath := SrvVSchemaFile
data, err := proto.Marshal(srvVSchema)
if err != nil {
return err
}
_, err = conn.Update(ctx, nodePath, data, nil)
return err
} | go | func (ts *Server) UpdateSrvVSchema(ctx context.Context, cell string, srvVSchema *vschemapb.SrvVSchema) error {
conn, err := ts.ConnForCell(ctx, cell)
if err != nil {
return err
}
nodePath := SrvVSchemaFile
data, err := proto.Marshal(srvVSchema)
if err != nil {
return err
}
_, err = conn.Update(ctx, nodePath, data, nil)
return err
} | [
"func",
"(",
"ts",
"*",
"Server",
")",
"UpdateSrvVSchema",
"(",
"ctx",
"context",
".",
"Context",
",",
"cell",
"string",
",",
"srvVSchema",
"*",
"vschemapb",
".",
"SrvVSchema",
")",
"error",
"{",
"conn",
",",
"err",
":=",
"ts",
".",
"ConnForCell",
"(",
"ctx",
",",
"cell",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"nodePath",
":=",
"SrvVSchemaFile",
"\n",
"data",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"srvVSchema",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"conn",
".",
"Update",
"(",
"ctx",
",",
"nodePath",
",",
"data",
",",
"nil",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // UpdateSrvVSchema updates the SrvVSchema file for a cell. | [
"UpdateSrvVSchema",
"updates",
"the",
"SrvVSchema",
"file",
"for",
"a",
"cell",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/srv_vschema.go#L93-L106 | train |
vitessio/vitess | go/vt/topo/srv_vschema.go | GetSrvVSchema | func (ts *Server) GetSrvVSchema(ctx context.Context, cell string) (*vschemapb.SrvVSchema, error) {
conn, err := ts.ConnForCell(ctx, cell)
if err != nil {
return nil, err
}
nodePath := SrvVSchemaFile
data, _, err := conn.Get(ctx, nodePath)
if err != nil {
return nil, err
}
srvVSchema := &vschemapb.SrvVSchema{}
if err := proto.Unmarshal(data, srvVSchema); err != nil {
return nil, vterrors.Wrapf(err, "SrvVSchema unmarshal failed: %v", data)
}
return srvVSchema, nil
} | go | func (ts *Server) GetSrvVSchema(ctx context.Context, cell string) (*vschemapb.SrvVSchema, error) {
conn, err := ts.ConnForCell(ctx, cell)
if err != nil {
return nil, err
}
nodePath := SrvVSchemaFile
data, _, err := conn.Get(ctx, nodePath)
if err != nil {
return nil, err
}
srvVSchema := &vschemapb.SrvVSchema{}
if err := proto.Unmarshal(data, srvVSchema); err != nil {
return nil, vterrors.Wrapf(err, "SrvVSchema unmarshal failed: %v", data)
}
return srvVSchema, nil
} | [
"func",
"(",
"ts",
"*",
"Server",
")",
"GetSrvVSchema",
"(",
"ctx",
"context",
".",
"Context",
",",
"cell",
"string",
")",
"(",
"*",
"vschemapb",
".",
"SrvVSchema",
",",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"ts",
".",
"ConnForCell",
"(",
"ctx",
",",
"cell",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"nodePath",
":=",
"SrvVSchemaFile",
"\n",
"data",
",",
"_",
",",
"err",
":=",
"conn",
".",
"Get",
"(",
"ctx",
",",
"nodePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"srvVSchema",
":=",
"&",
"vschemapb",
".",
"SrvVSchema",
"{",
"}",
"\n",
"if",
"err",
":=",
"proto",
".",
"Unmarshal",
"(",
"data",
",",
"srvVSchema",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"vterrors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"data",
")",
"\n",
"}",
"\n",
"return",
"srvVSchema",
",",
"nil",
"\n",
"}"
] | // GetSrvVSchema returns the SrvVSchema for a cell. | [
"GetSrvVSchema",
"returns",
"the",
"SrvVSchema",
"for",
"a",
"cell",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/srv_vschema.go#L109-L125 | train |
vitessio/vitess | go/vt/topo/srv_vschema.go | DeleteSrvVSchema | func (ts *Server) DeleteSrvVSchema(ctx context.Context, cell string) error {
conn, err := ts.ConnForCell(ctx, cell)
if err != nil {
return err
}
nodePath := SrvVSchemaFile
return conn.Delete(ctx, nodePath, nil)
} | go | func (ts *Server) DeleteSrvVSchema(ctx context.Context, cell string) error {
conn, err := ts.ConnForCell(ctx, cell)
if err != nil {
return err
}
nodePath := SrvVSchemaFile
return conn.Delete(ctx, nodePath, nil)
} | [
"func",
"(",
"ts",
"*",
"Server",
")",
"DeleteSrvVSchema",
"(",
"ctx",
"context",
".",
"Context",
",",
"cell",
"string",
")",
"error",
"{",
"conn",
",",
"err",
":=",
"ts",
".",
"ConnForCell",
"(",
"ctx",
",",
"cell",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"nodePath",
":=",
"SrvVSchemaFile",
"\n",
"return",
"conn",
".",
"Delete",
"(",
"ctx",
",",
"nodePath",
",",
"nil",
")",
"\n",
"}"
] | // DeleteSrvVSchema deletes the SrvVSchema file for a cell. | [
"DeleteSrvVSchema",
"deletes",
"the",
"SrvVSchema",
"file",
"for",
"a",
"cell",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/srv_vschema.go#L128-L136 | train |
vitessio/vitess | go/vt/vtgate/engine/delete.go | MarshalJSON | func (del *Delete) MarshalJSON() ([]byte, error) {
var tname, vindexName string
if del.Table != nil {
tname = del.Table.Name.String()
}
if del.Vindex != nil {
vindexName = del.Vindex.String()
}
marshalDelete := struct {
Opcode DeleteOpcode
Keyspace *vindexes.Keyspace `json:",omitempty"`
Query string `json:",omitempty"`
Vindex string `json:",omitempty"`
Values []sqltypes.PlanValue `json:",omitempty"`
Table string `json:",omitempty"`
OwnedVindexQuery string `json:",omitempty"`
MultiShardAutocommit bool `json:",omitempty"`
QueryTimeout int `json:",omitempty"`
}{
Opcode: del.Opcode,
Keyspace: del.Keyspace,
Query: del.Query,
Vindex: vindexName,
Values: del.Values,
Table: tname,
OwnedVindexQuery: del.OwnedVindexQuery,
MultiShardAutocommit: del.MultiShardAutocommit,
QueryTimeout: del.QueryTimeout,
}
return jsonutil.MarshalNoEscape(marshalDelete)
} | go | func (del *Delete) MarshalJSON() ([]byte, error) {
var tname, vindexName string
if del.Table != nil {
tname = del.Table.Name.String()
}
if del.Vindex != nil {
vindexName = del.Vindex.String()
}
marshalDelete := struct {
Opcode DeleteOpcode
Keyspace *vindexes.Keyspace `json:",omitempty"`
Query string `json:",omitempty"`
Vindex string `json:",omitempty"`
Values []sqltypes.PlanValue `json:",omitempty"`
Table string `json:",omitempty"`
OwnedVindexQuery string `json:",omitempty"`
MultiShardAutocommit bool `json:",omitempty"`
QueryTimeout int `json:",omitempty"`
}{
Opcode: del.Opcode,
Keyspace: del.Keyspace,
Query: del.Query,
Vindex: vindexName,
Values: del.Values,
Table: tname,
OwnedVindexQuery: del.OwnedVindexQuery,
MultiShardAutocommit: del.MultiShardAutocommit,
QueryTimeout: del.QueryTimeout,
}
return jsonutil.MarshalNoEscape(marshalDelete)
} | [
"func",
"(",
"del",
"*",
"Delete",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"tname",
",",
"vindexName",
"string",
"\n",
"if",
"del",
".",
"Table",
"!=",
"nil",
"{",
"tname",
"=",
"del",
".",
"Table",
".",
"Name",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"if",
"del",
".",
"Vindex",
"!=",
"nil",
"{",
"vindexName",
"=",
"del",
".",
"Vindex",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"marshalDelete",
":=",
"struct",
"{",
"Opcode",
"DeleteOpcode",
"\n",
"Keyspace",
"*",
"vindexes",
".",
"Keyspace",
"`json:\",omitempty\"`",
"\n",
"Query",
"string",
"`json:\",omitempty\"`",
"\n",
"Vindex",
"string",
"`json:\",omitempty\"`",
"\n",
"Values",
"[",
"]",
"sqltypes",
".",
"PlanValue",
"`json:\",omitempty\"`",
"\n",
"Table",
"string",
"`json:\",omitempty\"`",
"\n",
"OwnedVindexQuery",
"string",
"`json:\",omitempty\"`",
"\n",
"MultiShardAutocommit",
"bool",
"`json:\",omitempty\"`",
"\n",
"QueryTimeout",
"int",
"`json:\",omitempty\"`",
"\n",
"}",
"{",
"Opcode",
":",
"del",
".",
"Opcode",
",",
"Keyspace",
":",
"del",
".",
"Keyspace",
",",
"Query",
":",
"del",
".",
"Query",
",",
"Vindex",
":",
"vindexName",
",",
"Values",
":",
"del",
".",
"Values",
",",
"Table",
":",
"tname",
",",
"OwnedVindexQuery",
":",
"del",
".",
"OwnedVindexQuery",
",",
"MultiShardAutocommit",
":",
"del",
".",
"MultiShardAutocommit",
",",
"QueryTimeout",
":",
"del",
".",
"QueryTimeout",
",",
"}",
"\n",
"return",
"jsonutil",
".",
"MarshalNoEscape",
"(",
"marshalDelete",
")",
"\n",
"}"
] | // MarshalJSON serializes the Delete into a JSON representation.
// It's used for testing and diagnostics. | [
"MarshalJSON",
"serializes",
"the",
"Delete",
"into",
"a",
"JSON",
"representation",
".",
"It",
"s",
"used",
"for",
"testing",
"and",
"diagnostics",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/engine/delete.go#L74-L104 | train |
vitessio/vitess | go/vt/topo/keyspace.go | GetServedFrom | func (ki *KeyspaceInfo) GetServedFrom(tabletType topodatapb.TabletType) *topodatapb.Keyspace_ServedFrom {
for _, ksf := range ki.ServedFroms {
if ksf.TabletType == tabletType {
return ksf
}
}
return nil
} | go | func (ki *KeyspaceInfo) GetServedFrom(tabletType topodatapb.TabletType) *topodatapb.Keyspace_ServedFrom {
for _, ksf := range ki.ServedFroms {
if ksf.TabletType == tabletType {
return ksf
}
}
return nil
} | [
"func",
"(",
"ki",
"*",
"KeyspaceInfo",
")",
"GetServedFrom",
"(",
"tabletType",
"topodatapb",
".",
"TabletType",
")",
"*",
"topodatapb",
".",
"Keyspace_ServedFrom",
"{",
"for",
"_",
",",
"ksf",
":=",
"range",
"ki",
".",
"ServedFroms",
"{",
"if",
"ksf",
".",
"TabletType",
"==",
"tabletType",
"{",
"return",
"ksf",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // GetServedFrom returns a Keyspace_ServedFrom record if it exists. | [
"GetServedFrom",
"returns",
"a",
"Keyspace_ServedFrom",
"record",
"if",
"it",
"exists",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/keyspace.go#L53-L60 | train |
vitessio/vitess | go/vt/topo/keyspace.go | CheckServedFromMigration | func (ki *KeyspaceInfo) CheckServedFromMigration(tabletType topodatapb.TabletType, cells []string, keyspace string, remove bool) error {
// master is a special case with a few extra checks
if tabletType == topodatapb.TabletType_MASTER {
if !remove {
return vterrors.Errorf(vtrpc.Code_FAILED_PRECONDITION, "cannot add master back to %v", ki.keyspace)
}
if len(cells) > 0 {
return vterrors.Errorf(vtrpc.Code_FAILED_PRECONDITION, "cannot migrate only some cells for master removal in keyspace %v", ki.keyspace)
}
if len(ki.ServedFroms) > 1 {
return vterrors.Errorf(vtrpc.Code_FAILED_PRECONDITION, "cannot migrate master into %v until everything else is migrated", ki.keyspace)
}
}
// we can't remove a type we don't have
if ki.GetServedFrom(tabletType) == nil && remove {
return vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "supplied type cannot be migrated")
}
// check the keyspace is consistent in any case
for _, ksf := range ki.ServedFroms {
if ksf.Keyspace != keyspace {
return vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "inconsistent keypace specified in migration: %v != %v for type %v", keyspace, ksf.Keyspace, ksf.TabletType)
}
}
return nil
} | go | func (ki *KeyspaceInfo) CheckServedFromMigration(tabletType topodatapb.TabletType, cells []string, keyspace string, remove bool) error {
// master is a special case with a few extra checks
if tabletType == topodatapb.TabletType_MASTER {
if !remove {
return vterrors.Errorf(vtrpc.Code_FAILED_PRECONDITION, "cannot add master back to %v", ki.keyspace)
}
if len(cells) > 0 {
return vterrors.Errorf(vtrpc.Code_FAILED_PRECONDITION, "cannot migrate only some cells for master removal in keyspace %v", ki.keyspace)
}
if len(ki.ServedFroms) > 1 {
return vterrors.Errorf(vtrpc.Code_FAILED_PRECONDITION, "cannot migrate master into %v until everything else is migrated", ki.keyspace)
}
}
// we can't remove a type we don't have
if ki.GetServedFrom(tabletType) == nil && remove {
return vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "supplied type cannot be migrated")
}
// check the keyspace is consistent in any case
for _, ksf := range ki.ServedFroms {
if ksf.Keyspace != keyspace {
return vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "inconsistent keypace specified in migration: %v != %v for type %v", keyspace, ksf.Keyspace, ksf.TabletType)
}
}
return nil
} | [
"func",
"(",
"ki",
"*",
"KeyspaceInfo",
")",
"CheckServedFromMigration",
"(",
"tabletType",
"topodatapb",
".",
"TabletType",
",",
"cells",
"[",
"]",
"string",
",",
"keyspace",
"string",
",",
"remove",
"bool",
")",
"error",
"{",
"// master is a special case with a few extra checks",
"if",
"tabletType",
"==",
"topodatapb",
".",
"TabletType_MASTER",
"{",
"if",
"!",
"remove",
"{",
"return",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_FAILED_PRECONDITION",
",",
"\"",
"\"",
",",
"ki",
".",
"keyspace",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"cells",
")",
">",
"0",
"{",
"return",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_FAILED_PRECONDITION",
",",
"\"",
"\"",
",",
"ki",
".",
"keyspace",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"ki",
".",
"ServedFroms",
")",
">",
"1",
"{",
"return",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_FAILED_PRECONDITION",
",",
"\"",
"\"",
",",
"ki",
".",
"keyspace",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// we can't remove a type we don't have",
"if",
"ki",
".",
"GetServedFrom",
"(",
"tabletType",
")",
"==",
"nil",
"&&",
"remove",
"{",
"return",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_INVALID_ARGUMENT",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// check the keyspace is consistent in any case",
"for",
"_",
",",
"ksf",
":=",
"range",
"ki",
".",
"ServedFroms",
"{",
"if",
"ksf",
".",
"Keyspace",
"!=",
"keyspace",
"{",
"return",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_INVALID_ARGUMENT",
",",
"\"",
"\"",
",",
"keyspace",
",",
"ksf",
".",
"Keyspace",
",",
"ksf",
".",
"TabletType",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // CheckServedFromMigration makes sure a requested migration is safe | [
"CheckServedFromMigration",
"makes",
"sure",
"a",
"requested",
"migration",
"is",
"safe"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/keyspace.go#L63-L90 | train |
vitessio/vitess | go/vt/topo/keyspace.go | UpdateServedFromMap | func (ki *KeyspaceInfo) UpdateServedFromMap(tabletType topodatapb.TabletType, cells []string, keyspace string, remove bool, allCells []string) error {
// check parameters to be sure
if err := ki.CheckServedFromMigration(tabletType, cells, keyspace, remove); err != nil {
return err
}
ksf := ki.GetServedFrom(tabletType)
if ksf == nil {
// the record doesn't exist
if remove {
if len(ki.ServedFroms) == 0 {
ki.ServedFroms = nil
}
log.Warningf("Trying to remove KeyspaceServedFrom for missing type %v in keyspace %v", tabletType, ki.keyspace)
} else {
ki.ServedFroms = append(ki.ServedFroms, &topodatapb.Keyspace_ServedFrom{
TabletType: tabletType,
Cells: cells,
Keyspace: keyspace,
})
}
return nil
}
if remove {
result, emptyList := removeCells(ksf.Cells, cells, allCells)
if emptyList {
// we don't have any cell left, we need to clear this record
var newServedFroms []*topodatapb.Keyspace_ServedFrom
for _, k := range ki.ServedFroms {
if k != ksf {
newServedFroms = append(newServedFroms, k)
}
}
ki.ServedFroms = newServedFroms
} else {
ksf.Cells = result
}
} else {
if ksf.Keyspace != keyspace {
return vterrors.Errorf(vtrpc.Code_FAILED_PRECONDITION, "cannot UpdateServedFromMap on existing record for keyspace %v, different keyspace: %v != %v", ki.keyspace, ksf.Keyspace, keyspace)
}
ksf.Cells = addCells(ksf.Cells, cells)
}
return nil
} | go | func (ki *KeyspaceInfo) UpdateServedFromMap(tabletType topodatapb.TabletType, cells []string, keyspace string, remove bool, allCells []string) error {
// check parameters to be sure
if err := ki.CheckServedFromMigration(tabletType, cells, keyspace, remove); err != nil {
return err
}
ksf := ki.GetServedFrom(tabletType)
if ksf == nil {
// the record doesn't exist
if remove {
if len(ki.ServedFroms) == 0 {
ki.ServedFroms = nil
}
log.Warningf("Trying to remove KeyspaceServedFrom for missing type %v in keyspace %v", tabletType, ki.keyspace)
} else {
ki.ServedFroms = append(ki.ServedFroms, &topodatapb.Keyspace_ServedFrom{
TabletType: tabletType,
Cells: cells,
Keyspace: keyspace,
})
}
return nil
}
if remove {
result, emptyList := removeCells(ksf.Cells, cells, allCells)
if emptyList {
// we don't have any cell left, we need to clear this record
var newServedFroms []*topodatapb.Keyspace_ServedFrom
for _, k := range ki.ServedFroms {
if k != ksf {
newServedFroms = append(newServedFroms, k)
}
}
ki.ServedFroms = newServedFroms
} else {
ksf.Cells = result
}
} else {
if ksf.Keyspace != keyspace {
return vterrors.Errorf(vtrpc.Code_FAILED_PRECONDITION, "cannot UpdateServedFromMap on existing record for keyspace %v, different keyspace: %v != %v", ki.keyspace, ksf.Keyspace, keyspace)
}
ksf.Cells = addCells(ksf.Cells, cells)
}
return nil
} | [
"func",
"(",
"ki",
"*",
"KeyspaceInfo",
")",
"UpdateServedFromMap",
"(",
"tabletType",
"topodatapb",
".",
"TabletType",
",",
"cells",
"[",
"]",
"string",
",",
"keyspace",
"string",
",",
"remove",
"bool",
",",
"allCells",
"[",
"]",
"string",
")",
"error",
"{",
"// check parameters to be sure",
"if",
"err",
":=",
"ki",
".",
"CheckServedFromMigration",
"(",
"tabletType",
",",
"cells",
",",
"keyspace",
",",
"remove",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"ksf",
":=",
"ki",
".",
"GetServedFrom",
"(",
"tabletType",
")",
"\n",
"if",
"ksf",
"==",
"nil",
"{",
"// the record doesn't exist",
"if",
"remove",
"{",
"if",
"len",
"(",
"ki",
".",
"ServedFroms",
")",
"==",
"0",
"{",
"ki",
".",
"ServedFroms",
"=",
"nil",
"\n",
"}",
"\n",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"tabletType",
",",
"ki",
".",
"keyspace",
")",
"\n",
"}",
"else",
"{",
"ki",
".",
"ServedFroms",
"=",
"append",
"(",
"ki",
".",
"ServedFroms",
",",
"&",
"topodatapb",
".",
"Keyspace_ServedFrom",
"{",
"TabletType",
":",
"tabletType",
",",
"Cells",
":",
"cells",
",",
"Keyspace",
":",
"keyspace",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"remove",
"{",
"result",
",",
"emptyList",
":=",
"removeCells",
"(",
"ksf",
".",
"Cells",
",",
"cells",
",",
"allCells",
")",
"\n",
"if",
"emptyList",
"{",
"// we don't have any cell left, we need to clear this record",
"var",
"newServedFroms",
"[",
"]",
"*",
"topodatapb",
".",
"Keyspace_ServedFrom",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"ki",
".",
"ServedFroms",
"{",
"if",
"k",
"!=",
"ksf",
"{",
"newServedFroms",
"=",
"append",
"(",
"newServedFroms",
",",
"k",
")",
"\n",
"}",
"\n",
"}",
"\n",
"ki",
".",
"ServedFroms",
"=",
"newServedFroms",
"\n",
"}",
"else",
"{",
"ksf",
".",
"Cells",
"=",
"result",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"ksf",
".",
"Keyspace",
"!=",
"keyspace",
"{",
"return",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_FAILED_PRECONDITION",
",",
"\"",
"\"",
",",
"ki",
".",
"keyspace",
",",
"ksf",
".",
"Keyspace",
",",
"keyspace",
")",
"\n",
"}",
"\n",
"ksf",
".",
"Cells",
"=",
"addCells",
"(",
"ksf",
".",
"Cells",
",",
"cells",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // UpdateServedFromMap handles ServedFromMap. It can add or remove
// records, cells, ... | [
"UpdateServedFromMap",
"handles",
"ServedFromMap",
".",
"It",
"can",
"add",
"or",
"remove",
"records",
"cells",
"..."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/keyspace.go#L94-L139 | train |
vitessio/vitess | go/vt/topo/keyspace.go | ComputeCellServedFrom | func (ki *KeyspaceInfo) ComputeCellServedFrom(cell string) []*topodatapb.SrvKeyspace_ServedFrom {
var result []*topodatapb.SrvKeyspace_ServedFrom
for _, ksf := range ki.ServedFroms {
if InCellList(cell, ksf.Cells) {
result = append(result, &topodatapb.SrvKeyspace_ServedFrom{
TabletType: ksf.TabletType,
Keyspace: ksf.Keyspace,
})
}
}
return result
} | go | func (ki *KeyspaceInfo) ComputeCellServedFrom(cell string) []*topodatapb.SrvKeyspace_ServedFrom {
var result []*topodatapb.SrvKeyspace_ServedFrom
for _, ksf := range ki.ServedFroms {
if InCellList(cell, ksf.Cells) {
result = append(result, &topodatapb.SrvKeyspace_ServedFrom{
TabletType: ksf.TabletType,
Keyspace: ksf.Keyspace,
})
}
}
return result
} | [
"func",
"(",
"ki",
"*",
"KeyspaceInfo",
")",
"ComputeCellServedFrom",
"(",
"cell",
"string",
")",
"[",
"]",
"*",
"topodatapb",
".",
"SrvKeyspace_ServedFrom",
"{",
"var",
"result",
"[",
"]",
"*",
"topodatapb",
".",
"SrvKeyspace_ServedFrom",
"\n",
"for",
"_",
",",
"ksf",
":=",
"range",
"ki",
".",
"ServedFroms",
"{",
"if",
"InCellList",
"(",
"cell",
",",
"ksf",
".",
"Cells",
")",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"&",
"topodatapb",
".",
"SrvKeyspace_ServedFrom",
"{",
"TabletType",
":",
"ksf",
".",
"TabletType",
",",
"Keyspace",
":",
"ksf",
".",
"Keyspace",
",",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // ComputeCellServedFrom returns the ServedFrom list for a cell | [
"ComputeCellServedFrom",
"returns",
"the",
"ServedFrom",
"list",
"for",
"a",
"cell"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/keyspace.go#L142-L153 | train |
vitessio/vitess | go/vt/topo/keyspace.go | CreateKeyspace | func (ts *Server) CreateKeyspace(ctx context.Context, keyspace string, value *topodatapb.Keyspace) error {
data, err := proto.Marshal(value)
if err != nil {
return err
}
keyspacePath := path.Join(KeyspacesPath, keyspace, KeyspaceFile)
if _, err := ts.globalCell.Create(ctx, keyspacePath, data); err != nil {
return err
}
event.Dispatch(&events.KeyspaceChange{
KeyspaceName: keyspace,
Keyspace: value,
Status: "created",
})
return nil
} | go | func (ts *Server) CreateKeyspace(ctx context.Context, keyspace string, value *topodatapb.Keyspace) error {
data, err := proto.Marshal(value)
if err != nil {
return err
}
keyspacePath := path.Join(KeyspacesPath, keyspace, KeyspaceFile)
if _, err := ts.globalCell.Create(ctx, keyspacePath, data); err != nil {
return err
}
event.Dispatch(&events.KeyspaceChange{
KeyspaceName: keyspace,
Keyspace: value,
Status: "created",
})
return nil
} | [
"func",
"(",
"ts",
"*",
"Server",
")",
"CreateKeyspace",
"(",
"ctx",
"context",
".",
"Context",
",",
"keyspace",
"string",
",",
"value",
"*",
"topodatapb",
".",
"Keyspace",
")",
"error",
"{",
"data",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"keyspacePath",
":=",
"path",
".",
"Join",
"(",
"KeyspacesPath",
",",
"keyspace",
",",
"KeyspaceFile",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"ts",
".",
"globalCell",
".",
"Create",
"(",
"ctx",
",",
"keyspacePath",
",",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"event",
".",
"Dispatch",
"(",
"&",
"events",
".",
"KeyspaceChange",
"{",
"KeyspaceName",
":",
"keyspace",
",",
"Keyspace",
":",
"value",
",",
"Status",
":",
"\"",
"\"",
",",
"}",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // CreateKeyspace wraps the underlying Conn.Create
// and dispatches the event. | [
"CreateKeyspace",
"wraps",
"the",
"underlying",
"Conn",
".",
"Create",
"and",
"dispatches",
"the",
"event",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/keyspace.go#L157-L173 | train |
vitessio/vitess | go/vt/topo/keyspace.go | GetKeyspace | func (ts *Server) GetKeyspace(ctx context.Context, keyspace string) (*KeyspaceInfo, error) {
keyspacePath := path.Join(KeyspacesPath, keyspace, KeyspaceFile)
data, version, err := ts.globalCell.Get(ctx, keyspacePath)
if err != nil {
return nil, err
}
k := &topodatapb.Keyspace{}
if err = proto.Unmarshal(data, k); err != nil {
return nil, vterrors.Wrap(err, "bad keyspace data")
}
return &KeyspaceInfo{
keyspace: keyspace,
version: version,
Keyspace: k,
}, nil
} | go | func (ts *Server) GetKeyspace(ctx context.Context, keyspace string) (*KeyspaceInfo, error) {
keyspacePath := path.Join(KeyspacesPath, keyspace, KeyspaceFile)
data, version, err := ts.globalCell.Get(ctx, keyspacePath)
if err != nil {
return nil, err
}
k := &topodatapb.Keyspace{}
if err = proto.Unmarshal(data, k); err != nil {
return nil, vterrors.Wrap(err, "bad keyspace data")
}
return &KeyspaceInfo{
keyspace: keyspace,
version: version,
Keyspace: k,
}, nil
} | [
"func",
"(",
"ts",
"*",
"Server",
")",
"GetKeyspace",
"(",
"ctx",
"context",
".",
"Context",
",",
"keyspace",
"string",
")",
"(",
"*",
"KeyspaceInfo",
",",
"error",
")",
"{",
"keyspacePath",
":=",
"path",
".",
"Join",
"(",
"KeyspacesPath",
",",
"keyspace",
",",
"KeyspaceFile",
")",
"\n",
"data",
",",
"version",
",",
"err",
":=",
"ts",
".",
"globalCell",
".",
"Get",
"(",
"ctx",
",",
"keyspacePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"k",
":=",
"&",
"topodatapb",
".",
"Keyspace",
"{",
"}",
"\n",
"if",
"err",
"=",
"proto",
".",
"Unmarshal",
"(",
"data",
",",
"k",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"vterrors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"KeyspaceInfo",
"{",
"keyspace",
":",
"keyspace",
",",
"version",
":",
"version",
",",
"Keyspace",
":",
"k",
",",
"}",
",",
"nil",
"\n",
"}"
] | // GetKeyspace reads the given keyspace and returns it | [
"GetKeyspace",
"reads",
"the",
"given",
"keyspace",
"and",
"returns",
"it"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/keyspace.go#L176-L193 | train |
vitessio/vitess | go/vt/topo/keyspace.go | UpdateKeyspace | func (ts *Server) UpdateKeyspace(ctx context.Context, ki *KeyspaceInfo) error {
// make sure it is locked first
if err := CheckKeyspaceLocked(ctx, ki.keyspace); err != nil {
return err
}
data, err := proto.Marshal(ki.Keyspace)
if err != nil {
return err
}
keyspacePath := path.Join(KeyspacesPath, ki.keyspace, KeyspaceFile)
version, err := ts.globalCell.Update(ctx, keyspacePath, data, ki.version)
if err != nil {
return err
}
ki.version = version
event.Dispatch(&events.KeyspaceChange{
KeyspaceName: ki.keyspace,
Keyspace: ki.Keyspace,
Status: "updated",
})
return nil
} | go | func (ts *Server) UpdateKeyspace(ctx context.Context, ki *KeyspaceInfo) error {
// make sure it is locked first
if err := CheckKeyspaceLocked(ctx, ki.keyspace); err != nil {
return err
}
data, err := proto.Marshal(ki.Keyspace)
if err != nil {
return err
}
keyspacePath := path.Join(KeyspacesPath, ki.keyspace, KeyspaceFile)
version, err := ts.globalCell.Update(ctx, keyspacePath, data, ki.version)
if err != nil {
return err
}
ki.version = version
event.Dispatch(&events.KeyspaceChange{
KeyspaceName: ki.keyspace,
Keyspace: ki.Keyspace,
Status: "updated",
})
return nil
} | [
"func",
"(",
"ts",
"*",
"Server",
")",
"UpdateKeyspace",
"(",
"ctx",
"context",
".",
"Context",
",",
"ki",
"*",
"KeyspaceInfo",
")",
"error",
"{",
"// make sure it is locked first",
"if",
"err",
":=",
"CheckKeyspaceLocked",
"(",
"ctx",
",",
"ki",
".",
"keyspace",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"data",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"ki",
".",
"Keyspace",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"keyspacePath",
":=",
"path",
".",
"Join",
"(",
"KeyspacesPath",
",",
"ki",
".",
"keyspace",
",",
"KeyspaceFile",
")",
"\n",
"version",
",",
"err",
":=",
"ts",
".",
"globalCell",
".",
"Update",
"(",
"ctx",
",",
"keyspacePath",
",",
"data",
",",
"ki",
".",
"version",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ki",
".",
"version",
"=",
"version",
"\n\n",
"event",
".",
"Dispatch",
"(",
"&",
"events",
".",
"KeyspaceChange",
"{",
"KeyspaceName",
":",
"ki",
".",
"keyspace",
",",
"Keyspace",
":",
"ki",
".",
"Keyspace",
",",
"Status",
":",
"\"",
"\"",
",",
"}",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // UpdateKeyspace updates the keyspace data. It checks the keyspace is locked. | [
"UpdateKeyspace",
"updates",
"the",
"keyspace",
"data",
".",
"It",
"checks",
"the",
"keyspace",
"is",
"locked",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/keyspace.go#L196-L219 | train |
vitessio/vitess | go/vt/topo/keyspace.go | FindAllShardsInKeyspace | func (ts *Server) FindAllShardsInKeyspace(ctx context.Context, keyspace string) (map[string]*ShardInfo, error) {
shards, err := ts.GetShardNames(ctx, keyspace)
if err != nil {
return nil, vterrors.Wrapf(err, "failed to get list of shards for keyspace '%v'", keyspace)
}
result := make(map[string]*ShardInfo, len(shards))
wg := sync.WaitGroup{}
mu := sync.Mutex{}
rec := concurrency.FirstErrorRecorder{}
for _, shard := range shards {
wg.Add(1)
go func(shard string) {
defer wg.Done()
si, err := ts.GetShard(ctx, keyspace, shard)
if err != nil {
if IsErrType(err, NoNode) {
log.Warningf("GetShard(%v, %v) returned ErrNoNode, consider checking the topology.", keyspace, shard)
} else {
rec.RecordError(vterrors.Wrapf(err, "GetShard(%v, %v) failed", keyspace, shard))
}
return
}
mu.Lock()
result[shard] = si
mu.Unlock()
}(shard)
}
wg.Wait()
if rec.HasErrors() {
return nil, rec.Error()
}
return result, nil
} | go | func (ts *Server) FindAllShardsInKeyspace(ctx context.Context, keyspace string) (map[string]*ShardInfo, error) {
shards, err := ts.GetShardNames(ctx, keyspace)
if err != nil {
return nil, vterrors.Wrapf(err, "failed to get list of shards for keyspace '%v'", keyspace)
}
result := make(map[string]*ShardInfo, len(shards))
wg := sync.WaitGroup{}
mu := sync.Mutex{}
rec := concurrency.FirstErrorRecorder{}
for _, shard := range shards {
wg.Add(1)
go func(shard string) {
defer wg.Done()
si, err := ts.GetShard(ctx, keyspace, shard)
if err != nil {
if IsErrType(err, NoNode) {
log.Warningf("GetShard(%v, %v) returned ErrNoNode, consider checking the topology.", keyspace, shard)
} else {
rec.RecordError(vterrors.Wrapf(err, "GetShard(%v, %v) failed", keyspace, shard))
}
return
}
mu.Lock()
result[shard] = si
mu.Unlock()
}(shard)
}
wg.Wait()
if rec.HasErrors() {
return nil, rec.Error()
}
return result, nil
} | [
"func",
"(",
"ts",
"*",
"Server",
")",
"FindAllShardsInKeyspace",
"(",
"ctx",
"context",
".",
"Context",
",",
"keyspace",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"ShardInfo",
",",
"error",
")",
"{",
"shards",
",",
"err",
":=",
"ts",
".",
"GetShardNames",
"(",
"ctx",
",",
"keyspace",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"vterrors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"keyspace",
")",
"\n",
"}",
"\n\n",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"ShardInfo",
",",
"len",
"(",
"shards",
")",
")",
"\n",
"wg",
":=",
"sync",
".",
"WaitGroup",
"{",
"}",
"\n",
"mu",
":=",
"sync",
".",
"Mutex",
"{",
"}",
"\n",
"rec",
":=",
"concurrency",
".",
"FirstErrorRecorder",
"{",
"}",
"\n",
"for",
"_",
",",
"shard",
":=",
"range",
"shards",
"{",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
"shard",
"string",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"si",
",",
"err",
":=",
"ts",
".",
"GetShard",
"(",
"ctx",
",",
"keyspace",
",",
"shard",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"IsErrType",
"(",
"err",
",",
"NoNode",
")",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"keyspace",
",",
"shard",
")",
"\n",
"}",
"else",
"{",
"rec",
".",
"RecordError",
"(",
"vterrors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"keyspace",
",",
"shard",
")",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"mu",
".",
"Lock",
"(",
")",
"\n",
"result",
"[",
"shard",
"]",
"=",
"si",
"\n",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}",
"(",
"shard",
")",
"\n",
"}",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"if",
"rec",
".",
"HasErrors",
"(",
")",
"{",
"return",
"nil",
",",
"rec",
".",
"Error",
"(",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // FindAllShardsInKeyspace reads and returns all the existing shards in
// a keyspace. It doesn't take any lock. | [
"FindAllShardsInKeyspace",
"reads",
"and",
"returns",
"all",
"the",
"existing",
"shards",
"in",
"a",
"keyspace",
".",
"It",
"doesn",
"t",
"take",
"any",
"lock",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/keyspace.go#L223-L256 | train |
vitessio/vitess | go/vt/topo/keyspace.go | GetOnlyShard | func (ts *Server) GetOnlyShard(ctx context.Context, keyspace string) (*ShardInfo, error) {
allShards, err := ts.FindAllShardsInKeyspace(ctx, keyspace)
if err != nil {
return nil, err
}
if len(allShards) == 1 {
for _, s := range allShards {
return s, nil
}
}
return nil, vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "keyspace %s must have one and only one shard: %v", keyspace, allShards)
} | go | func (ts *Server) GetOnlyShard(ctx context.Context, keyspace string) (*ShardInfo, error) {
allShards, err := ts.FindAllShardsInKeyspace(ctx, keyspace)
if err != nil {
return nil, err
}
if len(allShards) == 1 {
for _, s := range allShards {
return s, nil
}
}
return nil, vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "keyspace %s must have one and only one shard: %v", keyspace, allShards)
} | [
"func",
"(",
"ts",
"*",
"Server",
")",
"GetOnlyShard",
"(",
"ctx",
"context",
".",
"Context",
",",
"keyspace",
"string",
")",
"(",
"*",
"ShardInfo",
",",
"error",
")",
"{",
"allShards",
",",
"err",
":=",
"ts",
".",
"FindAllShardsInKeyspace",
"(",
"ctx",
",",
"keyspace",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"allShards",
")",
"==",
"1",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"allShards",
"{",
"return",
"s",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_INVALID_ARGUMENT",
",",
"\"",
"\"",
",",
"keyspace",
",",
"allShards",
")",
"\n",
"}"
] | // GetOnlyShard returns the single ShardInfo of an unsharded keyspace. | [
"GetOnlyShard",
"returns",
"the",
"single",
"ShardInfo",
"of",
"an",
"unsharded",
"keyspace",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/keyspace.go#L259-L270 | train |
vitessio/vitess | go/vt/topo/keyspace.go | DeleteKeyspace | func (ts *Server) DeleteKeyspace(ctx context.Context, keyspace string) error {
keyspacePath := path.Join(KeyspacesPath, keyspace, KeyspaceFile)
if err := ts.globalCell.Delete(ctx, keyspacePath, nil); err != nil {
return err
}
event.Dispatch(&events.KeyspaceChange{
KeyspaceName: keyspace,
Keyspace: nil,
Status: "deleted",
})
return nil
} | go | func (ts *Server) DeleteKeyspace(ctx context.Context, keyspace string) error {
keyspacePath := path.Join(KeyspacesPath, keyspace, KeyspaceFile)
if err := ts.globalCell.Delete(ctx, keyspacePath, nil); err != nil {
return err
}
event.Dispatch(&events.KeyspaceChange{
KeyspaceName: keyspace,
Keyspace: nil,
Status: "deleted",
})
return nil
} | [
"func",
"(",
"ts",
"*",
"Server",
")",
"DeleteKeyspace",
"(",
"ctx",
"context",
".",
"Context",
",",
"keyspace",
"string",
")",
"error",
"{",
"keyspacePath",
":=",
"path",
".",
"Join",
"(",
"KeyspacesPath",
",",
"keyspace",
",",
"KeyspaceFile",
")",
"\n",
"if",
"err",
":=",
"ts",
".",
"globalCell",
".",
"Delete",
"(",
"ctx",
",",
"keyspacePath",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"event",
".",
"Dispatch",
"(",
"&",
"events",
".",
"KeyspaceChange",
"{",
"KeyspaceName",
":",
"keyspace",
",",
"Keyspace",
":",
"nil",
",",
"Status",
":",
"\"",
"\"",
",",
"}",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // DeleteKeyspace wraps the underlying Conn.Delete
// and dispatches the event. | [
"DeleteKeyspace",
"wraps",
"the",
"underlying",
"Conn",
".",
"Delete",
"and",
"dispatches",
"the",
"event",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/keyspace.go#L274-L285 | train |
vitessio/vitess | go/vt/topo/keyspace.go | GetKeyspaces | func (ts *Server) GetKeyspaces(ctx context.Context) ([]string, error) {
children, err := ts.globalCell.ListDir(ctx, KeyspacesPath, false /*full*/)
switch {
case err == nil:
return DirEntriesToStringArray(children), nil
case IsErrType(err, NoNode):
return nil, nil
default:
return nil, err
}
} | go | func (ts *Server) GetKeyspaces(ctx context.Context) ([]string, error) {
children, err := ts.globalCell.ListDir(ctx, KeyspacesPath, false /*full*/)
switch {
case err == nil:
return DirEntriesToStringArray(children), nil
case IsErrType(err, NoNode):
return nil, nil
default:
return nil, err
}
} | [
"func",
"(",
"ts",
"*",
"Server",
")",
"GetKeyspaces",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"children",
",",
"err",
":=",
"ts",
".",
"globalCell",
".",
"ListDir",
"(",
"ctx",
",",
"KeyspacesPath",
",",
"false",
"/*full*/",
")",
"\n",
"switch",
"{",
"case",
"err",
"==",
"nil",
":",
"return",
"DirEntriesToStringArray",
"(",
"children",
")",
",",
"nil",
"\n",
"case",
"IsErrType",
"(",
"err",
",",
"NoNode",
")",
":",
"return",
"nil",
",",
"nil",
"\n",
"default",
":",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}"
] | // GetKeyspaces returns the list of keyspaces in the topology. | [
"GetKeyspaces",
"returns",
"the",
"list",
"of",
"keyspaces",
"in",
"the",
"topology",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/keyspace.go#L288-L298 | train |
vitessio/vitess | go/vt/topo/keyspace.go | GetShardNames | func (ts *Server) GetShardNames(ctx context.Context, keyspace string) ([]string, error) {
shardsPath := path.Join(KeyspacesPath, keyspace, ShardsPath)
children, err := ts.globalCell.ListDir(ctx, shardsPath, false /*full*/)
if IsErrType(err, NoNode) {
// The directory doesn't exist, let's see if the keyspace
// is here or not.
_, kerr := ts.GetKeyspace(ctx, keyspace)
if kerr == nil {
// Keyspace is here, means no shards.
return nil, nil
}
return nil, err
}
return DirEntriesToStringArray(children), err
} | go | func (ts *Server) GetShardNames(ctx context.Context, keyspace string) ([]string, error) {
shardsPath := path.Join(KeyspacesPath, keyspace, ShardsPath)
children, err := ts.globalCell.ListDir(ctx, shardsPath, false /*full*/)
if IsErrType(err, NoNode) {
// The directory doesn't exist, let's see if the keyspace
// is here or not.
_, kerr := ts.GetKeyspace(ctx, keyspace)
if kerr == nil {
// Keyspace is here, means no shards.
return nil, nil
}
return nil, err
}
return DirEntriesToStringArray(children), err
} | [
"func",
"(",
"ts",
"*",
"Server",
")",
"GetShardNames",
"(",
"ctx",
"context",
".",
"Context",
",",
"keyspace",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"shardsPath",
":=",
"path",
".",
"Join",
"(",
"KeyspacesPath",
",",
"keyspace",
",",
"ShardsPath",
")",
"\n",
"children",
",",
"err",
":=",
"ts",
".",
"globalCell",
".",
"ListDir",
"(",
"ctx",
",",
"shardsPath",
",",
"false",
"/*full*/",
")",
"\n",
"if",
"IsErrType",
"(",
"err",
",",
"NoNode",
")",
"{",
"// The directory doesn't exist, let's see if the keyspace",
"// is here or not.",
"_",
",",
"kerr",
":=",
"ts",
".",
"GetKeyspace",
"(",
"ctx",
",",
"keyspace",
")",
"\n",
"if",
"kerr",
"==",
"nil",
"{",
"// Keyspace is here, means no shards.",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"DirEntriesToStringArray",
"(",
"children",
")",
",",
"err",
"\n",
"}"
] | // GetShardNames returns the list of shards in a keyspace. | [
"GetShardNames",
"returns",
"the",
"list",
"of",
"shards",
"in",
"a",
"keyspace",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/keyspace.go#L301-L315 | train |
vitessio/vitess | go/vt/worker/vtworkerclient/interface.go | RegisterFactory | func RegisterFactory(name string, factory Factory) {
if _, ok := factories[name]; ok {
log.Fatalf("RegisterFactory: %s already exists", name)
}
factories[name] = factory
} | go | func RegisterFactory(name string, factory Factory) {
if _, ok := factories[name]; ok {
log.Fatalf("RegisterFactory: %s already exists", name)
}
factories[name] = factory
} | [
"func",
"RegisterFactory",
"(",
"name",
"string",
",",
"factory",
"Factory",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"factories",
"[",
"name",
"]",
";",
"ok",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"factories",
"[",
"name",
"]",
"=",
"factory",
"\n",
"}"
] | // RegisterFactory allows a client implementation to register itself. | [
"RegisterFactory",
"allows",
"a",
"client",
"implementation",
"to",
"register",
"itself",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/worker/vtworkerclient/interface.go#L49-L54 | train |
vitessio/vitess | go/sync2/semaphore.go | NewSemaphore | func NewSemaphore(count int, timeout time.Duration) *Semaphore {
sem := &Semaphore{
slots: make(chan struct{}, count),
timeout: timeout,
}
for i := 0; i < count; i++ {
sem.slots <- struct{}{}
}
return sem
} | go | func NewSemaphore(count int, timeout time.Duration) *Semaphore {
sem := &Semaphore{
slots: make(chan struct{}, count),
timeout: timeout,
}
for i := 0; i < count; i++ {
sem.slots <- struct{}{}
}
return sem
} | [
"func",
"NewSemaphore",
"(",
"count",
"int",
",",
"timeout",
"time",
".",
"Duration",
")",
"*",
"Semaphore",
"{",
"sem",
":=",
"&",
"Semaphore",
"{",
"slots",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
",",
"count",
")",
",",
"timeout",
":",
"timeout",
",",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"count",
";",
"i",
"++",
"{",
"sem",
".",
"slots",
"<-",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"return",
"sem",
"\n",
"}"
] | // NewSemaphore creates a Semaphore. The count parameter must be a positive
// number. A timeout of zero means that there is no timeout. | [
"NewSemaphore",
"creates",
"a",
"Semaphore",
".",
"The",
"count",
"parameter",
"must",
"be",
"a",
"positive",
"number",
".",
"A",
"timeout",
"of",
"zero",
"means",
"that",
"there",
"is",
"no",
"timeout",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/sync2/semaphore.go#L36-L45 | train |
vitessio/vitess | go/vt/topo/helpers/tee.go | NewTee | func NewTee(primary, secondary *topo.Server, reverseLockOrder bool) (*topo.Server, error) {
f := &TeeFactory{
primary: primary,
secondary: secondary,
reverseLockOrder: reverseLockOrder,
}
return topo.NewWithFactory(f, "" /*serverAddress*/, "" /*root*/)
} | go | func NewTee(primary, secondary *topo.Server, reverseLockOrder bool) (*topo.Server, error) {
f := &TeeFactory{
primary: primary,
secondary: secondary,
reverseLockOrder: reverseLockOrder,
}
return topo.NewWithFactory(f, "" /*serverAddress*/, "" /*root*/)
} | [
"func",
"NewTee",
"(",
"primary",
",",
"secondary",
"*",
"topo",
".",
"Server",
",",
"reverseLockOrder",
"bool",
")",
"(",
"*",
"topo",
".",
"Server",
",",
"error",
")",
"{",
"f",
":=",
"&",
"TeeFactory",
"{",
"primary",
":",
"primary",
",",
"secondary",
":",
"secondary",
",",
"reverseLockOrder",
":",
"reverseLockOrder",
",",
"}",
"\n",
"return",
"topo",
".",
"NewWithFactory",
"(",
"f",
",",
"\"",
"\"",
"/*serverAddress*/",
",",
"\"",
"\"",
"/*root*/",
")",
"\n",
"}"
] | // NewTee returns a new topo.Server object. It uses a TeeFactory. | [
"NewTee",
"returns",
"a",
"new",
"topo",
".",
"Server",
"object",
".",
"It",
"uses",
"a",
"TeeFactory",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/helpers/tee.go#L75-L82 | train |
vitessio/vitess | go/vt/topo/helpers/tee.go | Watch | func (c *TeeConn) Watch(ctx context.Context, filePath string) (*topo.WatchData, <-chan *topo.WatchData, topo.CancelFunc) {
return c.primary.Watch(ctx, filePath)
} | go | func (c *TeeConn) Watch(ctx context.Context, filePath string) (*topo.WatchData, <-chan *topo.WatchData, topo.CancelFunc) {
return c.primary.Watch(ctx, filePath)
} | [
"func",
"(",
"c",
"*",
"TeeConn",
")",
"Watch",
"(",
"ctx",
"context",
".",
"Context",
",",
"filePath",
"string",
")",
"(",
"*",
"topo",
".",
"WatchData",
",",
"<-",
"chan",
"*",
"topo",
".",
"WatchData",
",",
"topo",
".",
"CancelFunc",
")",
"{",
"return",
"c",
".",
"primary",
".",
"Watch",
"(",
"ctx",
",",
"filePath",
")",
"\n",
"}"
] | // Watch is part of the topo.Conn interface | [
"Watch",
"is",
"part",
"of",
"the",
"topo",
".",
"Conn",
"interface"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/helpers/tee.go#L161-L163 | train |
vitessio/vitess | go/vt/topo/helpers/tee.go | NewMasterParticipation | func (c *TeeConn) NewMasterParticipation(name, id string) (topo.MasterParticipation, error) {
return c.primary.NewMasterParticipation(name, id)
} | go | func (c *TeeConn) NewMasterParticipation(name, id string) (topo.MasterParticipation, error) {
return c.primary.NewMasterParticipation(name, id)
} | [
"func",
"(",
"c",
"*",
"TeeConn",
")",
"NewMasterParticipation",
"(",
"name",
",",
"id",
"string",
")",
"(",
"topo",
".",
"MasterParticipation",
",",
"error",
")",
"{",
"return",
"c",
".",
"primary",
".",
"NewMasterParticipation",
"(",
"name",
",",
"id",
")",
"\n",
"}"
] | // NewMasterParticipation is part of the topo.Conn interface. | [
"NewMasterParticipation",
"is",
"part",
"of",
"the",
"topo",
".",
"Conn",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/helpers/tee.go#L227-L229 | train |
vitessio/vitess | go/vt/binlog/grpcbinlogstreamer/streamer.go | StreamKeyRange | func (server *UpdateStream) StreamKeyRange(req *binlogdatapb.StreamKeyRangeRequest, stream binlogservicepb.UpdateStream_StreamKeyRangeServer) (err error) {
defer server.updateStream.HandlePanic(&err)
return server.updateStream.StreamKeyRange(stream.Context(), req.Position, req.KeyRange, req.Charset, func(reply *binlogdatapb.BinlogTransaction) error {
return stream.Send(&binlogdatapb.StreamKeyRangeResponse{
BinlogTransaction: reply,
})
})
} | go | func (server *UpdateStream) StreamKeyRange(req *binlogdatapb.StreamKeyRangeRequest, stream binlogservicepb.UpdateStream_StreamKeyRangeServer) (err error) {
defer server.updateStream.HandlePanic(&err)
return server.updateStream.StreamKeyRange(stream.Context(), req.Position, req.KeyRange, req.Charset, func(reply *binlogdatapb.BinlogTransaction) error {
return stream.Send(&binlogdatapb.StreamKeyRangeResponse{
BinlogTransaction: reply,
})
})
} | [
"func",
"(",
"server",
"*",
"UpdateStream",
")",
"StreamKeyRange",
"(",
"req",
"*",
"binlogdatapb",
".",
"StreamKeyRangeRequest",
",",
"stream",
"binlogservicepb",
".",
"UpdateStream_StreamKeyRangeServer",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"server",
".",
"updateStream",
".",
"HandlePanic",
"(",
"&",
"err",
")",
"\n",
"return",
"server",
".",
"updateStream",
".",
"StreamKeyRange",
"(",
"stream",
".",
"Context",
"(",
")",
",",
"req",
".",
"Position",
",",
"req",
".",
"KeyRange",
",",
"req",
".",
"Charset",
",",
"func",
"(",
"reply",
"*",
"binlogdatapb",
".",
"BinlogTransaction",
")",
"error",
"{",
"return",
"stream",
".",
"Send",
"(",
"&",
"binlogdatapb",
".",
"StreamKeyRangeResponse",
"{",
"BinlogTransaction",
":",
"reply",
",",
"}",
")",
"\n",
"}",
")",
"\n",
"}"
] | // StreamKeyRange is part of the binlogservicepb.UpdateStreamServer interface | [
"StreamKeyRange",
"is",
"part",
"of",
"the",
"binlogservicepb",
".",
"UpdateStreamServer",
"interface"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/binlog/grpcbinlogstreamer/streamer.go#L40-L47 | train |
vitessio/vitess | go/vt/binlog/grpcbinlogstreamer/streamer.go | StreamTables | func (server *UpdateStream) StreamTables(req *binlogdatapb.StreamTablesRequest, stream binlogservicepb.UpdateStream_StreamTablesServer) (err error) {
defer server.updateStream.HandlePanic(&err)
return server.updateStream.StreamTables(stream.Context(), req.Position, req.Tables, req.Charset, func(reply *binlogdatapb.BinlogTransaction) error {
return stream.Send(&binlogdatapb.StreamTablesResponse{
BinlogTransaction: reply,
})
})
} | go | func (server *UpdateStream) StreamTables(req *binlogdatapb.StreamTablesRequest, stream binlogservicepb.UpdateStream_StreamTablesServer) (err error) {
defer server.updateStream.HandlePanic(&err)
return server.updateStream.StreamTables(stream.Context(), req.Position, req.Tables, req.Charset, func(reply *binlogdatapb.BinlogTransaction) error {
return stream.Send(&binlogdatapb.StreamTablesResponse{
BinlogTransaction: reply,
})
})
} | [
"func",
"(",
"server",
"*",
"UpdateStream",
")",
"StreamTables",
"(",
"req",
"*",
"binlogdatapb",
".",
"StreamTablesRequest",
",",
"stream",
"binlogservicepb",
".",
"UpdateStream_StreamTablesServer",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"server",
".",
"updateStream",
".",
"HandlePanic",
"(",
"&",
"err",
")",
"\n",
"return",
"server",
".",
"updateStream",
".",
"StreamTables",
"(",
"stream",
".",
"Context",
"(",
")",
",",
"req",
".",
"Position",
",",
"req",
".",
"Tables",
",",
"req",
".",
"Charset",
",",
"func",
"(",
"reply",
"*",
"binlogdatapb",
".",
"BinlogTransaction",
")",
"error",
"{",
"return",
"stream",
".",
"Send",
"(",
"&",
"binlogdatapb",
".",
"StreamTablesResponse",
"{",
"BinlogTransaction",
":",
"reply",
",",
"}",
")",
"\n",
"}",
")",
"\n",
"}"
] | // StreamTables is part of the binlogservicepb.UpdateStreamServer interface | [
"StreamTables",
"is",
"part",
"of",
"the",
"binlogservicepb",
".",
"UpdateStreamServer",
"interface"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/binlog/grpcbinlogstreamer/streamer.go#L50-L57 | train |
vitessio/vitess | go/mysql/binlog_event_make.go | NewMySQL56BinlogFormat | func NewMySQL56BinlogFormat() BinlogFormat {
return BinlogFormat{
FormatVersion: 4,
ServerVersion: "5.6.33-0ubuntu0.14.04.1-log",
HeaderLength: 19,
ChecksumAlgorithm: BinlogChecksumAlgCRC32, // most commonly used.
HeaderSizes: []byte{
56, 13, 0, 8, 0, 18, 0, 4, 4, 4,
4, 18, 0, 0, 92, 0, 4, 26, 8, 0,
0, 0, 8, 8, 8, 2, 0, 0, 0, 10,
10, 10, 25, 25, 0},
}
} | go | func NewMySQL56BinlogFormat() BinlogFormat {
return BinlogFormat{
FormatVersion: 4,
ServerVersion: "5.6.33-0ubuntu0.14.04.1-log",
HeaderLength: 19,
ChecksumAlgorithm: BinlogChecksumAlgCRC32, // most commonly used.
HeaderSizes: []byte{
56, 13, 0, 8, 0, 18, 0, 4, 4, 4,
4, 18, 0, 0, 92, 0, 4, 26, 8, 0,
0, 0, 8, 8, 8, 2, 0, 0, 0, 10,
10, 10, 25, 25, 0},
}
} | [
"func",
"NewMySQL56BinlogFormat",
"(",
")",
"BinlogFormat",
"{",
"return",
"BinlogFormat",
"{",
"FormatVersion",
":",
"4",
",",
"ServerVersion",
":",
"\"",
"\"",
",",
"HeaderLength",
":",
"19",
",",
"ChecksumAlgorithm",
":",
"BinlogChecksumAlgCRC32",
",",
"// most commonly used.",
"HeaderSizes",
":",
"[",
"]",
"byte",
"{",
"56",
",",
"13",
",",
"0",
",",
"8",
",",
"0",
",",
"18",
",",
"0",
",",
"4",
",",
"4",
",",
"4",
",",
"4",
",",
"18",
",",
"0",
",",
"0",
",",
"92",
",",
"0",
",",
"4",
",",
"26",
",",
"8",
",",
"0",
",",
"0",
",",
"0",
",",
"8",
",",
"8",
",",
"8",
",",
"2",
",",
"0",
",",
"0",
",",
"0",
",",
"10",
",",
"10",
",",
"10",
",",
"25",
",",
"25",
",",
"0",
"}",
",",
"}",
"\n",
"}"
] | // This file contains utility methods to create binlog replication
// packets. They are mostly used for testing.
// NewMySQL56BinlogFormat returns a typical BinlogFormat for MySQL 5.6. | [
"This",
"file",
"contains",
"utility",
"methods",
"to",
"create",
"binlog",
"replication",
"packets",
".",
"They",
"are",
"mostly",
"used",
"for",
"testing",
".",
"NewMySQL56BinlogFormat",
"returns",
"a",
"typical",
"BinlogFormat",
"for",
"MySQL",
"5",
".",
"6",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event_make.go#L27-L39 | train |
vitessio/vitess | go/mysql/binlog_event_make.go | NewMariaDBBinlogFormat | func NewMariaDBBinlogFormat() BinlogFormat {
return BinlogFormat{
FormatVersion: 4,
ServerVersion: "10.0.13-MariaDB-1~precise-log",
HeaderLength: 19,
ChecksumAlgorithm: BinlogChecksumAlgOff,
// HeaderSizes is very long because the MariaDB specific events are indexed at 160+
HeaderSizes: []byte{
56, 13, 0, 8, 0, 18, 0, 4, 4, 4,
4, 18, 0, 0, 220, 0, 4, 26, 8, 0,
0, 0, 8, 8, 8, 2, 0, 0, 0, 10,
10, 10, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4, 19, 4},
}
} | go | func NewMariaDBBinlogFormat() BinlogFormat {
return BinlogFormat{
FormatVersion: 4,
ServerVersion: "10.0.13-MariaDB-1~precise-log",
HeaderLength: 19,
ChecksumAlgorithm: BinlogChecksumAlgOff,
// HeaderSizes is very long because the MariaDB specific events are indexed at 160+
HeaderSizes: []byte{
56, 13, 0, 8, 0, 18, 0, 4, 4, 4,
4, 18, 0, 0, 220, 0, 4, 26, 8, 0,
0, 0, 8, 8, 8, 2, 0, 0, 0, 10,
10, 10, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4, 19, 4},
}
} | [
"func",
"NewMariaDBBinlogFormat",
"(",
")",
"BinlogFormat",
"{",
"return",
"BinlogFormat",
"{",
"FormatVersion",
":",
"4",
",",
"ServerVersion",
":",
"\"",
"\"",
",",
"HeaderLength",
":",
"19",
",",
"ChecksumAlgorithm",
":",
"BinlogChecksumAlgOff",
",",
"// HeaderSizes is very long because the MariaDB specific events are indexed at 160+",
"HeaderSizes",
":",
"[",
"]",
"byte",
"{",
"56",
",",
"13",
",",
"0",
",",
"8",
",",
"0",
",",
"18",
",",
"0",
",",
"4",
",",
"4",
",",
"4",
",",
"4",
",",
"18",
",",
"0",
",",
"0",
",",
"220",
",",
"0",
",",
"4",
",",
"26",
",",
"8",
",",
"0",
",",
"0",
",",
"0",
",",
"8",
",",
"8",
",",
"8",
",",
"2",
",",
"0",
",",
"0",
",",
"0",
",",
"10",
",",
"10",
",",
"10",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"4",
",",
"19",
",",
"4",
"}",
",",
"}",
"\n",
"}"
] | // NewMariaDBBinlogFormat returns a typical BinlogFormat for MariaDB 10.0. | [
"NewMariaDBBinlogFormat",
"returns",
"a",
"typical",
"BinlogFormat",
"for",
"MariaDB",
"10",
".",
"0",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event_make.go#L42-L68 | train |
vitessio/vitess | go/mysql/binlog_event_make.go | Packetize | func (s *FakeBinlogStream) Packetize(f BinlogFormat, typ byte, flags uint16, data []byte) []byte {
length := int(f.HeaderLength) + len(data)
if typ == eFormatDescriptionEvent || f.ChecksumAlgorithm == BinlogChecksumAlgCRC32 {
// Just add 4 zeroes to the end.
length += 4
}
result := make([]byte, length)
binary.LittleEndian.PutUint32(result[0:4], s.Timestamp)
result[4] = typ
binary.LittleEndian.PutUint32(result[5:9], s.ServerID)
binary.LittleEndian.PutUint32(result[9:13], uint32(length))
if f.HeaderLength >= 19 {
binary.LittleEndian.PutUint32(result[13:17], s.LogPosition)
binary.LittleEndian.PutUint16(result[17:19], flags)
}
copy(result[f.HeaderLength:], data)
return result
} | go | func (s *FakeBinlogStream) Packetize(f BinlogFormat, typ byte, flags uint16, data []byte) []byte {
length := int(f.HeaderLength) + len(data)
if typ == eFormatDescriptionEvent || f.ChecksumAlgorithm == BinlogChecksumAlgCRC32 {
// Just add 4 zeroes to the end.
length += 4
}
result := make([]byte, length)
binary.LittleEndian.PutUint32(result[0:4], s.Timestamp)
result[4] = typ
binary.LittleEndian.PutUint32(result[5:9], s.ServerID)
binary.LittleEndian.PutUint32(result[9:13], uint32(length))
if f.HeaderLength >= 19 {
binary.LittleEndian.PutUint32(result[13:17], s.LogPosition)
binary.LittleEndian.PutUint16(result[17:19], flags)
}
copy(result[f.HeaderLength:], data)
return result
} | [
"func",
"(",
"s",
"*",
"FakeBinlogStream",
")",
"Packetize",
"(",
"f",
"BinlogFormat",
",",
"typ",
"byte",
",",
"flags",
"uint16",
",",
"data",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"length",
":=",
"int",
"(",
"f",
".",
"HeaderLength",
")",
"+",
"len",
"(",
"data",
")",
"\n",
"if",
"typ",
"==",
"eFormatDescriptionEvent",
"||",
"f",
".",
"ChecksumAlgorithm",
"==",
"BinlogChecksumAlgCRC32",
"{",
"// Just add 4 zeroes to the end.",
"length",
"+=",
"4",
"\n",
"}",
"\n\n",
"result",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"length",
")",
"\n",
"binary",
".",
"LittleEndian",
".",
"PutUint32",
"(",
"result",
"[",
"0",
":",
"4",
"]",
",",
"s",
".",
"Timestamp",
")",
"\n",
"result",
"[",
"4",
"]",
"=",
"typ",
"\n",
"binary",
".",
"LittleEndian",
".",
"PutUint32",
"(",
"result",
"[",
"5",
":",
"9",
"]",
",",
"s",
".",
"ServerID",
")",
"\n",
"binary",
".",
"LittleEndian",
".",
"PutUint32",
"(",
"result",
"[",
"9",
":",
"13",
"]",
",",
"uint32",
"(",
"length",
")",
")",
"\n",
"if",
"f",
".",
"HeaderLength",
">=",
"19",
"{",
"binary",
".",
"LittleEndian",
".",
"PutUint32",
"(",
"result",
"[",
"13",
":",
"17",
"]",
",",
"s",
".",
"LogPosition",
")",
"\n",
"binary",
".",
"LittleEndian",
".",
"PutUint16",
"(",
"result",
"[",
"17",
":",
"19",
"]",
",",
"flags",
")",
"\n",
"}",
"\n",
"copy",
"(",
"result",
"[",
"f",
".",
"HeaderLength",
":",
"]",
",",
"data",
")",
"\n",
"return",
"result",
"\n",
"}"
] | // Packetize adds the binlog event header to a packet, and optionally
// the checksum. | [
"Packetize",
"adds",
"the",
"binlog",
"event",
"header",
"to",
"a",
"packet",
"and",
"optionally",
"the",
"checksum",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event_make.go#L95-L113 | train |
vitessio/vitess | go/mysql/binlog_event_make.go | NewFormatDescriptionEvent | func NewFormatDescriptionEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent {
length := 2 + // binlog-version
50 + // server version
4 + // create timestamp
1 + // event header length
len(f.HeaderSizes) + // event type header lengths
1 // (undocumented) checksum algorithm
data := make([]byte, length)
binary.LittleEndian.PutUint16(data[0:2], f.FormatVersion)
copy(data[2:52], f.ServerVersion)
binary.LittleEndian.PutUint32(data[52:56], s.Timestamp)
data[56] = f.HeaderLength
copy(data[57:], f.HeaderSizes)
data[57+len(f.HeaderSizes)] = f.ChecksumAlgorithm
ev := s.Packetize(f, eFormatDescriptionEvent, 0, data)
return NewMysql56BinlogEvent(ev)
} | go | func NewFormatDescriptionEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent {
length := 2 + // binlog-version
50 + // server version
4 + // create timestamp
1 + // event header length
len(f.HeaderSizes) + // event type header lengths
1 // (undocumented) checksum algorithm
data := make([]byte, length)
binary.LittleEndian.PutUint16(data[0:2], f.FormatVersion)
copy(data[2:52], f.ServerVersion)
binary.LittleEndian.PutUint32(data[52:56], s.Timestamp)
data[56] = f.HeaderLength
copy(data[57:], f.HeaderSizes)
data[57+len(f.HeaderSizes)] = f.ChecksumAlgorithm
ev := s.Packetize(f, eFormatDescriptionEvent, 0, data)
return NewMysql56BinlogEvent(ev)
} | [
"func",
"NewFormatDescriptionEvent",
"(",
"f",
"BinlogFormat",
",",
"s",
"*",
"FakeBinlogStream",
")",
"BinlogEvent",
"{",
"length",
":=",
"2",
"+",
"// binlog-version",
"50",
"+",
"// server version",
"4",
"+",
"// create timestamp",
"1",
"+",
"// event header length",
"len",
"(",
"f",
".",
"HeaderSizes",
")",
"+",
"// event type header lengths",
"1",
"// (undocumented) checksum algorithm",
"\n",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"length",
")",
"\n",
"binary",
".",
"LittleEndian",
".",
"PutUint16",
"(",
"data",
"[",
"0",
":",
"2",
"]",
",",
"f",
".",
"FormatVersion",
")",
"\n",
"copy",
"(",
"data",
"[",
"2",
":",
"52",
"]",
",",
"f",
".",
"ServerVersion",
")",
"\n",
"binary",
".",
"LittleEndian",
".",
"PutUint32",
"(",
"data",
"[",
"52",
":",
"56",
"]",
",",
"s",
".",
"Timestamp",
")",
"\n",
"data",
"[",
"56",
"]",
"=",
"f",
".",
"HeaderLength",
"\n",
"copy",
"(",
"data",
"[",
"57",
":",
"]",
",",
"f",
".",
"HeaderSizes",
")",
"\n",
"data",
"[",
"57",
"+",
"len",
"(",
"f",
".",
"HeaderSizes",
")",
"]",
"=",
"f",
".",
"ChecksumAlgorithm",
"\n\n",
"ev",
":=",
"s",
".",
"Packetize",
"(",
"f",
",",
"eFormatDescriptionEvent",
",",
"0",
",",
"data",
")",
"\n",
"return",
"NewMysql56BinlogEvent",
"(",
"ev",
")",
"\n",
"}"
] | // NewFormatDescriptionEvent creates a new FormatDescriptionEvent
// based on the provided BinlogFormat. It uses a mysql56BinlogEvent
// but could use a MariaDB one. | [
"NewFormatDescriptionEvent",
"creates",
"a",
"new",
"FormatDescriptionEvent",
"based",
"on",
"the",
"provided",
"BinlogFormat",
".",
"It",
"uses",
"a",
"mysql56BinlogEvent",
"but",
"could",
"use",
"a",
"MariaDB",
"one",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event_make.go#L123-L140 | train |
vitessio/vitess | go/mysql/binlog_event_make.go | NewRotateEvent | func NewRotateEvent(f BinlogFormat, s *FakeBinlogStream, position uint64, filename string) BinlogEvent {
length := 8 + // position
len(filename)
data := make([]byte, length)
binary.LittleEndian.PutUint64(data[0:8], position)
ev := s.Packetize(f, eRotateEvent, 0, data)
ev[0] = 0
ev[1] = 0
ev[2] = 0
ev[3] = 0
return NewMysql56BinlogEvent(ev)
} | go | func NewRotateEvent(f BinlogFormat, s *FakeBinlogStream, position uint64, filename string) BinlogEvent {
length := 8 + // position
len(filename)
data := make([]byte, length)
binary.LittleEndian.PutUint64(data[0:8], position)
ev := s.Packetize(f, eRotateEvent, 0, data)
ev[0] = 0
ev[1] = 0
ev[2] = 0
ev[3] = 0
return NewMysql56BinlogEvent(ev)
} | [
"func",
"NewRotateEvent",
"(",
"f",
"BinlogFormat",
",",
"s",
"*",
"FakeBinlogStream",
",",
"position",
"uint64",
",",
"filename",
"string",
")",
"BinlogEvent",
"{",
"length",
":=",
"8",
"+",
"// position",
"len",
"(",
"filename",
")",
"\n",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"length",
")",
"\n",
"binary",
".",
"LittleEndian",
".",
"PutUint64",
"(",
"data",
"[",
"0",
":",
"8",
"]",
",",
"position",
")",
"\n\n",
"ev",
":=",
"s",
".",
"Packetize",
"(",
"f",
",",
"eRotateEvent",
",",
"0",
",",
"data",
")",
"\n",
"ev",
"[",
"0",
"]",
"=",
"0",
"\n",
"ev",
"[",
"1",
"]",
"=",
"0",
"\n",
"ev",
"[",
"2",
"]",
"=",
"0",
"\n",
"ev",
"[",
"3",
"]",
"=",
"0",
"\n",
"return",
"NewMysql56BinlogEvent",
"(",
"ev",
")",
"\n",
"}"
] | // NewRotateEvent returns a RotateEvent.
// The timestmap of such an event should be zero, so we patch it in. | [
"NewRotateEvent",
"returns",
"a",
"RotateEvent",
".",
"The",
"timestmap",
"of",
"such",
"an",
"event",
"should",
"be",
"zero",
"so",
"we",
"patch",
"it",
"in",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event_make.go#L155-L167 | train |
vitessio/vitess | go/mysql/binlog_event_make.go | NewQueryEvent | func NewQueryEvent(f BinlogFormat, s *FakeBinlogStream, q Query) BinlogEvent {
statusVarLength := 0
if q.Charset != nil {
statusVarLength += 1 + 2 + 2 + 2
}
length := 4 + // slave proxy id
4 + // execution time
1 + // schema length
2 + // error code
2 + // status vars length
statusVarLength +
len(q.Database) + // schema
1 + // [00]
len(q.SQL) // query
data := make([]byte, length)
pos := 8
data[pos] = byte(len(q.Database))
pos += 1 + 2
data[pos] = byte(statusVarLength)
data[pos+1] = byte(statusVarLength >> 8)
pos += 2
if q.Charset != nil {
data[pos] = QCharsetCode
data[pos+1] = byte(q.Charset.Client)
data[pos+2] = byte(q.Charset.Client >> 8)
data[pos+3] = byte(q.Charset.Conn)
data[pos+4] = byte(q.Charset.Conn >> 8)
data[pos+5] = byte(q.Charset.Server)
data[pos+6] = byte(q.Charset.Server >> 8)
pos += 7
}
pos += copy(data[pos:pos+len(q.Database)], q.Database)
data[pos] = 0
pos++
copy(data[pos:], q.SQL)
ev := s.Packetize(f, eQueryEvent, 0, data)
return NewMysql56BinlogEvent(ev)
} | go | func NewQueryEvent(f BinlogFormat, s *FakeBinlogStream, q Query) BinlogEvent {
statusVarLength := 0
if q.Charset != nil {
statusVarLength += 1 + 2 + 2 + 2
}
length := 4 + // slave proxy id
4 + // execution time
1 + // schema length
2 + // error code
2 + // status vars length
statusVarLength +
len(q.Database) + // schema
1 + // [00]
len(q.SQL) // query
data := make([]byte, length)
pos := 8
data[pos] = byte(len(q.Database))
pos += 1 + 2
data[pos] = byte(statusVarLength)
data[pos+1] = byte(statusVarLength >> 8)
pos += 2
if q.Charset != nil {
data[pos] = QCharsetCode
data[pos+1] = byte(q.Charset.Client)
data[pos+2] = byte(q.Charset.Client >> 8)
data[pos+3] = byte(q.Charset.Conn)
data[pos+4] = byte(q.Charset.Conn >> 8)
data[pos+5] = byte(q.Charset.Server)
data[pos+6] = byte(q.Charset.Server >> 8)
pos += 7
}
pos += copy(data[pos:pos+len(q.Database)], q.Database)
data[pos] = 0
pos++
copy(data[pos:], q.SQL)
ev := s.Packetize(f, eQueryEvent, 0, data)
return NewMysql56BinlogEvent(ev)
} | [
"func",
"NewQueryEvent",
"(",
"f",
"BinlogFormat",
",",
"s",
"*",
"FakeBinlogStream",
",",
"q",
"Query",
")",
"BinlogEvent",
"{",
"statusVarLength",
":=",
"0",
"\n",
"if",
"q",
".",
"Charset",
"!=",
"nil",
"{",
"statusVarLength",
"+=",
"1",
"+",
"2",
"+",
"2",
"+",
"2",
"\n",
"}",
"\n",
"length",
":=",
"4",
"+",
"// slave proxy id",
"4",
"+",
"// execution time",
"1",
"+",
"// schema length",
"2",
"+",
"// error code",
"2",
"+",
"// status vars length",
"statusVarLength",
"+",
"len",
"(",
"q",
".",
"Database",
")",
"+",
"// schema",
"1",
"+",
"// [00]",
"len",
"(",
"q",
".",
"SQL",
")",
"// query",
"\n",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"length",
")",
"\n\n",
"pos",
":=",
"8",
"\n",
"data",
"[",
"pos",
"]",
"=",
"byte",
"(",
"len",
"(",
"q",
".",
"Database",
")",
")",
"\n",
"pos",
"+=",
"1",
"+",
"2",
"\n",
"data",
"[",
"pos",
"]",
"=",
"byte",
"(",
"statusVarLength",
")",
"\n",
"data",
"[",
"pos",
"+",
"1",
"]",
"=",
"byte",
"(",
"statusVarLength",
">>",
"8",
")",
"\n",
"pos",
"+=",
"2",
"\n",
"if",
"q",
".",
"Charset",
"!=",
"nil",
"{",
"data",
"[",
"pos",
"]",
"=",
"QCharsetCode",
"\n",
"data",
"[",
"pos",
"+",
"1",
"]",
"=",
"byte",
"(",
"q",
".",
"Charset",
".",
"Client",
")",
"\n",
"data",
"[",
"pos",
"+",
"2",
"]",
"=",
"byte",
"(",
"q",
".",
"Charset",
".",
"Client",
">>",
"8",
")",
"\n",
"data",
"[",
"pos",
"+",
"3",
"]",
"=",
"byte",
"(",
"q",
".",
"Charset",
".",
"Conn",
")",
"\n",
"data",
"[",
"pos",
"+",
"4",
"]",
"=",
"byte",
"(",
"q",
".",
"Charset",
".",
"Conn",
">>",
"8",
")",
"\n",
"data",
"[",
"pos",
"+",
"5",
"]",
"=",
"byte",
"(",
"q",
".",
"Charset",
".",
"Server",
")",
"\n",
"data",
"[",
"pos",
"+",
"6",
"]",
"=",
"byte",
"(",
"q",
".",
"Charset",
".",
"Server",
">>",
"8",
")",
"\n",
"pos",
"+=",
"7",
"\n",
"}",
"\n",
"pos",
"+=",
"copy",
"(",
"data",
"[",
"pos",
":",
"pos",
"+",
"len",
"(",
"q",
".",
"Database",
")",
"]",
",",
"q",
".",
"Database",
")",
"\n",
"data",
"[",
"pos",
"]",
"=",
"0",
"\n",
"pos",
"++",
"\n",
"copy",
"(",
"data",
"[",
"pos",
":",
"]",
",",
"q",
".",
"SQL",
")",
"\n\n",
"ev",
":=",
"s",
".",
"Packetize",
"(",
"f",
",",
"eQueryEvent",
",",
"0",
",",
"data",
")",
"\n",
"return",
"NewMysql56BinlogEvent",
"(",
"ev",
")",
"\n",
"}"
] | // NewQueryEvent makes up a QueryEvent based on the Query structure. | [
"NewQueryEvent",
"makes",
"up",
"a",
"QueryEvent",
"based",
"on",
"the",
"Query",
"structure",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event_make.go#L170-L209 | train |
vitessio/vitess | go/mysql/binlog_event_make.go | NewInvalidQueryEvent | func NewInvalidQueryEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent {
length := 100
data := make([]byte, length)
data[4+4] = 200 // > 100
ev := s.Packetize(f, eQueryEvent, 0, data)
return NewMysql56BinlogEvent(ev)
} | go | func NewInvalidQueryEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent {
length := 100
data := make([]byte, length)
data[4+4] = 200 // > 100
ev := s.Packetize(f, eQueryEvent, 0, data)
return NewMysql56BinlogEvent(ev)
} | [
"func",
"NewInvalidQueryEvent",
"(",
"f",
"BinlogFormat",
",",
"s",
"*",
"FakeBinlogStream",
")",
"BinlogEvent",
"{",
"length",
":=",
"100",
"\n",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"length",
")",
"\n",
"data",
"[",
"4",
"+",
"4",
"]",
"=",
"200",
"// > 100",
"\n\n",
"ev",
":=",
"s",
".",
"Packetize",
"(",
"f",
",",
"eQueryEvent",
",",
"0",
",",
"data",
")",
"\n",
"return",
"NewMysql56BinlogEvent",
"(",
"ev",
")",
"\n",
"}"
] | // NewInvalidQueryEvent returns an invalid QueryEvent. IsValid is however true.
// sqlPos is out of bounds. | [
"NewInvalidQueryEvent",
"returns",
"an",
"invalid",
"QueryEvent",
".",
"IsValid",
"is",
"however",
"true",
".",
"sqlPos",
"is",
"out",
"of",
"bounds",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event_make.go#L213-L220 | train |
vitessio/vitess | go/mysql/binlog_event_make.go | NewXIDEvent | func NewXIDEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent {
length := 8
data := make([]byte, length)
ev := s.Packetize(f, eXIDEvent, 0, data)
return NewMysql56BinlogEvent(ev)
} | go | func NewXIDEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent {
length := 8
data := make([]byte, length)
ev := s.Packetize(f, eXIDEvent, 0, data)
return NewMysql56BinlogEvent(ev)
} | [
"func",
"NewXIDEvent",
"(",
"f",
"BinlogFormat",
",",
"s",
"*",
"FakeBinlogStream",
")",
"BinlogEvent",
"{",
"length",
":=",
"8",
"\n",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"length",
")",
"\n\n",
"ev",
":=",
"s",
".",
"Packetize",
"(",
"f",
",",
"eXIDEvent",
",",
"0",
",",
"data",
")",
"\n",
"return",
"NewMysql56BinlogEvent",
"(",
"ev",
")",
"\n",
"}"
] | // NewXIDEvent returns a XID event. We do not use the data, so keep it 0. | [
"NewXIDEvent",
"returns",
"a",
"XID",
"event",
".",
"We",
"do",
"not",
"use",
"the",
"data",
"so",
"keep",
"it",
"0",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event_make.go#L223-L229 | train |
vitessio/vitess | go/mysql/binlog_event_make.go | NewIntVarEvent | func NewIntVarEvent(f BinlogFormat, s *FakeBinlogStream, typ byte, value uint64) BinlogEvent {
length := 9
data := make([]byte, length)
data[0] = typ
data[1] = byte(value)
data[2] = byte(value >> 8)
data[3] = byte(value >> 16)
data[4] = byte(value >> 24)
data[5] = byte(value >> 32)
data[6] = byte(value >> 40)
data[7] = byte(value >> 48)
data[8] = byte(value >> 56)
ev := s.Packetize(f, eIntVarEvent, 0, data)
return NewMysql56BinlogEvent(ev)
} | go | func NewIntVarEvent(f BinlogFormat, s *FakeBinlogStream, typ byte, value uint64) BinlogEvent {
length := 9
data := make([]byte, length)
data[0] = typ
data[1] = byte(value)
data[2] = byte(value >> 8)
data[3] = byte(value >> 16)
data[4] = byte(value >> 24)
data[5] = byte(value >> 32)
data[6] = byte(value >> 40)
data[7] = byte(value >> 48)
data[8] = byte(value >> 56)
ev := s.Packetize(f, eIntVarEvent, 0, data)
return NewMysql56BinlogEvent(ev)
} | [
"func",
"NewIntVarEvent",
"(",
"f",
"BinlogFormat",
",",
"s",
"*",
"FakeBinlogStream",
",",
"typ",
"byte",
",",
"value",
"uint64",
")",
"BinlogEvent",
"{",
"length",
":=",
"9",
"\n",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"length",
")",
"\n\n",
"data",
"[",
"0",
"]",
"=",
"typ",
"\n",
"data",
"[",
"1",
"]",
"=",
"byte",
"(",
"value",
")",
"\n",
"data",
"[",
"2",
"]",
"=",
"byte",
"(",
"value",
">>",
"8",
")",
"\n",
"data",
"[",
"3",
"]",
"=",
"byte",
"(",
"value",
">>",
"16",
")",
"\n",
"data",
"[",
"4",
"]",
"=",
"byte",
"(",
"value",
">>",
"24",
")",
"\n",
"data",
"[",
"5",
"]",
"=",
"byte",
"(",
"value",
">>",
"32",
")",
"\n",
"data",
"[",
"6",
"]",
"=",
"byte",
"(",
"value",
">>",
"40",
")",
"\n",
"data",
"[",
"7",
"]",
"=",
"byte",
"(",
"value",
">>",
"48",
")",
"\n",
"data",
"[",
"8",
"]",
"=",
"byte",
"(",
"value",
">>",
"56",
")",
"\n\n",
"ev",
":=",
"s",
".",
"Packetize",
"(",
"f",
",",
"eIntVarEvent",
",",
"0",
",",
"data",
")",
"\n",
"return",
"NewMysql56BinlogEvent",
"(",
"ev",
")",
"\n",
"}"
] | // NewIntVarEvent returns an IntVar event. | [
"NewIntVarEvent",
"returns",
"an",
"IntVar",
"event",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event_make.go#L232-L248 | train |
vitessio/vitess | go/mysql/binlog_event_make.go | NewMariaDBGTIDEvent | func NewMariaDBGTIDEvent(f BinlogFormat, s *FakeBinlogStream, gtid MariadbGTID, hasBegin bool) BinlogEvent {
length := 8 + // sequence
4 + // domain
1 // flags2
data := make([]byte, length)
data[0] = byte(gtid.Sequence)
data[1] = byte(gtid.Sequence >> 8)
data[2] = byte(gtid.Sequence >> 16)
data[3] = byte(gtid.Sequence >> 24)
data[4] = byte(gtid.Sequence >> 32)
data[5] = byte(gtid.Sequence >> 40)
data[6] = byte(gtid.Sequence >> 48)
data[7] = byte(gtid.Sequence >> 56)
data[8] = byte(gtid.Domain)
data[9] = byte(gtid.Domain >> 8)
data[10] = byte(gtid.Domain >> 16)
data[11] = byte(gtid.Domain >> 24)
const FLStandalone = 1
var flags2 byte
if !hasBegin {
flags2 |= FLStandalone
}
data[12] = flags2
ev := s.Packetize(f, eMariaGTIDEvent, 0, data)
return NewMariadbBinlogEvent(ev)
} | go | func NewMariaDBGTIDEvent(f BinlogFormat, s *FakeBinlogStream, gtid MariadbGTID, hasBegin bool) BinlogEvent {
length := 8 + // sequence
4 + // domain
1 // flags2
data := make([]byte, length)
data[0] = byte(gtid.Sequence)
data[1] = byte(gtid.Sequence >> 8)
data[2] = byte(gtid.Sequence >> 16)
data[3] = byte(gtid.Sequence >> 24)
data[4] = byte(gtid.Sequence >> 32)
data[5] = byte(gtid.Sequence >> 40)
data[6] = byte(gtid.Sequence >> 48)
data[7] = byte(gtid.Sequence >> 56)
data[8] = byte(gtid.Domain)
data[9] = byte(gtid.Domain >> 8)
data[10] = byte(gtid.Domain >> 16)
data[11] = byte(gtid.Domain >> 24)
const FLStandalone = 1
var flags2 byte
if !hasBegin {
flags2 |= FLStandalone
}
data[12] = flags2
ev := s.Packetize(f, eMariaGTIDEvent, 0, data)
return NewMariadbBinlogEvent(ev)
} | [
"func",
"NewMariaDBGTIDEvent",
"(",
"f",
"BinlogFormat",
",",
"s",
"*",
"FakeBinlogStream",
",",
"gtid",
"MariadbGTID",
",",
"hasBegin",
"bool",
")",
"BinlogEvent",
"{",
"length",
":=",
"8",
"+",
"// sequence",
"4",
"+",
"// domain",
"1",
"// flags2",
"\n",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"length",
")",
"\n\n",
"data",
"[",
"0",
"]",
"=",
"byte",
"(",
"gtid",
".",
"Sequence",
")",
"\n",
"data",
"[",
"1",
"]",
"=",
"byte",
"(",
"gtid",
".",
"Sequence",
">>",
"8",
")",
"\n",
"data",
"[",
"2",
"]",
"=",
"byte",
"(",
"gtid",
".",
"Sequence",
">>",
"16",
")",
"\n",
"data",
"[",
"3",
"]",
"=",
"byte",
"(",
"gtid",
".",
"Sequence",
">>",
"24",
")",
"\n",
"data",
"[",
"4",
"]",
"=",
"byte",
"(",
"gtid",
".",
"Sequence",
">>",
"32",
")",
"\n",
"data",
"[",
"5",
"]",
"=",
"byte",
"(",
"gtid",
".",
"Sequence",
">>",
"40",
")",
"\n",
"data",
"[",
"6",
"]",
"=",
"byte",
"(",
"gtid",
".",
"Sequence",
">>",
"48",
")",
"\n",
"data",
"[",
"7",
"]",
"=",
"byte",
"(",
"gtid",
".",
"Sequence",
">>",
"56",
")",
"\n",
"data",
"[",
"8",
"]",
"=",
"byte",
"(",
"gtid",
".",
"Domain",
")",
"\n",
"data",
"[",
"9",
"]",
"=",
"byte",
"(",
"gtid",
".",
"Domain",
">>",
"8",
")",
"\n",
"data",
"[",
"10",
"]",
"=",
"byte",
"(",
"gtid",
".",
"Domain",
">>",
"16",
")",
"\n",
"data",
"[",
"11",
"]",
"=",
"byte",
"(",
"gtid",
".",
"Domain",
">>",
"24",
")",
"\n\n",
"const",
"FLStandalone",
"=",
"1",
"\n",
"var",
"flags2",
"byte",
"\n",
"if",
"!",
"hasBegin",
"{",
"flags2",
"|=",
"FLStandalone",
"\n",
"}",
"\n",
"data",
"[",
"12",
"]",
"=",
"flags2",
"\n\n",
"ev",
":=",
"s",
".",
"Packetize",
"(",
"f",
",",
"eMariaGTIDEvent",
",",
"0",
",",
"data",
")",
"\n",
"return",
"NewMariadbBinlogEvent",
"(",
"ev",
")",
"\n",
"}"
] | // NewMariaDBGTIDEvent returns a MariaDB specific GTID event.
// It ignores the Server in the gtid, instead uses the FakeBinlogStream.ServerID. | [
"NewMariaDBGTIDEvent",
"returns",
"a",
"MariaDB",
"specific",
"GTID",
"event",
".",
"It",
"ignores",
"the",
"Server",
"in",
"the",
"gtid",
"instead",
"uses",
"the",
"FakeBinlogStream",
".",
"ServerID",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event_make.go#L252-L280 | train |
vitessio/vitess | go/mysql/binlog_event_make.go | NewTableMapEvent | func NewTableMapEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, tm *TableMap) BinlogEvent {
if f.HeaderSize(eTableMapEvent) != 8 {
panic("Not implemented, post_header_length!=8")
}
metadataLength := metadataTotalLength(tm.Types)
length := 6 + // table_id
2 + // flags
1 + // schema name length
len(tm.Database) +
1 + // [00]
1 + // table name length
len(tm.Name) +
1 + // [00]
1 + // column-count FIXME(alainjobart) len enc
len(tm.Types) +
1 + // lenenc-str column-meta-def FIXME(alainjobart) len enc
metadataLength +
len(tm.CanBeNull.data)
data := make([]byte, length)
data[0] = byte(tableID)
data[1] = byte(tableID >> 8)
data[2] = byte(tableID >> 16)
data[3] = byte(tableID >> 24)
data[4] = byte(tableID >> 32)
data[5] = byte(tableID >> 40)
data[6] = byte(tm.Flags)
data[7] = byte(tm.Flags >> 8)
data[8] = byte(len(tm.Database))
pos := 6 + 2 + 1 + copy(data[9:], tm.Database)
data[pos] = 0
pos++
data[pos] = byte(len(tm.Name))
pos += 1 + copy(data[pos+1:], tm.Name)
data[pos] = 0
pos++
data[pos] = byte(len(tm.Types)) // FIXME(alainjobart) lenenc
pos++
pos += copy(data[pos:], tm.Types)
// Per-column meta data. Starting with len-enc length.
// FIXME(alainjobart) lenenc
data[pos] = byte(metadataLength)
pos++
for c, typ := range tm.Types {
pos = metadataWrite(data, pos, typ, tm.Metadata[c])
}
pos += copy(data[pos:], tm.CanBeNull.data)
if pos != len(data) {
panic("bad encoding")
}
ev := s.Packetize(f, eTableMapEvent, 0, data)
return NewMariadbBinlogEvent(ev)
} | go | func NewTableMapEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, tm *TableMap) BinlogEvent {
if f.HeaderSize(eTableMapEvent) != 8 {
panic("Not implemented, post_header_length!=8")
}
metadataLength := metadataTotalLength(tm.Types)
length := 6 + // table_id
2 + // flags
1 + // schema name length
len(tm.Database) +
1 + // [00]
1 + // table name length
len(tm.Name) +
1 + // [00]
1 + // column-count FIXME(alainjobart) len enc
len(tm.Types) +
1 + // lenenc-str column-meta-def FIXME(alainjobart) len enc
metadataLength +
len(tm.CanBeNull.data)
data := make([]byte, length)
data[0] = byte(tableID)
data[1] = byte(tableID >> 8)
data[2] = byte(tableID >> 16)
data[3] = byte(tableID >> 24)
data[4] = byte(tableID >> 32)
data[5] = byte(tableID >> 40)
data[6] = byte(tm.Flags)
data[7] = byte(tm.Flags >> 8)
data[8] = byte(len(tm.Database))
pos := 6 + 2 + 1 + copy(data[9:], tm.Database)
data[pos] = 0
pos++
data[pos] = byte(len(tm.Name))
pos += 1 + copy(data[pos+1:], tm.Name)
data[pos] = 0
pos++
data[pos] = byte(len(tm.Types)) // FIXME(alainjobart) lenenc
pos++
pos += copy(data[pos:], tm.Types)
// Per-column meta data. Starting with len-enc length.
// FIXME(alainjobart) lenenc
data[pos] = byte(metadataLength)
pos++
for c, typ := range tm.Types {
pos = metadataWrite(data, pos, typ, tm.Metadata[c])
}
pos += copy(data[pos:], tm.CanBeNull.data)
if pos != len(data) {
panic("bad encoding")
}
ev := s.Packetize(f, eTableMapEvent, 0, data)
return NewMariadbBinlogEvent(ev)
} | [
"func",
"NewTableMapEvent",
"(",
"f",
"BinlogFormat",
",",
"s",
"*",
"FakeBinlogStream",
",",
"tableID",
"uint64",
",",
"tm",
"*",
"TableMap",
")",
"BinlogEvent",
"{",
"if",
"f",
".",
"HeaderSize",
"(",
"eTableMapEvent",
")",
"!=",
"8",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"metadataLength",
":=",
"metadataTotalLength",
"(",
"tm",
".",
"Types",
")",
"\n\n",
"length",
":=",
"6",
"+",
"// table_id",
"2",
"+",
"// flags",
"1",
"+",
"// schema name length",
"len",
"(",
"tm",
".",
"Database",
")",
"+",
"1",
"+",
"// [00]",
"1",
"+",
"// table name length",
"len",
"(",
"tm",
".",
"Name",
")",
"+",
"1",
"+",
"// [00]",
"1",
"+",
"// column-count FIXME(alainjobart) len enc",
"len",
"(",
"tm",
".",
"Types",
")",
"+",
"1",
"+",
"// lenenc-str column-meta-def FIXME(alainjobart) len enc",
"metadataLength",
"+",
"len",
"(",
"tm",
".",
"CanBeNull",
".",
"data",
")",
"\n",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"length",
")",
"\n\n",
"data",
"[",
"0",
"]",
"=",
"byte",
"(",
"tableID",
")",
"\n",
"data",
"[",
"1",
"]",
"=",
"byte",
"(",
"tableID",
">>",
"8",
")",
"\n",
"data",
"[",
"2",
"]",
"=",
"byte",
"(",
"tableID",
">>",
"16",
")",
"\n",
"data",
"[",
"3",
"]",
"=",
"byte",
"(",
"tableID",
">>",
"24",
")",
"\n",
"data",
"[",
"4",
"]",
"=",
"byte",
"(",
"tableID",
">>",
"32",
")",
"\n",
"data",
"[",
"5",
"]",
"=",
"byte",
"(",
"tableID",
">>",
"40",
")",
"\n",
"data",
"[",
"6",
"]",
"=",
"byte",
"(",
"tm",
".",
"Flags",
")",
"\n",
"data",
"[",
"7",
"]",
"=",
"byte",
"(",
"tm",
".",
"Flags",
">>",
"8",
")",
"\n",
"data",
"[",
"8",
"]",
"=",
"byte",
"(",
"len",
"(",
"tm",
".",
"Database",
")",
")",
"\n",
"pos",
":=",
"6",
"+",
"2",
"+",
"1",
"+",
"copy",
"(",
"data",
"[",
"9",
":",
"]",
",",
"tm",
".",
"Database",
")",
"\n",
"data",
"[",
"pos",
"]",
"=",
"0",
"\n",
"pos",
"++",
"\n",
"data",
"[",
"pos",
"]",
"=",
"byte",
"(",
"len",
"(",
"tm",
".",
"Name",
")",
")",
"\n",
"pos",
"+=",
"1",
"+",
"copy",
"(",
"data",
"[",
"pos",
"+",
"1",
":",
"]",
",",
"tm",
".",
"Name",
")",
"\n",
"data",
"[",
"pos",
"]",
"=",
"0",
"\n",
"pos",
"++",
"\n\n",
"data",
"[",
"pos",
"]",
"=",
"byte",
"(",
"len",
"(",
"tm",
".",
"Types",
")",
")",
"// FIXME(alainjobart) lenenc",
"\n",
"pos",
"++",
"\n\n",
"pos",
"+=",
"copy",
"(",
"data",
"[",
"pos",
":",
"]",
",",
"tm",
".",
"Types",
")",
"\n\n",
"// Per-column meta data. Starting with len-enc length.",
"// FIXME(alainjobart) lenenc",
"data",
"[",
"pos",
"]",
"=",
"byte",
"(",
"metadataLength",
")",
"\n",
"pos",
"++",
"\n",
"for",
"c",
",",
"typ",
":=",
"range",
"tm",
".",
"Types",
"{",
"pos",
"=",
"metadataWrite",
"(",
"data",
",",
"pos",
",",
"typ",
",",
"tm",
".",
"Metadata",
"[",
"c",
"]",
")",
"\n",
"}",
"\n\n",
"pos",
"+=",
"copy",
"(",
"data",
"[",
"pos",
":",
"]",
",",
"tm",
".",
"CanBeNull",
".",
"data",
")",
"\n",
"if",
"pos",
"!=",
"len",
"(",
"data",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"ev",
":=",
"s",
".",
"Packetize",
"(",
"f",
",",
"eTableMapEvent",
",",
"0",
",",
"data",
")",
"\n",
"return",
"NewMariadbBinlogEvent",
"(",
"ev",
")",
"\n",
"}"
] | // NewTableMapEvent returns a TableMap event.
// Only works with post_header_length=8. | [
"NewTableMapEvent",
"returns",
"a",
"TableMap",
"event",
".",
"Only",
"works",
"with",
"post_header_length",
"=",
"8",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event_make.go#L284-L343 | train |
vitessio/vitess | go/mysql/binlog_event_make.go | NewWriteRowsEvent | func NewWriteRowsEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, rows Rows) BinlogEvent {
return newRowsEvent(f, s, eWriteRowsEventV2, tableID, rows)
} | go | func NewWriteRowsEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, rows Rows) BinlogEvent {
return newRowsEvent(f, s, eWriteRowsEventV2, tableID, rows)
} | [
"func",
"NewWriteRowsEvent",
"(",
"f",
"BinlogFormat",
",",
"s",
"*",
"FakeBinlogStream",
",",
"tableID",
"uint64",
",",
"rows",
"Rows",
")",
"BinlogEvent",
"{",
"return",
"newRowsEvent",
"(",
"f",
",",
"s",
",",
"eWriteRowsEventV2",
",",
"tableID",
",",
"rows",
")",
"\n",
"}"
] | // NewWriteRowsEvent returns a WriteRows event. Uses v2. | [
"NewWriteRowsEvent",
"returns",
"a",
"WriteRows",
"event",
".",
"Uses",
"v2",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event_make.go#L346-L348 | train |
vitessio/vitess | go/mysql/binlog_event_make.go | NewUpdateRowsEvent | func NewUpdateRowsEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, rows Rows) BinlogEvent {
return newRowsEvent(f, s, eUpdateRowsEventV2, tableID, rows)
} | go | func NewUpdateRowsEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, rows Rows) BinlogEvent {
return newRowsEvent(f, s, eUpdateRowsEventV2, tableID, rows)
} | [
"func",
"NewUpdateRowsEvent",
"(",
"f",
"BinlogFormat",
",",
"s",
"*",
"FakeBinlogStream",
",",
"tableID",
"uint64",
",",
"rows",
"Rows",
")",
"BinlogEvent",
"{",
"return",
"newRowsEvent",
"(",
"f",
",",
"s",
",",
"eUpdateRowsEventV2",
",",
"tableID",
",",
"rows",
")",
"\n",
"}"
] | // NewUpdateRowsEvent returns an UpdateRows event. Uses v2. | [
"NewUpdateRowsEvent",
"returns",
"an",
"UpdateRows",
"event",
".",
"Uses",
"v2",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event_make.go#L351-L353 | train |
vitessio/vitess | go/mysql/binlog_event_make.go | NewDeleteRowsEvent | func NewDeleteRowsEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, rows Rows) BinlogEvent {
return newRowsEvent(f, s, eDeleteRowsEventV2, tableID, rows)
} | go | func NewDeleteRowsEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, rows Rows) BinlogEvent {
return newRowsEvent(f, s, eDeleteRowsEventV2, tableID, rows)
} | [
"func",
"NewDeleteRowsEvent",
"(",
"f",
"BinlogFormat",
",",
"s",
"*",
"FakeBinlogStream",
",",
"tableID",
"uint64",
",",
"rows",
"Rows",
")",
"BinlogEvent",
"{",
"return",
"newRowsEvent",
"(",
"f",
",",
"s",
",",
"eDeleteRowsEventV2",
",",
"tableID",
",",
"rows",
")",
"\n",
"}"
] | // NewDeleteRowsEvent returns an DeleteRows event. Uses v2. | [
"NewDeleteRowsEvent",
"returns",
"an",
"DeleteRows",
"event",
".",
"Uses",
"v2",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event_make.go#L356-L358 | train |
vitessio/vitess | go/timer/timer.go | NewTimer | func NewTimer(interval time.Duration) *Timer {
tm := &Timer{
msg: make(chan typeAction),
}
tm.interval.Set(interval)
return tm
} | go | func NewTimer(interval time.Duration) *Timer {
tm := &Timer{
msg: make(chan typeAction),
}
tm.interval.Set(interval)
return tm
} | [
"func",
"NewTimer",
"(",
"interval",
"time",
".",
"Duration",
")",
"*",
"Timer",
"{",
"tm",
":=",
"&",
"Timer",
"{",
"msg",
":",
"make",
"(",
"chan",
"typeAction",
")",
",",
"}",
"\n",
"tm",
".",
"interval",
".",
"Set",
"(",
"interval",
")",
"\n",
"return",
"tm",
"\n",
"}"
] | // NewTimer creates a new Timer object | [
"NewTimer",
"creates",
"a",
"new",
"Timer",
"object"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/timer/timer.go#L70-L76 | train |
vitessio/vitess | go/timer/timer.go | Start | func (tm *Timer) Start(keephouse func()) {
tm.mu.Lock()
defer tm.mu.Unlock()
if tm.running {
return
}
tm.running = true
go tm.run(keephouse)
} | go | func (tm *Timer) Start(keephouse func()) {
tm.mu.Lock()
defer tm.mu.Unlock()
if tm.running {
return
}
tm.running = true
go tm.run(keephouse)
} | [
"func",
"(",
"tm",
"*",
"Timer",
")",
"Start",
"(",
"keephouse",
"func",
"(",
")",
")",
"{",
"tm",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"tm",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"tm",
".",
"running",
"{",
"return",
"\n",
"}",
"\n",
"tm",
".",
"running",
"=",
"true",
"\n",
"go",
"tm",
".",
"run",
"(",
"keephouse",
")",
"\n",
"}"
] | // Start starts the timer. | [
"Start",
"starts",
"the",
"timer",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/timer/timer.go#L79-L87 | train |
vitessio/vitess | go/timer/timer.go | SetInterval | func (tm *Timer) SetInterval(ns time.Duration) {
tm.interval.Set(ns)
tm.mu.Lock()
defer tm.mu.Unlock()
if tm.running {
tm.msg <- timerReset
}
} | go | func (tm *Timer) SetInterval(ns time.Duration) {
tm.interval.Set(ns)
tm.mu.Lock()
defer tm.mu.Unlock()
if tm.running {
tm.msg <- timerReset
}
} | [
"func",
"(",
"tm",
"*",
"Timer",
")",
"SetInterval",
"(",
"ns",
"time",
".",
"Duration",
")",
"{",
"tm",
".",
"interval",
".",
"Set",
"(",
"ns",
")",
"\n",
"tm",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"tm",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"tm",
".",
"running",
"{",
"tm",
".",
"msg",
"<-",
"timerReset",
"\n",
"}",
"\n",
"}"
] | // SetInterval changes the wait interval.
// It will cause the timer to restart the wait. | [
"SetInterval",
"changes",
"the",
"wait",
"interval",
".",
"It",
"will",
"cause",
"the",
"timer",
"to",
"restart",
"the",
"wait",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/timer/timer.go#L118-L125 | train |
vitessio/vitess | go/timer/timer.go | Trigger | func (tm *Timer) Trigger() {
tm.mu.Lock()
defer tm.mu.Unlock()
if tm.running {
tm.msg <- timerTrigger
}
} | go | func (tm *Timer) Trigger() {
tm.mu.Lock()
defer tm.mu.Unlock()
if tm.running {
tm.msg <- timerTrigger
}
} | [
"func",
"(",
"tm",
"*",
"Timer",
")",
"Trigger",
"(",
")",
"{",
"tm",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"tm",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"tm",
".",
"running",
"{",
"tm",
".",
"msg",
"<-",
"timerTrigger",
"\n",
"}",
"\n",
"}"
] | // Trigger will cause the timer to immediately execute the keephouse function.
// It will then cause the timer to restart the wait. | [
"Trigger",
"will",
"cause",
"the",
"timer",
"to",
"immediately",
"execute",
"the",
"keephouse",
"function",
".",
"It",
"will",
"then",
"cause",
"the",
"timer",
"to",
"restart",
"the",
"wait",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/timer/timer.go#L129-L135 | train |
vitessio/vitess | go/timer/timer.go | TriggerAfter | func (tm *Timer) TriggerAfter(duration time.Duration) {
go func() {
time.Sleep(duration)
tm.Trigger()
}()
} | go | func (tm *Timer) TriggerAfter(duration time.Duration) {
go func() {
time.Sleep(duration)
tm.Trigger()
}()
} | [
"func",
"(",
"tm",
"*",
"Timer",
")",
"TriggerAfter",
"(",
"duration",
"time",
".",
"Duration",
")",
"{",
"go",
"func",
"(",
")",
"{",
"time",
".",
"Sleep",
"(",
"duration",
")",
"\n",
"tm",
".",
"Trigger",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"}"
] | // TriggerAfter waits for the specified duration and triggers the next event. | [
"TriggerAfter",
"waits",
"for",
"the",
"specified",
"duration",
"and",
"triggers",
"the",
"next",
"event",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/timer/timer.go#L138-L143 | train |
vitessio/vitess | go/timer/timer.go | Stop | func (tm *Timer) Stop() {
tm.mu.Lock()
defer tm.mu.Unlock()
if tm.running {
tm.msg <- timerStop
tm.running = false
}
} | go | func (tm *Timer) Stop() {
tm.mu.Lock()
defer tm.mu.Unlock()
if tm.running {
tm.msg <- timerStop
tm.running = false
}
} | [
"func",
"(",
"tm",
"*",
"Timer",
")",
"Stop",
"(",
")",
"{",
"tm",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"tm",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"tm",
".",
"running",
"{",
"tm",
".",
"msg",
"<-",
"timerStop",
"\n",
"tm",
".",
"running",
"=",
"false",
"\n",
"}",
"\n",
"}"
] | // Stop will stop the timer. It guarantees that the timer will not execute
// any more calls to keephouse once it has returned. | [
"Stop",
"will",
"stop",
"the",
"timer",
".",
"It",
"guarantees",
"that",
"the",
"timer",
"will",
"not",
"execute",
"any",
"more",
"calls",
"to",
"keephouse",
"once",
"it",
"has",
"returned",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/timer/timer.go#L147-L154 | train |
vitessio/vitess | go/vt/topo/locks.go | newLock | func newLock(action string) *Lock {
l := &Lock{
Action: action,
HostName: "unknown",
UserName: "unknown",
Time: time.Now().Format(time.RFC3339),
Status: "Running",
}
if h, err := os.Hostname(); err == nil {
l.HostName = h
}
if u, err := user.Current(); err == nil {
l.UserName = u.Username
}
return l
} | go | func newLock(action string) *Lock {
l := &Lock{
Action: action,
HostName: "unknown",
UserName: "unknown",
Time: time.Now().Format(time.RFC3339),
Status: "Running",
}
if h, err := os.Hostname(); err == nil {
l.HostName = h
}
if u, err := user.Current(); err == nil {
l.UserName = u.Username
}
return l
} | [
"func",
"newLock",
"(",
"action",
"string",
")",
"*",
"Lock",
"{",
"l",
":=",
"&",
"Lock",
"{",
"Action",
":",
"action",
",",
"HostName",
":",
"\"",
"\"",
",",
"UserName",
":",
"\"",
"\"",
",",
"Time",
":",
"time",
".",
"Now",
"(",
")",
".",
"Format",
"(",
"time",
".",
"RFC3339",
")",
",",
"Status",
":",
"\"",
"\"",
",",
"}",
"\n",
"if",
"h",
",",
"err",
":=",
"os",
".",
"Hostname",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"l",
".",
"HostName",
"=",
"h",
"\n",
"}",
"\n",
"if",
"u",
",",
"err",
":=",
"user",
".",
"Current",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"l",
".",
"UserName",
"=",
"u",
".",
"Username",
"\n",
"}",
"\n",
"return",
"l",
"\n",
"}"
] | // newLock creates a new Lock. | [
"newLock",
"creates",
"a",
"new",
"Lock",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/locks.go#L70-L85 | train |
vitessio/vitess | go/vt/topo/locks.go | ToJSON | func (l *Lock) ToJSON() (string, error) {
data, err := json.MarshalIndent(l, "", " ")
if err != nil {
return "", vterrors.Wrapf(err, "cannot JSON-marshal node")
}
return string(data), nil
} | go | func (l *Lock) ToJSON() (string, error) {
data, err := json.MarshalIndent(l, "", " ")
if err != nil {
return "", vterrors.Wrapf(err, "cannot JSON-marshal node")
}
return string(data), nil
} | [
"func",
"(",
"l",
"*",
"Lock",
")",
"ToJSON",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"json",
".",
"MarshalIndent",
"(",
"l",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"vterrors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"string",
"(",
"data",
")",
",",
"nil",
"\n",
"}"
] | // ToJSON returns a JSON representation of the object. | [
"ToJSON",
"returns",
"a",
"JSON",
"representation",
"of",
"the",
"object",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/locks.go#L88-L94 | train |
vitessio/vitess | go/vt/topo/locks.go | CheckKeyspaceLocked | func CheckKeyspaceLocked(ctx context.Context, keyspace string) error {
// extract the locksInfo pointer
i, ok := ctx.Value(locksKey).(*locksInfo)
if !ok {
return vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "keyspace %v is not locked (no locksInfo)", keyspace)
}
i.mu.Lock()
defer i.mu.Unlock()
// find the individual entry
_, ok = i.info[keyspace]
if !ok {
return vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "keyspace %v is not locked (no lockInfo in map)", keyspace)
}
// TODO(alainjobart): check the lock server implementation
// still holds the lock. Will need to look at the lockInfo struct.
// and we're good for now.
return nil
} | go | func CheckKeyspaceLocked(ctx context.Context, keyspace string) error {
// extract the locksInfo pointer
i, ok := ctx.Value(locksKey).(*locksInfo)
if !ok {
return vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "keyspace %v is not locked (no locksInfo)", keyspace)
}
i.mu.Lock()
defer i.mu.Unlock()
// find the individual entry
_, ok = i.info[keyspace]
if !ok {
return vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "keyspace %v is not locked (no lockInfo in map)", keyspace)
}
// TODO(alainjobart): check the lock server implementation
// still holds the lock. Will need to look at the lockInfo struct.
// and we're good for now.
return nil
} | [
"func",
"CheckKeyspaceLocked",
"(",
"ctx",
"context",
".",
"Context",
",",
"keyspace",
"string",
")",
"error",
"{",
"// extract the locksInfo pointer",
"i",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"locksKey",
")",
".",
"(",
"*",
"locksInfo",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_INVALID_ARGUMENT",
",",
"\"",
"\"",
",",
"keyspace",
")",
"\n",
"}",
"\n",
"i",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"i",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// find the individual entry",
"_",
",",
"ok",
"=",
"i",
".",
"info",
"[",
"keyspace",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_INVALID_ARGUMENT",
",",
"\"",
"\"",
",",
"keyspace",
")",
"\n",
"}",
"\n\n",
"// TODO(alainjobart): check the lock server implementation",
"// still holds the lock. Will need to look at the lockInfo struct.",
"// and we're good for now.",
"return",
"nil",
"\n",
"}"
] | // CheckKeyspaceLocked can be called on a context to make sure we have the lock
// for a given keyspace. | [
"CheckKeyspaceLocked",
"can",
"be",
"called",
"on",
"a",
"context",
"to",
"make",
"sure",
"we",
"have",
"the",
"lock",
"for",
"a",
"given",
"keyspace",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/locks.go#L193-L213 | train |
vitessio/vitess | go/vt/topo/locks.go | lockKeyspace | func (l *Lock) lockKeyspace(ctx context.Context, ts *Server, keyspace string) (LockDescriptor, error) {
log.Infof("Locking keyspace %v for action %v", keyspace, l.Action)
ctx, cancel := context.WithTimeout(ctx, *RemoteOperationTimeout)
defer cancel()
span, ctx := trace.NewSpan(ctx, "TopoServer.LockKeyspaceForAction")
span.Annotate("action", l.Action)
span.Annotate("keyspace", keyspace)
defer span.Finish()
keyspacePath := path.Join(KeyspacesPath, keyspace)
j, err := l.ToJSON()
if err != nil {
return nil, err
}
return ts.globalCell.Lock(ctx, keyspacePath, j)
} | go | func (l *Lock) lockKeyspace(ctx context.Context, ts *Server, keyspace string) (LockDescriptor, error) {
log.Infof("Locking keyspace %v for action %v", keyspace, l.Action)
ctx, cancel := context.WithTimeout(ctx, *RemoteOperationTimeout)
defer cancel()
span, ctx := trace.NewSpan(ctx, "TopoServer.LockKeyspaceForAction")
span.Annotate("action", l.Action)
span.Annotate("keyspace", keyspace)
defer span.Finish()
keyspacePath := path.Join(KeyspacesPath, keyspace)
j, err := l.ToJSON()
if err != nil {
return nil, err
}
return ts.globalCell.Lock(ctx, keyspacePath, j)
} | [
"func",
"(",
"l",
"*",
"Lock",
")",
"lockKeyspace",
"(",
"ctx",
"context",
".",
"Context",
",",
"ts",
"*",
"Server",
",",
"keyspace",
"string",
")",
"(",
"LockDescriptor",
",",
"error",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"keyspace",
",",
"l",
".",
"Action",
")",
"\n\n",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"ctx",
",",
"*",
"RemoteOperationTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n\n",
"span",
",",
"ctx",
":=",
"trace",
".",
"NewSpan",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"span",
".",
"Annotate",
"(",
"\"",
"\"",
",",
"l",
".",
"Action",
")",
"\n",
"span",
".",
"Annotate",
"(",
"\"",
"\"",
",",
"keyspace",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"keyspacePath",
":=",
"path",
".",
"Join",
"(",
"KeyspacesPath",
",",
"keyspace",
")",
"\n",
"j",
",",
"err",
":=",
"l",
".",
"ToJSON",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"ts",
".",
"globalCell",
".",
"Lock",
"(",
"ctx",
",",
"keyspacePath",
",",
"j",
")",
"\n",
"}"
] | // lockKeyspace will lock the keyspace in the topology server.
// unlockKeyspace should be called if this returns no error. | [
"lockKeyspace",
"will",
"lock",
"the",
"keyspace",
"in",
"the",
"topology",
"server",
".",
"unlockKeyspace",
"should",
"be",
"called",
"if",
"this",
"returns",
"no",
"error",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/locks.go#L217-L234 | train |
vitessio/vitess | go/vt/topo/locks.go | CheckShardLocked | func CheckShardLocked(ctx context.Context, keyspace, shard string) error {
// extract the locksInfo pointer
i, ok := ctx.Value(locksKey).(*locksInfo)
if !ok {
return vterrors.Errorf(vtrpc.Code_INTERNAL, "shard %v/%v is not locked (no locksInfo)", keyspace, shard)
}
i.mu.Lock()
defer i.mu.Unlock()
// func the individual entry
mapKey := keyspace + "/" + shard
li, ok := i.info[mapKey]
if !ok {
return vterrors.Errorf(vtrpc.Code_INTERNAL, "shard %v/%v is not locked (no lockInfo in map)", keyspace, shard)
}
// Check the lock server implementation still holds the lock.
return li.lockDescriptor.Check(ctx)
} | go | func CheckShardLocked(ctx context.Context, keyspace, shard string) error {
// extract the locksInfo pointer
i, ok := ctx.Value(locksKey).(*locksInfo)
if !ok {
return vterrors.Errorf(vtrpc.Code_INTERNAL, "shard %v/%v is not locked (no locksInfo)", keyspace, shard)
}
i.mu.Lock()
defer i.mu.Unlock()
// func the individual entry
mapKey := keyspace + "/" + shard
li, ok := i.info[mapKey]
if !ok {
return vterrors.Errorf(vtrpc.Code_INTERNAL, "shard %v/%v is not locked (no lockInfo in map)", keyspace, shard)
}
// Check the lock server implementation still holds the lock.
return li.lockDescriptor.Check(ctx)
} | [
"func",
"CheckShardLocked",
"(",
"ctx",
"context",
".",
"Context",
",",
"keyspace",
",",
"shard",
"string",
")",
"error",
"{",
"// extract the locksInfo pointer",
"i",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"locksKey",
")",
".",
"(",
"*",
"locksInfo",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_INTERNAL",
",",
"\"",
"\"",
",",
"keyspace",
",",
"shard",
")",
"\n",
"}",
"\n",
"i",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"i",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// func the individual entry",
"mapKey",
":=",
"keyspace",
"+",
"\"",
"\"",
"+",
"shard",
"\n",
"li",
",",
"ok",
":=",
"i",
".",
"info",
"[",
"mapKey",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_INTERNAL",
",",
"\"",
"\"",
",",
"keyspace",
",",
"shard",
")",
"\n",
"}",
"\n\n",
"// Check the lock server implementation still holds the lock.",
"return",
"li",
".",
"lockDescriptor",
".",
"Check",
"(",
"ctx",
")",
"\n",
"}"
] | // CheckShardLocked can be called on a context to make sure we have the lock
// for a given shard. | [
"CheckShardLocked",
"can",
"be",
"called",
"on",
"a",
"context",
"to",
"make",
"sure",
"we",
"have",
"the",
"lock",
"for",
"a",
"given",
"shard",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/locks.go#L336-L354 | train |
vitessio/vitess | go/vt/topo/locks.go | unlockShard | func (l *Lock) unlockShard(ctx context.Context, ts *Server, keyspace, shard string, lockDescriptor LockDescriptor, actionError error) error {
// Detach from the parent timeout, but copy the trace span.
// We need to still release the lock even if the parent context timed out.
// Note that we are not using the user provided RemoteOperationTimeout
// here because it is possible that that timeout is too short.
ctx = trace.CopySpan(context.TODO(), ctx)
ctx, cancel := context.WithTimeout(ctx, defaultLockTimeout)
defer cancel()
span, ctx := trace.NewSpan(ctx, "TopoServer.UnlockShardForAction")
span.Annotate("action", l.Action)
span.Annotate("keyspace", keyspace)
span.Annotate("shard", shard)
defer span.Finish()
// first update the actionNode
if actionError != nil {
log.Infof("Unlocking shard %v/%v for action %v with error %v", keyspace, shard, l.Action, actionError)
l.Status = "Error: " + actionError.Error()
} else {
log.Infof("Unlocking shard %v/%v for successful action %v", keyspace, shard, l.Action)
l.Status = "Done"
}
return lockDescriptor.Unlock(ctx)
} | go | func (l *Lock) unlockShard(ctx context.Context, ts *Server, keyspace, shard string, lockDescriptor LockDescriptor, actionError error) error {
// Detach from the parent timeout, but copy the trace span.
// We need to still release the lock even if the parent context timed out.
// Note that we are not using the user provided RemoteOperationTimeout
// here because it is possible that that timeout is too short.
ctx = trace.CopySpan(context.TODO(), ctx)
ctx, cancel := context.WithTimeout(ctx, defaultLockTimeout)
defer cancel()
span, ctx := trace.NewSpan(ctx, "TopoServer.UnlockShardForAction")
span.Annotate("action", l.Action)
span.Annotate("keyspace", keyspace)
span.Annotate("shard", shard)
defer span.Finish()
// first update the actionNode
if actionError != nil {
log.Infof("Unlocking shard %v/%v for action %v with error %v", keyspace, shard, l.Action, actionError)
l.Status = "Error: " + actionError.Error()
} else {
log.Infof("Unlocking shard %v/%v for successful action %v", keyspace, shard, l.Action)
l.Status = "Done"
}
return lockDescriptor.Unlock(ctx)
} | [
"func",
"(",
"l",
"*",
"Lock",
")",
"unlockShard",
"(",
"ctx",
"context",
".",
"Context",
",",
"ts",
"*",
"Server",
",",
"keyspace",
",",
"shard",
"string",
",",
"lockDescriptor",
"LockDescriptor",
",",
"actionError",
"error",
")",
"error",
"{",
"// Detach from the parent timeout, but copy the trace span.",
"// We need to still release the lock even if the parent context timed out.",
"// Note that we are not using the user provided RemoteOperationTimeout",
"// here because it is possible that that timeout is too short.",
"ctx",
"=",
"trace",
".",
"CopySpan",
"(",
"context",
".",
"TODO",
"(",
")",
",",
"ctx",
")",
"\n",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"ctx",
",",
"defaultLockTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n\n",
"span",
",",
"ctx",
":=",
"trace",
".",
"NewSpan",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"span",
".",
"Annotate",
"(",
"\"",
"\"",
",",
"l",
".",
"Action",
")",
"\n",
"span",
".",
"Annotate",
"(",
"\"",
"\"",
",",
"keyspace",
")",
"\n",
"span",
".",
"Annotate",
"(",
"\"",
"\"",
",",
"shard",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"// first update the actionNode",
"if",
"actionError",
"!=",
"nil",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"keyspace",
",",
"shard",
",",
"l",
".",
"Action",
",",
"actionError",
")",
"\n",
"l",
".",
"Status",
"=",
"\"",
"\"",
"+",
"actionError",
".",
"Error",
"(",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"keyspace",
",",
"shard",
",",
"l",
".",
"Action",
")",
"\n",
"l",
".",
"Status",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"lockDescriptor",
".",
"Unlock",
"(",
"ctx",
")",
"\n",
"}"
] | // unlockShard unlocks a previously locked shard. | [
"unlockShard",
"unlocks",
"a",
"previously",
"locked",
"shard",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/locks.go#L379-L403 | train |
vitessio/vitess | go/vt/tableacl/role.go | Name | func (r Role) Name() string {
if r < READER || r > ADMIN {
return ""
}
return roleNames[r]
} | go | func (r Role) Name() string {
if r < READER || r > ADMIN {
return ""
}
return roleNames[r]
} | [
"func",
"(",
"r",
"Role",
")",
"Name",
"(",
")",
"string",
"{",
"if",
"r",
"<",
"READER",
"||",
"r",
">",
"ADMIN",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"roleNames",
"[",
"r",
"]",
"\n",
"}"
] | // Name returns the name of a role | [
"Name",
"returns",
"the",
"name",
"of",
"a",
"role"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/tableacl/role.go#L44-L49 | train |
vitessio/vitess | go/vt/tableacl/role.go | RoleByName | func RoleByName(s string) (Role, bool) {
for i, v := range roleNames {
if v == strings.ToUpper(s) {
return Role(i), true
}
}
return NumRoles, false
} | go | func RoleByName(s string) (Role, bool) {
for i, v := range roleNames {
if v == strings.ToUpper(s) {
return Role(i), true
}
}
return NumRoles, false
} | [
"func",
"RoleByName",
"(",
"s",
"string",
")",
"(",
"Role",
",",
"bool",
")",
"{",
"for",
"i",
",",
"v",
":=",
"range",
"roleNames",
"{",
"if",
"v",
"==",
"strings",
".",
"ToUpper",
"(",
"s",
")",
"{",
"return",
"Role",
"(",
"i",
")",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"NumRoles",
",",
"false",
"\n",
"}"
] | // RoleByName returns the Role corresponding to a name | [
"RoleByName",
"returns",
"the",
"Role",
"corresponding",
"to",
"a",
"name"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/tableacl/role.go#L52-L59 | train |
vitessio/vitess | go/vt/srvtopo/resilient_server.go | NewResilientServer | func NewResilientServer(base *topo.Server, counterPrefix string) *ResilientServer {
if *srvTopoCacheRefresh > *srvTopoCacheTTL {
log.Fatalf("srv_topo_cache_refresh must be less than or equal to srv_topo_cache_ttl")
}
return &ResilientServer{
topoServer: base,
cacheTTL: *srvTopoCacheTTL,
cacheRefresh: *srvTopoCacheRefresh,
counts: stats.NewCountersWithSingleLabel(counterPrefix+"Counts", "Resilient srvtopo server operations", "type"),
srvKeyspaceNamesCache: make(map[string]*srvKeyspaceNamesEntry),
srvKeyspaceCache: make(map[string]*srvKeyspaceEntry),
}
} | go | func NewResilientServer(base *topo.Server, counterPrefix string) *ResilientServer {
if *srvTopoCacheRefresh > *srvTopoCacheTTL {
log.Fatalf("srv_topo_cache_refresh must be less than or equal to srv_topo_cache_ttl")
}
return &ResilientServer{
topoServer: base,
cacheTTL: *srvTopoCacheTTL,
cacheRefresh: *srvTopoCacheRefresh,
counts: stats.NewCountersWithSingleLabel(counterPrefix+"Counts", "Resilient srvtopo server operations", "type"),
srvKeyspaceNamesCache: make(map[string]*srvKeyspaceNamesEntry),
srvKeyspaceCache: make(map[string]*srvKeyspaceEntry),
}
} | [
"func",
"NewResilientServer",
"(",
"base",
"*",
"topo",
".",
"Server",
",",
"counterPrefix",
"string",
")",
"*",
"ResilientServer",
"{",
"if",
"*",
"srvTopoCacheRefresh",
">",
"*",
"srvTopoCacheTTL",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"ResilientServer",
"{",
"topoServer",
":",
"base",
",",
"cacheTTL",
":",
"*",
"srvTopoCacheTTL",
",",
"cacheRefresh",
":",
"*",
"srvTopoCacheRefresh",
",",
"counts",
":",
"stats",
".",
"NewCountersWithSingleLabel",
"(",
"counterPrefix",
"+",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"srvKeyspaceNamesCache",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"srvKeyspaceNamesEntry",
")",
",",
"srvKeyspaceCache",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"srvKeyspaceEntry",
")",
",",
"}",
"\n",
"}"
] | // NewResilientServer creates a new ResilientServer
// based on the provided topo.Server. | [
"NewResilientServer",
"creates",
"a",
"new",
"ResilientServer",
"based",
"on",
"the",
"provided",
"topo",
".",
"Server",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/srvtopo/resilient_server.go#L209-L223 | train |
vitessio/vitess | go/vt/srvtopo/resilient_server.go | GetSrvKeyspaceNames | func (server *ResilientServer) GetSrvKeyspaceNames(ctx context.Context, cell string) ([]string, error) {
server.counts.Add(queryCategory, 1)
// find the entry in the cache, add it if not there
key := cell
server.mutex.Lock()
entry, ok := server.srvKeyspaceNamesCache[key]
if !ok {
entry = &srvKeyspaceNamesEntry{
cell: cell,
}
server.srvKeyspaceNamesCache[key] = entry
}
server.mutex.Unlock()
// Lock the entry, and do everything holding the lock except
// querying the underlying topo server.
//
// This means that even if the topo server is very slow, two concurrent
// requests will only issue one underlying query.
entry.mutex.Lock()
defer entry.mutex.Unlock()
cacheValid := entry.value != nil && time.Since(entry.insertionTime) < server.cacheTTL
shouldRefresh := time.Since(entry.lastQueryTime) > server.cacheRefresh
// If it is not time to check again, then return either the cached
// value or the cached error but don't ask consul again.
if !shouldRefresh {
if cacheValid {
return entry.value, nil
}
return nil, entry.lastError
}
// Refresh the state in a background goroutine if no refresh is already
// in progress none is already running. This way queries are not blocked
// while the cache is still valid but past the refresh time, and avoids
// calling out to the topo service while the lock is held.
if entry.refreshingChan == nil {
entry.refreshingChan = make(chan struct{})
entry.lastQueryTime = time.Now()
go func() {
result, err := server.topoServer.GetSrvKeyspaceNames(ctx, cell)
entry.mutex.Lock()
defer func() {
close(entry.refreshingChan)
entry.refreshingChan = nil
entry.mutex.Unlock()
}()
if err == nil {
// save the value we got and the current time in the cache
entry.insertionTime = time.Now()
entry.value = result
} else {
server.counts.Add(errorCategory, 1)
if entry.insertionTime.IsZero() {
log.Errorf("GetSrvKeyspaceNames(%v, %v) failed: %v (no cached value, caching and returning error)", ctx, cell, err)
} else if entry.value != nil && time.Since(entry.insertionTime) < server.cacheTTL {
server.counts.Add(cachedCategory, 1)
log.Warningf("GetSrvKeyspaceNames(%v, %v) failed: %v (keeping cached value: %v)", ctx, cell, err, entry.value)
} else {
log.Errorf("GetSrvKeyspaceNames(%v, %v) failed: %v (cached value expired)", ctx, cell, err)
entry.insertionTime = time.Time{}
entry.value = nil
}
}
entry.lastError = err
entry.lastErrorCtx = ctx
}()
}
// If the cached entry is still valid then use it, otherwise wait
// for the refresh attempt to complete to get a more up to date
// response.
//
// In the event that the topo service is slow or unresponsive either
// on the initial fetch or if the cache TTL expires, then several
// requests could be blocked on refreshingCond waiting for the response
// to come back.
if cacheValid {
return entry.value, nil
}
refreshingChan := entry.refreshingChan
entry.mutex.Unlock()
select {
case <-refreshingChan:
case <-ctx.Done():
entry.mutex.Lock()
return nil, fmt.Errorf("timed out waiting for keyspace names")
}
entry.mutex.Lock()
if entry.value != nil {
return entry.value, nil
}
return nil, entry.lastError
} | go | func (server *ResilientServer) GetSrvKeyspaceNames(ctx context.Context, cell string) ([]string, error) {
server.counts.Add(queryCategory, 1)
// find the entry in the cache, add it if not there
key := cell
server.mutex.Lock()
entry, ok := server.srvKeyspaceNamesCache[key]
if !ok {
entry = &srvKeyspaceNamesEntry{
cell: cell,
}
server.srvKeyspaceNamesCache[key] = entry
}
server.mutex.Unlock()
// Lock the entry, and do everything holding the lock except
// querying the underlying topo server.
//
// This means that even if the topo server is very slow, two concurrent
// requests will only issue one underlying query.
entry.mutex.Lock()
defer entry.mutex.Unlock()
cacheValid := entry.value != nil && time.Since(entry.insertionTime) < server.cacheTTL
shouldRefresh := time.Since(entry.lastQueryTime) > server.cacheRefresh
// If it is not time to check again, then return either the cached
// value or the cached error but don't ask consul again.
if !shouldRefresh {
if cacheValid {
return entry.value, nil
}
return nil, entry.lastError
}
// Refresh the state in a background goroutine if no refresh is already
// in progress none is already running. This way queries are not blocked
// while the cache is still valid but past the refresh time, and avoids
// calling out to the topo service while the lock is held.
if entry.refreshingChan == nil {
entry.refreshingChan = make(chan struct{})
entry.lastQueryTime = time.Now()
go func() {
result, err := server.topoServer.GetSrvKeyspaceNames(ctx, cell)
entry.mutex.Lock()
defer func() {
close(entry.refreshingChan)
entry.refreshingChan = nil
entry.mutex.Unlock()
}()
if err == nil {
// save the value we got and the current time in the cache
entry.insertionTime = time.Now()
entry.value = result
} else {
server.counts.Add(errorCategory, 1)
if entry.insertionTime.IsZero() {
log.Errorf("GetSrvKeyspaceNames(%v, %v) failed: %v (no cached value, caching and returning error)", ctx, cell, err)
} else if entry.value != nil && time.Since(entry.insertionTime) < server.cacheTTL {
server.counts.Add(cachedCategory, 1)
log.Warningf("GetSrvKeyspaceNames(%v, %v) failed: %v (keeping cached value: %v)", ctx, cell, err, entry.value)
} else {
log.Errorf("GetSrvKeyspaceNames(%v, %v) failed: %v (cached value expired)", ctx, cell, err)
entry.insertionTime = time.Time{}
entry.value = nil
}
}
entry.lastError = err
entry.lastErrorCtx = ctx
}()
}
// If the cached entry is still valid then use it, otherwise wait
// for the refresh attempt to complete to get a more up to date
// response.
//
// In the event that the topo service is slow or unresponsive either
// on the initial fetch or if the cache TTL expires, then several
// requests could be blocked on refreshingCond waiting for the response
// to come back.
if cacheValid {
return entry.value, nil
}
refreshingChan := entry.refreshingChan
entry.mutex.Unlock()
select {
case <-refreshingChan:
case <-ctx.Done():
entry.mutex.Lock()
return nil, fmt.Errorf("timed out waiting for keyspace names")
}
entry.mutex.Lock()
if entry.value != nil {
return entry.value, nil
}
return nil, entry.lastError
} | [
"func",
"(",
"server",
"*",
"ResilientServer",
")",
"GetSrvKeyspaceNames",
"(",
"ctx",
"context",
".",
"Context",
",",
"cell",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"server",
".",
"counts",
".",
"Add",
"(",
"queryCategory",
",",
"1",
")",
"\n\n",
"// find the entry in the cache, add it if not there",
"key",
":=",
"cell",
"\n",
"server",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"entry",
",",
"ok",
":=",
"server",
".",
"srvKeyspaceNamesCache",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"entry",
"=",
"&",
"srvKeyspaceNamesEntry",
"{",
"cell",
":",
"cell",
",",
"}",
"\n",
"server",
".",
"srvKeyspaceNamesCache",
"[",
"key",
"]",
"=",
"entry",
"\n",
"}",
"\n",
"server",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Lock the entry, and do everything holding the lock except",
"// querying the underlying topo server.",
"//",
"// This means that even if the topo server is very slow, two concurrent",
"// requests will only issue one underlying query.",
"entry",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"entry",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"cacheValid",
":=",
"entry",
".",
"value",
"!=",
"nil",
"&&",
"time",
".",
"Since",
"(",
"entry",
".",
"insertionTime",
")",
"<",
"server",
".",
"cacheTTL",
"\n",
"shouldRefresh",
":=",
"time",
".",
"Since",
"(",
"entry",
".",
"lastQueryTime",
")",
">",
"server",
".",
"cacheRefresh",
"\n\n",
"// If it is not time to check again, then return either the cached",
"// value or the cached error but don't ask consul again.",
"if",
"!",
"shouldRefresh",
"{",
"if",
"cacheValid",
"{",
"return",
"entry",
".",
"value",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"entry",
".",
"lastError",
"\n",
"}",
"\n\n",
"// Refresh the state in a background goroutine if no refresh is already",
"// in progress none is already running. This way queries are not blocked",
"// while the cache is still valid but past the refresh time, and avoids",
"// calling out to the topo service while the lock is held.",
"if",
"entry",
".",
"refreshingChan",
"==",
"nil",
"{",
"entry",
".",
"refreshingChan",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"entry",
".",
"lastQueryTime",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"result",
",",
"err",
":=",
"server",
".",
"topoServer",
".",
"GetSrvKeyspaceNames",
"(",
"ctx",
",",
"cell",
")",
"\n\n",
"entry",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"close",
"(",
"entry",
".",
"refreshingChan",
")",
"\n",
"entry",
".",
"refreshingChan",
"=",
"nil",
"\n",
"entry",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"}",
"(",
")",
"\n\n",
"if",
"err",
"==",
"nil",
"{",
"// save the value we got and the current time in the cache",
"entry",
".",
"insertionTime",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"entry",
".",
"value",
"=",
"result",
"\n",
"}",
"else",
"{",
"server",
".",
"counts",
".",
"Add",
"(",
"errorCategory",
",",
"1",
")",
"\n",
"if",
"entry",
".",
"insertionTime",
".",
"IsZero",
"(",
")",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ctx",
",",
"cell",
",",
"err",
")",
"\n\n",
"}",
"else",
"if",
"entry",
".",
"value",
"!=",
"nil",
"&&",
"time",
".",
"Since",
"(",
"entry",
".",
"insertionTime",
")",
"<",
"server",
".",
"cacheTTL",
"{",
"server",
".",
"counts",
".",
"Add",
"(",
"cachedCategory",
",",
"1",
")",
"\n",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"ctx",
",",
"cell",
",",
"err",
",",
"entry",
".",
"value",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ctx",
",",
"cell",
",",
"err",
")",
"\n",
"entry",
".",
"insertionTime",
"=",
"time",
".",
"Time",
"{",
"}",
"\n",
"entry",
".",
"value",
"=",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"entry",
".",
"lastError",
"=",
"err",
"\n",
"entry",
".",
"lastErrorCtx",
"=",
"ctx",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n\n",
"// If the cached entry is still valid then use it, otherwise wait",
"// for the refresh attempt to complete to get a more up to date",
"// response.",
"//",
"// In the event that the topo service is slow or unresponsive either",
"// on the initial fetch or if the cache TTL expires, then several",
"// requests could be blocked on refreshingCond waiting for the response",
"// to come back.",
"if",
"cacheValid",
"{",
"return",
"entry",
".",
"value",
",",
"nil",
"\n",
"}",
"\n\n",
"refreshingChan",
":=",
"entry",
".",
"refreshingChan",
"\n",
"entry",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"select",
"{",
"case",
"<-",
"refreshingChan",
":",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"entry",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"entry",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n\n",
"if",
"entry",
".",
"value",
"!=",
"nil",
"{",
"return",
"entry",
".",
"value",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"entry",
".",
"lastError",
"\n",
"}"
] | // GetSrvKeyspaceNames returns all keyspace names for the given cell. | [
"GetSrvKeyspaceNames",
"returns",
"all",
"keyspace",
"names",
"for",
"the",
"given",
"cell",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/srvtopo/resilient_server.go#L231-L334 | train |
vitessio/vitess | go/vt/srvtopo/resilient_server.go | GetSrvKeyspace | func (server *ResilientServer) GetSrvKeyspace(ctx context.Context, cell, keyspace string) (*topodatapb.SrvKeyspace, error) {
entry := server.getSrvKeyspaceEntry(cell, keyspace)
// If the watch is already running, return the value
entry.mutex.RLock()
if entry.watchState == watchStateRunning {
v, e := entry.value, entry.lastError
entry.mutex.RUnlock()
return v, e
}
entry.mutex.RUnlock()
entry.mutex.Lock()
defer entry.mutex.Unlock()
// If the watch is already running (now that we have the write lock),
// return the value
if entry.watchState == watchStateRunning {
return entry.value, entry.lastError
}
// Watch is not running. Start a new one if it is time to use it and if
// there isn't one already one in the process of being started.
shouldRefresh := time.Since(entry.lastErrorTime) > server.cacheRefresh
if shouldRefresh && (entry.watchState == watchStateIdle) {
entry.watchState = watchStateStarting
entry.watchStartingChan = make(chan struct{})
go server.watchSrvKeyspace(ctx, entry, cell, keyspace)
}
// If the cached value is still valid, use it. Otherwise wait
// for the watch attempt to complete to get a more up to date
// response.
//
// In the event that the topo service is slow or unresponsive either
// on the initial fetch or if the cache TTL expires, then several
// requests could be blocked waiting for the response to come back.
cacheValid := entry.value != nil && time.Since(entry.lastValueTime) < server.cacheTTL
if cacheValid {
server.counts.Add(cachedCategory, 1)
return entry.value, nil
}
if entry.watchState == watchStateStarting {
watchStartingChan := entry.watchStartingChan
entry.mutex.Unlock()
select {
case <-watchStartingChan:
case <-ctx.Done():
entry.mutex.Lock()
return nil, fmt.Errorf("timed out waiting for keyspace")
}
entry.mutex.Lock()
}
if entry.value != nil {
return entry.value, nil
}
return nil, entry.lastError
} | go | func (server *ResilientServer) GetSrvKeyspace(ctx context.Context, cell, keyspace string) (*topodatapb.SrvKeyspace, error) {
entry := server.getSrvKeyspaceEntry(cell, keyspace)
// If the watch is already running, return the value
entry.mutex.RLock()
if entry.watchState == watchStateRunning {
v, e := entry.value, entry.lastError
entry.mutex.RUnlock()
return v, e
}
entry.mutex.RUnlock()
entry.mutex.Lock()
defer entry.mutex.Unlock()
// If the watch is already running (now that we have the write lock),
// return the value
if entry.watchState == watchStateRunning {
return entry.value, entry.lastError
}
// Watch is not running. Start a new one if it is time to use it and if
// there isn't one already one in the process of being started.
shouldRefresh := time.Since(entry.lastErrorTime) > server.cacheRefresh
if shouldRefresh && (entry.watchState == watchStateIdle) {
entry.watchState = watchStateStarting
entry.watchStartingChan = make(chan struct{})
go server.watchSrvKeyspace(ctx, entry, cell, keyspace)
}
// If the cached value is still valid, use it. Otherwise wait
// for the watch attempt to complete to get a more up to date
// response.
//
// In the event that the topo service is slow or unresponsive either
// on the initial fetch or if the cache TTL expires, then several
// requests could be blocked waiting for the response to come back.
cacheValid := entry.value != nil && time.Since(entry.lastValueTime) < server.cacheTTL
if cacheValid {
server.counts.Add(cachedCategory, 1)
return entry.value, nil
}
if entry.watchState == watchStateStarting {
watchStartingChan := entry.watchStartingChan
entry.mutex.Unlock()
select {
case <-watchStartingChan:
case <-ctx.Done():
entry.mutex.Lock()
return nil, fmt.Errorf("timed out waiting for keyspace")
}
entry.mutex.Lock()
}
if entry.value != nil {
return entry.value, nil
}
return nil, entry.lastError
} | [
"func",
"(",
"server",
"*",
"ResilientServer",
")",
"GetSrvKeyspace",
"(",
"ctx",
"context",
".",
"Context",
",",
"cell",
",",
"keyspace",
"string",
")",
"(",
"*",
"topodatapb",
".",
"SrvKeyspace",
",",
"error",
")",
"{",
"entry",
":=",
"server",
".",
"getSrvKeyspaceEntry",
"(",
"cell",
",",
"keyspace",
")",
"\n\n",
"// If the watch is already running, return the value",
"entry",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"if",
"entry",
".",
"watchState",
"==",
"watchStateRunning",
"{",
"v",
",",
"e",
":=",
"entry",
".",
"value",
",",
"entry",
".",
"lastError",
"\n",
"entry",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"v",
",",
"e",
"\n",
"}",
"\n",
"entry",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"entry",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"entry",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// If the watch is already running (now that we have the write lock),",
"// return the value",
"if",
"entry",
".",
"watchState",
"==",
"watchStateRunning",
"{",
"return",
"entry",
".",
"value",
",",
"entry",
".",
"lastError",
"\n",
"}",
"\n\n",
"// Watch is not running. Start a new one if it is time to use it and if",
"// there isn't one already one in the process of being started.",
"shouldRefresh",
":=",
"time",
".",
"Since",
"(",
"entry",
".",
"lastErrorTime",
")",
">",
"server",
".",
"cacheRefresh",
"\n",
"if",
"shouldRefresh",
"&&",
"(",
"entry",
".",
"watchState",
"==",
"watchStateIdle",
")",
"{",
"entry",
".",
"watchState",
"=",
"watchStateStarting",
"\n",
"entry",
".",
"watchStartingChan",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"go",
"server",
".",
"watchSrvKeyspace",
"(",
"ctx",
",",
"entry",
",",
"cell",
",",
"keyspace",
")",
"\n",
"}",
"\n\n",
"// If the cached value is still valid, use it. Otherwise wait",
"// for the watch attempt to complete to get a more up to date",
"// response.",
"//",
"// In the event that the topo service is slow or unresponsive either",
"// on the initial fetch or if the cache TTL expires, then several",
"// requests could be blocked waiting for the response to come back.",
"cacheValid",
":=",
"entry",
".",
"value",
"!=",
"nil",
"&&",
"time",
".",
"Since",
"(",
"entry",
".",
"lastValueTime",
")",
"<",
"server",
".",
"cacheTTL",
"\n",
"if",
"cacheValid",
"{",
"server",
".",
"counts",
".",
"Add",
"(",
"cachedCategory",
",",
"1",
")",
"\n",
"return",
"entry",
".",
"value",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"entry",
".",
"watchState",
"==",
"watchStateStarting",
"{",
"watchStartingChan",
":=",
"entry",
".",
"watchStartingChan",
"\n",
"entry",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"select",
"{",
"case",
"<-",
"watchStartingChan",
":",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"entry",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"entry",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"entry",
".",
"value",
"!=",
"nil",
"{",
"return",
"entry",
".",
"value",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"entry",
".",
"lastError",
"\n",
"}"
] | // GetSrvKeyspace returns SrvKeyspace object for the given cell and keyspace. | [
"GetSrvKeyspace",
"returns",
"SrvKeyspace",
"object",
"for",
"the",
"given",
"cell",
"and",
"keyspace",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/srvtopo/resilient_server.go#L361-L421 | train |
vitessio/vitess | go/vt/srvtopo/resilient_server.go | watchSrvKeyspace | func (server *ResilientServer) watchSrvKeyspace(callerCtx context.Context, entry *srvKeyspaceEntry, cell, keyspace string) {
// We use a background context, as starting the watch should keep going
// even if the current query context is short-lived.
newCtx := context.Background()
current, changes, cancel := server.topoServer.WatchSrvKeyspace(newCtx, cell, keyspace)
entry.mutex.Lock()
if current.Err != nil {
// lastError and lastErrorCtx will be visible from the UI
// until the next try
entry.lastError = current.Err
entry.lastErrorCtx = callerCtx
entry.lastErrorTime = time.Now()
// if the node disappears, delete the cached value
if topo.IsErrType(current.Err, topo.NoNode) {
entry.value = nil
}
server.counts.Add(errorCategory, 1)
log.Errorf("Initial WatchSrvKeyspace failed for %v/%v: %v", cell, keyspace, current.Err)
if time.Since(entry.lastValueTime) > server.cacheTTL {
log.Errorf("WatchSrvKeyspace clearing cached entry for %v/%v", cell, keyspace)
entry.value = nil
}
entry.watchState = watchStateIdle
close(entry.watchStartingChan)
entry.watchStartingChan = nil
entry.mutex.Unlock()
return
}
// we are now watching, cache the first notification
entry.watchState = watchStateRunning
close(entry.watchStartingChan)
entry.watchStartingChan = nil
entry.value = current.Value
entry.lastValueTime = time.Now()
entry.lastError = nil
entry.lastErrorCtx = nil
entry.lastErrorTime = time.Time{}
entry.mutex.Unlock()
defer cancel()
for c := range changes {
if c.Err != nil {
// Watch errored out.
//
// Log it and store the error, but do not clear the value
// so it can be used until the ttl elapses unless the node
// was deleted.
err := fmt.Errorf("WatchSrvKeyspace failed for %v/%v: %v", cell, keyspace, c.Err)
log.Errorf("%v", err)
server.counts.Add(errorCategory, 1)
entry.mutex.Lock()
if topo.IsErrType(c.Err, topo.NoNode) {
entry.value = nil
}
entry.watchState = watchStateIdle
// Even though we didn't get a new value, update the lastValueTime
// here since the watch was successfully running before and we want
// the value to be cached for the full TTL from here onwards.
entry.lastValueTime = time.Now()
entry.lastError = err
entry.lastErrorCtx = nil
entry.lastErrorTime = time.Now()
entry.mutex.Unlock()
return
}
// We got a new value, save it.
entry.mutex.Lock()
entry.value = c.Value
entry.lastError = nil
entry.lastErrorCtx = nil
entry.lastErrorTime = time.Time{}
entry.mutex.Unlock()
}
} | go | func (server *ResilientServer) watchSrvKeyspace(callerCtx context.Context, entry *srvKeyspaceEntry, cell, keyspace string) {
// We use a background context, as starting the watch should keep going
// even if the current query context is short-lived.
newCtx := context.Background()
current, changes, cancel := server.topoServer.WatchSrvKeyspace(newCtx, cell, keyspace)
entry.mutex.Lock()
if current.Err != nil {
// lastError and lastErrorCtx will be visible from the UI
// until the next try
entry.lastError = current.Err
entry.lastErrorCtx = callerCtx
entry.lastErrorTime = time.Now()
// if the node disappears, delete the cached value
if topo.IsErrType(current.Err, topo.NoNode) {
entry.value = nil
}
server.counts.Add(errorCategory, 1)
log.Errorf("Initial WatchSrvKeyspace failed for %v/%v: %v", cell, keyspace, current.Err)
if time.Since(entry.lastValueTime) > server.cacheTTL {
log.Errorf("WatchSrvKeyspace clearing cached entry for %v/%v", cell, keyspace)
entry.value = nil
}
entry.watchState = watchStateIdle
close(entry.watchStartingChan)
entry.watchStartingChan = nil
entry.mutex.Unlock()
return
}
// we are now watching, cache the first notification
entry.watchState = watchStateRunning
close(entry.watchStartingChan)
entry.watchStartingChan = nil
entry.value = current.Value
entry.lastValueTime = time.Now()
entry.lastError = nil
entry.lastErrorCtx = nil
entry.lastErrorTime = time.Time{}
entry.mutex.Unlock()
defer cancel()
for c := range changes {
if c.Err != nil {
// Watch errored out.
//
// Log it and store the error, but do not clear the value
// so it can be used until the ttl elapses unless the node
// was deleted.
err := fmt.Errorf("WatchSrvKeyspace failed for %v/%v: %v", cell, keyspace, c.Err)
log.Errorf("%v", err)
server.counts.Add(errorCategory, 1)
entry.mutex.Lock()
if topo.IsErrType(c.Err, topo.NoNode) {
entry.value = nil
}
entry.watchState = watchStateIdle
// Even though we didn't get a new value, update the lastValueTime
// here since the watch was successfully running before and we want
// the value to be cached for the full TTL from here onwards.
entry.lastValueTime = time.Now()
entry.lastError = err
entry.lastErrorCtx = nil
entry.lastErrorTime = time.Now()
entry.mutex.Unlock()
return
}
// We got a new value, save it.
entry.mutex.Lock()
entry.value = c.Value
entry.lastError = nil
entry.lastErrorCtx = nil
entry.lastErrorTime = time.Time{}
entry.mutex.Unlock()
}
} | [
"func",
"(",
"server",
"*",
"ResilientServer",
")",
"watchSrvKeyspace",
"(",
"callerCtx",
"context",
".",
"Context",
",",
"entry",
"*",
"srvKeyspaceEntry",
",",
"cell",
",",
"keyspace",
"string",
")",
"{",
"// We use a background context, as starting the watch should keep going",
"// even if the current query context is short-lived.",
"newCtx",
":=",
"context",
".",
"Background",
"(",
")",
"\n",
"current",
",",
"changes",
",",
"cancel",
":=",
"server",
".",
"topoServer",
".",
"WatchSrvKeyspace",
"(",
"newCtx",
",",
"cell",
",",
"keyspace",
")",
"\n\n",
"entry",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n\n",
"if",
"current",
".",
"Err",
"!=",
"nil",
"{",
"// lastError and lastErrorCtx will be visible from the UI",
"// until the next try",
"entry",
".",
"lastError",
"=",
"current",
".",
"Err",
"\n",
"entry",
".",
"lastErrorCtx",
"=",
"callerCtx",
"\n",
"entry",
".",
"lastErrorTime",
"=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"// if the node disappears, delete the cached value",
"if",
"topo",
".",
"IsErrType",
"(",
"current",
".",
"Err",
",",
"topo",
".",
"NoNode",
")",
"{",
"entry",
".",
"value",
"=",
"nil",
"\n",
"}",
"\n\n",
"server",
".",
"counts",
".",
"Add",
"(",
"errorCategory",
",",
"1",
")",
"\n",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cell",
",",
"keyspace",
",",
"current",
".",
"Err",
")",
"\n\n",
"if",
"time",
".",
"Since",
"(",
"entry",
".",
"lastValueTime",
")",
">",
"server",
".",
"cacheTTL",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cell",
",",
"keyspace",
")",
"\n",
"entry",
".",
"value",
"=",
"nil",
"\n",
"}",
"\n\n",
"entry",
".",
"watchState",
"=",
"watchStateIdle",
"\n",
"close",
"(",
"entry",
".",
"watchStartingChan",
")",
"\n",
"entry",
".",
"watchStartingChan",
"=",
"nil",
"\n",
"entry",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// we are now watching, cache the first notification",
"entry",
".",
"watchState",
"=",
"watchStateRunning",
"\n",
"close",
"(",
"entry",
".",
"watchStartingChan",
")",
"\n",
"entry",
".",
"watchStartingChan",
"=",
"nil",
"\n",
"entry",
".",
"value",
"=",
"current",
".",
"Value",
"\n",
"entry",
".",
"lastValueTime",
"=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"entry",
".",
"lastError",
"=",
"nil",
"\n",
"entry",
".",
"lastErrorCtx",
"=",
"nil",
"\n",
"entry",
".",
"lastErrorTime",
"=",
"time",
".",
"Time",
"{",
"}",
"\n\n",
"entry",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"defer",
"cancel",
"(",
")",
"\n",
"for",
"c",
":=",
"range",
"changes",
"{",
"if",
"c",
".",
"Err",
"!=",
"nil",
"{",
"// Watch errored out.",
"//",
"// Log it and store the error, but do not clear the value",
"// so it can be used until the ttl elapses unless the node",
"// was deleted.",
"err",
":=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cell",
",",
"keyspace",
",",
"c",
".",
"Err",
")",
"\n",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"server",
".",
"counts",
".",
"Add",
"(",
"errorCategory",
",",
"1",
")",
"\n",
"entry",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"if",
"topo",
".",
"IsErrType",
"(",
"c",
".",
"Err",
",",
"topo",
".",
"NoNode",
")",
"{",
"entry",
".",
"value",
"=",
"nil",
"\n",
"}",
"\n",
"entry",
".",
"watchState",
"=",
"watchStateIdle",
"\n\n",
"// Even though we didn't get a new value, update the lastValueTime",
"// here since the watch was successfully running before and we want",
"// the value to be cached for the full TTL from here onwards.",
"entry",
".",
"lastValueTime",
"=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"entry",
".",
"lastError",
"=",
"err",
"\n",
"entry",
".",
"lastErrorCtx",
"=",
"nil",
"\n",
"entry",
".",
"lastErrorTime",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"entry",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// We got a new value, save it.",
"entry",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"entry",
".",
"value",
"=",
"c",
".",
"Value",
"\n",
"entry",
".",
"lastError",
"=",
"nil",
"\n",
"entry",
".",
"lastErrorCtx",
"=",
"nil",
"\n",
"entry",
".",
"lastErrorTime",
"=",
"time",
".",
"Time",
"{",
"}",
"\n",
"entry",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // watchSrvKeyspace is started in a separate goroutine and attempts to establish
// a watch. The caller context is provided to show in the UI in case the watch
// fails due to an error like a mistyped keyspace. | [
"watchSrvKeyspace",
"is",
"started",
"in",
"a",
"separate",
"goroutine",
"and",
"attempts",
"to",
"establish",
"a",
"watch",
".",
"The",
"caller",
"context",
"is",
"provided",
"to",
"show",
"in",
"the",
"UI",
"in",
"case",
"the",
"watch",
"fails",
"due",
"to",
"an",
"error",
"like",
"a",
"mistyped",
"keyspace",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/srvtopo/resilient_server.go#L426-L511 | train |
vitessio/vitess | go/vt/srvtopo/resilient_server.go | StatusAsHTML | func (st *SrvKeyspaceCacheStatus) StatusAsHTML() template.HTML {
if st.Value == nil {
return template.HTML("No Data")
}
result := "<b>Partitions:</b><br>"
for _, keyspacePartition := range st.Value.Partitions {
result += " <b>" + keyspacePartition.ServedType.String() + ":</b>"
for _, shard := range keyspacePartition.ShardReferences {
result += " " + shard.Name
}
result += "<br>"
}
if st.Value.ShardingColumnName != "" {
result += "<b>ShardingColumnName:</b> " + st.Value.ShardingColumnName + "<br>"
result += "<b>ShardingColumnType:</b> " + st.Value.ShardingColumnType.String() + "<br>"
}
if len(st.Value.ServedFrom) > 0 {
result += "<b>ServedFrom:</b><br>"
for _, sf := range st.Value.ServedFrom {
result += " <b>" + sf.TabletType.String() + ":</b> " + sf.Keyspace + "<br>"
}
}
return template.HTML(result)
} | go | func (st *SrvKeyspaceCacheStatus) StatusAsHTML() template.HTML {
if st.Value == nil {
return template.HTML("No Data")
}
result := "<b>Partitions:</b><br>"
for _, keyspacePartition := range st.Value.Partitions {
result += " <b>" + keyspacePartition.ServedType.String() + ":</b>"
for _, shard := range keyspacePartition.ShardReferences {
result += " " + shard.Name
}
result += "<br>"
}
if st.Value.ShardingColumnName != "" {
result += "<b>ShardingColumnName:</b> " + st.Value.ShardingColumnName + "<br>"
result += "<b>ShardingColumnType:</b> " + st.Value.ShardingColumnType.String() + "<br>"
}
if len(st.Value.ServedFrom) > 0 {
result += "<b>ServedFrom:</b><br>"
for _, sf := range st.Value.ServedFrom {
result += " <b>" + sf.TabletType.String() + ":</b> " + sf.Keyspace + "<br>"
}
}
return template.HTML(result)
} | [
"func",
"(",
"st",
"*",
"SrvKeyspaceCacheStatus",
")",
"StatusAsHTML",
"(",
")",
"template",
".",
"HTML",
"{",
"if",
"st",
".",
"Value",
"==",
"nil",
"{",
"return",
"template",
".",
"HTML",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"result",
":=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"keyspacePartition",
":=",
"range",
"st",
".",
"Value",
".",
"Partitions",
"{",
"result",
"+=",
"\"",
"\"",
"+",
"keyspacePartition",
".",
"ServedType",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"for",
"_",
",",
"shard",
":=",
"range",
"keyspacePartition",
".",
"ShardReferences",
"{",
"result",
"+=",
"\"",
"\"",
"+",
"shard",
".",
"Name",
"\n",
"}",
"\n",
"result",
"+=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"st",
".",
"Value",
".",
"ShardingColumnName",
"!=",
"\"",
"\"",
"{",
"result",
"+=",
"\"",
"\"",
"+",
"st",
".",
"Value",
".",
"ShardingColumnName",
"+",
"\"",
"\"",
"\n",
"result",
"+=",
"\"",
"\"",
"+",
"st",
".",
"Value",
".",
"ShardingColumnType",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"st",
".",
"Value",
".",
"ServedFrom",
")",
">",
"0",
"{",
"result",
"+=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"sf",
":=",
"range",
"st",
".",
"Value",
".",
"ServedFrom",
"{",
"result",
"+=",
"\"",
"\"",
"+",
"sf",
".",
"TabletType",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"+",
"sf",
".",
"Keyspace",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"template",
".",
"HTML",
"(",
"result",
")",
"\n",
"}"
] | // StatusAsHTML returns an HTML version of our status.
// It works best if there is data in the cache. | [
"StatusAsHTML",
"returns",
"an",
"HTML",
"version",
"of",
"our",
"status",
".",
"It",
"works",
"best",
"if",
"there",
"is",
"data",
"in",
"the",
"cache",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/srvtopo/resilient_server.go#L599-L626 | train |
vitessio/vitess | go/vt/srvtopo/resilient_server.go | CacheStatus | func (server *ResilientServer) CacheStatus() *ResilientServerCacheStatus {
result := &ResilientServerCacheStatus{}
server.mutex.Lock()
for _, entry := range server.srvKeyspaceNamesCache {
entry.mutex.Lock()
result.SrvKeyspaceNames = append(result.SrvKeyspaceNames, &SrvKeyspaceNamesCacheStatus{
Cell: entry.cell,
Value: entry.value,
ExpirationTime: entry.insertionTime.Add(server.cacheTTL),
LastQueryTime: entry.lastQueryTime,
LastError: entry.lastError,
LastErrorCtx: entry.lastErrorCtx,
})
entry.mutex.Unlock()
}
for _, entry := range server.srvKeyspaceCache {
entry.mutex.RLock()
expirationTime := time.Now().Add(server.cacheTTL)
if entry.watchState != watchStateRunning {
expirationTime = entry.lastValueTime.Add(server.cacheTTL)
}
result.SrvKeyspaces = append(result.SrvKeyspaces, &SrvKeyspaceCacheStatus{
Cell: entry.cell,
Keyspace: entry.keyspace,
Value: entry.value,
ExpirationTime: expirationTime,
LastErrorTime: entry.lastErrorTime,
LastError: entry.lastError,
LastErrorCtx: entry.lastErrorCtx,
})
entry.mutex.RUnlock()
}
server.mutex.Unlock()
// do the sorting without the mutex
sort.Sort(result.SrvKeyspaceNames)
sort.Sort(result.SrvKeyspaces)
return result
} | go | func (server *ResilientServer) CacheStatus() *ResilientServerCacheStatus {
result := &ResilientServerCacheStatus{}
server.mutex.Lock()
for _, entry := range server.srvKeyspaceNamesCache {
entry.mutex.Lock()
result.SrvKeyspaceNames = append(result.SrvKeyspaceNames, &SrvKeyspaceNamesCacheStatus{
Cell: entry.cell,
Value: entry.value,
ExpirationTime: entry.insertionTime.Add(server.cacheTTL),
LastQueryTime: entry.lastQueryTime,
LastError: entry.lastError,
LastErrorCtx: entry.lastErrorCtx,
})
entry.mutex.Unlock()
}
for _, entry := range server.srvKeyspaceCache {
entry.mutex.RLock()
expirationTime := time.Now().Add(server.cacheTTL)
if entry.watchState != watchStateRunning {
expirationTime = entry.lastValueTime.Add(server.cacheTTL)
}
result.SrvKeyspaces = append(result.SrvKeyspaces, &SrvKeyspaceCacheStatus{
Cell: entry.cell,
Keyspace: entry.keyspace,
Value: entry.value,
ExpirationTime: expirationTime,
LastErrorTime: entry.lastErrorTime,
LastError: entry.lastError,
LastErrorCtx: entry.lastErrorCtx,
})
entry.mutex.RUnlock()
}
server.mutex.Unlock()
// do the sorting without the mutex
sort.Sort(result.SrvKeyspaceNames)
sort.Sort(result.SrvKeyspaces)
return result
} | [
"func",
"(",
"server",
"*",
"ResilientServer",
")",
"CacheStatus",
"(",
")",
"*",
"ResilientServerCacheStatus",
"{",
"result",
":=",
"&",
"ResilientServerCacheStatus",
"{",
"}",
"\n",
"server",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n\n",
"for",
"_",
",",
"entry",
":=",
"range",
"server",
".",
"srvKeyspaceNamesCache",
"{",
"entry",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n\n",
"result",
".",
"SrvKeyspaceNames",
"=",
"append",
"(",
"result",
".",
"SrvKeyspaceNames",
",",
"&",
"SrvKeyspaceNamesCacheStatus",
"{",
"Cell",
":",
"entry",
".",
"cell",
",",
"Value",
":",
"entry",
".",
"value",
",",
"ExpirationTime",
":",
"entry",
".",
"insertionTime",
".",
"Add",
"(",
"server",
".",
"cacheTTL",
")",
",",
"LastQueryTime",
":",
"entry",
".",
"lastQueryTime",
",",
"LastError",
":",
"entry",
".",
"lastError",
",",
"LastErrorCtx",
":",
"entry",
".",
"lastErrorCtx",
",",
"}",
")",
"\n",
"entry",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"entry",
":=",
"range",
"server",
".",
"srvKeyspaceCache",
"{",
"entry",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n\n",
"expirationTime",
":=",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"server",
".",
"cacheTTL",
")",
"\n",
"if",
"entry",
".",
"watchState",
"!=",
"watchStateRunning",
"{",
"expirationTime",
"=",
"entry",
".",
"lastValueTime",
".",
"Add",
"(",
"server",
".",
"cacheTTL",
")",
"\n",
"}",
"\n\n",
"result",
".",
"SrvKeyspaces",
"=",
"append",
"(",
"result",
".",
"SrvKeyspaces",
",",
"&",
"SrvKeyspaceCacheStatus",
"{",
"Cell",
":",
"entry",
".",
"cell",
",",
"Keyspace",
":",
"entry",
".",
"keyspace",
",",
"Value",
":",
"entry",
".",
"value",
",",
"ExpirationTime",
":",
"expirationTime",
",",
"LastErrorTime",
":",
"entry",
".",
"lastErrorTime",
",",
"LastError",
":",
"entry",
".",
"lastError",
",",
"LastErrorCtx",
":",
"entry",
".",
"lastErrorCtx",
",",
"}",
")",
"\n",
"entry",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n",
"}",
"\n\n",
"server",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// do the sorting without the mutex",
"sort",
".",
"Sort",
"(",
"result",
".",
"SrvKeyspaceNames",
")",
"\n",
"sort",
".",
"Sort",
"(",
"result",
".",
"SrvKeyspaces",
")",
"\n\n",
"return",
"result",
"\n",
"}"
] | // CacheStatus returns a displayable version of the cache | [
"CacheStatus",
"returns",
"a",
"displayable",
"version",
"of",
"the",
"cache"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/srvtopo/resilient_server.go#L654-L699 | train |
vitessio/vitess | go/vt/srvtopo/resilient_server.go | ttlTime | func ttlTime(expirationTime time.Time) template.HTML {
ttl := time.Until(expirationTime).Round(time.Second)
if ttl < 0 {
return template.HTML("<b>Expired</b>")
}
return template.HTML(ttl.String())
} | go | func ttlTime(expirationTime time.Time) template.HTML {
ttl := time.Until(expirationTime).Round(time.Second)
if ttl < 0 {
return template.HTML("<b>Expired</b>")
}
return template.HTML(ttl.String())
} | [
"func",
"ttlTime",
"(",
"expirationTime",
"time",
".",
"Time",
")",
"template",
".",
"HTML",
"{",
"ttl",
":=",
"time",
".",
"Until",
"(",
"expirationTime",
")",
".",
"Round",
"(",
"time",
".",
"Second",
")",
"\n",
"if",
"ttl",
"<",
"0",
"{",
"return",
"template",
".",
"HTML",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"template",
".",
"HTML",
"(",
"ttl",
".",
"String",
"(",
")",
")",
"\n",
"}"
] | // Returns the ttl for the cached entry or "Expired" if it is in the past | [
"Returns",
"the",
"ttl",
"for",
"the",
"cached",
"entry",
"or",
"Expired",
"if",
"it",
"is",
"in",
"the",
"past"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/srvtopo/resilient_server.go#L702-L708 | train |
vitessio/vitess | go/vt/schemamanager/ui_controller.go | NewUIController | func NewUIController(
sqlStr string, keyspace string, writer http.ResponseWriter) *UIController {
controller := &UIController{
sqls: make([]string, 0, 32),
keyspace: keyspace,
writer: writer,
}
for _, sql := range strings.Split(sqlStr, ";") {
s := strings.TrimSpace(sql)
if s != "" {
controller.sqls = append(controller.sqls, s)
}
}
return controller
} | go | func NewUIController(
sqlStr string, keyspace string, writer http.ResponseWriter) *UIController {
controller := &UIController{
sqls: make([]string, 0, 32),
keyspace: keyspace,
writer: writer,
}
for _, sql := range strings.Split(sqlStr, ";") {
s := strings.TrimSpace(sql)
if s != "" {
controller.sqls = append(controller.sqls, s)
}
}
return controller
} | [
"func",
"NewUIController",
"(",
"sqlStr",
"string",
",",
"keyspace",
"string",
",",
"writer",
"http",
".",
"ResponseWriter",
")",
"*",
"UIController",
"{",
"controller",
":=",
"&",
"UIController",
"{",
"sqls",
":",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"32",
")",
",",
"keyspace",
":",
"keyspace",
",",
"writer",
":",
"writer",
",",
"}",
"\n",
"for",
"_",
",",
"sql",
":=",
"range",
"strings",
".",
"Split",
"(",
"sqlStr",
",",
"\"",
"\"",
")",
"{",
"s",
":=",
"strings",
".",
"TrimSpace",
"(",
"sql",
")",
"\n",
"if",
"s",
"!=",
"\"",
"\"",
"{",
"controller",
".",
"sqls",
"=",
"append",
"(",
"controller",
".",
"sqls",
",",
"s",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"controller",
"\n",
"}"
] | // NewUIController creates a UIController instance | [
"NewUIController",
"creates",
"a",
"UIController",
"instance"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/schemamanager/ui_controller.go#L37-L52 | train |
vitessio/vitess | go/vt/schemamanager/ui_controller.go | OnReadSuccess | func (controller *UIController) OnReadSuccess(ctx context.Context) error {
controller.writer.Write(
[]byte(fmt.Sprintf("OnReadSuccess, sqls: %v\n", controller.sqls)))
return nil
} | go | func (controller *UIController) OnReadSuccess(ctx context.Context) error {
controller.writer.Write(
[]byte(fmt.Sprintf("OnReadSuccess, sqls: %v\n", controller.sqls)))
return nil
} | [
"func",
"(",
"controller",
"*",
"UIController",
")",
"OnReadSuccess",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"controller",
".",
"writer",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"controller",
".",
"sqls",
")",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // OnReadSuccess is no-op | [
"OnReadSuccess",
"is",
"no",
"-",
"op"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/schemamanager/ui_controller.go#L74-L78 | train |
vitessio/vitess | go/mysql/ldapauthserver/auth_server_ldap.go | ValidateHash | func (asl *AuthServerLdap) ValidateHash(salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (mysql.Getter, error) {
panic("unimplemented")
} | go | func (asl *AuthServerLdap) ValidateHash(salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (mysql.Getter, error) {
panic("unimplemented")
} | [
"func",
"(",
"asl",
"*",
"AuthServerLdap",
")",
"ValidateHash",
"(",
"salt",
"[",
"]",
"byte",
",",
"user",
"string",
",",
"authResponse",
"[",
"]",
"byte",
",",
"remoteAddr",
"net",
".",
"Addr",
")",
"(",
"mysql",
".",
"Getter",
",",
"error",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // ValidateHash is unimplemented for AuthServerLdap. | [
"ValidateHash",
"is",
"unimplemented",
"for",
"AuthServerLdap",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/ldapauthserver/auth_server_ldap.go#L98-L100 | train |
vitessio/vitess | go/mysql/ldapauthserver/auth_server_ldap.go | Negotiate | func (asl *AuthServerLdap) Negotiate(c *mysql.Conn, user string, remoteAddr net.Addr) (mysql.Getter, error) {
// Finish the negotiation.
password, err := mysql.AuthServerNegotiateClearOrDialog(c, asl.Method)
if err != nil {
return nil, err
}
return asl.validate(user, password)
} | go | func (asl *AuthServerLdap) Negotiate(c *mysql.Conn, user string, remoteAddr net.Addr) (mysql.Getter, error) {
// Finish the negotiation.
password, err := mysql.AuthServerNegotiateClearOrDialog(c, asl.Method)
if err != nil {
return nil, err
}
return asl.validate(user, password)
} | [
"func",
"(",
"asl",
"*",
"AuthServerLdap",
")",
"Negotiate",
"(",
"c",
"*",
"mysql",
".",
"Conn",
",",
"user",
"string",
",",
"remoteAddr",
"net",
".",
"Addr",
")",
"(",
"mysql",
".",
"Getter",
",",
"error",
")",
"{",
"// Finish the negotiation.",
"password",
",",
"err",
":=",
"mysql",
".",
"AuthServerNegotiateClearOrDialog",
"(",
"c",
",",
"asl",
".",
"Method",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"asl",
".",
"validate",
"(",
"user",
",",
"password",
")",
"\n",
"}"
] | // Negotiate is part of the AuthServer interface. | [
"Negotiate",
"is",
"part",
"of",
"the",
"AuthServer",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/ldapauthserver/auth_server_ldap.go#L103-L110 | train |
vitessio/vitess | go/mysql/ldapauthserver/auth_server_ldap.go | getGroups | func (asl *AuthServerLdap) getGroups(username string) ([]string, error) {
err := asl.Client.Bind(asl.User, asl.Password)
if err != nil {
return nil, err
}
req := ldap.NewSearchRequest(
asl.GroupQuery,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(memberUid=%s)", username),
[]string{"cn"},
nil,
)
res, err := asl.Client.Search(req)
if err != nil {
return nil, err
}
var groups []string
for _, entry := range res.Entries {
for _, attr := range entry.Attributes {
groups = append(groups, attr.Values[0])
}
}
return groups, nil
} | go | func (asl *AuthServerLdap) getGroups(username string) ([]string, error) {
err := asl.Client.Bind(asl.User, asl.Password)
if err != nil {
return nil, err
}
req := ldap.NewSearchRequest(
asl.GroupQuery,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(memberUid=%s)", username),
[]string{"cn"},
nil,
)
res, err := asl.Client.Search(req)
if err != nil {
return nil, err
}
var groups []string
for _, entry := range res.Entries {
for _, attr := range entry.Attributes {
groups = append(groups, attr.Values[0])
}
}
return groups, nil
} | [
"func",
"(",
"asl",
"*",
"AuthServerLdap",
")",
"getGroups",
"(",
"username",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"err",
":=",
"asl",
".",
"Client",
".",
"Bind",
"(",
"asl",
".",
"User",
",",
"asl",
".",
"Password",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"req",
":=",
"ldap",
".",
"NewSearchRequest",
"(",
"asl",
".",
"GroupQuery",
",",
"ldap",
".",
"ScopeWholeSubtree",
",",
"ldap",
".",
"NeverDerefAliases",
",",
"0",
",",
"0",
",",
"false",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"username",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
",",
")",
"\n",
"res",
",",
"err",
":=",
"asl",
".",
"Client",
".",
"Search",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"groups",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"entry",
":=",
"range",
"res",
".",
"Entries",
"{",
"for",
"_",
",",
"attr",
":=",
"range",
"entry",
".",
"Attributes",
"{",
"groups",
"=",
"append",
"(",
"groups",
",",
"attr",
".",
"Values",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"groups",
",",
"nil",
"\n",
"}"
] | //this needs to be passed an already connected client...should check for this | [
"this",
"needs",
"to",
"be",
"passed",
"an",
"already",
"connected",
"client",
"...",
"should",
"check",
"for",
"this"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/ldapauthserver/auth_server_ldap.go#L128-L151 | train |
vitessio/vitess | go/mysql/ldapauthserver/auth_server_ldap.go | Get | func (lud *LdapUserData) Get() *querypb.VTGateCallerID {
if int64(time.Since(lud.lastUpdated).Seconds()) > lud.asl.RefreshSeconds {
go lud.update()
}
return &querypb.VTGateCallerID{Username: lud.username, Groups: lud.groups}
} | go | func (lud *LdapUserData) Get() *querypb.VTGateCallerID {
if int64(time.Since(lud.lastUpdated).Seconds()) > lud.asl.RefreshSeconds {
go lud.update()
}
return &querypb.VTGateCallerID{Username: lud.username, Groups: lud.groups}
} | [
"func",
"(",
"lud",
"*",
"LdapUserData",
")",
"Get",
"(",
")",
"*",
"querypb",
".",
"VTGateCallerID",
"{",
"if",
"int64",
"(",
"time",
".",
"Since",
"(",
"lud",
".",
"lastUpdated",
")",
".",
"Seconds",
"(",
")",
")",
">",
"lud",
".",
"asl",
".",
"RefreshSeconds",
"{",
"go",
"lud",
".",
"update",
"(",
")",
"\n",
"}",
"\n",
"return",
"&",
"querypb",
".",
"VTGateCallerID",
"{",
"Username",
":",
"lud",
".",
"username",
",",
"Groups",
":",
"lud",
".",
"groups",
"}",
"\n",
"}"
] | // Get returns wrapped username and LDAP groups and possibly updates the cache | [
"Get",
"returns",
"wrapped",
"username",
"and",
"LDAP",
"groups",
"and",
"possibly",
"updates",
"the",
"cache"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/ldapauthserver/auth_server_ldap.go#L191-L196 | train |
vitessio/vitess | go/mysql/ldapauthserver/auth_server_ldap.go | Connect | func (lci *ClientImpl) Connect(network string, config *ServerConfig) error {
conn, err := ldap.Dial(network, config.LdapServer)
if err != nil {
return err
}
lci.Conn = conn
// Reconnect with TLS ... why don't we simply DialTLS directly?
serverName, _, err := netutil.SplitHostPort(config.LdapServer)
if err != nil {
return err
}
tlsConfig, err := vttls.ClientConfig(config.LdapCert, config.LdapKey, config.LdapCA, serverName)
if err != nil {
return err
}
err = conn.StartTLS(tlsConfig)
if err != nil {
return err
}
return nil
} | go | func (lci *ClientImpl) Connect(network string, config *ServerConfig) error {
conn, err := ldap.Dial(network, config.LdapServer)
if err != nil {
return err
}
lci.Conn = conn
// Reconnect with TLS ... why don't we simply DialTLS directly?
serverName, _, err := netutil.SplitHostPort(config.LdapServer)
if err != nil {
return err
}
tlsConfig, err := vttls.ClientConfig(config.LdapCert, config.LdapKey, config.LdapCA, serverName)
if err != nil {
return err
}
err = conn.StartTLS(tlsConfig)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"lci",
"*",
"ClientImpl",
")",
"Connect",
"(",
"network",
"string",
",",
"config",
"*",
"ServerConfig",
")",
"error",
"{",
"conn",
",",
"err",
":=",
"ldap",
".",
"Dial",
"(",
"network",
",",
"config",
".",
"LdapServer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"lci",
".",
"Conn",
"=",
"conn",
"\n",
"// Reconnect with TLS ... why don't we simply DialTLS directly?",
"serverName",
",",
"_",
",",
"err",
":=",
"netutil",
".",
"SplitHostPort",
"(",
"config",
".",
"LdapServer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"tlsConfig",
",",
"err",
":=",
"vttls",
".",
"ClientConfig",
"(",
"config",
".",
"LdapCert",
",",
"config",
".",
"LdapKey",
",",
"config",
".",
"LdapCA",
",",
"serverName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"conn",
".",
"StartTLS",
"(",
"tlsConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Connect calls ldap.Dial and then upgrades the connection to TLS
// This must be called before any other methods | [
"Connect",
"calls",
"ldap",
".",
"Dial",
"and",
"then",
"upgrades",
"the",
"connection",
"to",
"TLS",
"This",
"must",
"be",
"called",
"before",
"any",
"other",
"methods"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/ldapauthserver/auth_server_ldap.go#L222-L242 | train |
vitessio/vitess | go/vt/vttablet/tabletmanager/rpc_actions.go | GetPermissions | func (agent *ActionAgent) GetPermissions(ctx context.Context) (*tabletmanagerdatapb.Permissions, error) {
return mysqlctl.GetPermissions(agent.MysqlDaemon)
} | go | func (agent *ActionAgent) GetPermissions(ctx context.Context) (*tabletmanagerdatapb.Permissions, error) {
return mysqlctl.GetPermissions(agent.MysqlDaemon)
} | [
"func",
"(",
"agent",
"*",
"ActionAgent",
")",
"GetPermissions",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"tabletmanagerdatapb",
".",
"Permissions",
",",
"error",
")",
"{",
"return",
"mysqlctl",
".",
"GetPermissions",
"(",
"agent",
".",
"MysqlDaemon",
")",
"\n",
"}"
] | // GetPermissions returns the db permissions. | [
"GetPermissions",
"returns",
"the",
"db",
"permissions",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletmanager/rpc_actions.go#L46-L48 | train |
vitessio/vitess | go/vt/vttablet/tabletmanager/rpc_actions.go | SetReadOnly | func (agent *ActionAgent) SetReadOnly(ctx context.Context, rdonly bool) error {
if err := agent.lock(ctx); err != nil {
return err
}
defer agent.unlock()
return agent.MysqlDaemon.SetReadOnly(rdonly)
} | go | func (agent *ActionAgent) SetReadOnly(ctx context.Context, rdonly bool) error {
if err := agent.lock(ctx); err != nil {
return err
}
defer agent.unlock()
return agent.MysqlDaemon.SetReadOnly(rdonly)
} | [
"func",
"(",
"agent",
"*",
"ActionAgent",
")",
"SetReadOnly",
"(",
"ctx",
"context",
".",
"Context",
",",
"rdonly",
"bool",
")",
"error",
"{",
"if",
"err",
":=",
"agent",
".",
"lock",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"agent",
".",
"unlock",
"(",
")",
"\n\n",
"return",
"agent",
".",
"MysqlDaemon",
".",
"SetReadOnly",
"(",
"rdonly",
")",
"\n",
"}"
] | // SetReadOnly makes the mysql instance read-only or read-write. | [
"SetReadOnly",
"makes",
"the",
"mysql",
"instance",
"read",
"-",
"only",
"or",
"read",
"-",
"write",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletmanager/rpc_actions.go#L51-L58 | train |
vitessio/vitess | go/vt/vttablet/tabletmanager/rpc_actions.go | ChangeType | func (agent *ActionAgent) ChangeType(ctx context.Context, tabletType topodatapb.TabletType) error {
if err := agent.lock(ctx); err != nil {
return err
}
defer agent.unlock()
// We don't want to allow multiple callers to claim a tablet as drained. There is a race that could happen during
// horizontal resharding where two vtworkers will try to DRAIN the same tablet. This check prevents that race from
// causing errors.
if tabletType == topodatapb.TabletType_DRAINED && agent.Tablet().Type == topodatapb.TabletType_DRAINED {
return fmt.Errorf("Tablet: %v, is already drained", agent.TabletAlias)
}
// change our type in the topology
_, err := topotools.ChangeType(ctx, agent.TopoServer, agent.TabletAlias, tabletType)
if err != nil {
return err
}
// let's update our internal state (stop query service and other things)
if err := agent.refreshTablet(ctx, "ChangeType"); err != nil {
return err
}
// Let's see if we need to fix semi-sync acking.
if err := agent.fixSemiSyncAndReplication(agent.Tablet().Type); err != nil {
return vterrors.Wrap(err, "fixSemiSyncAndReplication failed, may not ack correctly")
}
// and re-run health check
agent.runHealthCheckLocked()
return nil
} | go | func (agent *ActionAgent) ChangeType(ctx context.Context, tabletType topodatapb.TabletType) error {
if err := agent.lock(ctx); err != nil {
return err
}
defer agent.unlock()
// We don't want to allow multiple callers to claim a tablet as drained. There is a race that could happen during
// horizontal resharding where two vtworkers will try to DRAIN the same tablet. This check prevents that race from
// causing errors.
if tabletType == topodatapb.TabletType_DRAINED && agent.Tablet().Type == topodatapb.TabletType_DRAINED {
return fmt.Errorf("Tablet: %v, is already drained", agent.TabletAlias)
}
// change our type in the topology
_, err := topotools.ChangeType(ctx, agent.TopoServer, agent.TabletAlias, tabletType)
if err != nil {
return err
}
// let's update our internal state (stop query service and other things)
if err := agent.refreshTablet(ctx, "ChangeType"); err != nil {
return err
}
// Let's see if we need to fix semi-sync acking.
if err := agent.fixSemiSyncAndReplication(agent.Tablet().Type); err != nil {
return vterrors.Wrap(err, "fixSemiSyncAndReplication failed, may not ack correctly")
}
// and re-run health check
agent.runHealthCheckLocked()
return nil
} | [
"func",
"(",
"agent",
"*",
"ActionAgent",
")",
"ChangeType",
"(",
"ctx",
"context",
".",
"Context",
",",
"tabletType",
"topodatapb",
".",
"TabletType",
")",
"error",
"{",
"if",
"err",
":=",
"agent",
".",
"lock",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"agent",
".",
"unlock",
"(",
")",
"\n\n",
"// We don't want to allow multiple callers to claim a tablet as drained. There is a race that could happen during",
"// horizontal resharding where two vtworkers will try to DRAIN the same tablet. This check prevents that race from",
"// causing errors.",
"if",
"tabletType",
"==",
"topodatapb",
".",
"TabletType_DRAINED",
"&&",
"agent",
".",
"Tablet",
"(",
")",
".",
"Type",
"==",
"topodatapb",
".",
"TabletType_DRAINED",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"agent",
".",
"TabletAlias",
")",
"\n",
"}",
"\n",
"// change our type in the topology",
"_",
",",
"err",
":=",
"topotools",
".",
"ChangeType",
"(",
"ctx",
",",
"agent",
".",
"TopoServer",
",",
"agent",
".",
"TabletAlias",
",",
"tabletType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// let's update our internal state (stop query service and other things)",
"if",
"err",
":=",
"agent",
".",
"refreshTablet",
"(",
"ctx",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Let's see if we need to fix semi-sync acking.",
"if",
"err",
":=",
"agent",
".",
"fixSemiSyncAndReplication",
"(",
"agent",
".",
"Tablet",
"(",
")",
".",
"Type",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"vterrors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// and re-run health check",
"agent",
".",
"runHealthCheckLocked",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // ChangeType changes the tablet type | [
"ChangeType",
"changes",
"the",
"tablet",
"type"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletmanager/rpc_actions.go#L61-L92 | train |
vitessio/vitess | go/vt/vttablet/tabletmanager/rpc_actions.go | Sleep | func (agent *ActionAgent) Sleep(ctx context.Context, duration time.Duration) {
if err := agent.lock(ctx); err != nil {
// client gave up
return
}
defer agent.unlock()
time.Sleep(duration)
} | go | func (agent *ActionAgent) Sleep(ctx context.Context, duration time.Duration) {
if err := agent.lock(ctx); err != nil {
// client gave up
return
}
defer agent.unlock()
time.Sleep(duration)
} | [
"func",
"(",
"agent",
"*",
"ActionAgent",
")",
"Sleep",
"(",
"ctx",
"context",
".",
"Context",
",",
"duration",
"time",
".",
"Duration",
")",
"{",
"if",
"err",
":=",
"agent",
".",
"lock",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"// client gave up",
"return",
"\n",
"}",
"\n",
"defer",
"agent",
".",
"unlock",
"(",
")",
"\n\n",
"time",
".",
"Sleep",
"(",
"duration",
")",
"\n",
"}"
] | // Sleep sleeps for the duration | [
"Sleep",
"sleeps",
"for",
"the",
"duration"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletmanager/rpc_actions.go#L95-L103 | train |
vitessio/vitess | go/vt/vttablet/tabletmanager/rpc_actions.go | ExecuteHook | func (agent *ActionAgent) ExecuteHook(ctx context.Context, hk *hook.Hook) *hook.HookResult {
if err := agent.lock(ctx); err != nil {
// client gave up
return &hook.HookResult{}
}
defer agent.unlock()
// Execute the hooks
topotools.ConfigureTabletHook(hk, agent.TabletAlias)
hr := hk.Execute()
// We never know what the hook did, so let's refresh our state.
if err := agent.refreshTablet(ctx, "ExecuteHook"); err != nil {
log.Errorf("refreshTablet after ExecuteHook failed: %v", err)
}
return hr
} | go | func (agent *ActionAgent) ExecuteHook(ctx context.Context, hk *hook.Hook) *hook.HookResult {
if err := agent.lock(ctx); err != nil {
// client gave up
return &hook.HookResult{}
}
defer agent.unlock()
// Execute the hooks
topotools.ConfigureTabletHook(hk, agent.TabletAlias)
hr := hk.Execute()
// We never know what the hook did, so let's refresh our state.
if err := agent.refreshTablet(ctx, "ExecuteHook"); err != nil {
log.Errorf("refreshTablet after ExecuteHook failed: %v", err)
}
return hr
} | [
"func",
"(",
"agent",
"*",
"ActionAgent",
")",
"ExecuteHook",
"(",
"ctx",
"context",
".",
"Context",
",",
"hk",
"*",
"hook",
".",
"Hook",
")",
"*",
"hook",
".",
"HookResult",
"{",
"if",
"err",
":=",
"agent",
".",
"lock",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"// client gave up",
"return",
"&",
"hook",
".",
"HookResult",
"{",
"}",
"\n",
"}",
"\n",
"defer",
"agent",
".",
"unlock",
"(",
")",
"\n\n",
"// Execute the hooks",
"topotools",
".",
"ConfigureTabletHook",
"(",
"hk",
",",
"agent",
".",
"TabletAlias",
")",
"\n",
"hr",
":=",
"hk",
".",
"Execute",
"(",
")",
"\n\n",
"// We never know what the hook did, so let's refresh our state.",
"if",
"err",
":=",
"agent",
".",
"refreshTablet",
"(",
"ctx",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"hr",
"\n",
"}"
] | // ExecuteHook executes the provided hook locally, and returns the result. | [
"ExecuteHook",
"executes",
"the",
"provided",
"hook",
"locally",
"and",
"returns",
"the",
"result",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletmanager/rpc_actions.go#L106-L123 | train |
vitessio/vitess | go/vt/vttablet/tabletmanager/rpc_actions.go | RefreshState | func (agent *ActionAgent) RefreshState(ctx context.Context) error {
if err := agent.lock(ctx); err != nil {
return err
}
defer agent.unlock()
return agent.refreshTablet(ctx, "RefreshState")
} | go | func (agent *ActionAgent) RefreshState(ctx context.Context) error {
if err := agent.lock(ctx); err != nil {
return err
}
defer agent.unlock()
return agent.refreshTablet(ctx, "RefreshState")
} | [
"func",
"(",
"agent",
"*",
"ActionAgent",
")",
"RefreshState",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"err",
":=",
"agent",
".",
"lock",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"agent",
".",
"unlock",
"(",
")",
"\n\n",
"return",
"agent",
".",
"refreshTablet",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // RefreshState reload the tablet record from the topo server. | [
"RefreshState",
"reload",
"the",
"tablet",
"record",
"from",
"the",
"topo",
"server",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletmanager/rpc_actions.go#L126-L133 | train |
vitessio/vitess | go/vt/vttablet/tabletmanager/rpc_actions.go | IgnoreHealthError | func (agent *ActionAgent) IgnoreHealthError(ctx context.Context, pattern string) error {
var expr *regexp.Regexp
if pattern != "" {
var err error
if expr, err = regexp.Compile(fmt.Sprintf("^%s$", pattern)); err != nil {
return err
}
}
agent.mutex.Lock()
agent._ignoreHealthErrorExpr = expr
agent.mutex.Unlock()
return nil
} | go | func (agent *ActionAgent) IgnoreHealthError(ctx context.Context, pattern string) error {
var expr *regexp.Regexp
if pattern != "" {
var err error
if expr, err = regexp.Compile(fmt.Sprintf("^%s$", pattern)); err != nil {
return err
}
}
agent.mutex.Lock()
agent._ignoreHealthErrorExpr = expr
agent.mutex.Unlock()
return nil
} | [
"func",
"(",
"agent",
"*",
"ActionAgent",
")",
"IgnoreHealthError",
"(",
"ctx",
"context",
".",
"Context",
",",
"pattern",
"string",
")",
"error",
"{",
"var",
"expr",
"*",
"regexp",
".",
"Regexp",
"\n",
"if",
"pattern",
"!=",
"\"",
"\"",
"{",
"var",
"err",
"error",
"\n",
"if",
"expr",
",",
"err",
"=",
"regexp",
".",
"Compile",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pattern",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"agent",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"agent",
".",
"_ignoreHealthErrorExpr",
"=",
"expr",
"\n",
"agent",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // IgnoreHealthError sets the regexp for health check errors to ignore. | [
"IgnoreHealthError",
"sets",
"the",
"regexp",
"for",
"health",
"check",
"errors",
"to",
"ignore",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletmanager/rpc_actions.go#L141-L153 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | Resolve | func (rb *route) Resolve() *route {
for rb.Redirect != nil {
rb = rb.Redirect
}
return rb
} | go | func (rb *route) Resolve() *route {
for rb.Redirect != nil {
rb = rb.Redirect
}
return rb
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"Resolve",
"(",
")",
"*",
"route",
"{",
"for",
"rb",
".",
"Redirect",
"!=",
"nil",
"{",
"rb",
"=",
"rb",
".",
"Redirect",
"\n",
"}",
"\n",
"return",
"rb",
"\n",
"}"
] | // Resolve resolves redirects, and returns the last
// un-redirected route. | [
"Resolve",
"resolves",
"redirects",
"and",
"returns",
"the",
"last",
"un",
"-",
"redirected",
"route",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L74-L79 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | PushFilter | func (rb *route) PushFilter(pb *primitiveBuilder, filter sqlparser.Expr, whereType string, _ builder) error {
sel := rb.Select.(*sqlparser.Select)
switch whereType {
case sqlparser.WhereStr:
sel.AddWhere(filter)
case sqlparser.HavingStr:
sel.AddHaving(filter)
}
rb.UpdatePlans(pb, filter)
return nil
} | go | func (rb *route) PushFilter(pb *primitiveBuilder, filter sqlparser.Expr, whereType string, _ builder) error {
sel := rb.Select.(*sqlparser.Select)
switch whereType {
case sqlparser.WhereStr:
sel.AddWhere(filter)
case sqlparser.HavingStr:
sel.AddHaving(filter)
}
rb.UpdatePlans(pb, filter)
return nil
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"PushFilter",
"(",
"pb",
"*",
"primitiveBuilder",
",",
"filter",
"sqlparser",
".",
"Expr",
",",
"whereType",
"string",
",",
"_",
"builder",
")",
"error",
"{",
"sel",
":=",
"rb",
".",
"Select",
".",
"(",
"*",
"sqlparser",
".",
"Select",
")",
"\n",
"switch",
"whereType",
"{",
"case",
"sqlparser",
".",
"WhereStr",
":",
"sel",
".",
"AddWhere",
"(",
"filter",
")",
"\n",
"case",
"sqlparser",
".",
"HavingStr",
":",
"sel",
".",
"AddHaving",
"(",
"filter",
")",
"\n",
"}",
"\n",
"rb",
".",
"UpdatePlans",
"(",
"pb",
",",
"filter",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // PushFilter satisfies the builder interface.
// The primitive will be updated if the new filter improves the plan. | [
"PushFilter",
"satisfies",
"the",
"builder",
"interface",
".",
"The",
"primitive",
"will",
"be",
"updated",
"if",
"the",
"new",
"filter",
"improves",
"the",
"plan",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L108-L118 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | MakeDistinct | func (rb *route) MakeDistinct() error {
rb.Select.(*sqlparser.Select).Distinct = sqlparser.DistinctStr
return nil
} | go | func (rb *route) MakeDistinct() error {
rb.Select.(*sqlparser.Select).Distinct = sqlparser.DistinctStr
return nil
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"MakeDistinct",
"(",
")",
"error",
"{",
"rb",
".",
"Select",
".",
"(",
"*",
"sqlparser",
".",
"Select",
")",
".",
"Distinct",
"=",
"sqlparser",
".",
"DistinctStr",
"\n",
"return",
"nil",
"\n",
"}"
] | // MakeDistinct sets the DISTINCT property to the select. | [
"MakeDistinct",
"sets",
"the",
"DISTINCT",
"property",
"to",
"the",
"select",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L153-L156 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | SetGroupBy | func (rb *route) SetGroupBy(groupBy sqlparser.GroupBy) error {
rb.Select.(*sqlparser.Select).GroupBy = groupBy
return nil
} | go | func (rb *route) SetGroupBy(groupBy sqlparser.GroupBy) error {
rb.Select.(*sqlparser.Select).GroupBy = groupBy
return nil
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"SetGroupBy",
"(",
"groupBy",
"sqlparser",
".",
"GroupBy",
")",
"error",
"{",
"rb",
".",
"Select",
".",
"(",
"*",
"sqlparser",
".",
"Select",
")",
".",
"GroupBy",
"=",
"groupBy",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetGroupBy sets the GROUP BY clause for the route. | [
"SetGroupBy",
"sets",
"the",
"GROUP",
"BY",
"clause",
"for",
"the",
"route",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L159-L162 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | PushOrderBy | func (rb *route) PushOrderBy(order *sqlparser.Order) error {
// By this time, if any single shard options were already present,
// multi-sharded options would have already been removed. So, this
// call is only for checking if the route has single shard options.
if rb.removeMultishardOptions() {
rb.Select.AddOrder(order)
return nil
}
// If it's a scatter, we have to populate the OrderBy field.
colnum := -1
switch expr := order.Expr.(type) {
case *sqlparser.SQLVal:
var err error
if colnum, err = ResultFromNumber(rb.resultColumns, expr); err != nil {
return fmt.Errorf("invalid order by: %v", err)
}
case *sqlparser.ColName:
c := expr.Metadata.(*column)
for i, rc := range rb.resultColumns {
if rc.column == c {
colnum = i
break
}
}
default:
return fmt.Errorf("unsupported: in scatter query: complex order by expression: %s", sqlparser.String(expr))
}
// If column is not found, then the order by is referencing
// a column that's not on the select list.
if colnum == -1 {
return fmt.Errorf("unsupported: in scatter query: order by must reference a column in the select list: %s", sqlparser.String(order))
}
ob := engine.OrderbyParams{
Col: colnum,
Desc: order.Direction == sqlparser.DescScr,
}
for _, ro := range rb.routeOptions {
ro.eroute.OrderBy = append(ro.eroute.OrderBy, ob)
}
rb.Select.AddOrder(order)
return nil
} | go | func (rb *route) PushOrderBy(order *sqlparser.Order) error {
// By this time, if any single shard options were already present,
// multi-sharded options would have already been removed. So, this
// call is only for checking if the route has single shard options.
if rb.removeMultishardOptions() {
rb.Select.AddOrder(order)
return nil
}
// If it's a scatter, we have to populate the OrderBy field.
colnum := -1
switch expr := order.Expr.(type) {
case *sqlparser.SQLVal:
var err error
if colnum, err = ResultFromNumber(rb.resultColumns, expr); err != nil {
return fmt.Errorf("invalid order by: %v", err)
}
case *sqlparser.ColName:
c := expr.Metadata.(*column)
for i, rc := range rb.resultColumns {
if rc.column == c {
colnum = i
break
}
}
default:
return fmt.Errorf("unsupported: in scatter query: complex order by expression: %s", sqlparser.String(expr))
}
// If column is not found, then the order by is referencing
// a column that's not on the select list.
if colnum == -1 {
return fmt.Errorf("unsupported: in scatter query: order by must reference a column in the select list: %s", sqlparser.String(order))
}
ob := engine.OrderbyParams{
Col: colnum,
Desc: order.Direction == sqlparser.DescScr,
}
for _, ro := range rb.routeOptions {
ro.eroute.OrderBy = append(ro.eroute.OrderBy, ob)
}
rb.Select.AddOrder(order)
return nil
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"PushOrderBy",
"(",
"order",
"*",
"sqlparser",
".",
"Order",
")",
"error",
"{",
"// By this time, if any single shard options were already present,",
"// multi-sharded options would have already been removed. So, this",
"// call is only for checking if the route has single shard options.",
"if",
"rb",
".",
"removeMultishardOptions",
"(",
")",
"{",
"rb",
".",
"Select",
".",
"AddOrder",
"(",
"order",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"// If it's a scatter, we have to populate the OrderBy field.",
"colnum",
":=",
"-",
"1",
"\n",
"switch",
"expr",
":=",
"order",
".",
"Expr",
".",
"(",
"type",
")",
"{",
"case",
"*",
"sqlparser",
".",
"SQLVal",
":",
"var",
"err",
"error",
"\n",
"if",
"colnum",
",",
"err",
"=",
"ResultFromNumber",
"(",
"rb",
".",
"resultColumns",
",",
"expr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"case",
"*",
"sqlparser",
".",
"ColName",
":",
"c",
":=",
"expr",
".",
"Metadata",
".",
"(",
"*",
"column",
")",
"\n",
"for",
"i",
",",
"rc",
":=",
"range",
"rb",
".",
"resultColumns",
"{",
"if",
"rc",
".",
"column",
"==",
"c",
"{",
"colnum",
"=",
"i",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"default",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sqlparser",
".",
"String",
"(",
"expr",
")",
")",
"\n",
"}",
"\n",
"// If column is not found, then the order by is referencing",
"// a column that's not on the select list.",
"if",
"colnum",
"==",
"-",
"1",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sqlparser",
".",
"String",
"(",
"order",
")",
")",
"\n",
"}",
"\n",
"ob",
":=",
"engine",
".",
"OrderbyParams",
"{",
"Col",
":",
"colnum",
",",
"Desc",
":",
"order",
".",
"Direction",
"==",
"sqlparser",
".",
"DescScr",
",",
"}",
"\n",
"for",
"_",
",",
"ro",
":=",
"range",
"rb",
".",
"routeOptions",
"{",
"ro",
".",
"eroute",
".",
"OrderBy",
"=",
"append",
"(",
"ro",
".",
"eroute",
".",
"OrderBy",
",",
"ob",
")",
"\n",
"}",
"\n\n",
"rb",
".",
"Select",
".",
"AddOrder",
"(",
"order",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // PushOrderBy sets the order by for the route. | [
"PushOrderBy",
"sets",
"the",
"order",
"by",
"for",
"the",
"route",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L165-L208 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | PushOrderByNull | func (rb *route) PushOrderByNull() {
rb.Select.(*sqlparser.Select).OrderBy = sqlparser.OrderBy{&sqlparser.Order{Expr: &sqlparser.NullVal{}}}
} | go | func (rb *route) PushOrderByNull() {
rb.Select.(*sqlparser.Select).OrderBy = sqlparser.OrderBy{&sqlparser.Order{Expr: &sqlparser.NullVal{}}}
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"PushOrderByNull",
"(",
")",
"{",
"rb",
".",
"Select",
".",
"(",
"*",
"sqlparser",
".",
"Select",
")",
".",
"OrderBy",
"=",
"sqlparser",
".",
"OrderBy",
"{",
"&",
"sqlparser",
".",
"Order",
"{",
"Expr",
":",
"&",
"sqlparser",
".",
"NullVal",
"{",
"}",
"}",
"}",
"\n",
"}"
] | // PushOrderByNull satisfies the builder interface. | [
"PushOrderByNull",
"satisfies",
"the",
"builder",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L211-L213 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | PushOrderByRand | func (rb *route) PushOrderByRand() {
rb.Select.(*sqlparser.Select).OrderBy = sqlparser.OrderBy{&sqlparser.Order{Expr: &sqlparser.FuncExpr{Name: sqlparser.NewColIdent("rand")}}}
} | go | func (rb *route) PushOrderByRand() {
rb.Select.(*sqlparser.Select).OrderBy = sqlparser.OrderBy{&sqlparser.Order{Expr: &sqlparser.FuncExpr{Name: sqlparser.NewColIdent("rand")}}}
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"PushOrderByRand",
"(",
")",
"{",
"rb",
".",
"Select",
".",
"(",
"*",
"sqlparser",
".",
"Select",
")",
".",
"OrderBy",
"=",
"sqlparser",
".",
"OrderBy",
"{",
"&",
"sqlparser",
".",
"Order",
"{",
"Expr",
":",
"&",
"sqlparser",
".",
"FuncExpr",
"{",
"Name",
":",
"sqlparser",
".",
"NewColIdent",
"(",
"\"",
"\"",
")",
"}",
"}",
"}",
"\n",
"}"
] | // PushOrderByRand satisfies the builder interface. | [
"PushOrderByRand",
"satisfies",
"the",
"builder",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L216-L218 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | SetLimit | func (rb *route) SetLimit(limit *sqlparser.Limit) {
rb.Select.SetLimit(limit)
} | go | func (rb *route) SetLimit(limit *sqlparser.Limit) {
rb.Select.SetLimit(limit)
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"SetLimit",
"(",
"limit",
"*",
"sqlparser",
".",
"Limit",
")",
"{",
"rb",
".",
"Select",
".",
"SetLimit",
"(",
"limit",
")",
"\n",
"}"
] | // SetLimit adds a LIMIT clause to the route. | [
"SetLimit",
"adds",
"a",
"LIMIT",
"clause",
"to",
"the",
"route",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L221-L223 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | SetUpperLimit | func (rb *route) SetUpperLimit(count *sqlparser.SQLVal) {
rb.Select.SetLimit(&sqlparser.Limit{Rowcount: count})
} | go | func (rb *route) SetUpperLimit(count *sqlparser.SQLVal) {
rb.Select.SetLimit(&sqlparser.Limit{Rowcount: count})
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"SetUpperLimit",
"(",
"count",
"*",
"sqlparser",
".",
"SQLVal",
")",
"{",
"rb",
".",
"Select",
".",
"SetLimit",
"(",
"&",
"sqlparser",
".",
"Limit",
"{",
"Rowcount",
":",
"count",
"}",
")",
"\n",
"}"
] | // SetUpperLimit satisfies the builder interface.
// The route pushes the limit regardless of the plan.
// If it's a scatter query, the rows returned will be
// more than the upper limit, but enough for the limit
// primitive to chop off where needed. | [
"SetUpperLimit",
"satisfies",
"the",
"builder",
"interface",
".",
"The",
"route",
"pushes",
"the",
"limit",
"regardless",
"of",
"the",
"plan",
".",
"If",
"it",
"s",
"a",
"scatter",
"query",
"the",
"rows",
"returned",
"will",
"be",
"more",
"than",
"the",
"upper",
"limit",
"but",
"enough",
"for",
"the",
"limit",
"primitive",
"to",
"chop",
"off",
"where",
"needed",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L230-L232 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | procureValues | func (rb *route) procureValues(bldr builder, jt *jointab, val sqlparser.Expr) (sqltypes.PlanValue, error) {
switch val := val.(type) {
case sqlparser.ValTuple:
pv := sqltypes.PlanValue{}
for _, val := range val {
v, err := rb.procureValues(bldr, jt, val)
if err != nil {
return pv, err
}
pv.Values = append(pv.Values, v)
}
return pv, nil
case *sqlparser.ColName:
joinVar := jt.Procure(bldr, val, rb.Order())
return sqltypes.PlanValue{Key: joinVar}, nil
default:
return sqlparser.NewPlanValue(val)
}
} | go | func (rb *route) procureValues(bldr builder, jt *jointab, val sqlparser.Expr) (sqltypes.PlanValue, error) {
switch val := val.(type) {
case sqlparser.ValTuple:
pv := sqltypes.PlanValue{}
for _, val := range val {
v, err := rb.procureValues(bldr, jt, val)
if err != nil {
return pv, err
}
pv.Values = append(pv.Values, v)
}
return pv, nil
case *sqlparser.ColName:
joinVar := jt.Procure(bldr, val, rb.Order())
return sqltypes.PlanValue{Key: joinVar}, nil
default:
return sqlparser.NewPlanValue(val)
}
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"procureValues",
"(",
"bldr",
"builder",
",",
"jt",
"*",
"jointab",
",",
"val",
"sqlparser",
".",
"Expr",
")",
"(",
"sqltypes",
".",
"PlanValue",
",",
"error",
")",
"{",
"switch",
"val",
":=",
"val",
".",
"(",
"type",
")",
"{",
"case",
"sqlparser",
".",
"ValTuple",
":",
"pv",
":=",
"sqltypes",
".",
"PlanValue",
"{",
"}",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"val",
"{",
"v",
",",
"err",
":=",
"rb",
".",
"procureValues",
"(",
"bldr",
",",
"jt",
",",
"val",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"pv",
",",
"err",
"\n",
"}",
"\n",
"pv",
".",
"Values",
"=",
"append",
"(",
"pv",
".",
"Values",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"pv",
",",
"nil",
"\n",
"case",
"*",
"sqlparser",
".",
"ColName",
":",
"joinVar",
":=",
"jt",
".",
"Procure",
"(",
"bldr",
",",
"val",
",",
"rb",
".",
"Order",
"(",
")",
")",
"\n",
"return",
"sqltypes",
".",
"PlanValue",
"{",
"Key",
":",
"joinVar",
"}",
",",
"nil",
"\n",
"default",
":",
"return",
"sqlparser",
".",
"NewPlanValue",
"(",
"val",
")",
"\n",
"}",
"\n",
"}"
] | // procureValues procures and converts the input into
// the expected types for rb.Values. | [
"procureValues",
"procures",
"and",
"converts",
"the",
"input",
"into",
"the",
"expected",
"types",
"for",
"rb",
".",
"Values",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L375-L393 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | generateFieldQuery | func (rb *route) generateFieldQuery(sel sqlparser.SelectStatement, jt *jointab) string {
formatter := func(buf *sqlparser.TrackedBuffer, node sqlparser.SQLNode) {
switch node := node.(type) {
case *sqlparser.ColName:
if !rb.isLocal(node) {
_, joinVar := jt.Lookup(node)
buf.Myprintf("%a", ":"+joinVar)
return
}
case sqlparser.TableName:
if !systemTable(node.Qualifier.String()) {
node.Name.Format(buf)
return
}
node.Format(buf)
return
}
sqlparser.FormatImpossibleQuery(buf, node)
}
return sqlparser.NewTrackedBuffer(formatter).WriteNode(sel).ParsedQuery().Query
} | go | func (rb *route) generateFieldQuery(sel sqlparser.SelectStatement, jt *jointab) string {
formatter := func(buf *sqlparser.TrackedBuffer, node sqlparser.SQLNode) {
switch node := node.(type) {
case *sqlparser.ColName:
if !rb.isLocal(node) {
_, joinVar := jt.Lookup(node)
buf.Myprintf("%a", ":"+joinVar)
return
}
case sqlparser.TableName:
if !systemTable(node.Qualifier.String()) {
node.Name.Format(buf)
return
}
node.Format(buf)
return
}
sqlparser.FormatImpossibleQuery(buf, node)
}
return sqlparser.NewTrackedBuffer(formatter).WriteNode(sel).ParsedQuery().Query
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"generateFieldQuery",
"(",
"sel",
"sqlparser",
".",
"SelectStatement",
",",
"jt",
"*",
"jointab",
")",
"string",
"{",
"formatter",
":=",
"func",
"(",
"buf",
"*",
"sqlparser",
".",
"TrackedBuffer",
",",
"node",
"sqlparser",
".",
"SQLNode",
")",
"{",
"switch",
"node",
":=",
"node",
".",
"(",
"type",
")",
"{",
"case",
"*",
"sqlparser",
".",
"ColName",
":",
"if",
"!",
"rb",
".",
"isLocal",
"(",
"node",
")",
"{",
"_",
",",
"joinVar",
":=",
"jt",
".",
"Lookup",
"(",
"node",
")",
"\n",
"buf",
".",
"Myprintf",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"joinVar",
")",
"\n",
"return",
"\n",
"}",
"\n",
"case",
"sqlparser",
".",
"TableName",
":",
"if",
"!",
"systemTable",
"(",
"node",
".",
"Qualifier",
".",
"String",
"(",
")",
")",
"{",
"node",
".",
"Name",
".",
"Format",
"(",
"buf",
")",
"\n",
"return",
"\n",
"}",
"\n",
"node",
".",
"Format",
"(",
"buf",
")",
"\n",
"return",
"\n",
"}",
"\n",
"sqlparser",
".",
"FormatImpossibleQuery",
"(",
"buf",
",",
"node",
")",
"\n",
"}",
"\n\n",
"return",
"sqlparser",
".",
"NewTrackedBuffer",
"(",
"formatter",
")",
".",
"WriteNode",
"(",
"sel",
")",
".",
"ParsedQuery",
"(",
")",
".",
"Query",
"\n",
"}"
] | // generateFieldQuery generates a query with an impossible where.
// This will be used on the RHS node to fetch field info if the LHS
// returns no result. | [
"generateFieldQuery",
"generates",
"a",
"query",
"with",
"an",
"impossible",
"where",
".",
"This",
"will",
"be",
"used",
"on",
"the",
"RHS",
"node",
"to",
"fetch",
"field",
"info",
"if",
"the",
"LHS",
"returns",
"no",
"result",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L402-L423 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | MergeSubquery | func (rb *route) MergeSubquery(pb *primitiveBuilder, inner *route) bool {
var mergedRouteOptions []*routeOption
outer:
for _, lro := range rb.routeOptions {
for _, rro := range inner.routeOptions {
if lro.SubqueryCanMerge(pb, rro) {
lro.MergeSubquery(rro)
mergedRouteOptions = append(mergedRouteOptions, lro)
continue outer
}
}
}
if len(mergedRouteOptions) != 0 {
rb.routeOptions = mergedRouteOptions
inner.Redirect = rb
return true
}
return false
} | go | func (rb *route) MergeSubquery(pb *primitiveBuilder, inner *route) bool {
var mergedRouteOptions []*routeOption
outer:
for _, lro := range rb.routeOptions {
for _, rro := range inner.routeOptions {
if lro.SubqueryCanMerge(pb, rro) {
lro.MergeSubquery(rro)
mergedRouteOptions = append(mergedRouteOptions, lro)
continue outer
}
}
}
if len(mergedRouteOptions) != 0 {
rb.routeOptions = mergedRouteOptions
inner.Redirect = rb
return true
}
return false
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"MergeSubquery",
"(",
"pb",
"*",
"primitiveBuilder",
",",
"inner",
"*",
"route",
")",
"bool",
"{",
"var",
"mergedRouteOptions",
"[",
"]",
"*",
"routeOption",
"\n",
"outer",
":",
"for",
"_",
",",
"lro",
":=",
"range",
"rb",
".",
"routeOptions",
"{",
"for",
"_",
",",
"rro",
":=",
"range",
"inner",
".",
"routeOptions",
"{",
"if",
"lro",
".",
"SubqueryCanMerge",
"(",
"pb",
",",
"rro",
")",
"{",
"lro",
".",
"MergeSubquery",
"(",
"rro",
")",
"\n",
"mergedRouteOptions",
"=",
"append",
"(",
"mergedRouteOptions",
",",
"lro",
")",
"\n",
"continue",
"outer",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"mergedRouteOptions",
")",
"!=",
"0",
"{",
"rb",
".",
"routeOptions",
"=",
"mergedRouteOptions",
"\n",
"inner",
".",
"Redirect",
"=",
"rb",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // MergeSubquery returns true if the subquery route could successfully be merged
// with the outer route. | [
"MergeSubquery",
"returns",
"true",
"if",
"the",
"subquery",
"route",
"could",
"successfully",
"be",
"merged",
"with",
"the",
"outer",
"route",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L491-L509 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | MergeUnion | func (rb *route) MergeUnion(right *route) bool {
var mergedRouteOptions []*routeOption
outer:
for _, lro := range rb.routeOptions {
for _, rro := range right.routeOptions {
if lro.UnionCanMerge(rro) {
lro.MergeUnion(rro)
mergedRouteOptions = append(mergedRouteOptions, lro)
continue outer
}
}
}
if len(mergedRouteOptions) != 0 {
rb.routeOptions = mergedRouteOptions
right.Redirect = rb
return true
}
return false
} | go | func (rb *route) MergeUnion(right *route) bool {
var mergedRouteOptions []*routeOption
outer:
for _, lro := range rb.routeOptions {
for _, rro := range right.routeOptions {
if lro.UnionCanMerge(rro) {
lro.MergeUnion(rro)
mergedRouteOptions = append(mergedRouteOptions, lro)
continue outer
}
}
}
if len(mergedRouteOptions) != 0 {
rb.routeOptions = mergedRouteOptions
right.Redirect = rb
return true
}
return false
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"MergeUnion",
"(",
"right",
"*",
"route",
")",
"bool",
"{",
"var",
"mergedRouteOptions",
"[",
"]",
"*",
"routeOption",
"\n",
"outer",
":",
"for",
"_",
",",
"lro",
":=",
"range",
"rb",
".",
"routeOptions",
"{",
"for",
"_",
",",
"rro",
":=",
"range",
"right",
".",
"routeOptions",
"{",
"if",
"lro",
".",
"UnionCanMerge",
"(",
"rro",
")",
"{",
"lro",
".",
"MergeUnion",
"(",
"rro",
")",
"\n",
"mergedRouteOptions",
"=",
"append",
"(",
"mergedRouteOptions",
",",
"lro",
")",
"\n",
"continue",
"outer",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"mergedRouteOptions",
")",
"!=",
"0",
"{",
"rb",
".",
"routeOptions",
"=",
"mergedRouteOptions",
"\n",
"right",
".",
"Redirect",
"=",
"rb",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // MergeUnion returns true if the rhs route could successfully be merged
// with the rb route. | [
"MergeUnion",
"returns",
"true",
"if",
"the",
"rhs",
"route",
"could",
"successfully",
"be",
"merged",
"with",
"the",
"rb",
"route",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L513-L531 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | removeMultishardOptions | func (rb *route) removeMultishardOptions() bool {
return rb.removeOptions(func(ro *routeOption) bool {
switch ro.eroute.Opcode {
case engine.SelectUnsharded, engine.SelectDBA, engine.SelectNext, engine.SelectEqualUnique, engine.SelectReference:
return true
}
return false
})
} | go | func (rb *route) removeMultishardOptions() bool {
return rb.removeOptions(func(ro *routeOption) bool {
switch ro.eroute.Opcode {
case engine.SelectUnsharded, engine.SelectDBA, engine.SelectNext, engine.SelectEqualUnique, engine.SelectReference:
return true
}
return false
})
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"removeMultishardOptions",
"(",
")",
"bool",
"{",
"return",
"rb",
".",
"removeOptions",
"(",
"func",
"(",
"ro",
"*",
"routeOption",
")",
"bool",
"{",
"switch",
"ro",
".",
"eroute",
".",
"Opcode",
"{",
"case",
"engine",
".",
"SelectUnsharded",
",",
"engine",
".",
"SelectDBA",
",",
"engine",
".",
"SelectNext",
",",
"engine",
".",
"SelectEqualUnique",
",",
"engine",
".",
"SelectReference",
":",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"}"
] | // removeMultishardOptions removes all multi-shard options from the
// route. It returns false if no such options exist. | [
"removeMultishardOptions",
"removes",
"all",
"multi",
"-",
"shard",
"options",
"from",
"the",
"route",
".",
"It",
"returns",
"false",
"if",
"no",
"such",
"options",
"exist",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L535-L543 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | removeShardedOptions | func (rb *route) removeShardedOptions() bool {
return rb.removeOptions(func(ro *routeOption) bool {
return ro.eroute.Opcode == engine.SelectUnsharded
})
} | go | func (rb *route) removeShardedOptions() bool {
return rb.removeOptions(func(ro *routeOption) bool {
return ro.eroute.Opcode == engine.SelectUnsharded
})
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"removeShardedOptions",
"(",
")",
"bool",
"{",
"return",
"rb",
".",
"removeOptions",
"(",
"func",
"(",
"ro",
"*",
"routeOption",
")",
"bool",
"{",
"return",
"ro",
".",
"eroute",
".",
"Opcode",
"==",
"engine",
".",
"SelectUnsharded",
"\n",
"}",
")",
"\n",
"}"
] | // removeShardedOptions removes all sharded options from the
// route. It returns false if no such options exist.
// This is used for constructs that are only supported for unsharded
// keyspaces like last_insert_id. | [
"removeShardedOptions",
"removes",
"all",
"sharded",
"options",
"from",
"the",
"route",
".",
"It",
"returns",
"false",
"if",
"no",
"such",
"options",
"exist",
".",
"This",
"is",
"used",
"for",
"constructs",
"that",
"are",
"only",
"supported",
"for",
"unsharded",
"keyspaces",
"like",
"last_insert_id",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L549-L553 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | removeOptionsWithUnmatchedKeyspace | func (rb *route) removeOptionsWithUnmatchedKeyspace(keyspace string) bool {
return rb.removeOptions(func(ro *routeOption) bool {
return ro.eroute.Keyspace.Name == keyspace
})
} | go | func (rb *route) removeOptionsWithUnmatchedKeyspace(keyspace string) bool {
return rb.removeOptions(func(ro *routeOption) bool {
return ro.eroute.Keyspace.Name == keyspace
})
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"removeOptionsWithUnmatchedKeyspace",
"(",
"keyspace",
"string",
")",
"bool",
"{",
"return",
"rb",
".",
"removeOptions",
"(",
"func",
"(",
"ro",
"*",
"routeOption",
")",
"bool",
"{",
"return",
"ro",
".",
"eroute",
".",
"Keyspace",
".",
"Name",
"==",
"keyspace",
"\n",
"}",
")",
"\n",
"}"
] | // removeOptionsWithUnmatchedKeyspace removes all options that don't match
// the specified keyspace. It returns false if no such options exist. | [
"removeOptionsWithUnmatchedKeyspace",
"removes",
"all",
"options",
"that",
"don",
"t",
"match",
"the",
"specified",
"keyspace",
".",
"It",
"returns",
"false",
"if",
"no",
"such",
"options",
"exist",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L557-L561 | train |
vitessio/vitess | go/vt/vtgate/planbuilder/route.go | removeOptions | func (rb *route) removeOptions(match func(*routeOption) bool) bool {
var newOptions []*routeOption
for _, ro := range rb.routeOptions {
if match(ro) {
newOptions = append(newOptions, ro)
}
}
if len(newOptions) == 0 {
return false
}
rb.routeOptions = newOptions
return true
} | go | func (rb *route) removeOptions(match func(*routeOption) bool) bool {
var newOptions []*routeOption
for _, ro := range rb.routeOptions {
if match(ro) {
newOptions = append(newOptions, ro)
}
}
if len(newOptions) == 0 {
return false
}
rb.routeOptions = newOptions
return true
} | [
"func",
"(",
"rb",
"*",
"route",
")",
"removeOptions",
"(",
"match",
"func",
"(",
"*",
"routeOption",
")",
"bool",
")",
"bool",
"{",
"var",
"newOptions",
"[",
"]",
"*",
"routeOption",
"\n",
"for",
"_",
",",
"ro",
":=",
"range",
"rb",
".",
"routeOptions",
"{",
"if",
"match",
"(",
"ro",
")",
"{",
"newOptions",
"=",
"append",
"(",
"newOptions",
",",
"ro",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"newOptions",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"rb",
".",
"routeOptions",
"=",
"newOptions",
"\n",
"return",
"true",
"\n",
"}"
] | // removeOptions removes all options that don't match on
// the criteria function. It returns false if no such options exist. | [
"removeOptions",
"removes",
"all",
"options",
"that",
"don",
"t",
"match",
"on",
"the",
"criteria",
"function",
".",
"It",
"returns",
"false",
"if",
"no",
"such",
"options",
"exist",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/planbuilder/route.go#L565-L577 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.