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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
hashicorp/serf | cmd/serf/command/agent/agent.go | loadTagsFile | func (a *Agent) loadTagsFile(tagsFile string) error {
// Avoid passing tags and using a tags file at the same time
if len(a.agentConf.Tags) > 0 {
return fmt.Errorf("Tags config not allowed while using tag files")
}
if _, err := os.Stat(tagsFile); err == nil {
tagData, err := ioutil.ReadFile(tagsFile)
if err ... | go | func (a *Agent) loadTagsFile(tagsFile string) error {
// Avoid passing tags and using a tags file at the same time
if len(a.agentConf.Tags) > 0 {
return fmt.Errorf("Tags config not allowed while using tag files")
}
if _, err := os.Stat(tagsFile); err == nil {
tagData, err := ioutil.ReadFile(tagsFile)
if err ... | [
"func",
"(",
"a",
"*",
"Agent",
")",
"loadTagsFile",
"(",
"tagsFile",
"string",
")",
"error",
"{",
"// Avoid passing tags and using a tags file at the same time",
"if",
"len",
"(",
"a",
".",
"agentConf",
".",
"Tags",
")",
">",
"0",
"{",
"return",
"fmt",
".",
... | // loadTagsFile will load agent tags out of a file and set them in the
// current serf configuration. | [
"loadTagsFile",
"will",
"load",
"agent",
"tags",
"out",
"of",
"a",
"file",
"and",
"set",
"them",
"in",
"the",
"current",
"serf",
"configuration",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/agent.go#L308-L328 | train |
hashicorp/serf | cmd/serf/command/agent/agent.go | writeTagsFile | func (a *Agent) writeTagsFile(tags map[string]string) error {
encoded, err := json.MarshalIndent(tags, "", " ")
if err != nil {
return fmt.Errorf("Failed to encode tags: %s", err)
}
// Use 0600 for permissions, in case tag data is sensitive
if err = ioutil.WriteFile(a.agentConf.TagsFile, encoded, 0600); err !=... | go | func (a *Agent) writeTagsFile(tags map[string]string) error {
encoded, err := json.MarshalIndent(tags, "", " ")
if err != nil {
return fmt.Errorf("Failed to encode tags: %s", err)
}
// Use 0600 for permissions, in case tag data is sensitive
if err = ioutil.WriteFile(a.agentConf.TagsFile, encoded, 0600); err !=... | [
"func",
"(",
"a",
"*",
"Agent",
")",
"writeTagsFile",
"(",
"tags",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"encoded",
",",
"err",
":=",
"json",
".",
"MarshalIndent",
"(",
"tags",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
... | // writeTagsFile will write the current tags to the configured tags file. | [
"writeTagsFile",
"will",
"write",
"the",
"current",
"tags",
"to",
"the",
"configured",
"tags",
"file",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/agent.go#L331-L344 | train |
hashicorp/serf | cmd/serf/command/agent/agent.go | UnmarshalTags | func UnmarshalTags(tags []string) (map[string]string, error) {
result := make(map[string]string)
for _, tag := range tags {
parts := strings.SplitN(tag, "=", 2)
if len(parts) != 2 || len(parts[0]) == 0 {
return nil, fmt.Errorf("Invalid tag: '%s'", tag)
}
result[parts[0]] = parts[1]
}
return result, nil
} | go | func UnmarshalTags(tags []string) (map[string]string, error) {
result := make(map[string]string)
for _, tag := range tags {
parts := strings.SplitN(tag, "=", 2)
if len(parts) != 2 || len(parts[0]) == 0 {
return nil, fmt.Errorf("Invalid tag: '%s'", tag)
}
result[parts[0]] = parts[1]
}
return result, nil
} | [
"func",
"UnmarshalTags",
"(",
"tags",
"[",
"]",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"for",
"_",
",",
"tag",
":=",
"range",
"... | // UnmarshalTags is a utility function which takes a slice of strings in
// key=value format and returns them as a tag mapping. | [
"UnmarshalTags",
"is",
"a",
"utility",
"function",
"which",
"takes",
"a",
"slice",
"of",
"strings",
"in",
"key",
"=",
"value",
"format",
"and",
"returns",
"them",
"as",
"a",
"tag",
"mapping",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/agent.go#L358-L368 | train |
hashicorp/serf | cmd/serf/command/agent/agent.go | loadKeyringFile | func (a *Agent) loadKeyringFile(keyringFile string) error {
// Avoid passing an encryption key and a keyring file at the same time
if len(a.agentConf.EncryptKey) > 0 {
return fmt.Errorf("Encryption key not allowed while using a keyring")
}
if _, err := os.Stat(keyringFile); err != nil {
return err
}
// Read... | go | func (a *Agent) loadKeyringFile(keyringFile string) error {
// Avoid passing an encryption key and a keyring file at the same time
if len(a.agentConf.EncryptKey) > 0 {
return fmt.Errorf("Encryption key not allowed while using a keyring")
}
if _, err := os.Stat(keyringFile); err != nil {
return err
}
// Read... | [
"func",
"(",
"a",
"*",
"Agent",
")",
"loadKeyringFile",
"(",
"keyringFile",
"string",
")",
"error",
"{",
"// Avoid passing an encryption key and a keyring file at the same time",
"if",
"len",
"(",
"a",
".",
"agentConf",
".",
"EncryptKey",
")",
">",
"0",
"{",
"retu... | // loadKeyringFile will load a keyring out of a file | [
"loadKeyringFile",
"will",
"load",
"a",
"keyring",
"out",
"of",
"a",
"file"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/agent.go#L371-L419 | train |
hashicorp/serf | cmd/serf/command/agent/agent.go | Stats | func (a *Agent) Stats() map[string]map[string]string {
local := a.serf.LocalMember()
event_handlers := make(map[string]string)
// Convert event handlers from a string slice to a string map
for _, script := range a.agentConf.EventScripts() {
script_filter := fmt.Sprintf("%s:%s", script.EventFilter.Event, script.E... | go | func (a *Agent) Stats() map[string]map[string]string {
local := a.serf.LocalMember()
event_handlers := make(map[string]string)
// Convert event handlers from a string slice to a string map
for _, script := range a.agentConf.EventScripts() {
script_filter := fmt.Sprintf("%s:%s", script.EventFilter.Event, script.E... | [
"func",
"(",
"a",
"*",
"Agent",
")",
"Stats",
"(",
")",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"string",
"{",
"local",
":=",
"a",
".",
"serf",
".",
"LocalMember",
"(",
")",
"\n",
"event_handlers",
":=",
"make",
"(",
"map",
"[",
"st... | // Stats is used to get various runtime information and stats | [
"Stats",
"is",
"used",
"to",
"get",
"various",
"runtime",
"information",
"and",
"stats"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/agent.go#L422-L442 | train |
hashicorp/serf | serf/ping_delegate.go | AckPayload | func (p *pingDelegate) AckPayload() []byte {
var buf bytes.Buffer
// The first byte is the version number, forming a simple header.
version := []byte{PingVersion}
buf.Write(version)
// The rest of the message is the serialized coordinate.
enc := codec.NewEncoder(&buf, &codec.MsgpackHandle{})
if err := enc.Enco... | go | func (p *pingDelegate) AckPayload() []byte {
var buf bytes.Buffer
// The first byte is the version number, forming a simple header.
version := []byte{PingVersion}
buf.Write(version)
// The rest of the message is the serialized coordinate.
enc := codec.NewEncoder(&buf, &codec.MsgpackHandle{})
if err := enc.Enco... | [
"func",
"(",
"p",
"*",
"pingDelegate",
")",
"AckPayload",
"(",
")",
"[",
"]",
"byte",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n\n",
"// The first byte is the version number, forming a simple header.",
"version",
":=",
"[",
"]",
"byte",
"{",
"PingVersion",
"... | // AckPayload is called to produce a payload to send back in response to a ping
// request. | [
"AckPayload",
"is",
"called",
"to",
"produce",
"a",
"payload",
"to",
"send",
"back",
"in",
"response",
"to",
"a",
"ping",
"request",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/ping_delegate.go#L29-L42 | train |
hashicorp/serf | serf/ping_delegate.go | NotifyPingComplete | func (p *pingDelegate) NotifyPingComplete(other *memberlist.Node, rtt time.Duration, payload []byte) {
if payload == nil || len(payload) == 0 {
return
}
// Verify ping version in the header.
version := payload[0]
if version != PingVersion {
p.serf.logger.Printf("[ERR] serf: Unsupported ping version: %v", vers... | go | func (p *pingDelegate) NotifyPingComplete(other *memberlist.Node, rtt time.Duration, payload []byte) {
if payload == nil || len(payload) == 0 {
return
}
// Verify ping version in the header.
version := payload[0]
if version != PingVersion {
p.serf.logger.Printf("[ERR] serf: Unsupported ping version: %v", vers... | [
"func",
"(",
"p",
"*",
"pingDelegate",
")",
"NotifyPingComplete",
"(",
"other",
"*",
"memberlist",
".",
"Node",
",",
"rtt",
"time",
".",
"Duration",
",",
"payload",
"[",
"]",
"byte",
")",
"{",
"if",
"payload",
"==",
"nil",
"||",
"len",
"(",
"payload",
... | // NotifyPingComplete is called when this node successfully completes a direct ping
// of a peer node. | [
"NotifyPingComplete",
"is",
"called",
"when",
"this",
"node",
"successfully",
"completes",
"a",
"direct",
"ping",
"of",
"a",
"peer",
"node",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/ping_delegate.go#L46-L90 | train |
hashicorp/serf | cmd/serf/command/agent/ipc.go | RegisterQuery | func (c *IPCClient) RegisterQuery(q *serf.Query) uint64 {
// Generate a unique-per-client ID
id := c.nextQueryID()
// Ensure the query deadline is in the future
timeout := q.Deadline().Sub(time.Now())
if timeout < 0 {
return id
}
// Register the query
c.queryLock.Lock()
c.pendingQueries[id] = q
c.queryLoc... | go | func (c *IPCClient) RegisterQuery(q *serf.Query) uint64 {
// Generate a unique-per-client ID
id := c.nextQueryID()
// Ensure the query deadline is in the future
timeout := q.Deadline().Sub(time.Now())
if timeout < 0 {
return id
}
// Register the query
c.queryLock.Lock()
c.pendingQueries[id] = q
c.queryLoc... | [
"func",
"(",
"c",
"*",
"IPCClient",
")",
"RegisterQuery",
"(",
"q",
"*",
"serf",
".",
"Query",
")",
"uint64",
"{",
"// Generate a unique-per-client ID",
"id",
":=",
"c",
".",
"nextQueryID",
"(",
")",
"\n\n",
"// Ensure the query deadline is in the future",
"timeou... | // RegisterQuery is used to register a pending query that may
// get a response. The ID of the query is returned | [
"RegisterQuery",
"is",
"used",
"to",
"register",
"a",
"pending",
"query",
"that",
"may",
"get",
"a",
"response",
".",
"The",
"ID",
"of",
"the",
"query",
"is",
"returned"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/ipc.go#L303-L325 | train |
hashicorp/serf | cmd/serf/command/agent/ipc.go | NewAgentIPC | func NewAgentIPC(agent *Agent, authKey string, listener net.Listener,
logOutput io.Writer, logWriter *logWriter) *AgentIPC {
if logOutput == nil {
logOutput = os.Stderr
}
ipc := &AgentIPC{
agent: agent,
authKey: authKey,
clients: make(map[string]*IPCClient),
listener: listener,
logger: log.N... | go | func NewAgentIPC(agent *Agent, authKey string, listener net.Listener,
logOutput io.Writer, logWriter *logWriter) *AgentIPC {
if logOutput == nil {
logOutput = os.Stderr
}
ipc := &AgentIPC{
agent: agent,
authKey: authKey,
clients: make(map[string]*IPCClient),
listener: listener,
logger: log.N... | [
"func",
"NewAgentIPC",
"(",
"agent",
"*",
"Agent",
",",
"authKey",
"string",
",",
"listener",
"net",
".",
"Listener",
",",
"logOutput",
"io",
".",
"Writer",
",",
"logWriter",
"*",
"logWriter",
")",
"*",
"AgentIPC",
"{",
"if",
"logOutput",
"==",
"nil",
"{... | // NewAgentIPC is used to create a new Agent IPC handler | [
"NewAgentIPC",
"is",
"used",
"to",
"create",
"a",
"new",
"Agent",
"IPC",
"handler"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/ipc.go#L328-L344 | train |
hashicorp/serf | cmd/serf/command/agent/ipc.go | Shutdown | func (i *AgentIPC) Shutdown() {
i.Lock()
defer i.Unlock()
if i.stop {
return
}
i.stop = true
close(i.stopCh)
i.listener.Close()
// Close the existing connections
for _, client := range i.clients {
client.conn.Close()
}
} | go | func (i *AgentIPC) Shutdown() {
i.Lock()
defer i.Unlock()
if i.stop {
return
}
i.stop = true
close(i.stopCh)
i.listener.Close()
// Close the existing connections
for _, client := range i.clients {
client.conn.Close()
}
} | [
"func",
"(",
"i",
"*",
"AgentIPC",
")",
"Shutdown",
"(",
")",
"{",
"i",
".",
"Lock",
"(",
")",
"\n",
"defer",
"i",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"i",
".",
"stop",
"{",
"return",
"\n",
"}",
"\n\n",
"i",
".",
"stop",
"=",
"true",
"\n",... | // Shutdown is used to shutdown the IPC layer | [
"Shutdown",
"is",
"used",
"to",
"shutdown",
"the",
"IPC",
"layer"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/ipc.go#L347-L363 | train |
hashicorp/serf | cmd/serf/command/agent/ipc.go | listen | func (i *AgentIPC) listen() {
for {
conn, err := i.listener.Accept()
if err != nil {
if i.stop {
return
}
i.logger.Printf("[ERR] agent.ipc: Failed to accept client: %v", err)
continue
}
i.logger.Printf("[INFO] agent.ipc: Accepted client: %v", conn.RemoteAddr())
metrics.IncrCounter([]string{"a... | go | func (i *AgentIPC) listen() {
for {
conn, err := i.listener.Accept()
if err != nil {
if i.stop {
return
}
i.logger.Printf("[ERR] agent.ipc: Failed to accept client: %v", err)
continue
}
i.logger.Printf("[INFO] agent.ipc: Accepted client: %v", conn.RemoteAddr())
metrics.IncrCounter([]string{"a... | [
"func",
"(",
"i",
"*",
"AgentIPC",
")",
"listen",
"(",
")",
"{",
"for",
"{",
"conn",
",",
"err",
":=",
"i",
".",
"listener",
".",
"Accept",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"i",
".",
"stop",
"{",
"return",
"\n",
"}",
"\n",... | // listen is a long running routine that listens for new clients | [
"listen",
"is",
"a",
"long",
"running",
"routine",
"that",
"listens",
"for",
"new",
"clients"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/ipc.go#L366-L403 | train |
hashicorp/serf | cmd/serf/command/agent/ipc.go | deregisterClient | func (i *AgentIPC) deregisterClient(client *IPCClient) {
// Close the socket
client.conn.Close()
// Remove from the clients list
i.Lock()
delete(i.clients, client.name)
i.Unlock()
// Remove from the log writer
if client.logStreamer != nil {
i.logWriter.DeregisterHandler(client.logStreamer)
client.logStrea... | go | func (i *AgentIPC) deregisterClient(client *IPCClient) {
// Close the socket
client.conn.Close()
// Remove from the clients list
i.Lock()
delete(i.clients, client.name)
i.Unlock()
// Remove from the log writer
if client.logStreamer != nil {
i.logWriter.DeregisterHandler(client.logStreamer)
client.logStrea... | [
"func",
"(",
"i",
"*",
"AgentIPC",
")",
"deregisterClient",
"(",
"client",
"*",
"IPCClient",
")",
"{",
"// Close the socket",
"client",
".",
"conn",
".",
"Close",
"(",
")",
"\n\n",
"// Remove from the clients list",
"i",
".",
"Lock",
"(",
")",
"\n",
"delete"... | // deregisterClient is called to cleanup after a client disconnects | [
"deregisterClient",
"is",
"called",
"to",
"cleanup",
"after",
"a",
"client",
"disconnects"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/ipc.go#L406-L426 | train |
hashicorp/serf | cmd/serf/command/agent/ipc.go | handleClient | func (i *AgentIPC) handleClient(client *IPCClient) {
defer i.deregisterClient(client)
var reqHeader requestHeader
for {
// Decode the header
if err := client.dec.Decode(&reqHeader); err != nil {
if !i.stop {
// The second part of this if is to block socket
// errors from Windows which appear to happen... | go | func (i *AgentIPC) handleClient(client *IPCClient) {
defer i.deregisterClient(client)
var reqHeader requestHeader
for {
// Decode the header
if err := client.dec.Decode(&reqHeader); err != nil {
if !i.stop {
// The second part of this if is to block socket
// errors from Windows which appear to happen... | [
"func",
"(",
"i",
"*",
"AgentIPC",
")",
"handleClient",
"(",
"client",
"*",
"IPCClient",
")",
"{",
"defer",
"i",
".",
"deregisterClient",
"(",
"client",
")",
"\n",
"var",
"reqHeader",
"requestHeader",
"\n",
"for",
"{",
"// Decode the header",
"if",
"err",
... | // handleClient is a long running routine that handles a single client | [
"handleClient",
"is",
"a",
"long",
"running",
"routine",
"that",
"handles",
"a",
"single",
"client"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/ipc.go#L429-L452 | train |
hashicorp/serf | cmd/serf/command/agent/ipc.go | handleRequest | func (i *AgentIPC) handleRequest(client *IPCClient, reqHeader *requestHeader) error {
// Look for a command field
command := reqHeader.Command
seq := reqHeader.Seq
// Ensure the handshake is performed before other commands
if command != handshakeCommand && client.version == 0 {
respHeader := responseHeader{Seq:... | go | func (i *AgentIPC) handleRequest(client *IPCClient, reqHeader *requestHeader) error {
// Look for a command field
command := reqHeader.Command
seq := reqHeader.Seq
// Ensure the handshake is performed before other commands
if command != handshakeCommand && client.version == 0 {
respHeader := responseHeader{Seq:... | [
"func",
"(",
"i",
"*",
"AgentIPC",
")",
"handleRequest",
"(",
"client",
"*",
"IPCClient",
",",
"reqHeader",
"*",
"requestHeader",
")",
"error",
"{",
"// Look for a command field",
"command",
":=",
"reqHeader",
".",
"Command",
"\n",
"seq",
":=",
"reqHeader",
".... | // handleRequest is used to evaluate a single client command | [
"handleRequest",
"is",
"used",
"to",
"evaluate",
"a",
"single",
"client",
"command"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/ipc.go#L455-L540 | train |
hashicorp/serf | cmd/serf/command/agent/ipc.go | handleStats | func (i *AgentIPC) handleStats(client *IPCClient, seq uint64) error {
header := responseHeader{
Seq: seq,
Error: "",
}
resp := i.agent.Stats()
return client.Send(&header, resp)
} | go | func (i *AgentIPC) handleStats(client *IPCClient, seq uint64) error {
header := responseHeader{
Seq: seq,
Error: "",
}
resp := i.agent.Stats()
return client.Send(&header, resp)
} | [
"func",
"(",
"i",
"*",
"AgentIPC",
")",
"handleStats",
"(",
"client",
"*",
"IPCClient",
",",
"seq",
"uint64",
")",
"error",
"{",
"header",
":=",
"responseHeader",
"{",
"Seq",
":",
"seq",
",",
"Error",
":",
"\"",
"\"",
",",
"}",
"\n",
"resp",
":=",
... | // handleStats is used to get various statistics | [
"handleStats",
"is",
"used",
"to",
"get",
"various",
"statistics"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/ipc.go#L1030-L1037 | train |
hashicorp/serf | cmd/serf/command/agent/ipc.go | handleGetCoordinate | func (i *AgentIPC) handleGetCoordinate(client *IPCClient, seq uint64) error {
var req coordinateRequest
if err := client.dec.Decode(&req); err != nil {
return fmt.Errorf("decode failed: %v", err)
}
// Fetch the coordinate.
var result coordinate.Coordinate
coord, ok := i.agent.Serf().GetCachedCoordinate(req.Nod... | go | func (i *AgentIPC) handleGetCoordinate(client *IPCClient, seq uint64) error {
var req coordinateRequest
if err := client.dec.Decode(&req); err != nil {
return fmt.Errorf("decode failed: %v", err)
}
// Fetch the coordinate.
var result coordinate.Coordinate
coord, ok := i.agent.Serf().GetCachedCoordinate(req.Nod... | [
"func",
"(",
"i",
"*",
"AgentIPC",
")",
"handleGetCoordinate",
"(",
"client",
"*",
"IPCClient",
",",
"seq",
"uint64",
")",
"error",
"{",
"var",
"req",
"coordinateRequest",
"\n",
"if",
"err",
":=",
"client",
".",
"dec",
".",
"Decode",
"(",
"&",
"req",
"... | // handleGetCoordinate is used to get the cached coordinate for a node. | [
"handleGetCoordinate",
"is",
"used",
"to",
"get",
"the",
"cached",
"coordinate",
"for",
"a",
"node",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/ipc.go#L1040-L1063 | train |
hashicorp/serf | cmd/serf/command/agent/event_handler.go | UpdateScripts | func (h *ScriptEventHandler) UpdateScripts(scripts []EventScript) {
h.scriptLock.Lock()
defer h.scriptLock.Unlock()
h.newScripts = scripts
} | go | func (h *ScriptEventHandler) UpdateScripts(scripts []EventScript) {
h.scriptLock.Lock()
defer h.scriptLock.Unlock()
h.newScripts = scripts
} | [
"func",
"(",
"h",
"*",
"ScriptEventHandler",
")",
"UpdateScripts",
"(",
"scripts",
"[",
"]",
"EventScript",
")",
"{",
"h",
".",
"scriptLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"scriptLock",
".",
"Unlock",
"(",
")",
"\n",
"h",
".",
"newS... | // UpdateScripts is used to safely update the scripts we invoke in
// a thread safe manner | [
"UpdateScripts",
"is",
"used",
"to",
"safely",
"update",
"the",
"scripts",
"we",
"invoke",
"in",
"a",
"thread",
"safe",
"manner"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/event_handler.go#L57-L61 | train |
hashicorp/serf | cmd/serf/command/agent/event_handler.go | Invoke | func (s *EventFilter) Invoke(e serf.Event) bool {
if s.Event == "*" {
return true
}
if e.EventType().String() != s.Event {
return false
}
if s.Event == "user" && s.Name != "" {
userE, ok := e.(serf.UserEvent)
if !ok {
return false
}
if userE.Name != s.Name {
return false
}
}
if s.Event ==... | go | func (s *EventFilter) Invoke(e serf.Event) bool {
if s.Event == "*" {
return true
}
if e.EventType().String() != s.Event {
return false
}
if s.Event == "user" && s.Name != "" {
userE, ok := e.(serf.UserEvent)
if !ok {
return false
}
if userE.Name != s.Name {
return false
}
}
if s.Event ==... | [
"func",
"(",
"s",
"*",
"EventFilter",
")",
"Invoke",
"(",
"e",
"serf",
".",
"Event",
")",
"bool",
"{",
"if",
"s",
".",
"Event",
"==",
"\"",
"\"",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"if",
"e",
".",
"EventType",
"(",
")",
".",
"String",
"(... | // Invoke tests whether or not this event script should be invoked
// for the given Serf event. | [
"Invoke",
"tests",
"whether",
"or",
"not",
"this",
"event",
"script",
"should",
"be",
"invoked",
"for",
"the",
"given",
"Serf",
"event",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/event_handler.go#L71-L103 | train |
hashicorp/serf | cmd/serf/command/agent/event_handler.go | ParseEventScript | func ParseEventScript(v string) []EventScript {
var filter, script string
parts := strings.SplitN(v, "=", 2)
if len(parts) == 1 {
script = parts[0]
} else {
filter = parts[0]
script = parts[1]
}
filters := ParseEventFilter(filter)
results := make([]EventScript, 0, len(filters))
for _, filt := range filte... | go | func ParseEventScript(v string) []EventScript {
var filter, script string
parts := strings.SplitN(v, "=", 2)
if len(parts) == 1 {
script = parts[0]
} else {
filter = parts[0]
script = parts[1]
}
filters := ParseEventFilter(filter)
results := make([]EventScript, 0, len(filters))
for _, filt := range filte... | [
"func",
"ParseEventScript",
"(",
"v",
"string",
")",
"[",
"]",
"EventScript",
"{",
"var",
"filter",
",",
"script",
"string",
"\n",
"parts",
":=",
"strings",
".",
"SplitN",
"(",
"v",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"parts",
"... | // ParseEventScript takes a string in the format of "type=script" and
// parses it into an EventScript struct, if it can. | [
"ParseEventScript",
"takes",
"a",
"string",
"in",
"the",
"format",
"of",
"type",
"=",
"script",
"and",
"parses",
"it",
"into",
"an",
"EventScript",
"struct",
"if",
"it",
"can",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/event_handler.go#L139-L159 | train |
hashicorp/serf | cmd/serf/command/agent/event_handler.go | ParseEventFilter | func ParseEventFilter(v string) []EventFilter {
// No filter translates to stream all
if v == "" {
v = "*"
}
events := strings.Split(v, ",")
results := make([]EventFilter, 0, len(events))
for _, event := range events {
var result EventFilter
var name string
if strings.HasPrefix(event, "user:") {
name... | go | func ParseEventFilter(v string) []EventFilter {
// No filter translates to stream all
if v == "" {
v = "*"
}
events := strings.Split(v, ",")
results := make([]EventFilter, 0, len(events))
for _, event := range events {
var result EventFilter
var name string
if strings.HasPrefix(event, "user:") {
name... | [
"func",
"ParseEventFilter",
"(",
"v",
"string",
")",
"[",
"]",
"EventFilter",
"{",
"// No filter translates to stream all",
"if",
"v",
"==",
"\"",
"\"",
"{",
"v",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"events",
":=",
"strings",
".",
"Split",
"(",
"v",
",",... | // ParseEventFilter a string with the event type filters and
// parses it into a series of EventFilters if it can. | [
"ParseEventFilter",
"a",
"string",
"with",
"the",
"event",
"type",
"filters",
"and",
"parses",
"it",
"into",
"a",
"series",
"of",
"EventFilters",
"if",
"it",
"can",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/event_handler.go#L163-L189 | train |
hashicorp/serf | cmd/serf/command/rpc.go | RPCAddrFlag | func RPCAddrFlag(f *flag.FlagSet) *string {
defaultRpcAddr := os.Getenv("SERF_RPC_ADDR")
if defaultRpcAddr == "" {
defaultRpcAddr = "127.0.0.1:7373"
}
return f.String("rpc-addr", defaultRpcAddr,
"RPC address of the Serf agent")
} | go | func RPCAddrFlag(f *flag.FlagSet) *string {
defaultRpcAddr := os.Getenv("SERF_RPC_ADDR")
if defaultRpcAddr == "" {
defaultRpcAddr = "127.0.0.1:7373"
}
return f.String("rpc-addr", defaultRpcAddr,
"RPC address of the Serf agent")
} | [
"func",
"RPCAddrFlag",
"(",
"f",
"*",
"flag",
".",
"FlagSet",
")",
"*",
"string",
"{",
"defaultRpcAddr",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"if",
"defaultRpcAddr",
"==",
"\"",
"\"",
"{",
"defaultRpcAddr",
"=",
"\"",
"\"",
"\n",
"}... | // RPCAddrFlag returns a pointer to a string that will be populated
// when the given flagset is parsed with the RPC address of the Serf. | [
"RPCAddrFlag",
"returns",
"a",
"pointer",
"to",
"a",
"string",
"that",
"will",
"be",
"populated",
"when",
"the",
"given",
"flagset",
"is",
"parsed",
"with",
"the",
"RPC",
"address",
"of",
"the",
"Serf",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/rpc.go#L12-L20 | train |
hashicorp/serf | cmd/serf/command/rpc.go | RPCAuthFlag | func RPCAuthFlag(f *flag.FlagSet) *string {
rpcAuth := os.Getenv("SERF_RPC_AUTH")
return f.String("rpc-auth", rpcAuth,
"RPC auth token of the Serf agent")
} | go | func RPCAuthFlag(f *flag.FlagSet) *string {
rpcAuth := os.Getenv("SERF_RPC_AUTH")
return f.String("rpc-auth", rpcAuth,
"RPC auth token of the Serf agent")
} | [
"func",
"RPCAuthFlag",
"(",
"f",
"*",
"flag",
".",
"FlagSet",
")",
"*",
"string",
"{",
"rpcAuth",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"return",
"f",
".",
"String",
"(",
"\"",
"\"",
",",
"rpcAuth",
",",
"\"",
"\"",
")",
"\n",
... | // RPCAuthFlag returns a pointer to a string that will be populated
// when the given flagset is parsed with the RPC auth token of the Serf. | [
"RPCAuthFlag",
"returns",
"a",
"pointer",
"to",
"a",
"string",
"that",
"will",
"be",
"populated",
"when",
"the",
"given",
"flagset",
"is",
"parsed",
"with",
"the",
"RPC",
"auth",
"token",
"of",
"the",
"Serf",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/rpc.go#L24-L28 | train |
hashicorp/serf | cmd/serf/command/rpc.go | RPCClient | func RPCClient(addr, auth string) (*client.RPCClient, error) {
config := client.Config{Addr: addr, AuthKey: auth}
return client.ClientFromConfig(&config)
} | go | func RPCClient(addr, auth string) (*client.RPCClient, error) {
config := client.Config{Addr: addr, AuthKey: auth}
return client.ClientFromConfig(&config)
} | [
"func",
"RPCClient",
"(",
"addr",
",",
"auth",
"string",
")",
"(",
"*",
"client",
".",
"RPCClient",
",",
"error",
")",
"{",
"config",
":=",
"client",
".",
"Config",
"{",
"Addr",
":",
"addr",
",",
"AuthKey",
":",
"auth",
"}",
"\n",
"return",
"client",... | // RPCClient returns a new Serf RPC client with the given address. | [
"RPCClient",
"returns",
"a",
"new",
"Serf",
"RPC",
"client",
"with",
"the",
"given",
"address",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/rpc.go#L31-L34 | train |
hashicorp/serf | serf/keymanager.go | handleKeyRequest | func (k *KeyManager) handleKeyRequest(key, query string, opts *KeyRequestOptions) (*KeyResponse, error) {
resp := &KeyResponse{
Messages: make(map[string]string),
Keys: make(map[string]int),
}
qName := internalQueryName(query)
// Decode the new key into raw bytes
rawKey, err := base64.StdEncoding.DecodeSt... | go | func (k *KeyManager) handleKeyRequest(key, query string, opts *KeyRequestOptions) (*KeyResponse, error) {
resp := &KeyResponse{
Messages: make(map[string]string),
Keys: make(map[string]int),
}
qName := internalQueryName(query)
// Decode the new key into raw bytes
rawKey, err := base64.StdEncoding.DecodeSt... | [
"func",
"(",
"k",
"*",
"KeyManager",
")",
"handleKeyRequest",
"(",
"key",
",",
"query",
"string",
",",
"opts",
"*",
"KeyRequestOptions",
")",
"(",
"*",
"KeyResponse",
",",
"error",
")",
"{",
"resp",
":=",
"&",
"KeyResponse",
"{",
"Messages",
":",
"make",... | // handleKeyRequest performs query broadcasting to all members for any type of
// key operation and manages gathering responses and packing them up into a
// KeyResponse for uniform response handling. | [
"handleKeyRequest",
"performs",
"query",
"broadcasting",
"to",
"all",
"members",
"for",
"any",
"type",
"of",
"key",
"operation",
"and",
"manages",
"gathering",
"responses",
"and",
"packing",
"them",
"up",
"into",
"a",
"KeyResponse",
"for",
"uniform",
"response",
... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/keymanager.go#L98-L139 | train |
hashicorp/serf | serf/keymanager.go | InstallKey | func (k *KeyManager) InstallKey(key string) (*KeyResponse, error) {
return k.InstallKeyWithOptions(key, nil)
} | go | func (k *KeyManager) InstallKey(key string) (*KeyResponse, error) {
return k.InstallKeyWithOptions(key, nil)
} | [
"func",
"(",
"k",
"*",
"KeyManager",
")",
"InstallKey",
"(",
"key",
"string",
")",
"(",
"*",
"KeyResponse",
",",
"error",
")",
"{",
"return",
"k",
".",
"InstallKeyWithOptions",
"(",
"key",
",",
"nil",
")",
"\n",
"}"
] | // InstallKey handles broadcasting a query to all members and gathering
// responses from each of them, returning a list of messages from each node
// and any applicable error conditions. | [
"InstallKey",
"handles",
"broadcasting",
"a",
"query",
"to",
"all",
"members",
"and",
"gathering",
"responses",
"from",
"each",
"of",
"them",
"returning",
"a",
"list",
"of",
"messages",
"from",
"each",
"node",
"and",
"any",
"applicable",
"error",
"conditions",
... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/keymanager.go#L144-L146 | train |
hashicorp/serf | serf/keymanager.go | UseKey | func (k *KeyManager) UseKey(key string) (*KeyResponse, error) {
return k.UseKeyWithOptions(key, nil)
} | go | func (k *KeyManager) UseKey(key string) (*KeyResponse, error) {
return k.UseKeyWithOptions(key, nil)
} | [
"func",
"(",
"k",
"*",
"KeyManager",
")",
"UseKey",
"(",
"key",
"string",
")",
"(",
"*",
"KeyResponse",
",",
"error",
")",
"{",
"return",
"k",
".",
"UseKeyWithOptions",
"(",
"key",
",",
"nil",
")",
"\n",
"}"
] | // UseKey handles broadcasting a primary key change to all members in the
// cluster, and gathering any response messages. If successful, there should
// be an empty KeyResponse returned. | [
"UseKey",
"handles",
"broadcasting",
"a",
"primary",
"key",
"change",
"to",
"all",
"members",
"in",
"the",
"cluster",
"and",
"gathering",
"any",
"response",
"messages",
".",
"If",
"successful",
"there",
"should",
"be",
"an",
"empty",
"KeyResponse",
"returned",
... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/keymanager.go#L158-L160 | train |
hashicorp/serf | serf/keymanager.go | RemoveKey | func (k *KeyManager) RemoveKey(key string) (*KeyResponse, error) {
return k.RemoveKeyWithOptions(key, nil)
} | go | func (k *KeyManager) RemoveKey(key string) (*KeyResponse, error) {
return k.RemoveKeyWithOptions(key, nil)
} | [
"func",
"(",
"k",
"*",
"KeyManager",
")",
"RemoveKey",
"(",
"key",
"string",
")",
"(",
"*",
"KeyResponse",
",",
"error",
")",
"{",
"return",
"k",
".",
"RemoveKeyWithOptions",
"(",
"key",
",",
"nil",
")",
"\n",
"}"
] | // RemoveKey handles broadcasting a key to the cluster for removal. Each member
// will receive this event, and if they have the key in their keyring, remove
// it. If any errors are encountered, RemoveKey will collect and relay them. | [
"RemoveKey",
"handles",
"broadcasting",
"a",
"key",
"to",
"the",
"cluster",
"for",
"removal",
".",
"Each",
"member",
"will",
"receive",
"this",
"event",
"and",
"if",
"they",
"have",
"the",
"key",
"in",
"their",
"keyring",
"remove",
"it",
".",
"If",
"any",
... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/keymanager.go#L172-L174 | train |
hashicorp/serf | cmd/serf/command/agent/command.go | setupLoggers | func (c *Command) setupLoggers(config *Config) (*GatedWriter, *logWriter, io.Writer) {
// Setup logging. First create the gated log writer, which will
// store logs until we're ready to show them. Then create the level
// filter, filtering logs of the specified level.
logGate := &GatedWriter{
Writer: &cli.UiWrite... | go | func (c *Command) setupLoggers(config *Config) (*GatedWriter, *logWriter, io.Writer) {
// Setup logging. First create the gated log writer, which will
// store logs until we're ready to show them. Then create the level
// filter, filtering logs of the specified level.
logGate := &GatedWriter{
Writer: &cli.UiWrite... | [
"func",
"(",
"c",
"*",
"Command",
")",
"setupLoggers",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"GatedWriter",
",",
"*",
"logWriter",
",",
"io",
".",
"Writer",
")",
"{",
"// Setup logging. First create the gated log writer, which will",
"// store logs until we'r... | // setupLoggers is used to setup the logGate, logWriter, and our logOutput | [
"setupLoggers",
"is",
"used",
"to",
"setup",
"the",
"logGate",
"logWriter",
"and",
"our",
"logOutput"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/command.go#L362-L403 | train |
hashicorp/serf | cmd/serf/command/agent/command.go | retryJoin | func (c *Command) retryJoin(config *Config, agent *Agent, errCh chan struct{}) {
// Quit fast if there is no nodes to join
if len(config.RetryJoin) == 0 {
return
}
// Track the number of join attempts
attempt := 0
for {
// Try to perform the join
c.logger.Printf("[INFO] agent: Joining cluster...(replay: %v... | go | func (c *Command) retryJoin(config *Config, agent *Agent, errCh chan struct{}) {
// Quit fast if there is no nodes to join
if len(config.RetryJoin) == 0 {
return
}
// Track the number of join attempts
attempt := 0
for {
// Try to perform the join
c.logger.Printf("[INFO] agent: Joining cluster...(replay: %v... | [
"func",
"(",
"c",
"*",
"Command",
")",
"retryJoin",
"(",
"config",
"*",
"Config",
",",
"agent",
"*",
"Agent",
",",
"errCh",
"chan",
"struct",
"{",
"}",
")",
"{",
"// Quit fast if there is no nodes to join",
"if",
"len",
"(",
"config",
".",
"RetryJoin",
")"... | // retryJoin is invoked to handle joins with retries. This runs until at least a
// single successful join or RetryMaxAttempts is reached | [
"retryJoin",
"is",
"invoked",
"to",
"handle",
"joins",
"with",
"retries",
".",
"This",
"runs",
"until",
"at",
"least",
"a",
"single",
"successful",
"join",
"or",
"RetryMaxAttempts",
"is",
"reached"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/command.go#L494-L523 | train |
hashicorp/serf | cmd/serf/command/agent/config.go | DefaultConfig | func DefaultConfig() *Config {
return &Config{
DisableCoordinates: false,
Tags: make(map[string]string),
BindAddr: "0.0.0.0",
AdvertiseAddr: "",
LogLevel: "INFO",
RPCAddr: "127.0.0.1:7373",
Protocol: serf.ProtocolVers... | go | func DefaultConfig() *Config {
return &Config{
DisableCoordinates: false,
Tags: make(map[string]string),
BindAddr: "0.0.0.0",
AdvertiseAddr: "",
LogLevel: "INFO",
RPCAddr: "127.0.0.1:7373",
Protocol: serf.ProtocolVers... | [
"func",
"DefaultConfig",
"(",
")",
"*",
"Config",
"{",
"return",
"&",
"Config",
"{",
"DisableCoordinates",
":",
"false",
",",
"Tags",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
",",
"BindAddr",
":",
"\"",
"\"",
",",
"AdvertiseAddr",
":... | // DefaultConfig contains the defaults for configurations. | [
"DefaultConfig",
"contains",
"the",
"defaults",
"for",
"configurations",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/config.go#L23-L41 | train |
hashicorp/serf | cmd/serf/command/agent/config.go | AddrParts | func (c *Config) AddrParts(address string) (string, int, error) {
checkAddr := address
START:
_, _, err := net.SplitHostPort(checkAddr)
if ae, ok := err.(*net.AddrError); ok && ae.Err == "missing port in address" {
checkAddr = fmt.Sprintf("%s:%d", checkAddr, DefaultBindPort)
goto START
}
if err != nil {
ret... | go | func (c *Config) AddrParts(address string) (string, int, error) {
checkAddr := address
START:
_, _, err := net.SplitHostPort(checkAddr)
if ae, ok := err.(*net.AddrError); ok && ae.Err == "missing port in address" {
checkAddr = fmt.Sprintf("%s:%d", checkAddr, DefaultBindPort)
goto START
}
if err != nil {
ret... | [
"func",
"(",
"c",
"*",
"Config",
")",
"AddrParts",
"(",
"address",
"string",
")",
"(",
"string",
",",
"int",
",",
"error",
")",
"{",
"checkAddr",
":=",
"address",
"\n\n",
"START",
":",
"_",
",",
"_",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"... | // BindAddrParts returns the parts of the BindAddr that should be
// used to configure Serf. | [
"BindAddrParts",
"returns",
"the",
"parts",
"of",
"the",
"BindAddr",
"that",
"should",
"be",
"used",
"to",
"configure",
"Serf",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/config.go#L234-L254 | train |
hashicorp/serf | cmd/serf/command/agent/config.go | EventScripts | func (c *Config) EventScripts() []EventScript {
result := make([]EventScript, 0, len(c.EventHandlers))
for _, v := range c.EventHandlers {
part := ParseEventScript(v)
result = append(result, part...)
}
return result
} | go | func (c *Config) EventScripts() []EventScript {
result := make([]EventScript, 0, len(c.EventHandlers))
for _, v := range c.EventHandlers {
part := ParseEventScript(v)
result = append(result, part...)
}
return result
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"EventScripts",
"(",
")",
"[",
"]",
"EventScript",
"{",
"result",
":=",
"make",
"(",
"[",
"]",
"EventScript",
",",
"0",
",",
"len",
"(",
"c",
".",
"EventHandlers",
")",
")",
"\n",
"for",
"_",
",",
"v",
":=",
... | // EventScripts returns the list of EventScripts associated with this
// configuration and specified by the "event_handlers" configuration. | [
"EventScripts",
"returns",
"the",
"list",
"of",
"EventScripts",
"associated",
"with",
"this",
"configuration",
"and",
"specified",
"by",
"the",
"event_handlers",
"configuration",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/config.go#L263-L270 | train |
hashicorp/serf | cmd/serf/command/agent/config.go | NetworkInterface | func (c *Config) NetworkInterface() (*net.Interface, error) {
if c.Interface == "" {
return nil, nil
}
return net.InterfaceByName(c.Interface)
} | go | func (c *Config) NetworkInterface() (*net.Interface, error) {
if c.Interface == "" {
return nil, nil
}
return net.InterfaceByName(c.Interface)
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"NetworkInterface",
"(",
")",
"(",
"*",
"net",
".",
"Interface",
",",
"error",
")",
"{",
"if",
"c",
".",
"Interface",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"net",
".",... | // Networkinterface is used to get the associated network
// interface from the configured value | [
"Networkinterface",
"is",
"used",
"to",
"get",
"the",
"associated",
"network",
"interface",
"from",
"the",
"configured",
"value"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/config.go#L274-L279 | train |
hashicorp/serf | cmd/serf/command/agent/config.go | DecodeConfig | func DecodeConfig(r io.Reader) (*Config, error) {
var raw interface{}
dec := json.NewDecoder(r)
if err := dec.Decode(&raw); err != nil {
return nil, err
}
// Decode
var md mapstructure.Metadata
var result Config
msdec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Metadata: &md,
Result: ... | go | func DecodeConfig(r io.Reader) (*Config, error) {
var raw interface{}
dec := json.NewDecoder(r)
if err := dec.Decode(&raw); err != nil {
return nil, err
}
// Decode
var md mapstructure.Metadata
var result Config
msdec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Metadata: &md,
Result: ... | [
"func",
"DecodeConfig",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"var",
"raw",
"interface",
"{",
"}",
"\n",
"dec",
":=",
"json",
".",
"NewDecoder",
"(",
"r",
")",
"\n",
"if",
"err",
":=",
"dec",
".",
"Decode... | // DecodeConfig reads the configuration from the given reader in JSON
// format and decodes it into a proper Config structure. | [
"DecodeConfig",
"reads",
"the",
"configuration",
"from",
"the",
"given",
"reader",
"in",
"JSON",
"format",
"and",
"decodes",
"it",
"into",
"a",
"proper",
"Config",
"structure",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/config.go#L283-L348 | train |
hashicorp/serf | cmd/serf/command/agent/config.go | containsKey | func containsKey(keys []string, key string) bool {
for _, k := range keys {
if k == key {
return true
}
}
return false
} | go | func containsKey(keys []string, key string) bool {
for _, k := range keys {
if k == key {
return true
}
}
return false
} | [
"func",
"containsKey",
"(",
"keys",
"[",
"]",
"string",
",",
"key",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"k",
":=",
"range",
"keys",
"{",
"if",
"k",
"==",
"key",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
... | // containsKey is used to check if a slice of string keys contains
// another key | [
"containsKey",
"is",
"used",
"to",
"check",
"if",
"a",
"slice",
"of",
"string",
"keys",
"contains",
"another",
"key"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/config.go#L352-L359 | train |
hashicorp/serf | cmd/serf/command/agent/config.go | ReadConfigPaths | func ReadConfigPaths(paths []string) (*Config, error) {
result := new(Config)
for _, path := range paths {
f, err := os.Open(path)
if err != nil {
return nil, fmt.Errorf("Error reading '%s': %s", path, err)
}
fi, err := f.Stat()
if err != nil {
f.Close()
return nil, fmt.Errorf("Error reading '%s':... | go | func ReadConfigPaths(paths []string) (*Config, error) {
result := new(Config)
for _, path := range paths {
f, err := os.Open(path)
if err != nil {
return nil, fmt.Errorf("Error reading '%s': %s", path, err)
}
fi, err := f.Stat()
if err != nil {
f.Close()
return nil, fmt.Errorf("Error reading '%s':... | [
"func",
"ReadConfigPaths",
"(",
"paths",
"[",
"]",
"string",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"result",
":=",
"new",
"(",
"Config",
")",
"\n",
"for",
"_",
",",
"path",
":=",
"range",
"paths",
"{",
"f",
",",
"err",
":=",
"os",
".",... | // ReadConfigPaths reads the paths in the given order to load configurations.
// The paths can be to files or directories. If the path is a directory,
// we read one directory deep and read any files ending in ".json" as
// configuration files. | [
"ReadConfigPaths",
"reads",
"the",
"paths",
"in",
"the",
"given",
"order",
"to",
"load",
"configurations",
".",
"The",
"paths",
"can",
"be",
"to",
"files",
"or",
"directories",
".",
"If",
"the",
"path",
"is",
"a",
"directory",
"we",
"read",
"one",
"directo... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/config.go#L501-L565 | train |
hashicorp/serf | coordinate/phantom.go | GenerateClients | func GenerateClients(nodes int, config *Config) ([]*Client, error) {
clients := make([]*Client, nodes)
for i, _ := range clients {
client, err := NewClient(config)
if err != nil {
return nil, err
}
clients[i] = client
}
return clients, nil
} | go | func GenerateClients(nodes int, config *Config) ([]*Client, error) {
clients := make([]*Client, nodes)
for i, _ := range clients {
client, err := NewClient(config)
if err != nil {
return nil, err
}
clients[i] = client
}
return clients, nil
} | [
"func",
"GenerateClients",
"(",
"nodes",
"int",
",",
"config",
"*",
"Config",
")",
"(",
"[",
"]",
"*",
"Client",
",",
"error",
")",
"{",
"clients",
":=",
"make",
"(",
"[",
"]",
"*",
"Client",
",",
"nodes",
")",
"\n",
"for",
"i",
",",
"_",
":=",
... | // GenerateClients returns a slice with nodes number of clients, all with the
// given config. | [
"GenerateClients",
"returns",
"a",
"slice",
"with",
"nodes",
"number",
"of",
"clients",
"all",
"with",
"the",
"given",
"config",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/phantom.go#L12-L23 | train |
hashicorp/serf | coordinate/phantom.go | GenerateLine | func GenerateLine(nodes int, spacing time.Duration) [][]time.Duration {
truth := make([][]time.Duration, nodes)
for i := range truth {
truth[i] = make([]time.Duration, nodes)
}
for i := 0; i < nodes; i++ {
for j := i + 1; j < nodes; j++ {
rtt := time.Duration(j-i) * spacing
truth[i][j], truth[j][i] = rtt... | go | func GenerateLine(nodes int, spacing time.Duration) [][]time.Duration {
truth := make([][]time.Duration, nodes)
for i := range truth {
truth[i] = make([]time.Duration, nodes)
}
for i := 0; i < nodes; i++ {
for j := i + 1; j < nodes; j++ {
rtt := time.Duration(j-i) * spacing
truth[i][j], truth[j][i] = rtt... | [
"func",
"GenerateLine",
"(",
"nodes",
"int",
",",
"spacing",
"time",
".",
"Duration",
")",
"[",
"]",
"[",
"]",
"time",
".",
"Duration",
"{",
"truth",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"time",
".",
"Duration",
",",
"nodes",
")",
"\n",
"for",
... | // GenerateLine returns a truth matrix as if all the nodes are in a straight linke
// with the given spacing between them. | [
"GenerateLine",
"returns",
"a",
"truth",
"matrix",
"as",
"if",
"all",
"the",
"nodes",
"are",
"in",
"a",
"straight",
"linke",
"with",
"the",
"given",
"spacing",
"between",
"them",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/phantom.go#L27-L40 | train |
hashicorp/serf | coordinate/phantom.go | GenerateGrid | func GenerateGrid(nodes int, spacing time.Duration) [][]time.Duration {
truth := make([][]time.Duration, nodes)
for i := range truth {
truth[i] = make([]time.Duration, nodes)
}
n := int(math.Sqrt(float64(nodes)))
for i := 0; i < nodes; i++ {
for j := i + 1; j < nodes; j++ {
x1, y1 := float64(i%n), float64(... | go | func GenerateGrid(nodes int, spacing time.Duration) [][]time.Duration {
truth := make([][]time.Duration, nodes)
for i := range truth {
truth[i] = make([]time.Duration, nodes)
}
n := int(math.Sqrt(float64(nodes)))
for i := 0; i < nodes; i++ {
for j := i + 1; j < nodes; j++ {
x1, y1 := float64(i%n), float64(... | [
"func",
"GenerateGrid",
"(",
"nodes",
"int",
",",
"spacing",
"time",
".",
"Duration",
")",
"[",
"]",
"[",
"]",
"time",
".",
"Duration",
"{",
"truth",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"time",
".",
"Duration",
",",
"nodes",
")",
"\n",
"for",
... | // GenerateGrid returns a truth matrix as if all the nodes are in a two dimensional
// grid with the given spacing between them. | [
"GenerateGrid",
"returns",
"a",
"truth",
"matrix",
"as",
"if",
"all",
"the",
"nodes",
"are",
"in",
"a",
"two",
"dimensional",
"grid",
"with",
"the",
"given",
"spacing",
"between",
"them",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/phantom.go#L44-L62 | train |
hashicorp/serf | coordinate/phantom.go | GenerateSplit | func GenerateSplit(nodes int, lan time.Duration, wan time.Duration) [][]time.Duration {
truth := make([][]time.Duration, nodes)
for i := range truth {
truth[i] = make([]time.Duration, nodes)
}
split := nodes / 2
for i := 0; i < nodes; i++ {
for j := i + 1; j < nodes; j++ {
rtt := lan
if (i <= split && j... | go | func GenerateSplit(nodes int, lan time.Duration, wan time.Duration) [][]time.Duration {
truth := make([][]time.Duration, nodes)
for i := range truth {
truth[i] = make([]time.Duration, nodes)
}
split := nodes / 2
for i := 0; i < nodes; i++ {
for j := i + 1; j < nodes; j++ {
rtt := lan
if (i <= split && j... | [
"func",
"GenerateSplit",
"(",
"nodes",
"int",
",",
"lan",
"time",
".",
"Duration",
",",
"wan",
"time",
".",
"Duration",
")",
"[",
"]",
"[",
"]",
"time",
".",
"Duration",
"{",
"truth",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"time",
".",
"Duration",
... | // GenerateSplit returns a truth matrix as if half the nodes are close together in
// one location and half the nodes are close together in another. The lan factor
// is used to separate the nodes locally and the wan factor represents the split
// between the two sides. | [
"GenerateSplit",
"returns",
"a",
"truth",
"matrix",
"as",
"if",
"half",
"the",
"nodes",
"are",
"close",
"together",
"in",
"one",
"location",
"and",
"half",
"the",
"nodes",
"are",
"close",
"together",
"in",
"another",
".",
"The",
"lan",
"factor",
"is",
"use... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/phantom.go#L68-L85 | train |
hashicorp/serf | coordinate/phantom.go | GenerateCircle | func GenerateCircle(nodes int, radius time.Duration) [][]time.Duration {
truth := make([][]time.Duration, nodes)
for i := range truth {
truth[i] = make([]time.Duration, nodes)
}
for i := 0; i < nodes; i++ {
for j := i + 1; j < nodes; j++ {
var rtt time.Duration
if i == 0 {
rtt = 2 * radius
} else ... | go | func GenerateCircle(nodes int, radius time.Duration) [][]time.Duration {
truth := make([][]time.Duration, nodes)
for i := range truth {
truth[i] = make([]time.Duration, nodes)
}
for i := 0; i < nodes; i++ {
for j := i + 1; j < nodes; j++ {
var rtt time.Duration
if i == 0 {
rtt = 2 * radius
} else ... | [
"func",
"GenerateCircle",
"(",
"nodes",
"int",
",",
"radius",
"time",
".",
"Duration",
")",
"[",
"]",
"[",
"]",
"time",
".",
"Duration",
"{",
"truth",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"time",
".",
"Duration",
",",
"nodes",
")",
"\n",
"for",
... | // GenerateCircle returns a truth matrix for a set of nodes, evenly distributed
// around a circle with the given radius. The first node is at the "center" of the
// circle because it's equidistant from all the other nodes, but we place it at
// double the radius, so it should show up above all the other nodes in heigh... | [
"GenerateCircle",
"returns",
"a",
"truth",
"matrix",
"for",
"a",
"set",
"of",
"nodes",
"evenly",
"distributed",
"around",
"a",
"circle",
"with",
"the",
"given",
"radius",
".",
"The",
"first",
"node",
"is",
"at",
"the",
"center",
"of",
"the",
"circle",
"bec... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/phantom.go#L91-L115 | train |
hashicorp/serf | coordinate/phantom.go | GenerateRandom | func GenerateRandom(nodes int, mean time.Duration, deviation time.Duration) [][]time.Duration {
rand.Seed(1)
truth := make([][]time.Duration, nodes)
for i := range truth {
truth[i] = make([]time.Duration, nodes)
}
for i := 0; i < nodes; i++ {
for j := i + 1; j < nodes; j++ {
rttSeconds := rand.NormFloat64... | go | func GenerateRandom(nodes int, mean time.Duration, deviation time.Duration) [][]time.Duration {
rand.Seed(1)
truth := make([][]time.Duration, nodes)
for i := range truth {
truth[i] = make([]time.Duration, nodes)
}
for i := 0; i < nodes; i++ {
for j := i + 1; j < nodes; j++ {
rttSeconds := rand.NormFloat64... | [
"func",
"GenerateRandom",
"(",
"nodes",
"int",
",",
"mean",
"time",
".",
"Duration",
",",
"deviation",
"time",
".",
"Duration",
")",
"[",
"]",
"[",
"]",
"time",
".",
"Duration",
"{",
"rand",
".",
"Seed",
"(",
"1",
")",
"\n\n",
"truth",
":=",
"make",
... | // GenerateRandom returns a truth matrix for a set of nodes with normally
// distributed delays, with the given mean and deviation. The RNG is re-seeded
// so you always get the same matrix for a given size. | [
"GenerateRandom",
"returns",
"a",
"truth",
"matrix",
"for",
"a",
"set",
"of",
"nodes",
"with",
"normally",
"distributed",
"delays",
"with",
"the",
"given",
"mean",
"and",
"deviation",
".",
"The",
"RNG",
"is",
"re",
"-",
"seeded",
"so",
"you",
"always",
"ge... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/phantom.go#L120-L136 | train |
hashicorp/serf | coordinate/phantom.go | Evaluate | func Evaluate(clients []*Client, truth [][]time.Duration) (stats Stats) {
nodes := len(clients)
count := 0
for i := 0; i < nodes; i++ {
for j := i + 1; j < nodes; j++ {
est := clients[i].DistanceTo(clients[j].GetCoordinate()).Seconds()
actual := truth[i][j].Seconds()
error := math.Abs(est-actual) / actual... | go | func Evaluate(clients []*Client, truth [][]time.Duration) (stats Stats) {
nodes := len(clients)
count := 0
for i := 0; i < nodes; i++ {
for j := i + 1; j < nodes; j++ {
est := clients[i].DistanceTo(clients[j].GetCoordinate()).Seconds()
actual := truth[i][j].Seconds()
error := math.Abs(est-actual) / actual... | [
"func",
"Evaluate",
"(",
"clients",
"[",
"]",
"*",
"Client",
",",
"truth",
"[",
"]",
"[",
"]",
"time",
".",
"Duration",
")",
"(",
"stats",
"Stats",
")",
"{",
"nodes",
":=",
"len",
"(",
"clients",
")",
"\n",
"count",
":=",
"0",
"\n",
"for",
"i",
... | // Evaluate uses the coordinates of the given clients to calculate estimated
// distances and compares them with the given truth matrix, returning summary
// stats. | [
"Evaluate",
"uses",
"the",
"coordinates",
"of",
"the",
"given",
"clients",
"to",
"calculate",
"estimated",
"distances",
"and",
"compares",
"them",
"with",
"the",
"given",
"truth",
"matrix",
"returning",
"summary",
"stats",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/phantom.go#L170-L187 | train |
hashicorp/serf | serf/snapshot.go | NewSnapshotter | func NewSnapshotter(path string,
minCompactSize int,
rejoinAfterLeave bool,
logger *log.Logger,
clock *LamportClock,
outCh chan<- Event,
shutdownCh <-chan struct{}) (chan<- Event, *Snapshotter, error) {
inCh := make(chan Event, eventChSize)
streamCh := make(chan Event, eventChSize)
// Try to open the file
fh... | go | func NewSnapshotter(path string,
minCompactSize int,
rejoinAfterLeave bool,
logger *log.Logger,
clock *LamportClock,
outCh chan<- Event,
shutdownCh <-chan struct{}) (chan<- Event, *Snapshotter, error) {
inCh := make(chan Event, eventChSize)
streamCh := make(chan Event, eventChSize)
// Try to open the file
fh... | [
"func",
"NewSnapshotter",
"(",
"path",
"string",
",",
"minCompactSize",
"int",
",",
"rejoinAfterLeave",
"bool",
",",
"logger",
"*",
"log",
".",
"Logger",
",",
"clock",
"*",
"LamportClock",
",",
"outCh",
"chan",
"<-",
"Event",
",",
"shutdownCh",
"<-",
"chan",... | // NewSnapshotter creates a new Snapshotter that records events up to a
// max byte size before rotating the file. It can also be used to
// recover old state. Snapshotter works by reading an event channel it returns,
// passing through to an output channel, and persisting relevant events to disk.
// Setting rejoinAfte... | [
"NewSnapshotter",
"creates",
"a",
"new",
"Snapshotter",
"that",
"records",
"events",
"up",
"to",
"a",
"max",
"byte",
"size",
"before",
"rotating",
"the",
"file",
".",
"It",
"can",
"also",
"be",
"used",
"to",
"recover",
"old",
"state",
".",
"Snapshotter",
"... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/snapshot.go#L99-L155 | train |
hashicorp/serf | serf/snapshot.go | AliveNodes | func (s *Snapshotter) AliveNodes() []*PreviousNode {
// Copy the previously known
previous := make([]*PreviousNode, 0, len(s.aliveNodes))
for name, addr := range s.aliveNodes {
previous = append(previous, &PreviousNode{name, addr})
}
// Randomize the order, prevents hot shards
for i := range previous {
j := ... | go | func (s *Snapshotter) AliveNodes() []*PreviousNode {
// Copy the previously known
previous := make([]*PreviousNode, 0, len(s.aliveNodes))
for name, addr := range s.aliveNodes {
previous = append(previous, &PreviousNode{name, addr})
}
// Randomize the order, prevents hot shards
for i := range previous {
j := ... | [
"func",
"(",
"s",
"*",
"Snapshotter",
")",
"AliveNodes",
"(",
")",
"[",
"]",
"*",
"PreviousNode",
"{",
"// Copy the previously known",
"previous",
":=",
"make",
"(",
"[",
"]",
"*",
"PreviousNode",
",",
"0",
",",
"len",
"(",
"s",
".",
"aliveNodes",
")",
... | // AliveNodes returns the last known alive nodes | [
"AliveNodes",
"returns",
"the",
"last",
"known",
"alive",
"nodes"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/snapshot.go#L173-L186 | train |
hashicorp/serf | serf/snapshot.go | teeStream | func (s *Snapshotter) teeStream() {
flushEvent := func(e Event) {
// Forward to the internal stream, do not block
select {
case s.streamCh <- e:
default:
}
// Forward the event immediately, do not block
if s.outCh != nil {
select {
case s.outCh <- e:
default:
}
}
}
OUTER:
for {
select... | go | func (s *Snapshotter) teeStream() {
flushEvent := func(e Event) {
// Forward to the internal stream, do not block
select {
case s.streamCh <- e:
default:
}
// Forward the event immediately, do not block
if s.outCh != nil {
select {
case s.outCh <- e:
default:
}
}
}
OUTER:
for {
select... | [
"func",
"(",
"s",
"*",
"Snapshotter",
")",
"teeStream",
"(",
")",
"{",
"flushEvent",
":=",
"func",
"(",
"e",
"Event",
")",
"{",
"// Forward to the internal stream, do not block",
"select",
"{",
"case",
"s",
".",
"streamCh",
"<-",
"e",
":",
"default",
":",
... | // teeStream is a long running routine that is used to copy events
// to the output channel and the internal event handler. | [
"teeStream",
"is",
"a",
"long",
"running",
"routine",
"that",
"is",
"used",
"to",
"copy",
"events",
"to",
"the",
"output",
"channel",
"and",
"the",
"internal",
"event",
"handler",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/snapshot.go#L204-L240 | train |
hashicorp/serf | serf/snapshot.go | stream | func (s *Snapshotter) stream() {
clockTicker := time.NewTicker(clockUpdateInterval)
defer clockTicker.Stop()
// flushEvent is used to handle writing out an event
flushEvent := func(e Event) {
// Stop recording events after a leave is issued
if s.leaving {
return
}
switch typed := e.(type) {
case Membe... | go | func (s *Snapshotter) stream() {
clockTicker := time.NewTicker(clockUpdateInterval)
defer clockTicker.Stop()
// flushEvent is used to handle writing out an event
flushEvent := func(e Event) {
// Stop recording events after a leave is issued
if s.leaving {
return
}
switch typed := e.(type) {
case Membe... | [
"func",
"(",
"s",
"*",
"Snapshotter",
")",
"stream",
"(",
")",
"{",
"clockTicker",
":=",
"time",
".",
"NewTicker",
"(",
"clockUpdateInterval",
")",
"\n",
"defer",
"clockTicker",
".",
"Stop",
"(",
")",
"\n\n",
"// flushEvent is used to handle writing out an event",... | // stream is a long running routine that is used to handle events | [
"stream",
"is",
"a",
"long",
"running",
"routine",
"that",
"is",
"used",
"to",
"handle",
"events"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/snapshot.go#L243-L319 | train |
hashicorp/serf | serf/snapshot.go | processMemberEvent | func (s *Snapshotter) processMemberEvent(e MemberEvent) {
switch e.Type {
case EventMemberJoin:
for _, mem := range e.Members {
addr := net.TCPAddr{IP: mem.Addr, Port: int(mem.Port)}
s.aliveNodes[mem.Name] = addr.String()
s.tryAppend(fmt.Sprintf("alive: %s %s\n", mem.Name, addr.String()))
}
case EventM... | go | func (s *Snapshotter) processMemberEvent(e MemberEvent) {
switch e.Type {
case EventMemberJoin:
for _, mem := range e.Members {
addr := net.TCPAddr{IP: mem.Addr, Port: int(mem.Port)}
s.aliveNodes[mem.Name] = addr.String()
s.tryAppend(fmt.Sprintf("alive: %s %s\n", mem.Name, addr.String()))
}
case EventM... | [
"func",
"(",
"s",
"*",
"Snapshotter",
")",
"processMemberEvent",
"(",
"e",
"MemberEvent",
")",
"{",
"switch",
"e",
".",
"Type",
"{",
"case",
"EventMemberJoin",
":",
"for",
"_",
",",
"mem",
":=",
"range",
"e",
".",
"Members",
"{",
"addr",
":=",
"net",
... | // processMemberEvent is used to handle a single member event | [
"processMemberEvent",
"is",
"used",
"to",
"handle",
"a",
"single",
"member",
"event"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/snapshot.go#L322-L340 | train |
hashicorp/serf | serf/snapshot.go | updateClock | func (s *Snapshotter) updateClock() {
lastSeen := s.clock.Time() - 1
if lastSeen > s.lastClock {
s.lastClock = lastSeen
s.tryAppend(fmt.Sprintf("clock: %d\n", s.lastClock))
}
} | go | func (s *Snapshotter) updateClock() {
lastSeen := s.clock.Time() - 1
if lastSeen > s.lastClock {
s.lastClock = lastSeen
s.tryAppend(fmt.Sprintf("clock: %d\n", s.lastClock))
}
} | [
"func",
"(",
"s",
"*",
"Snapshotter",
")",
"updateClock",
"(",
")",
"{",
"lastSeen",
":=",
"s",
".",
"clock",
".",
"Time",
"(",
")",
"-",
"1",
"\n",
"if",
"lastSeen",
">",
"s",
".",
"lastClock",
"{",
"s",
".",
"lastClock",
"=",
"lastSeen",
"\n",
... | // updateClock is called periodically to check if we should udpate our
// clock value. This is done after member events but should also be done
// periodically due to race conditions with join and leave intents | [
"updateClock",
"is",
"called",
"periodically",
"to",
"check",
"if",
"we",
"should",
"udpate",
"our",
"clock",
"value",
".",
"This",
"is",
"done",
"after",
"member",
"events",
"but",
"should",
"also",
"be",
"done",
"periodically",
"due",
"to",
"race",
"condit... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/snapshot.go#L345-L351 | train |
hashicorp/serf | serf/snapshot.go | processUserEvent | func (s *Snapshotter) processUserEvent(e UserEvent) {
// Ignore old clocks
if e.LTime <= s.lastEventClock {
return
}
s.lastEventClock = e.LTime
s.tryAppend(fmt.Sprintf("event-clock: %d\n", e.LTime))
} | go | func (s *Snapshotter) processUserEvent(e UserEvent) {
// Ignore old clocks
if e.LTime <= s.lastEventClock {
return
}
s.lastEventClock = e.LTime
s.tryAppend(fmt.Sprintf("event-clock: %d\n", e.LTime))
} | [
"func",
"(",
"s",
"*",
"Snapshotter",
")",
"processUserEvent",
"(",
"e",
"UserEvent",
")",
"{",
"// Ignore old clocks",
"if",
"e",
".",
"LTime",
"<=",
"s",
".",
"lastEventClock",
"{",
"return",
"\n",
"}",
"\n",
"s",
".",
"lastEventClock",
"=",
"e",
".",
... | // processUserEvent is used to handle a single user event | [
"processUserEvent",
"is",
"used",
"to",
"handle",
"a",
"single",
"user",
"event"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/snapshot.go#L354-L361 | train |
hashicorp/serf | serf/snapshot.go | processQuery | func (s *Snapshotter) processQuery(q *Query) {
// Ignore old clocks
if q.LTime <= s.lastQueryClock {
return
}
s.lastQueryClock = q.LTime
s.tryAppend(fmt.Sprintf("query-clock: %d\n", q.LTime))
} | go | func (s *Snapshotter) processQuery(q *Query) {
// Ignore old clocks
if q.LTime <= s.lastQueryClock {
return
}
s.lastQueryClock = q.LTime
s.tryAppend(fmt.Sprintf("query-clock: %d\n", q.LTime))
} | [
"func",
"(",
"s",
"*",
"Snapshotter",
")",
"processQuery",
"(",
"q",
"*",
"Query",
")",
"{",
"// Ignore old clocks",
"if",
"q",
".",
"LTime",
"<=",
"s",
".",
"lastQueryClock",
"{",
"return",
"\n",
"}",
"\n",
"s",
".",
"lastQueryClock",
"=",
"q",
".",
... | // processQuery is used to handle a single query event | [
"processQuery",
"is",
"used",
"to",
"handle",
"a",
"single",
"query",
"event"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/snapshot.go#L364-L371 | train |
hashicorp/serf | serf/snapshot.go | tryAppend | func (s *Snapshotter) tryAppend(l string) {
if err := s.appendLine(l); err != nil {
s.logger.Printf("[ERR] serf: Failed to update snapshot: %v", err)
now := time.Now()
if now.Sub(s.lastAttemptedCompaction) > snapshotErrorRecoveryInterval {
s.lastAttemptedCompaction = now
s.logger.Printf("[INFO] serf: Attem... | go | func (s *Snapshotter) tryAppend(l string) {
if err := s.appendLine(l); err != nil {
s.logger.Printf("[ERR] serf: Failed to update snapshot: %v", err)
now := time.Now()
if now.Sub(s.lastAttemptedCompaction) > snapshotErrorRecoveryInterval {
s.lastAttemptedCompaction = now
s.logger.Printf("[INFO] serf: Attem... | [
"func",
"(",
"s",
"*",
"Snapshotter",
")",
"tryAppend",
"(",
"l",
"string",
")",
"{",
"if",
"err",
":=",
"s",
".",
"appendLine",
"(",
"l",
")",
";",
"err",
"!=",
"nil",
"{",
"s",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
... | // tryAppend will invoke append line but will not return an error | [
"tryAppend",
"will",
"invoke",
"append",
"line",
"but",
"will",
"not",
"return",
"an",
"error"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/snapshot.go#L374-L389 | train |
hashicorp/serf | serf/snapshot.go | appendLine | func (s *Snapshotter) appendLine(l string) error {
defer metrics.MeasureSince([]string{"serf", "snapshot", "appendLine"}, time.Now())
n, err := s.buffered.WriteString(l)
if err != nil {
return err
}
// Check if we should flush
now := time.Now()
if now.Sub(s.lastFlush) > flushInterval {
s.lastFlush = now
... | go | func (s *Snapshotter) appendLine(l string) error {
defer metrics.MeasureSince([]string{"serf", "snapshot", "appendLine"}, time.Now())
n, err := s.buffered.WriteString(l)
if err != nil {
return err
}
// Check if we should flush
now := time.Now()
if now.Sub(s.lastFlush) > flushInterval {
s.lastFlush = now
... | [
"func",
"(",
"s",
"*",
"Snapshotter",
")",
"appendLine",
"(",
"l",
"string",
")",
"error",
"{",
"defer",
"metrics",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"time",
".",
"Now",
"("... | // appendLine is used to append a line to the existing log | [
"appendLine",
"is",
"used",
"to",
"append",
"a",
"line",
"to",
"the",
"existing",
"log"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/snapshot.go#L392-L415 | train |
hashicorp/serf | serf/snapshot.go | snapshotMaxSize | func (s *Snapshotter) snapshotMaxSize() int64 {
nodes := int64(len(s.aliveNodes))
estSize := nodes * snapshotBytesPerNode
threshold := estSize * snapshotCompactionThreshold
// Apply a minimum threshold to avoid frequent compaction
if threshold < s.minCompactSize {
threshold = s.minCompactSize
}
return thresho... | go | func (s *Snapshotter) snapshotMaxSize() int64 {
nodes := int64(len(s.aliveNodes))
estSize := nodes * snapshotBytesPerNode
threshold := estSize * snapshotCompactionThreshold
// Apply a minimum threshold to avoid frequent compaction
if threshold < s.minCompactSize {
threshold = s.minCompactSize
}
return thresho... | [
"func",
"(",
"s",
"*",
"Snapshotter",
")",
"snapshotMaxSize",
"(",
")",
"int64",
"{",
"nodes",
":=",
"int64",
"(",
"len",
"(",
"s",
".",
"aliveNodes",
")",
")",
"\n",
"estSize",
":=",
"nodes",
"*",
"snapshotBytesPerNode",
"\n",
"threshold",
":=",
"estSiz... | // snapshotMaxSize computes the maximum size and is used to force periodic compaction. | [
"snapshotMaxSize",
"computes",
"the",
"maximum",
"size",
"and",
"is",
"used",
"to",
"force",
"periodic",
"compaction",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/snapshot.go#L418-L428 | train |
hashicorp/serf | cmd/serf/command/agent/invoke.go | eventClean | func eventClean(v string) string {
v = strings.Replace(v, "\t", "\\t", -1)
v = strings.Replace(v, "\n", "\\n", -1)
return v
} | go | func eventClean(v string) string {
v = strings.Replace(v, "\t", "\\t", -1)
v = strings.Replace(v, "\n", "\\n", -1)
return v
} | [
"func",
"eventClean",
"(",
"v",
"string",
")",
"string",
"{",
"v",
"=",
"strings",
".",
"Replace",
"(",
"v",
",",
"\"",
"\\t",
"\"",
",",
"\"",
"\\\\",
"\"",
",",
"-",
"1",
")",
"\n",
"v",
"=",
"strings",
".",
"Replace",
"(",
"v",
",",
"\"",
... | // eventClean cleans a value to be a parameter in an event line. | [
"eventClean",
"cleans",
"a",
"value",
"to",
"be",
"a",
"parameter",
"in",
"an",
"event",
"line",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/invoke.go#L132-L136 | train |
hashicorp/serf | cmd/serf/command/agent/ipc_event_stream.go | sendMemberEvent | func (es *eventStream) sendMemberEvent(me serf.MemberEvent) error {
members := make([]Member, 0, len(me.Members))
for _, m := range me.Members {
sm := Member{
Name: m.Name,
Addr: m.Addr,
Port: m.Port,
Tags: m.Tags,
Status: m.Status.String(),
ProtocolMin: m.Protocol... | go | func (es *eventStream) sendMemberEvent(me serf.MemberEvent) error {
members := make([]Member, 0, len(me.Members))
for _, m := range me.Members {
sm := Member{
Name: m.Name,
Addr: m.Addr,
Port: m.Port,
Tags: m.Tags,
Status: m.Status.String(),
ProtocolMin: m.Protocol... | [
"func",
"(",
"es",
"*",
"eventStream",
")",
"sendMemberEvent",
"(",
"me",
"serf",
".",
"MemberEvent",
")",
"error",
"{",
"members",
":=",
"make",
"(",
"[",
"]",
"Member",
",",
"0",
",",
"len",
"(",
"me",
".",
"Members",
")",
")",
"\n",
"for",
"_",
... | // sendMemberEvent is used to send a single member event | [
"sendMemberEvent",
"is",
"used",
"to",
"send",
"a",
"single",
"member",
"event"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/ipc_event_stream.go#L80-L108 | train |
hashicorp/serf | cmd/serf/command/agent/ipc_event_stream.go | sendUserEvent | func (es *eventStream) sendUserEvent(ue serf.UserEvent) error {
header := responseHeader{
Seq: es.seq,
Error: "",
}
rec := userEventRecord{
Event: ue.EventType().String(),
LTime: ue.LTime,
Name: ue.Name,
Payload: ue.Payload,
Coalesce: ue.Coalesce,
}
return es.client.Send(&header, &rec)
} | go | func (es *eventStream) sendUserEvent(ue serf.UserEvent) error {
header := responseHeader{
Seq: es.seq,
Error: "",
}
rec := userEventRecord{
Event: ue.EventType().String(),
LTime: ue.LTime,
Name: ue.Name,
Payload: ue.Payload,
Coalesce: ue.Coalesce,
}
return es.client.Send(&header, &rec)
} | [
"func",
"(",
"es",
"*",
"eventStream",
")",
"sendUserEvent",
"(",
"ue",
"serf",
".",
"UserEvent",
")",
"error",
"{",
"header",
":=",
"responseHeader",
"{",
"Seq",
":",
"es",
".",
"seq",
",",
"Error",
":",
"\"",
"\"",
",",
"}",
"\n",
"rec",
":=",
"u... | // sendUserEvent is used to send a single user event | [
"sendUserEvent",
"is",
"used",
"to",
"send",
"a",
"single",
"user",
"event"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/ipc_event_stream.go#L111-L124 | train |
hashicorp/serf | cmd/serf/command/agent/ipc_event_stream.go | sendQuery | func (es *eventStream) sendQuery(q *serf.Query) error {
id := es.client.RegisterQuery(q)
header := responseHeader{
Seq: es.seq,
Error: "",
}
rec := queryEventRecord{
Event: q.EventType().String(),
ID: id,
LTime: q.LTime,
Name: q.Name,
Payload: q.Payload,
}
return es.client.Send(&heade... | go | func (es *eventStream) sendQuery(q *serf.Query) error {
id := es.client.RegisterQuery(q)
header := responseHeader{
Seq: es.seq,
Error: "",
}
rec := queryEventRecord{
Event: q.EventType().String(),
ID: id,
LTime: q.LTime,
Name: q.Name,
Payload: q.Payload,
}
return es.client.Send(&heade... | [
"func",
"(",
"es",
"*",
"eventStream",
")",
"sendQuery",
"(",
"q",
"*",
"serf",
".",
"Query",
")",
"error",
"{",
"id",
":=",
"es",
".",
"client",
".",
"RegisterQuery",
"(",
"q",
")",
"\n\n",
"header",
":=",
"responseHeader",
"{",
"Seq",
":",
"es",
... | // sendQuery is used to send a single query event | [
"sendQuery",
"is",
"used",
"to",
"send",
"a",
"single",
"query",
"event"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/cmd/serf/command/agent/ipc_event_stream.go#L127-L142 | train |
hashicorp/serf | serf/event.go | checkResponseSize | func (q *Query) checkResponseSize(resp []byte) error {
if len(resp) > q.serf.config.QueryResponseSizeLimit {
return fmt.Errorf("response exceeds limit of %d bytes", q.serf.config.QueryResponseSizeLimit)
}
return nil
} | go | func (q *Query) checkResponseSize(resp []byte) error {
if len(resp) > q.serf.config.QueryResponseSizeLimit {
return fmt.Errorf("response exceeds limit of %d bytes", q.serf.config.QueryResponseSizeLimit)
}
return nil
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"checkResponseSize",
"(",
"resp",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"resp",
")",
">",
"q",
".",
"serf",
".",
"config",
".",
"QueryResponseSizeLimit",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
... | // Check response size | [
"Check",
"response",
"size"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/event.go#L137-L142 | train |
hashicorp/serf | serf/event.go | Respond | func (q *Query) Respond(buf []byte) error {
// Create response
resp := q.createResponse(buf)
// Encode response
raw, err := encodeMessage(messageQueryResponseType, resp)
if err != nil {
return fmt.Errorf("failed to format response: %v", err)
}
if err := q.respondWithMessageAndResponse(raw, resp); err != nil ... | go | func (q *Query) Respond(buf []byte) error {
// Create response
resp := q.createResponse(buf)
// Encode response
raw, err := encodeMessage(messageQueryResponseType, resp)
if err != nil {
return fmt.Errorf("failed to format response: %v", err)
}
if err := q.respondWithMessageAndResponse(raw, resp); err != nil ... | [
"func",
"(",
"q",
"*",
"Query",
")",
"Respond",
"(",
"buf",
"[",
"]",
"byte",
")",
"error",
"{",
"// Create response",
"resp",
":=",
"q",
".",
"createResponse",
"(",
"buf",
")",
"\n\n",
"// Encode response",
"raw",
",",
"err",
":=",
"encodeMessage",
"(",... | // Respond is used to send a response to the user query | [
"Respond",
"is",
"used",
"to",
"send",
"a",
"response",
"to",
"the",
"user",
"query"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/event.go#L181-L196 | train |
hashicorp/serf | serf/messages.go | encodeRelayMessage | func encodeRelayMessage(t messageType, addr net.UDPAddr, msg interface{}) ([]byte, error) {
buf := bytes.NewBuffer(nil)
handle := codec.MsgpackHandle{}
encoder := codec.NewEncoder(buf, &handle)
buf.WriteByte(uint8(messageRelayType))
if err := encoder.Encode(relayHeader{DestAddr: addr}); err != nil {
return nil,... | go | func encodeRelayMessage(t messageType, addr net.UDPAddr, msg interface{}) ([]byte, error) {
buf := bytes.NewBuffer(nil)
handle := codec.MsgpackHandle{}
encoder := codec.NewEncoder(buf, &handle)
buf.WriteByte(uint8(messageRelayType))
if err := encoder.Encode(relayHeader{DestAddr: addr}); err != nil {
return nil,... | [
"func",
"encodeRelayMessage",
"(",
"t",
"messageType",
",",
"addr",
"net",
".",
"UDPAddr",
",",
"msg",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"nil",
")",
"\n",
"handle",... | // encodeRelayMessage wraps a message in the messageRelayType, adding the length and
// address of the end recipient to the front of the message | [
"encodeRelayMessage",
"wraps",
"a",
"message",
"in",
"the",
"messageRelayType",
"adding",
"the",
"length",
"and",
"address",
"of",
"the",
"end",
"recipient",
"to",
"the",
"front",
"of",
"the",
"message"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/messages.go#L150-L163 | train |
hashicorp/serf | coordinate/client.go | NewClient | func NewClient(config *Config) (*Client, error) {
if !(config.Dimensionality > 0) {
return nil, fmt.Errorf("dimensionality must be >0")
}
return &Client{
coord: NewCoordinate(config),
origin: NewCoordinate(config),
config: config,
adjustmentIndex: 0,
adjus... | go | func NewClient(config *Config) (*Client, error) {
if !(config.Dimensionality > 0) {
return nil, fmt.Errorf("dimensionality must be >0")
}
return &Client{
coord: NewCoordinate(config),
origin: NewCoordinate(config),
config: config,
adjustmentIndex: 0,
adjus... | [
"func",
"NewClient",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"if",
"!",
"(",
"config",
".",
"Dimensionality",
">",
"0",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
... | // NewClient creates a new Client and verifies the configuration is valid. | [
"NewClient",
"creates",
"a",
"new",
"Client",
"and",
"verifies",
"the",
"configuration",
"is",
"valid",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/client.go#L54-L67 | train |
hashicorp/serf | coordinate/client.go | GetCoordinate | func (c *Client) GetCoordinate() *Coordinate {
c.mutex.RLock()
defer c.mutex.RUnlock()
return c.coord.Clone()
} | go | func (c *Client) GetCoordinate() *Coordinate {
c.mutex.RLock()
defer c.mutex.RUnlock()
return c.coord.Clone()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetCoordinate",
"(",
")",
"*",
"Coordinate",
"{",
"c",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"c",
".",
"coord",
".",
"Clone",
"("... | // GetCoordinate returns a copy of the coordinate for this client. | [
"GetCoordinate",
"returns",
"a",
"copy",
"of",
"the",
"coordinate",
"for",
"this",
"client",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/client.go#L70-L75 | train |
hashicorp/serf | coordinate/client.go | SetCoordinate | func (c *Client) SetCoordinate(coord *Coordinate) error {
c.mutex.Lock()
defer c.mutex.Unlock()
if err := c.checkCoordinate(coord); err != nil {
return err
}
c.coord = coord.Clone()
return nil
} | go | func (c *Client) SetCoordinate(coord *Coordinate) error {
c.mutex.Lock()
defer c.mutex.Unlock()
if err := c.checkCoordinate(coord); err != nil {
return err
}
c.coord = coord.Clone()
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetCoordinate",
"(",
"coord",
"*",
"Coordinate",
")",
"error",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"err",
":=",
"c",
".",
... | // SetCoordinate forces the client's coordinate to a known state. | [
"SetCoordinate",
"forces",
"the",
"client",
"s",
"coordinate",
"to",
"a",
"known",
"state",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/client.go#L78-L88 | train |
hashicorp/serf | coordinate/client.go | ForgetNode | func (c *Client) ForgetNode(node string) {
c.mutex.Lock()
defer c.mutex.Unlock()
delete(c.latencyFilterSamples, node)
} | go | func (c *Client) ForgetNode(node string) {
c.mutex.Lock()
defer c.mutex.Unlock()
delete(c.latencyFilterSamples, node)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ForgetNode",
"(",
"node",
"string",
")",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"delete",
"(",
"c",
".",
"latencyFilterSamples",
",",
... | // ForgetNode removes any client state for the given node. | [
"ForgetNode",
"removes",
"any",
"client",
"state",
"for",
"the",
"given",
"node",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/client.go#L91-L96 | train |
hashicorp/serf | coordinate/client.go | Stats | func (c *Client) Stats() ClientStats {
c.mutex.Lock()
defer c.mutex.Unlock()
return c.stats
} | go | func (c *Client) Stats() ClientStats {
c.mutex.Lock()
defer c.mutex.Unlock()
return c.stats
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Stats",
"(",
")",
"ClientStats",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"c",
".",
"stats",
"\n",
"}"
] | // Stats returns a copy of stats for the client. | [
"Stats",
"returns",
"a",
"copy",
"of",
"stats",
"for",
"the",
"client",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/client.go#L99-L104 | train |
hashicorp/serf | coordinate/client.go | checkCoordinate | func (c *Client) checkCoordinate(coord *Coordinate) error {
if !c.coord.IsCompatibleWith(coord) {
return fmt.Errorf("dimensions aren't compatible")
}
if !coord.IsValid() {
return fmt.Errorf("coordinate is invalid")
}
return nil
} | go | func (c *Client) checkCoordinate(coord *Coordinate) error {
if !c.coord.IsCompatibleWith(coord) {
return fmt.Errorf("dimensions aren't compatible")
}
if !coord.IsValid() {
return fmt.Errorf("coordinate is invalid")
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"checkCoordinate",
"(",
"coord",
"*",
"Coordinate",
")",
"error",
"{",
"if",
"!",
"c",
".",
"coord",
".",
"IsCompatibleWith",
"(",
"coord",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
... | // checkCoordinate returns an error if the coordinate isn't compatible with
// this client, or if the coordinate itself isn't valid. This assumes the mutex
// has been locked already. | [
"checkCoordinate",
"returns",
"an",
"error",
"if",
"the",
"coordinate",
"isn",
"t",
"compatible",
"with",
"this",
"client",
"or",
"if",
"the",
"coordinate",
"itself",
"isn",
"t",
"valid",
".",
"This",
"assumes",
"the",
"mutex",
"has",
"been",
"locked",
"alre... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/client.go#L109-L119 | train |
hashicorp/serf | coordinate/client.go | latencyFilter | func (c *Client) latencyFilter(node string, rttSeconds float64) float64 {
samples, ok := c.latencyFilterSamples[node]
if !ok {
samples = make([]float64, 0, c.config.LatencyFilterSize)
}
// Add the new sample and trim the list, if needed.
samples = append(samples, rttSeconds)
if len(samples) > int(c.config.Late... | go | func (c *Client) latencyFilter(node string, rttSeconds float64) float64 {
samples, ok := c.latencyFilterSamples[node]
if !ok {
samples = make([]float64, 0, c.config.LatencyFilterSize)
}
// Add the new sample and trim the list, if needed.
samples = append(samples, rttSeconds)
if len(samples) > int(c.config.Late... | [
"func",
"(",
"c",
"*",
"Client",
")",
"latencyFilter",
"(",
"node",
"string",
",",
"rttSeconds",
"float64",
")",
"float64",
"{",
"samples",
",",
"ok",
":=",
"c",
".",
"latencyFilterSamples",
"[",
"node",
"]",
"\n",
"if",
"!",
"ok",
"{",
"samples",
"=",... | // latencyFilter applies a simple moving median filter with a new sample for
// a node. This assumes that the mutex has been locked already. | [
"latencyFilter",
"applies",
"a",
"simple",
"moving",
"median",
"filter",
"with",
"a",
"new",
"sample",
"for",
"a",
"node",
".",
"This",
"assumes",
"that",
"the",
"mutex",
"has",
"been",
"locked",
"already",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/client.go#L123-L141 | train |
hashicorp/serf | coordinate/client.go | updateVivaldi | func (c *Client) updateVivaldi(other *Coordinate, rttSeconds float64) {
const zeroThreshold = 1.0e-6
dist := c.coord.DistanceTo(other).Seconds()
if rttSeconds < zeroThreshold {
rttSeconds = zeroThreshold
}
wrongness := math.Abs(dist-rttSeconds) / rttSeconds
totalError := c.coord.Error + other.Error
if totalE... | go | func (c *Client) updateVivaldi(other *Coordinate, rttSeconds float64) {
const zeroThreshold = 1.0e-6
dist := c.coord.DistanceTo(other).Seconds()
if rttSeconds < zeroThreshold {
rttSeconds = zeroThreshold
}
wrongness := math.Abs(dist-rttSeconds) / rttSeconds
totalError := c.coord.Error + other.Error
if totalE... | [
"func",
"(",
"c",
"*",
"Client",
")",
"updateVivaldi",
"(",
"other",
"*",
"Coordinate",
",",
"rttSeconds",
"float64",
")",
"{",
"const",
"zeroThreshold",
"=",
"1.0e-6",
"\n\n",
"dist",
":=",
"c",
".",
"coord",
".",
"DistanceTo",
"(",
"other",
")",
".",
... | // updateVivialdi updates the Vivaldi portion of the client's coordinate. This
// assumes that the mutex has been locked already. | [
"updateVivialdi",
"updates",
"the",
"Vivaldi",
"portion",
"of",
"the",
"client",
"s",
"coordinate",
".",
"This",
"assumes",
"that",
"the",
"mutex",
"has",
"been",
"locked",
"already",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/client.go#L145-L168 | train |
hashicorp/serf | coordinate/client.go | updateAdjustment | func (c *Client) updateAdjustment(other *Coordinate, rttSeconds float64) {
if c.config.AdjustmentWindowSize == 0 {
return
}
// Note that the existing adjustment factors don't figure in to this
// calculation so we use the raw distance here.
dist := c.coord.rawDistanceTo(other)
c.adjustmentSamples[c.adjustmentI... | go | func (c *Client) updateAdjustment(other *Coordinate, rttSeconds float64) {
if c.config.AdjustmentWindowSize == 0 {
return
}
// Note that the existing adjustment factors don't figure in to this
// calculation so we use the raw distance here.
dist := c.coord.rawDistanceTo(other)
c.adjustmentSamples[c.adjustmentI... | [
"func",
"(",
"c",
"*",
"Client",
")",
"updateAdjustment",
"(",
"other",
"*",
"Coordinate",
",",
"rttSeconds",
"float64",
")",
"{",
"if",
"c",
".",
"config",
".",
"AdjustmentWindowSize",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"// Note that the existing ... | // updateAdjustment updates the adjustment portion of the client's coordinate, if
// the feature is enabled. This assumes that the mutex has been locked already. | [
"updateAdjustment",
"updates",
"the",
"adjustment",
"portion",
"of",
"the",
"client",
"s",
"coordinate",
"if",
"the",
"feature",
"is",
"enabled",
".",
"This",
"assumes",
"that",
"the",
"mutex",
"has",
"been",
"locked",
"already",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/client.go#L172-L188 | train |
hashicorp/serf | coordinate/client.go | updateGravity | func (c *Client) updateGravity() {
dist := c.origin.DistanceTo(c.coord).Seconds()
force := -1.0 * math.Pow(dist/c.config.GravityRho, 2.0)
c.coord = c.coord.ApplyForce(c.config, force, c.origin)
} | go | func (c *Client) updateGravity() {
dist := c.origin.DistanceTo(c.coord).Seconds()
force := -1.0 * math.Pow(dist/c.config.GravityRho, 2.0)
c.coord = c.coord.ApplyForce(c.config, force, c.origin)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"updateGravity",
"(",
")",
"{",
"dist",
":=",
"c",
".",
"origin",
".",
"DistanceTo",
"(",
"c",
".",
"coord",
")",
".",
"Seconds",
"(",
")",
"\n",
"force",
":=",
"-",
"1.0",
"*",
"math",
".",
"Pow",
"(",
"di... | // updateGravity applies a small amount of gravity to pull coordinates towards
// the center of the coordinate system to combat drift. This assumes that the
// mutex is locked already. | [
"updateGravity",
"applies",
"a",
"small",
"amount",
"of",
"gravity",
"to",
"pull",
"coordinates",
"towards",
"the",
"center",
"of",
"the",
"coordinate",
"system",
"to",
"combat",
"drift",
".",
"This",
"assumes",
"that",
"the",
"mutex",
"is",
"locked",
"already... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/client.go#L193-L197 | train |
hashicorp/serf | coordinate/client.go | Update | func (c *Client) Update(node string, other *Coordinate, rtt time.Duration) (*Coordinate, error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if err := c.checkCoordinate(other); err != nil {
return nil, err
}
// The code down below can handle zero RTTs, which we have seen in
// https://github.com/hashicorp/consul/i... | go | func (c *Client) Update(node string, other *Coordinate, rtt time.Duration) (*Coordinate, error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if err := c.checkCoordinate(other); err != nil {
return nil, err
}
// The code down below can handle zero RTTs, which we have seen in
// https://github.com/hashicorp/consul/i... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Update",
"(",
"node",
"string",
",",
"other",
"*",
"Coordinate",
",",
"rtt",
"time",
".",
"Duration",
")",
"(",
"*",
"Coordinate",
",",
"error",
")",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"def... | // Update takes other, a coordinate for another node, and rtt, a round trip
// time observation for a ping to that node, and updates the estimated position of
// the client's coordinate. Returns the updated coordinate. | [
"Update",
"takes",
"other",
"a",
"coordinate",
"for",
"another",
"node",
"and",
"rtt",
"a",
"round",
"trip",
"time",
"observation",
"for",
"a",
"ping",
"to",
"that",
"node",
"and",
"updates",
"the",
"estimated",
"position",
"of",
"the",
"client",
"s",
"coo... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/client.go#L202-L234 | train |
hashicorp/serf | coordinate/client.go | DistanceTo | func (c *Client) DistanceTo(other *Coordinate) time.Duration {
c.mutex.RLock()
defer c.mutex.RUnlock()
return c.coord.DistanceTo(other)
} | go | func (c *Client) DistanceTo(other *Coordinate) time.Duration {
c.mutex.RLock()
defer c.mutex.RUnlock()
return c.coord.DistanceTo(other)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"DistanceTo",
"(",
"other",
"*",
"Coordinate",
")",
"time",
".",
"Duration",
"{",
"c",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"c",
... | // DistanceTo returns the estimated RTT from the client's coordinate to other, the
// coordinate for another node. | [
"DistanceTo",
"returns",
"the",
"estimated",
"RTT",
"from",
"the",
"client",
"s",
"coordinate",
"to",
"other",
"the",
"coordinate",
"for",
"another",
"node",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/coordinate/client.go#L238-L243 | train |
hashicorp/serf | serf/serf.go | UserEvent | func (s *Serf) UserEvent(name string, payload []byte, coalesce bool) error {
payloadSizeBeforeEncoding := len(name)+len(payload)
// Check size before encoding to prevent needless encoding and return early if it's over the specified limit.
if payloadSizeBeforeEncoding > s.config.UserEventSizeLimit {
return fmt.Err... | go | func (s *Serf) UserEvent(name string, payload []byte, coalesce bool) error {
payloadSizeBeforeEncoding := len(name)+len(payload)
// Check size before encoding to prevent needless encoding and return early if it's over the specified limit.
if payloadSizeBeforeEncoding > s.config.UserEventSizeLimit {
return fmt.Err... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"UserEvent",
"(",
"name",
"string",
",",
"payload",
"[",
"]",
"byte",
",",
"coalesce",
"bool",
")",
"error",
"{",
"payloadSizeBeforeEncoding",
":=",
"len",
"(",
"name",
")",
"+",
"len",
"(",
"payload",
")",
"\n\n",
... | // UserEvent is used to broadcast a custom user event with a given
// name and payload. If the configured size limit is exceeded and error will be returned.
// If coalesce is enabled, nodes are allowed to coalesce this event.
// Coalescing is only available starting in v0.2 | [
"UserEvent",
"is",
"used",
"to",
"broadcast",
"a",
"custom",
"user",
"event",
"with",
"a",
"given",
"name",
"and",
"payload",
".",
"If",
"the",
"configured",
"size",
"limit",
"is",
"exceeded",
"and",
"error",
"will",
"be",
"returned",
".",
"If",
"coalesce"... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L447-L504 | train |
hashicorp/serf | serf/serf.go | Query | func (s *Serf) Query(name string, payload []byte, params *QueryParam) (*QueryResponse, error) {
// Check that the latest protocol is in use
if s.ProtocolVersion() < 4 {
return nil, FeatureNotSupported
}
// Provide default parameters if none given
if params == nil {
params = s.DefaultQueryParams()
} else if p... | go | func (s *Serf) Query(name string, payload []byte, params *QueryParam) (*QueryResponse, error) {
// Check that the latest protocol is in use
if s.ProtocolVersion() < 4 {
return nil, FeatureNotSupported
}
// Provide default parameters if none given
if params == nil {
params = s.DefaultQueryParams()
} else if p... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"Query",
"(",
"name",
"string",
",",
"payload",
"[",
"]",
"byte",
",",
"params",
"*",
"QueryParam",
")",
"(",
"*",
"QueryResponse",
",",
"error",
")",
"{",
"// Check that the latest protocol is in use",
"if",
"s",
".",
... | // Query is used to broadcast a new query. The query must be fairly small,
// and an error will be returned if the size limit is exceeded. This is only
// available with protocol version 4 and newer. Query parameters are optional,
// and if not provided, a sane set of defaults will be used. | [
"Query",
"is",
"used",
"to",
"broadcast",
"a",
"new",
"query",
".",
"The",
"query",
"must",
"be",
"fairly",
"small",
"and",
"an",
"error",
"will",
"be",
"returned",
"if",
"the",
"size",
"limit",
"is",
"exceeded",
".",
"This",
"is",
"only",
"available",
... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L510-L575 | train |
hashicorp/serf | serf/serf.go | registerQueryResponse | func (s *Serf) registerQueryResponse(timeout time.Duration, resp *QueryResponse) {
s.queryLock.Lock()
defer s.queryLock.Unlock()
// Map the LTime to the QueryResponse. This is necessarily 1-to-1,
// since we increment the time for each new query.
s.queryResponse[resp.lTime] = resp
// Setup a timer to close the ... | go | func (s *Serf) registerQueryResponse(timeout time.Duration, resp *QueryResponse) {
s.queryLock.Lock()
defer s.queryLock.Unlock()
// Map the LTime to the QueryResponse. This is necessarily 1-to-1,
// since we increment the time for each new query.
s.queryResponse[resp.lTime] = resp
// Setup a timer to close the ... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"registerQueryResponse",
"(",
"timeout",
"time",
".",
"Duration",
",",
"resp",
"*",
"QueryResponse",
")",
"{",
"s",
".",
"queryLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"queryLock",
".",
"Unlock",
"(",
... | // registerQueryResponse is used to setup the listeners for the query,
// and to schedule closing the query after the timeout. | [
"registerQueryResponse",
"is",
"used",
"to",
"setup",
"the",
"listeners",
"for",
"the",
"query",
"and",
"to",
"schedule",
"closing",
"the",
"query",
"after",
"the",
"timeout",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L579-L594 | train |
hashicorp/serf | serf/serf.go | SetTags | func (s *Serf) SetTags(tags map[string]string) error {
// Check that the meta data length is okay
if len(s.encodeTags(tags)) > memberlist.MetaMaxSize {
return fmt.Errorf("Encoded length of tags exceeds limit of %d bytes",
memberlist.MetaMaxSize)
}
// Update the config
s.config.Tags = tags
// Trigger a memb... | go | func (s *Serf) SetTags(tags map[string]string) error {
// Check that the meta data length is okay
if len(s.encodeTags(tags)) > memberlist.MetaMaxSize {
return fmt.Errorf("Encoded length of tags exceeds limit of %d bytes",
memberlist.MetaMaxSize)
}
// Update the config
s.config.Tags = tags
// Trigger a memb... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"SetTags",
"(",
"tags",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"// Check that the meta data length is okay",
"if",
"len",
"(",
"s",
".",
"encodeTags",
"(",
"tags",
")",
")",
">",
"memberlist",
".",
"Me... | // SetTags is used to dynamically update the tags associated with
// the local node. This will propagate the change to the rest of
// the cluster. Blocks until a the message is broadcast out. | [
"SetTags",
"is",
"used",
"to",
"dynamically",
"update",
"the",
"tags",
"associated",
"with",
"the",
"local",
"node",
".",
"This",
"will",
"propagate",
"the",
"change",
"to",
"the",
"rest",
"of",
"the",
"cluster",
".",
"Blocks",
"until",
"a",
"the",
"messag... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L599-L611 | train |
hashicorp/serf | serf/serf.go | Join | func (s *Serf) Join(existing []string, ignoreOld bool) (int, error) {
// Do a quick state check
if s.State() != SerfAlive {
return 0, fmt.Errorf("Serf can't Join after Leave or Shutdown")
}
// Hold the joinLock, this is to make eventJoinIgnore safe
s.joinLock.Lock()
defer s.joinLock.Unlock()
// Ignore any ev... | go | func (s *Serf) Join(existing []string, ignoreOld bool) (int, error) {
// Do a quick state check
if s.State() != SerfAlive {
return 0, fmt.Errorf("Serf can't Join after Leave or Shutdown")
}
// Hold the joinLock, this is to make eventJoinIgnore safe
s.joinLock.Lock()
defer s.joinLock.Unlock()
// Ignore any ev... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"Join",
"(",
"existing",
"[",
"]",
"string",
",",
"ignoreOld",
"bool",
")",
"(",
"int",
",",
"error",
")",
"{",
"// Do a quick state check",
"if",
"s",
".",
"State",
"(",
")",
"!=",
"SerfAlive",
"{",
"return",
"0",... | // Join joins an existing Serf cluster. Returns the number of nodes
// successfully contacted. The returned error will be non-nil only in the
// case that no nodes could be contacted. If ignoreOld is true, then any
// user messages sent prior to the join will be ignored. | [
"Join",
"joins",
"an",
"existing",
"Serf",
"cluster",
".",
"Returns",
"the",
"number",
"of",
"nodes",
"successfully",
"contacted",
".",
"The",
"returned",
"error",
"will",
"be",
"non",
"-",
"nil",
"only",
"in",
"the",
"case",
"that",
"no",
"nodes",
"could"... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L617-L648 | train |
hashicorp/serf | serf/serf.go | broadcastJoin | func (s *Serf) broadcastJoin(ltime LamportTime) error {
// Construct message to update our lamport clock
msg := messageJoin{
LTime: ltime,
Node: s.config.NodeName,
}
s.clock.Witness(ltime)
// Process update locally
s.handleNodeJoinIntent(&msg)
// Start broadcasting the update
if err := s.broadcast(messag... | go | func (s *Serf) broadcastJoin(ltime LamportTime) error {
// Construct message to update our lamport clock
msg := messageJoin{
LTime: ltime,
Node: s.config.NodeName,
}
s.clock.Witness(ltime)
// Process update locally
s.handleNodeJoinIntent(&msg)
// Start broadcasting the update
if err := s.broadcast(messag... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"broadcastJoin",
"(",
"ltime",
"LamportTime",
")",
"error",
"{",
"// Construct message to update our lamport clock",
"msg",
":=",
"messageJoin",
"{",
"LTime",
":",
"ltime",
",",
"Node",
":",
"s",
".",
"config",
".",
"NodeNam... | // broadcastJoin broadcasts a new join intent with a
// given clock value. It is used on either join, or if
// we need to refute an older leave intent. Cannot be called
// with the memberLock held. | [
"broadcastJoin",
"broadcasts",
"a",
"new",
"join",
"intent",
"with",
"a",
"given",
"clock",
"value",
".",
"It",
"is",
"used",
"on",
"either",
"join",
"or",
"if",
"we",
"need",
"to",
"refute",
"an",
"older",
"leave",
"intent",
".",
"Cannot",
"be",
"called... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L654-L671 | train |
hashicorp/serf | serf/serf.go | Leave | func (s *Serf) Leave() error {
// Check the current state
s.stateLock.Lock()
if s.state == SerfLeft {
s.stateLock.Unlock()
return nil
} else if s.state == SerfLeaving {
s.stateLock.Unlock()
return fmt.Errorf("Leave already in progress")
} else if s.state == SerfShutdown {
s.stateLock.Unlock()
return fm... | go | func (s *Serf) Leave() error {
// Check the current state
s.stateLock.Lock()
if s.state == SerfLeft {
s.stateLock.Unlock()
return nil
} else if s.state == SerfLeaving {
s.stateLock.Unlock()
return fmt.Errorf("Leave already in progress")
} else if s.state == SerfShutdown {
s.stateLock.Unlock()
return fm... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"Leave",
"(",
")",
"error",
"{",
"// Check the current state",
"s",
".",
"stateLock",
".",
"Lock",
"(",
")",
"\n",
"if",
"s",
".",
"state",
"==",
"SerfLeft",
"{",
"s",
".",
"stateLock",
".",
"Unlock",
"(",
")",
"... | // Leave gracefully exits the cluster. It is safe to call this multiple
// times. | [
"Leave",
"gracefully",
"exits",
"the",
"cluster",
".",
"It",
"is",
"safe",
"to",
"call",
"this",
"multiple",
"times",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L675-L741 | train |
hashicorp/serf | serf/serf.go | hasAliveMembers | func (s *Serf) hasAliveMembers() bool {
s.memberLock.RLock()
defer s.memberLock.RUnlock()
hasAlive := false
for _, m := range s.members {
// Skip ourself, we want to know if OTHER members are alive
if m.Name == s.config.NodeName {
continue
}
if m.Status == StatusAlive {
hasAlive = true
break
}
... | go | func (s *Serf) hasAliveMembers() bool {
s.memberLock.RLock()
defer s.memberLock.RUnlock()
hasAlive := false
for _, m := range s.members {
// Skip ourself, we want to know if OTHER members are alive
if m.Name == s.config.NodeName {
continue
}
if m.Status == StatusAlive {
hasAlive = true
break
}
... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"hasAliveMembers",
"(",
")",
"bool",
"{",
"s",
".",
"memberLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"memberLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"hasAlive",
":=",
"false",
"\n",
"for",
"_",
",",... | // hasAliveMembers is called to check for any alive members other than
// ourself. | [
"hasAliveMembers",
"is",
"called",
"to",
"check",
"for",
"any",
"alive",
"members",
"other",
"than",
"ourself",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L745-L762 | train |
hashicorp/serf | serf/serf.go | LocalMember | func (s *Serf) LocalMember() Member {
s.memberLock.RLock()
defer s.memberLock.RUnlock()
return s.members[s.config.NodeName].Member
} | go | func (s *Serf) LocalMember() Member {
s.memberLock.RLock()
defer s.memberLock.RUnlock()
return s.members[s.config.NodeName].Member
} | [
"func",
"(",
"s",
"*",
"Serf",
")",
"LocalMember",
"(",
")",
"Member",
"{",
"s",
".",
"memberLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"memberLock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"s",
".",
"members",
"[",
"s",
".",
"conf... | // LocalMember returns the Member information for the local node | [
"LocalMember",
"returns",
"the",
"Member",
"information",
"for",
"the",
"local",
"node"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L765-L769 | train |
hashicorp/serf | serf/serf.go | Members | func (s *Serf) Members() []Member {
s.memberLock.RLock()
defer s.memberLock.RUnlock()
members := make([]Member, 0, len(s.members))
for _, m := range s.members {
members = append(members, m.Member)
}
return members
} | go | func (s *Serf) Members() []Member {
s.memberLock.RLock()
defer s.memberLock.RUnlock()
members := make([]Member, 0, len(s.members))
for _, m := range s.members {
members = append(members, m.Member)
}
return members
} | [
"func",
"(",
"s",
"*",
"Serf",
")",
"Members",
"(",
")",
"[",
"]",
"Member",
"{",
"s",
".",
"memberLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"memberLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"members",
":=",
"make",
"(",
"[",
"]",
"... | // Members returns a point-in-time snapshot of the members of this cluster. | [
"Members",
"returns",
"a",
"point",
"-",
"in",
"-",
"time",
"snapshot",
"of",
"the",
"members",
"of",
"this",
"cluster",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L772-L782 | train |
hashicorp/serf | serf/serf.go | RemoveFailedNode | func (s *Serf) RemoveFailedNode(node string) error {
// Construct the message to broadcast
msg := messageLeave{
LTime: s.clock.Time(),
Node: node,
}
s.clock.Increment()
// Process our own event
s.handleNodeLeaveIntent(&msg)
// If we have no members, then we don't need to broadcast
if !s.hasAliveMembers()... | go | func (s *Serf) RemoveFailedNode(node string) error {
// Construct the message to broadcast
msg := messageLeave{
LTime: s.clock.Time(),
Node: node,
}
s.clock.Increment()
// Process our own event
s.handleNodeLeaveIntent(&msg)
// If we have no members, then we don't need to broadcast
if !s.hasAliveMembers()... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"RemoveFailedNode",
"(",
"node",
"string",
")",
"error",
"{",
"// Construct the message to broadcast",
"msg",
":=",
"messageLeave",
"{",
"LTime",
":",
"s",
".",
"clock",
".",
"Time",
"(",
")",
",",
"Node",
":",
"node",
... | // RemoveFailedNode forcibly removes a failed node from the cluster
// immediately, instead of waiting for the reaper to eventually reclaim it.
// This also has the effect that Serf will no longer attempt to reconnect
// to this node. | [
"RemoveFailedNode",
"forcibly",
"removes",
"a",
"failed",
"node",
"from",
"the",
"cluster",
"immediately",
"instead",
"of",
"waiting",
"for",
"the",
"reaper",
"to",
"eventually",
"reclaim",
"it",
".",
"This",
"also",
"has",
"the",
"effect",
"that",
"Serf",
"wi... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L788-L818 | train |
hashicorp/serf | serf/serf.go | Shutdown | func (s *Serf) Shutdown() error {
s.stateLock.Lock()
defer s.stateLock.Unlock()
if s.state == SerfShutdown {
return nil
}
if s.state != SerfLeft {
s.logger.Printf("[WARN] serf: Shutdown without a Leave")
}
// Wait to close the shutdown channel until after we've shut down the
// memberlist and its associa... | go | func (s *Serf) Shutdown() error {
s.stateLock.Lock()
defer s.stateLock.Unlock()
if s.state == SerfShutdown {
return nil
}
if s.state != SerfLeft {
s.logger.Printf("[WARN] serf: Shutdown without a Leave")
}
// Wait to close the shutdown channel until after we've shut down the
// memberlist and its associa... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"Shutdown",
"(",
")",
"error",
"{",
"s",
".",
"stateLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"stateLock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"s",
".",
"state",
"==",
"SerfShutdown",
"{",
"retu... | // Shutdown forcefully shuts down the Serf instance, stopping all network
// activity and background maintenance associated with the instance.
//
// This is not a graceful shutdown, and should be preceded by a call
// to Leave. Otherwise, other nodes in the cluster will detect this node's
// exit as a node failure.
//
... | [
"Shutdown",
"forcefully",
"shuts",
"down",
"the",
"Serf",
"instance",
"stopping",
"all",
"network",
"activity",
"and",
"background",
"maintenance",
"associated",
"with",
"the",
"instance",
".",
"This",
"is",
"not",
"a",
"graceful",
"shutdown",
"and",
"should",
"... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L828-L856 | train |
hashicorp/serf | serf/serf.go | State | func (s *Serf) State() SerfState {
s.stateLock.Lock()
defer s.stateLock.Unlock()
return s.state
} | go | func (s *Serf) State() SerfState {
s.stateLock.Lock()
defer s.stateLock.Unlock()
return s.state
} | [
"func",
"(",
"s",
"*",
"Serf",
")",
"State",
"(",
")",
"SerfState",
"{",
"s",
".",
"stateLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"stateLock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"s",
".",
"state",
"\n",
"}"
] | // State is the current state of this Serf instance. | [
"State",
"is",
"the",
"current",
"state",
"of",
"this",
"Serf",
"instance",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L870-L874 | train |
hashicorp/serf | serf/serf.go | broadcast | func (s *Serf) broadcast(t messageType, msg interface{}, notify chan<- struct{}) error {
raw, err := encodeMessage(t, msg)
if err != nil {
return err
}
s.broadcasts.QueueBroadcast(&broadcast{
msg: raw,
notify: notify,
})
return nil
} | go | func (s *Serf) broadcast(t messageType, msg interface{}, notify chan<- struct{}) error {
raw, err := encodeMessage(t, msg)
if err != nil {
return err
}
s.broadcasts.QueueBroadcast(&broadcast{
msg: raw,
notify: notify,
})
return nil
} | [
"func",
"(",
"s",
"*",
"Serf",
")",
"broadcast",
"(",
"t",
"messageType",
",",
"msg",
"interface",
"{",
"}",
",",
"notify",
"chan",
"<-",
"struct",
"{",
"}",
")",
"error",
"{",
"raw",
",",
"err",
":=",
"encodeMessage",
"(",
"t",
",",
"msg",
")",
... | // broadcast takes a Serf message type, encodes it for the wire, and queues
// the broadcast. If a notify channel is given, this channel will be closed
// when the broadcast is sent. | [
"broadcast",
"takes",
"a",
"Serf",
"message",
"type",
"encodes",
"it",
"for",
"the",
"wire",
"and",
"queues",
"the",
"broadcast",
".",
"If",
"a",
"notify",
"channel",
"is",
"given",
"this",
"channel",
"will",
"be",
"closed",
"when",
"the",
"broadcast",
"is... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L879-L890 | train |
hashicorp/serf | serf/serf.go | handleNodeJoin | func (s *Serf) handleNodeJoin(n *memberlist.Node) {
s.memberLock.Lock()
defer s.memberLock.Unlock()
var oldStatus MemberStatus
member, ok := s.members[n.Name]
if !ok {
oldStatus = StatusNone
member = &memberState{
Member: Member{
Name: n.Name,
Addr: net.IP(n.Addr),
Port: n.Port,
Tags:... | go | func (s *Serf) handleNodeJoin(n *memberlist.Node) {
s.memberLock.Lock()
defer s.memberLock.Unlock()
var oldStatus MemberStatus
member, ok := s.members[n.Name]
if !ok {
oldStatus = StatusNone
member = &memberState{
Member: Member{
Name: n.Name,
Addr: net.IP(n.Addr),
Port: n.Port,
Tags:... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"handleNodeJoin",
"(",
"n",
"*",
"memberlist",
".",
"Node",
")",
"{",
"s",
".",
"memberLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"memberLock",
".",
"Unlock",
"(",
")",
"\n\n",
"var",
"oldStatus",
"Me... | // handleNodeJoin is called when a node join event is received
// from memberlist. | [
"handleNodeJoin",
"is",
"called",
"when",
"a",
"node",
"join",
"event",
"is",
"received",
"from",
"memberlist",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L894-L966 | train |
hashicorp/serf | serf/serf.go | handleNodeLeave | func (s *Serf) handleNodeLeave(n *memberlist.Node) {
s.memberLock.Lock()
defer s.memberLock.Unlock()
member, ok := s.members[n.Name]
if !ok {
// We've never even heard of this node that is supposedly
// leaving. Just ignore it completely.
return
}
switch member.Status {
case StatusLeaving:
member.Statu... | go | func (s *Serf) handleNodeLeave(n *memberlist.Node) {
s.memberLock.Lock()
defer s.memberLock.Unlock()
member, ok := s.members[n.Name]
if !ok {
// We've never even heard of this node that is supposedly
// leaving. Just ignore it completely.
return
}
switch member.Status {
case StatusLeaving:
member.Statu... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"handleNodeLeave",
"(",
"n",
"*",
"memberlist",
".",
"Node",
")",
"{",
"s",
".",
"memberLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"memberLock",
".",
"Unlock",
"(",
")",
"\n\n",
"member",
",",
"ok",
... | // handleNodeLeave is called when a node leave event is received
// from memberlist. | [
"handleNodeLeave",
"is",
"called",
"when",
"a",
"node",
"leave",
"event",
"is",
"received",
"from",
"memberlist",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L970-L1015 | train |
hashicorp/serf | serf/serf.go | handleNodeUpdate | func (s *Serf) handleNodeUpdate(n *memberlist.Node) {
s.memberLock.Lock()
defer s.memberLock.Unlock()
member, ok := s.members[n.Name]
if !ok {
// We've never even heard of this node that is updating.
// Just ignore it completely.
return
}
// Update the member attributes
member.Addr = net.IP(n.Addr)
memb... | go | func (s *Serf) handleNodeUpdate(n *memberlist.Node) {
s.memberLock.Lock()
defer s.memberLock.Unlock()
member, ok := s.members[n.Name]
if !ok {
// We've never even heard of this node that is updating.
// Just ignore it completely.
return
}
// Update the member attributes
member.Addr = net.IP(n.Addr)
memb... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"handleNodeUpdate",
"(",
"n",
"*",
"memberlist",
".",
"Node",
")",
"{",
"s",
".",
"memberLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"memberLock",
".",
"Unlock",
"(",
")",
"\n\n",
"member",
",",
"ok",
... | // handleNodeUpdate is called when a node meta data update
// has taken place | [
"handleNodeUpdate",
"is",
"called",
"when",
"a",
"node",
"meta",
"data",
"update",
"has",
"taken",
"place"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L1019-L1059 | train |
hashicorp/serf | serf/serf.go | handleNodeLeaveIntent | func (s *Serf) handleNodeLeaveIntent(leaveMsg *messageLeave) bool {
// Witness a potentially newer time
s.clock.Witness(leaveMsg.LTime)
s.memberLock.Lock()
defer s.memberLock.Unlock()
member, ok := s.members[leaveMsg.Node]
if !ok {
// Rebroadcast only if this was an update we hadn't seen before.
return upse... | go | func (s *Serf) handleNodeLeaveIntent(leaveMsg *messageLeave) bool {
// Witness a potentially newer time
s.clock.Witness(leaveMsg.LTime)
s.memberLock.Lock()
defer s.memberLock.Unlock()
member, ok := s.members[leaveMsg.Node]
if !ok {
// Rebroadcast only if this was an update we hadn't seen before.
return upse... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"handleNodeLeaveIntent",
"(",
"leaveMsg",
"*",
"messageLeave",
")",
"bool",
"{",
"// Witness a potentially newer time",
"s",
".",
"clock",
".",
"Witness",
"(",
"leaveMsg",
".",
"LTime",
")",
"\n\n",
"s",
".",
"memberLock",
... | // handleNodeLeaveIntent is called when an intent to leave is received. | [
"handleNodeLeaveIntent",
"is",
"called",
"when",
"an",
"intent",
"to",
"leave",
"is",
"received",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L1062-L1119 | train |
hashicorp/serf | serf/serf.go | handleNodeJoinIntent | func (s *Serf) handleNodeJoinIntent(joinMsg *messageJoin) bool {
// Witness a potentially newer time
s.clock.Witness(joinMsg.LTime)
s.memberLock.Lock()
defer s.memberLock.Unlock()
member, ok := s.members[joinMsg.Node]
if !ok {
// Rebroadcast only if this was an update we hadn't seen before.
return upsertInt... | go | func (s *Serf) handleNodeJoinIntent(joinMsg *messageJoin) bool {
// Witness a potentially newer time
s.clock.Witness(joinMsg.LTime)
s.memberLock.Lock()
defer s.memberLock.Unlock()
member, ok := s.members[joinMsg.Node]
if !ok {
// Rebroadcast only if this was an update we hadn't seen before.
return upsertInt... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"handleNodeJoinIntent",
"(",
"joinMsg",
"*",
"messageJoin",
")",
"bool",
"{",
"// Witness a potentially newer time",
"s",
".",
"clock",
".",
"Witness",
"(",
"joinMsg",
".",
"LTime",
")",
"\n\n",
"s",
".",
"memberLock",
"."... | // handleNodeJoinIntent is called when a node broadcasts a
// join message to set the lamport time of its join | [
"handleNodeJoinIntent",
"is",
"called",
"when",
"a",
"node",
"broadcasts",
"a",
"join",
"message",
"to",
"set",
"the",
"lamport",
"time",
"of",
"its",
"join"
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L1123-L1150 | train |
hashicorp/serf | serf/serf.go | handleUserEvent | func (s *Serf) handleUserEvent(eventMsg *messageUserEvent) bool {
// Witness a potentially newer time
s.eventClock.Witness(eventMsg.LTime)
s.eventLock.Lock()
defer s.eventLock.Unlock()
// Ignore if it is before our minimum event time
if eventMsg.LTime < s.eventMinTime {
return false
}
// Check if this mess... | go | func (s *Serf) handleUserEvent(eventMsg *messageUserEvent) bool {
// Witness a potentially newer time
s.eventClock.Witness(eventMsg.LTime)
s.eventLock.Lock()
defer s.eventLock.Unlock()
// Ignore if it is before our minimum event time
if eventMsg.LTime < s.eventMinTime {
return false
}
// Check if this mess... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"handleUserEvent",
"(",
"eventMsg",
"*",
"messageUserEvent",
")",
"bool",
"{",
"// Witness a potentially newer time",
"s",
".",
"eventClock",
".",
"Witness",
"(",
"eventMsg",
".",
"LTime",
")",
"\n\n",
"s",
".",
"eventLock",... | // handleUserEvent is called when a user event broadcast is
// received. Returns if the message should be rebroadcast. | [
"handleUserEvent",
"is",
"called",
"when",
"a",
"user",
"event",
"broadcast",
"is",
"received",
".",
"Returns",
"if",
"the",
"message",
"should",
"be",
"rebroadcast",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L1154-L1209 | train |
hashicorp/serf | serf/serf.go | handleQueryResponse | func (s *Serf) handleQueryResponse(resp *messageQueryResponse) {
// Look for a corresponding QueryResponse
s.queryLock.RLock()
query, ok := s.queryResponse[resp.LTime]
s.queryLock.RUnlock()
if !ok {
s.logger.Printf("[WARN] serf: reply for non-running query (LTime: %d, ID: %d) From: %s",
resp.LTime, resp.ID, r... | go | func (s *Serf) handleQueryResponse(resp *messageQueryResponse) {
// Look for a corresponding QueryResponse
s.queryLock.RLock()
query, ok := s.queryResponse[resp.LTime]
s.queryLock.RUnlock()
if !ok {
s.logger.Printf("[WARN] serf: reply for non-running query (LTime: %d, ID: %d) From: %s",
resp.LTime, resp.ID, r... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"handleQueryResponse",
"(",
"resp",
"*",
"messageQueryResponse",
")",
"{",
"// Look for a corresponding QueryResponse",
"s",
".",
"queryLock",
".",
"RLock",
"(",
")",
"\n",
"query",
",",
"ok",
":=",
"s",
".",
"queryResponse"... | // handleResponse is called when a query response is
// received. | [
"handleResponse",
"is",
"called",
"when",
"a",
"query",
"response",
"is",
"received",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L1312-L1363 | train |
hashicorp/serf | serf/serf.go | resolveNodeConflict | func (s *Serf) resolveNodeConflict() {
// Get the local node
local := s.memberlist.LocalNode()
// Start a name resolution query
qName := internalQueryName(conflictQuery)
payload := []byte(s.config.NodeName)
resp, err := s.Query(qName, payload, nil)
if err != nil {
s.logger.Printf("[ERR] serf: Failed to start ... | go | func (s *Serf) resolveNodeConflict() {
// Get the local node
local := s.memberlist.LocalNode()
// Start a name resolution query
qName := internalQueryName(conflictQuery)
payload := []byte(s.config.NodeName)
resp, err := s.Query(qName, payload, nil)
if err != nil {
s.logger.Printf("[ERR] serf: Failed to start ... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"resolveNodeConflict",
"(",
")",
"{",
"// Get the local node",
"local",
":=",
"s",
".",
"memberlist",
".",
"LocalNode",
"(",
")",
"\n\n",
"// Start a name resolution query",
"qName",
":=",
"internalQueryName",
"(",
"conflictQuer... | // resolveNodeConflict is used to determine which node should remain during
// a name conflict. This is done by running an internal query. | [
"resolveNodeConflict",
"is",
"used",
"to",
"determine",
"which",
"node",
"should",
"remain",
"during",
"a",
"name",
"conflict",
".",
"This",
"is",
"done",
"by",
"running",
"an",
"internal",
"query",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L1388-L1439 | train |
hashicorp/serf | serf/serf.go | handleReap | func (s *Serf) handleReap() {
for {
select {
case <-time.After(s.config.ReapInterval):
s.memberLock.Lock()
now := time.Now()
s.failedMembers = s.reap(s.failedMembers, now, s.config.ReconnectTimeout)
s.leftMembers = s.reap(s.leftMembers, now, s.config.TombstoneTimeout)
reapIntents(s.recentIntents, no... | go | func (s *Serf) handleReap() {
for {
select {
case <-time.After(s.config.ReapInterval):
s.memberLock.Lock()
now := time.Now()
s.failedMembers = s.reap(s.failedMembers, now, s.config.ReconnectTimeout)
s.leftMembers = s.reap(s.leftMembers, now, s.config.TombstoneTimeout)
reapIntents(s.recentIntents, no... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"handleReap",
"(",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"<-",
"time",
".",
"After",
"(",
"s",
".",
"config",
".",
"ReapInterval",
")",
":",
"s",
".",
"memberLock",
".",
"Lock",
"(",
")",
"\n",
"now",
... | // handleReap periodically reaps the list of failed and left members, as well
// as old buffered intents. | [
"handleReap",
"periodically",
"reaps",
"the",
"list",
"of",
"failed",
"and",
"left",
"members",
"as",
"well",
"as",
"old",
"buffered",
"intents",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L1443-L1457 | train |
hashicorp/serf | serf/serf.go | handleReconnect | func (s *Serf) handleReconnect() {
for {
select {
case <-time.After(s.config.ReconnectInterval):
s.reconnect()
case <-s.shutdownCh:
return
}
}
} | go | func (s *Serf) handleReconnect() {
for {
select {
case <-time.After(s.config.ReconnectInterval):
s.reconnect()
case <-s.shutdownCh:
return
}
}
} | [
"func",
"(",
"s",
"*",
"Serf",
")",
"handleReconnect",
"(",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"<-",
"time",
".",
"After",
"(",
"s",
".",
"config",
".",
"ReconnectInterval",
")",
":",
"s",
".",
"reconnect",
"(",
")",
"\n",
"case",
"<-",
... | // handleReconnect attempts to reconnect to recently failed nodes
// on configured intervals. | [
"handleReconnect",
"attempts",
"to",
"reconnect",
"to",
"recently",
"failed",
"nodes",
"on",
"configured",
"intervals",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L1461-L1470 | train |
hashicorp/serf | serf/serf.go | reap | func (s *Serf) reap(old []*memberState, now time.Time, timeout time.Duration) []*memberState {
n := len(old)
for i := 0; i < n; i++ {
m := old[i]
// Skip if the timeout is not yet reached
if now.Sub(m.leaveTime) <= timeout {
continue
}
// Delete from the list
old[i], old[n-1] = old[n-1], nil
old = ... | go | func (s *Serf) reap(old []*memberState, now time.Time, timeout time.Duration) []*memberState {
n := len(old)
for i := 0; i < n; i++ {
m := old[i]
// Skip if the timeout is not yet reached
if now.Sub(m.leaveTime) <= timeout {
continue
}
// Delete from the list
old[i], old[n-1] = old[n-1], nil
old = ... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"reap",
"(",
"old",
"[",
"]",
"*",
"memberState",
",",
"now",
"time",
".",
"Time",
",",
"timeout",
"time",
".",
"Duration",
")",
"[",
"]",
"*",
"memberState",
"{",
"n",
":=",
"len",
"(",
"old",
")",
"\n",
"fo... | // reap is called with a list of old members and a timeout, and removes
// members that have exceeded the timeout. The members are removed from
// both the old list and the members itself. Locking is left to the caller. | [
"reap",
"is",
"called",
"with",
"a",
"list",
"of",
"old",
"members",
"and",
"a",
"timeout",
"and",
"removes",
"members",
"that",
"have",
"exceeded",
"the",
"timeout",
".",
"The",
"members",
"are",
"removed",
"from",
"both",
"the",
"old",
"list",
"and",
"... | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L1475-L1515 | train |
hashicorp/serf | serf/serf.go | reconnect | func (s *Serf) reconnect() {
s.memberLock.RLock()
// Nothing to do if there are no failed members
n := len(s.failedMembers)
if n == 0 {
s.memberLock.RUnlock()
return
}
// Probability we should attempt to reconect is given
// by num failed / (num members - num failed - num left)
// This means that we proba... | go | func (s *Serf) reconnect() {
s.memberLock.RLock()
// Nothing to do if there are no failed members
n := len(s.failedMembers)
if n == 0 {
s.memberLock.RUnlock()
return
}
// Probability we should attempt to reconect is given
// by num failed / (num members - num failed - num left)
// This means that we proba... | [
"func",
"(",
"s",
"*",
"Serf",
")",
"reconnect",
"(",
")",
"{",
"s",
".",
"memberLock",
".",
"RLock",
"(",
")",
"\n\n",
"// Nothing to do if there are no failed members",
"n",
":=",
"len",
"(",
"s",
".",
"failedMembers",
")",
"\n",
"if",
"n",
"==",
"0",
... | // reconnect attempts to reconnect to recently fail nodes. | [
"reconnect",
"attempts",
"to",
"reconnect",
"to",
"recently",
"fail",
"nodes",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L1518-L1556 | train |
hashicorp/serf | serf/serf.go | getQueueMax | func (s *Serf) getQueueMax() int {
max := s.config.MaxQueueDepth
if s.config.MinQueueDepth > 0 {
s.memberLock.RLock()
max = 2 * len(s.members)
s.memberLock.RUnlock()
if max < s.config.MinQueueDepth {
max = s.config.MinQueueDepth
}
}
return max
} | go | func (s *Serf) getQueueMax() int {
max := s.config.MaxQueueDepth
if s.config.MinQueueDepth > 0 {
s.memberLock.RLock()
max = 2 * len(s.members)
s.memberLock.RUnlock()
if max < s.config.MinQueueDepth {
max = s.config.MinQueueDepth
}
}
return max
} | [
"func",
"(",
"s",
"*",
"Serf",
")",
"getQueueMax",
"(",
")",
"int",
"{",
"max",
":=",
"s",
".",
"config",
".",
"MaxQueueDepth",
"\n",
"if",
"s",
".",
"config",
".",
"MinQueueDepth",
">",
"0",
"{",
"s",
".",
"memberLock",
".",
"RLock",
"(",
")",
"... | // getQueueMax will get the maximum queue depth, which might be dynamic depending
// on how Serf is configured. | [
"getQueueMax",
"will",
"get",
"the",
"maximum",
"queue",
"depth",
"which",
"might",
"be",
"dynamic",
"depending",
"on",
"how",
"Serf",
"is",
"configured",
"."
] | 15cfd05de3dffb3664aa37b06e91f970b825e380 | https://github.com/hashicorp/serf/blob/15cfd05de3dffb3664aa37b06e91f970b825e380/serf/serf.go#L1560-L1572 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.