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/mysql/server.go | NewFromListener | func NewFromListener(l net.Listener, authServer AuthServer, handler Handler, connReadTimeout time.Duration, connWriteTimeout time.Duration) (*Listener, error) {
cfg := ListenerConfig{
Listener: l,
AuthServer: authServer,
Handler: handler,
ConnReadTimeout: connReadTimeout,
ConnWriteTimeout: connWriteTimeout,
ConnReadBufferSize: connBufferSize,
}
return NewListenerWithConfig(cfg)
} | go | func NewFromListener(l net.Listener, authServer AuthServer, handler Handler, connReadTimeout time.Duration, connWriteTimeout time.Duration) (*Listener, error) {
cfg := ListenerConfig{
Listener: l,
AuthServer: authServer,
Handler: handler,
ConnReadTimeout: connReadTimeout,
ConnWriteTimeout: connWriteTimeout,
ConnReadBufferSize: connBufferSize,
}
return NewListenerWithConfig(cfg)
} | [
"func",
"NewFromListener",
"(",
"l",
"net",
".",
"Listener",
",",
"authServer",
"AuthServer",
",",
"handler",
"Handler",
",",
"connReadTimeout",
"time",
".",
"Duration",
",",
"connWriteTimeout",
"time",
".",
"Duration",
")",
"(",
"*",
"Listener",
",",
"error",
")",
"{",
"cfg",
":=",
"ListenerConfig",
"{",
"Listener",
":",
"l",
",",
"AuthServer",
":",
"authServer",
",",
"Handler",
":",
"handler",
",",
"ConnReadTimeout",
":",
"connReadTimeout",
",",
"ConnWriteTimeout",
":",
"connWriteTimeout",
",",
"ConnReadBufferSize",
":",
"connBufferSize",
",",
"}",
"\n",
"return",
"NewListenerWithConfig",
"(",
"cfg",
")",
"\n",
"}"
] | // NewFromListener creares a new mysql listener from an existing net.Listener | [
"NewFromListener",
"creares",
"a",
"new",
"mysql",
"listener",
"from",
"an",
"existing",
"net",
".",
"Listener"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/server.go#L160-L170 | train |
vitessio/vitess | go/mysql/server.go | NewListenerWithConfig | func NewListenerWithConfig(cfg ListenerConfig) (*Listener, error) {
var l net.Listener
if cfg.Listener != nil {
l = cfg.Listener
} else {
listener, err := net.Listen(cfg.Protocol, cfg.Address)
if err != nil {
return nil, err
}
l = listener
}
return &Listener{
authServer: cfg.AuthServer,
handler: cfg.Handler,
listener: l,
ServerVersion: DefaultServerVersion,
connectionID: 1,
connReadTimeout: cfg.ConnReadTimeout,
connWriteTimeout: cfg.ConnWriteTimeout,
connReadBufferSize: cfg.ConnReadBufferSize,
}, nil
} | go | func NewListenerWithConfig(cfg ListenerConfig) (*Listener, error) {
var l net.Listener
if cfg.Listener != nil {
l = cfg.Listener
} else {
listener, err := net.Listen(cfg.Protocol, cfg.Address)
if err != nil {
return nil, err
}
l = listener
}
return &Listener{
authServer: cfg.AuthServer,
handler: cfg.Handler,
listener: l,
ServerVersion: DefaultServerVersion,
connectionID: 1,
connReadTimeout: cfg.ConnReadTimeout,
connWriteTimeout: cfg.ConnWriteTimeout,
connReadBufferSize: cfg.ConnReadBufferSize,
}, nil
} | [
"func",
"NewListenerWithConfig",
"(",
"cfg",
"ListenerConfig",
")",
"(",
"*",
"Listener",
",",
"error",
")",
"{",
"var",
"l",
"net",
".",
"Listener",
"\n",
"if",
"cfg",
".",
"Listener",
"!=",
"nil",
"{",
"l",
"=",
"cfg",
".",
"Listener",
"\n",
"}",
"else",
"{",
"listener",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"cfg",
".",
"Protocol",
",",
"cfg",
".",
"Address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"l",
"=",
"listener",
"\n",
"}",
"\n\n",
"return",
"&",
"Listener",
"{",
"authServer",
":",
"cfg",
".",
"AuthServer",
",",
"handler",
":",
"cfg",
".",
"Handler",
",",
"listener",
":",
"l",
",",
"ServerVersion",
":",
"DefaultServerVersion",
",",
"connectionID",
":",
"1",
",",
"connReadTimeout",
":",
"cfg",
".",
"ConnReadTimeout",
",",
"connWriteTimeout",
":",
"cfg",
".",
"ConnWriteTimeout",
",",
"connReadBufferSize",
":",
"cfg",
".",
"ConnReadBufferSize",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewListenerWithConfig creates new listener using provided config. There are
// no default values for config, so caller should ensure its correctness. | [
"NewListenerWithConfig",
"creates",
"new",
"listener",
"using",
"provided",
"config",
".",
"There",
"are",
"no",
"default",
"values",
"for",
"config",
"so",
"caller",
"should",
"ensure",
"its",
"correctness",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/server.go#L197-L219 | train |
vitessio/vitess | go/mysql/server.go | Accept | func (l *Listener) Accept() {
for {
conn, err := l.listener.Accept()
if err != nil {
// Close() was probably called.
return
}
acceptTime := time.Now()
connectionID := l.connectionID
l.connectionID++
connCount.Add(1)
connAccept.Add(1)
go l.handle(conn, connectionID, acceptTime)
}
} | go | func (l *Listener) Accept() {
for {
conn, err := l.listener.Accept()
if err != nil {
// Close() was probably called.
return
}
acceptTime := time.Now()
connectionID := l.connectionID
l.connectionID++
connCount.Add(1)
connAccept.Add(1)
go l.handle(conn, connectionID, acceptTime)
}
} | [
"func",
"(",
"l",
"*",
"Listener",
")",
"Accept",
"(",
")",
"{",
"for",
"{",
"conn",
",",
"err",
":=",
"l",
".",
"listener",
".",
"Accept",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Close() was probably called.",
"return",
"\n",
"}",
"\n\n",
"acceptTime",
":=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"connectionID",
":=",
"l",
".",
"connectionID",
"\n",
"l",
".",
"connectionID",
"++",
"\n\n",
"connCount",
".",
"Add",
"(",
"1",
")",
"\n",
"connAccept",
".",
"Add",
"(",
"1",
")",
"\n\n",
"go",
"l",
".",
"handle",
"(",
"conn",
",",
"connectionID",
",",
"acceptTime",
")",
"\n",
"}",
"\n",
"}"
] | // Accept runs an accept loop until the listener is closed. | [
"Accept",
"runs",
"an",
"accept",
"loop",
"until",
"the",
"listener",
"is",
"closed",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/server.go#L227-L245 | train |
vitessio/vitess | go/mysql/server.go | Shutdown | func (l *Listener) Shutdown() {
if l.shutdown.CompareAndSwap(false, true) {
l.Close()
}
} | go | func (l *Listener) Shutdown() {
if l.shutdown.CompareAndSwap(false, true) {
l.Close()
}
} | [
"func",
"(",
"l",
"*",
"Listener",
")",
"Shutdown",
"(",
")",
"{",
"if",
"l",
".",
"shutdown",
".",
"CompareAndSwap",
"(",
"false",
",",
"true",
")",
"{",
"l",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Shutdown closes listener and fails any Ping requests from existing connections.
// This can be used for graceful shutdown, to let clients know that they should reconnect to another server. | [
"Shutdown",
"closes",
"listener",
"and",
"fails",
"any",
"Ping",
"requests",
"from",
"existing",
"connections",
".",
"This",
"can",
"be",
"used",
"for",
"graceful",
"shutdown",
"to",
"let",
"clients",
"know",
"that",
"they",
"should",
"reconnect",
"to",
"another",
"server",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/server.go#L455-L459 | train |
vitessio/vitess | go/mysql/server.go | writeHandshakeV10 | func (c *Conn) writeHandshakeV10(serverVersion string, authServer AuthServer, enableTLS bool) ([]byte, error) {
capabilities := CapabilityClientLongPassword |
CapabilityClientLongFlag |
CapabilityClientConnectWithDB |
CapabilityClientProtocol41 |
CapabilityClientTransactions |
CapabilityClientSecureConnection |
CapabilityClientMultiStatements |
CapabilityClientMultiResults |
CapabilityClientPluginAuth |
CapabilityClientPluginAuthLenencClientData |
CapabilityClientDeprecateEOF |
CapabilityClientConnAttr
if enableTLS {
capabilities |= CapabilityClientSSL
}
length :=
1 + // protocol version
lenNullString(serverVersion) +
4 + // connection ID
8 + // first part of salt data
1 + // filler byte
2 + // capability flags (lower 2 bytes)
1 + // character set
2 + // status flag
2 + // capability flags (upper 2 bytes)
1 + // length of auth plugin data
10 + // reserved (0)
13 + // auth-plugin-data
lenNullString(MysqlNativePassword) // auth-plugin-name
data := c.startEphemeralPacket(length)
pos := 0
// Protocol version.
pos = writeByte(data, pos, protocolVersion)
// Copy server version.
pos = writeNullString(data, pos, serverVersion)
// Add connectionID in.
pos = writeUint32(data, pos, c.ConnectionID)
// Generate the salt, put 8 bytes in.
salt, err := authServer.Salt()
if err != nil {
return nil, err
}
pos += copy(data[pos:], salt[:8])
// One filler byte, always 0.
pos = writeByte(data, pos, 0)
// Lower part of the capability flags.
pos = writeUint16(data, pos, uint16(capabilities))
// Character set.
pos = writeByte(data, pos, CharacterSetUtf8)
// Status flag.
pos = writeUint16(data, pos, c.StatusFlags)
// Upper part of the capability flags.
pos = writeUint16(data, pos, uint16(capabilities>>16))
// Length of auth plugin data.
// Always 21 (8 + 13).
pos = writeByte(data, pos, 21)
// Reserved 10 bytes: all 0
pos = writeZeroes(data, pos, 10)
// Second part of auth plugin data.
pos += copy(data[pos:], salt[8:])
data[pos] = 0
pos++
// Copy authPluginName. We always start with mysql_native_password.
pos = writeNullString(data, pos, MysqlNativePassword)
// Sanity check.
if pos != len(data) {
return nil, vterrors.Errorf(vtrpc.Code_INTERNAL, "error building Handshake packet: got %v bytes expected %v", pos, len(data))
}
if err := c.writeEphemeralPacket(); err != nil {
if strings.HasSuffix(err.Error(), "write: connection reset by peer") {
return nil, io.EOF
}
if strings.HasSuffix(err.Error(), "write: broken pipe") {
return nil, io.EOF
}
return nil, err
}
return salt, nil
} | go | func (c *Conn) writeHandshakeV10(serverVersion string, authServer AuthServer, enableTLS bool) ([]byte, error) {
capabilities := CapabilityClientLongPassword |
CapabilityClientLongFlag |
CapabilityClientConnectWithDB |
CapabilityClientProtocol41 |
CapabilityClientTransactions |
CapabilityClientSecureConnection |
CapabilityClientMultiStatements |
CapabilityClientMultiResults |
CapabilityClientPluginAuth |
CapabilityClientPluginAuthLenencClientData |
CapabilityClientDeprecateEOF |
CapabilityClientConnAttr
if enableTLS {
capabilities |= CapabilityClientSSL
}
length :=
1 + // protocol version
lenNullString(serverVersion) +
4 + // connection ID
8 + // first part of salt data
1 + // filler byte
2 + // capability flags (lower 2 bytes)
1 + // character set
2 + // status flag
2 + // capability flags (upper 2 bytes)
1 + // length of auth plugin data
10 + // reserved (0)
13 + // auth-plugin-data
lenNullString(MysqlNativePassword) // auth-plugin-name
data := c.startEphemeralPacket(length)
pos := 0
// Protocol version.
pos = writeByte(data, pos, protocolVersion)
// Copy server version.
pos = writeNullString(data, pos, serverVersion)
// Add connectionID in.
pos = writeUint32(data, pos, c.ConnectionID)
// Generate the salt, put 8 bytes in.
salt, err := authServer.Salt()
if err != nil {
return nil, err
}
pos += copy(data[pos:], salt[:8])
// One filler byte, always 0.
pos = writeByte(data, pos, 0)
// Lower part of the capability flags.
pos = writeUint16(data, pos, uint16(capabilities))
// Character set.
pos = writeByte(data, pos, CharacterSetUtf8)
// Status flag.
pos = writeUint16(data, pos, c.StatusFlags)
// Upper part of the capability flags.
pos = writeUint16(data, pos, uint16(capabilities>>16))
// Length of auth plugin data.
// Always 21 (8 + 13).
pos = writeByte(data, pos, 21)
// Reserved 10 bytes: all 0
pos = writeZeroes(data, pos, 10)
// Second part of auth plugin data.
pos += copy(data[pos:], salt[8:])
data[pos] = 0
pos++
// Copy authPluginName. We always start with mysql_native_password.
pos = writeNullString(data, pos, MysqlNativePassword)
// Sanity check.
if pos != len(data) {
return nil, vterrors.Errorf(vtrpc.Code_INTERNAL, "error building Handshake packet: got %v bytes expected %v", pos, len(data))
}
if err := c.writeEphemeralPacket(); err != nil {
if strings.HasSuffix(err.Error(), "write: connection reset by peer") {
return nil, io.EOF
}
if strings.HasSuffix(err.Error(), "write: broken pipe") {
return nil, io.EOF
}
return nil, err
}
return salt, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"writeHandshakeV10",
"(",
"serverVersion",
"string",
",",
"authServer",
"AuthServer",
",",
"enableTLS",
"bool",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"capabilities",
":=",
"CapabilityClientLongPassword",
"|",
"CapabilityClientLongFlag",
"|",
"CapabilityClientConnectWithDB",
"|",
"CapabilityClientProtocol41",
"|",
"CapabilityClientTransactions",
"|",
"CapabilityClientSecureConnection",
"|",
"CapabilityClientMultiStatements",
"|",
"CapabilityClientMultiResults",
"|",
"CapabilityClientPluginAuth",
"|",
"CapabilityClientPluginAuthLenencClientData",
"|",
"CapabilityClientDeprecateEOF",
"|",
"CapabilityClientConnAttr",
"\n",
"if",
"enableTLS",
"{",
"capabilities",
"|=",
"CapabilityClientSSL",
"\n",
"}",
"\n\n",
"length",
":=",
"1",
"+",
"// protocol version",
"lenNullString",
"(",
"serverVersion",
")",
"+",
"4",
"+",
"// connection ID",
"8",
"+",
"// first part of salt data",
"1",
"+",
"// filler byte",
"2",
"+",
"// capability flags (lower 2 bytes)",
"1",
"+",
"// character set",
"2",
"+",
"// status flag",
"2",
"+",
"// capability flags (upper 2 bytes)",
"1",
"+",
"// length of auth plugin data",
"10",
"+",
"// reserved (0)",
"13",
"+",
"// auth-plugin-data",
"lenNullString",
"(",
"MysqlNativePassword",
")",
"// auth-plugin-name",
"\n\n",
"data",
":=",
"c",
".",
"startEphemeralPacket",
"(",
"length",
")",
"\n",
"pos",
":=",
"0",
"\n\n",
"// Protocol version.",
"pos",
"=",
"writeByte",
"(",
"data",
",",
"pos",
",",
"protocolVersion",
")",
"\n\n",
"// Copy server version.",
"pos",
"=",
"writeNullString",
"(",
"data",
",",
"pos",
",",
"serverVersion",
")",
"\n\n",
"// Add connectionID in.",
"pos",
"=",
"writeUint32",
"(",
"data",
",",
"pos",
",",
"c",
".",
"ConnectionID",
")",
"\n\n",
"// Generate the salt, put 8 bytes in.",
"salt",
",",
"err",
":=",
"authServer",
".",
"Salt",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"pos",
"+=",
"copy",
"(",
"data",
"[",
"pos",
":",
"]",
",",
"salt",
"[",
":",
"8",
"]",
")",
"\n\n",
"// One filler byte, always 0.",
"pos",
"=",
"writeByte",
"(",
"data",
",",
"pos",
",",
"0",
")",
"\n\n",
"// Lower part of the capability flags.",
"pos",
"=",
"writeUint16",
"(",
"data",
",",
"pos",
",",
"uint16",
"(",
"capabilities",
")",
")",
"\n\n",
"// Character set.",
"pos",
"=",
"writeByte",
"(",
"data",
",",
"pos",
",",
"CharacterSetUtf8",
")",
"\n\n",
"// Status flag.",
"pos",
"=",
"writeUint16",
"(",
"data",
",",
"pos",
",",
"c",
".",
"StatusFlags",
")",
"\n\n",
"// Upper part of the capability flags.",
"pos",
"=",
"writeUint16",
"(",
"data",
",",
"pos",
",",
"uint16",
"(",
"capabilities",
">>",
"16",
")",
")",
"\n\n",
"// Length of auth plugin data.",
"// Always 21 (8 + 13).",
"pos",
"=",
"writeByte",
"(",
"data",
",",
"pos",
",",
"21",
")",
"\n\n",
"// Reserved 10 bytes: all 0",
"pos",
"=",
"writeZeroes",
"(",
"data",
",",
"pos",
",",
"10",
")",
"\n\n",
"// Second part of auth plugin data.",
"pos",
"+=",
"copy",
"(",
"data",
"[",
"pos",
":",
"]",
",",
"salt",
"[",
"8",
":",
"]",
")",
"\n",
"data",
"[",
"pos",
"]",
"=",
"0",
"\n",
"pos",
"++",
"\n\n",
"// Copy authPluginName. We always start with mysql_native_password.",
"pos",
"=",
"writeNullString",
"(",
"data",
",",
"pos",
",",
"MysqlNativePassword",
")",
"\n\n",
"// Sanity check.",
"if",
"pos",
"!=",
"len",
"(",
"data",
")",
"{",
"return",
"nil",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_INTERNAL",
",",
"\"",
"\"",
",",
"pos",
",",
"len",
"(",
"data",
")",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"writeEphemeralPacket",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"strings",
".",
"HasSuffix",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"return",
"nil",
",",
"io",
".",
"EOF",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasSuffix",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"return",
"nil",
",",
"io",
".",
"EOF",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"salt",
",",
"nil",
"\n",
"}"
] | // writeHandshakeV10 writes the Initial Handshake Packet, server side.
// It returns the salt data. | [
"writeHandshakeV10",
"writes",
"the",
"Initial",
"Handshake",
"Packet",
"server",
"side",
".",
"It",
"returns",
"the",
"salt",
"data",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/server.go#L467-L565 | train |
vitessio/vitess | go/mysql/server.go | writeAuthSwitchRequest | func (c *Conn) writeAuthSwitchRequest(pluginName string, pluginData []byte) error {
length := 1 + // AuthSwitchRequestPacket
len(pluginName) + 1 + // 0-terminated pluginName
len(pluginData)
data := c.startEphemeralPacket(length)
pos := 0
// Packet header.
pos = writeByte(data, pos, AuthSwitchRequestPacket)
// Copy server version.
pos = writeNullString(data, pos, pluginName)
// Copy auth data.
pos += copy(data[pos:], pluginData)
// Sanity check.
if pos != len(data) {
return vterrors.Errorf(vtrpc.Code_INTERNAL, "error building AuthSwitchRequestPacket packet: got %v bytes expected %v", pos, len(data))
}
return c.writeEphemeralPacket()
} | go | func (c *Conn) writeAuthSwitchRequest(pluginName string, pluginData []byte) error {
length := 1 + // AuthSwitchRequestPacket
len(pluginName) + 1 + // 0-terminated pluginName
len(pluginData)
data := c.startEphemeralPacket(length)
pos := 0
// Packet header.
pos = writeByte(data, pos, AuthSwitchRequestPacket)
// Copy server version.
pos = writeNullString(data, pos, pluginName)
// Copy auth data.
pos += copy(data[pos:], pluginData)
// Sanity check.
if pos != len(data) {
return vterrors.Errorf(vtrpc.Code_INTERNAL, "error building AuthSwitchRequestPacket packet: got %v bytes expected %v", pos, len(data))
}
return c.writeEphemeralPacket()
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"writeAuthSwitchRequest",
"(",
"pluginName",
"string",
",",
"pluginData",
"[",
"]",
"byte",
")",
"error",
"{",
"length",
":=",
"1",
"+",
"// AuthSwitchRequestPacket",
"len",
"(",
"pluginName",
")",
"+",
"1",
"+",
"// 0-terminated pluginName",
"len",
"(",
"pluginData",
")",
"\n\n",
"data",
":=",
"c",
".",
"startEphemeralPacket",
"(",
"length",
")",
"\n",
"pos",
":=",
"0",
"\n\n",
"// Packet header.",
"pos",
"=",
"writeByte",
"(",
"data",
",",
"pos",
",",
"AuthSwitchRequestPacket",
")",
"\n\n",
"// Copy server version.",
"pos",
"=",
"writeNullString",
"(",
"data",
",",
"pos",
",",
"pluginName",
")",
"\n\n",
"// Copy auth data.",
"pos",
"+=",
"copy",
"(",
"data",
"[",
"pos",
":",
"]",
",",
"pluginData",
")",
"\n\n",
"// Sanity check.",
"if",
"pos",
"!=",
"len",
"(",
"data",
")",
"{",
"return",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_INTERNAL",
",",
"\"",
"\"",
",",
"pos",
",",
"len",
"(",
"data",
")",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"writeEphemeralPacket",
"(",
")",
"\n",
"}"
] | // writeAuthSwitchRequest writes an auth switch request packet. | [
"writeAuthSwitchRequest",
"writes",
"an",
"auth",
"switch",
"request",
"packet",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/server.go#L743-L765 | train |
vitessio/vitess | go/mysql/server.go | tlsVersionToString | func tlsVersionToString(version uint16) string {
switch version {
case tls.VersionSSL30:
return versionSSL30
case tls.VersionTLS10:
return versionTLS10
case tls.VersionTLS11:
return versionTLS11
case tls.VersionTLS12:
return versionTLS12
default:
return versionTLSUnknown
}
} | go | func tlsVersionToString(version uint16) string {
switch version {
case tls.VersionSSL30:
return versionSSL30
case tls.VersionTLS10:
return versionTLS10
case tls.VersionTLS11:
return versionTLS11
case tls.VersionTLS12:
return versionTLS12
default:
return versionTLSUnknown
}
} | [
"func",
"tlsVersionToString",
"(",
"version",
"uint16",
")",
"string",
"{",
"switch",
"version",
"{",
"case",
"tls",
".",
"VersionSSL30",
":",
"return",
"versionSSL30",
"\n",
"case",
"tls",
".",
"VersionTLS10",
":",
"return",
"versionTLS10",
"\n",
"case",
"tls",
".",
"VersionTLS11",
":",
"return",
"versionTLS11",
"\n",
"case",
"tls",
".",
"VersionTLS12",
":",
"return",
"versionTLS12",
"\n",
"default",
":",
"return",
"versionTLSUnknown",
"\n",
"}",
"\n",
"}"
] | // Whenever we move to a new version of go, we will need add any new supported TLS versions here | [
"Whenever",
"we",
"move",
"to",
"a",
"new",
"version",
"of",
"go",
"we",
"will",
"need",
"add",
"any",
"new",
"supported",
"TLS",
"versions",
"here"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/server.go#L768-L781 | train |
vitessio/vitess | go/vt/vtgate/vindexes/numeric_static_map.go | NewNumericStaticMap | func NewNumericStaticMap(name string, params map[string]string) (Vindex, error) {
jsonPath, ok := params["json_path"]
if !ok {
return nil, errors.New("NumericStaticMap: Could not find `json_path` param in vschema")
}
lt, err := loadNumericLookupTable(jsonPath)
if err != nil {
return nil, err
}
return &NumericStaticMap{
name: name,
lookup: lt,
}, nil
} | go | func NewNumericStaticMap(name string, params map[string]string) (Vindex, error) {
jsonPath, ok := params["json_path"]
if !ok {
return nil, errors.New("NumericStaticMap: Could not find `json_path` param in vschema")
}
lt, err := loadNumericLookupTable(jsonPath)
if err != nil {
return nil, err
}
return &NumericStaticMap{
name: name,
lookup: lt,
}, nil
} | [
"func",
"NewNumericStaticMap",
"(",
"name",
"string",
",",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"Vindex",
",",
"error",
")",
"{",
"jsonPath",
",",
"ok",
":=",
"params",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"lt",
",",
"err",
":=",
"loadNumericLookupTable",
"(",
"jsonPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"NumericStaticMap",
"{",
"name",
":",
"name",
",",
"lookup",
":",
"lt",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewNumericStaticMap creates a NumericStaticMap vindex. | [
"NewNumericStaticMap",
"creates",
"a",
"NumericStaticMap",
"vindex",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/numeric_static_map.go#L51-L66 | train |
vitessio/vitess | go/vt/vtgate/vindexes/numeric_static_map.go | Verify | func (vind *NumericStaticMap) Verify(_ VCursor, ids []sqltypes.Value, ksids [][]byte) ([]bool, error) {
out := make([]bool, len(ids))
for i := range ids {
var keybytes [8]byte
num, err := sqltypes.ToUint64(ids[i])
if err != nil {
return nil, vterrors.Wrap(err, "NumericStaticMap.Verify")
}
lookupNum, ok := vind.lookup[num]
if ok {
num = lookupNum
}
binary.BigEndian.PutUint64(keybytes[:], num)
out[i] = bytes.Equal(keybytes[:], ksids[i])
}
return out, nil
} | go | func (vind *NumericStaticMap) Verify(_ VCursor, ids []sqltypes.Value, ksids [][]byte) ([]bool, error) {
out := make([]bool, len(ids))
for i := range ids {
var keybytes [8]byte
num, err := sqltypes.ToUint64(ids[i])
if err != nil {
return nil, vterrors.Wrap(err, "NumericStaticMap.Verify")
}
lookupNum, ok := vind.lookup[num]
if ok {
num = lookupNum
}
binary.BigEndian.PutUint64(keybytes[:], num)
out[i] = bytes.Equal(keybytes[:], ksids[i])
}
return out, nil
} | [
"func",
"(",
"vind",
"*",
"NumericStaticMap",
")",
"Verify",
"(",
"_",
"VCursor",
",",
"ids",
"[",
"]",
"sqltypes",
".",
"Value",
",",
"ksids",
"[",
"]",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"bool",
",",
"error",
")",
"{",
"out",
":=",
"make",
"(",
"[",
"]",
"bool",
",",
"len",
"(",
"ids",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"ids",
"{",
"var",
"keybytes",
"[",
"8",
"]",
"byte",
"\n",
"num",
",",
"err",
":=",
"sqltypes",
".",
"ToUint64",
"(",
"ids",
"[",
"i",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"vterrors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"lookupNum",
",",
"ok",
":=",
"vind",
".",
"lookup",
"[",
"num",
"]",
"\n",
"if",
"ok",
"{",
"num",
"=",
"lookupNum",
"\n",
"}",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint64",
"(",
"keybytes",
"[",
":",
"]",
",",
"num",
")",
"\n",
"out",
"[",
"i",
"]",
"=",
"bytes",
".",
"Equal",
"(",
"keybytes",
"[",
":",
"]",
",",
"ksids",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"return",
"out",
",",
"nil",
"\n",
"}"
] | // Verify returns true if ids and ksids match. | [
"Verify",
"returns",
"true",
"if",
"ids",
"and",
"ksids",
"match",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/numeric_static_map.go#L89-L105 | train |
vitessio/vitess | go/mysql/binlog_event.go | String | func (q Query) String() string {
return fmt.Sprintf("{Database: %q, Charset: %v, SQL: %q}",
q.Database, q.Charset, q.SQL)
} | go | func (q Query) String() string {
return fmt.Sprintf("{Database: %q, Charset: %v, SQL: %q}",
q.Database, q.Charset, q.SQL)
} | [
"func",
"(",
"q",
"Query",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"q",
".",
"Database",
",",
"q",
".",
"Charset",
",",
"q",
".",
"SQL",
")",
"\n",
"}"
] | // String pretty-prints a Query. | [
"String",
"pretty",
"-",
"prints",
"a",
"Query",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event.go#L169-L172 | train |
vitessio/vitess | go/mysql/binlog_event.go | NewServerBitmap | func NewServerBitmap(count int) Bitmap {
byteSize := (count + 7) / 8
return Bitmap{
data: make([]byte, byteSize),
count: count,
}
} | go | func NewServerBitmap(count int) Bitmap {
byteSize := (count + 7) / 8
return Bitmap{
data: make([]byte, byteSize),
count: count,
}
} | [
"func",
"NewServerBitmap",
"(",
"count",
"int",
")",
"Bitmap",
"{",
"byteSize",
":=",
"(",
"count",
"+",
"7",
")",
"/",
"8",
"\n",
"return",
"Bitmap",
"{",
"data",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"byteSize",
")",
",",
"count",
":",
"count",
",",
"}",
"\n",
"}"
] | // NewServerBitmap returns a bitmap that can hold 'count' bits. | [
"NewServerBitmap",
"returns",
"a",
"bitmap",
"that",
"can",
"hold",
"count",
"bits",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event.go#L257-L263 | train |
vitessio/vitess | go/mysql/binlog_event.go | Bit | func (b *Bitmap) Bit(index int) bool {
byteIndex := index / 8
bitMask := byte(1 << (uint(index) & 0x7))
return b.data[byteIndex]&bitMask > 0
} | go | func (b *Bitmap) Bit(index int) bool {
byteIndex := index / 8
bitMask := byte(1 << (uint(index) & 0x7))
return b.data[byteIndex]&bitMask > 0
} | [
"func",
"(",
"b",
"*",
"Bitmap",
")",
"Bit",
"(",
"index",
"int",
")",
"bool",
"{",
"byteIndex",
":=",
"index",
"/",
"8",
"\n",
"bitMask",
":=",
"byte",
"(",
"1",
"<<",
"(",
"uint",
"(",
"index",
")",
"&",
"0x7",
")",
")",
"\n",
"return",
"b",
".",
"data",
"[",
"byteIndex",
"]",
"&",
"bitMask",
">",
"0",
"\n",
"}"
] | // Bit returned the value of a given bit in the Bitmap. | [
"Bit",
"returned",
"the",
"value",
"of",
"a",
"given",
"bit",
"in",
"the",
"Bitmap",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event.go#L271-L275 | train |
vitessio/vitess | go/mysql/binlog_event.go | Set | func (b *Bitmap) Set(index int, value bool) {
byteIndex := index / 8
bitMask := byte(1 << (uint(index) & 0x7))
if value {
b.data[byteIndex] |= bitMask
} else {
b.data[byteIndex] &= 0xff - bitMask
}
} | go | func (b *Bitmap) Set(index int, value bool) {
byteIndex := index / 8
bitMask := byte(1 << (uint(index) & 0x7))
if value {
b.data[byteIndex] |= bitMask
} else {
b.data[byteIndex] &= 0xff - bitMask
}
} | [
"func",
"(",
"b",
"*",
"Bitmap",
")",
"Set",
"(",
"index",
"int",
",",
"value",
"bool",
")",
"{",
"byteIndex",
":=",
"index",
"/",
"8",
"\n",
"bitMask",
":=",
"byte",
"(",
"1",
"<<",
"(",
"uint",
"(",
"index",
")",
"&",
"0x7",
")",
")",
"\n",
"if",
"value",
"{",
"b",
".",
"data",
"[",
"byteIndex",
"]",
"|=",
"bitMask",
"\n",
"}",
"else",
"{",
"b",
".",
"data",
"[",
"byteIndex",
"]",
"&=",
"0xff",
"-",
"bitMask",
"\n",
"}",
"\n",
"}"
] | // Set sets the given boolean value. | [
"Set",
"sets",
"the",
"given",
"boolean",
"value",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event.go#L278-L286 | train |
vitessio/vitess | go/mysql/binlog_event.go | BitCount | func (b *Bitmap) BitCount() int {
sum := 0
for i := 0; i < b.count; i++ {
if b.Bit(i) {
sum++
}
}
return sum
} | go | func (b *Bitmap) BitCount() int {
sum := 0
for i := 0; i < b.count; i++ {
if b.Bit(i) {
sum++
}
}
return sum
} | [
"func",
"(",
"b",
"*",
"Bitmap",
")",
"BitCount",
"(",
")",
"int",
"{",
"sum",
":=",
"0",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"b",
".",
"count",
";",
"i",
"++",
"{",
"if",
"b",
".",
"Bit",
"(",
"i",
")",
"{",
"sum",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"sum",
"\n",
"}"
] | // BitCount returns how many bits are set in the bitmap.
// Note values that are not used may be set to 0 or 1,
// hence the non-efficient logic. | [
"BitCount",
"returns",
"how",
"many",
"bits",
"are",
"set",
"in",
"the",
"bitmap",
".",
"Note",
"values",
"that",
"are",
"not",
"used",
"may",
"be",
"set",
"to",
"0",
"or",
"1",
"hence",
"the",
"non",
"-",
"efficient",
"logic",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/binlog_event.go#L291-L299 | train |
vitessio/vitess | go/vt/binlog/event_streamer.go | NewEventStreamer | func NewEventStreamer(cp *mysql.ConnParams, se *schema.Engine, startPos mysql.Position, timestamp int64, sendEvent sendEventFunc) *EventStreamer {
evs := &EventStreamer{
sendEvent: sendEvent,
}
evs.bls = NewStreamer(cp, se, nil, startPos, timestamp, evs.transactionToEvent)
evs.bls.extractPK = true
return evs
} | go | func NewEventStreamer(cp *mysql.ConnParams, se *schema.Engine, startPos mysql.Position, timestamp int64, sendEvent sendEventFunc) *EventStreamer {
evs := &EventStreamer{
sendEvent: sendEvent,
}
evs.bls = NewStreamer(cp, se, nil, startPos, timestamp, evs.transactionToEvent)
evs.bls.extractPK = true
return evs
} | [
"func",
"NewEventStreamer",
"(",
"cp",
"*",
"mysql",
".",
"ConnParams",
",",
"se",
"*",
"schema",
".",
"Engine",
",",
"startPos",
"mysql",
".",
"Position",
",",
"timestamp",
"int64",
",",
"sendEvent",
"sendEventFunc",
")",
"*",
"EventStreamer",
"{",
"evs",
":=",
"&",
"EventStreamer",
"{",
"sendEvent",
":",
"sendEvent",
",",
"}",
"\n",
"evs",
".",
"bls",
"=",
"NewStreamer",
"(",
"cp",
",",
"se",
",",
"nil",
",",
"startPos",
",",
"timestamp",
",",
"evs",
".",
"transactionToEvent",
")",
"\n",
"evs",
".",
"bls",
".",
"extractPK",
"=",
"true",
"\n",
"return",
"evs",
"\n",
"}"
] | // NewEventStreamer returns a new EventStreamer on top of a Streamer | [
"NewEventStreamer",
"returns",
"a",
"new",
"EventStreamer",
"on",
"top",
"of",
"a",
"Streamer"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/binlog/event_streamer.go#L54-L61 | train |
vitessio/vitess | go/vt/binlog/event_streamer.go | Stream | func (evs *EventStreamer) Stream(ctx context.Context) error {
return evs.bls.Stream(ctx)
} | go | func (evs *EventStreamer) Stream(ctx context.Context) error {
return evs.bls.Stream(ctx)
} | [
"func",
"(",
"evs",
"*",
"EventStreamer",
")",
"Stream",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"return",
"evs",
".",
"bls",
".",
"Stream",
"(",
"ctx",
")",
"\n",
"}"
] | // Stream starts streaming updates | [
"Stream",
"starts",
"streaming",
"updates"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/binlog/event_streamer.go#L64-L66 | train |
vitessio/vitess | go/vt/topo/consultopo/error.go | convertError | func convertError(err error, nodePath string) error {
switch err {
case context.Canceled:
return topo.NewError(topo.Interrupted, nodePath)
case context.DeadlineExceeded:
return topo.NewError(topo.Timeout, nodePath)
}
return err
} | go | func convertError(err error, nodePath string) error {
switch err {
case context.Canceled:
return topo.NewError(topo.Interrupted, nodePath)
case context.DeadlineExceeded:
return topo.NewError(topo.Timeout, nodePath)
}
return err
} | [
"func",
"convertError",
"(",
"err",
"error",
",",
"nodePath",
"string",
")",
"error",
"{",
"switch",
"err",
"{",
"case",
"context",
".",
"Canceled",
":",
"return",
"topo",
".",
"NewError",
"(",
"topo",
".",
"Interrupted",
",",
"nodePath",
")",
"\n",
"case",
"context",
".",
"DeadlineExceeded",
":",
"return",
"topo",
".",
"NewError",
"(",
"topo",
".",
"Timeout",
",",
"nodePath",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // convertError converts a context error into a topo error. All errors
// are either application-level errors, or context errors. | [
"convertError",
"converts",
"a",
"context",
"error",
"into",
"a",
"topo",
"error",
".",
"All",
"errors",
"are",
"either",
"application",
"-",
"level",
"errors",
"or",
"context",
"errors",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/consultopo/error.go#L40-L48 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/messager/cache.go | newCache | func newCache(size int) *cache {
mc := &cache{
size: size,
inQueue: make(map[string]*MessageRow),
inFlight: make(map[string]bool),
}
return mc
} | go | func newCache(size int) *cache {
mc := &cache{
size: size,
inQueue: make(map[string]*MessageRow),
inFlight: make(map[string]bool),
}
return mc
} | [
"func",
"newCache",
"(",
"size",
"int",
")",
"*",
"cache",
"{",
"mc",
":=",
"&",
"cache",
"{",
"size",
":",
"size",
",",
"inQueue",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"MessageRow",
")",
",",
"inFlight",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
",",
"}",
"\n",
"return",
"mc",
"\n",
"}"
] | // NewMessagerCache creates a new cache. | [
"NewMessagerCache",
"creates",
"a",
"new",
"cache",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/messager/cache.go#L96-L103 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/messager/cache.go | Add | func (mc *cache) Add(mr *MessageRow) bool {
mc.mu.Lock()
defer mc.mu.Unlock()
if len(mc.sendQueue) >= mc.size {
return false
}
id := mr.Row[0].ToString()
if mc.inFlight[id] {
return true
}
if _, ok := mc.inQueue[id]; ok {
return true
}
heap.Push(&mc.sendQueue, mr)
mc.inQueue[id] = mr
return true
} | go | func (mc *cache) Add(mr *MessageRow) bool {
mc.mu.Lock()
defer mc.mu.Unlock()
if len(mc.sendQueue) >= mc.size {
return false
}
id := mr.Row[0].ToString()
if mc.inFlight[id] {
return true
}
if _, ok := mc.inQueue[id]; ok {
return true
}
heap.Push(&mc.sendQueue, mr)
mc.inQueue[id] = mr
return true
} | [
"func",
"(",
"mc",
"*",
"cache",
")",
"Add",
"(",
"mr",
"*",
"MessageRow",
")",
"bool",
"{",
"mc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mc",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"len",
"(",
"mc",
".",
"sendQueue",
")",
">=",
"mc",
".",
"size",
"{",
"return",
"false",
"\n",
"}",
"\n",
"id",
":=",
"mr",
".",
"Row",
"[",
"0",
"]",
".",
"ToString",
"(",
")",
"\n",
"if",
"mc",
".",
"inFlight",
"[",
"id",
"]",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"mc",
".",
"inQueue",
"[",
"id",
"]",
";",
"ok",
"{",
"return",
"true",
"\n",
"}",
"\n",
"heap",
".",
"Push",
"(",
"&",
"mc",
".",
"sendQueue",
",",
"mr",
")",
"\n",
"mc",
".",
"inQueue",
"[",
"id",
"]",
"=",
"mr",
"\n",
"return",
"true",
"\n",
"}"
] | // Add adds a MessageRow to the cache. It returns
// false if the cache is full. | [
"Add",
"adds",
"a",
"MessageRow",
"to",
"the",
"cache",
".",
"It",
"returns",
"false",
"if",
"the",
"cache",
"is",
"full",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/messager/cache.go#L116-L132 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/messager/cache.go | Pop | func (mc *cache) Pop() *MessageRow {
mc.mu.Lock()
defer mc.mu.Unlock()
for {
if len(mc.sendQueue) == 0 {
return nil
}
mr := heap.Pop(&mc.sendQueue).(*MessageRow)
// If message was previously marked as defunct, drop
// it and continue.
if mr.defunct {
continue
}
id := mr.Row[0].ToString()
// Move the message from inQueue to inFlight.
delete(mc.inQueue, id)
mc.inFlight[id] = true
return mr
}
} | go | func (mc *cache) Pop() *MessageRow {
mc.mu.Lock()
defer mc.mu.Unlock()
for {
if len(mc.sendQueue) == 0 {
return nil
}
mr := heap.Pop(&mc.sendQueue).(*MessageRow)
// If message was previously marked as defunct, drop
// it and continue.
if mr.defunct {
continue
}
id := mr.Row[0].ToString()
// Move the message from inQueue to inFlight.
delete(mc.inQueue, id)
mc.inFlight[id] = true
return mr
}
} | [
"func",
"(",
"mc",
"*",
"cache",
")",
"Pop",
"(",
")",
"*",
"MessageRow",
"{",
"mc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mc",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"for",
"{",
"if",
"len",
"(",
"mc",
".",
"sendQueue",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"mr",
":=",
"heap",
".",
"Pop",
"(",
"&",
"mc",
".",
"sendQueue",
")",
".",
"(",
"*",
"MessageRow",
")",
"\n",
"// If message was previously marked as defunct, drop",
"// it and continue.",
"if",
"mr",
".",
"defunct",
"{",
"continue",
"\n",
"}",
"\n",
"id",
":=",
"mr",
".",
"Row",
"[",
"0",
"]",
".",
"ToString",
"(",
")",
"\n\n",
"// Move the message from inQueue to inFlight.",
"delete",
"(",
"mc",
".",
"inQueue",
",",
"id",
")",
"\n",
"mc",
".",
"inFlight",
"[",
"id",
"]",
"=",
"true",
"\n",
"return",
"mr",
"\n",
"}",
"\n",
"}"
] | // Pop removes the next MessageRow. Once the
// message has been sent, Discard must be called.
// The discard has to happen as a separate operation
// to prevent the poller thread from repopulating the
// message while it's being sent.
// If the Cache is empty Pop returns nil. | [
"Pop",
"removes",
"the",
"next",
"MessageRow",
".",
"Once",
"the",
"message",
"has",
"been",
"sent",
"Discard",
"must",
"be",
"called",
".",
"The",
"discard",
"has",
"to",
"happen",
"as",
"a",
"separate",
"operation",
"to",
"prevent",
"the",
"poller",
"thread",
"from",
"repopulating",
"the",
"message",
"while",
"it",
"s",
"being",
"sent",
".",
"If",
"the",
"Cache",
"is",
"empty",
"Pop",
"returns",
"nil",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/messager/cache.go#L140-L160 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/messager/cache.go | Discard | func (mc *cache) Discard(ids []string) {
mc.mu.Lock()
defer mc.mu.Unlock()
for _, id := range ids {
if mr := mc.inQueue[id]; mr != nil {
// The row is still in the queue somewhere. Mark
// it as defunct. It will be "garbage collected" later.
mr.defunct = true
}
delete(mc.inQueue, id)
delete(mc.inFlight, id)
}
} | go | func (mc *cache) Discard(ids []string) {
mc.mu.Lock()
defer mc.mu.Unlock()
for _, id := range ids {
if mr := mc.inQueue[id]; mr != nil {
// The row is still in the queue somewhere. Mark
// it as defunct. It will be "garbage collected" later.
mr.defunct = true
}
delete(mc.inQueue, id)
delete(mc.inFlight, id)
}
} | [
"func",
"(",
"mc",
"*",
"cache",
")",
"Discard",
"(",
"ids",
"[",
"]",
"string",
")",
"{",
"mc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mc",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"ids",
"{",
"if",
"mr",
":=",
"mc",
".",
"inQueue",
"[",
"id",
"]",
";",
"mr",
"!=",
"nil",
"{",
"// The row is still in the queue somewhere. Mark",
"// it as defunct. It will be \"garbage collected\" later.",
"mr",
".",
"defunct",
"=",
"true",
"\n",
"}",
"\n",
"delete",
"(",
"mc",
".",
"inQueue",
",",
"id",
")",
"\n",
"delete",
"(",
"mc",
".",
"inFlight",
",",
"id",
")",
"\n",
"}",
"\n",
"}"
] | // Discard forgets the specified id. | [
"Discard",
"forgets",
"the",
"specified",
"id",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/messager/cache.go#L163-L175 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/messager/cache.go | Size | func (mc *cache) Size() int {
mc.mu.Lock()
defer mc.mu.Unlock()
return mc.size
} | go | func (mc *cache) Size() int {
mc.mu.Lock()
defer mc.mu.Unlock()
return mc.size
} | [
"func",
"(",
"mc",
"*",
"cache",
")",
"Size",
"(",
")",
"int",
"{",
"mc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mc",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"mc",
".",
"size",
"\n",
"}"
] | // Size returns the max size of cache. | [
"Size",
"returns",
"the",
"max",
"size",
"of",
"cache",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/messager/cache.go#L178-L182 | train |
vitessio/vitess | go/vt/dtids/dtids.go | New | func New(mmShard *vtgatepb.Session_ShardSession) string {
return fmt.Sprintf("%s:%s:%d", mmShard.Target.Keyspace, mmShard.Target.Shard, mmShard.TransactionId)
} | go | func New(mmShard *vtgatepb.Session_ShardSession) string {
return fmt.Sprintf("%s:%s:%d", mmShard.Target.Keyspace, mmShard.Target.Shard, mmShard.TransactionId)
} | [
"func",
"New",
"(",
"mmShard",
"*",
"vtgatepb",
".",
"Session_ShardSession",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"mmShard",
".",
"Target",
".",
"Keyspace",
",",
"mmShard",
".",
"Target",
".",
"Shard",
",",
"mmShard",
".",
"TransactionId",
")",
"\n",
"}"
] | // New generates a dtid based on Session_ShardSession. | [
"New",
"generates",
"a",
"dtid",
"based",
"on",
"Session_ShardSession",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/dtids/dtids.go#L34-L36 | train |
vitessio/vitess | go/vt/dtids/dtids.go | ShardSession | func ShardSession(dtid string) (*vtgatepb.Session_ShardSession, error) {
splits := strings.Split(dtid, ":")
if len(splits) != 3 {
return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "invalid parts in dtid: %s", dtid)
}
target := &querypb.Target{
Keyspace: splits[0],
Shard: splits[1],
TabletType: topodatapb.TabletType_MASTER,
}
txid, err := strconv.ParseInt(splits[2], 10, 0)
if err != nil {
return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "invalid transaction id in dtid: %s", dtid)
}
return &vtgatepb.Session_ShardSession{
Target: target,
TransactionId: txid,
}, nil
} | go | func ShardSession(dtid string) (*vtgatepb.Session_ShardSession, error) {
splits := strings.Split(dtid, ":")
if len(splits) != 3 {
return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "invalid parts in dtid: %s", dtid)
}
target := &querypb.Target{
Keyspace: splits[0],
Shard: splits[1],
TabletType: topodatapb.TabletType_MASTER,
}
txid, err := strconv.ParseInt(splits[2], 10, 0)
if err != nil {
return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "invalid transaction id in dtid: %s", dtid)
}
return &vtgatepb.Session_ShardSession{
Target: target,
TransactionId: txid,
}, nil
} | [
"func",
"ShardSession",
"(",
"dtid",
"string",
")",
"(",
"*",
"vtgatepb",
".",
"Session_ShardSession",
",",
"error",
")",
"{",
"splits",
":=",
"strings",
".",
"Split",
"(",
"dtid",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"splits",
")",
"!=",
"3",
"{",
"return",
"nil",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpcpb",
".",
"Code_INVALID_ARGUMENT",
",",
"\"",
"\"",
",",
"dtid",
")",
"\n",
"}",
"\n",
"target",
":=",
"&",
"querypb",
".",
"Target",
"{",
"Keyspace",
":",
"splits",
"[",
"0",
"]",
",",
"Shard",
":",
"splits",
"[",
"1",
"]",
",",
"TabletType",
":",
"topodatapb",
".",
"TabletType_MASTER",
",",
"}",
"\n",
"txid",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"splits",
"[",
"2",
"]",
",",
"10",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpcpb",
".",
"Code_INVALID_ARGUMENT",
",",
"\"",
"\"",
",",
"dtid",
")",
"\n",
"}",
"\n",
"return",
"&",
"vtgatepb",
".",
"Session_ShardSession",
"{",
"Target",
":",
"target",
",",
"TransactionId",
":",
"txid",
",",
"}",
",",
"nil",
"\n",
"}"
] | // ShardSession builds a Session_ShardSession from a dtid. | [
"ShardSession",
"builds",
"a",
"Session_ShardSession",
"from",
"a",
"dtid",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/dtids/dtids.go#L39-L57 | train |
vitessio/vitess | go/vt/dtids/dtids.go | TransactionID | func TransactionID(dtid string) (int64, error) {
splits := strings.Split(dtid, ":")
if len(splits) != 3 {
return 0, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "invalid parts in dtid: %s", dtid)
}
txid, err := strconv.ParseInt(splits[2], 10, 0)
if err != nil {
return 0, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "invalid transaction id in dtid: %s", dtid)
}
return txid, nil
} | go | func TransactionID(dtid string) (int64, error) {
splits := strings.Split(dtid, ":")
if len(splits) != 3 {
return 0, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "invalid parts in dtid: %s", dtid)
}
txid, err := strconv.ParseInt(splits[2], 10, 0)
if err != nil {
return 0, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "invalid transaction id in dtid: %s", dtid)
}
return txid, nil
} | [
"func",
"TransactionID",
"(",
"dtid",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"splits",
":=",
"strings",
".",
"Split",
"(",
"dtid",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"splits",
")",
"!=",
"3",
"{",
"return",
"0",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpcpb",
".",
"Code_INVALID_ARGUMENT",
",",
"\"",
"\"",
",",
"dtid",
")",
"\n",
"}",
"\n",
"txid",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"splits",
"[",
"2",
"]",
",",
"10",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpcpb",
".",
"Code_INVALID_ARGUMENT",
",",
"\"",
"\"",
",",
"dtid",
")",
"\n",
"}",
"\n",
"return",
"txid",
",",
"nil",
"\n",
"}"
] | // TransactionID extracts the original transaction ID from the dtid. | [
"TransactionID",
"extracts",
"the",
"original",
"transaction",
"ID",
"from",
"the",
"dtid",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/dtids/dtids.go#L60-L70 | train |
vitessio/vitess | go/cmd/vtexplain/vtexplain.go | flagUsage | func flagUsage(f *flag.Flag) {
s := fmt.Sprintf(" -%s", f.Name) // Two spaces before -; see next two comments.
name, usage := flag.UnquoteUsage(f)
if len(name) > 0 {
s += " " + name
}
// Boolean flags of one ASCII letter are so common we
// treat them specially, putting their usage on the same line.
if len(s) <= 4 { // space, space, '-', 'x'.
s += "\t"
} else {
// Four spaces before the tab triggers good alignment
// for both 4- and 8-space tab stops.
s += "\n \t"
}
s += usage
if name == "string" {
// put quotes on the value
s += fmt.Sprintf(" (default %q)", f.DefValue)
} else {
s += fmt.Sprintf(" (default %v)", f.DefValue)
}
fmt.Printf(s + "\n")
} | go | func flagUsage(f *flag.Flag) {
s := fmt.Sprintf(" -%s", f.Name) // Two spaces before -; see next two comments.
name, usage := flag.UnquoteUsage(f)
if len(name) > 0 {
s += " " + name
}
// Boolean flags of one ASCII letter are so common we
// treat them specially, putting their usage on the same line.
if len(s) <= 4 { // space, space, '-', 'x'.
s += "\t"
} else {
// Four spaces before the tab triggers good alignment
// for both 4- and 8-space tab stops.
s += "\n \t"
}
s += usage
if name == "string" {
// put quotes on the value
s += fmt.Sprintf(" (default %q)", f.DefValue)
} else {
s += fmt.Sprintf(" (default %v)", f.DefValue)
}
fmt.Printf(s + "\n")
} | [
"func",
"flagUsage",
"(",
"f",
"*",
"flag",
".",
"Flag",
")",
"{",
"s",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"f",
".",
"Name",
")",
"// Two spaces before -; see next two comments.",
"\n",
"name",
",",
"usage",
":=",
"flag",
".",
"UnquoteUsage",
"(",
"f",
")",
"\n",
"if",
"len",
"(",
"name",
")",
">",
"0",
"{",
"s",
"+=",
"\"",
"\"",
"+",
"name",
"\n",
"}",
"\n",
"// Boolean flags of one ASCII letter are so common we",
"// treat them specially, putting their usage on the same line.",
"if",
"len",
"(",
"s",
")",
"<=",
"4",
"{",
"// space, space, '-', 'x'.",
"s",
"+=",
"\"",
"\\t",
"\"",
"\n",
"}",
"else",
"{",
"// Four spaces before the tab triggers good alignment",
"// for both 4- and 8-space tab stops.",
"s",
"+=",
"\"",
"\\n",
"\\t",
"\"",
"\n",
"}",
"\n",
"s",
"+=",
"usage",
"\n",
"if",
"name",
"==",
"\"",
"\"",
"{",
"// put quotes on the value",
"s",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"f",
".",
"DefValue",
")",
"\n",
"}",
"else",
"{",
"s",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"f",
".",
"DefValue",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Printf",
"(",
"s",
"+",
"\"",
"\\n",
"\"",
")",
"\n",
"}"
] | // Cloned from the source to print out the usage for a given flag | [
"Cloned",
"from",
"the",
"source",
"to",
"print",
"out",
"the",
"usage",
"for",
"a",
"given",
"flag"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/cmd/vtexplain/vtexplain.go#L74-L97 | train |
vitessio/vitess | go/cmd/vtexplain/vtexplain.go | getFileParam | func getFileParam(flag, flagFile, name string) (string, error) {
if flag != "" {
if flagFile != "" {
return "", fmt.Errorf("action requires only one of %v or %v-file", name, name)
}
return flag, nil
}
if flagFile == "" {
return "", fmt.Errorf("action requires one of %v or %v-file", name, name)
}
data, err := ioutil.ReadFile(flagFile)
if err != nil {
return "", fmt.Errorf("cannot read file %v: %v", flagFile, err)
}
return string(data), nil
} | go | func getFileParam(flag, flagFile, name string) (string, error) {
if flag != "" {
if flagFile != "" {
return "", fmt.Errorf("action requires only one of %v or %v-file", name, name)
}
return flag, nil
}
if flagFile == "" {
return "", fmt.Errorf("action requires one of %v or %v-file", name, name)
}
data, err := ioutil.ReadFile(flagFile)
if err != nil {
return "", fmt.Errorf("cannot read file %v: %v", flagFile, err)
}
return string(data), nil
} | [
"func",
"getFileParam",
"(",
"flag",
",",
"flagFile",
",",
"name",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"flag",
"!=",
"\"",
"\"",
"{",
"if",
"flagFile",
"!=",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"name",
")",
"\n",
"}",
"\n",
"return",
"flag",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"flagFile",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"name",
")",
"\n",
"}",
"\n",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"flagFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"flagFile",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"string",
"(",
"data",
")",
",",
"nil",
"\n",
"}"
] | // getFileParam returns a string containing either flag is not "",
// or the content of the file named flagFile | [
"getFileParam",
"returns",
"a",
"string",
"containing",
"either",
"flag",
"is",
"not",
"or",
"the",
"content",
"of",
"the",
"file",
"named",
"flagFile"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/cmd/vtexplain/vtexplain.go#L107-L123 | train |
vitessio/vitess | go/vt/mysqlctl/replication.go | WaitForSlaveStart | func WaitForSlaveStart(mysqld MysqlDaemon, slaveStartDeadline int) error {
var rowMap map[string]string
for slaveWait := 0; slaveWait < slaveStartDeadline; slaveWait++ {
status, err := mysqld.SlaveStatus()
if err != nil {
return err
}
if status.SlaveRunning() {
return nil
}
time.Sleep(time.Second)
}
errorKeys := []string{"Last_Error", "Last_IO_Error", "Last_SQL_Error"}
errs := make([]string, 0, len(errorKeys))
for _, key := range errorKeys {
if rowMap[key] != "" {
errs = append(errs, key+": "+rowMap[key])
}
}
if len(errs) != 0 {
return errors.New(strings.Join(errs, ", "))
}
return nil
} | go | func WaitForSlaveStart(mysqld MysqlDaemon, slaveStartDeadline int) error {
var rowMap map[string]string
for slaveWait := 0; slaveWait < slaveStartDeadline; slaveWait++ {
status, err := mysqld.SlaveStatus()
if err != nil {
return err
}
if status.SlaveRunning() {
return nil
}
time.Sleep(time.Second)
}
errorKeys := []string{"Last_Error", "Last_IO_Error", "Last_SQL_Error"}
errs := make([]string, 0, len(errorKeys))
for _, key := range errorKeys {
if rowMap[key] != "" {
errs = append(errs, key+": "+rowMap[key])
}
}
if len(errs) != 0 {
return errors.New(strings.Join(errs, ", "))
}
return nil
} | [
"func",
"WaitForSlaveStart",
"(",
"mysqld",
"MysqlDaemon",
",",
"slaveStartDeadline",
"int",
")",
"error",
"{",
"var",
"rowMap",
"map",
"[",
"string",
"]",
"string",
"\n",
"for",
"slaveWait",
":=",
"0",
";",
"slaveWait",
"<",
"slaveStartDeadline",
";",
"slaveWait",
"++",
"{",
"status",
",",
"err",
":=",
"mysqld",
".",
"SlaveStatus",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"status",
".",
"SlaveRunning",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"time",
".",
"Second",
")",
"\n",
"}",
"\n\n",
"errorKeys",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
"errs",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"errorKeys",
")",
")",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"errorKeys",
"{",
"if",
"rowMap",
"[",
"key",
"]",
"!=",
"\"",
"\"",
"{",
"errs",
"=",
"append",
"(",
"errs",
",",
"key",
"+",
"\"",
"\"",
"+",
"rowMap",
"[",
"key",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"errs",
")",
"!=",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"strings",
".",
"Join",
"(",
"errs",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // WaitForSlaveStart waits until the deadline for replication to start.
// This validates the current master is correct and can be connected to. | [
"WaitForSlaveStart",
"waits",
"until",
"the",
"deadline",
"for",
"replication",
"to",
"start",
".",
"This",
"validates",
"the",
"current",
"master",
"is",
"correct",
"and",
"can",
"be",
"connected",
"to",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/replication.go#L42-L67 | train |
vitessio/vitess | go/vt/mysqlctl/replication.go | StartSlave | func (mysqld *Mysqld) StartSlave(hookExtraEnv map[string]string) error {
ctx := context.TODO()
conn, err := getPoolReconnect(ctx, mysqld.dbaPool)
if err != nil {
return err
}
defer conn.Recycle()
if err := mysqld.executeSuperQueryListConn(ctx, conn, []string{conn.StartSlaveCommand()}); err != nil {
return err
}
h := hook.NewSimpleHook("postflight_start_slave")
h.ExtraEnv = hookExtraEnv
return h.ExecuteOptional()
} | go | func (mysqld *Mysqld) StartSlave(hookExtraEnv map[string]string) error {
ctx := context.TODO()
conn, err := getPoolReconnect(ctx, mysqld.dbaPool)
if err != nil {
return err
}
defer conn.Recycle()
if err := mysqld.executeSuperQueryListConn(ctx, conn, []string{conn.StartSlaveCommand()}); err != nil {
return err
}
h := hook.NewSimpleHook("postflight_start_slave")
h.ExtraEnv = hookExtraEnv
return h.ExecuteOptional()
} | [
"func",
"(",
"mysqld",
"*",
"Mysqld",
")",
"StartSlave",
"(",
"hookExtraEnv",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"ctx",
":=",
"context",
".",
"TODO",
"(",
")",
"\n",
"conn",
",",
"err",
":=",
"getPoolReconnect",
"(",
"ctx",
",",
"mysqld",
".",
"dbaPool",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"conn",
".",
"Recycle",
"(",
")",
"\n\n",
"if",
"err",
":=",
"mysqld",
".",
"executeSuperQueryListConn",
"(",
"ctx",
",",
"conn",
",",
"[",
"]",
"string",
"{",
"conn",
".",
"StartSlaveCommand",
"(",
")",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"h",
":=",
"hook",
".",
"NewSimpleHook",
"(",
"\"",
"\"",
")",
"\n",
"h",
".",
"ExtraEnv",
"=",
"hookExtraEnv",
"\n",
"return",
"h",
".",
"ExecuteOptional",
"(",
")",
"\n",
"}"
] | // StartSlave starts a slave. | [
"StartSlave",
"starts",
"a",
"slave",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/replication.go#L70-L85 | train |
vitessio/vitess | go/vt/mysqlctl/replication.go | StartSlaveUntilAfter | func (mysqld *Mysqld) StartSlaveUntilAfter(ctx context.Context, targetPos mysql.Position) error {
conn, err := getPoolReconnect(ctx, mysqld.dbaPool)
if err != nil {
return err
}
defer conn.Recycle()
queries := []string{conn.StartSlaveUntilAfterCommand(targetPos)}
return mysqld.executeSuperQueryListConn(ctx, conn, queries)
} | go | func (mysqld *Mysqld) StartSlaveUntilAfter(ctx context.Context, targetPos mysql.Position) error {
conn, err := getPoolReconnect(ctx, mysqld.dbaPool)
if err != nil {
return err
}
defer conn.Recycle()
queries := []string{conn.StartSlaveUntilAfterCommand(targetPos)}
return mysqld.executeSuperQueryListConn(ctx, conn, queries)
} | [
"func",
"(",
"mysqld",
"*",
"Mysqld",
")",
"StartSlaveUntilAfter",
"(",
"ctx",
"context",
".",
"Context",
",",
"targetPos",
"mysql",
".",
"Position",
")",
"error",
"{",
"conn",
",",
"err",
":=",
"getPoolReconnect",
"(",
"ctx",
",",
"mysqld",
".",
"dbaPool",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"conn",
".",
"Recycle",
"(",
")",
"\n\n",
"queries",
":=",
"[",
"]",
"string",
"{",
"conn",
".",
"StartSlaveUntilAfterCommand",
"(",
"targetPos",
")",
"}",
"\n\n",
"return",
"mysqld",
".",
"executeSuperQueryListConn",
"(",
"ctx",
",",
"conn",
",",
"queries",
")",
"\n",
"}"
] | // StartSlaveUntilAfter starts a slave until replication has come to `targetPos`, then it stops replication | [
"StartSlaveUntilAfter",
"starts",
"a",
"slave",
"until",
"replication",
"has",
"come",
"to",
"targetPos",
"then",
"it",
"stops",
"replication"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/replication.go#L88-L98 | train |
vitessio/vitess | go/vt/mysqlctl/replication.go | GetMysqlPort | func (mysqld *Mysqld) GetMysqlPort() (int32, error) {
qr, err := mysqld.FetchSuperQuery(context.TODO(), "SHOW VARIABLES LIKE 'port'")
if err != nil {
return 0, err
}
if len(qr.Rows) != 1 {
return 0, errors.New("no port variable in mysql")
}
utemp, err := sqltypes.ToUint64(qr.Rows[0][1])
if err != nil {
return 0, err
}
return int32(utemp), nil
} | go | func (mysqld *Mysqld) GetMysqlPort() (int32, error) {
qr, err := mysqld.FetchSuperQuery(context.TODO(), "SHOW VARIABLES LIKE 'port'")
if err != nil {
return 0, err
}
if len(qr.Rows) != 1 {
return 0, errors.New("no port variable in mysql")
}
utemp, err := sqltypes.ToUint64(qr.Rows[0][1])
if err != nil {
return 0, err
}
return int32(utemp), nil
} | [
"func",
"(",
"mysqld",
"*",
"Mysqld",
")",
"GetMysqlPort",
"(",
")",
"(",
"int32",
",",
"error",
")",
"{",
"qr",
",",
"err",
":=",
"mysqld",
".",
"FetchSuperQuery",
"(",
"context",
".",
"TODO",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"qr",
".",
"Rows",
")",
"!=",
"1",
"{",
"return",
"0",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"utemp",
",",
"err",
":=",
"sqltypes",
".",
"ToUint64",
"(",
"qr",
".",
"Rows",
"[",
"0",
"]",
"[",
"1",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"int32",
"(",
"utemp",
")",
",",
"nil",
"\n",
"}"
] | // GetMysqlPort returns mysql port | [
"GetMysqlPort",
"returns",
"mysql",
"port"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/replication.go#L118-L131 | train |
vitessio/vitess | go/vt/mysqlctl/replication.go | IsReadOnly | func (mysqld *Mysqld) IsReadOnly() (bool, error) {
qr, err := mysqld.FetchSuperQuery(context.TODO(), "SHOW VARIABLES LIKE 'read_only'")
if err != nil {
return true, err
}
if len(qr.Rows) != 1 {
return true, errors.New("no read_only variable in mysql")
}
if qr.Rows[0][1].ToString() == "ON" {
return true, nil
}
return false, nil
} | go | func (mysqld *Mysqld) IsReadOnly() (bool, error) {
qr, err := mysqld.FetchSuperQuery(context.TODO(), "SHOW VARIABLES LIKE 'read_only'")
if err != nil {
return true, err
}
if len(qr.Rows) != 1 {
return true, errors.New("no read_only variable in mysql")
}
if qr.Rows[0][1].ToString() == "ON" {
return true, nil
}
return false, nil
} | [
"func",
"(",
"mysqld",
"*",
"Mysqld",
")",
"IsReadOnly",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"qr",
",",
"err",
":=",
"mysqld",
".",
"FetchSuperQuery",
"(",
"context",
".",
"TODO",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"true",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"qr",
".",
"Rows",
")",
"!=",
"1",
"{",
"return",
"true",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"qr",
".",
"Rows",
"[",
"0",
"]",
"[",
"1",
"]",
".",
"ToString",
"(",
")",
"==",
"\"",
"\"",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}"
] | // IsReadOnly return true if the instance is read only | [
"IsReadOnly",
"return",
"true",
"if",
"the",
"instance",
"is",
"read",
"only"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/replication.go#L134-L146 | train |
vitessio/vitess | go/vt/mysqlctl/replication.go | WaitMasterPos | func (mysqld *Mysqld) WaitMasterPos(ctx context.Context, targetPos mysql.Position) error {
// Get a connection.
conn, err := getPoolReconnect(ctx, mysqld.dbaPool)
if err != nil {
return err
}
defer conn.Recycle()
// Find the query to run, run it.
query, err := conn.WaitUntilPositionCommand(ctx, targetPos)
if err != nil {
return err
}
qr, err := mysqld.FetchSuperQuery(ctx, query)
if err != nil {
return fmt.Errorf("WaitUntilPositionCommand(%v) failed: %v", query, err)
}
if len(qr.Rows) != 1 || len(qr.Rows[0]) != 1 {
return fmt.Errorf("unexpected result format from WaitUntilPositionCommand(%v): %#v", query, qr)
}
result := qr.Rows[0][0]
if result.IsNull() {
return fmt.Errorf("WaitUntilPositionCommand(%v) failed: replication is probably stopped", query)
}
if result.ToString() == "-1" {
return fmt.Errorf("timed out waiting for position %v", targetPos)
}
return nil
} | go | func (mysqld *Mysqld) WaitMasterPos(ctx context.Context, targetPos mysql.Position) error {
// Get a connection.
conn, err := getPoolReconnect(ctx, mysqld.dbaPool)
if err != nil {
return err
}
defer conn.Recycle()
// Find the query to run, run it.
query, err := conn.WaitUntilPositionCommand(ctx, targetPos)
if err != nil {
return err
}
qr, err := mysqld.FetchSuperQuery(ctx, query)
if err != nil {
return fmt.Errorf("WaitUntilPositionCommand(%v) failed: %v", query, err)
}
if len(qr.Rows) != 1 || len(qr.Rows[0]) != 1 {
return fmt.Errorf("unexpected result format from WaitUntilPositionCommand(%v): %#v", query, qr)
}
result := qr.Rows[0][0]
if result.IsNull() {
return fmt.Errorf("WaitUntilPositionCommand(%v) failed: replication is probably stopped", query)
}
if result.ToString() == "-1" {
return fmt.Errorf("timed out waiting for position %v", targetPos)
}
return nil
} | [
"func",
"(",
"mysqld",
"*",
"Mysqld",
")",
"WaitMasterPos",
"(",
"ctx",
"context",
".",
"Context",
",",
"targetPos",
"mysql",
".",
"Position",
")",
"error",
"{",
"// Get a connection.",
"conn",
",",
"err",
":=",
"getPoolReconnect",
"(",
"ctx",
",",
"mysqld",
".",
"dbaPool",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"conn",
".",
"Recycle",
"(",
")",
"\n\n",
"// Find the query to run, run it.",
"query",
",",
"err",
":=",
"conn",
".",
"WaitUntilPositionCommand",
"(",
"ctx",
",",
"targetPos",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"qr",
",",
"err",
":=",
"mysqld",
".",
"FetchSuperQuery",
"(",
"ctx",
",",
"query",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"query",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"qr",
".",
"Rows",
")",
"!=",
"1",
"||",
"len",
"(",
"qr",
".",
"Rows",
"[",
"0",
"]",
")",
"!=",
"1",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"query",
",",
"qr",
")",
"\n",
"}",
"\n",
"result",
":=",
"qr",
".",
"Rows",
"[",
"0",
"]",
"[",
"0",
"]",
"\n",
"if",
"result",
".",
"IsNull",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"query",
")",
"\n",
"}",
"\n",
"if",
"result",
".",
"ToString",
"(",
")",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"targetPos",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // WaitMasterPos lets slaves wait to given replication position | [
"WaitMasterPos",
"lets",
"slaves",
"wait",
"to",
"given",
"replication",
"position"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/replication.go#L176-L204 | train |
vitessio/vitess | go/vt/mysqlctl/replication.go | SlaveStatus | func (mysqld *Mysqld) SlaveStatus() (mysql.SlaveStatus, error) {
conn, err := getPoolReconnect(context.TODO(), mysqld.dbaPool)
if err != nil {
return mysql.SlaveStatus{}, err
}
defer conn.Recycle()
return conn.ShowSlaveStatus()
} | go | func (mysqld *Mysqld) SlaveStatus() (mysql.SlaveStatus, error) {
conn, err := getPoolReconnect(context.TODO(), mysqld.dbaPool)
if err != nil {
return mysql.SlaveStatus{}, err
}
defer conn.Recycle()
return conn.ShowSlaveStatus()
} | [
"func",
"(",
"mysqld",
"*",
"Mysqld",
")",
"SlaveStatus",
"(",
")",
"(",
"mysql",
".",
"SlaveStatus",
",",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"getPoolReconnect",
"(",
"context",
".",
"TODO",
"(",
")",
",",
"mysqld",
".",
"dbaPool",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"mysql",
".",
"SlaveStatus",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"defer",
"conn",
".",
"Recycle",
"(",
")",
"\n\n",
"return",
"conn",
".",
"ShowSlaveStatus",
"(",
")",
"\n",
"}"
] | // SlaveStatus returns the slave replication statuses | [
"SlaveStatus",
"returns",
"the",
"slave",
"replication",
"statuses"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/replication.go#L207-L215 | train |
vitessio/vitess | go/vt/mysqlctl/replication.go | MasterPosition | func (mysqld *Mysqld) MasterPosition() (mysql.Position, error) {
conn, err := getPoolReconnect(context.TODO(), mysqld.dbaPool)
if err != nil {
return mysql.Position{}, err
}
defer conn.Recycle()
return conn.MasterPosition()
} | go | func (mysqld *Mysqld) MasterPosition() (mysql.Position, error) {
conn, err := getPoolReconnect(context.TODO(), mysqld.dbaPool)
if err != nil {
return mysql.Position{}, err
}
defer conn.Recycle()
return conn.MasterPosition()
} | [
"func",
"(",
"mysqld",
"*",
"Mysqld",
")",
"MasterPosition",
"(",
")",
"(",
"mysql",
".",
"Position",
",",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"getPoolReconnect",
"(",
"context",
".",
"TODO",
"(",
")",
",",
"mysqld",
".",
"dbaPool",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"mysql",
".",
"Position",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"defer",
"conn",
".",
"Recycle",
"(",
")",
"\n\n",
"return",
"conn",
".",
"MasterPosition",
"(",
")",
"\n",
"}"
] | // MasterPosition returns the master replication position. | [
"MasterPosition",
"returns",
"the",
"master",
"replication",
"position",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/replication.go#L218-L226 | train |
vitessio/vitess | go/vt/mysqlctl/replication.go | SetSlavePosition | func (mysqld *Mysqld) SetSlavePosition(ctx context.Context, pos mysql.Position) error {
conn, err := getPoolReconnect(ctx, mysqld.dbaPool)
if err != nil {
return err
}
defer conn.Recycle()
cmds := conn.SetSlavePositionCommands(pos)
log.Infof("Executing commands to set slave position: %v", cmds)
return mysqld.executeSuperQueryListConn(ctx, conn, cmds)
} | go | func (mysqld *Mysqld) SetSlavePosition(ctx context.Context, pos mysql.Position) error {
conn, err := getPoolReconnect(ctx, mysqld.dbaPool)
if err != nil {
return err
}
defer conn.Recycle()
cmds := conn.SetSlavePositionCommands(pos)
log.Infof("Executing commands to set slave position: %v", cmds)
return mysqld.executeSuperQueryListConn(ctx, conn, cmds)
} | [
"func",
"(",
"mysqld",
"*",
"Mysqld",
")",
"SetSlavePosition",
"(",
"ctx",
"context",
".",
"Context",
",",
"pos",
"mysql",
".",
"Position",
")",
"error",
"{",
"conn",
",",
"err",
":=",
"getPoolReconnect",
"(",
"ctx",
",",
"mysqld",
".",
"dbaPool",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"conn",
".",
"Recycle",
"(",
")",
"\n\n",
"cmds",
":=",
"conn",
".",
"SetSlavePositionCommands",
"(",
"pos",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"cmds",
")",
"\n",
"return",
"mysqld",
".",
"executeSuperQueryListConn",
"(",
"ctx",
",",
"conn",
",",
"cmds",
")",
"\n",
"}"
] | // SetSlavePosition sets the replication position at which the slave will resume
// when its replication is started. | [
"SetSlavePosition",
"sets",
"the",
"replication",
"position",
"at",
"which",
"the",
"slave",
"will",
"resume",
"when",
"its",
"replication",
"is",
"started",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/replication.go#L230-L240 | train |
vitessio/vitess | go/vt/mysqlctl/replication.go | ResetReplication | func (mysqld *Mysqld) ResetReplication(ctx context.Context) error {
conn, connErr := getPoolReconnect(ctx, mysqld.dbaPool)
if connErr != nil {
return connErr
}
defer conn.Recycle()
cmds := conn.ResetReplicationCommands()
return mysqld.executeSuperQueryListConn(ctx, conn, cmds)
} | go | func (mysqld *Mysqld) ResetReplication(ctx context.Context) error {
conn, connErr := getPoolReconnect(ctx, mysqld.dbaPool)
if connErr != nil {
return connErr
}
defer conn.Recycle()
cmds := conn.ResetReplicationCommands()
return mysqld.executeSuperQueryListConn(ctx, conn, cmds)
} | [
"func",
"(",
"mysqld",
"*",
"Mysqld",
")",
"ResetReplication",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"conn",
",",
"connErr",
":=",
"getPoolReconnect",
"(",
"ctx",
",",
"mysqld",
".",
"dbaPool",
")",
"\n",
"if",
"connErr",
"!=",
"nil",
"{",
"return",
"connErr",
"\n",
"}",
"\n",
"defer",
"conn",
".",
"Recycle",
"(",
")",
"\n\n",
"cmds",
":=",
"conn",
".",
"ResetReplicationCommands",
"(",
")",
"\n",
"return",
"mysqld",
".",
"executeSuperQueryListConn",
"(",
"ctx",
",",
"conn",
",",
"cmds",
")",
"\n",
"}"
] | // ResetReplication resets all replication for this host. | [
"ResetReplication",
"resets",
"all",
"replication",
"for",
"this",
"host",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/replication.go#L268-L277 | train |
vitessio/vitess | go/vt/mysqlctl/replication.go | FindSlaves | func FindSlaves(mysqld MysqlDaemon) ([]string, error) {
qr, err := mysqld.FetchSuperQuery(context.TODO(), "SHOW PROCESSLIST")
if err != nil {
return nil, err
}
addrs := make([]string, 0, 32)
for _, row := range qr.Rows {
// Check for prefix, since it could be "Binlog Dump GTID".
if strings.HasPrefix(row[colCommand].ToString(), binlogDumpCommand) {
host := row[colClientAddr].ToString()
if host == "localhost" {
// If we have a local binlog streamer, it will
// show up as being connected
// from 'localhost' through the local
// socket. Ignore it.
continue
}
host, _, err = netutil.SplitHostPort(host)
if err != nil {
return nil, fmt.Errorf("FindSlaves: malformed addr %v", err)
}
var ips []string
ips, err = net.LookupHost(host)
if err != nil {
return nil, fmt.Errorf("FindSlaves: LookupHost failed %v", err)
}
addrs = append(addrs, ips...)
}
}
return addrs, nil
} | go | func FindSlaves(mysqld MysqlDaemon) ([]string, error) {
qr, err := mysqld.FetchSuperQuery(context.TODO(), "SHOW PROCESSLIST")
if err != nil {
return nil, err
}
addrs := make([]string, 0, 32)
for _, row := range qr.Rows {
// Check for prefix, since it could be "Binlog Dump GTID".
if strings.HasPrefix(row[colCommand].ToString(), binlogDumpCommand) {
host := row[colClientAddr].ToString()
if host == "localhost" {
// If we have a local binlog streamer, it will
// show up as being connected
// from 'localhost' through the local
// socket. Ignore it.
continue
}
host, _, err = netutil.SplitHostPort(host)
if err != nil {
return nil, fmt.Errorf("FindSlaves: malformed addr %v", err)
}
var ips []string
ips, err = net.LookupHost(host)
if err != nil {
return nil, fmt.Errorf("FindSlaves: LookupHost failed %v", err)
}
addrs = append(addrs, ips...)
}
}
return addrs, nil
} | [
"func",
"FindSlaves",
"(",
"mysqld",
"MysqlDaemon",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"qr",
",",
"err",
":=",
"mysqld",
".",
"FetchSuperQuery",
"(",
"context",
".",
"TODO",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"addrs",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"32",
")",
"\n",
"for",
"_",
",",
"row",
":=",
"range",
"qr",
".",
"Rows",
"{",
"// Check for prefix, since it could be \"Binlog Dump GTID\".",
"if",
"strings",
".",
"HasPrefix",
"(",
"row",
"[",
"colCommand",
"]",
".",
"ToString",
"(",
")",
",",
"binlogDumpCommand",
")",
"{",
"host",
":=",
"row",
"[",
"colClientAddr",
"]",
".",
"ToString",
"(",
")",
"\n",
"if",
"host",
"==",
"\"",
"\"",
"{",
"// If we have a local binlog streamer, it will",
"// show up as being connected",
"// from 'localhost' through the local",
"// socket. Ignore it.",
"continue",
"\n",
"}",
"\n",
"host",
",",
"_",
",",
"err",
"=",
"netutil",
".",
"SplitHostPort",
"(",
"host",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"var",
"ips",
"[",
"]",
"string",
"\n",
"ips",
",",
"err",
"=",
"net",
".",
"LookupHost",
"(",
"host",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"addrs",
"=",
"append",
"(",
"addrs",
",",
"ips",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"addrs",
",",
"nil",
"\n",
"}"
] | // FindSlaves gets IP addresses for all currently connected slaves. | [
"FindSlaves",
"gets",
"IP",
"addresses",
"for",
"all",
"currently",
"connected",
"slaves",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/replication.go#L304-L335 | train |
vitessio/vitess | go/vt/mysqlctl/replication.go | EnableBinlogPlayback | func (mysqld *Mysqld) EnableBinlogPlayback() error {
// Get a connection.
conn, err := getPoolReconnect(context.TODO(), mysqld.dbaPool)
if err != nil {
return err
}
defer conn.Recycle()
// See if we have a command to run, and run it.
cmd := conn.EnableBinlogPlaybackCommand()
if cmd == "" {
return nil
}
if err := mysqld.ExecuteSuperQuery(context.TODO(), cmd); err != nil {
log.Errorf("EnableBinlogPlayback: cannot run query '%v': %v", cmd, err)
return fmt.Errorf("EnableBinlogPlayback: cannot run query '%v': %v", cmd, err)
}
log.Info("EnableBinlogPlayback: successfully ran %v", cmd)
return nil
} | go | func (mysqld *Mysqld) EnableBinlogPlayback() error {
// Get a connection.
conn, err := getPoolReconnect(context.TODO(), mysqld.dbaPool)
if err != nil {
return err
}
defer conn.Recycle()
// See if we have a command to run, and run it.
cmd := conn.EnableBinlogPlaybackCommand()
if cmd == "" {
return nil
}
if err := mysqld.ExecuteSuperQuery(context.TODO(), cmd); err != nil {
log.Errorf("EnableBinlogPlayback: cannot run query '%v': %v", cmd, err)
return fmt.Errorf("EnableBinlogPlayback: cannot run query '%v': %v", cmd, err)
}
log.Info("EnableBinlogPlayback: successfully ran %v", cmd)
return nil
} | [
"func",
"(",
"mysqld",
"*",
"Mysqld",
")",
"EnableBinlogPlayback",
"(",
")",
"error",
"{",
"// Get a connection.",
"conn",
",",
"err",
":=",
"getPoolReconnect",
"(",
"context",
".",
"TODO",
"(",
")",
",",
"mysqld",
".",
"dbaPool",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"conn",
".",
"Recycle",
"(",
")",
"\n\n",
"// See if we have a command to run, and run it.",
"cmd",
":=",
"conn",
".",
"EnableBinlogPlaybackCommand",
"(",
")",
"\n",
"if",
"cmd",
"==",
"\"",
"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"err",
":=",
"mysqld",
".",
"ExecuteSuperQuery",
"(",
"context",
".",
"TODO",
"(",
")",
",",
"cmd",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cmd",
",",
"err",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cmd",
",",
"err",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Info",
"(",
"\"",
"\"",
",",
"cmd",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // EnableBinlogPlayback prepares the server to play back events from a binlog stream.
// Whatever it does for a given flavor, it must be idempotent. | [
"EnableBinlogPlayback",
"prepares",
"the",
"server",
"to",
"play",
"back",
"events",
"from",
"a",
"binlog",
"stream",
".",
"Whatever",
"it",
"does",
"for",
"a",
"given",
"flavor",
"it",
"must",
"be",
"idempotent",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/replication.go#L339-L359 | train |
vitessio/vitess | go/vt/mysqlctl/replication.go | SemiSyncEnabled | func (mysqld *Mysqld) SemiSyncEnabled() (master, slave bool) {
vars, err := mysqld.fetchVariables(context.TODO(), "rpl_semi_sync_%_enabled")
if err != nil {
return false, false
}
master = (vars["rpl_semi_sync_master_enabled"] == "ON")
slave = (vars["rpl_semi_sync_slave_enabled"] == "ON")
return master, slave
} | go | func (mysqld *Mysqld) SemiSyncEnabled() (master, slave bool) {
vars, err := mysqld.fetchVariables(context.TODO(), "rpl_semi_sync_%_enabled")
if err != nil {
return false, false
}
master = (vars["rpl_semi_sync_master_enabled"] == "ON")
slave = (vars["rpl_semi_sync_slave_enabled"] == "ON")
return master, slave
} | [
"func",
"(",
"mysqld",
"*",
"Mysqld",
")",
"SemiSyncEnabled",
"(",
")",
"(",
"master",
",",
"slave",
"bool",
")",
"{",
"vars",
",",
"err",
":=",
"mysqld",
".",
"fetchVariables",
"(",
"context",
".",
"TODO",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"false",
"\n",
"}",
"\n",
"master",
"=",
"(",
"vars",
"[",
"\"",
"\"",
"]",
"==",
"\"",
"\"",
")",
"\n",
"slave",
"=",
"(",
"vars",
"[",
"\"",
"\"",
"]",
"==",
"\"",
"\"",
")",
"\n",
"return",
"master",
",",
"slave",
"\n",
"}"
] | // SemiSyncEnabled returns whether semi-sync is enabled for master or slave.
// If the semi-sync plugin is not loaded, we assume semi-sync is disabled. | [
"SemiSyncEnabled",
"returns",
"whether",
"semi",
"-",
"sync",
"is",
"enabled",
"for",
"master",
"or",
"slave",
".",
"If",
"the",
"semi",
"-",
"sync",
"plugin",
"is",
"not",
"loaded",
"we",
"assume",
"semi",
"-",
"sync",
"is",
"disabled",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/replication.go#L410-L418 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | RegisterFakeVTGateConnDialer | func RegisterFakeVTGateConnDialer() (*FakeVTGateConn, string) {
protocol := "fake"
impl := &FakeVTGateConn{
execMap: make(map[string]*queryResponse),
splitQueryMap: make(map[string]*splitQueryResponse),
}
vtgateconn.RegisterDialer(protocol, func(ctx context.Context, address string) (vtgateconn.Impl, error) {
return impl, nil
})
return impl, protocol
} | go | func RegisterFakeVTGateConnDialer() (*FakeVTGateConn, string) {
protocol := "fake"
impl := &FakeVTGateConn{
execMap: make(map[string]*queryResponse),
splitQueryMap: make(map[string]*splitQueryResponse),
}
vtgateconn.RegisterDialer(protocol, func(ctx context.Context, address string) (vtgateconn.Impl, error) {
return impl, nil
})
return impl, protocol
} | [
"func",
"RegisterFakeVTGateConnDialer",
"(",
")",
"(",
"*",
"FakeVTGateConn",
",",
"string",
")",
"{",
"protocol",
":=",
"\"",
"\"",
"\n",
"impl",
":=",
"&",
"FakeVTGateConn",
"{",
"execMap",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"queryResponse",
")",
",",
"splitQueryMap",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"splitQueryResponse",
")",
",",
"}",
"\n",
"vtgateconn",
".",
"RegisterDialer",
"(",
"protocol",
",",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"address",
"string",
")",
"(",
"vtgateconn",
".",
"Impl",
",",
"error",
")",
"{",
"return",
"impl",
",",
"nil",
"\n",
"}",
")",
"\n",
"return",
"impl",
",",
"protocol",
"\n",
"}"
] | // RegisterFakeVTGateConnDialer registers the proper dialer for this fake,
// and returns the underlying instance that will be returned by the dialer,
// and the protocol to use to get this fake. | [
"RegisterFakeVTGateConnDialer",
"registers",
"the",
"proper",
"dialer",
"for",
"this",
"fake",
"and",
"returns",
"the",
"underlying",
"instance",
"that",
"will",
"be",
"returned",
"by",
"the",
"dialer",
"and",
"the",
"protocol",
"to",
"use",
"to",
"get",
"this",
"fake",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L91-L101 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | AddQuery | func (conn *FakeVTGateConn) AddQuery(
sql string,
bindVariables map[string]*querypb.BindVariable,
session *vtgatepb.Session,
expectedResult *sqltypes.Result) {
conn.execMap[sql] = &queryResponse{
execQuery: &queryExecute{
SQL: sql,
BindVariables: bindVariables,
Session: session,
},
reply: expectedResult,
}
} | go | func (conn *FakeVTGateConn) AddQuery(
sql string,
bindVariables map[string]*querypb.BindVariable,
session *vtgatepb.Session,
expectedResult *sqltypes.Result) {
conn.execMap[sql] = &queryResponse{
execQuery: &queryExecute{
SQL: sql,
BindVariables: bindVariables,
Session: session,
},
reply: expectedResult,
}
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"AddQuery",
"(",
"sql",
"string",
",",
"bindVariables",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
",",
"session",
"*",
"vtgatepb",
".",
"Session",
",",
"expectedResult",
"*",
"sqltypes",
".",
"Result",
")",
"{",
"conn",
".",
"execMap",
"[",
"sql",
"]",
"=",
"&",
"queryResponse",
"{",
"execQuery",
":",
"&",
"queryExecute",
"{",
"SQL",
":",
"sql",
",",
"BindVariables",
":",
"bindVariables",
",",
"Session",
":",
"session",
",",
"}",
",",
"reply",
":",
"expectedResult",
",",
"}",
"\n",
"}"
] | // AddQuery adds a query and expected result. | [
"AddQuery",
"adds",
"a",
"query",
"and",
"expected",
"result",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L104-L117 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | AddShardQuery | func (conn *FakeVTGateConn) AddShardQuery(
sql string,
bindVariables map[string]*querypb.BindVariable,
keyspace string,
shards []string,
tabletType topodatapb.TabletType,
session *vtgatepb.Session,
notInTransaction bool,
expectedResult *sqltypes.Result) {
conn.execMap[getShardQueryKey(sql, shards)] = &queryResponse{
shardQuery: &queryExecuteShards{
SQL: sql,
BindVariables: bindVariables,
Keyspace: keyspace,
Shards: shards,
TabletType: tabletType,
Session: session,
NotInTransaction: notInTransaction,
},
reply: expectedResult,
}
} | go | func (conn *FakeVTGateConn) AddShardQuery(
sql string,
bindVariables map[string]*querypb.BindVariable,
keyspace string,
shards []string,
tabletType topodatapb.TabletType,
session *vtgatepb.Session,
notInTransaction bool,
expectedResult *sqltypes.Result) {
conn.execMap[getShardQueryKey(sql, shards)] = &queryResponse{
shardQuery: &queryExecuteShards{
SQL: sql,
BindVariables: bindVariables,
Keyspace: keyspace,
Shards: shards,
TabletType: tabletType,
Session: session,
NotInTransaction: notInTransaction,
},
reply: expectedResult,
}
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"AddShardQuery",
"(",
"sql",
"string",
",",
"bindVariables",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
",",
"keyspace",
"string",
",",
"shards",
"[",
"]",
"string",
",",
"tabletType",
"topodatapb",
".",
"TabletType",
",",
"session",
"*",
"vtgatepb",
".",
"Session",
",",
"notInTransaction",
"bool",
",",
"expectedResult",
"*",
"sqltypes",
".",
"Result",
")",
"{",
"conn",
".",
"execMap",
"[",
"getShardQueryKey",
"(",
"sql",
",",
"shards",
")",
"]",
"=",
"&",
"queryResponse",
"{",
"shardQuery",
":",
"&",
"queryExecuteShards",
"{",
"SQL",
":",
"sql",
",",
"BindVariables",
":",
"bindVariables",
",",
"Keyspace",
":",
"keyspace",
",",
"Shards",
":",
"shards",
",",
"TabletType",
":",
"tabletType",
",",
"Session",
":",
"session",
",",
"NotInTransaction",
":",
"notInTransaction",
",",
"}",
",",
"reply",
":",
"expectedResult",
",",
"}",
"\n",
"}"
] | // AddShardQuery adds a shard query and expected result. | [
"AddShardQuery",
"adds",
"a",
"shard",
"query",
"and",
"expected",
"result",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L120-L141 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | AddSplitQuery | func (conn *FakeVTGateConn) AddSplitQuery(
keyspace string,
sql string,
bindVariables map[string]*querypb.BindVariable,
splitColumns []string,
splitCount int64,
numRowsPerQueryPart int64,
algorithm querypb.SplitQueryRequest_Algorithm,
expectedResult []*vtgatepb.SplitQueryResponse_Part) {
reply := make([]*vtgatepb.SplitQueryResponse_Part, len(expectedResult))
copy(reply, expectedResult)
key := getSplitQueryKey(keyspace, sql, splitColumns, splitCount, numRowsPerQueryPart, algorithm)
conn.splitQueryMap[key] = &splitQueryResponse{
splitQuery: &querySplitQuery{
Keyspace: keyspace,
SQL: sql,
BindVariables: bindVariables,
SplitColumns: splitColumns,
SplitCount: splitCount,
NumRowsPerQueryPart: numRowsPerQueryPart,
Algorithm: algorithm,
},
reply: reply,
err: nil,
}
} | go | func (conn *FakeVTGateConn) AddSplitQuery(
keyspace string,
sql string,
bindVariables map[string]*querypb.BindVariable,
splitColumns []string,
splitCount int64,
numRowsPerQueryPart int64,
algorithm querypb.SplitQueryRequest_Algorithm,
expectedResult []*vtgatepb.SplitQueryResponse_Part) {
reply := make([]*vtgatepb.SplitQueryResponse_Part, len(expectedResult))
copy(reply, expectedResult)
key := getSplitQueryKey(keyspace, sql, splitColumns, splitCount, numRowsPerQueryPart, algorithm)
conn.splitQueryMap[key] = &splitQueryResponse{
splitQuery: &querySplitQuery{
Keyspace: keyspace,
SQL: sql,
BindVariables: bindVariables,
SplitColumns: splitColumns,
SplitCount: splitCount,
NumRowsPerQueryPart: numRowsPerQueryPart,
Algorithm: algorithm,
},
reply: reply,
err: nil,
}
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"AddSplitQuery",
"(",
"keyspace",
"string",
",",
"sql",
"string",
",",
"bindVariables",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
",",
"splitColumns",
"[",
"]",
"string",
",",
"splitCount",
"int64",
",",
"numRowsPerQueryPart",
"int64",
",",
"algorithm",
"querypb",
".",
"SplitQueryRequest_Algorithm",
",",
"expectedResult",
"[",
"]",
"*",
"vtgatepb",
".",
"SplitQueryResponse_Part",
")",
"{",
"reply",
":=",
"make",
"(",
"[",
"]",
"*",
"vtgatepb",
".",
"SplitQueryResponse_Part",
",",
"len",
"(",
"expectedResult",
")",
")",
"\n",
"copy",
"(",
"reply",
",",
"expectedResult",
")",
"\n",
"key",
":=",
"getSplitQueryKey",
"(",
"keyspace",
",",
"sql",
",",
"splitColumns",
",",
"splitCount",
",",
"numRowsPerQueryPart",
",",
"algorithm",
")",
"\n",
"conn",
".",
"splitQueryMap",
"[",
"key",
"]",
"=",
"&",
"splitQueryResponse",
"{",
"splitQuery",
":",
"&",
"querySplitQuery",
"{",
"Keyspace",
":",
"keyspace",
",",
"SQL",
":",
"sql",
",",
"BindVariables",
":",
"bindVariables",
",",
"SplitColumns",
":",
"splitColumns",
",",
"SplitCount",
":",
"splitCount",
",",
"NumRowsPerQueryPart",
":",
"numRowsPerQueryPart",
",",
"Algorithm",
":",
"algorithm",
",",
"}",
",",
"reply",
":",
"reply",
",",
"err",
":",
"nil",
",",
"}",
"\n",
"}"
] | // AddSplitQuery adds a split query and expected result. | [
"AddSplitQuery",
"adds",
"a",
"split",
"query",
"and",
"expected",
"result",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L144-L170 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | Execute | func (conn *FakeVTGateConn) Execute(ctx context.Context, session *vtgatepb.Session, sql string, bindVars map[string]*querypb.BindVariable) (*vtgatepb.Session, *sqltypes.Result, error) {
response, ok := conn.execMap[sql]
if !ok {
return nil, nil, fmt.Errorf("no match for: %s", sql)
}
query := &queryExecute{
SQL: sql,
BindVariables: bindVars,
Session: session,
}
if !reflect.DeepEqual(query, response.execQuery) {
return nil, nil, fmt.Errorf(
"Execute: %+v, want %+v", query, response.execQuery)
}
reply := *response.reply
s := newSession(true, "test_keyspace", []string{}, topodatapb.TabletType_MASTER)
return s, &reply, nil
} | go | func (conn *FakeVTGateConn) Execute(ctx context.Context, session *vtgatepb.Session, sql string, bindVars map[string]*querypb.BindVariable) (*vtgatepb.Session, *sqltypes.Result, error) {
response, ok := conn.execMap[sql]
if !ok {
return nil, nil, fmt.Errorf("no match for: %s", sql)
}
query := &queryExecute{
SQL: sql,
BindVariables: bindVars,
Session: session,
}
if !reflect.DeepEqual(query, response.execQuery) {
return nil, nil, fmt.Errorf(
"Execute: %+v, want %+v", query, response.execQuery)
}
reply := *response.reply
s := newSession(true, "test_keyspace", []string{}, topodatapb.TabletType_MASTER)
return s, &reply, nil
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"Execute",
"(",
"ctx",
"context",
".",
"Context",
",",
"session",
"*",
"vtgatepb",
".",
"Session",
",",
"sql",
"string",
",",
"bindVars",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
")",
"(",
"*",
"vtgatepb",
".",
"Session",
",",
"*",
"sqltypes",
".",
"Result",
",",
"error",
")",
"{",
"response",
",",
"ok",
":=",
"conn",
".",
"execMap",
"[",
"sql",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sql",
")",
"\n",
"}",
"\n",
"query",
":=",
"&",
"queryExecute",
"{",
"SQL",
":",
"sql",
",",
"BindVariables",
":",
"bindVars",
",",
"Session",
":",
"session",
",",
"}",
"\n",
"if",
"!",
"reflect",
".",
"DeepEqual",
"(",
"query",
",",
"response",
".",
"execQuery",
")",
"{",
"return",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"query",
",",
"response",
".",
"execQuery",
")",
"\n",
"}",
"\n",
"reply",
":=",
"*",
"response",
".",
"reply",
"\n",
"s",
":=",
"newSession",
"(",
"true",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"}",
",",
"topodatapb",
".",
"TabletType_MASTER",
")",
"\n",
"return",
"s",
",",
"&",
"reply",
",",
"nil",
"\n",
"}"
] | // Execute please see vtgateconn.Impl.Execute | [
"Execute",
"please",
"see",
"vtgateconn",
".",
"Impl",
".",
"Execute"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L173-L190 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | ExecuteBatch | func (conn *FakeVTGateConn) ExecuteBatch(ctx context.Context, session *vtgatepb.Session, sqlList []string, bindVarsList []map[string]*querypb.BindVariable) (*vtgatepb.Session, []sqltypes.QueryResponse, error) {
panic("not implemented")
} | go | func (conn *FakeVTGateConn) ExecuteBatch(ctx context.Context, session *vtgatepb.Session, sqlList []string, bindVarsList []map[string]*querypb.BindVariable) (*vtgatepb.Session, []sqltypes.QueryResponse, error) {
panic("not implemented")
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"ExecuteBatch",
"(",
"ctx",
"context",
".",
"Context",
",",
"session",
"*",
"vtgatepb",
".",
"Session",
",",
"sqlList",
"[",
"]",
"string",
",",
"bindVarsList",
"[",
"]",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
")",
"(",
"*",
"vtgatepb",
".",
"Session",
",",
"[",
"]",
"sqltypes",
".",
"QueryResponse",
",",
"error",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // ExecuteBatch please see vtgateconn.Impl.ExecuteBatch | [
"ExecuteBatch",
"please",
"see",
"vtgateconn",
".",
"Impl",
".",
"ExecuteBatch"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L193-L195 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | StreamExecute | func (conn *FakeVTGateConn) StreamExecute(ctx context.Context, session *vtgatepb.Session, sql string, bindVars map[string]*querypb.BindVariable) (sqltypes.ResultStream, error) {
response, ok := conn.execMap[sql]
if !ok {
return nil, fmt.Errorf("no match for: %s", sql)
}
query := &queryExecute{
SQL: sql,
BindVariables: bindVars,
Session: session,
}
if !reflect.DeepEqual(query, response.execQuery) {
return nil, fmt.Errorf("StreamExecute: %+v, want %+v", sql, response.execQuery)
}
if response.err != nil {
return nil, response.err
}
var resultChan chan *sqltypes.Result
defer close(resultChan)
if response.reply != nil {
// create a result channel big enough to buffer all of
// the responses so we don't need to fork a go routine.
resultChan = make(chan *sqltypes.Result, len(response.reply.Rows)+1)
result := &sqltypes.Result{}
result.Fields = response.reply.Fields
resultChan <- result
for _, row := range response.reply.Rows {
result := &sqltypes.Result{}
result.Rows = [][]sqltypes.Value{row}
resultChan <- result
}
} else {
resultChan = make(chan *sqltypes.Result)
}
return &streamExecuteAdapter{resultChan}, nil
} | go | func (conn *FakeVTGateConn) StreamExecute(ctx context.Context, session *vtgatepb.Session, sql string, bindVars map[string]*querypb.BindVariable) (sqltypes.ResultStream, error) {
response, ok := conn.execMap[sql]
if !ok {
return nil, fmt.Errorf("no match for: %s", sql)
}
query := &queryExecute{
SQL: sql,
BindVariables: bindVars,
Session: session,
}
if !reflect.DeepEqual(query, response.execQuery) {
return nil, fmt.Errorf("StreamExecute: %+v, want %+v", sql, response.execQuery)
}
if response.err != nil {
return nil, response.err
}
var resultChan chan *sqltypes.Result
defer close(resultChan)
if response.reply != nil {
// create a result channel big enough to buffer all of
// the responses so we don't need to fork a go routine.
resultChan = make(chan *sqltypes.Result, len(response.reply.Rows)+1)
result := &sqltypes.Result{}
result.Fields = response.reply.Fields
resultChan <- result
for _, row := range response.reply.Rows {
result := &sqltypes.Result{}
result.Rows = [][]sqltypes.Value{row}
resultChan <- result
}
} else {
resultChan = make(chan *sqltypes.Result)
}
return &streamExecuteAdapter{resultChan}, nil
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"StreamExecute",
"(",
"ctx",
"context",
".",
"Context",
",",
"session",
"*",
"vtgatepb",
".",
"Session",
",",
"sql",
"string",
",",
"bindVars",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
")",
"(",
"sqltypes",
".",
"ResultStream",
",",
"error",
")",
"{",
"response",
",",
"ok",
":=",
"conn",
".",
"execMap",
"[",
"sql",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sql",
")",
"\n",
"}",
"\n",
"query",
":=",
"&",
"queryExecute",
"{",
"SQL",
":",
"sql",
",",
"BindVariables",
":",
"bindVars",
",",
"Session",
":",
"session",
",",
"}",
"\n",
"if",
"!",
"reflect",
".",
"DeepEqual",
"(",
"query",
",",
"response",
".",
"execQuery",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sql",
",",
"response",
".",
"execQuery",
")",
"\n",
"}",
"\n",
"if",
"response",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"response",
".",
"err",
"\n",
"}",
"\n",
"var",
"resultChan",
"chan",
"*",
"sqltypes",
".",
"Result",
"\n",
"defer",
"close",
"(",
"resultChan",
")",
"\n",
"if",
"response",
".",
"reply",
"!=",
"nil",
"{",
"// create a result channel big enough to buffer all of",
"// the responses so we don't need to fork a go routine.",
"resultChan",
"=",
"make",
"(",
"chan",
"*",
"sqltypes",
".",
"Result",
",",
"len",
"(",
"response",
".",
"reply",
".",
"Rows",
")",
"+",
"1",
")",
"\n",
"result",
":=",
"&",
"sqltypes",
".",
"Result",
"{",
"}",
"\n",
"result",
".",
"Fields",
"=",
"response",
".",
"reply",
".",
"Fields",
"\n",
"resultChan",
"<-",
"result",
"\n",
"for",
"_",
",",
"row",
":=",
"range",
"response",
".",
"reply",
".",
"Rows",
"{",
"result",
":=",
"&",
"sqltypes",
".",
"Result",
"{",
"}",
"\n",
"result",
".",
"Rows",
"=",
"[",
"]",
"[",
"]",
"sqltypes",
".",
"Value",
"{",
"row",
"}",
"\n",
"resultChan",
"<-",
"result",
"\n",
"}",
"\n",
"}",
"else",
"{",
"resultChan",
"=",
"make",
"(",
"chan",
"*",
"sqltypes",
".",
"Result",
")",
"\n",
"}",
"\n",
"return",
"&",
"streamExecuteAdapter",
"{",
"resultChan",
"}",
",",
"nil",
"\n",
"}"
] | // StreamExecute please see vtgateconn.Impl.StreamExecute | [
"StreamExecute",
"please",
"see",
"vtgateconn",
".",
"Impl",
".",
"StreamExecute"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L198-L232 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | ExecuteShards | func (conn *FakeVTGateConn) ExecuteShards(ctx context.Context, sql string, keyspace string, shards []string, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, session *vtgatepb.Session, options *querypb.ExecuteOptions) (*vtgatepb.Session, *sqltypes.Result, error) {
var s *vtgatepb.Session
if session != nil {
s = session
}
response, ok := conn.execMap[getShardQueryKey(sql, shards)]
if !ok {
return nil, nil, fmt.Errorf("no match for: %s", sql)
}
query := &queryExecuteShards{
SQL: sql,
BindVariables: bindVars,
TabletType: tabletType,
Keyspace: keyspace,
Shards: shards,
Session: s,
}
if !reflect.DeepEqual(query, response.shardQuery) {
return nil, nil, fmt.Errorf(
"ExecuteShards: %+v, want %+v", query, response.shardQuery)
}
reply := *response.reply
if s != nil {
s = newSession(true, keyspace, shards, tabletType)
}
return s, &reply, nil
} | go | func (conn *FakeVTGateConn) ExecuteShards(ctx context.Context, sql string, keyspace string, shards []string, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, session *vtgatepb.Session, options *querypb.ExecuteOptions) (*vtgatepb.Session, *sqltypes.Result, error) {
var s *vtgatepb.Session
if session != nil {
s = session
}
response, ok := conn.execMap[getShardQueryKey(sql, shards)]
if !ok {
return nil, nil, fmt.Errorf("no match for: %s", sql)
}
query := &queryExecuteShards{
SQL: sql,
BindVariables: bindVars,
TabletType: tabletType,
Keyspace: keyspace,
Shards: shards,
Session: s,
}
if !reflect.DeepEqual(query, response.shardQuery) {
return nil, nil, fmt.Errorf(
"ExecuteShards: %+v, want %+v", query, response.shardQuery)
}
reply := *response.reply
if s != nil {
s = newSession(true, keyspace, shards, tabletType)
}
return s, &reply, nil
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"ExecuteShards",
"(",
"ctx",
"context",
".",
"Context",
",",
"sql",
"string",
",",
"keyspace",
"string",
",",
"shards",
"[",
"]",
"string",
",",
"bindVars",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
",",
"tabletType",
"topodatapb",
".",
"TabletType",
",",
"session",
"*",
"vtgatepb",
".",
"Session",
",",
"options",
"*",
"querypb",
".",
"ExecuteOptions",
")",
"(",
"*",
"vtgatepb",
".",
"Session",
",",
"*",
"sqltypes",
".",
"Result",
",",
"error",
")",
"{",
"var",
"s",
"*",
"vtgatepb",
".",
"Session",
"\n",
"if",
"session",
"!=",
"nil",
"{",
"s",
"=",
"session",
"\n",
"}",
"\n",
"response",
",",
"ok",
":=",
"conn",
".",
"execMap",
"[",
"getShardQueryKey",
"(",
"sql",
",",
"shards",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sql",
")",
"\n",
"}",
"\n",
"query",
":=",
"&",
"queryExecuteShards",
"{",
"SQL",
":",
"sql",
",",
"BindVariables",
":",
"bindVars",
",",
"TabletType",
":",
"tabletType",
",",
"Keyspace",
":",
"keyspace",
",",
"Shards",
":",
"shards",
",",
"Session",
":",
"s",
",",
"}",
"\n",
"if",
"!",
"reflect",
".",
"DeepEqual",
"(",
"query",
",",
"response",
".",
"shardQuery",
")",
"{",
"return",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"query",
",",
"response",
".",
"shardQuery",
")",
"\n",
"}",
"\n",
"reply",
":=",
"*",
"response",
".",
"reply",
"\n",
"if",
"s",
"!=",
"nil",
"{",
"s",
"=",
"newSession",
"(",
"true",
",",
"keyspace",
",",
"shards",
",",
"tabletType",
")",
"\n",
"}",
"\n",
"return",
"s",
",",
"&",
"reply",
",",
"nil",
"\n",
"}"
] | // ExecuteShards please see vtgateconn.Impl.ExecuteShard | [
"ExecuteShards",
"please",
"see",
"vtgateconn",
".",
"Impl",
".",
"ExecuteShard"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L235-L261 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | ExecuteKeyspaceIds | func (conn *FakeVTGateConn) ExecuteKeyspaceIds(ctx context.Context, query string, keyspace string, keyspaceIds [][]byte, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, session *vtgatepb.Session, options *querypb.ExecuteOptions) (*vtgatepb.Session, *sqltypes.Result, error) {
panic("not implemented")
} | go | func (conn *FakeVTGateConn) ExecuteKeyspaceIds(ctx context.Context, query string, keyspace string, keyspaceIds [][]byte, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, session *vtgatepb.Session, options *querypb.ExecuteOptions) (*vtgatepb.Session, *sqltypes.Result, error) {
panic("not implemented")
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"ExecuteKeyspaceIds",
"(",
"ctx",
"context",
".",
"Context",
",",
"query",
"string",
",",
"keyspace",
"string",
",",
"keyspaceIds",
"[",
"]",
"[",
"]",
"byte",
",",
"bindVars",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
",",
"tabletType",
"topodatapb",
".",
"TabletType",
",",
"session",
"*",
"vtgatepb",
".",
"Session",
",",
"options",
"*",
"querypb",
".",
"ExecuteOptions",
")",
"(",
"*",
"vtgatepb",
".",
"Session",
",",
"*",
"sqltypes",
".",
"Result",
",",
"error",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // ExecuteKeyspaceIds please see vtgateconn.Impl.ExecuteKeyspaceIds | [
"ExecuteKeyspaceIds",
"please",
"see",
"vtgateconn",
".",
"Impl",
".",
"ExecuteKeyspaceIds"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L264-L266 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | ExecuteKeyRanges | func (conn *FakeVTGateConn) ExecuteKeyRanges(ctx context.Context, query string, keyspace string, keyRanges []*topodatapb.KeyRange, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, session *vtgatepb.Session, options *querypb.ExecuteOptions) (*vtgatepb.Session, *sqltypes.Result, error) {
panic("not implemented")
} | go | func (conn *FakeVTGateConn) ExecuteKeyRanges(ctx context.Context, query string, keyspace string, keyRanges []*topodatapb.KeyRange, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, session *vtgatepb.Session, options *querypb.ExecuteOptions) (*vtgatepb.Session, *sqltypes.Result, error) {
panic("not implemented")
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"ExecuteKeyRanges",
"(",
"ctx",
"context",
".",
"Context",
",",
"query",
"string",
",",
"keyspace",
"string",
",",
"keyRanges",
"[",
"]",
"*",
"topodatapb",
".",
"KeyRange",
",",
"bindVars",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
",",
"tabletType",
"topodatapb",
".",
"TabletType",
",",
"session",
"*",
"vtgatepb",
".",
"Session",
",",
"options",
"*",
"querypb",
".",
"ExecuteOptions",
")",
"(",
"*",
"vtgatepb",
".",
"Session",
",",
"*",
"sqltypes",
".",
"Result",
",",
"error",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // ExecuteKeyRanges please see vtgateconn.Impl.ExecuteKeyRanges | [
"ExecuteKeyRanges",
"please",
"see",
"vtgateconn",
".",
"Impl",
".",
"ExecuteKeyRanges"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L269-L271 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | ExecuteEntityIds | func (conn *FakeVTGateConn) ExecuteEntityIds(ctx context.Context, query string, keyspace string, entityColumnName string, entityKeyspaceIDs []*vtgatepb.ExecuteEntityIdsRequest_EntityId, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, session *vtgatepb.Session, options *querypb.ExecuteOptions) (*vtgatepb.Session, *sqltypes.Result, error) {
panic("not implemented")
} | go | func (conn *FakeVTGateConn) ExecuteEntityIds(ctx context.Context, query string, keyspace string, entityColumnName string, entityKeyspaceIDs []*vtgatepb.ExecuteEntityIdsRequest_EntityId, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, session *vtgatepb.Session, options *querypb.ExecuteOptions) (*vtgatepb.Session, *sqltypes.Result, error) {
panic("not implemented")
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"ExecuteEntityIds",
"(",
"ctx",
"context",
".",
"Context",
",",
"query",
"string",
",",
"keyspace",
"string",
",",
"entityColumnName",
"string",
",",
"entityKeyspaceIDs",
"[",
"]",
"*",
"vtgatepb",
".",
"ExecuteEntityIdsRequest_EntityId",
",",
"bindVars",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
",",
"tabletType",
"topodatapb",
".",
"TabletType",
",",
"session",
"*",
"vtgatepb",
".",
"Session",
",",
"options",
"*",
"querypb",
".",
"ExecuteOptions",
")",
"(",
"*",
"vtgatepb",
".",
"Session",
",",
"*",
"sqltypes",
".",
"Result",
",",
"error",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // ExecuteEntityIds please see vtgateconn.Impl.ExecuteEntityIds | [
"ExecuteEntityIds",
"please",
"see",
"vtgateconn",
".",
"Impl",
".",
"ExecuteEntityIds"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L274-L276 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | ExecuteBatchShards | func (conn *FakeVTGateConn) ExecuteBatchShards(ctx context.Context, queries []*vtgatepb.BoundShardQuery, tabletType topodatapb.TabletType, asTransaction bool, session *vtgatepb.Session, options *querypb.ExecuteOptions) (*vtgatepb.Session, []sqltypes.Result, error) {
panic("not implemented")
} | go | func (conn *FakeVTGateConn) ExecuteBatchShards(ctx context.Context, queries []*vtgatepb.BoundShardQuery, tabletType topodatapb.TabletType, asTransaction bool, session *vtgatepb.Session, options *querypb.ExecuteOptions) (*vtgatepb.Session, []sqltypes.Result, error) {
panic("not implemented")
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"ExecuteBatchShards",
"(",
"ctx",
"context",
".",
"Context",
",",
"queries",
"[",
"]",
"*",
"vtgatepb",
".",
"BoundShardQuery",
",",
"tabletType",
"topodatapb",
".",
"TabletType",
",",
"asTransaction",
"bool",
",",
"session",
"*",
"vtgatepb",
".",
"Session",
",",
"options",
"*",
"querypb",
".",
"ExecuteOptions",
")",
"(",
"*",
"vtgatepb",
".",
"Session",
",",
"[",
"]",
"sqltypes",
".",
"Result",
",",
"error",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // ExecuteBatchShards please see vtgateconn.Impl.ExecuteBatchShards | [
"ExecuteBatchShards",
"please",
"see",
"vtgateconn",
".",
"Impl",
".",
"ExecuteBatchShards"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L279-L281 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | StreamExecuteShards | func (conn *FakeVTGateConn) StreamExecuteShards(ctx context.Context, query string, keyspace string, shards []string, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (sqltypes.ResultStream, error) {
panic("not implemented")
} | go | func (conn *FakeVTGateConn) StreamExecuteShards(ctx context.Context, query string, keyspace string, shards []string, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (sqltypes.ResultStream, error) {
panic("not implemented")
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"StreamExecuteShards",
"(",
"ctx",
"context",
".",
"Context",
",",
"query",
"string",
",",
"keyspace",
"string",
",",
"shards",
"[",
"]",
"string",
",",
"bindVars",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
",",
"tabletType",
"topodatapb",
".",
"TabletType",
",",
"options",
"*",
"querypb",
".",
"ExecuteOptions",
")",
"(",
"sqltypes",
".",
"ResultStream",
",",
"error",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // StreamExecuteShards please see vtgateconn.Impl.StreamExecuteShards | [
"StreamExecuteShards",
"please",
"see",
"vtgateconn",
".",
"Impl",
".",
"StreamExecuteShards"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L301-L303 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | Begin | func (conn *FakeVTGateConn) Begin(ctx context.Context, singledb bool) (*vtgatepb.Session, error) {
return &vtgatepb.Session{
InTransaction: true,
SingleDb: singledb,
}, nil
} | go | func (conn *FakeVTGateConn) Begin(ctx context.Context, singledb bool) (*vtgatepb.Session, error) {
return &vtgatepb.Session{
InTransaction: true,
SingleDb: singledb,
}, nil
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"Begin",
"(",
"ctx",
"context",
".",
"Context",
",",
"singledb",
"bool",
")",
"(",
"*",
"vtgatepb",
".",
"Session",
",",
"error",
")",
"{",
"return",
"&",
"vtgatepb",
".",
"Session",
"{",
"InTransaction",
":",
"true",
",",
"SingleDb",
":",
"singledb",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Begin please see vtgateconn.Impl.Begin | [
"Begin",
"please",
"see",
"vtgateconn",
".",
"Impl",
".",
"Begin"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L316-L321 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | Commit | func (conn *FakeVTGateConn) Commit(ctx context.Context, session *vtgatepb.Session, twopc bool) error {
if session == nil {
return errors.New("commit: not in transaction")
}
return nil
} | go | func (conn *FakeVTGateConn) Commit(ctx context.Context, session *vtgatepb.Session, twopc bool) error {
if session == nil {
return errors.New("commit: not in transaction")
}
return nil
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"Commit",
"(",
"ctx",
"context",
".",
"Context",
",",
"session",
"*",
"vtgatepb",
".",
"Session",
",",
"twopc",
"bool",
")",
"error",
"{",
"if",
"session",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Commit please see vtgateconn.Impl.Commit | [
"Commit",
"please",
"see",
"vtgateconn",
".",
"Impl",
".",
"Commit"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L324-L329 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | Rollback | func (conn *FakeVTGateConn) Rollback(ctx context.Context, session *vtgatepb.Session) error {
return nil
} | go | func (conn *FakeVTGateConn) Rollback(ctx context.Context, session *vtgatepb.Session) error {
return nil
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"Rollback",
"(",
"ctx",
"context",
".",
"Context",
",",
"session",
"*",
"vtgatepb",
".",
"Session",
")",
"error",
"{",
"return",
"nil",
"\n",
"}"
] | // Rollback please see vtgateconn.Impl.Rollback | [
"Rollback",
"please",
"see",
"vtgateconn",
".",
"Impl",
".",
"Rollback"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L332-L334 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | ResolveTransaction | func (conn *FakeVTGateConn) ResolveTransaction(ctx context.Context, dtid string) error {
return nil
} | go | func (conn *FakeVTGateConn) ResolveTransaction(ctx context.Context, dtid string) error {
return nil
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"ResolveTransaction",
"(",
"ctx",
"context",
".",
"Context",
",",
"dtid",
"string",
")",
"error",
"{",
"return",
"nil",
"\n",
"}"
] | // ResolveTransaction please see vtgateconn.Impl.ResolveTransaction | [
"ResolveTransaction",
"please",
"see",
"vtgateconn",
".",
"Impl",
".",
"ResolveTransaction"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L337-L339 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | MessageStream | func (conn *FakeVTGateConn) MessageStream(ctx context.Context, keyspace string, shard string, keyRange *topodatapb.KeyRange, name string, callback func(*sqltypes.Result) error) error {
panic("not implemented")
} | go | func (conn *FakeVTGateConn) MessageStream(ctx context.Context, keyspace string, shard string, keyRange *topodatapb.KeyRange, name string, callback func(*sqltypes.Result) error) error {
panic("not implemented")
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"MessageStream",
"(",
"ctx",
"context",
".",
"Context",
",",
"keyspace",
"string",
",",
"shard",
"string",
",",
"keyRange",
"*",
"topodatapb",
".",
"KeyRange",
",",
"name",
"string",
",",
"callback",
"func",
"(",
"*",
"sqltypes",
".",
"Result",
")",
"error",
")",
"error",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // MessageStream is part of the vtgate service API. | [
"MessageStream",
"is",
"part",
"of",
"the",
"vtgate",
"service",
"API",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L342-L344 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | MessageAck | func (conn *FakeVTGateConn) MessageAck(ctx context.Context, keyspace string, name string, ids []*querypb.Value) (int64, error) {
panic("not implemented")
} | go | func (conn *FakeVTGateConn) MessageAck(ctx context.Context, keyspace string, name string, ids []*querypb.Value) (int64, error) {
panic("not implemented")
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"MessageAck",
"(",
"ctx",
"context",
".",
"Context",
",",
"keyspace",
"string",
",",
"name",
"string",
",",
"ids",
"[",
"]",
"*",
"querypb",
".",
"Value",
")",
"(",
"int64",
",",
"error",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // MessageAck is part of the vtgate service API. | [
"MessageAck",
"is",
"part",
"of",
"the",
"vtgate",
"service",
"API",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L347-L349 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | MessageAckKeyspaceIds | func (conn *FakeVTGateConn) MessageAckKeyspaceIds(ctx context.Context, keyspace string, name string, idKeyspaceIDs []*vtgatepb.IdKeyspaceId) (int64, error) {
panic("not implemented")
} | go | func (conn *FakeVTGateConn) MessageAckKeyspaceIds(ctx context.Context, keyspace string, name string, idKeyspaceIDs []*vtgatepb.IdKeyspaceId) (int64, error) {
panic("not implemented")
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"MessageAckKeyspaceIds",
"(",
"ctx",
"context",
".",
"Context",
",",
"keyspace",
"string",
",",
"name",
"string",
",",
"idKeyspaceIDs",
"[",
"]",
"*",
"vtgatepb",
".",
"IdKeyspaceId",
")",
"(",
"int64",
",",
"error",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // MessageAckKeyspaceIds is part of the vtgate service API. | [
"MessageAckKeyspaceIds",
"is",
"part",
"of",
"the",
"vtgate",
"service",
"API",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L352-L354 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | SplitQuery | func (conn *FakeVTGateConn) SplitQuery(
ctx context.Context,
keyspace string,
query string,
bindVars map[string]*querypb.BindVariable,
splitColumns []string,
splitCount int64,
numRowsPerQueryPart int64,
algorithm querypb.SplitQueryRequest_Algorithm) ([]*vtgatepb.SplitQueryResponse_Part, error) {
response, ok := conn.splitQueryMap[getSplitQueryKey(
keyspace, query, splitColumns, splitCount, numRowsPerQueryPart, algorithm)]
if !ok {
return nil, fmt.Errorf(
"no match for keyspace: %s,"+
" query: %v,"+
" splitColumns: %v,"+
" splitCount: %v"+
" numRowsPerQueryPart: %v"+
" algorithm: %v",
keyspace, query, splitColumns, splitCount, numRowsPerQueryPart, algorithm)
}
reply := make([]*vtgatepb.SplitQueryResponse_Part, len(response.reply))
copy(reply, response.reply)
return reply, nil
} | go | func (conn *FakeVTGateConn) SplitQuery(
ctx context.Context,
keyspace string,
query string,
bindVars map[string]*querypb.BindVariable,
splitColumns []string,
splitCount int64,
numRowsPerQueryPart int64,
algorithm querypb.SplitQueryRequest_Algorithm) ([]*vtgatepb.SplitQueryResponse_Part, error) {
response, ok := conn.splitQueryMap[getSplitQueryKey(
keyspace, query, splitColumns, splitCount, numRowsPerQueryPart, algorithm)]
if !ok {
return nil, fmt.Errorf(
"no match for keyspace: %s,"+
" query: %v,"+
" splitColumns: %v,"+
" splitCount: %v"+
" numRowsPerQueryPart: %v"+
" algorithm: %v",
keyspace, query, splitColumns, splitCount, numRowsPerQueryPart, algorithm)
}
reply := make([]*vtgatepb.SplitQueryResponse_Part, len(response.reply))
copy(reply, response.reply)
return reply, nil
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"SplitQuery",
"(",
"ctx",
"context",
".",
"Context",
",",
"keyspace",
"string",
",",
"query",
"string",
",",
"bindVars",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
",",
"splitColumns",
"[",
"]",
"string",
",",
"splitCount",
"int64",
",",
"numRowsPerQueryPart",
"int64",
",",
"algorithm",
"querypb",
".",
"SplitQueryRequest_Algorithm",
")",
"(",
"[",
"]",
"*",
"vtgatepb",
".",
"SplitQueryResponse_Part",
",",
"error",
")",
"{",
"response",
",",
"ok",
":=",
"conn",
".",
"splitQueryMap",
"[",
"getSplitQueryKey",
"(",
"keyspace",
",",
"query",
",",
"splitColumns",
",",
"splitCount",
",",
"numRowsPerQueryPart",
",",
"algorithm",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
"+",
"\"",
"\"",
"+",
"\"",
"\"",
"+",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"keyspace",
",",
"query",
",",
"splitColumns",
",",
"splitCount",
",",
"numRowsPerQueryPart",
",",
"algorithm",
")",
"\n",
"}",
"\n",
"reply",
":=",
"make",
"(",
"[",
"]",
"*",
"vtgatepb",
".",
"SplitQueryResponse_Part",
",",
"len",
"(",
"response",
".",
"reply",
")",
")",
"\n",
"copy",
"(",
"reply",
",",
"response",
".",
"reply",
")",
"\n",
"return",
"reply",
",",
"nil",
"\n",
"}"
] | // SplitQuery please see vtgateconn.Impl.SplitQuery | [
"SplitQuery",
"please",
"see",
"vtgateconn",
".",
"Impl",
".",
"SplitQuery"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L357-L382 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | GetSrvKeyspace | func (conn *FakeVTGateConn) GetSrvKeyspace(ctx context.Context, keyspace string) (*topodatapb.SrvKeyspace, error) {
return nil, fmt.Errorf("NYI")
} | go | func (conn *FakeVTGateConn) GetSrvKeyspace(ctx context.Context, keyspace string) (*topodatapb.SrvKeyspace, error) {
return nil, fmt.Errorf("NYI")
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"GetSrvKeyspace",
"(",
"ctx",
"context",
".",
"Context",
",",
"keyspace",
"string",
")",
"(",
"*",
"topodatapb",
".",
"SrvKeyspace",
",",
"error",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // GetSrvKeyspace please see vtgateconn.Impl.GetSrvKeyspace | [
"GetSrvKeyspace",
"please",
"see",
"vtgateconn",
".",
"Impl",
".",
"GetSrvKeyspace"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L385-L387 | train |
vitessio/vitess | go/vt/vtgate/fakerpcvtgateconn/conn.go | UpdateStream | func (conn *FakeVTGateConn) UpdateStream(ctx context.Context, keyspace string, shard string, keyRange *topodatapb.KeyRange, tabletType topodatapb.TabletType, timestamp int64, event *querypb.EventToken) (vtgateconn.UpdateStreamReader, error) {
return nil, fmt.Errorf("NYI")
} | go | func (conn *FakeVTGateConn) UpdateStream(ctx context.Context, keyspace string, shard string, keyRange *topodatapb.KeyRange, tabletType topodatapb.TabletType, timestamp int64, event *querypb.EventToken) (vtgateconn.UpdateStreamReader, error) {
return nil, fmt.Errorf("NYI")
} | [
"func",
"(",
"conn",
"*",
"FakeVTGateConn",
")",
"UpdateStream",
"(",
"ctx",
"context",
".",
"Context",
",",
"keyspace",
"string",
",",
"shard",
"string",
",",
"keyRange",
"*",
"topodatapb",
".",
"KeyRange",
",",
"tabletType",
"topodatapb",
".",
"TabletType",
",",
"timestamp",
"int64",
",",
"event",
"*",
"querypb",
".",
"EventToken",
")",
"(",
"vtgateconn",
".",
"UpdateStreamReader",
",",
"error",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // UpdateStream please see vtgateconn.Impl.UpdateStream | [
"UpdateStream",
"please",
"see",
"vtgateconn",
".",
"Impl",
".",
"UpdateStream"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/fakerpcvtgateconn/conn.go#L390-L392 | train |
vitessio/vitess | go/vt/sqlparser/encodable.go | EncodeSQL | func (iv InsertValues) EncodeSQL(buf *strings.Builder) {
for i, rows := range iv {
if i != 0 {
buf.WriteString(", ")
}
buf.WriteByte('(')
for j, bv := range rows {
if j != 0 {
buf.WriteString(", ")
}
bv.EncodeSQL(buf)
}
buf.WriteByte(')')
}
} | go | func (iv InsertValues) EncodeSQL(buf *strings.Builder) {
for i, rows := range iv {
if i != 0 {
buf.WriteString(", ")
}
buf.WriteByte('(')
for j, bv := range rows {
if j != 0 {
buf.WriteString(", ")
}
bv.EncodeSQL(buf)
}
buf.WriteByte(')')
}
} | [
"func",
"(",
"iv",
"InsertValues",
")",
"EncodeSQL",
"(",
"buf",
"*",
"strings",
".",
"Builder",
")",
"{",
"for",
"i",
",",
"rows",
":=",
"range",
"iv",
"{",
"if",
"i",
"!=",
"0",
"{",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"buf",
".",
"WriteByte",
"(",
"'('",
")",
"\n",
"for",
"j",
",",
"bv",
":=",
"range",
"rows",
"{",
"if",
"j",
"!=",
"0",
"{",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"bv",
".",
"EncodeSQL",
"(",
"buf",
")",
"\n",
"}",
"\n",
"buf",
".",
"WriteByte",
"(",
"')'",
")",
"\n",
"}",
"\n",
"}"
] | // EncodeSQL performs the SQL encoding for InsertValues. | [
"EncodeSQL",
"performs",
"the",
"SQL",
"encoding",
"for",
"InsertValues",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/encodable.go#L38-L52 | train |
vitessio/vitess | go/vt/sqlparser/encodable.go | EncodeSQL | func (tpl *TupleEqualityList) EncodeSQL(buf *strings.Builder) {
if len(tpl.Columns) == 1 {
tpl.encodeAsIn(buf)
return
}
tpl.encodeAsEquality(buf)
} | go | func (tpl *TupleEqualityList) EncodeSQL(buf *strings.Builder) {
if len(tpl.Columns) == 1 {
tpl.encodeAsIn(buf)
return
}
tpl.encodeAsEquality(buf)
} | [
"func",
"(",
"tpl",
"*",
"TupleEqualityList",
")",
"EncodeSQL",
"(",
"buf",
"*",
"strings",
".",
"Builder",
")",
"{",
"if",
"len",
"(",
"tpl",
".",
"Columns",
")",
"==",
"1",
"{",
"tpl",
".",
"encodeAsIn",
"(",
"buf",
")",
"\n",
"return",
"\n",
"}",
"\n",
"tpl",
".",
"encodeAsEquality",
"(",
"buf",
")",
"\n",
"}"
] | // EncodeSQL generates the where clause constraints for the tuple
// equality. | [
"EncodeSQL",
"generates",
"the",
"where",
"clause",
"constraints",
"for",
"the",
"tuple",
"equality",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/sqlparser/encodable.go#L63-L69 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/txserializer/tx_serializer.go | New | func New(dryRun bool, maxQueueSize, maxGlobalQueueSize, concurrentTransactions int) *TxSerializer {
return &TxSerializer{
ConsolidatorCache: sync2.NewConsolidatorCache(1000),
dryRun: dryRun,
maxQueueSize: maxQueueSize,
maxGlobalQueueSize: maxGlobalQueueSize,
concurrentTransactions: concurrentTransactions,
log: logutil.NewThrottledLogger("HotRowProtection", 5*time.Second),
logDryRun: logutil.NewThrottledLogger("HotRowProtection DryRun", 5*time.Second),
logWaitsDryRun: logutil.NewThrottledLogger("HotRowProtection Waits DryRun", 5*time.Second),
logQueueExceededDryRun: logutil.NewThrottledLogger("HotRowProtection QueueExceeded DryRun", 5*time.Second),
logGlobalQueueExceededDryRun: logutil.NewThrottledLogger("HotRowProtection GlobalQueueExceeded DryRun", 5*time.Second),
queues: make(map[string]*queue),
}
} | go | func New(dryRun bool, maxQueueSize, maxGlobalQueueSize, concurrentTransactions int) *TxSerializer {
return &TxSerializer{
ConsolidatorCache: sync2.NewConsolidatorCache(1000),
dryRun: dryRun,
maxQueueSize: maxQueueSize,
maxGlobalQueueSize: maxGlobalQueueSize,
concurrentTransactions: concurrentTransactions,
log: logutil.NewThrottledLogger("HotRowProtection", 5*time.Second),
logDryRun: logutil.NewThrottledLogger("HotRowProtection DryRun", 5*time.Second),
logWaitsDryRun: logutil.NewThrottledLogger("HotRowProtection Waits DryRun", 5*time.Second),
logQueueExceededDryRun: logutil.NewThrottledLogger("HotRowProtection QueueExceeded DryRun", 5*time.Second),
logGlobalQueueExceededDryRun: logutil.NewThrottledLogger("HotRowProtection GlobalQueueExceeded DryRun", 5*time.Second),
queues: make(map[string]*queue),
}
} | [
"func",
"New",
"(",
"dryRun",
"bool",
",",
"maxQueueSize",
",",
"maxGlobalQueueSize",
",",
"concurrentTransactions",
"int",
")",
"*",
"TxSerializer",
"{",
"return",
"&",
"TxSerializer",
"{",
"ConsolidatorCache",
":",
"sync2",
".",
"NewConsolidatorCache",
"(",
"1000",
")",
",",
"dryRun",
":",
"dryRun",
",",
"maxQueueSize",
":",
"maxQueueSize",
",",
"maxGlobalQueueSize",
":",
"maxGlobalQueueSize",
",",
"concurrentTransactions",
":",
"concurrentTransactions",
",",
"log",
":",
"logutil",
".",
"NewThrottledLogger",
"(",
"\"",
"\"",
",",
"5",
"*",
"time",
".",
"Second",
")",
",",
"logDryRun",
":",
"logutil",
".",
"NewThrottledLogger",
"(",
"\"",
"\"",
",",
"5",
"*",
"time",
".",
"Second",
")",
",",
"logWaitsDryRun",
":",
"logutil",
".",
"NewThrottledLogger",
"(",
"\"",
"\"",
",",
"5",
"*",
"time",
".",
"Second",
")",
",",
"logQueueExceededDryRun",
":",
"logutil",
".",
"NewThrottledLogger",
"(",
"\"",
"\"",
",",
"5",
"*",
"time",
".",
"Second",
")",
",",
"logGlobalQueueExceededDryRun",
":",
"logutil",
".",
"NewThrottledLogger",
"(",
"\"",
"\"",
",",
"5",
"*",
"time",
".",
"Second",
")",
",",
"queues",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"queue",
")",
",",
"}",
"\n",
"}"
] | // New returns a TxSerializer object. | [
"New",
"returns",
"a",
"TxSerializer",
"object",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/txserializer/tx_serializer.go#L113-L127 | train |
vitessio/vitess | go/vt/vttablet/tabletserver/txserializer/tx_serializer.go | lockLocked | func (t *TxSerializer) lockLocked(ctx context.Context, key, table string) (bool, error) {
q, ok := t.queues[key]
if !ok {
// First transaction in the queue i.e. we don't wait and return immediately.
t.queues[key] = newQueueForFirstTransaction(t.concurrentTransactions)
t.globalSize++
return false, nil
}
if t.globalSize >= t.maxGlobalQueueSize {
if t.dryRun {
globalQueueExceededDryRun.Add(1)
t.logGlobalQueueExceededDryRun.Warningf("Would have rejected BeginExecute RPC because there are too many queued transactions (%d >= %d)", t.globalSize, t.maxGlobalQueueSize)
} else {
globalQueueExceeded.Add(1)
return false, vterrors.Errorf(vtrpcpb.Code_RESOURCE_EXHAUSTED,
"hot row protection: too many queued transactions (%d >= %d)", t.globalSize, t.maxGlobalQueueSize)
}
}
if q.size >= t.maxQueueSize {
if t.dryRun {
queueExceededDryRun.Add(table, 1)
t.logQueueExceededDryRun.Warningf("Would have rejected BeginExecute RPC because there are too many queued transactions (%d >= %d) for the same row (table + WHERE clause: '%v')", q.size, t.maxQueueSize, key)
} else {
queueExceeded.Add(table, 1)
return false, vterrors.Errorf(vtrpcpb.Code_RESOURCE_EXHAUSTED,
"hot row protection: too many queued transactions (%d >= %d) for the same row (table + WHERE clause: '%v')", q.size, t.maxQueueSize, key)
}
}
if q.availableSlots == nil {
// Hot row detected: A second, concurrent transaction is seen for the
// first time.
// As an optimization, we deferred the creation of the channel until now.
q.availableSlots = make(chan struct{}, t.concurrentTransactions)
q.availableSlots <- struct{}{}
// Include first transaction in the count at /debug/hotrows. (It was not
// recorded on purpose because it did not wait.)
t.Record(key)
}
t.globalSize++
q.size++
q.count++
if q.size > q.max {
q.max = q.size
}
// Publish the number of waits at /debug/hotrows.
t.Record(key)
if t.dryRun {
waitsDryRun.Add(table, 1)
t.logWaitsDryRun.Warningf("Would have queued BeginExecute RPC for row (range): '%v' because another transaction to the same range is already in progress.", key)
return false, nil
}
// Unlock before the wait and relock before returning because our caller
// Wait() holds the lock and assumes it still has it.
t.mu.Unlock()
defer t.mu.Lock()
// Non-blocking write attempt to get a slot.
select {
case q.availableSlots <- struct{}{}:
// Return waited=false because a slot was immediately available.
return false, nil
default:
}
// Blocking wait for the next available slot.
waits.Add(table, 1)
select {
case q.availableSlots <- struct{}{}:
return true, nil
case <-ctx.Done():
return true, ctx.Err()
}
} | go | func (t *TxSerializer) lockLocked(ctx context.Context, key, table string) (bool, error) {
q, ok := t.queues[key]
if !ok {
// First transaction in the queue i.e. we don't wait and return immediately.
t.queues[key] = newQueueForFirstTransaction(t.concurrentTransactions)
t.globalSize++
return false, nil
}
if t.globalSize >= t.maxGlobalQueueSize {
if t.dryRun {
globalQueueExceededDryRun.Add(1)
t.logGlobalQueueExceededDryRun.Warningf("Would have rejected BeginExecute RPC because there are too many queued transactions (%d >= %d)", t.globalSize, t.maxGlobalQueueSize)
} else {
globalQueueExceeded.Add(1)
return false, vterrors.Errorf(vtrpcpb.Code_RESOURCE_EXHAUSTED,
"hot row protection: too many queued transactions (%d >= %d)", t.globalSize, t.maxGlobalQueueSize)
}
}
if q.size >= t.maxQueueSize {
if t.dryRun {
queueExceededDryRun.Add(table, 1)
t.logQueueExceededDryRun.Warningf("Would have rejected BeginExecute RPC because there are too many queued transactions (%d >= %d) for the same row (table + WHERE clause: '%v')", q.size, t.maxQueueSize, key)
} else {
queueExceeded.Add(table, 1)
return false, vterrors.Errorf(vtrpcpb.Code_RESOURCE_EXHAUSTED,
"hot row protection: too many queued transactions (%d >= %d) for the same row (table + WHERE clause: '%v')", q.size, t.maxQueueSize, key)
}
}
if q.availableSlots == nil {
// Hot row detected: A second, concurrent transaction is seen for the
// first time.
// As an optimization, we deferred the creation of the channel until now.
q.availableSlots = make(chan struct{}, t.concurrentTransactions)
q.availableSlots <- struct{}{}
// Include first transaction in the count at /debug/hotrows. (It was not
// recorded on purpose because it did not wait.)
t.Record(key)
}
t.globalSize++
q.size++
q.count++
if q.size > q.max {
q.max = q.size
}
// Publish the number of waits at /debug/hotrows.
t.Record(key)
if t.dryRun {
waitsDryRun.Add(table, 1)
t.logWaitsDryRun.Warningf("Would have queued BeginExecute RPC for row (range): '%v' because another transaction to the same range is already in progress.", key)
return false, nil
}
// Unlock before the wait and relock before returning because our caller
// Wait() holds the lock and assumes it still has it.
t.mu.Unlock()
defer t.mu.Lock()
// Non-blocking write attempt to get a slot.
select {
case q.availableSlots <- struct{}{}:
// Return waited=false because a slot was immediately available.
return false, nil
default:
}
// Blocking wait for the next available slot.
waits.Add(table, 1)
select {
case q.availableSlots <- struct{}{}:
return true, nil
case <-ctx.Done():
return true, ctx.Err()
}
} | [
"func",
"(",
"t",
"*",
"TxSerializer",
")",
"lockLocked",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
",",
"table",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"q",
",",
"ok",
":=",
"t",
".",
"queues",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"// First transaction in the queue i.e. we don't wait and return immediately.",
"t",
".",
"queues",
"[",
"key",
"]",
"=",
"newQueueForFirstTransaction",
"(",
"t",
".",
"concurrentTransactions",
")",
"\n",
"t",
".",
"globalSize",
"++",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"t",
".",
"globalSize",
">=",
"t",
".",
"maxGlobalQueueSize",
"{",
"if",
"t",
".",
"dryRun",
"{",
"globalQueueExceededDryRun",
".",
"Add",
"(",
"1",
")",
"\n",
"t",
".",
"logGlobalQueueExceededDryRun",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"t",
".",
"globalSize",
",",
"t",
".",
"maxGlobalQueueSize",
")",
"\n",
"}",
"else",
"{",
"globalQueueExceeded",
".",
"Add",
"(",
"1",
")",
"\n",
"return",
"false",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpcpb",
".",
"Code_RESOURCE_EXHAUSTED",
",",
"\"",
"\"",
",",
"t",
".",
"globalSize",
",",
"t",
".",
"maxGlobalQueueSize",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"q",
".",
"size",
">=",
"t",
".",
"maxQueueSize",
"{",
"if",
"t",
".",
"dryRun",
"{",
"queueExceededDryRun",
".",
"Add",
"(",
"table",
",",
"1",
")",
"\n",
"t",
".",
"logQueueExceededDryRun",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"q",
".",
"size",
",",
"t",
".",
"maxQueueSize",
",",
"key",
")",
"\n",
"}",
"else",
"{",
"queueExceeded",
".",
"Add",
"(",
"table",
",",
"1",
")",
"\n",
"return",
"false",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpcpb",
".",
"Code_RESOURCE_EXHAUSTED",
",",
"\"",
"\"",
",",
"q",
".",
"size",
",",
"t",
".",
"maxQueueSize",
",",
"key",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"q",
".",
"availableSlots",
"==",
"nil",
"{",
"// Hot row detected: A second, concurrent transaction is seen for the",
"// first time.",
"// As an optimization, we deferred the creation of the channel until now.",
"q",
".",
"availableSlots",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
",",
"t",
".",
"concurrentTransactions",
")",
"\n",
"q",
".",
"availableSlots",
"<-",
"struct",
"{",
"}",
"{",
"}",
"\n\n",
"// Include first transaction in the count at /debug/hotrows. (It was not",
"// recorded on purpose because it did not wait.)",
"t",
".",
"Record",
"(",
"key",
")",
"\n",
"}",
"\n\n",
"t",
".",
"globalSize",
"++",
"\n",
"q",
".",
"size",
"++",
"\n",
"q",
".",
"count",
"++",
"\n",
"if",
"q",
".",
"size",
">",
"q",
".",
"max",
"{",
"q",
".",
"max",
"=",
"q",
".",
"size",
"\n",
"}",
"\n",
"// Publish the number of waits at /debug/hotrows.",
"t",
".",
"Record",
"(",
"key",
")",
"\n\n",
"if",
"t",
".",
"dryRun",
"{",
"waitsDryRun",
".",
"Add",
"(",
"table",
",",
"1",
")",
"\n",
"t",
".",
"logWaitsDryRun",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"// Unlock before the wait and relock before returning because our caller",
"// Wait() holds the lock and assumes it still has it.",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n\n",
"// Non-blocking write attempt to get a slot.",
"select",
"{",
"case",
"q",
".",
"availableSlots",
"<-",
"struct",
"{",
"}",
"{",
"}",
":",
"// Return waited=false because a slot was immediately available.",
"return",
"false",
",",
"nil",
"\n",
"default",
":",
"}",
"\n\n",
"// Blocking wait for the next available slot.",
"waits",
".",
"Add",
"(",
"table",
",",
"1",
")",
"\n",
"select",
"{",
"case",
"q",
".",
"availableSlots",
"<-",
"struct",
"{",
"}",
"{",
"}",
":",
"return",
"true",
",",
"nil",
"\n",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"true",
",",
"ctx",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // lockLocked queues this transaction. It will unblock immediately if this
// transaction is the first in the queue or when it acquired a slot.
// The method has the suffix "Locked" to clarify that "t.mu" must be locked. | [
"lockLocked",
"queues",
"this",
"transaction",
".",
"It",
"will",
"unblock",
"immediately",
"if",
"this",
"transaction",
"is",
"the",
"first",
"in",
"the",
"queue",
"or",
"when",
"it",
"acquired",
"a",
"slot",
".",
"The",
"method",
"has",
"the",
"suffix",
"Locked",
"to",
"clarify",
"that",
"t",
".",
"mu",
"must",
"be",
"locked",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/tabletserver/txserializer/tx_serializer.go#L157-L237 | train |
vitessio/vitess | go/vt/vttablet/heartbeat/reader.go | NewReader | func NewReader(checker connpool.MySQLChecker, config tabletenv.TabletConfig) *Reader {
if !config.HeartbeatEnable {
return &Reader{}
}
return &Reader{
enabled: true,
now: time.Now,
interval: config.HeartbeatInterval,
ticks: timer.NewTimer(config.HeartbeatInterval),
errorLog: logutil.NewThrottledLogger("HeartbeatReporter", 60*time.Second),
pool: connpool.New(config.PoolNamePrefix+"HeartbeatReadPool", 1, time.Duration(config.IdleTimeout*1e9), checker),
}
} | go | func NewReader(checker connpool.MySQLChecker, config tabletenv.TabletConfig) *Reader {
if !config.HeartbeatEnable {
return &Reader{}
}
return &Reader{
enabled: true,
now: time.Now,
interval: config.HeartbeatInterval,
ticks: timer.NewTimer(config.HeartbeatInterval),
errorLog: logutil.NewThrottledLogger("HeartbeatReporter", 60*time.Second),
pool: connpool.New(config.PoolNamePrefix+"HeartbeatReadPool", 1, time.Duration(config.IdleTimeout*1e9), checker),
}
} | [
"func",
"NewReader",
"(",
"checker",
"connpool",
".",
"MySQLChecker",
",",
"config",
"tabletenv",
".",
"TabletConfig",
")",
"*",
"Reader",
"{",
"if",
"!",
"config",
".",
"HeartbeatEnable",
"{",
"return",
"&",
"Reader",
"{",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"Reader",
"{",
"enabled",
":",
"true",
",",
"now",
":",
"time",
".",
"Now",
",",
"interval",
":",
"config",
".",
"HeartbeatInterval",
",",
"ticks",
":",
"timer",
".",
"NewTimer",
"(",
"config",
".",
"HeartbeatInterval",
")",
",",
"errorLog",
":",
"logutil",
".",
"NewThrottledLogger",
"(",
"\"",
"\"",
",",
"60",
"*",
"time",
".",
"Second",
")",
",",
"pool",
":",
"connpool",
".",
"New",
"(",
"config",
".",
"PoolNamePrefix",
"+",
"\"",
"\"",
",",
"1",
",",
"time",
".",
"Duration",
"(",
"config",
".",
"IdleTimeout",
"*",
"1e9",
")",
",",
"checker",
")",
",",
"}",
"\n",
"}"
] | // NewReader returns a new heartbeat reader. | [
"NewReader",
"returns",
"a",
"new",
"heartbeat",
"reader",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/heartbeat/reader.go#L72-L85 | train |
vitessio/vitess | go/vt/vttablet/heartbeat/reader.go | Init | func (r *Reader) Init(target querypb.Target) {
if !r.enabled {
return
}
r.dbName = sqlescape.EscapeID(r.dbconfigs.SidecarDBName.Get())
r.keyspaceShard = fmt.Sprintf("%s:%s", target.Keyspace, target.Shard)
} | go | func (r *Reader) Init(target querypb.Target) {
if !r.enabled {
return
}
r.dbName = sqlescape.EscapeID(r.dbconfigs.SidecarDBName.Get())
r.keyspaceShard = fmt.Sprintf("%s:%s", target.Keyspace, target.Shard)
} | [
"func",
"(",
"r",
"*",
"Reader",
")",
"Init",
"(",
"target",
"querypb",
".",
"Target",
")",
"{",
"if",
"!",
"r",
".",
"enabled",
"{",
"return",
"\n",
"}",
"\n",
"r",
".",
"dbName",
"=",
"sqlescape",
".",
"EscapeID",
"(",
"r",
".",
"dbconfigs",
".",
"SidecarDBName",
".",
"Get",
"(",
")",
")",
"\n",
"r",
".",
"keyspaceShard",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"target",
".",
"Keyspace",
",",
"target",
".",
"Shard",
")",
"\n",
"}"
] | // Init does last minute initialization of db settings, such as dbName
// and keyspaceShard | [
"Init",
"does",
"last",
"minute",
"initialization",
"of",
"db",
"settings",
"such",
"as",
"dbName",
"and",
"keyspaceShard"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/heartbeat/reader.go#L94-L100 | train |
vitessio/vitess | go/vt/vttablet/heartbeat/reader.go | Open | func (r *Reader) Open() {
if !r.enabled {
return
}
r.runMu.Lock()
defer r.runMu.Unlock()
if r.isOpen {
return
}
log.Info("Beginning heartbeat reads")
r.pool.Open(r.dbconfigs.AppWithDB(), r.dbconfigs.DbaWithDB(), r.dbconfigs.AppDebugWithDB())
r.ticks.Start(func() { r.readHeartbeat() })
r.isOpen = true
} | go | func (r *Reader) Open() {
if !r.enabled {
return
}
r.runMu.Lock()
defer r.runMu.Unlock()
if r.isOpen {
return
}
log.Info("Beginning heartbeat reads")
r.pool.Open(r.dbconfigs.AppWithDB(), r.dbconfigs.DbaWithDB(), r.dbconfigs.AppDebugWithDB())
r.ticks.Start(func() { r.readHeartbeat() })
r.isOpen = true
} | [
"func",
"(",
"r",
"*",
"Reader",
")",
"Open",
"(",
")",
"{",
"if",
"!",
"r",
".",
"enabled",
"{",
"return",
"\n",
"}",
"\n",
"r",
".",
"runMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"runMu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"r",
".",
"isOpen",
"{",
"return",
"\n",
"}",
"\n\n",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"r",
".",
"pool",
".",
"Open",
"(",
"r",
".",
"dbconfigs",
".",
"AppWithDB",
"(",
")",
",",
"r",
".",
"dbconfigs",
".",
"DbaWithDB",
"(",
")",
",",
"r",
".",
"dbconfigs",
".",
"AppDebugWithDB",
"(",
")",
")",
"\n",
"r",
".",
"ticks",
".",
"Start",
"(",
"func",
"(",
")",
"{",
"r",
".",
"readHeartbeat",
"(",
")",
"}",
")",
"\n",
"r",
".",
"isOpen",
"=",
"true",
"\n",
"}"
] | // Open starts the heartbeat ticker and opens the db pool. It may be called multiple
// times, as long as it was closed since last invocation. | [
"Open",
"starts",
"the",
"heartbeat",
"ticker",
"and",
"opens",
"the",
"db",
"pool",
".",
"It",
"may",
"be",
"called",
"multiple",
"times",
"as",
"long",
"as",
"it",
"was",
"closed",
"since",
"last",
"invocation",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/heartbeat/reader.go#L104-L118 | train |
vitessio/vitess | go/vt/vttablet/heartbeat/reader.go | Close | func (r *Reader) Close() {
if !r.enabled {
return
}
r.runMu.Lock()
defer r.runMu.Unlock()
if !r.isOpen {
return
}
r.ticks.Stop()
r.pool.Close()
log.Info("Stopped heartbeat reads")
r.isOpen = false
} | go | func (r *Reader) Close() {
if !r.enabled {
return
}
r.runMu.Lock()
defer r.runMu.Unlock()
if !r.isOpen {
return
}
r.ticks.Stop()
r.pool.Close()
log.Info("Stopped heartbeat reads")
r.isOpen = false
} | [
"func",
"(",
"r",
"*",
"Reader",
")",
"Close",
"(",
")",
"{",
"if",
"!",
"r",
".",
"enabled",
"{",
"return",
"\n",
"}",
"\n",
"r",
".",
"runMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"runMu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"r",
".",
"isOpen",
"{",
"return",
"\n",
"}",
"\n",
"r",
".",
"ticks",
".",
"Stop",
"(",
")",
"\n",
"r",
".",
"pool",
".",
"Close",
"(",
")",
"\n",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"r",
".",
"isOpen",
"=",
"false",
"\n",
"}"
] | // Close cancels the watchHeartbeat periodic ticker and closes the db pool.
// A reader object can be re-opened after closing. | [
"Close",
"cancels",
"the",
"watchHeartbeat",
"periodic",
"ticker",
"and",
"closes",
"the",
"db",
"pool",
".",
"A",
"reader",
"object",
"can",
"be",
"re",
"-",
"opened",
"after",
"closing",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/heartbeat/reader.go#L122-L135 | train |
vitessio/vitess | go/vt/vttablet/heartbeat/reader.go | fetchMostRecentHeartbeat | func (r *Reader) fetchMostRecentHeartbeat(ctx context.Context) (*sqltypes.Result, error) {
conn, err := r.pool.Get(ctx)
if err != nil {
return nil, err
}
defer conn.Recycle()
sel, err := r.bindHeartbeatFetch()
if err != nil {
return nil, err
}
return conn.Exec(ctx, sel, 1, false)
} | go | func (r *Reader) fetchMostRecentHeartbeat(ctx context.Context) (*sqltypes.Result, error) {
conn, err := r.pool.Get(ctx)
if err != nil {
return nil, err
}
defer conn.Recycle()
sel, err := r.bindHeartbeatFetch()
if err != nil {
return nil, err
}
return conn.Exec(ctx, sel, 1, false)
} | [
"func",
"(",
"r",
"*",
"Reader",
")",
"fetchMostRecentHeartbeat",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"sqltypes",
".",
"Result",
",",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"r",
".",
"pool",
".",
"Get",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"conn",
".",
"Recycle",
"(",
")",
"\n",
"sel",
",",
"err",
":=",
"r",
".",
"bindHeartbeatFetch",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"conn",
".",
"Exec",
"(",
"ctx",
",",
"sel",
",",
"1",
",",
"false",
")",
"\n",
"}"
] | // fetchMostRecentHeartbeat fetches the most recently recorded heartbeat from the heartbeat table,
// returning a result with the timestamp of the heartbeat. | [
"fetchMostRecentHeartbeat",
"fetches",
"the",
"most",
"recently",
"recorded",
"heartbeat",
"from",
"the",
"heartbeat",
"table",
"returning",
"a",
"result",
"with",
"the",
"timestamp",
"of",
"the",
"heartbeat",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/heartbeat/reader.go#L179-L190 | train |
vitessio/vitess | go/vt/vttablet/heartbeat/reader.go | bindHeartbeatFetch | func (r *Reader) bindHeartbeatFetch() (string, error) {
bindVars := map[string]*querypb.BindVariable{
"ks": sqltypes.StringBindVariable(r.keyspaceShard),
}
parsed := sqlparser.BuildParsedQuery(sqlFetchMostRecentHeartbeat, r.dbName, ":ks")
bound, err := parsed.GenerateQuery(bindVars, nil)
if err != nil {
return "", err
}
return bound, nil
} | go | func (r *Reader) bindHeartbeatFetch() (string, error) {
bindVars := map[string]*querypb.BindVariable{
"ks": sqltypes.StringBindVariable(r.keyspaceShard),
}
parsed := sqlparser.BuildParsedQuery(sqlFetchMostRecentHeartbeat, r.dbName, ":ks")
bound, err := parsed.GenerateQuery(bindVars, nil)
if err != nil {
return "", err
}
return bound, nil
} | [
"func",
"(",
"r",
"*",
"Reader",
")",
"bindHeartbeatFetch",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"bindVars",
":=",
"map",
"[",
"string",
"]",
"*",
"querypb",
".",
"BindVariable",
"{",
"\"",
"\"",
":",
"sqltypes",
".",
"StringBindVariable",
"(",
"r",
".",
"keyspaceShard",
")",
",",
"}",
"\n",
"parsed",
":=",
"sqlparser",
".",
"BuildParsedQuery",
"(",
"sqlFetchMostRecentHeartbeat",
",",
"r",
".",
"dbName",
",",
"\"",
"\"",
")",
"\n",
"bound",
",",
"err",
":=",
"parsed",
".",
"GenerateQuery",
"(",
"bindVars",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"bound",
",",
"nil",
"\n",
"}"
] | // bindHeartbeatFetch takes a heartbeat read and adds the necessary
// fields to the query as bind vars. This is done to protect ourselves
// against a badly formed keyspace or shard name. | [
"bindHeartbeatFetch",
"takes",
"a",
"heartbeat",
"read",
"and",
"adds",
"the",
"necessary",
"fields",
"to",
"the",
"query",
"as",
"bind",
"vars",
".",
"This",
"is",
"done",
"to",
"protect",
"ourselves",
"against",
"a",
"badly",
"formed",
"keyspace",
"or",
"shard",
"name",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/heartbeat/reader.go#L195-L205 | train |
vitessio/vitess | go/vt/vttablet/heartbeat/reader.go | parseHeartbeatResult | func parseHeartbeatResult(res *sqltypes.Result) (int64, error) {
if len(res.Rows) != 1 {
return 0, fmt.Errorf("failed to read heartbeat: writer query did not result in 1 row. Got %v", len(res.Rows))
}
ts, err := sqltypes.ToInt64(res.Rows[0][0])
if err != nil {
return 0, err
}
return ts, nil
} | go | func parseHeartbeatResult(res *sqltypes.Result) (int64, error) {
if len(res.Rows) != 1 {
return 0, fmt.Errorf("failed to read heartbeat: writer query did not result in 1 row. Got %v", len(res.Rows))
}
ts, err := sqltypes.ToInt64(res.Rows[0][0])
if err != nil {
return 0, err
}
return ts, nil
} | [
"func",
"parseHeartbeatResult",
"(",
"res",
"*",
"sqltypes",
".",
"Result",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"len",
"(",
"res",
".",
"Rows",
")",
"!=",
"1",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"res",
".",
"Rows",
")",
")",
"\n",
"}",
"\n",
"ts",
",",
"err",
":=",
"sqltypes",
".",
"ToInt64",
"(",
"res",
".",
"Rows",
"[",
"0",
"]",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"ts",
",",
"nil",
"\n",
"}"
] | // parseHeartbeatResult turns a raw result into the timestamp for processing. | [
"parseHeartbeatResult",
"turns",
"a",
"raw",
"result",
"into",
"the",
"timestamp",
"for",
"processing",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/heartbeat/reader.go#L208-L217 | train |
vitessio/vitess | go/vt/vttablet/heartbeat/reader.go | recordError | func (r *Reader) recordError(err error) {
r.lagMu.Lock()
r.lastKnownError = err
r.lagMu.Unlock()
r.errorLog.Errorf("%v", err)
readErrors.Add(1)
} | go | func (r *Reader) recordError(err error) {
r.lagMu.Lock()
r.lastKnownError = err
r.lagMu.Unlock()
r.errorLog.Errorf("%v", err)
readErrors.Add(1)
} | [
"func",
"(",
"r",
"*",
"Reader",
")",
"recordError",
"(",
"err",
"error",
")",
"{",
"r",
".",
"lagMu",
".",
"Lock",
"(",
")",
"\n",
"r",
".",
"lastKnownError",
"=",
"err",
"\n",
"r",
".",
"lagMu",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"errorLog",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"readErrors",
".",
"Add",
"(",
"1",
")",
"\n",
"}"
] | // recordError keeps track of the lastKnown error for reporting to the healthcheck.
// Errors tracked here are logged with throttling to cut down on log spam since
// operations can happen very frequently in this package. | [
"recordError",
"keeps",
"track",
"of",
"the",
"lastKnown",
"error",
"for",
"reporting",
"to",
"the",
"healthcheck",
".",
"Errors",
"tracked",
"here",
"are",
"logged",
"with",
"throttling",
"to",
"cut",
"down",
"on",
"log",
"spam",
"since",
"operations",
"can",
"happen",
"very",
"frequently",
"in",
"this",
"package",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vttablet/heartbeat/reader.go#L222-L228 | train |
vitessio/vitess | go/vt/servenv/rpc_utils.go | HandlePanic | func HandlePanic(component string, err *error) {
if x := recover(); x != nil {
// gRPC 0.13 chokes when you return a streaming error that contains newlines.
*err = fmt.Errorf("uncaught %v panic: %v, %s", component, x,
strings.Replace(string(tb.Stack(4)), "\n", ";", -1))
}
} | go | func HandlePanic(component string, err *error) {
if x := recover(); x != nil {
// gRPC 0.13 chokes when you return a streaming error that contains newlines.
*err = fmt.Errorf("uncaught %v panic: %v, %s", component, x,
strings.Replace(string(tb.Stack(4)), "\n", ";", -1))
}
} | [
"func",
"HandlePanic",
"(",
"component",
"string",
",",
"err",
"*",
"error",
")",
"{",
"if",
"x",
":=",
"recover",
"(",
")",
";",
"x",
"!=",
"nil",
"{",
"// gRPC 0.13 chokes when you return a streaming error that contains newlines.",
"*",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"component",
",",
"x",
",",
"strings",
".",
"Replace",
"(",
"string",
"(",
"tb",
".",
"Stack",
"(",
"4",
")",
")",
",",
"\"",
"\\n",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
")",
"\n",
"}",
"\n",
"}"
] | // HandlePanic should be called using 'defer' in the RPC code that executes the command. | [
"HandlePanic",
"should",
"be",
"called",
"using",
"defer",
"in",
"the",
"RPC",
"code",
"that",
"executes",
"the",
"command",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/servenv/rpc_utils.go#L27-L33 | train |
vitessio/vitess | go/vt/topo/consultopo/server.go | NewServer | func NewServer(cell, serverAddr, root string) (*Server, error) {
creds, err := getClientCreds()
if err != nil {
return nil, err
}
cfg := api.DefaultConfig()
cfg.Address = serverAddr
if creds != nil {
if creds[cell] != nil {
cfg.Token = creds[cell].ACLToken
} else {
log.Warningf("Client auth not configured for cell: %v", cell)
}
}
client, err := api.NewClient(cfg)
if err != nil {
return nil, err
}
return &Server{
client: client,
kv: client.KV(),
root: root,
locks: make(map[string]*lockInstance),
}, nil
} | go | func NewServer(cell, serverAddr, root string) (*Server, error) {
creds, err := getClientCreds()
if err != nil {
return nil, err
}
cfg := api.DefaultConfig()
cfg.Address = serverAddr
if creds != nil {
if creds[cell] != nil {
cfg.Token = creds[cell].ACLToken
} else {
log.Warningf("Client auth not configured for cell: %v", cell)
}
}
client, err := api.NewClient(cfg)
if err != nil {
return nil, err
}
return &Server{
client: client,
kv: client.KV(),
root: root,
locks: make(map[string]*lockInstance),
}, nil
} | [
"func",
"NewServer",
"(",
"cell",
",",
"serverAddr",
",",
"root",
"string",
")",
"(",
"*",
"Server",
",",
"error",
")",
"{",
"creds",
",",
"err",
":=",
"getClientCreds",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"cfg",
":=",
"api",
".",
"DefaultConfig",
"(",
")",
"\n",
"cfg",
".",
"Address",
"=",
"serverAddr",
"\n",
"if",
"creds",
"!=",
"nil",
"{",
"if",
"creds",
"[",
"cell",
"]",
"!=",
"nil",
"{",
"cfg",
".",
"Token",
"=",
"creds",
"[",
"cell",
"]",
".",
"ACLToken",
"\n",
"}",
"else",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"cell",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"client",
",",
"err",
":=",
"api",
".",
"NewClient",
"(",
"cfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"Server",
"{",
"client",
":",
"client",
",",
"kv",
":",
"client",
".",
"KV",
"(",
")",
",",
"root",
":",
"root",
",",
"locks",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"lockInstance",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewServer returns a new consultopo.Server. | [
"NewServer",
"returns",
"a",
"new",
"consultopo",
".",
"Server",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/consultopo/server.go#L107-L133 | train |
vitessio/vitess | go/vt/topo/consultopo/server.go | Close | func (s *Server) Close() {
s.client = nil
s.kv = nil
s.mu.Lock()
defer s.mu.Unlock()
s.locks = nil
} | go | func (s *Server) Close() {
s.client = nil
s.kv = nil
s.mu.Lock()
defer s.mu.Unlock()
s.locks = nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Close",
"(",
")",
"{",
"s",
".",
"client",
"=",
"nil",
"\n",
"s",
".",
"kv",
"=",
"nil",
"\n",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"s",
".",
"locks",
"=",
"nil",
"\n",
"}"
] | // Close implements topo.Server.Close.
// It will nil out the global and cells fields, so any attempt to
// re-use this server will panic. | [
"Close",
"implements",
"topo",
".",
"Server",
".",
"Close",
".",
"It",
"will",
"nil",
"out",
"the",
"global",
"and",
"cells",
"fields",
"so",
"any",
"attempt",
"to",
"re",
"-",
"use",
"this",
"server",
"will",
"panic",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/consultopo/server.go#L138-L144 | train |
vitessio/vitess | go/vt/vtgate/vindexes/vschema.go | MarshalJSON | func (ks *KeyspaceSchema) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
Sharded bool `json:"sharded,omitempty"`
Tables map[string]*Table `json:"tables,omitempty"`
Vindexes map[string]Vindex `json:"vindexes,omitempty"`
Error string `json:"error,omitempty"`
}{
Sharded: ks.Keyspace.Sharded,
Tables: ks.Tables,
Vindexes: ks.Vindexes,
Error: func(ks *KeyspaceSchema) string {
if ks.Error == nil {
return ""
}
return ks.Error.Error()
}(ks),
})
} | go | func (ks *KeyspaceSchema) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
Sharded bool `json:"sharded,omitempty"`
Tables map[string]*Table `json:"tables,omitempty"`
Vindexes map[string]Vindex `json:"vindexes,omitempty"`
Error string `json:"error,omitempty"`
}{
Sharded: ks.Keyspace.Sharded,
Tables: ks.Tables,
Vindexes: ks.Vindexes,
Error: func(ks *KeyspaceSchema) string {
if ks.Error == nil {
return ""
}
return ks.Error.Error()
}(ks),
})
} | [
"func",
"(",
"ks",
"*",
"KeyspaceSchema",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"struct",
"{",
"Sharded",
"bool",
"`json:\"sharded,omitempty\"`",
"\n",
"Tables",
"map",
"[",
"string",
"]",
"*",
"Table",
"`json:\"tables,omitempty\"`",
"\n",
"Vindexes",
"map",
"[",
"string",
"]",
"Vindex",
"`json:\"vindexes,omitempty\"`",
"\n",
"Error",
"string",
"`json:\"error,omitempty\"`",
"\n",
"}",
"{",
"Sharded",
":",
"ks",
".",
"Keyspace",
".",
"Sharded",
",",
"Tables",
":",
"ks",
".",
"Tables",
",",
"Vindexes",
":",
"ks",
".",
"Vindexes",
",",
"Error",
":",
"func",
"(",
"ks",
"*",
"KeyspaceSchema",
")",
"string",
"{",
"if",
"ks",
".",
"Error",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"ks",
".",
"Error",
".",
"Error",
"(",
")",
"\n",
"}",
"(",
"ks",
")",
",",
"}",
")",
"\n",
"}"
] | // MarshalJSON returns a JSON representation of KeyspaceSchema. | [
"MarshalJSON",
"returns",
"a",
"JSON",
"representation",
"of",
"KeyspaceSchema",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/vschema.go#L136-L153 | train |
vitessio/vitess | go/vt/vtgate/vindexes/vschema.go | BuildVSchema | func BuildVSchema(source *vschemapb.SrvVSchema) (vschema *VSchema, err error) {
vschema = &VSchema{
RoutingRules: make(map[string]*RoutingRule),
uniqueTables: make(map[string]*Table),
uniqueVindexes: make(map[string]Vindex),
Keyspaces: make(map[string]*KeyspaceSchema),
}
buildKeyspaces(source, vschema)
resolveAutoIncrement(source, vschema)
addDual(vschema)
buildRoutingRule(source, vschema)
return vschema, nil
} | go | func BuildVSchema(source *vschemapb.SrvVSchema) (vschema *VSchema, err error) {
vschema = &VSchema{
RoutingRules: make(map[string]*RoutingRule),
uniqueTables: make(map[string]*Table),
uniqueVindexes: make(map[string]Vindex),
Keyspaces: make(map[string]*KeyspaceSchema),
}
buildKeyspaces(source, vschema)
resolveAutoIncrement(source, vschema)
addDual(vschema)
buildRoutingRule(source, vschema)
return vschema, nil
} | [
"func",
"BuildVSchema",
"(",
"source",
"*",
"vschemapb",
".",
"SrvVSchema",
")",
"(",
"vschema",
"*",
"VSchema",
",",
"err",
"error",
")",
"{",
"vschema",
"=",
"&",
"VSchema",
"{",
"RoutingRules",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"RoutingRule",
")",
",",
"uniqueTables",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Table",
")",
",",
"uniqueVindexes",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"Vindex",
")",
",",
"Keyspaces",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"KeyspaceSchema",
")",
",",
"}",
"\n",
"buildKeyspaces",
"(",
"source",
",",
"vschema",
")",
"\n",
"resolveAutoIncrement",
"(",
"source",
",",
"vschema",
")",
"\n",
"addDual",
"(",
"vschema",
")",
"\n",
"buildRoutingRule",
"(",
"source",
",",
"vschema",
")",
"\n",
"return",
"vschema",
",",
"nil",
"\n",
"}"
] | // BuildVSchema builds a VSchema from a SrvVSchema. | [
"BuildVSchema",
"builds",
"a",
"VSchema",
"from",
"a",
"SrvVSchema",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/vschema.go#L162-L174 | train |
vitessio/vitess | go/vt/vtgate/vindexes/vschema.go | BuildKeyspaceSchema | func BuildKeyspaceSchema(input *vschemapb.Keyspace, keyspace string) (*KeyspaceSchema, error) {
if input == nil {
input = &vschemapb.Keyspace{}
}
formal := &vschemapb.SrvVSchema{
Keyspaces: map[string]*vschemapb.Keyspace{
keyspace: input,
},
}
vschema := &VSchema{
uniqueTables: make(map[string]*Table),
uniqueVindexes: make(map[string]Vindex),
Keyspaces: make(map[string]*KeyspaceSchema),
}
buildKeyspaces(formal, vschema)
err := vschema.Keyspaces[keyspace].Error
return vschema.Keyspaces[keyspace], err
} | go | func BuildKeyspaceSchema(input *vschemapb.Keyspace, keyspace string) (*KeyspaceSchema, error) {
if input == nil {
input = &vschemapb.Keyspace{}
}
formal := &vschemapb.SrvVSchema{
Keyspaces: map[string]*vschemapb.Keyspace{
keyspace: input,
},
}
vschema := &VSchema{
uniqueTables: make(map[string]*Table),
uniqueVindexes: make(map[string]Vindex),
Keyspaces: make(map[string]*KeyspaceSchema),
}
buildKeyspaces(formal, vschema)
err := vschema.Keyspaces[keyspace].Error
return vschema.Keyspaces[keyspace], err
} | [
"func",
"BuildKeyspaceSchema",
"(",
"input",
"*",
"vschemapb",
".",
"Keyspace",
",",
"keyspace",
"string",
")",
"(",
"*",
"KeyspaceSchema",
",",
"error",
")",
"{",
"if",
"input",
"==",
"nil",
"{",
"input",
"=",
"&",
"vschemapb",
".",
"Keyspace",
"{",
"}",
"\n",
"}",
"\n",
"formal",
":=",
"&",
"vschemapb",
".",
"SrvVSchema",
"{",
"Keyspaces",
":",
"map",
"[",
"string",
"]",
"*",
"vschemapb",
".",
"Keyspace",
"{",
"keyspace",
":",
"input",
",",
"}",
",",
"}",
"\n",
"vschema",
":=",
"&",
"VSchema",
"{",
"uniqueTables",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Table",
")",
",",
"uniqueVindexes",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"Vindex",
")",
",",
"Keyspaces",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"KeyspaceSchema",
")",
",",
"}",
"\n",
"buildKeyspaces",
"(",
"formal",
",",
"vschema",
")",
"\n",
"err",
":=",
"vschema",
".",
"Keyspaces",
"[",
"keyspace",
"]",
".",
"Error",
"\n",
"return",
"vschema",
".",
"Keyspaces",
"[",
"keyspace",
"]",
",",
"err",
"\n",
"}"
] | // BuildKeyspaceSchema builds the vschema portion for one keyspace.
// The build ignores sequence references because those dependencies can
// go cross-keyspace. | [
"BuildKeyspaceSchema",
"builds",
"the",
"vschema",
"portion",
"for",
"one",
"keyspace",
".",
"The",
"build",
"ignores",
"sequence",
"references",
"because",
"those",
"dependencies",
"can",
"go",
"cross",
"-",
"keyspace",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/vschema.go#L179-L196 | train |
vitessio/vitess | go/vt/vtgate/vindexes/vschema.go | addDual | func addDual(vschema *VSchema) {
first := ""
for ksname, ks := range vschema.Keyspaces {
t := &Table{
Name: sqlparser.NewTableIdent("dual"),
Keyspace: ks.Keyspace,
}
if ks.Keyspace.Sharded {
t.Pinned = []byte{0}
}
ks.Tables["dual"] = t
if first == "" || first > ksname {
// In case of a reference to dual that's not qualified
// by keyspace, we still want to resolve it to one of
// the keyspaces. For consistency, we'll always use the
// first keyspace by lexical ordering.
first = ksname
vschema.uniqueTables["dual"] = t
}
}
} | go | func addDual(vschema *VSchema) {
first := ""
for ksname, ks := range vschema.Keyspaces {
t := &Table{
Name: sqlparser.NewTableIdent("dual"),
Keyspace: ks.Keyspace,
}
if ks.Keyspace.Sharded {
t.Pinned = []byte{0}
}
ks.Tables["dual"] = t
if first == "" || first > ksname {
// In case of a reference to dual that's not qualified
// by keyspace, we still want to resolve it to one of
// the keyspaces. For consistency, we'll always use the
// first keyspace by lexical ordering.
first = ksname
vschema.uniqueTables["dual"] = t
}
}
} | [
"func",
"addDual",
"(",
"vschema",
"*",
"VSchema",
")",
"{",
"first",
":=",
"\"",
"\"",
"\n",
"for",
"ksname",
",",
"ks",
":=",
"range",
"vschema",
".",
"Keyspaces",
"{",
"t",
":=",
"&",
"Table",
"{",
"Name",
":",
"sqlparser",
".",
"NewTableIdent",
"(",
"\"",
"\"",
")",
",",
"Keyspace",
":",
"ks",
".",
"Keyspace",
",",
"}",
"\n",
"if",
"ks",
".",
"Keyspace",
".",
"Sharded",
"{",
"t",
".",
"Pinned",
"=",
"[",
"]",
"byte",
"{",
"0",
"}",
"\n",
"}",
"\n",
"ks",
".",
"Tables",
"[",
"\"",
"\"",
"]",
"=",
"t",
"\n",
"if",
"first",
"==",
"\"",
"\"",
"||",
"first",
">",
"ksname",
"{",
"// In case of a reference to dual that's not qualified",
"// by keyspace, we still want to resolve it to one of",
"// the keyspaces. For consistency, we'll always use the",
"// first keyspace by lexical ordering.",
"first",
"=",
"ksname",
"\n",
"vschema",
".",
"uniqueTables",
"[",
"\"",
"\"",
"]",
"=",
"t",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // addDual adds dual as a valid table to all keyspaces.
// For sharded keyspaces, it gets pinned against keyspace id '0x00'. | [
"addDual",
"adds",
"dual",
"as",
"a",
"valid",
"table",
"to",
"all",
"keyspaces",
".",
"For",
"sharded",
"keyspaces",
"it",
"gets",
"pinned",
"against",
"keyspace",
"id",
"0x00",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/vschema.go#L355-L375 | train |
vitessio/vitess | go/vt/vtgate/vindexes/vschema.go | findQualified | func (vschema *VSchema) findQualified(name string) (*Table, error) {
splits := strings.Split(name, ".")
switch len(splits) {
case 1:
return vschema.FindTable("", splits[0])
case 2:
return vschema.FindTable(splits[0], splits[1])
}
return nil, fmt.Errorf("table %s not found", name)
} | go | func (vschema *VSchema) findQualified(name string) (*Table, error) {
splits := strings.Split(name, ".")
switch len(splits) {
case 1:
return vschema.FindTable("", splits[0])
case 2:
return vschema.FindTable(splits[0], splits[1])
}
return nil, fmt.Errorf("table %s not found", name)
} | [
"func",
"(",
"vschema",
"*",
"VSchema",
")",
"findQualified",
"(",
"name",
"string",
")",
"(",
"*",
"Table",
",",
"error",
")",
"{",
"splits",
":=",
"strings",
".",
"Split",
"(",
"name",
",",
"\"",
"\"",
")",
"\n",
"switch",
"len",
"(",
"splits",
")",
"{",
"case",
"1",
":",
"return",
"vschema",
".",
"FindTable",
"(",
"\"",
"\"",
",",
"splits",
"[",
"0",
"]",
")",
"\n",
"case",
"2",
":",
"return",
"vschema",
".",
"FindTable",
"(",
"splits",
"[",
"0",
"]",
",",
"splits",
"[",
"1",
"]",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
] | // findQualified finds a table t or k.t. | [
"findQualified",
"finds",
"a",
"table",
"t",
"or",
"k",
".",
"t",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/vschema.go#L420-L429 | train |
vitessio/vitess | go/vt/vtgate/vindexes/vschema.go | findTable | func (vschema *VSchema) findTable(keyspace, tablename string) (*Table, error) {
if keyspace == "" {
table, ok := vschema.uniqueTables[tablename]
if table == nil {
if ok {
return nil, fmt.Errorf("ambiguous table reference: %s", tablename)
}
if len(vschema.Keyspaces) != 1 {
return nil, nil
}
// Loop happens only once.
for _, ks := range vschema.Keyspaces {
if ks.Keyspace.Sharded {
return nil, nil
}
return &Table{Name: sqlparser.NewTableIdent(tablename), Keyspace: ks.Keyspace}, nil
}
}
return table, nil
}
ks, ok := vschema.Keyspaces[keyspace]
if !ok {
return nil, fmt.Errorf("keyspace %s not found in vschema", keyspace)
}
table := ks.Tables[tablename]
if table == nil {
if ks.Keyspace.Sharded {
return nil, nil
}
return &Table{Name: sqlparser.NewTableIdent(tablename), Keyspace: ks.Keyspace}, nil
}
return table, nil
} | go | func (vschema *VSchema) findTable(keyspace, tablename string) (*Table, error) {
if keyspace == "" {
table, ok := vschema.uniqueTables[tablename]
if table == nil {
if ok {
return nil, fmt.Errorf("ambiguous table reference: %s", tablename)
}
if len(vschema.Keyspaces) != 1 {
return nil, nil
}
// Loop happens only once.
for _, ks := range vschema.Keyspaces {
if ks.Keyspace.Sharded {
return nil, nil
}
return &Table{Name: sqlparser.NewTableIdent(tablename), Keyspace: ks.Keyspace}, nil
}
}
return table, nil
}
ks, ok := vschema.Keyspaces[keyspace]
if !ok {
return nil, fmt.Errorf("keyspace %s not found in vschema", keyspace)
}
table := ks.Tables[tablename]
if table == nil {
if ks.Keyspace.Sharded {
return nil, nil
}
return &Table{Name: sqlparser.NewTableIdent(tablename), Keyspace: ks.Keyspace}, nil
}
return table, nil
} | [
"func",
"(",
"vschema",
"*",
"VSchema",
")",
"findTable",
"(",
"keyspace",
",",
"tablename",
"string",
")",
"(",
"*",
"Table",
",",
"error",
")",
"{",
"if",
"keyspace",
"==",
"\"",
"\"",
"{",
"table",
",",
"ok",
":=",
"vschema",
".",
"uniqueTables",
"[",
"tablename",
"]",
"\n",
"if",
"table",
"==",
"nil",
"{",
"if",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tablename",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"vschema",
".",
"Keyspaces",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"// Loop happens only once.",
"for",
"_",
",",
"ks",
":=",
"range",
"vschema",
".",
"Keyspaces",
"{",
"if",
"ks",
".",
"Keyspace",
".",
"Sharded",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"Table",
"{",
"Name",
":",
"sqlparser",
".",
"NewTableIdent",
"(",
"tablename",
")",
",",
"Keyspace",
":",
"ks",
".",
"Keyspace",
"}",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"table",
",",
"nil",
"\n",
"}",
"\n",
"ks",
",",
"ok",
":=",
"vschema",
".",
"Keyspaces",
"[",
"keyspace",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyspace",
")",
"\n",
"}",
"\n",
"table",
":=",
"ks",
".",
"Tables",
"[",
"tablename",
"]",
"\n",
"if",
"table",
"==",
"nil",
"{",
"if",
"ks",
".",
"Keyspace",
".",
"Sharded",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"Table",
"{",
"Name",
":",
"sqlparser",
".",
"NewTableIdent",
"(",
"tablename",
")",
",",
"Keyspace",
":",
"ks",
".",
"Keyspace",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"table",
",",
"nil",
"\n",
"}"
] | // findTable is like FindTable, but does not return an error if a table is not found. | [
"findTable",
"is",
"like",
"FindTable",
"but",
"does",
"not",
"return",
"an",
"error",
"if",
"a",
"table",
"is",
"not",
"found",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/vschema.go#L451-L483 | train |
vitessio/vitess | go/vt/vtgate/vindexes/vschema.go | FindTablesOrVindex | func (vschema *VSchema) FindTablesOrVindex(keyspace, name string, tabletType topodatapb.TabletType) ([]*Table, Vindex, error) {
tables, err := vschema.findTables(keyspace, name, tabletType)
if err != nil {
return nil, nil, err
}
if tables != nil {
return tables, nil, nil
}
v, err := vschema.FindVindex(keyspace, name)
if err != nil {
return nil, nil, err
}
if v != nil {
return nil, v, nil
}
return nil, nil, fmt.Errorf("table %s not found", name)
} | go | func (vschema *VSchema) FindTablesOrVindex(keyspace, name string, tabletType topodatapb.TabletType) ([]*Table, Vindex, error) {
tables, err := vschema.findTables(keyspace, name, tabletType)
if err != nil {
return nil, nil, err
}
if tables != nil {
return tables, nil, nil
}
v, err := vschema.FindVindex(keyspace, name)
if err != nil {
return nil, nil, err
}
if v != nil {
return nil, v, nil
}
return nil, nil, fmt.Errorf("table %s not found", name)
} | [
"func",
"(",
"vschema",
"*",
"VSchema",
")",
"FindTablesOrVindex",
"(",
"keyspace",
",",
"name",
"string",
",",
"tabletType",
"topodatapb",
".",
"TabletType",
")",
"(",
"[",
"]",
"*",
"Table",
",",
"Vindex",
",",
"error",
")",
"{",
"tables",
",",
"err",
":=",
"vschema",
".",
"findTables",
"(",
"keyspace",
",",
"name",
",",
"tabletType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"tables",
"!=",
"nil",
"{",
"return",
"tables",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"vschema",
".",
"FindVindex",
"(",
"keyspace",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"v",
"!=",
"nil",
"{",
"return",
"nil",
",",
"v",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
] | // FindTablesOrVindex finds a table or a Vindex by name using Find and FindVindex. | [
"FindTablesOrVindex",
"finds",
"a",
"table",
"or",
"a",
"Vindex",
"by",
"name",
"using",
"Find",
"and",
"FindVindex",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/vschema.go#L516-L532 | train |
vitessio/vitess | go/vt/vtgate/vindexes/vschema.go | FindVindex | func (vschema *VSchema) FindVindex(keyspace, name string) (Vindex, error) {
if keyspace == "" {
vindex, ok := vschema.uniqueVindexes[name]
if vindex == nil && ok {
return nil, fmt.Errorf("ambiguous vindex reference: %s", name)
}
return vindex, nil
}
ks, ok := vschema.Keyspaces[keyspace]
if !ok {
return nil, fmt.Errorf("keyspace %s not found in vschema", keyspace)
}
return ks.Vindexes[name], nil
} | go | func (vschema *VSchema) FindVindex(keyspace, name string) (Vindex, error) {
if keyspace == "" {
vindex, ok := vschema.uniqueVindexes[name]
if vindex == nil && ok {
return nil, fmt.Errorf("ambiguous vindex reference: %s", name)
}
return vindex, nil
}
ks, ok := vschema.Keyspaces[keyspace]
if !ok {
return nil, fmt.Errorf("keyspace %s not found in vschema", keyspace)
}
return ks.Vindexes[name], nil
} | [
"func",
"(",
"vschema",
"*",
"VSchema",
")",
"FindVindex",
"(",
"keyspace",
",",
"name",
"string",
")",
"(",
"Vindex",
",",
"error",
")",
"{",
"if",
"keyspace",
"==",
"\"",
"\"",
"{",
"vindex",
",",
"ok",
":=",
"vschema",
".",
"uniqueVindexes",
"[",
"name",
"]",
"\n",
"if",
"vindex",
"==",
"nil",
"&&",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"return",
"vindex",
",",
"nil",
"\n",
"}",
"\n",
"ks",
",",
"ok",
":=",
"vschema",
".",
"Keyspaces",
"[",
"keyspace",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyspace",
")",
"\n",
"}",
"\n",
"return",
"ks",
".",
"Vindexes",
"[",
"name",
"]",
",",
"nil",
"\n",
"}"
] | // FindVindex finds a vindex by name. If a keyspace is specified, only vindexes
// from that keyspace are searched. If no kesypace is specified, then a vindex
// is returned only if its name is unique across all keyspaces. The function
// returns an error only if the vindex name is ambiguous. | [
"FindVindex",
"finds",
"a",
"vindex",
"by",
"name",
".",
"If",
"a",
"keyspace",
"is",
"specified",
"only",
"vindexes",
"from",
"that",
"keyspace",
"are",
"searched",
".",
"If",
"no",
"kesypace",
"is",
"specified",
"then",
"a",
"vindex",
"is",
"returned",
"only",
"if",
"its",
"name",
"is",
"unique",
"across",
"all",
"keyspaces",
".",
"The",
"function",
"returns",
"an",
"error",
"only",
"if",
"the",
"vindex",
"name",
"is",
"ambiguous",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/vschema.go#L538-L551 | train |
vitessio/vitess | go/vt/vtgate/vindexes/vschema.go | LoadFormal | func LoadFormal(filename string) (*vschemapb.SrvVSchema, error) {
formal := &vschemapb.SrvVSchema{}
if filename == "" {
return formal, nil
}
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
err = json2.Unmarshal(data, formal)
if err != nil {
return nil, err
}
return formal, nil
} | go | func LoadFormal(filename string) (*vschemapb.SrvVSchema, error) {
formal := &vschemapb.SrvVSchema{}
if filename == "" {
return formal, nil
}
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
err = json2.Unmarshal(data, formal)
if err != nil {
return nil, err
}
return formal, nil
} | [
"func",
"LoadFormal",
"(",
"filename",
"string",
")",
"(",
"*",
"vschemapb",
".",
"SrvVSchema",
",",
"error",
")",
"{",
"formal",
":=",
"&",
"vschemapb",
".",
"SrvVSchema",
"{",
"}",
"\n",
"if",
"filename",
"==",
"\"",
"\"",
"{",
"return",
"formal",
",",
"nil",
"\n",
"}",
"\n",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"err",
"=",
"json2",
".",
"Unmarshal",
"(",
"data",
",",
"formal",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"formal",
",",
"nil",
"\n",
"}"
] | // LoadFormal loads the JSON representation of VSchema from a file. | [
"LoadFormal",
"loads",
"the",
"JSON",
"representation",
"of",
"VSchema",
"from",
"a",
"file",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/vschema.go#L568-L582 | train |
vitessio/vitess | go/vt/vtgate/vindexes/vschema.go | LoadFormalKeyspace | func LoadFormalKeyspace(filename string) (*vschemapb.Keyspace, error) {
formal := &vschemapb.Keyspace{}
if filename == "" {
return formal, nil
}
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
err = json2.Unmarshal(data, formal)
if err != nil {
return nil, err
}
return formal, nil
} | go | func LoadFormalKeyspace(filename string) (*vschemapb.Keyspace, error) {
formal := &vschemapb.Keyspace{}
if filename == "" {
return formal, nil
}
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
err = json2.Unmarshal(data, formal)
if err != nil {
return nil, err
}
return formal, nil
} | [
"func",
"LoadFormalKeyspace",
"(",
"filename",
"string",
")",
"(",
"*",
"vschemapb",
".",
"Keyspace",
",",
"error",
")",
"{",
"formal",
":=",
"&",
"vschemapb",
".",
"Keyspace",
"{",
"}",
"\n",
"if",
"filename",
"==",
"\"",
"\"",
"{",
"return",
"formal",
",",
"nil",
"\n",
"}",
"\n",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"err",
"=",
"json2",
".",
"Unmarshal",
"(",
"data",
",",
"formal",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"formal",
",",
"nil",
"\n",
"}"
] | // LoadFormalKeyspace loads the JSON representation of VSchema from a file,
// for a single keyspace. | [
"LoadFormalKeyspace",
"loads",
"the",
"JSON",
"representation",
"of",
"VSchema",
"from",
"a",
"file",
"for",
"a",
"single",
"keyspace",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/vschema.go#L586-L600 | train |
vitessio/vitess | go/vt/vtgate/vindexes/vschema.go | FindVindexForSharding | func FindVindexForSharding(tableName string, colVindexes []*ColumnVindex) (*ColumnVindex, error) {
if len(colVindexes) == 0 {
return nil, fmt.Errorf("no vindex definition for table %v", tableName)
}
result := colVindexes[0]
for _, colVindex := range colVindexes {
if colVindex.Vindex.Cost() < result.Vindex.Cost() && colVindex.Vindex.IsUnique() {
result = colVindex
}
}
if result.Vindex.Cost() > 1 || !result.Vindex.IsUnique() {
return nil, fmt.Errorf("could not find a vindex to use for sharding table %v", tableName)
}
return result, nil
} | go | func FindVindexForSharding(tableName string, colVindexes []*ColumnVindex) (*ColumnVindex, error) {
if len(colVindexes) == 0 {
return nil, fmt.Errorf("no vindex definition for table %v", tableName)
}
result := colVindexes[0]
for _, colVindex := range colVindexes {
if colVindex.Vindex.Cost() < result.Vindex.Cost() && colVindex.Vindex.IsUnique() {
result = colVindex
}
}
if result.Vindex.Cost() > 1 || !result.Vindex.IsUnique() {
return nil, fmt.Errorf("could not find a vindex to use for sharding table %v", tableName)
}
return result, nil
} | [
"func",
"FindVindexForSharding",
"(",
"tableName",
"string",
",",
"colVindexes",
"[",
"]",
"*",
"ColumnVindex",
")",
"(",
"*",
"ColumnVindex",
",",
"error",
")",
"{",
"if",
"len",
"(",
"colVindexes",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tableName",
")",
"\n",
"}",
"\n",
"result",
":=",
"colVindexes",
"[",
"0",
"]",
"\n",
"for",
"_",
",",
"colVindex",
":=",
"range",
"colVindexes",
"{",
"if",
"colVindex",
".",
"Vindex",
".",
"Cost",
"(",
")",
"<",
"result",
".",
"Vindex",
".",
"Cost",
"(",
")",
"&&",
"colVindex",
".",
"Vindex",
".",
"IsUnique",
"(",
")",
"{",
"result",
"=",
"colVindex",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"result",
".",
"Vindex",
".",
"Cost",
"(",
")",
">",
"1",
"||",
"!",
"result",
".",
"Vindex",
".",
"IsUnique",
"(",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tableName",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // FindVindexForSharding searches through the given slice
// to find the lowest cost unique vindex
// primary vindex is always unique
// if two have the same cost, use the one that occurs earlier in the definition
// if the final result is too expensive, return nil | [
"FindVindexForSharding",
"searches",
"through",
"the",
"given",
"slice",
"to",
"find",
"the",
"lowest",
"cost",
"unique",
"vindex",
"primary",
"vindex",
"is",
"always",
"unique",
"if",
"two",
"have",
"the",
"same",
"cost",
"use",
"the",
"one",
"that",
"occurs",
"earlier",
"in",
"the",
"definition",
"if",
"the",
"final",
"result",
"is",
"too",
"expensive",
"return",
"nil"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/vindexes/vschema.go#L607-L621 | train |
vitessio/vitess | go/cmd/vtclient/vtclient.go | merge | func (r *results) merge(other *results) {
if other == nil {
return
}
r.mu.Lock()
defer r.mu.Unlock()
r.rowsAffected += other.rowsAffected
if other.lastInsertID > r.lastInsertID {
r.lastInsertID = other.lastInsertID
}
r.cumulativeDuration += other.duration
} | go | func (r *results) merge(other *results) {
if other == nil {
return
}
r.mu.Lock()
defer r.mu.Unlock()
r.rowsAffected += other.rowsAffected
if other.lastInsertID > r.lastInsertID {
r.lastInsertID = other.lastInsertID
}
r.cumulativeDuration += other.duration
} | [
"func",
"(",
"r",
"*",
"results",
")",
"merge",
"(",
"other",
"*",
"results",
")",
"{",
"if",
"other",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"r",
".",
"rowsAffected",
"+=",
"other",
".",
"rowsAffected",
"\n",
"if",
"other",
".",
"lastInsertID",
">",
"r",
".",
"lastInsertID",
"{",
"r",
".",
"lastInsertID",
"=",
"other",
".",
"lastInsertID",
"\n",
"}",
"\n",
"r",
".",
"cumulativeDuration",
"+=",
"other",
".",
"duration",
"\n",
"}"
] | // merge aggregates "other" into "r".
// This is only used for executing DMLs concurrently and repeatedly.
// Therefore, "Fields" and "Rows" are not merged. | [
"merge",
"aggregates",
"other",
"into",
"r",
".",
"This",
"is",
"only",
"used",
"for",
"executing",
"DMLs",
"concurrently",
"and",
"repeatedly",
".",
"Therefore",
"Fields",
"and",
"Rows",
"are",
"not",
"merged",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/cmd/vtclient/vtclient.go#L317-L330 | train |
vitessio/vitess | go/vt/dbconfigs/credentials.go | GetCredentialsServer | func GetCredentialsServer() CredentialsServer {
cs, ok := AllCredentialsServers[*dbCredentialsServer]
if !ok {
log.Exitf("Invalid credential server: %v", *dbCredentialsServer)
}
return cs
} | go | func GetCredentialsServer() CredentialsServer {
cs, ok := AllCredentialsServers[*dbCredentialsServer]
if !ok {
log.Exitf("Invalid credential server: %v", *dbCredentialsServer)
}
return cs
} | [
"func",
"GetCredentialsServer",
"(",
")",
"CredentialsServer",
"{",
"cs",
",",
"ok",
":=",
"AllCredentialsServers",
"[",
"*",
"dbCredentialsServer",
"]",
"\n",
"if",
"!",
"ok",
"{",
"log",
".",
"Exitf",
"(",
"\"",
"\"",
",",
"*",
"dbCredentialsServer",
")",
"\n",
"}",
"\n",
"return",
"cs",
"\n",
"}"
] | // GetCredentialsServer returns the current CredentialsServer. Only valid
// after flag.Init was called. | [
"GetCredentialsServer",
"returns",
"the",
"current",
"CredentialsServer",
".",
"Only",
"valid",
"after",
"flag",
".",
"Init",
"was",
"called",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/dbconfigs/credentials.go#L67-L73 | train |
vitessio/vitess | go/vt/dbconfigs/credentials.go | GetUserAndPassword | func (fcs *FileCredentialsServer) GetUserAndPassword(user string) (string, string, error) {
fcs.mu.Lock()
defer fcs.mu.Unlock()
if *dbCredentialsFile == "" {
return "", "", ErrUnknownUser
}
// read the json file only once
if fcs.dbCredentials == nil {
fcs.dbCredentials = make(map[string][]string)
data, err := ioutil.ReadFile(*dbCredentialsFile)
if err != nil {
log.Warningf("Failed to read dbCredentials file: %v", *dbCredentialsFile)
return "", "", err
}
if err = json.Unmarshal(data, &fcs.dbCredentials); err != nil {
log.Warningf("Failed to parse dbCredentials file: %v", *dbCredentialsFile)
return "", "", err
}
}
passwd, ok := fcs.dbCredentials[user]
if !ok {
return "", "", ErrUnknownUser
}
return user, passwd[0], nil
} | go | func (fcs *FileCredentialsServer) GetUserAndPassword(user string) (string, string, error) {
fcs.mu.Lock()
defer fcs.mu.Unlock()
if *dbCredentialsFile == "" {
return "", "", ErrUnknownUser
}
// read the json file only once
if fcs.dbCredentials == nil {
fcs.dbCredentials = make(map[string][]string)
data, err := ioutil.ReadFile(*dbCredentialsFile)
if err != nil {
log.Warningf("Failed to read dbCredentials file: %v", *dbCredentialsFile)
return "", "", err
}
if err = json.Unmarshal(data, &fcs.dbCredentials); err != nil {
log.Warningf("Failed to parse dbCredentials file: %v", *dbCredentialsFile)
return "", "", err
}
}
passwd, ok := fcs.dbCredentials[user]
if !ok {
return "", "", ErrUnknownUser
}
return user, passwd[0], nil
} | [
"func",
"(",
"fcs",
"*",
"FileCredentialsServer",
")",
"GetUserAndPassword",
"(",
"user",
"string",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"fcs",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"fcs",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"*",
"dbCredentialsFile",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"ErrUnknownUser",
"\n",
"}",
"\n\n",
"// read the json file only once",
"if",
"fcs",
".",
"dbCredentials",
"==",
"nil",
"{",
"fcs",
".",
"dbCredentials",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"\n\n",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"*",
"dbCredentialsFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"*",
"dbCredentialsFile",
")",
"\n",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"fcs",
".",
"dbCredentials",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"*",
"dbCredentialsFile",
")",
"\n",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"passwd",
",",
"ok",
":=",
"fcs",
".",
"dbCredentials",
"[",
"user",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"ErrUnknownUser",
"\n",
"}",
"\n",
"return",
"user",
",",
"passwd",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] | // GetUserAndPassword is part of the CredentialsServer interface | [
"GetUserAndPassword",
"is",
"part",
"of",
"the",
"CredentialsServer",
"interface"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/dbconfigs/credentials.go#L83-L112 | train |
vitessio/vitess | go/vt/dbconfigs/credentials.go | WithCredentials | func WithCredentials(cp *mysql.ConnParams) (*mysql.ConnParams, error) {
result := *cp
user, passwd, err := GetCredentialsServer().GetUserAndPassword(cp.Uname)
switch err {
case nil:
result.Uname = user
result.Pass = passwd
case ErrUnknownUser:
// we just use what we have, and will fail later anyway
err = nil
}
return &result, err
} | go | func WithCredentials(cp *mysql.ConnParams) (*mysql.ConnParams, error) {
result := *cp
user, passwd, err := GetCredentialsServer().GetUserAndPassword(cp.Uname)
switch err {
case nil:
result.Uname = user
result.Pass = passwd
case ErrUnknownUser:
// we just use what we have, and will fail later anyway
err = nil
}
return &result, err
} | [
"func",
"WithCredentials",
"(",
"cp",
"*",
"mysql",
".",
"ConnParams",
")",
"(",
"*",
"mysql",
".",
"ConnParams",
",",
"error",
")",
"{",
"result",
":=",
"*",
"cp",
"\n",
"user",
",",
"passwd",
",",
"err",
":=",
"GetCredentialsServer",
"(",
")",
".",
"GetUserAndPassword",
"(",
"cp",
".",
"Uname",
")",
"\n",
"switch",
"err",
"{",
"case",
"nil",
":",
"result",
".",
"Uname",
"=",
"user",
"\n",
"result",
".",
"Pass",
"=",
"passwd",
"\n",
"case",
"ErrUnknownUser",
":",
"// we just use what we have, and will fail later anyway",
"err",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"result",
",",
"err",
"\n",
"}"
] | // WithCredentials returns a copy of the provided ConnParams that we can use
// to connect, after going through the CredentialsServer. | [
"WithCredentials",
"returns",
"a",
"copy",
"of",
"the",
"provided",
"ConnParams",
"that",
"we",
"can",
"use",
"to",
"connect",
"after",
"going",
"through",
"the",
"CredentialsServer",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/dbconfigs/credentials.go#L116-L128 | train |
vitessio/vitess | go/vt/topo/memorytopo/file.go | Create | func (c *Conn) Create(ctx context.Context, filePath string, contents []byte) (topo.Version, error) {
if contents == nil {
contents = []byte{}
}
c.factory.mu.Lock()
defer c.factory.mu.Unlock()
if c.factory.err != nil {
return nil, c.factory.err
}
// Get the parent dir.
dir, file := path.Split(filePath)
p := c.factory.getOrCreatePath(c.cell, dir)
if p == nil {
return nil, vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "trying to create file %v in cell %v in a path that contains files", filePath, c.cell)
}
// Check the file doesn't already exist.
if _, ok := p.children[file]; ok {
return nil, topo.NewError(topo.NodeExists, file)
}
// Create the file.
n := c.factory.newFile(file, contents, p)
p.children[file] = n
return NodeVersion(n.version), nil
} | go | func (c *Conn) Create(ctx context.Context, filePath string, contents []byte) (topo.Version, error) {
if contents == nil {
contents = []byte{}
}
c.factory.mu.Lock()
defer c.factory.mu.Unlock()
if c.factory.err != nil {
return nil, c.factory.err
}
// Get the parent dir.
dir, file := path.Split(filePath)
p := c.factory.getOrCreatePath(c.cell, dir)
if p == nil {
return nil, vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "trying to create file %v in cell %v in a path that contains files", filePath, c.cell)
}
// Check the file doesn't already exist.
if _, ok := p.children[file]; ok {
return nil, topo.NewError(topo.NodeExists, file)
}
// Create the file.
n := c.factory.newFile(file, contents, p)
p.children[file] = n
return NodeVersion(n.version), nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"filePath",
"string",
",",
"contents",
"[",
"]",
"byte",
")",
"(",
"topo",
".",
"Version",
",",
"error",
")",
"{",
"if",
"contents",
"==",
"nil",
"{",
"contents",
"=",
"[",
"]",
"byte",
"{",
"}",
"\n",
"}",
"\n\n",
"c",
".",
"factory",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"factory",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"c",
".",
"factory",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"c",
".",
"factory",
".",
"err",
"\n",
"}",
"\n\n",
"// Get the parent dir.",
"dir",
",",
"file",
":=",
"path",
".",
"Split",
"(",
"filePath",
")",
"\n",
"p",
":=",
"c",
".",
"factory",
".",
"getOrCreatePath",
"(",
"c",
".",
"cell",
",",
"dir",
")",
"\n",
"if",
"p",
"==",
"nil",
"{",
"return",
"nil",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_INVALID_ARGUMENT",
",",
"\"",
"\"",
",",
"filePath",
",",
"c",
".",
"cell",
")",
"\n",
"}",
"\n\n",
"// Check the file doesn't already exist.",
"if",
"_",
",",
"ok",
":=",
"p",
".",
"children",
"[",
"file",
"]",
";",
"ok",
"{",
"return",
"nil",
",",
"topo",
".",
"NewError",
"(",
"topo",
".",
"NodeExists",
",",
"file",
")",
"\n",
"}",
"\n\n",
"// Create the file.",
"n",
":=",
"c",
".",
"factory",
".",
"newFile",
"(",
"file",
",",
"contents",
",",
"p",
")",
"\n",
"p",
".",
"children",
"[",
"file",
"]",
"=",
"n",
"\n",
"return",
"NodeVersion",
"(",
"n",
".",
"version",
")",
",",
"nil",
"\n",
"}"
] | // Create is part of topo.Conn interface. | [
"Create",
"is",
"part",
"of",
"topo",
".",
"Conn",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/memorytopo/file.go#L31-L59 | train |
vitessio/vitess | go/vt/topo/memorytopo/file.go | Update | func (c *Conn) Update(ctx context.Context, filePath string, contents []byte, version topo.Version) (topo.Version, error) {
if contents == nil {
contents = []byte{}
}
c.factory.mu.Lock()
defer c.factory.mu.Unlock()
if c.factory.err != nil {
return nil, c.factory.err
}
// Get the parent dir, we'll need it in case of creation.
dir, file := path.Split(filePath)
p := c.factory.nodeByPath(c.cell, dir)
if p == nil {
// Parent doesn't exist, let's create it if we need to.
if version != nil {
return nil, topo.NewError(topo.NoNode, filePath)
}
p = c.factory.getOrCreatePath(c.cell, dir)
if p == nil {
return nil, vterrors.Errorf(vtrpc.Code_FAILED_PRECONDITION, "trying to create file %v in cell %v in a path that contains files", filePath, c.cell)
}
}
// Get the existing file.
n, ok := p.children[file]
if !ok {
// File doesn't exist, see if we need to create it.
if version != nil {
return nil, topo.NewError(topo.NoNode, filePath)
}
n = c.factory.newFile(file, contents, p)
p.children[file] = n
return NodeVersion(n.version), nil
}
// Check if it's a directory.
if n.isDirectory() {
return nil, vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "Update(%v, %v) failed: it's a directory", c.cell, filePath)
}
// Check the version.
if version != nil && n.version != uint64(version.(NodeVersion)) {
return nil, topo.NewError(topo.BadVersion, filePath)
}
// Now we can update.
n.version = c.factory.getNextVersion()
n.contents = contents
// Call the watches
for _, w := range n.watches {
w <- &topo.WatchData{
Contents: n.contents,
Version: NodeVersion(n.version),
}
}
return NodeVersion(n.version), nil
} | go | func (c *Conn) Update(ctx context.Context, filePath string, contents []byte, version topo.Version) (topo.Version, error) {
if contents == nil {
contents = []byte{}
}
c.factory.mu.Lock()
defer c.factory.mu.Unlock()
if c.factory.err != nil {
return nil, c.factory.err
}
// Get the parent dir, we'll need it in case of creation.
dir, file := path.Split(filePath)
p := c.factory.nodeByPath(c.cell, dir)
if p == nil {
// Parent doesn't exist, let's create it if we need to.
if version != nil {
return nil, topo.NewError(topo.NoNode, filePath)
}
p = c.factory.getOrCreatePath(c.cell, dir)
if p == nil {
return nil, vterrors.Errorf(vtrpc.Code_FAILED_PRECONDITION, "trying to create file %v in cell %v in a path that contains files", filePath, c.cell)
}
}
// Get the existing file.
n, ok := p.children[file]
if !ok {
// File doesn't exist, see if we need to create it.
if version != nil {
return nil, topo.NewError(topo.NoNode, filePath)
}
n = c.factory.newFile(file, contents, p)
p.children[file] = n
return NodeVersion(n.version), nil
}
// Check if it's a directory.
if n.isDirectory() {
return nil, vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "Update(%v, %v) failed: it's a directory", c.cell, filePath)
}
// Check the version.
if version != nil && n.version != uint64(version.(NodeVersion)) {
return nil, topo.NewError(topo.BadVersion, filePath)
}
// Now we can update.
n.version = c.factory.getNextVersion()
n.contents = contents
// Call the watches
for _, w := range n.watches {
w <- &topo.WatchData{
Contents: n.contents,
Version: NodeVersion(n.version),
}
}
return NodeVersion(n.version), nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Update",
"(",
"ctx",
"context",
".",
"Context",
",",
"filePath",
"string",
",",
"contents",
"[",
"]",
"byte",
",",
"version",
"topo",
".",
"Version",
")",
"(",
"topo",
".",
"Version",
",",
"error",
")",
"{",
"if",
"contents",
"==",
"nil",
"{",
"contents",
"=",
"[",
"]",
"byte",
"{",
"}",
"\n",
"}",
"\n\n",
"c",
".",
"factory",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"factory",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"c",
".",
"factory",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"c",
".",
"factory",
".",
"err",
"\n",
"}",
"\n\n",
"// Get the parent dir, we'll need it in case of creation.",
"dir",
",",
"file",
":=",
"path",
".",
"Split",
"(",
"filePath",
")",
"\n",
"p",
":=",
"c",
".",
"factory",
".",
"nodeByPath",
"(",
"c",
".",
"cell",
",",
"dir",
")",
"\n",
"if",
"p",
"==",
"nil",
"{",
"// Parent doesn't exist, let's create it if we need to.",
"if",
"version",
"!=",
"nil",
"{",
"return",
"nil",
",",
"topo",
".",
"NewError",
"(",
"topo",
".",
"NoNode",
",",
"filePath",
")",
"\n",
"}",
"\n",
"p",
"=",
"c",
".",
"factory",
".",
"getOrCreatePath",
"(",
"c",
".",
"cell",
",",
"dir",
")",
"\n",
"if",
"p",
"==",
"nil",
"{",
"return",
"nil",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_FAILED_PRECONDITION",
",",
"\"",
"\"",
",",
"filePath",
",",
"c",
".",
"cell",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Get the existing file.",
"n",
",",
"ok",
":=",
"p",
".",
"children",
"[",
"file",
"]",
"\n",
"if",
"!",
"ok",
"{",
"// File doesn't exist, see if we need to create it.",
"if",
"version",
"!=",
"nil",
"{",
"return",
"nil",
",",
"topo",
".",
"NewError",
"(",
"topo",
".",
"NoNode",
",",
"filePath",
")",
"\n",
"}",
"\n",
"n",
"=",
"c",
".",
"factory",
".",
"newFile",
"(",
"file",
",",
"contents",
",",
"p",
")",
"\n",
"p",
".",
"children",
"[",
"file",
"]",
"=",
"n",
"\n",
"return",
"NodeVersion",
"(",
"n",
".",
"version",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"// Check if it's a directory.",
"if",
"n",
".",
"isDirectory",
"(",
")",
"{",
"return",
"nil",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_INVALID_ARGUMENT",
",",
"\"",
"\"",
",",
"c",
".",
"cell",
",",
"filePath",
")",
"\n",
"}",
"\n\n",
"// Check the version.",
"if",
"version",
"!=",
"nil",
"&&",
"n",
".",
"version",
"!=",
"uint64",
"(",
"version",
".",
"(",
"NodeVersion",
")",
")",
"{",
"return",
"nil",
",",
"topo",
".",
"NewError",
"(",
"topo",
".",
"BadVersion",
",",
"filePath",
")",
"\n",
"}",
"\n\n",
"// Now we can update.",
"n",
".",
"version",
"=",
"c",
".",
"factory",
".",
"getNextVersion",
"(",
")",
"\n",
"n",
".",
"contents",
"=",
"contents",
"\n\n",
"// Call the watches",
"for",
"_",
",",
"w",
":=",
"range",
"n",
".",
"watches",
"{",
"w",
"<-",
"&",
"topo",
".",
"WatchData",
"{",
"Contents",
":",
"n",
".",
"contents",
",",
"Version",
":",
"NodeVersion",
"(",
"n",
".",
"version",
")",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"NodeVersion",
"(",
"n",
".",
"version",
")",
",",
"nil",
"\n",
"}"
] | // Update is part of topo.Conn interface. | [
"Update",
"is",
"part",
"of",
"topo",
".",
"Conn",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/memorytopo/file.go#L62-L123 | train |
vitessio/vitess | go/vt/topo/memorytopo/file.go | Get | func (c *Conn) Get(ctx context.Context, filePath string) ([]byte, topo.Version, error) {
c.factory.mu.Lock()
defer c.factory.mu.Unlock()
if c.factory.err != nil {
return nil, nil, c.factory.err
}
// Get the node.
n := c.factory.nodeByPath(c.cell, filePath)
if n == nil {
return nil, nil, topo.NewError(topo.NoNode, filePath)
}
if n.contents == nil {
// it's a directory
return nil, nil, fmt.Errorf("cannot Get() directory %v in cell %v", filePath, c.cell)
}
return n.contents, NodeVersion(n.version), nil
} | go | func (c *Conn) Get(ctx context.Context, filePath string) ([]byte, topo.Version, error) {
c.factory.mu.Lock()
defer c.factory.mu.Unlock()
if c.factory.err != nil {
return nil, nil, c.factory.err
}
// Get the node.
n := c.factory.nodeByPath(c.cell, filePath)
if n == nil {
return nil, nil, topo.NewError(topo.NoNode, filePath)
}
if n.contents == nil {
// it's a directory
return nil, nil, fmt.Errorf("cannot Get() directory %v in cell %v", filePath, c.cell)
}
return n.contents, NodeVersion(n.version), nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"filePath",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"topo",
".",
"Version",
",",
"error",
")",
"{",
"c",
".",
"factory",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"factory",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"c",
".",
"factory",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"c",
".",
"factory",
".",
"err",
"\n",
"}",
"\n\n",
"// Get the node.",
"n",
":=",
"c",
".",
"factory",
".",
"nodeByPath",
"(",
"c",
".",
"cell",
",",
"filePath",
")",
"\n",
"if",
"n",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"topo",
".",
"NewError",
"(",
"topo",
".",
"NoNode",
",",
"filePath",
")",
"\n",
"}",
"\n",
"if",
"n",
".",
"contents",
"==",
"nil",
"{",
"// it's a directory",
"return",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"filePath",
",",
"c",
".",
"cell",
")",
"\n",
"}",
"\n",
"return",
"n",
".",
"contents",
",",
"NodeVersion",
"(",
"n",
".",
"version",
")",
",",
"nil",
"\n",
"}"
] | // Get is part of topo.Conn interface. | [
"Get",
"is",
"part",
"of",
"topo",
".",
"Conn",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/memorytopo/file.go#L126-L144 | train |
vitessio/vitess | go/vt/topo/memorytopo/file.go | Delete | func (c *Conn) Delete(ctx context.Context, filePath string, version topo.Version) error {
c.factory.mu.Lock()
defer c.factory.mu.Unlock()
if c.factory.err != nil {
return c.factory.err
}
// Get the parent dir.
dir, file := path.Split(filePath)
p := c.factory.nodeByPath(c.cell, dir)
if p == nil {
return topo.NewError(topo.NoNode, filePath)
}
// Get the existing file.
n, ok := p.children[file]
if !ok {
return topo.NewError(topo.NoNode, filePath)
}
// Check if it's a directory.
if n.isDirectory() {
//lint:ignore ST1005 Delete is a function name
return fmt.Errorf("Delete(%v, %v) failed: it's a directory", c.cell, filePath)
}
// Check the version.
if version != nil && n.version != uint64(version.(NodeVersion)) {
return topo.NewError(topo.BadVersion, filePath)
}
// Now we can delete.
c.factory.recursiveDelete(n)
// Call the watches
for _, w := range n.watches {
w <- &topo.WatchData{
Err: topo.NewError(topo.NoNode, filePath),
}
close(w)
}
return nil
} | go | func (c *Conn) Delete(ctx context.Context, filePath string, version topo.Version) error {
c.factory.mu.Lock()
defer c.factory.mu.Unlock()
if c.factory.err != nil {
return c.factory.err
}
// Get the parent dir.
dir, file := path.Split(filePath)
p := c.factory.nodeByPath(c.cell, dir)
if p == nil {
return topo.NewError(topo.NoNode, filePath)
}
// Get the existing file.
n, ok := p.children[file]
if !ok {
return topo.NewError(topo.NoNode, filePath)
}
// Check if it's a directory.
if n.isDirectory() {
//lint:ignore ST1005 Delete is a function name
return fmt.Errorf("Delete(%v, %v) failed: it's a directory", c.cell, filePath)
}
// Check the version.
if version != nil && n.version != uint64(version.(NodeVersion)) {
return topo.NewError(topo.BadVersion, filePath)
}
// Now we can delete.
c.factory.recursiveDelete(n)
// Call the watches
for _, w := range n.watches {
w <- &topo.WatchData{
Err: topo.NewError(topo.NoNode, filePath),
}
close(w)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Delete",
"(",
"ctx",
"context",
".",
"Context",
",",
"filePath",
"string",
",",
"version",
"topo",
".",
"Version",
")",
"error",
"{",
"c",
".",
"factory",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"factory",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"c",
".",
"factory",
".",
"err",
"!=",
"nil",
"{",
"return",
"c",
".",
"factory",
".",
"err",
"\n",
"}",
"\n\n",
"// Get the parent dir.",
"dir",
",",
"file",
":=",
"path",
".",
"Split",
"(",
"filePath",
")",
"\n",
"p",
":=",
"c",
".",
"factory",
".",
"nodeByPath",
"(",
"c",
".",
"cell",
",",
"dir",
")",
"\n",
"if",
"p",
"==",
"nil",
"{",
"return",
"topo",
".",
"NewError",
"(",
"topo",
".",
"NoNode",
",",
"filePath",
")",
"\n",
"}",
"\n\n",
"// Get the existing file.",
"n",
",",
"ok",
":=",
"p",
".",
"children",
"[",
"file",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"topo",
".",
"NewError",
"(",
"topo",
".",
"NoNode",
",",
"filePath",
")",
"\n",
"}",
"\n\n",
"// Check if it's a directory.",
"if",
"n",
".",
"isDirectory",
"(",
")",
"{",
"//lint:ignore ST1005 Delete is a function name",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"c",
".",
"cell",
",",
"filePath",
")",
"\n",
"}",
"\n\n",
"// Check the version.",
"if",
"version",
"!=",
"nil",
"&&",
"n",
".",
"version",
"!=",
"uint64",
"(",
"version",
".",
"(",
"NodeVersion",
")",
")",
"{",
"return",
"topo",
".",
"NewError",
"(",
"topo",
".",
"BadVersion",
",",
"filePath",
")",
"\n",
"}",
"\n\n",
"// Now we can delete.",
"c",
".",
"factory",
".",
"recursiveDelete",
"(",
"n",
")",
"\n\n",
"// Call the watches",
"for",
"_",
",",
"w",
":=",
"range",
"n",
".",
"watches",
"{",
"w",
"<-",
"&",
"topo",
".",
"WatchData",
"{",
"Err",
":",
"topo",
".",
"NewError",
"(",
"topo",
".",
"NoNode",
",",
"filePath",
")",
",",
"}",
"\n",
"close",
"(",
"w",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Delete is part of topo.Conn interface. | [
"Delete",
"is",
"part",
"of",
"topo",
".",
"Conn",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/topo/memorytopo/file.go#L147-L191 | train |
vitessio/vitess | go/mysql/flavor_mysql.go | masterGTIDSet | func (mysqlFlavor) masterGTIDSet(c *Conn) (GTIDSet, error) {
qr, err := c.ExecuteFetch("SELECT @@GLOBAL.gtid_executed", 1, false)
if err != nil {
return nil, err
}
if len(qr.Rows) != 1 || len(qr.Rows[0]) != 1 {
return nil, vterrors.Errorf(vtrpc.Code_INTERNAL, "unexpected result format for gtid_executed: %#v", qr)
}
return parseMysql56GTIDSet(qr.Rows[0][0].ToString())
} | go | func (mysqlFlavor) masterGTIDSet(c *Conn) (GTIDSet, error) {
qr, err := c.ExecuteFetch("SELECT @@GLOBAL.gtid_executed", 1, false)
if err != nil {
return nil, err
}
if len(qr.Rows) != 1 || len(qr.Rows[0]) != 1 {
return nil, vterrors.Errorf(vtrpc.Code_INTERNAL, "unexpected result format for gtid_executed: %#v", qr)
}
return parseMysql56GTIDSet(qr.Rows[0][0].ToString())
} | [
"func",
"(",
"mysqlFlavor",
")",
"masterGTIDSet",
"(",
"c",
"*",
"Conn",
")",
"(",
"GTIDSet",
",",
"error",
")",
"{",
"qr",
",",
"err",
":=",
"c",
".",
"ExecuteFetch",
"(",
"\"",
"\"",
",",
"1",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"qr",
".",
"Rows",
")",
"!=",
"1",
"||",
"len",
"(",
"qr",
".",
"Rows",
"[",
"0",
"]",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_INTERNAL",
",",
"\"",
"\"",
",",
"qr",
")",
"\n",
"}",
"\n",
"return",
"parseMysql56GTIDSet",
"(",
"qr",
".",
"Rows",
"[",
"0",
"]",
"[",
"0",
"]",
".",
"ToString",
"(",
")",
")",
"\n",
"}"
] | // masterGTIDSet is part of the Flavor interface. | [
"masterGTIDSet",
"is",
"part",
"of",
"the",
"Flavor",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/flavor_mysql.go#L33-L42 | train |
vitessio/vitess | go/mysql/flavor_mysql.go | status | func (mysqlFlavor) status(c *Conn) (SlaveStatus, error) {
qr, err := c.ExecuteFetch("SHOW SLAVE STATUS", 100, true /* wantfields */)
if err != nil {
return SlaveStatus{}, err
}
if len(qr.Rows) == 0 {
// The query returned no data, meaning the server
// is not configured as a slave.
return SlaveStatus{}, ErrNotSlave
}
resultMap, err := resultToMap(qr)
if err != nil {
return SlaveStatus{}, err
}
status := parseSlaveStatus(resultMap)
status.Position.GTIDSet, err = parseMysql56GTIDSet(resultMap["Executed_Gtid_Set"])
if err != nil {
return SlaveStatus{}, vterrors.Wrapf(err, "SlaveStatus can't parse MySQL 5.6 GTID (Executed_Gtid_Set: %#v)", resultMap["Executed_Gtid_Set"])
}
return status, nil
} | go | func (mysqlFlavor) status(c *Conn) (SlaveStatus, error) {
qr, err := c.ExecuteFetch("SHOW SLAVE STATUS", 100, true /* wantfields */)
if err != nil {
return SlaveStatus{}, err
}
if len(qr.Rows) == 0 {
// The query returned no data, meaning the server
// is not configured as a slave.
return SlaveStatus{}, ErrNotSlave
}
resultMap, err := resultToMap(qr)
if err != nil {
return SlaveStatus{}, err
}
status := parseSlaveStatus(resultMap)
status.Position.GTIDSet, err = parseMysql56GTIDSet(resultMap["Executed_Gtid_Set"])
if err != nil {
return SlaveStatus{}, vterrors.Wrapf(err, "SlaveStatus can't parse MySQL 5.6 GTID (Executed_Gtid_Set: %#v)", resultMap["Executed_Gtid_Set"])
}
return status, nil
} | [
"func",
"(",
"mysqlFlavor",
")",
"status",
"(",
"c",
"*",
"Conn",
")",
"(",
"SlaveStatus",
",",
"error",
")",
"{",
"qr",
",",
"err",
":=",
"c",
".",
"ExecuteFetch",
"(",
"\"",
"\"",
",",
"100",
",",
"true",
"/* wantfields */",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"SlaveStatus",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"qr",
".",
"Rows",
")",
"==",
"0",
"{",
"// The query returned no data, meaning the server",
"// is not configured as a slave.",
"return",
"SlaveStatus",
"{",
"}",
",",
"ErrNotSlave",
"\n",
"}",
"\n\n",
"resultMap",
",",
"err",
":=",
"resultToMap",
"(",
"qr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"SlaveStatus",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"status",
":=",
"parseSlaveStatus",
"(",
"resultMap",
")",
"\n",
"status",
".",
"Position",
".",
"GTIDSet",
",",
"err",
"=",
"parseMysql56GTIDSet",
"(",
"resultMap",
"[",
"\"",
"\"",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"SlaveStatus",
"{",
"}",
",",
"vterrors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"resultMap",
"[",
"\"",
"\"",
"]",
")",
"\n",
"}",
"\n",
"return",
"status",
",",
"nil",
"\n",
"}"
] | // status is part of the Flavor interface. | [
"status",
"is",
"part",
"of",
"the",
"Flavor",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/flavor_mysql.go#L92-L114 | train |
vitessio/vitess | go/mysql/flavor_mysql.go | waitUntilPositionCommand | func (mysqlFlavor) waitUntilPositionCommand(ctx context.Context, pos Position) (string, error) {
// A timeout of 0 means wait indefinitely.
timeoutSeconds := 0
if deadline, ok := ctx.Deadline(); ok {
timeout := time.Until(deadline)
if timeout <= 0 {
return "", vterrors.Errorf(vtrpc.Code_DEADLINE_EXCEEDED, "timed out waiting for position %v", pos)
}
// Only whole numbers of seconds are supported.
timeoutSeconds = int(timeout.Seconds())
if timeoutSeconds == 0 {
// We don't want a timeout <1.0s to truncate down to become infinite.
timeoutSeconds = 1
}
}
return fmt.Sprintf("SELECT WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS('%s', %v)", pos, timeoutSeconds), nil
} | go | func (mysqlFlavor) waitUntilPositionCommand(ctx context.Context, pos Position) (string, error) {
// A timeout of 0 means wait indefinitely.
timeoutSeconds := 0
if deadline, ok := ctx.Deadline(); ok {
timeout := time.Until(deadline)
if timeout <= 0 {
return "", vterrors.Errorf(vtrpc.Code_DEADLINE_EXCEEDED, "timed out waiting for position %v", pos)
}
// Only whole numbers of seconds are supported.
timeoutSeconds = int(timeout.Seconds())
if timeoutSeconds == 0 {
// We don't want a timeout <1.0s to truncate down to become infinite.
timeoutSeconds = 1
}
}
return fmt.Sprintf("SELECT WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS('%s', %v)", pos, timeoutSeconds), nil
} | [
"func",
"(",
"mysqlFlavor",
")",
"waitUntilPositionCommand",
"(",
"ctx",
"context",
".",
"Context",
",",
"pos",
"Position",
")",
"(",
"string",
",",
"error",
")",
"{",
"// A timeout of 0 means wait indefinitely.",
"timeoutSeconds",
":=",
"0",
"\n",
"if",
"deadline",
",",
"ok",
":=",
"ctx",
".",
"Deadline",
"(",
")",
";",
"ok",
"{",
"timeout",
":=",
"time",
".",
"Until",
"(",
"deadline",
")",
"\n",
"if",
"timeout",
"<=",
"0",
"{",
"return",
"\"",
"\"",
",",
"vterrors",
".",
"Errorf",
"(",
"vtrpc",
".",
"Code_DEADLINE_EXCEEDED",
",",
"\"",
"\"",
",",
"pos",
")",
"\n",
"}",
"\n\n",
"// Only whole numbers of seconds are supported.",
"timeoutSeconds",
"=",
"int",
"(",
"timeout",
".",
"Seconds",
"(",
")",
")",
"\n",
"if",
"timeoutSeconds",
"==",
"0",
"{",
"// We don't want a timeout <1.0s to truncate down to become infinite.",
"timeoutSeconds",
"=",
"1",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pos",
",",
"timeoutSeconds",
")",
",",
"nil",
"\n",
"}"
] | // waitUntilPositionCommand is part of the Flavor interface. | [
"waitUntilPositionCommand",
"is",
"part",
"of",
"the",
"Flavor",
"interface",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/mysql/flavor_mysql.go#L117-L135 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.