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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
pilosa/pilosa
|
cluster.go
|
listenForJoins
|
func (c *cluster) listenForJoins() {
c.wg.Add(1)
go func() {
defer c.wg.Done()
// When a cluster starts, the state is STARTING.
// We first want to wait for at least one node to join.
// Then we want to clear out the joiningLeavingNodes queue (buffered channel).
// Then we want to set the cluster state to NORMAL and resume processing of joiningLeavingNodes events.
// We use a bool `setNormal` to indicate when at least one node has joined.
var setNormal bool
for {
// Handle all pending joins before changing state back to NORMAL.
select {
case nodeAction := <-c.joiningLeavingNodes:
err := c.handleNodeAction(nodeAction)
if err != nil {
c.logger.Printf("handleNodeAction error: err=%s", err)
continue
}
setNormal = true
continue
default:
}
// Only change state to NORMAL if we have successfully added at least one host.
if setNormal {
// Put the cluster back to state NORMAL and broadcast.
if err := c.setStateAndBroadcast(ClusterStateNormal); err != nil {
c.logger.Printf("setStateAndBroadcast error: err=%s", err)
}
}
// Wait for a joining host or a close.
select {
case <-c.closing:
return
case nodeAction := <-c.joiningLeavingNodes:
err := c.handleNodeAction(nodeAction)
if err != nil {
c.logger.Printf("handleNodeAction error: err=%s", err)
continue
}
setNormal = true
continue
}
}
}()
}
|
go
|
func (c *cluster) listenForJoins() {
c.wg.Add(1)
go func() {
defer c.wg.Done()
// When a cluster starts, the state is STARTING.
// We first want to wait for at least one node to join.
// Then we want to clear out the joiningLeavingNodes queue (buffered channel).
// Then we want to set the cluster state to NORMAL and resume processing of joiningLeavingNodes events.
// We use a bool `setNormal` to indicate when at least one node has joined.
var setNormal bool
for {
// Handle all pending joins before changing state back to NORMAL.
select {
case nodeAction := <-c.joiningLeavingNodes:
err := c.handleNodeAction(nodeAction)
if err != nil {
c.logger.Printf("handleNodeAction error: err=%s", err)
continue
}
setNormal = true
continue
default:
}
// Only change state to NORMAL if we have successfully added at least one host.
if setNormal {
// Put the cluster back to state NORMAL and broadcast.
if err := c.setStateAndBroadcast(ClusterStateNormal); err != nil {
c.logger.Printf("setStateAndBroadcast error: err=%s", err)
}
}
// Wait for a joining host or a close.
select {
case <-c.closing:
return
case nodeAction := <-c.joiningLeavingNodes:
err := c.handleNodeAction(nodeAction)
if err != nil {
c.logger.Printf("handleNodeAction error: err=%s", err)
continue
}
setNormal = true
continue
}
}
}()
}
|
[
"func",
"(",
"c",
"*",
"cluster",
")",
"listenForJoins",
"(",
")",
"{",
"c",
".",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"c",
".",
"wg",
".",
"Done",
"(",
")",
"\n\n",
"// When a cluster starts, the state is STARTING.",
"// We first want to wait for at least one node to join.",
"// Then we want to clear out the joiningLeavingNodes queue (buffered channel).",
"// Then we want to set the cluster state to NORMAL and resume processing of joiningLeavingNodes events.",
"// We use a bool `setNormal` to indicate when at least one node has joined.",
"var",
"setNormal",
"bool",
"\n\n",
"for",
"{",
"// Handle all pending joins before changing state back to NORMAL.",
"select",
"{",
"case",
"nodeAction",
":=",
"<-",
"c",
".",
"joiningLeavingNodes",
":",
"err",
":=",
"c",
".",
"handleNodeAction",
"(",
"nodeAction",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"setNormal",
"=",
"true",
"\n",
"continue",
"\n",
"default",
":",
"}",
"\n\n",
"// Only change state to NORMAL if we have successfully added at least one host.",
"if",
"setNormal",
"{",
"// Put the cluster back to state NORMAL and broadcast.",
"if",
"err",
":=",
"c",
".",
"setStateAndBroadcast",
"(",
"ClusterStateNormal",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Wait for a joining host or a close.",
"select",
"{",
"case",
"<-",
"c",
".",
"closing",
":",
"return",
"\n",
"case",
"nodeAction",
":=",
"<-",
"c",
".",
"joiningLeavingNodes",
":",
"err",
":=",
"c",
".",
"handleNodeAction",
"(",
"nodeAction",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"setNormal",
"=",
"true",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"}"
] |
// listenForJoins handles cluster-resize events.
|
[
"listenForJoins",
"handles",
"cluster",
"-",
"resize",
"events",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1110-L1160
|
train
|
pilosa/pilosa
|
cluster.go
|
completeCurrentJob
|
func (c *cluster) completeCurrentJob(state string) error {
c.mu.Lock()
defer c.mu.Unlock()
return c.unprotectedCompleteCurrentJob(state)
}
|
go
|
func (c *cluster) completeCurrentJob(state string) error {
c.mu.Lock()
defer c.mu.Unlock()
return c.unprotectedCompleteCurrentJob(state)
}
|
[
"func",
"(",
"c",
"*",
"cluster",
")",
"completeCurrentJob",
"(",
"state",
"string",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"c",
".",
"unprotectedCompleteCurrentJob",
"(",
"state",
")",
"\n",
"}"
] |
// completeCurrentJob sets the state of the current resizeJob
// then removes the pointer to currentJob.
|
[
"completeCurrentJob",
"sets",
"the",
"state",
"of",
"the",
"current",
"resizeJob",
"then",
"removes",
"the",
"pointer",
"to",
"currentJob",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1247-L1251
|
train
|
pilosa/pilosa
|
cluster.go
|
job
|
func (c *cluster) job(id int64) *resizeJob {
c.mu.RLock()
defer c.mu.RUnlock()
return c.jobs[id]
}
|
go
|
func (c *cluster) job(id int64) *resizeJob {
c.mu.RLock()
defer c.mu.RUnlock()
return c.jobs[id]
}
|
[
"func",
"(",
"c",
"*",
"cluster",
")",
"job",
"(",
"id",
"int64",
")",
"*",
"resizeJob",
"{",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"c",
".",
"jobs",
"[",
"id",
"]",
"\n",
"}"
] |
// job returns a resizeJob by id.
|
[
"job",
"returns",
"a",
"resizeJob",
"by",
"id",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1410-L1414
|
train
|
pilosa/pilosa
|
cluster.go
|
newResizeJob
|
func newResizeJob(existingNodes []*Node, node *Node, action string) *resizeJob {
// Build a map of uris to track their resize status.
// The value for a node will be set to true after that node
// has indicated that it has completed all resize instructions.
ids := make(map[string]bool)
if action == resizeJobActionRemove {
for _, n := range existingNodes {
// Exclude the removed node from the map.
if n.ID == node.ID {
continue
}
ids[n.ID] = false
}
} else if action == resizeJobActionAdd {
for _, n := range existingNodes {
ids[n.ID] = false
}
// Include the added node in the map for tracking.
ids[node.ID] = false
}
return &resizeJob{
ID: rand.Int63(),
IDs: ids,
action: action,
result: make(chan string),
Logger: logger.NopLogger,
}
}
|
go
|
func newResizeJob(existingNodes []*Node, node *Node, action string) *resizeJob {
// Build a map of uris to track their resize status.
// The value for a node will be set to true after that node
// has indicated that it has completed all resize instructions.
ids := make(map[string]bool)
if action == resizeJobActionRemove {
for _, n := range existingNodes {
// Exclude the removed node from the map.
if n.ID == node.ID {
continue
}
ids[n.ID] = false
}
} else if action == resizeJobActionAdd {
for _, n := range existingNodes {
ids[n.ID] = false
}
// Include the added node in the map for tracking.
ids[node.ID] = false
}
return &resizeJob{
ID: rand.Int63(),
IDs: ids,
action: action,
result: make(chan string),
Logger: logger.NopLogger,
}
}
|
[
"func",
"newResizeJob",
"(",
"existingNodes",
"[",
"]",
"*",
"Node",
",",
"node",
"*",
"Node",
",",
"action",
"string",
")",
"*",
"resizeJob",
"{",
"// Build a map of uris to track their resize status.",
"// The value for a node will be set to true after that node",
"// has indicated that it has completed all resize instructions.",
"ids",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n\n",
"if",
"action",
"==",
"resizeJobActionRemove",
"{",
"for",
"_",
",",
"n",
":=",
"range",
"existingNodes",
"{",
"// Exclude the removed node from the map.",
"if",
"n",
".",
"ID",
"==",
"node",
".",
"ID",
"{",
"continue",
"\n",
"}",
"\n",
"ids",
"[",
"n",
".",
"ID",
"]",
"=",
"false",
"\n",
"}",
"\n",
"}",
"else",
"if",
"action",
"==",
"resizeJobActionAdd",
"{",
"for",
"_",
",",
"n",
":=",
"range",
"existingNodes",
"{",
"ids",
"[",
"n",
".",
"ID",
"]",
"=",
"false",
"\n",
"}",
"\n",
"// Include the added node in the map for tracking.",
"ids",
"[",
"node",
".",
"ID",
"]",
"=",
"false",
"\n",
"}",
"\n\n",
"return",
"&",
"resizeJob",
"{",
"ID",
":",
"rand",
".",
"Int63",
"(",
")",
",",
"IDs",
":",
"ids",
",",
"action",
":",
"action",
",",
"result",
":",
"make",
"(",
"chan",
"string",
")",
",",
"Logger",
":",
"logger",
".",
"NopLogger",
",",
"}",
"\n",
"}"
] |
// newResizeJob returns a new instance of resizeJob.
|
[
"newResizeJob",
"returns",
"a",
"new",
"instance",
"of",
"resizeJob",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1432-L1462
|
train
|
pilosa/pilosa
|
cluster.go
|
run
|
func (j *resizeJob) run() error {
j.Logger.Printf("run resizeJob")
// Set job state to RUNNING.
j.setState(resizeJobStateRunning)
// Job can be considered done in the case where it doesn't require any action.
if !j.nodesArePending() {
j.Logger.Printf("resizeJob contains no pending tasks; mark as done")
j.result <- resizeJobStateDone
return nil
}
j.Logger.Printf("distribute tasks for resizeJob")
err := j.distributeResizeInstructions()
if err != nil {
j.result <- resizeJobStateAborted
return errors.Wrap(err, "distributing instructions")
}
return nil
}
|
go
|
func (j *resizeJob) run() error {
j.Logger.Printf("run resizeJob")
// Set job state to RUNNING.
j.setState(resizeJobStateRunning)
// Job can be considered done in the case where it doesn't require any action.
if !j.nodesArePending() {
j.Logger.Printf("resizeJob contains no pending tasks; mark as done")
j.result <- resizeJobStateDone
return nil
}
j.Logger.Printf("distribute tasks for resizeJob")
err := j.distributeResizeInstructions()
if err != nil {
j.result <- resizeJobStateAborted
return errors.Wrap(err, "distributing instructions")
}
return nil
}
|
[
"func",
"(",
"j",
"*",
"resizeJob",
")",
"run",
"(",
")",
"error",
"{",
"j",
".",
"Logger",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"// Set job state to RUNNING.",
"j",
".",
"setState",
"(",
"resizeJobStateRunning",
")",
"\n\n",
"// Job can be considered done in the case where it doesn't require any action.",
"if",
"!",
"j",
".",
"nodesArePending",
"(",
")",
"{",
"j",
".",
"Logger",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"j",
".",
"result",
"<-",
"resizeJobStateDone",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"j",
".",
"Logger",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"err",
":=",
"j",
".",
"distributeResizeInstructions",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"j",
".",
"result",
"<-",
"resizeJobStateAborted",
"\n",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// run distributes ResizeInstructions.
|
[
"run",
"distributes",
"ResizeInstructions",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1473-L1492
|
train
|
pilosa/pilosa
|
cluster.go
|
isComplete
|
func (j *resizeJob) isComplete() bool {
switch j.state {
case resizeJobStateDone, resizeJobStateAborted:
return true
default:
return false
}
}
|
go
|
func (j *resizeJob) isComplete() bool {
switch j.state {
case resizeJobStateDone, resizeJobStateAborted:
return true
default:
return false
}
}
|
[
"func",
"(",
"j",
"*",
"resizeJob",
")",
"isComplete",
"(",
")",
"bool",
"{",
"switch",
"j",
".",
"state",
"{",
"case",
"resizeJobStateDone",
",",
"resizeJobStateAborted",
":",
"return",
"true",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"}"
] |
// isComplete return true if the job is any one of several completion states.
|
[
"isComplete",
"return",
"true",
"if",
"the",
"job",
"is",
"any",
"one",
"of",
"several",
"completion",
"states",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1495-L1502
|
train
|
pilosa/pilosa
|
cluster.go
|
nodesArePending
|
func (j *resizeJob) nodesArePending() bool {
for _, complete := range j.IDs {
if !complete {
return true
}
}
return false
}
|
go
|
func (j *resizeJob) nodesArePending() bool {
for _, complete := range j.IDs {
if !complete {
return true
}
}
return false
}
|
[
"func",
"(",
"j",
"*",
"resizeJob",
")",
"nodesArePending",
"(",
")",
"bool",
"{",
"for",
"_",
",",
"complete",
":=",
"range",
"j",
".",
"IDs",
"{",
"if",
"!",
"complete",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// nodesArePending returns true if any node is still working on the resize.
|
[
"nodesArePending",
"returns",
"true",
"if",
"any",
"node",
"is",
"still",
"working",
"on",
"the",
"resize",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1505-L1512
|
train
|
pilosa/pilosa
|
cluster.go
|
ContainsID
|
func (n nodeIDs) ContainsID(id string) bool {
for _, nid := range n {
if nid == id {
return true
}
}
return false
}
|
go
|
func (n nodeIDs) ContainsID(id string) bool {
for _, nid := range n {
if nid == id {
return true
}
}
return false
}
|
[
"func",
"(",
"n",
"nodeIDs",
")",
"ContainsID",
"(",
"id",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"nid",
":=",
"range",
"n",
"{",
"if",
"nid",
"==",
"id",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// ContainsID returns true if idi matches one of the nodesets's IDs.
|
[
"ContainsID",
"returns",
"true",
"if",
"idi",
"matches",
"one",
"of",
"the",
"nodesets",
"s",
"IDs",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1539-L1546
|
train
|
pilosa/pilosa
|
cluster.go
|
ContainsID
|
func (t *Topology) ContainsID(id string) bool {
t.mu.RLock()
defer t.mu.RUnlock()
return t.containsID(id)
}
|
go
|
func (t *Topology) ContainsID(id string) bool {
t.mu.RLock()
defer t.mu.RUnlock()
return t.containsID(id)
}
|
[
"func",
"(",
"t",
"*",
"Topology",
")",
"ContainsID",
"(",
"id",
"string",
")",
"bool",
"{",
"t",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"t",
".",
"containsID",
"(",
"id",
")",
"\n",
"}"
] |
// ContainsID returns true if id matches one of the topology's IDs.
|
[
"ContainsID",
"returns",
"true",
"if",
"id",
"matches",
"one",
"of",
"the",
"topology",
"s",
"IDs",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1567-L1571
|
train
|
pilosa/pilosa
|
cluster.go
|
addID
|
func (t *Topology) addID(nodeID string) bool {
t.mu.Lock()
defer t.mu.Unlock()
if t.containsID(nodeID) {
return false
}
t.nodeIDs = append(t.nodeIDs, nodeID)
sort.Slice(t.nodeIDs,
func(i, j int) bool {
return t.nodeIDs[i] < t.nodeIDs[j]
})
return true
}
|
go
|
func (t *Topology) addID(nodeID string) bool {
t.mu.Lock()
defer t.mu.Unlock()
if t.containsID(nodeID) {
return false
}
t.nodeIDs = append(t.nodeIDs, nodeID)
sort.Slice(t.nodeIDs,
func(i, j int) bool {
return t.nodeIDs[i] < t.nodeIDs[j]
})
return true
}
|
[
"func",
"(",
"t",
"*",
"Topology",
")",
"addID",
"(",
"nodeID",
"string",
")",
"bool",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"t",
".",
"containsID",
"(",
"nodeID",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"t",
".",
"nodeIDs",
"=",
"append",
"(",
"t",
".",
"nodeIDs",
",",
"nodeID",
")",
"\n\n",
"sort",
".",
"Slice",
"(",
"t",
".",
"nodeIDs",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"t",
".",
"nodeIDs",
"[",
"i",
"]",
"<",
"t",
".",
"nodeIDs",
"[",
"j",
"]",
"\n",
"}",
")",
"\n\n",
"return",
"true",
"\n",
"}"
] |
// addID adds the node ID to the topology and returns true if added.
|
[
"addID",
"adds",
"the",
"node",
"ID",
"to",
"the",
"topology",
"and",
"returns",
"true",
"if",
"added",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1587-L1601
|
train
|
pilosa/pilosa
|
cluster.go
|
removeID
|
func (t *Topology) removeID(nodeID string) bool {
t.mu.Lock()
defer t.mu.Unlock()
i := t.positionByID(nodeID)
if i < 0 {
return false
}
copy(t.nodeIDs[i:], t.nodeIDs[i+1:])
t.nodeIDs[len(t.nodeIDs)-1] = ""
t.nodeIDs = t.nodeIDs[:len(t.nodeIDs)-1]
return true
}
|
go
|
func (t *Topology) removeID(nodeID string) bool {
t.mu.Lock()
defer t.mu.Unlock()
i := t.positionByID(nodeID)
if i < 0 {
return false
}
copy(t.nodeIDs[i:], t.nodeIDs[i+1:])
t.nodeIDs[len(t.nodeIDs)-1] = ""
t.nodeIDs = t.nodeIDs[:len(t.nodeIDs)-1]
return true
}
|
[
"func",
"(",
"t",
"*",
"Topology",
")",
"removeID",
"(",
"nodeID",
"string",
")",
"bool",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"i",
":=",
"t",
".",
"positionByID",
"(",
"nodeID",
")",
"\n",
"if",
"i",
"<",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"copy",
"(",
"t",
".",
"nodeIDs",
"[",
"i",
":",
"]",
",",
"t",
".",
"nodeIDs",
"[",
"i",
"+",
"1",
":",
"]",
")",
"\n",
"t",
".",
"nodeIDs",
"[",
"len",
"(",
"t",
".",
"nodeIDs",
")",
"-",
"1",
"]",
"=",
"\"",
"\"",
"\n",
"t",
".",
"nodeIDs",
"=",
"t",
".",
"nodeIDs",
"[",
":",
"len",
"(",
"t",
".",
"nodeIDs",
")",
"-",
"1",
"]",
"\n\n",
"return",
"true",
"\n",
"}"
] |
// removeID removes the node ID from the topology and returns true if removed.
|
[
"removeID",
"removes",
"the",
"node",
"ID",
"from",
"the",
"topology",
"and",
"returns",
"true",
"if",
"removed",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1604-L1618
|
train
|
pilosa/pilosa
|
cluster.go
|
loadTopology
|
func (c *cluster) loadTopology() error {
buf, err := ioutil.ReadFile(filepath.Join(c.Path, ".topology"))
if os.IsNotExist(err) {
c.Topology = newTopology()
return nil
} else if err != nil {
return errors.Wrap(err, "reading file")
}
var pb internal.Topology
if err := proto.Unmarshal(buf, &pb); err != nil {
return errors.Wrap(err, "unmarshalling")
}
top, err := decodeTopology(&pb)
if err != nil {
return errors.Wrap(err, "decoding")
}
c.Topology = top
return nil
}
|
go
|
func (c *cluster) loadTopology() error {
buf, err := ioutil.ReadFile(filepath.Join(c.Path, ".topology"))
if os.IsNotExist(err) {
c.Topology = newTopology()
return nil
} else if err != nil {
return errors.Wrap(err, "reading file")
}
var pb internal.Topology
if err := proto.Unmarshal(buf, &pb); err != nil {
return errors.Wrap(err, "unmarshalling")
}
top, err := decodeTopology(&pb)
if err != nil {
return errors.Wrap(err, "decoding")
}
c.Topology = top
return nil
}
|
[
"func",
"(",
"c",
"*",
"cluster",
")",
"loadTopology",
"(",
")",
"error",
"{",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filepath",
".",
"Join",
"(",
"c",
".",
"Path",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"c",
".",
"Topology",
"=",
"newTopology",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"pb",
"internal",
".",
"Topology",
"\n",
"if",
"err",
":=",
"proto",
".",
"Unmarshal",
"(",
"buf",
",",
"&",
"pb",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"top",
",",
"err",
":=",
"decodeTopology",
"(",
"&",
"pb",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"c",
".",
"Topology",
"=",
"top",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// loadTopology reads the topology for the node. unprotected.
|
[
"loadTopology",
"reads",
"the",
"topology",
"for",
"the",
"node",
".",
"unprotected",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1626-L1646
|
train
|
pilosa/pilosa
|
cluster.go
|
saveTopology
|
func (c *cluster) saveTopology() error {
if err := os.MkdirAll(c.Path, 0777); err != nil {
return errors.Wrap(err, "creating directory")
}
if buf, err := proto.Marshal(encodeTopology(c.Topology)); err != nil {
return errors.Wrap(err, "marshalling")
} else if err := ioutil.WriteFile(filepath.Join(c.Path, ".topology"), buf, 0666); err != nil {
return errors.Wrap(err, "writing file")
}
return nil
}
|
go
|
func (c *cluster) saveTopology() error {
if err := os.MkdirAll(c.Path, 0777); err != nil {
return errors.Wrap(err, "creating directory")
}
if buf, err := proto.Marshal(encodeTopology(c.Topology)); err != nil {
return errors.Wrap(err, "marshalling")
} else if err := ioutil.WriteFile(filepath.Join(c.Path, ".topology"), buf, 0666); err != nil {
return errors.Wrap(err, "writing file")
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"cluster",
")",
"saveTopology",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"c",
".",
"Path",
",",
"0777",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"buf",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"encodeTopology",
"(",
"c",
".",
"Topology",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"err",
":=",
"ioutil",
".",
"WriteFile",
"(",
"filepath",
".",
"Join",
"(",
"c",
".",
"Path",
",",
"\"",
"\"",
")",
",",
"buf",
",",
"0666",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// saveTopology writes the current topology to disk. unprotected.
|
[
"saveTopology",
"writes",
"the",
"current",
"topology",
"to",
"disk",
".",
"unprotected",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1649-L1661
|
train
|
pilosa/pilosa
|
cluster.go
|
ReceiveEvent
|
func (c *cluster) ReceiveEvent(e *NodeEvent) (err error) {
// Ignore events sent from this node.
if e.Node.ID == c.Node.ID {
return nil
}
switch e.Event {
case NodeJoin:
c.logger.Debugf("nodeJoin of %s on %s", e.Node.URI, c.Node.URI)
// Ignore the event if this is not the coordinator.
if !c.isCoordinator() {
return nil
}
return c.nodeJoin(e.Node)
case NodeLeave:
c.mu.Lock()
defer c.mu.Unlock()
if c.unprotectedIsCoordinator() {
c.logger.Printf("received node leave: %v", e.Node)
// if removeNodeBasicSorted succeeds, that means that the node was
// not already removed by a removeNode request. We treat this as the
// host being temporarily unavailable, and expect it to come back
// up.
if c.removeNodeBasicSorted(e.Node.ID) {
c.Topology.nodeStates[e.Node.ID] = nodeStateDown
// put the cluster into STARTING if we've lost a number of nodes
// equal to or greater than ReplicaN
err = c.unprotectedSetStateAndBroadcast(c.determineClusterState())
}
}
case NodeUpdate:
c.logger.Printf("received node update event: id: %v, string: %v, uri: %v", e.Node.ID, e.Node.String(), e.Node.URI)
// NodeUpdate is intentionally not implemented.
}
return err
}
|
go
|
func (c *cluster) ReceiveEvent(e *NodeEvent) (err error) {
// Ignore events sent from this node.
if e.Node.ID == c.Node.ID {
return nil
}
switch e.Event {
case NodeJoin:
c.logger.Debugf("nodeJoin of %s on %s", e.Node.URI, c.Node.URI)
// Ignore the event if this is not the coordinator.
if !c.isCoordinator() {
return nil
}
return c.nodeJoin(e.Node)
case NodeLeave:
c.mu.Lock()
defer c.mu.Unlock()
if c.unprotectedIsCoordinator() {
c.logger.Printf("received node leave: %v", e.Node)
// if removeNodeBasicSorted succeeds, that means that the node was
// not already removed by a removeNode request. We treat this as the
// host being temporarily unavailable, and expect it to come back
// up.
if c.removeNodeBasicSorted(e.Node.ID) {
c.Topology.nodeStates[e.Node.ID] = nodeStateDown
// put the cluster into STARTING if we've lost a number of nodes
// equal to or greater than ReplicaN
err = c.unprotectedSetStateAndBroadcast(c.determineClusterState())
}
}
case NodeUpdate:
c.logger.Printf("received node update event: id: %v, string: %v, uri: %v", e.Node.ID, e.Node.String(), e.Node.URI)
// NodeUpdate is intentionally not implemented.
}
return err
}
|
[
"func",
"(",
"c",
"*",
"cluster",
")",
"ReceiveEvent",
"(",
"e",
"*",
"NodeEvent",
")",
"(",
"err",
"error",
")",
"{",
"// Ignore events sent from this node.",
"if",
"e",
".",
"Node",
".",
"ID",
"==",
"c",
".",
"Node",
".",
"ID",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"switch",
"e",
".",
"Event",
"{",
"case",
"NodeJoin",
":",
"c",
".",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"e",
".",
"Node",
".",
"URI",
",",
"c",
".",
"Node",
".",
"URI",
")",
"\n",
"// Ignore the event if this is not the coordinator.",
"if",
"!",
"c",
".",
"isCoordinator",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"c",
".",
"nodeJoin",
"(",
"e",
".",
"Node",
")",
"\n",
"case",
"NodeLeave",
":",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"c",
".",
"unprotectedIsCoordinator",
"(",
")",
"{",
"c",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"e",
".",
"Node",
")",
"\n",
"// if removeNodeBasicSorted succeeds, that means that the node was",
"// not already removed by a removeNode request. We treat this as the",
"// host being temporarily unavailable, and expect it to come back",
"// up.",
"if",
"c",
".",
"removeNodeBasicSorted",
"(",
"e",
".",
"Node",
".",
"ID",
")",
"{",
"c",
".",
"Topology",
".",
"nodeStates",
"[",
"e",
".",
"Node",
".",
"ID",
"]",
"=",
"nodeStateDown",
"\n",
"// put the cluster into STARTING if we've lost a number of nodes",
"// equal to or greater than ReplicaN",
"err",
"=",
"c",
".",
"unprotectedSetStateAndBroadcast",
"(",
"c",
".",
"determineClusterState",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"NodeUpdate",
":",
"c",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"e",
".",
"Node",
".",
"ID",
",",
"e",
".",
"Node",
".",
"String",
"(",
")",
",",
"e",
".",
"Node",
".",
"URI",
")",
"\n",
"// NodeUpdate is intentionally not implemented.",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] |
// ReceiveEvent represents an implementation of EventHandler.
|
[
"ReceiveEvent",
"represents",
"an",
"implementation",
"of",
"EventHandler",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1691-L1727
|
train
|
pilosa/pilosa
|
cluster.go
|
nodeJoin
|
func (c *cluster) nodeJoin(node *Node) error {
c.mu.Lock()
defer c.mu.Unlock()
c.logger.Printf("node join event on coordinator, node: %s, id: %s", node.URI, node.ID)
if c.needTopologyAgreement() {
// A host that is not part of the topology can't be added to the STARTING cluster.
if !c.Topology.ContainsID(node.ID) {
err := fmt.Sprintf("host is not in topology: %s", node.ID)
c.logger.Printf("%v", err)
return errors.New(err)
}
if err := c.addNode(node); err != nil {
return errors.Wrap(err, "adding node for agreement")
}
// Only change to normal if there is no existing data. Otherwise,
// the coordinator needs to wait to receive READY messages (nodeStates)
// from remote nodes before setting the cluster to state NORMAL.
if ok, err := c.holder.HasData(); !ok && err == nil {
// If the result of the previous AddNode completed the joining of nodes
// in the topology, then change the state to NORMAL.
if c.haveTopologyAgreement() {
return c.unprotectedSetStateAndBroadcast(ClusterStateNormal)
}
return nil
} else if err != nil {
return errors.Wrap(err, "checking if holder has data")
}
if c.haveTopologyAgreement() && c.allNodesReady() {
return c.unprotectedSetStateAndBroadcast(ClusterStateNormal)
}
// Send the status to the remote node. This lets the remote node
// know that it can proceed with opening its Holder.
return c.sendTo(node, c.unprotectedStatus())
}
// If the cluster already contains the node, just send it the cluster status.
// This is useful in the case where a node is restarted or temporarily leaves
// the cluster.
if cnode := c.unprotectedNodeByID(node.ID); cnode != nil {
if cnode.URI != node.URI {
c.logger.Printf("node: %v changed URI from %s to %s", cnode.ID, cnode.URI, node.URI)
cnode.URI = node.URI
}
return c.unprotectedSetStateAndBroadcast(c.determineClusterState())
}
// If the holder does not yet contain data, go ahead and add the node.
if ok, err := c.holder.HasData(); !ok && err == nil {
if err := c.addNode(node); err != nil {
return errors.Wrap(err, "adding node")
}
return c.unprotectedSetStateAndBroadcast(ClusterStateNormal)
} else if err != nil {
return errors.Wrap(err, "checking if holder has data2")
}
// If the cluster has data, we need to change to RESIZING and
// kick off the resizing process.
if err := c.unprotectedSetStateAndBroadcast(ClusterStateResizing); err != nil {
return errors.Wrap(err, "broadcasting state")
}
c.joiningLeavingNodes <- nodeAction{node, resizeJobActionAdd}
return nil
}
|
go
|
func (c *cluster) nodeJoin(node *Node) error {
c.mu.Lock()
defer c.mu.Unlock()
c.logger.Printf("node join event on coordinator, node: %s, id: %s", node.URI, node.ID)
if c.needTopologyAgreement() {
// A host that is not part of the topology can't be added to the STARTING cluster.
if !c.Topology.ContainsID(node.ID) {
err := fmt.Sprintf("host is not in topology: %s", node.ID)
c.logger.Printf("%v", err)
return errors.New(err)
}
if err := c.addNode(node); err != nil {
return errors.Wrap(err, "adding node for agreement")
}
// Only change to normal if there is no existing data. Otherwise,
// the coordinator needs to wait to receive READY messages (nodeStates)
// from remote nodes before setting the cluster to state NORMAL.
if ok, err := c.holder.HasData(); !ok && err == nil {
// If the result of the previous AddNode completed the joining of nodes
// in the topology, then change the state to NORMAL.
if c.haveTopologyAgreement() {
return c.unprotectedSetStateAndBroadcast(ClusterStateNormal)
}
return nil
} else if err != nil {
return errors.Wrap(err, "checking if holder has data")
}
if c.haveTopologyAgreement() && c.allNodesReady() {
return c.unprotectedSetStateAndBroadcast(ClusterStateNormal)
}
// Send the status to the remote node. This lets the remote node
// know that it can proceed with opening its Holder.
return c.sendTo(node, c.unprotectedStatus())
}
// If the cluster already contains the node, just send it the cluster status.
// This is useful in the case where a node is restarted or temporarily leaves
// the cluster.
if cnode := c.unprotectedNodeByID(node.ID); cnode != nil {
if cnode.URI != node.URI {
c.logger.Printf("node: %v changed URI from %s to %s", cnode.ID, cnode.URI, node.URI)
cnode.URI = node.URI
}
return c.unprotectedSetStateAndBroadcast(c.determineClusterState())
}
// If the holder does not yet contain data, go ahead and add the node.
if ok, err := c.holder.HasData(); !ok && err == nil {
if err := c.addNode(node); err != nil {
return errors.Wrap(err, "adding node")
}
return c.unprotectedSetStateAndBroadcast(ClusterStateNormal)
} else if err != nil {
return errors.Wrap(err, "checking if holder has data2")
}
// If the cluster has data, we need to change to RESIZING and
// kick off the resizing process.
if err := c.unprotectedSetStateAndBroadcast(ClusterStateResizing); err != nil {
return errors.Wrap(err, "broadcasting state")
}
c.joiningLeavingNodes <- nodeAction{node, resizeJobActionAdd}
return nil
}
|
[
"func",
"(",
"c",
"*",
"cluster",
")",
"nodeJoin",
"(",
"node",
"*",
"Node",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"c",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"node",
".",
"URI",
",",
"node",
".",
"ID",
")",
"\n",
"if",
"c",
".",
"needTopologyAgreement",
"(",
")",
"{",
"// A host that is not part of the topology can't be added to the STARTING cluster.",
"if",
"!",
"c",
".",
"Topology",
".",
"ContainsID",
"(",
"node",
".",
"ID",
")",
"{",
"err",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"node",
".",
"ID",
")",
"\n",
"c",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"addNode",
"(",
"node",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Only change to normal if there is no existing data. Otherwise,",
"// the coordinator needs to wait to receive READY messages (nodeStates)",
"// from remote nodes before setting the cluster to state NORMAL.",
"if",
"ok",
",",
"err",
":=",
"c",
".",
"holder",
".",
"HasData",
"(",
")",
";",
"!",
"ok",
"&&",
"err",
"==",
"nil",
"{",
"// If the result of the previous AddNode completed the joining of nodes",
"// in the topology, then change the state to NORMAL.",
"if",
"c",
".",
"haveTopologyAgreement",
"(",
")",
"{",
"return",
"c",
".",
"unprotectedSetStateAndBroadcast",
"(",
"ClusterStateNormal",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"haveTopologyAgreement",
"(",
")",
"&&",
"c",
".",
"allNodesReady",
"(",
")",
"{",
"return",
"c",
".",
"unprotectedSetStateAndBroadcast",
"(",
"ClusterStateNormal",
")",
"\n",
"}",
"\n",
"// Send the status to the remote node. This lets the remote node",
"// know that it can proceed with opening its Holder.",
"return",
"c",
".",
"sendTo",
"(",
"node",
",",
"c",
".",
"unprotectedStatus",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// If the cluster already contains the node, just send it the cluster status.",
"// This is useful in the case where a node is restarted or temporarily leaves",
"// the cluster.",
"if",
"cnode",
":=",
"c",
".",
"unprotectedNodeByID",
"(",
"node",
".",
"ID",
")",
";",
"cnode",
"!=",
"nil",
"{",
"if",
"cnode",
".",
"URI",
"!=",
"node",
".",
"URI",
"{",
"c",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"cnode",
".",
"ID",
",",
"cnode",
".",
"URI",
",",
"node",
".",
"URI",
")",
"\n",
"cnode",
".",
"URI",
"=",
"node",
".",
"URI",
"\n",
"}",
"\n",
"return",
"c",
".",
"unprotectedSetStateAndBroadcast",
"(",
"c",
".",
"determineClusterState",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// If the holder does not yet contain data, go ahead and add the node.",
"if",
"ok",
",",
"err",
":=",
"c",
".",
"holder",
".",
"HasData",
"(",
")",
";",
"!",
"ok",
"&&",
"err",
"==",
"nil",
"{",
"if",
"err",
":=",
"c",
".",
"addNode",
"(",
"node",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"unprotectedSetStateAndBroadcast",
"(",
"ClusterStateNormal",
")",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// If the cluster has data, we need to change to RESIZING and",
"// kick off the resizing process.",
"if",
"err",
":=",
"c",
".",
"unprotectedSetStateAndBroadcast",
"(",
"ClusterStateResizing",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"c",
".",
"joiningLeavingNodes",
"<-",
"nodeAction",
"{",
"node",
",",
"resizeJobActionAdd",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// nodeJoin should only be called by the coordinator.
|
[
"nodeJoin",
"should",
"only",
"be",
"called",
"by",
"the",
"coordinator",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1730-L1797
|
train
|
pilosa/pilosa
|
cluster.go
|
nodeLeave
|
func (c *cluster) nodeLeave(nodeID string) error {
c.mu.Lock()
defer c.mu.Unlock()
// Refuse the request if this is not the coordinator.
if !c.unprotectedIsCoordinator() {
return fmt.Errorf("node removal requests are only valid on the coordinator node: %s",
c.unprotectedCoordinatorNode().ID)
}
if c.state != ClusterStateNormal && c.state != ClusterStateDegraded {
return fmt.Errorf("cluster must be '%s' to remove a node but is '%s'",
ClusterStateNormal, c.state)
}
// Ensure that node is in the cluster.
if !c.topologyContainsNode(nodeID) {
return fmt.Errorf("Node is not a member of the cluster: %s", nodeID)
}
// Prevent removing the coordinator node (this node).
if nodeID == c.Node.ID {
return fmt.Errorf("coordinator cannot be removed; first, make a different node the new coordinator")
}
// See if resize job can be generated
if _, err := c.unprotectedGenerateResizeJobByAction(
nodeAction{
node: &Node{ID: nodeID},
action: resizeJobActionRemove},
); err != nil {
return errors.Wrap(err, "generating job")
}
// If the holder does not yet contain data, go ahead and remove the node.
if ok, err := c.holder.HasData(); !ok && err == nil {
if err := c.removeNode(nodeID); err != nil {
return errors.Wrap(err, "removing node")
}
return c.unprotectedSetStateAndBroadcast(c.determineClusterState())
} else if err != nil {
return errors.Wrap(err, "checking if holder has data")
}
// If the cluster has data then change state to RESIZING and
// kick off the resizing process.
if err := c.unprotectedSetStateAndBroadcast(ClusterStateResizing); err != nil {
return errors.Wrap(err, "broadcasting state")
}
c.joiningLeavingNodes <- nodeAction{node: &Node{ID: nodeID}, action: resizeJobActionRemove}
return nil
}
|
go
|
func (c *cluster) nodeLeave(nodeID string) error {
c.mu.Lock()
defer c.mu.Unlock()
// Refuse the request if this is not the coordinator.
if !c.unprotectedIsCoordinator() {
return fmt.Errorf("node removal requests are only valid on the coordinator node: %s",
c.unprotectedCoordinatorNode().ID)
}
if c.state != ClusterStateNormal && c.state != ClusterStateDegraded {
return fmt.Errorf("cluster must be '%s' to remove a node but is '%s'",
ClusterStateNormal, c.state)
}
// Ensure that node is in the cluster.
if !c.topologyContainsNode(nodeID) {
return fmt.Errorf("Node is not a member of the cluster: %s", nodeID)
}
// Prevent removing the coordinator node (this node).
if nodeID == c.Node.ID {
return fmt.Errorf("coordinator cannot be removed; first, make a different node the new coordinator")
}
// See if resize job can be generated
if _, err := c.unprotectedGenerateResizeJobByAction(
nodeAction{
node: &Node{ID: nodeID},
action: resizeJobActionRemove},
); err != nil {
return errors.Wrap(err, "generating job")
}
// If the holder does not yet contain data, go ahead and remove the node.
if ok, err := c.holder.HasData(); !ok && err == nil {
if err := c.removeNode(nodeID); err != nil {
return errors.Wrap(err, "removing node")
}
return c.unprotectedSetStateAndBroadcast(c.determineClusterState())
} else if err != nil {
return errors.Wrap(err, "checking if holder has data")
}
// If the cluster has data then change state to RESIZING and
// kick off the resizing process.
if err := c.unprotectedSetStateAndBroadcast(ClusterStateResizing); err != nil {
return errors.Wrap(err, "broadcasting state")
}
c.joiningLeavingNodes <- nodeAction{node: &Node{ID: nodeID}, action: resizeJobActionRemove}
return nil
}
|
[
"func",
"(",
"c",
"*",
"cluster",
")",
"nodeLeave",
"(",
"nodeID",
"string",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"// Refuse the request if this is not the coordinator.",
"if",
"!",
"c",
".",
"unprotectedIsCoordinator",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"c",
".",
"unprotectedCoordinatorNode",
"(",
")",
".",
"ID",
")",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"state",
"!=",
"ClusterStateNormal",
"&&",
"c",
".",
"state",
"!=",
"ClusterStateDegraded",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ClusterStateNormal",
",",
"c",
".",
"state",
")",
"\n",
"}",
"\n\n",
"// Ensure that node is in the cluster.",
"if",
"!",
"c",
".",
"topologyContainsNode",
"(",
"nodeID",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"nodeID",
")",
"\n",
"}",
"\n\n",
"// Prevent removing the coordinator node (this node).",
"if",
"nodeID",
"==",
"c",
".",
"Node",
".",
"ID",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// See if resize job can be generated",
"if",
"_",
",",
"err",
":=",
"c",
".",
"unprotectedGenerateResizeJobByAction",
"(",
"nodeAction",
"{",
"node",
":",
"&",
"Node",
"{",
"ID",
":",
"nodeID",
"}",
",",
"action",
":",
"resizeJobActionRemove",
"}",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// If the holder does not yet contain data, go ahead and remove the node.",
"if",
"ok",
",",
"err",
":=",
"c",
".",
"holder",
".",
"HasData",
"(",
")",
";",
"!",
"ok",
"&&",
"err",
"==",
"nil",
"{",
"if",
"err",
":=",
"c",
".",
"removeNode",
"(",
"nodeID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"unprotectedSetStateAndBroadcast",
"(",
"c",
".",
"determineClusterState",
"(",
")",
")",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// If the cluster has data then change state to RESIZING and",
"// kick off the resizing process.",
"if",
"err",
":=",
"c",
".",
"unprotectedSetStateAndBroadcast",
"(",
"ClusterStateResizing",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"c",
".",
"joiningLeavingNodes",
"<-",
"nodeAction",
"{",
"node",
":",
"&",
"Node",
"{",
"ID",
":",
"nodeID",
"}",
",",
"action",
":",
"resizeJobActionRemove",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// nodeLeave initiates the removal of a node from the cluster.
|
[
"nodeLeave",
"initiates",
"the",
"removal",
"of",
"a",
"node",
"from",
"the",
"cluster",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1800-L1851
|
train
|
pilosa/pilosa
|
cluster.go
|
unprotectedPreviousNode
|
func (c *cluster) unprotectedPreviousNode() *Node {
if len(c.nodes) <= 1 {
return nil
}
pos := c.nodePositionByID(c.Node.ID)
if pos == -1 {
return nil
} else if pos == 0 {
return c.nodes[len(c.nodes)-1]
} else {
return c.nodes[pos-1]
}
}
|
go
|
func (c *cluster) unprotectedPreviousNode() *Node {
if len(c.nodes) <= 1 {
return nil
}
pos := c.nodePositionByID(c.Node.ID)
if pos == -1 {
return nil
} else if pos == 0 {
return c.nodes[len(c.nodes)-1]
} else {
return c.nodes[pos-1]
}
}
|
[
"func",
"(",
"c",
"*",
"cluster",
")",
"unprotectedPreviousNode",
"(",
")",
"*",
"Node",
"{",
"if",
"len",
"(",
"c",
".",
"nodes",
")",
"<=",
"1",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"pos",
":=",
"c",
".",
"nodePositionByID",
"(",
"c",
".",
"Node",
".",
"ID",
")",
"\n",
"if",
"pos",
"==",
"-",
"1",
"{",
"return",
"nil",
"\n",
"}",
"else",
"if",
"pos",
"==",
"0",
"{",
"return",
"c",
".",
"nodes",
"[",
"len",
"(",
"c",
".",
"nodes",
")",
"-",
"1",
"]",
"\n",
"}",
"else",
"{",
"return",
"c",
".",
"nodes",
"[",
"pos",
"-",
"1",
"]",
"\n",
"}",
"\n",
"}"
] |
// unprotectedPreviousNode returns the node listed before the current node in c.Nodes.
// If there is only one node in the cluster, returns nil.
// If the current node is the first node in the list, returns the last node.
|
[
"unprotectedPreviousNode",
"returns",
"the",
"node",
"listed",
"before",
"the",
"current",
"node",
"in",
"c",
".",
"Nodes",
".",
"If",
"there",
"is",
"only",
"one",
"node",
"in",
"the",
"cluster",
"returns",
"nil",
".",
"If",
"the",
"current",
"node",
"is",
"the",
"first",
"node",
"in",
"the",
"list",
"returns",
"the",
"last",
"node",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1942-L1955
|
train
|
pilosa/pilosa
|
server.go
|
OptServerLogger
|
func OptServerLogger(l logger.Logger) ServerOption {
return func(s *Server) error {
s.logger = l
return nil
}
}
|
go
|
func OptServerLogger(l logger.Logger) ServerOption {
return func(s *Server) error {
s.logger = l
return nil
}
}
|
[
"func",
"OptServerLogger",
"(",
"l",
"logger",
".",
"Logger",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"logger",
"=",
"l",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerLogger is a functional option on Server
// used to set the logger.
|
[
"OptServerLogger",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"set",
"the",
"logger",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L89-L94
|
train
|
pilosa/pilosa
|
server.go
|
OptServerReplicaN
|
func OptServerReplicaN(n int) ServerOption {
return func(s *Server) error {
s.cluster.ReplicaN = n
return nil
}
}
|
go
|
func OptServerReplicaN(n int) ServerOption {
return func(s *Server) error {
s.cluster.ReplicaN = n
return nil
}
}
|
[
"func",
"OptServerReplicaN",
"(",
"n",
"int",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"cluster",
".",
"ReplicaN",
"=",
"n",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerReplicaN is a functional option on Server
// used to set the number of replicas.
|
[
"OptServerReplicaN",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"set",
"the",
"number",
"of",
"replicas",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L98-L103
|
train
|
pilosa/pilosa
|
server.go
|
OptServerDataDir
|
func OptServerDataDir(dir string) ServerOption {
return func(s *Server) error {
s.dataDir = dir
return nil
}
}
|
go
|
func OptServerDataDir(dir string) ServerOption {
return func(s *Server) error {
s.dataDir = dir
return nil
}
}
|
[
"func",
"OptServerDataDir",
"(",
"dir",
"string",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"dataDir",
"=",
"dir",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerDataDir is a functional option on Server
// used to set the data directory.
|
[
"OptServerDataDir",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"set",
"the",
"data",
"directory",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L107-L112
|
train
|
pilosa/pilosa
|
server.go
|
OptServerAttrStoreFunc
|
func OptServerAttrStoreFunc(af func(string) AttrStore) ServerOption {
return func(s *Server) error {
s.holder.NewAttrStore = af
return nil
}
}
|
go
|
func OptServerAttrStoreFunc(af func(string) AttrStore) ServerOption {
return func(s *Server) error {
s.holder.NewAttrStore = af
return nil
}
}
|
[
"func",
"OptServerAttrStoreFunc",
"(",
"af",
"func",
"(",
"string",
")",
"AttrStore",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"holder",
".",
"NewAttrStore",
"=",
"af",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerAttrStoreFunc is a functional option on Server
// used to provide the function to use to generate a new
// attribute store.
|
[
"OptServerAttrStoreFunc",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"provide",
"the",
"function",
"to",
"use",
"to",
"generate",
"a",
"new",
"attribute",
"store",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L117-L122
|
train
|
pilosa/pilosa
|
server.go
|
OptServerAntiEntropyInterval
|
func OptServerAntiEntropyInterval(interval time.Duration) ServerOption {
return func(s *Server) error {
s.antiEntropyInterval = interval
return nil
}
}
|
go
|
func OptServerAntiEntropyInterval(interval time.Duration) ServerOption {
return func(s *Server) error {
s.antiEntropyInterval = interval
return nil
}
}
|
[
"func",
"OptServerAntiEntropyInterval",
"(",
"interval",
"time",
".",
"Duration",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"antiEntropyInterval",
"=",
"interval",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerAntiEntropyInterval is a functional option on Server
// used to set the anti-entropy interval.
|
[
"OptServerAntiEntropyInterval",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"set",
"the",
"anti",
"-",
"entropy",
"interval",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L126-L131
|
train
|
pilosa/pilosa
|
server.go
|
OptServerLongQueryTime
|
func OptServerLongQueryTime(dur time.Duration) ServerOption {
return func(s *Server) error {
s.cluster.longQueryTime = dur
return nil
}
}
|
go
|
func OptServerLongQueryTime(dur time.Duration) ServerOption {
return func(s *Server) error {
s.cluster.longQueryTime = dur
return nil
}
}
|
[
"func",
"OptServerLongQueryTime",
"(",
"dur",
"time",
".",
"Duration",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"cluster",
".",
"longQueryTime",
"=",
"dur",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerLongQueryTime is a functional option on Server
// used to set long query duration.
|
[
"OptServerLongQueryTime",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"set",
"long",
"query",
"duration",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L135-L140
|
train
|
pilosa/pilosa
|
server.go
|
OptServerMaxWritesPerRequest
|
func OptServerMaxWritesPerRequest(n int) ServerOption {
return func(s *Server) error {
s.maxWritesPerRequest = n
return nil
}
}
|
go
|
func OptServerMaxWritesPerRequest(n int) ServerOption {
return func(s *Server) error {
s.maxWritesPerRequest = n
return nil
}
}
|
[
"func",
"OptServerMaxWritesPerRequest",
"(",
"n",
"int",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"maxWritesPerRequest",
"=",
"n",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerMaxWritesPerRequest is a functional option on Server
// used to set the maximum number of writes allowed per request.
|
[
"OptServerMaxWritesPerRequest",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"set",
"the",
"maximum",
"number",
"of",
"writes",
"allowed",
"per",
"request",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L144-L149
|
train
|
pilosa/pilosa
|
server.go
|
OptServerMetricInterval
|
func OptServerMetricInterval(dur time.Duration) ServerOption {
return func(s *Server) error {
s.metricInterval = dur
return nil
}
}
|
go
|
func OptServerMetricInterval(dur time.Duration) ServerOption {
return func(s *Server) error {
s.metricInterval = dur
return nil
}
}
|
[
"func",
"OptServerMetricInterval",
"(",
"dur",
"time",
".",
"Duration",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"metricInterval",
"=",
"dur",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerMetricInterval is a functional option on Server
// used to set the interval between metric samples.
|
[
"OptServerMetricInterval",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"set",
"the",
"interval",
"between",
"metric",
"samples",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L153-L158
|
train
|
pilosa/pilosa
|
server.go
|
OptServerSystemInfo
|
func OptServerSystemInfo(si SystemInfo) ServerOption {
return func(s *Server) error {
s.systemInfo = si
return nil
}
}
|
go
|
func OptServerSystemInfo(si SystemInfo) ServerOption {
return func(s *Server) error {
s.systemInfo = si
return nil
}
}
|
[
"func",
"OptServerSystemInfo",
"(",
"si",
"SystemInfo",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"systemInfo",
"=",
"si",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerSystemInfo is a functional option on Server
// used to set the system information source.
|
[
"OptServerSystemInfo",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"set",
"the",
"system",
"information",
"source",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L162-L167
|
train
|
pilosa/pilosa
|
server.go
|
OptServerGCNotifier
|
func OptServerGCNotifier(gcn GCNotifier) ServerOption {
return func(s *Server) error {
s.gcNotifier = gcn
return nil
}
}
|
go
|
func OptServerGCNotifier(gcn GCNotifier) ServerOption {
return func(s *Server) error {
s.gcNotifier = gcn
return nil
}
}
|
[
"func",
"OptServerGCNotifier",
"(",
"gcn",
"GCNotifier",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"gcNotifier",
"=",
"gcn",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerGCNotifier is a functional option on Server
// used to set the garbage collection notification source.
|
[
"OptServerGCNotifier",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"set",
"the",
"garbage",
"collection",
"notification",
"source",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L171-L176
|
train
|
pilosa/pilosa
|
server.go
|
OptServerInternalClient
|
func OptServerInternalClient(c InternalClient) ServerOption {
return func(s *Server) error {
s.executor = newExecutor(optExecutorInternalQueryClient(c))
s.defaultClient = c
s.cluster.InternalClient = c
return nil
}
}
|
go
|
func OptServerInternalClient(c InternalClient) ServerOption {
return func(s *Server) error {
s.executor = newExecutor(optExecutorInternalQueryClient(c))
s.defaultClient = c
s.cluster.InternalClient = c
return nil
}
}
|
[
"func",
"OptServerInternalClient",
"(",
"c",
"InternalClient",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"executor",
"=",
"newExecutor",
"(",
"optExecutorInternalQueryClient",
"(",
"c",
")",
")",
"\n",
"s",
".",
"defaultClient",
"=",
"c",
"\n",
"s",
".",
"cluster",
".",
"InternalClient",
"=",
"c",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerInternalClient is a functional option on Server
// used to set the implementation of InternalClient.
|
[
"OptServerInternalClient",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"set",
"the",
"implementation",
"of",
"InternalClient",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L180-L187
|
train
|
pilosa/pilosa
|
server.go
|
OptServerPrimaryTranslateStore
|
func OptServerPrimaryTranslateStore(store TranslateStore) ServerOption {
return func(s *Server) error {
s.logger.Printf("DEPRECATED: OptServerPrimaryTranslateStore")
return nil
}
}
|
go
|
func OptServerPrimaryTranslateStore(store TranslateStore) ServerOption {
return func(s *Server) error {
s.logger.Printf("DEPRECATED: OptServerPrimaryTranslateStore")
return nil
}
}
|
[
"func",
"OptServerPrimaryTranslateStore",
"(",
"store",
"TranslateStore",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerPrimaryTranslateStore has been deprecated.
|
[
"OptServerPrimaryTranslateStore",
"has",
"been",
"deprecated",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L190-L195
|
train
|
pilosa/pilosa
|
server.go
|
OptServerPrimaryTranslateStoreFunc
|
func OptServerPrimaryTranslateStoreFunc(tf func(interface{}) TranslateStore) ServerOption {
return func(s *Server) error {
s.holder.NewPrimaryTranslateStore = tf
return nil
}
}
|
go
|
func OptServerPrimaryTranslateStoreFunc(tf func(interface{}) TranslateStore) ServerOption {
return func(s *Server) error {
s.holder.NewPrimaryTranslateStore = tf
return nil
}
}
|
[
"func",
"OptServerPrimaryTranslateStoreFunc",
"(",
"tf",
"func",
"(",
"interface",
"{",
"}",
")",
"TranslateStore",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"holder",
".",
"NewPrimaryTranslateStore",
"=",
"tf",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerPrimaryTranslateStoreFunc is a functional option on Server
// used to specify the function used to create a new primary translate
// store.
|
[
"OptServerPrimaryTranslateStoreFunc",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"specify",
"the",
"function",
"used",
"to",
"create",
"a",
"new",
"primary",
"translate",
"store",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L200-L206
|
train
|
pilosa/pilosa
|
server.go
|
OptServerStatsClient
|
func OptServerStatsClient(sc stats.StatsClient) ServerOption {
return func(s *Server) error {
s.holder.Stats = sc
return nil
}
}
|
go
|
func OptServerStatsClient(sc stats.StatsClient) ServerOption {
return func(s *Server) error {
s.holder.Stats = sc
return nil
}
}
|
[
"func",
"OptServerStatsClient",
"(",
"sc",
"stats",
".",
"StatsClient",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"holder",
".",
"Stats",
"=",
"sc",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerStatsClient is a functional option on Server
// used to specify the stats client.
|
[
"OptServerStatsClient",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"specify",
"the",
"stats",
"client",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L210-L215
|
train
|
pilosa/pilosa
|
server.go
|
OptServerDiagnosticsInterval
|
func OptServerDiagnosticsInterval(dur time.Duration) ServerOption {
return func(s *Server) error {
s.diagnosticInterval = dur
return nil
}
}
|
go
|
func OptServerDiagnosticsInterval(dur time.Duration) ServerOption {
return func(s *Server) error {
s.diagnosticInterval = dur
return nil
}
}
|
[
"func",
"OptServerDiagnosticsInterval",
"(",
"dur",
"time",
".",
"Duration",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"diagnosticInterval",
"=",
"dur",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerDiagnosticsInterval is a functional option on Server
// used to specify the duration between diagnostic checks.
|
[
"OptServerDiagnosticsInterval",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"specify",
"the",
"duration",
"between",
"diagnostic",
"checks",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L219-L224
|
train
|
pilosa/pilosa
|
server.go
|
OptServerURI
|
func OptServerURI(uri *URI) ServerOption {
return func(s *Server) error {
s.uri = *uri
return nil
}
}
|
go
|
func OptServerURI(uri *URI) ServerOption {
return func(s *Server) error {
s.uri = *uri
return nil
}
}
|
[
"func",
"OptServerURI",
"(",
"uri",
"*",
"URI",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"uri",
"=",
"*",
"uri",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerURI is a functional option on Server
// used to set the server URI.
|
[
"OptServerURI",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"set",
"the",
"server",
"URI",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L228-L233
|
train
|
pilosa/pilosa
|
server.go
|
OptServerClusterDisabled
|
func OptServerClusterDisabled(disabled bool, hosts []string) ServerOption {
return func(s *Server) error {
s.hosts = hosts
s.clusterDisabled = disabled
return nil
}
}
|
go
|
func OptServerClusterDisabled(disabled bool, hosts []string) ServerOption {
return func(s *Server) error {
s.hosts = hosts
s.clusterDisabled = disabled
return nil
}
}
|
[
"func",
"OptServerClusterDisabled",
"(",
"disabled",
"bool",
",",
"hosts",
"[",
"]",
"string",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"hosts",
"=",
"hosts",
"\n",
"s",
".",
"clusterDisabled",
"=",
"disabled",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerClusterDisabled tells the server whether to use a static cluster with the
// defined hosts. Mostly used for testing.
|
[
"OptServerClusterDisabled",
"tells",
"the",
"server",
"whether",
"to",
"use",
"a",
"static",
"cluster",
"with",
"the",
"defined",
"hosts",
".",
"Mostly",
"used",
"for",
"testing",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L237-L243
|
train
|
pilosa/pilosa
|
server.go
|
OptServerSerializer
|
func OptServerSerializer(ser Serializer) ServerOption {
return func(s *Server) error {
s.serializer = ser
return nil
}
}
|
go
|
func OptServerSerializer(ser Serializer) ServerOption {
return func(s *Server) error {
s.serializer = ser
return nil
}
}
|
[
"func",
"OptServerSerializer",
"(",
"ser",
"Serializer",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"serializer",
"=",
"ser",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerSerializer is a functional option on Server
// used to set the serializer.
|
[
"OptServerSerializer",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"set",
"the",
"serializer",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L247-L252
|
train
|
pilosa/pilosa
|
server.go
|
OptServerIsCoordinator
|
func OptServerIsCoordinator(is bool) ServerOption {
return func(s *Server) error {
s.isCoordinator = is
return nil
}
}
|
go
|
func OptServerIsCoordinator(is bool) ServerOption {
return func(s *Server) error {
s.isCoordinator = is
return nil
}
}
|
[
"func",
"OptServerIsCoordinator",
"(",
"is",
"bool",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"isCoordinator",
"=",
"is",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerIsCoordinator is a functional option on Server
// used to specify whether or not this server is the coordinator.
|
[
"OptServerIsCoordinator",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"specify",
"whether",
"or",
"not",
"this",
"server",
"is",
"the",
"coordinator",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L256-L261
|
train
|
pilosa/pilosa
|
server.go
|
OptServerNodeID
|
func OptServerNodeID(nodeID string) ServerOption {
return func(s *Server) error {
s.nodeID = nodeID
return nil
}
}
|
go
|
func OptServerNodeID(nodeID string) ServerOption {
return func(s *Server) error {
s.nodeID = nodeID
return nil
}
}
|
[
"func",
"OptServerNodeID",
"(",
"nodeID",
"string",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"nodeID",
"=",
"nodeID",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerNodeID is a functional option on Server
// used to set the server node ID.
|
[
"OptServerNodeID",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"set",
"the",
"server",
"node",
"ID",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L265-L270
|
train
|
pilosa/pilosa
|
server.go
|
OptServerClusterHasher
|
func OptServerClusterHasher(h Hasher) ServerOption {
return func(s *Server) error {
s.cluster.Hasher = h
return nil
}
}
|
go
|
func OptServerClusterHasher(h Hasher) ServerOption {
return func(s *Server) error {
s.cluster.Hasher = h
return nil
}
}
|
[
"func",
"OptServerClusterHasher",
"(",
"h",
"Hasher",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"cluster",
".",
"Hasher",
"=",
"h",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerClusterHasher is a functional option on Server
// used to specify the consistent hash algorithm for data
// location within the cluster.
|
[
"OptServerClusterHasher",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"specify",
"the",
"consistent",
"hash",
"algorithm",
"for",
"data",
"location",
"within",
"the",
"cluster",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L275-L280
|
train
|
pilosa/pilosa
|
server.go
|
OptServerTranslateFileMapSize
|
func OptServerTranslateFileMapSize(mapSize int) ServerOption {
return func(s *Server) error {
s.holder.translateFile = NewTranslateFile(OptTranslateFileMapSize(mapSize))
return nil
}
}
|
go
|
func OptServerTranslateFileMapSize(mapSize int) ServerOption {
return func(s *Server) error {
s.holder.translateFile = NewTranslateFile(OptTranslateFileMapSize(mapSize))
return nil
}
}
|
[
"func",
"OptServerTranslateFileMapSize",
"(",
"mapSize",
"int",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"holder",
".",
"translateFile",
"=",
"NewTranslateFile",
"(",
"OptTranslateFileMapSize",
"(",
"mapSize",
")",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptServerTranslateFileMapSize is a functional option on Server
// used to specify the size of the translate file.
|
[
"OptServerTranslateFileMapSize",
"is",
"a",
"functional",
"option",
"on",
"Server",
"used",
"to",
"specify",
"the",
"size",
"of",
"the",
"translate",
"file",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L284-L289
|
train
|
pilosa/pilosa
|
server.go
|
Open
|
func (s *Server) Open() error {
s.logger.Printf("open server")
// Log startup
err := s.holder.logStartup()
if err != nil {
log.Println(errors.Wrap(err, "logging startup"))
}
// Initialize id-key storage.
if err := s.holder.translateFile.Open(); err != nil {
return errors.Wrap(err, "opening TranslateFile")
}
// Open Cluster management.
if err := s.cluster.waitForStarted(); err != nil {
return errors.Wrap(err, "opening Cluster")
}
// Open holder.
if err := s.holder.Open(); err != nil {
return errors.Wrap(err, "opening Holder")
}
if err := s.cluster.setNodeState(nodeStateReady); err != nil {
return errors.Wrap(err, "setting nodeState")
}
// Listen for joining nodes.
// This needs to start after the Holder has opened so that nodes can join
// the cluster without waiting for data to load on the coordinator. Before
// this starts, the joins are queued up in the Cluster.joiningLeavingNodes
// buffered channel.
s.cluster.listenForJoins()
s.syncer.Holder = s.holder
s.syncer.Node = s.cluster.Node
s.syncer.Cluster = s.cluster
s.syncer.Closing = s.closing
s.syncer.Stats = s.holder.Stats.WithTags("HolderSyncer")
// Start background monitoring.
s.wg.Add(3)
go func() { defer s.wg.Done(); s.monitorAntiEntropy() }()
go func() { defer s.wg.Done(); s.monitorRuntime() }()
go func() { defer s.wg.Done(); s.monitorDiagnostics() }()
return nil
}
|
go
|
func (s *Server) Open() error {
s.logger.Printf("open server")
// Log startup
err := s.holder.logStartup()
if err != nil {
log.Println(errors.Wrap(err, "logging startup"))
}
// Initialize id-key storage.
if err := s.holder.translateFile.Open(); err != nil {
return errors.Wrap(err, "opening TranslateFile")
}
// Open Cluster management.
if err := s.cluster.waitForStarted(); err != nil {
return errors.Wrap(err, "opening Cluster")
}
// Open holder.
if err := s.holder.Open(); err != nil {
return errors.Wrap(err, "opening Holder")
}
if err := s.cluster.setNodeState(nodeStateReady); err != nil {
return errors.Wrap(err, "setting nodeState")
}
// Listen for joining nodes.
// This needs to start after the Holder has opened so that nodes can join
// the cluster without waiting for data to load on the coordinator. Before
// this starts, the joins are queued up in the Cluster.joiningLeavingNodes
// buffered channel.
s.cluster.listenForJoins()
s.syncer.Holder = s.holder
s.syncer.Node = s.cluster.Node
s.syncer.Cluster = s.cluster
s.syncer.Closing = s.closing
s.syncer.Stats = s.holder.Stats.WithTags("HolderSyncer")
// Start background monitoring.
s.wg.Add(3)
go func() { defer s.wg.Done(); s.monitorAntiEntropy() }()
go func() { defer s.wg.Done(); s.monitorRuntime() }()
go func() { defer s.wg.Done(); s.monitorDiagnostics() }()
return nil
}
|
[
"func",
"(",
"s",
"*",
"Server",
")",
"Open",
"(",
")",
"error",
"{",
"s",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n\n",
"// Log startup",
"err",
":=",
"s",
".",
"holder",
".",
"logStartup",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Println",
"(",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"// Initialize id-key storage.",
"if",
"err",
":=",
"s",
".",
"holder",
".",
"translateFile",
".",
"Open",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Open Cluster management.",
"if",
"err",
":=",
"s",
".",
"cluster",
".",
"waitForStarted",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Open holder.",
"if",
"err",
":=",
"s",
".",
"holder",
".",
"Open",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"s",
".",
"cluster",
".",
"setNodeState",
"(",
"nodeStateReady",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Listen for joining nodes.",
"// This needs to start after the Holder has opened so that nodes can join",
"// the cluster without waiting for data to load on the coordinator. Before",
"// this starts, the joins are queued up in the Cluster.joiningLeavingNodes",
"// buffered channel.",
"s",
".",
"cluster",
".",
"listenForJoins",
"(",
")",
"\n\n",
"s",
".",
"syncer",
".",
"Holder",
"=",
"s",
".",
"holder",
"\n",
"s",
".",
"syncer",
".",
"Node",
"=",
"s",
".",
"cluster",
".",
"Node",
"\n",
"s",
".",
"syncer",
".",
"Cluster",
"=",
"s",
".",
"cluster",
"\n",
"s",
".",
"syncer",
".",
"Closing",
"=",
"s",
".",
"closing",
"\n",
"s",
".",
"syncer",
".",
"Stats",
"=",
"s",
".",
"holder",
".",
"Stats",
".",
"WithTags",
"(",
"\"",
"\"",
")",
"\n\n",
"// Start background monitoring.",
"s",
".",
"wg",
".",
"Add",
"(",
"3",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"s",
".",
"wg",
".",
"Done",
"(",
")",
";",
"s",
".",
"monitorAntiEntropy",
"(",
")",
"}",
"(",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"s",
".",
"wg",
".",
"Done",
"(",
")",
";",
"s",
".",
"monitorRuntime",
"(",
")",
"}",
"(",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"s",
".",
"wg",
".",
"Done",
"(",
")",
";",
"s",
".",
"monitorDiagnostics",
"(",
")",
"}",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Open opens and initializes the server.
|
[
"Open",
"opens",
"and",
"initializes",
"the",
"server",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L378-L425
|
train
|
pilosa/pilosa
|
server.go
|
Close
|
func (s *Server) Close() error {
// Notify goroutines to stop.
close(s.closing)
s.wg.Wait()
var errh error
var errc error
if s.cluster != nil {
errc = s.cluster.close()
}
if s.holder != nil {
errh = s.holder.Close()
}
// prefer to return holder error over cluster
// error. This order is somewhat arbitrary. It would be better if we had
// some way to combine all the errors, but probably not important enough to
// warrant the extra complexity.
if errh != nil {
return errors.Wrap(errh, "closing holder")
}
return errors.Wrap(errc, "closing cluster")
}
|
go
|
func (s *Server) Close() error {
// Notify goroutines to stop.
close(s.closing)
s.wg.Wait()
var errh error
var errc error
if s.cluster != nil {
errc = s.cluster.close()
}
if s.holder != nil {
errh = s.holder.Close()
}
// prefer to return holder error over cluster
// error. This order is somewhat arbitrary. It would be better if we had
// some way to combine all the errors, but probably not important enough to
// warrant the extra complexity.
if errh != nil {
return errors.Wrap(errh, "closing holder")
}
return errors.Wrap(errc, "closing cluster")
}
|
[
"func",
"(",
"s",
"*",
"Server",
")",
"Close",
"(",
")",
"error",
"{",
"// Notify goroutines to stop.",
"close",
"(",
"s",
".",
"closing",
")",
"\n",
"s",
".",
"wg",
".",
"Wait",
"(",
")",
"\n\n",
"var",
"errh",
"error",
"\n",
"var",
"errc",
"error",
"\n",
"if",
"s",
".",
"cluster",
"!=",
"nil",
"{",
"errc",
"=",
"s",
".",
"cluster",
".",
"close",
"(",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"holder",
"!=",
"nil",
"{",
"errh",
"=",
"s",
".",
"holder",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"// prefer to return holder error over cluster",
"// error. This order is somewhat arbitrary. It would be better if we had",
"// some way to combine all the errors, but probably not important enough to",
"// warrant the extra complexity.",
"if",
"errh",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"errh",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Wrap",
"(",
"errc",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// Close closes the server and waits for it to shutdown.
|
[
"Close",
"closes",
"the",
"server",
"and",
"waits",
"for",
"it",
"to",
"shutdown",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L428-L449
|
train
|
pilosa/pilosa
|
server.go
|
loadNodeID
|
func (s *Server) loadNodeID() string {
if s.nodeID != "" {
return s.nodeID
}
nodeID, err := s.holder.loadNodeID()
if err != nil {
s.logger.Printf("loading NodeID: %v", err)
return s.nodeID
}
return nodeID
}
|
go
|
func (s *Server) loadNodeID() string {
if s.nodeID != "" {
return s.nodeID
}
nodeID, err := s.holder.loadNodeID()
if err != nil {
s.logger.Printf("loading NodeID: %v", err)
return s.nodeID
}
return nodeID
}
|
[
"func",
"(",
"s",
"*",
"Server",
")",
"loadNodeID",
"(",
")",
"string",
"{",
"if",
"s",
".",
"nodeID",
"!=",
"\"",
"\"",
"{",
"return",
"s",
".",
"nodeID",
"\n",
"}",
"\n",
"nodeID",
",",
"err",
":=",
"s",
".",
"holder",
".",
"loadNodeID",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"s",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"s",
".",
"nodeID",
"\n",
"}",
"\n",
"return",
"nodeID",
"\n",
"}"
] |
// loadNodeID gets NodeID from disk, or creates a new value.
// If server.NodeID is already set, a new ID is not created.
|
[
"loadNodeID",
"gets",
"NodeID",
"from",
"disk",
"or",
"creates",
"a",
"new",
"value",
".",
"If",
"server",
".",
"NodeID",
"is",
"already",
"set",
"a",
"new",
"ID",
"is",
"not",
"created",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L453-L463
|
train
|
pilosa/pilosa
|
server.go
|
SendSync
|
func (s *Server) SendSync(m Message) error {
var eg errgroup.Group
msg, err := s.serializer.Marshal(m)
if err != nil {
return fmt.Errorf("marshaling message: %v", err)
}
msg = append([]byte{getMessageType(m)}, msg...)
for _, node := range s.cluster.Nodes() {
node := node
// Don't forward the message to ourselves.
if s.uri == node.URI {
continue
}
eg.Go(func() error {
return s.defaultClient.SendMessage(context.Background(), &node.URI, msg)
})
}
return eg.Wait()
}
|
go
|
func (s *Server) SendSync(m Message) error {
var eg errgroup.Group
msg, err := s.serializer.Marshal(m)
if err != nil {
return fmt.Errorf("marshaling message: %v", err)
}
msg = append([]byte{getMessageType(m)}, msg...)
for _, node := range s.cluster.Nodes() {
node := node
// Don't forward the message to ourselves.
if s.uri == node.URI {
continue
}
eg.Go(func() error {
return s.defaultClient.SendMessage(context.Background(), &node.URI, msg)
})
}
return eg.Wait()
}
|
[
"func",
"(",
"s",
"*",
"Server",
")",
"SendSync",
"(",
"m",
"Message",
")",
"error",
"{",
"var",
"eg",
"errgroup",
".",
"Group",
"\n",
"msg",
",",
"err",
":=",
"s",
".",
"serializer",
".",
"Marshal",
"(",
"m",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"msg",
"=",
"append",
"(",
"[",
"]",
"byte",
"{",
"getMessageType",
"(",
"m",
")",
"}",
",",
"msg",
"...",
")",
"\n\n",
"for",
"_",
",",
"node",
":=",
"range",
"s",
".",
"cluster",
".",
"Nodes",
"(",
")",
"{",
"node",
":=",
"node",
"\n",
"// Don't forward the message to ourselves.",
"if",
"s",
".",
"uri",
"==",
"node",
".",
"URI",
"{",
"continue",
"\n",
"}",
"\n\n",
"eg",
".",
"Go",
"(",
"func",
"(",
")",
"error",
"{",
"return",
"s",
".",
"defaultClient",
".",
"SendMessage",
"(",
"context",
".",
"Background",
"(",
")",
",",
"&",
"node",
".",
"URI",
",",
"msg",
")",
"\n",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"eg",
".",
"Wait",
"(",
")",
"\n",
"}"
] |
// SendSync represents an implementation of Broadcaster.
|
[
"SendSync",
"represents",
"an",
"implementation",
"of",
"Broadcaster",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L626-L647
|
train
|
pilosa/pilosa
|
server.go
|
SendTo
|
func (s *Server) SendTo(to *Node, m Message) error {
msg, err := s.serializer.Marshal(m)
if err != nil {
return fmt.Errorf("marshaling message: %v", err)
}
msg = append([]byte{getMessageType(m)}, msg...)
return s.defaultClient.SendMessage(context.Background(), &to.URI, msg)
}
|
go
|
func (s *Server) SendTo(to *Node, m Message) error {
msg, err := s.serializer.Marshal(m)
if err != nil {
return fmt.Errorf("marshaling message: %v", err)
}
msg = append([]byte{getMessageType(m)}, msg...)
return s.defaultClient.SendMessage(context.Background(), &to.URI, msg)
}
|
[
"func",
"(",
"s",
"*",
"Server",
")",
"SendTo",
"(",
"to",
"*",
"Node",
",",
"m",
"Message",
")",
"error",
"{",
"msg",
",",
"err",
":=",
"s",
".",
"serializer",
".",
"Marshal",
"(",
"m",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"msg",
"=",
"append",
"(",
"[",
"]",
"byte",
"{",
"getMessageType",
"(",
"m",
")",
"}",
",",
"msg",
"...",
")",
"\n",
"return",
"s",
".",
"defaultClient",
".",
"SendMessage",
"(",
"context",
".",
"Background",
"(",
")",
",",
"&",
"to",
".",
"URI",
",",
"msg",
")",
"\n",
"}"
] |
// SendTo represents an implementation of Broadcaster.
|
[
"SendTo",
"represents",
"an",
"implementation",
"of",
"Broadcaster",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L655-L662
|
train
|
pilosa/pilosa
|
server.go
|
handleRemoteStatus
|
func (s *Server) handleRemoteStatus(pb Message) {
// Ignore NodeStatus messages until the cluster is in a Normal state.
if s.cluster.State() != ClusterStateNormal {
return
}
go func() {
// Make sure the holder has opened.
s.holder.opened.Recv()
err := s.mergeRemoteStatus(pb.(*NodeStatus))
if err != nil {
s.logger.Printf("merge remote status: %s", err)
}
}()
}
|
go
|
func (s *Server) handleRemoteStatus(pb Message) {
// Ignore NodeStatus messages until the cluster is in a Normal state.
if s.cluster.State() != ClusterStateNormal {
return
}
go func() {
// Make sure the holder has opened.
s.holder.opened.Recv()
err := s.mergeRemoteStatus(pb.(*NodeStatus))
if err != nil {
s.logger.Printf("merge remote status: %s", err)
}
}()
}
|
[
"func",
"(",
"s",
"*",
"Server",
")",
"handleRemoteStatus",
"(",
"pb",
"Message",
")",
"{",
"// Ignore NodeStatus messages until the cluster is in a Normal state.",
"if",
"s",
".",
"cluster",
".",
"State",
"(",
")",
"!=",
"ClusterStateNormal",
"{",
"return",
"\n",
"}",
"\n\n",
"go",
"func",
"(",
")",
"{",
"// Make sure the holder has opened.",
"s",
".",
"holder",
".",
"opened",
".",
"Recv",
"(",
")",
"\n\n",
"err",
":=",
"s",
".",
"mergeRemoteStatus",
"(",
"pb",
".",
"(",
"*",
"NodeStatus",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"s",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"}"
] |
// handleRemoteStatus receives incoming NodeStatus from remote nodes.
|
[
"handleRemoteStatus",
"receives",
"incoming",
"NodeStatus",
"from",
"remote",
"nodes",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L671-L686
|
train
|
pilosa/pilosa
|
server.go
|
monitorDiagnostics
|
func (s *Server) monitorDiagnostics() {
// Do not send more than once a minute
if s.diagnosticInterval < time.Minute {
s.logger.Printf("diagnostics disabled")
return
}
s.logger.Printf("Pilosa is currently configured to send small diagnostics reports to our team every %v. More information here: https://www.pilosa.com/docs/latest/administration/#diagnostics", s.diagnosticInterval)
s.diagnostics.Logger = s.logger
s.diagnostics.SetVersion(Version)
s.diagnostics.Set("Host", s.uri.Host)
s.diagnostics.Set("Cluster", strings.Join(s.cluster.nodeIDs(), ","))
s.diagnostics.Set("NumNodes", len(s.cluster.nodes))
s.diagnostics.Set("NumCPU", runtime.NumCPU())
s.diagnostics.Set("NodeID", s.nodeID)
s.diagnostics.Set("ClusterID", s.cluster.id)
s.diagnostics.EnrichWithCPUInfo()
s.diagnostics.EnrichWithOSInfo()
// Flush the diagnostics metrics at startup, then on each tick interval
flush := func() {
openFiles, err := countOpenFiles()
if err == nil {
s.diagnostics.Set("OpenFiles", openFiles)
}
s.diagnostics.Set("GoRoutines", runtime.NumGoroutine())
s.diagnostics.EnrichWithMemoryInfo()
s.diagnostics.EnrichWithSchemaProperties()
err = s.diagnostics.CheckVersion()
if err != nil {
s.logger.Printf("can't check version: %v", err)
}
err = s.diagnostics.Flush()
if err != nil {
s.logger.Printf("diagnostics error: %s", err)
}
}
ticker := time.NewTicker(s.diagnosticInterval)
defer ticker.Stop()
flush()
for {
// Wait for tick or a close.
select {
case <-s.closing:
return
case <-ticker.C:
flush()
}
}
}
|
go
|
func (s *Server) monitorDiagnostics() {
// Do not send more than once a minute
if s.diagnosticInterval < time.Minute {
s.logger.Printf("diagnostics disabled")
return
}
s.logger.Printf("Pilosa is currently configured to send small diagnostics reports to our team every %v. More information here: https://www.pilosa.com/docs/latest/administration/#diagnostics", s.diagnosticInterval)
s.diagnostics.Logger = s.logger
s.diagnostics.SetVersion(Version)
s.diagnostics.Set("Host", s.uri.Host)
s.diagnostics.Set("Cluster", strings.Join(s.cluster.nodeIDs(), ","))
s.diagnostics.Set("NumNodes", len(s.cluster.nodes))
s.diagnostics.Set("NumCPU", runtime.NumCPU())
s.diagnostics.Set("NodeID", s.nodeID)
s.diagnostics.Set("ClusterID", s.cluster.id)
s.diagnostics.EnrichWithCPUInfo()
s.diagnostics.EnrichWithOSInfo()
// Flush the diagnostics metrics at startup, then on each tick interval
flush := func() {
openFiles, err := countOpenFiles()
if err == nil {
s.diagnostics.Set("OpenFiles", openFiles)
}
s.diagnostics.Set("GoRoutines", runtime.NumGoroutine())
s.diagnostics.EnrichWithMemoryInfo()
s.diagnostics.EnrichWithSchemaProperties()
err = s.diagnostics.CheckVersion()
if err != nil {
s.logger.Printf("can't check version: %v", err)
}
err = s.diagnostics.Flush()
if err != nil {
s.logger.Printf("diagnostics error: %s", err)
}
}
ticker := time.NewTicker(s.diagnosticInterval)
defer ticker.Stop()
flush()
for {
// Wait for tick or a close.
select {
case <-s.closing:
return
case <-ticker.C:
flush()
}
}
}
|
[
"func",
"(",
"s",
"*",
"Server",
")",
"monitorDiagnostics",
"(",
")",
"{",
"// Do not send more than once a minute",
"if",
"s",
".",
"diagnosticInterval",
"<",
"time",
".",
"Minute",
"{",
"s",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"s",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"s",
".",
"diagnosticInterval",
")",
"\n\n",
"s",
".",
"diagnostics",
".",
"Logger",
"=",
"s",
".",
"logger",
"\n",
"s",
".",
"diagnostics",
".",
"SetVersion",
"(",
"Version",
")",
"\n",
"s",
".",
"diagnostics",
".",
"Set",
"(",
"\"",
"\"",
",",
"s",
".",
"uri",
".",
"Host",
")",
"\n",
"s",
".",
"diagnostics",
".",
"Set",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"s",
".",
"cluster",
".",
"nodeIDs",
"(",
")",
",",
"\"",
"\"",
")",
")",
"\n",
"s",
".",
"diagnostics",
".",
"Set",
"(",
"\"",
"\"",
",",
"len",
"(",
"s",
".",
"cluster",
".",
"nodes",
")",
")",
"\n",
"s",
".",
"diagnostics",
".",
"Set",
"(",
"\"",
"\"",
",",
"runtime",
".",
"NumCPU",
"(",
")",
")",
"\n",
"s",
".",
"diagnostics",
".",
"Set",
"(",
"\"",
"\"",
",",
"s",
".",
"nodeID",
")",
"\n",
"s",
".",
"diagnostics",
".",
"Set",
"(",
"\"",
"\"",
",",
"s",
".",
"cluster",
".",
"id",
")",
"\n",
"s",
".",
"diagnostics",
".",
"EnrichWithCPUInfo",
"(",
")",
"\n",
"s",
".",
"diagnostics",
".",
"EnrichWithOSInfo",
"(",
")",
"\n\n",
"// Flush the diagnostics metrics at startup, then on each tick interval",
"flush",
":=",
"func",
"(",
")",
"{",
"openFiles",
",",
"err",
":=",
"countOpenFiles",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"s",
".",
"diagnostics",
".",
"Set",
"(",
"\"",
"\"",
",",
"openFiles",
")",
"\n",
"}",
"\n",
"s",
".",
"diagnostics",
".",
"Set",
"(",
"\"",
"\"",
",",
"runtime",
".",
"NumGoroutine",
"(",
")",
")",
"\n",
"s",
".",
"diagnostics",
".",
"EnrichWithMemoryInfo",
"(",
")",
"\n",
"s",
".",
"diagnostics",
".",
"EnrichWithSchemaProperties",
"(",
")",
"\n",
"err",
"=",
"s",
".",
"diagnostics",
".",
"CheckVersion",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"s",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"err",
"=",
"s",
".",
"diagnostics",
".",
"Flush",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"s",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"ticker",
":=",
"time",
".",
"NewTicker",
"(",
"s",
".",
"diagnosticInterval",
")",
"\n",
"defer",
"ticker",
".",
"Stop",
"(",
")",
"\n",
"flush",
"(",
")",
"\n",
"for",
"{",
"// Wait for tick or a close.",
"select",
"{",
"case",
"<-",
"s",
".",
"closing",
":",
"return",
"\n",
"case",
"<-",
"ticker",
".",
"C",
":",
"flush",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// monitorDiagnostics periodically polls the Pilosa Indexes for cluster info.
|
[
"monitorDiagnostics",
"periodically",
"polls",
"the",
"Pilosa",
"Indexes",
"for",
"cluster",
"info",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L720-L770
|
train
|
pilosa/pilosa
|
server.go
|
monitorRuntime
|
func (s *Server) monitorRuntime() {
// Disable metrics when poll interval is zero.
if s.metricInterval <= 0 {
return
}
var m runtime.MemStats
ticker := time.NewTicker(s.metricInterval)
defer ticker.Stop()
defer s.gcNotifier.Close()
s.logger.Printf("runtime stats initializing (%s interval)", s.metricInterval)
for {
// Wait for tick or a close.
select {
case <-s.closing:
return
case <-s.gcNotifier.AfterGC():
// GC just ran.
s.holder.Stats.Count("garbage_collection", 1, 1.0)
case <-ticker.C:
}
// Record the number of go routines.
s.holder.Stats.Gauge("goroutines", float64(runtime.NumGoroutine()), 1.0)
openFiles, err := countOpenFiles()
// Open File handles.
if err == nil {
s.holder.Stats.Gauge("OpenFiles", float64(openFiles), 1.0)
}
// Runtime memory metrics.
runtime.ReadMemStats(&m)
s.holder.Stats.Gauge("HeapAlloc", float64(m.HeapAlloc), 1.0)
s.holder.Stats.Gauge("HeapInuse", float64(m.HeapInuse), 1.0)
s.holder.Stats.Gauge("StackInuse", float64(m.StackInuse), 1.0)
s.holder.Stats.Gauge("Mallocs", float64(m.Mallocs), 1.0)
s.holder.Stats.Gauge("Frees", float64(m.Frees), 1.0)
}
}
|
go
|
func (s *Server) monitorRuntime() {
// Disable metrics when poll interval is zero.
if s.metricInterval <= 0 {
return
}
var m runtime.MemStats
ticker := time.NewTicker(s.metricInterval)
defer ticker.Stop()
defer s.gcNotifier.Close()
s.logger.Printf("runtime stats initializing (%s interval)", s.metricInterval)
for {
// Wait for tick or a close.
select {
case <-s.closing:
return
case <-s.gcNotifier.AfterGC():
// GC just ran.
s.holder.Stats.Count("garbage_collection", 1, 1.0)
case <-ticker.C:
}
// Record the number of go routines.
s.holder.Stats.Gauge("goroutines", float64(runtime.NumGoroutine()), 1.0)
openFiles, err := countOpenFiles()
// Open File handles.
if err == nil {
s.holder.Stats.Gauge("OpenFiles", float64(openFiles), 1.0)
}
// Runtime memory metrics.
runtime.ReadMemStats(&m)
s.holder.Stats.Gauge("HeapAlloc", float64(m.HeapAlloc), 1.0)
s.holder.Stats.Gauge("HeapInuse", float64(m.HeapInuse), 1.0)
s.holder.Stats.Gauge("StackInuse", float64(m.StackInuse), 1.0)
s.holder.Stats.Gauge("Mallocs", float64(m.Mallocs), 1.0)
s.holder.Stats.Gauge("Frees", float64(m.Frees), 1.0)
}
}
|
[
"func",
"(",
"s",
"*",
"Server",
")",
"monitorRuntime",
"(",
")",
"{",
"// Disable metrics when poll interval is zero.",
"if",
"s",
".",
"metricInterval",
"<=",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"var",
"m",
"runtime",
".",
"MemStats",
"\n",
"ticker",
":=",
"time",
".",
"NewTicker",
"(",
"s",
".",
"metricInterval",
")",
"\n",
"defer",
"ticker",
".",
"Stop",
"(",
")",
"\n\n",
"defer",
"s",
".",
"gcNotifier",
".",
"Close",
"(",
")",
"\n\n",
"s",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"s",
".",
"metricInterval",
")",
"\n\n",
"for",
"{",
"// Wait for tick or a close.",
"select",
"{",
"case",
"<-",
"s",
".",
"closing",
":",
"return",
"\n",
"case",
"<-",
"s",
".",
"gcNotifier",
".",
"AfterGC",
"(",
")",
":",
"// GC just ran.",
"s",
".",
"holder",
".",
"Stats",
".",
"Count",
"(",
"\"",
"\"",
",",
"1",
",",
"1.0",
")",
"\n",
"case",
"<-",
"ticker",
".",
"C",
":",
"}",
"\n\n",
"// Record the number of go routines.",
"s",
".",
"holder",
".",
"Stats",
".",
"Gauge",
"(",
"\"",
"\"",
",",
"float64",
"(",
"runtime",
".",
"NumGoroutine",
"(",
")",
")",
",",
"1.0",
")",
"\n\n",
"openFiles",
",",
"err",
":=",
"countOpenFiles",
"(",
")",
"\n",
"// Open File handles.",
"if",
"err",
"==",
"nil",
"{",
"s",
".",
"holder",
".",
"Stats",
".",
"Gauge",
"(",
"\"",
"\"",
",",
"float64",
"(",
"openFiles",
")",
",",
"1.0",
")",
"\n",
"}",
"\n\n",
"// Runtime memory metrics.",
"runtime",
".",
"ReadMemStats",
"(",
"&",
"m",
")",
"\n",
"s",
".",
"holder",
".",
"Stats",
".",
"Gauge",
"(",
"\"",
"\"",
",",
"float64",
"(",
"m",
".",
"HeapAlloc",
")",
",",
"1.0",
")",
"\n",
"s",
".",
"holder",
".",
"Stats",
".",
"Gauge",
"(",
"\"",
"\"",
",",
"float64",
"(",
"m",
".",
"HeapInuse",
")",
",",
"1.0",
")",
"\n",
"s",
".",
"holder",
".",
"Stats",
".",
"Gauge",
"(",
"\"",
"\"",
",",
"float64",
"(",
"m",
".",
"StackInuse",
")",
",",
"1.0",
")",
"\n",
"s",
".",
"holder",
".",
"Stats",
".",
"Gauge",
"(",
"\"",
"\"",
",",
"float64",
"(",
"m",
".",
"Mallocs",
")",
",",
"1.0",
")",
"\n",
"s",
".",
"holder",
".",
"Stats",
".",
"Gauge",
"(",
"\"",
"\"",
",",
"float64",
"(",
"m",
".",
"Frees",
")",
",",
"1.0",
")",
"\n",
"}",
"\n",
"}"
] |
// monitorRuntime periodically polls the Go runtime metrics.
|
[
"monitorRuntime",
"periodically",
"polls",
"the",
"Go",
"runtime",
"metrics",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L773-L815
|
train
|
pilosa/pilosa
|
server.go
|
countOpenFiles
|
func countOpenFiles() (int, error) {
switch runtime.GOOS {
case "darwin", "linux", "unix", "freebsd":
// -b option avoid kernel blocks
pid := os.Getpid()
out, err := exec.Command("/bin/sh", "-c", fmt.Sprintf("lsof -b -p %v", pid)).Output()
if err != nil {
return 0, fmt.Errorf("calling lsof: %s", err)
}
// only count lines with our pid, avoiding warning messages from -b
lines := strings.Split(string(out), strconv.Itoa(pid))
return len(lines), nil
case "windows":
// TODO: count open file handles on windows
return 0, errors.New("countOpenFiles() on Windows is not supported")
default:
return 0, errors.New("countOpenFiles() on this OS is not supported")
}
}
|
go
|
func countOpenFiles() (int, error) {
switch runtime.GOOS {
case "darwin", "linux", "unix", "freebsd":
// -b option avoid kernel blocks
pid := os.Getpid()
out, err := exec.Command("/bin/sh", "-c", fmt.Sprintf("lsof -b -p %v", pid)).Output()
if err != nil {
return 0, fmt.Errorf("calling lsof: %s", err)
}
// only count lines with our pid, avoiding warning messages from -b
lines := strings.Split(string(out), strconv.Itoa(pid))
return len(lines), nil
case "windows":
// TODO: count open file handles on windows
return 0, errors.New("countOpenFiles() on Windows is not supported")
default:
return 0, errors.New("countOpenFiles() on this OS is not supported")
}
}
|
[
"func",
"countOpenFiles",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"switch",
"runtime",
".",
"GOOS",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"// -b option avoid kernel blocks",
"pid",
":=",
"os",
".",
"Getpid",
"(",
")",
"\n",
"out",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pid",
")",
")",
".",
"Output",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"// only count lines with our pid, avoiding warning messages from -b",
"lines",
":=",
"strings",
".",
"Split",
"(",
"string",
"(",
"out",
")",
",",
"strconv",
".",
"Itoa",
"(",
"pid",
")",
")",
"\n",
"return",
"len",
"(",
"lines",
")",
",",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"// TODO: count open file handles on windows",
"return",
"0",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"default",
":",
"return",
"0",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] |
// countOpenFiles on operating systems that support lsof.
|
[
"countOpenFiles",
"on",
"operating",
"systems",
"that",
"support",
"lsof",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server.go#L818-L836
|
train
|
pilosa/pilosa
|
ctl/inspect.go
|
NewInspectCommand
|
func NewInspectCommand(stdin io.Reader, stdout, stderr io.Writer) *InspectCommand {
return &InspectCommand{
CmdIO: pilosa.NewCmdIO(stdin, stdout, stderr),
}
}
|
go
|
func NewInspectCommand(stdin io.Reader, stdout, stderr io.Writer) *InspectCommand {
return &InspectCommand{
CmdIO: pilosa.NewCmdIO(stdin, stdout, stderr),
}
}
|
[
"func",
"NewInspectCommand",
"(",
"stdin",
"io",
".",
"Reader",
",",
"stdout",
",",
"stderr",
"io",
".",
"Writer",
")",
"*",
"InspectCommand",
"{",
"return",
"&",
"InspectCommand",
"{",
"CmdIO",
":",
"pilosa",
".",
"NewCmdIO",
"(",
"stdin",
",",
"stdout",
",",
"stderr",
")",
",",
"}",
"\n",
"}"
] |
// NewInspectCommand returns a new instance of InspectCommand.
|
[
"NewInspectCommand",
"returns",
"a",
"new",
"instance",
"of",
"InspectCommand",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/ctl/inspect.go#L42-L46
|
train
|
pilosa/pilosa
|
ctl/inspect.go
|
Run
|
func (cmd *InspectCommand) Run(_ context.Context) error {
// Open file handle.
f, err := os.Open(cmd.Path)
if err != nil {
return errors.Wrap(err, "opening file")
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
return errors.Wrap(err, "statting file")
}
// Memory map the file.
data, err := syscall.Mmap(int(f.Fd()), 0, int(fi.Size()), syscall.PROT_READ, syscall.MAP_SHARED)
if err != nil {
return errors.Wrap(err, "mmapping")
}
defer func() {
err := syscall.Munmap(data)
if err != nil {
fmt.Fprintf(cmd.Stderr, "inspect command: munmap failed: %v", err)
}
}()
// Attach the mmap file to the bitmap.
t := time.Now()
fmt.Fprintf(cmd.Stderr, "unmarshalling bitmap...")
bm := roaring.NewBitmap()
if err := bm.UnmarshalBinary(data); err != nil {
return errors.Wrap(err, "unmarshalling")
}
fmt.Fprintf(cmd.Stderr, " (%s)\n", time.Since(t))
// Retrieve stats.
t = time.Now()
fmt.Fprintf(cmd.Stderr, "calculating stats...")
info := bm.Info()
fmt.Fprintf(cmd.Stderr, " (%s)\n", time.Since(t))
// Print top-level info.
fmt.Fprintf(cmd.Stdout, "== Bitmap Info ==\n")
fmt.Fprintf(cmd.Stdout, "Containers: %d\n", len(info.Containers))
fmt.Fprintf(cmd.Stdout, "Operations: %d\n", info.OpN)
fmt.Fprintln(cmd.Stdout, "")
// Print info for each container.
fmt.Fprintln(cmd.Stdout, "== Containers ==")
tw := tabwriter.NewWriter(cmd.Stdout, 0, 8, 0, '\t', 0)
fmt.Fprintf(tw, "%s\t%s\t% 8s \t% 8s\t%s\n", "KEY", "TYPE", "N", "ALLOC", "OFFSET")
for _, ci := range info.Containers {
fmt.Fprintf(tw, "%d\t%s\t% 8d \t% 8d \t0x%08x\n",
ci.Key,
ci.Type,
ci.N,
ci.Alloc,
uintptr(ci.Pointer)-uintptr(unsafe.Pointer(&data[0])),
)
}
tw.Flush()
return nil
}
|
go
|
func (cmd *InspectCommand) Run(_ context.Context) error {
// Open file handle.
f, err := os.Open(cmd.Path)
if err != nil {
return errors.Wrap(err, "opening file")
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
return errors.Wrap(err, "statting file")
}
// Memory map the file.
data, err := syscall.Mmap(int(f.Fd()), 0, int(fi.Size()), syscall.PROT_READ, syscall.MAP_SHARED)
if err != nil {
return errors.Wrap(err, "mmapping")
}
defer func() {
err := syscall.Munmap(data)
if err != nil {
fmt.Fprintf(cmd.Stderr, "inspect command: munmap failed: %v", err)
}
}()
// Attach the mmap file to the bitmap.
t := time.Now()
fmt.Fprintf(cmd.Stderr, "unmarshalling bitmap...")
bm := roaring.NewBitmap()
if err := bm.UnmarshalBinary(data); err != nil {
return errors.Wrap(err, "unmarshalling")
}
fmt.Fprintf(cmd.Stderr, " (%s)\n", time.Since(t))
// Retrieve stats.
t = time.Now()
fmt.Fprintf(cmd.Stderr, "calculating stats...")
info := bm.Info()
fmt.Fprintf(cmd.Stderr, " (%s)\n", time.Since(t))
// Print top-level info.
fmt.Fprintf(cmd.Stdout, "== Bitmap Info ==\n")
fmt.Fprintf(cmd.Stdout, "Containers: %d\n", len(info.Containers))
fmt.Fprintf(cmd.Stdout, "Operations: %d\n", info.OpN)
fmt.Fprintln(cmd.Stdout, "")
// Print info for each container.
fmt.Fprintln(cmd.Stdout, "== Containers ==")
tw := tabwriter.NewWriter(cmd.Stdout, 0, 8, 0, '\t', 0)
fmt.Fprintf(tw, "%s\t%s\t% 8s \t% 8s\t%s\n", "KEY", "TYPE", "N", "ALLOC", "OFFSET")
for _, ci := range info.Containers {
fmt.Fprintf(tw, "%d\t%s\t% 8d \t% 8d \t0x%08x\n",
ci.Key,
ci.Type,
ci.N,
ci.Alloc,
uintptr(ci.Pointer)-uintptr(unsafe.Pointer(&data[0])),
)
}
tw.Flush()
return nil
}
|
[
"func",
"(",
"cmd",
"*",
"InspectCommand",
")",
"Run",
"(",
"_",
"context",
".",
"Context",
")",
"error",
"{",
"// Open file handle.",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"cmd",
".",
"Path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"fi",
",",
"err",
":=",
"f",
".",
"Stat",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Memory map the file.",
"data",
",",
"err",
":=",
"syscall",
".",
"Mmap",
"(",
"int",
"(",
"f",
".",
"Fd",
"(",
")",
")",
",",
"0",
",",
"int",
"(",
"fi",
".",
"Size",
"(",
")",
")",
",",
"syscall",
".",
"PROT_READ",
",",
"syscall",
".",
"MAP_SHARED",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"err",
":=",
"syscall",
".",
"Munmap",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintf",
"(",
"cmd",
".",
"Stderr",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"// Attach the mmap file to the bitmap.",
"t",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"cmd",
".",
"Stderr",
",",
"\"",
"\"",
")",
"\n",
"bm",
":=",
"roaring",
".",
"NewBitmap",
"(",
")",
"\n",
"if",
"err",
":=",
"bm",
".",
"UnmarshalBinary",
"(",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"cmd",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"time",
".",
"Since",
"(",
"t",
")",
")",
"\n\n",
"// Retrieve stats.",
"t",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"cmd",
".",
"Stderr",
",",
"\"",
"\"",
")",
"\n",
"info",
":=",
"bm",
".",
"Info",
"(",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"cmd",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"time",
".",
"Since",
"(",
"t",
")",
")",
"\n\n",
"// Print top-level info.",
"fmt",
".",
"Fprintf",
"(",
"cmd",
".",
"Stdout",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"cmd",
".",
"Stdout",
",",
"\"",
"\\n",
"\"",
",",
"len",
"(",
"info",
".",
"Containers",
")",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"cmd",
".",
"Stdout",
",",
"\"",
"\\n",
"\"",
",",
"info",
".",
"OpN",
")",
"\n",
"fmt",
".",
"Fprintln",
"(",
"cmd",
".",
"Stdout",
",",
"\"",
"\"",
")",
"\n\n",
"// Print info for each container.",
"fmt",
".",
"Fprintln",
"(",
"cmd",
".",
"Stdout",
",",
"\"",
"\"",
")",
"\n",
"tw",
":=",
"tabwriter",
".",
"NewWriter",
"(",
"cmd",
".",
"Stdout",
",",
"0",
",",
"8",
",",
"0",
",",
"'\\t'",
",",
"0",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"tw",
",",
"\"",
"\\t",
"\\t",
"\\t",
"\\t",
"\\n",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"ci",
":=",
"range",
"info",
".",
"Containers",
"{",
"fmt",
".",
"Fprintf",
"(",
"tw",
",",
"\"",
"\\t",
"\\t",
"\\t",
"\\t",
"\\n",
"\"",
",",
"ci",
".",
"Key",
",",
"ci",
".",
"Type",
",",
"ci",
".",
"N",
",",
"ci",
".",
"Alloc",
",",
"uintptr",
"(",
"ci",
".",
"Pointer",
")",
"-",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"data",
"[",
"0",
"]",
")",
")",
",",
")",
"\n",
"}",
"\n",
"tw",
".",
"Flush",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Run executes the inspect command.
|
[
"Run",
"executes",
"the",
"inspect",
"command",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/ctl/inspect.go#L49-L110
|
train
|
pilosa/pilosa
|
index.go
|
Options
|
func (i *Index) Options() IndexOptions {
i.mu.RLock()
defer i.mu.RUnlock()
return i.options()
}
|
go
|
func (i *Index) Options() IndexOptions {
i.mu.RLock()
defer i.mu.RUnlock()
return i.options()
}
|
[
"func",
"(",
"i",
"*",
"Index",
")",
"Options",
"(",
")",
"IndexOptions",
"{",
"i",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"i",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"i",
".",
"options",
"(",
")",
"\n",
"}"
] |
// Options returns all options for this index.
|
[
"Options",
"returns",
"all",
"options",
"for",
"this",
"index",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/index.go#L94-L98
|
train
|
pilosa/pilosa
|
index.go
|
Open
|
func (i *Index) Open() error {
// Ensure the path exists.
i.logger.Debugf("ensure index path exists: %s", i.path)
if err := os.MkdirAll(i.path, 0777); err != nil {
return errors.Wrap(err, "creating directory")
}
// Read meta file.
i.logger.Debugf("load meta file for index: %s", i.name)
if err := i.loadMeta(); err != nil {
return errors.Wrap(err, "loading meta file")
}
i.logger.Debugf("open fields for index: %s", i.name)
if err := i.openFields(); err != nil {
return errors.Wrap(err, "opening fields")
}
if i.trackExistence {
if err := i.openExistenceField(); err != nil {
return errors.Wrap(err, "opening existence field")
}
}
if err := i.columnAttrs.Open(); err != nil {
return errors.Wrap(err, "opening attrstore")
}
return nil
}
|
go
|
func (i *Index) Open() error {
// Ensure the path exists.
i.logger.Debugf("ensure index path exists: %s", i.path)
if err := os.MkdirAll(i.path, 0777); err != nil {
return errors.Wrap(err, "creating directory")
}
// Read meta file.
i.logger.Debugf("load meta file for index: %s", i.name)
if err := i.loadMeta(); err != nil {
return errors.Wrap(err, "loading meta file")
}
i.logger.Debugf("open fields for index: %s", i.name)
if err := i.openFields(); err != nil {
return errors.Wrap(err, "opening fields")
}
if i.trackExistence {
if err := i.openExistenceField(); err != nil {
return errors.Wrap(err, "opening existence field")
}
}
if err := i.columnAttrs.Open(); err != nil {
return errors.Wrap(err, "opening attrstore")
}
return nil
}
|
[
"func",
"(",
"i",
"*",
"Index",
")",
"Open",
"(",
")",
"error",
"{",
"// Ensure the path exists.",
"i",
".",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"i",
".",
"path",
")",
"\n",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"i",
".",
"path",
",",
"0777",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Read meta file.",
"i",
".",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"i",
".",
"name",
")",
"\n",
"if",
"err",
":=",
"i",
".",
"loadMeta",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"i",
".",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"i",
".",
"name",
")",
"\n",
"if",
"err",
":=",
"i",
".",
"openFields",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"i",
".",
"trackExistence",
"{",
"if",
"err",
":=",
"i",
".",
"openExistenceField",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"i",
".",
"columnAttrs",
".",
"Open",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Open opens and initializes the index.
|
[
"Open",
"opens",
"and",
"initializes",
"the",
"index",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/index.go#L108-L137
|
train
|
pilosa/pilosa
|
index.go
|
openFields
|
func (i *Index) openFields() error {
f, err := os.Open(i.path)
if err != nil {
return errors.Wrap(err, "opening directory")
}
defer f.Close()
fis, err := f.Readdir(0)
if err != nil {
return errors.Wrap(err, "reading directory")
}
for _, fi := range fis {
if !fi.IsDir() {
continue
}
i.logger.Debugf("open field: %s", fi.Name())
fld, err := i.newField(i.fieldPath(filepath.Base(fi.Name())), filepath.Base(fi.Name()))
if err != nil {
return errors.Wrapf(ErrName, "'%s'", fi.Name())
}
if err := fld.Open(); err != nil {
return fmt.Errorf("open field: name=%s, err=%s", fld.Name(), err)
}
i.logger.Debugf("add field to index.fields: %s", fi.Name())
i.fields[fld.Name()] = fld
}
return nil
}
|
go
|
func (i *Index) openFields() error {
f, err := os.Open(i.path)
if err != nil {
return errors.Wrap(err, "opening directory")
}
defer f.Close()
fis, err := f.Readdir(0)
if err != nil {
return errors.Wrap(err, "reading directory")
}
for _, fi := range fis {
if !fi.IsDir() {
continue
}
i.logger.Debugf("open field: %s", fi.Name())
fld, err := i.newField(i.fieldPath(filepath.Base(fi.Name())), filepath.Base(fi.Name()))
if err != nil {
return errors.Wrapf(ErrName, "'%s'", fi.Name())
}
if err := fld.Open(); err != nil {
return fmt.Errorf("open field: name=%s, err=%s", fld.Name(), err)
}
i.logger.Debugf("add field to index.fields: %s", fi.Name())
i.fields[fld.Name()] = fld
}
return nil
}
|
[
"func",
"(",
"i",
"*",
"Index",
")",
"openFields",
"(",
")",
"error",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"i",
".",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"fis",
",",
"err",
":=",
"f",
".",
"Readdir",
"(",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"fi",
":=",
"range",
"fis",
"{",
"if",
"!",
"fi",
".",
"IsDir",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"i",
".",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"fi",
".",
"Name",
"(",
")",
")",
"\n",
"fld",
",",
"err",
":=",
"i",
".",
"newField",
"(",
"i",
".",
"fieldPath",
"(",
"filepath",
".",
"Base",
"(",
"fi",
".",
"Name",
"(",
")",
")",
")",
",",
"filepath",
".",
"Base",
"(",
"fi",
".",
"Name",
"(",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"ErrName",
",",
"\"",
"\"",
",",
"fi",
".",
"Name",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"fld",
".",
"Open",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fld",
".",
"Name",
"(",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"i",
".",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"fi",
".",
"Name",
"(",
")",
")",
"\n",
"i",
".",
"fields",
"[",
"fld",
".",
"Name",
"(",
")",
"]",
"=",
"fld",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// openFields opens and initializes the fields inside the index.
|
[
"openFields",
"opens",
"and",
"initializes",
"the",
"fields",
"inside",
"the",
"index",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/index.go#L140-L169
|
train
|
pilosa/pilosa
|
index.go
|
openExistenceField
|
func (i *Index) openExistenceField() error {
f, err := i.createFieldIfNotExists(existenceFieldName, FieldOptions{CacheType: CacheTypeNone, CacheSize: 0})
if err != nil {
return errors.Wrap(err, "creating existence field")
}
i.existenceFld = f
return nil
}
|
go
|
func (i *Index) openExistenceField() error {
f, err := i.createFieldIfNotExists(existenceFieldName, FieldOptions{CacheType: CacheTypeNone, CacheSize: 0})
if err != nil {
return errors.Wrap(err, "creating existence field")
}
i.existenceFld = f
return nil
}
|
[
"func",
"(",
"i",
"*",
"Index",
")",
"openExistenceField",
"(",
")",
"error",
"{",
"f",
",",
"err",
":=",
"i",
".",
"createFieldIfNotExists",
"(",
"existenceFieldName",
",",
"FieldOptions",
"{",
"CacheType",
":",
"CacheTypeNone",
",",
"CacheSize",
":",
"0",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"i",
".",
"existenceFld",
"=",
"f",
"\n",
"return",
"nil",
"\n",
"}"
] |
// openExistenceField gets or creates the existence field and associates it to the index.
|
[
"openExistenceField",
"gets",
"or",
"creates",
"the",
"existence",
"field",
"and",
"associates",
"it",
"to",
"the",
"index",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/index.go#L172-L179
|
train
|
pilosa/pilosa
|
index.go
|
loadMeta
|
func (i *Index) loadMeta() error {
var pb internal.IndexMeta
// Read data from meta file.
buf, err := ioutil.ReadFile(filepath.Join(i.path, ".meta"))
if os.IsNotExist(err) {
return nil
} else if err != nil {
return errors.Wrap(err, "reading")
} else {
if err := proto.Unmarshal(buf, &pb); err != nil {
return errors.Wrap(err, "unmarshalling")
}
}
// Copy metadata fields.
i.keys = pb.Keys
i.trackExistence = pb.TrackExistence
return nil
}
|
go
|
func (i *Index) loadMeta() error {
var pb internal.IndexMeta
// Read data from meta file.
buf, err := ioutil.ReadFile(filepath.Join(i.path, ".meta"))
if os.IsNotExist(err) {
return nil
} else if err != nil {
return errors.Wrap(err, "reading")
} else {
if err := proto.Unmarshal(buf, &pb); err != nil {
return errors.Wrap(err, "unmarshalling")
}
}
// Copy metadata fields.
i.keys = pb.Keys
i.trackExistence = pb.TrackExistence
return nil
}
|
[
"func",
"(",
"i",
"*",
"Index",
")",
"loadMeta",
"(",
")",
"error",
"{",
"var",
"pb",
"internal",
".",
"IndexMeta",
"\n\n",
"// Read data from meta file.",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filepath",
".",
"Join",
"(",
"i",
".",
"path",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"nil",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"if",
"err",
":=",
"proto",
".",
"Unmarshal",
"(",
"buf",
",",
"&",
"pb",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Copy metadata fields.",
"i",
".",
"keys",
"=",
"pb",
".",
"Keys",
"\n",
"i",
".",
"trackExistence",
"=",
"pb",
".",
"TrackExistence",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// loadMeta reads meta data for the index, if any.
|
[
"loadMeta",
"reads",
"meta",
"data",
"for",
"the",
"index",
"if",
"any",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/index.go#L182-L202
|
train
|
pilosa/pilosa
|
index.go
|
saveMeta
|
func (i *Index) saveMeta() error {
// Marshal metadata.
buf, err := proto.Marshal(&internal.IndexMeta{
Keys: i.keys,
TrackExistence: i.trackExistence,
})
if err != nil {
return errors.Wrap(err, "marshalling")
}
// Write to meta file.
if err := ioutil.WriteFile(filepath.Join(i.path, ".meta"), buf, 0666); err != nil {
return errors.Wrap(err, "writing")
}
return nil
}
|
go
|
func (i *Index) saveMeta() error {
// Marshal metadata.
buf, err := proto.Marshal(&internal.IndexMeta{
Keys: i.keys,
TrackExistence: i.trackExistence,
})
if err != nil {
return errors.Wrap(err, "marshalling")
}
// Write to meta file.
if err := ioutil.WriteFile(filepath.Join(i.path, ".meta"), buf, 0666); err != nil {
return errors.Wrap(err, "writing")
}
return nil
}
|
[
"func",
"(",
"i",
"*",
"Index",
")",
"saveMeta",
"(",
")",
"error",
"{",
"// Marshal metadata.",
"buf",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"&",
"internal",
".",
"IndexMeta",
"{",
"Keys",
":",
"i",
".",
"keys",
",",
"TrackExistence",
":",
"i",
".",
"trackExistence",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Write to meta file.",
"if",
"err",
":=",
"ioutil",
".",
"WriteFile",
"(",
"filepath",
".",
"Join",
"(",
"i",
".",
"path",
",",
"\"",
"\"",
")",
",",
"buf",
",",
"0666",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// saveMeta writes meta data for the index.
|
[
"saveMeta",
"writes",
"meta",
"data",
"for",
"the",
"index",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/index.go#L205-L221
|
train
|
pilosa/pilosa
|
index.go
|
Close
|
func (i *Index) Close() error {
i.mu.Lock()
defer i.mu.Unlock()
// Close the attribute store.
i.columnAttrs.Close()
// Close all fields.
for _, f := range i.fields {
if err := f.Close(); err != nil {
return errors.Wrap(err, "closing field")
}
}
i.fields = make(map[string]*Field)
return nil
}
|
go
|
func (i *Index) Close() error {
i.mu.Lock()
defer i.mu.Unlock()
// Close the attribute store.
i.columnAttrs.Close()
// Close all fields.
for _, f := range i.fields {
if err := f.Close(); err != nil {
return errors.Wrap(err, "closing field")
}
}
i.fields = make(map[string]*Field)
return nil
}
|
[
"func",
"(",
"i",
"*",
"Index",
")",
"Close",
"(",
")",
"error",
"{",
"i",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"i",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Close the attribute store.",
"i",
".",
"columnAttrs",
".",
"Close",
"(",
")",
"\n\n",
"// Close all fields.",
"for",
"_",
",",
"f",
":=",
"range",
"i",
".",
"fields",
"{",
"if",
"err",
":=",
"f",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"i",
".",
"fields",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Field",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Close closes the index and its fields.
|
[
"Close",
"closes",
"the",
"index",
"and",
"its",
"fields",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/index.go#L224-L240
|
train
|
pilosa/pilosa
|
index.go
|
AvailableShards
|
func (i *Index) AvailableShards() *roaring.Bitmap {
if i == nil {
return roaring.NewBitmap()
}
i.mu.RLock()
defer i.mu.RUnlock()
b := roaring.NewBitmap()
for _, f := range i.fields {
b = b.Union(f.AvailableShards())
}
i.Stats.Gauge("maxShard", float64(b.Max()), 1.0)
return b
}
|
go
|
func (i *Index) AvailableShards() *roaring.Bitmap {
if i == nil {
return roaring.NewBitmap()
}
i.mu.RLock()
defer i.mu.RUnlock()
b := roaring.NewBitmap()
for _, f := range i.fields {
b = b.Union(f.AvailableShards())
}
i.Stats.Gauge("maxShard", float64(b.Max()), 1.0)
return b
}
|
[
"func",
"(",
"i",
"*",
"Index",
")",
"AvailableShards",
"(",
")",
"*",
"roaring",
".",
"Bitmap",
"{",
"if",
"i",
"==",
"nil",
"{",
"return",
"roaring",
".",
"NewBitmap",
"(",
")",
"\n",
"}",
"\n\n",
"i",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"i",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"b",
":=",
"roaring",
".",
"NewBitmap",
"(",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"i",
".",
"fields",
"{",
"b",
"=",
"b",
".",
"Union",
"(",
"f",
".",
"AvailableShards",
"(",
")",
")",
"\n",
"}",
"\n\n",
"i",
".",
"Stats",
".",
"Gauge",
"(",
"\"",
"\"",
",",
"float64",
"(",
"b",
".",
"Max",
"(",
")",
")",
",",
"1.0",
")",
"\n",
"return",
"b",
"\n",
"}"
] |
// AvailableShards returns a bitmap of all shards with data in the index.
|
[
"AvailableShards",
"returns",
"a",
"bitmap",
"of",
"all",
"shards",
"with",
"data",
"in",
"the",
"index",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/index.go#L243-L258
|
train
|
pilosa/pilosa
|
index.go
|
Field
|
func (i *Index) Field(name string) *Field {
i.mu.RLock()
defer i.mu.RUnlock()
return i.field(name)
}
|
go
|
func (i *Index) Field(name string) *Field {
i.mu.RLock()
defer i.mu.RUnlock()
return i.field(name)
}
|
[
"func",
"(",
"i",
"*",
"Index",
")",
"Field",
"(",
"name",
"string",
")",
"*",
"Field",
"{",
"i",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"i",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"i",
".",
"field",
"(",
"name",
")",
"\n",
"}"
] |
// Field returns a field in the index by name.
|
[
"Field",
"returns",
"a",
"field",
"in",
"the",
"index",
"by",
"name",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/index.go#L264-L268
|
train
|
pilosa/pilosa
|
index.go
|
Fields
|
func (i *Index) Fields() []*Field {
i.mu.RLock()
defer i.mu.RUnlock()
a := make([]*Field, 0, len(i.fields))
for _, f := range i.fields {
a = append(a, f)
}
sort.Sort(fieldSlice(a))
return a
}
|
go
|
func (i *Index) Fields() []*Field {
i.mu.RLock()
defer i.mu.RUnlock()
a := make([]*Field, 0, len(i.fields))
for _, f := range i.fields {
a = append(a, f)
}
sort.Sort(fieldSlice(a))
return a
}
|
[
"func",
"(",
"i",
"*",
"Index",
")",
"Fields",
"(",
")",
"[",
"]",
"*",
"Field",
"{",
"i",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"i",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"a",
":=",
"make",
"(",
"[",
"]",
"*",
"Field",
",",
"0",
",",
"len",
"(",
"i",
".",
"fields",
")",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"i",
".",
"fields",
"{",
"a",
"=",
"append",
"(",
"a",
",",
"f",
")",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"fieldSlice",
"(",
"a",
")",
")",
"\n\n",
"return",
"a",
"\n",
"}"
] |
// Fields returns a list of all fields in the index.
|
[
"Fields",
"returns",
"a",
"list",
"of",
"all",
"fields",
"in",
"the",
"index",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/index.go#L273-L284
|
train
|
pilosa/pilosa
|
index.go
|
existenceField
|
func (i *Index) existenceField() *Field {
i.mu.RLock()
defer i.mu.RUnlock()
return i.existenceFld
}
|
go
|
func (i *Index) existenceField() *Field {
i.mu.RLock()
defer i.mu.RUnlock()
return i.existenceFld
}
|
[
"func",
"(",
"i",
"*",
"Index",
")",
"existenceField",
"(",
")",
"*",
"Field",
"{",
"i",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"i",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"i",
".",
"existenceFld",
"\n",
"}"
] |
// existenceField returns the internal field used to track column existence.
|
[
"existenceField",
"returns",
"the",
"internal",
"field",
"used",
"to",
"track",
"column",
"existence",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/index.go#L287-L292
|
train
|
pilosa/pilosa
|
index.go
|
CreateFieldIfNotExists
|
func (i *Index) CreateFieldIfNotExists(name string, opts ...FieldOption) (*Field, error) {
err := validateName(name)
if err != nil {
return nil, errors.Wrap(err, "validating name")
}
i.mu.Lock()
defer i.mu.Unlock()
// Find field in cache first.
if f := i.fields[name]; f != nil {
return f, nil
}
// Apply functional options.
fo := FieldOptions{}
for _, opt := range opts {
err := opt(&fo)
if err != nil {
return nil, errors.Wrap(err, "applying option")
}
}
return i.createField(name, fo)
}
|
go
|
func (i *Index) CreateFieldIfNotExists(name string, opts ...FieldOption) (*Field, error) {
err := validateName(name)
if err != nil {
return nil, errors.Wrap(err, "validating name")
}
i.mu.Lock()
defer i.mu.Unlock()
// Find field in cache first.
if f := i.fields[name]; f != nil {
return f, nil
}
// Apply functional options.
fo := FieldOptions{}
for _, opt := range opts {
err := opt(&fo)
if err != nil {
return nil, errors.Wrap(err, "applying option")
}
}
return i.createField(name, fo)
}
|
[
"func",
"(",
"i",
"*",
"Index",
")",
"CreateFieldIfNotExists",
"(",
"name",
"string",
",",
"opts",
"...",
"FieldOption",
")",
"(",
"*",
"Field",
",",
"error",
")",
"{",
"err",
":=",
"validateName",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"i",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"i",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Find field in cache first.",
"if",
"f",
":=",
"i",
".",
"fields",
"[",
"name",
"]",
";",
"f",
"!=",
"nil",
"{",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n\n",
"// Apply functional options.",
"fo",
":=",
"FieldOptions",
"{",
"}",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"err",
":=",
"opt",
"(",
"&",
"fo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"i",
".",
"createField",
"(",
"name",
",",
"fo",
")",
"\n",
"}"
] |
// CreateFieldIfNotExists creates a field with the given options if it doesn't exist.
|
[
"CreateFieldIfNotExists",
"creates",
"a",
"field",
"with",
"the",
"given",
"options",
"if",
"it",
"doesn",
"t",
"exist",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/index.go#L329-L353
|
train
|
pilosa/pilosa
|
index.go
|
DeleteField
|
func (i *Index) DeleteField(name string) error {
i.mu.Lock()
defer i.mu.Unlock()
// Confirm field exists.
f := i.field(name)
if f == nil {
return newNotFoundError(ErrFieldNotFound)
}
// Close field.
if err := f.Close(); err != nil {
return errors.Wrap(err, "closing")
}
// Delete field directory.
if err := os.RemoveAll(i.fieldPath(name)); err != nil {
return errors.Wrap(err, "removing directory")
}
// If the field being deleted is the existence field,
// turn off existence tracking on the index.
if name == existenceFieldName {
i.trackExistence = false
i.existenceFld = nil
// Update meta data on disk.
if err := i.saveMeta(); err != nil {
return errors.Wrap(err, "saving existence meta data")
}
}
// Remove reference.
delete(i.fields, name)
return nil
}
|
go
|
func (i *Index) DeleteField(name string) error {
i.mu.Lock()
defer i.mu.Unlock()
// Confirm field exists.
f := i.field(name)
if f == nil {
return newNotFoundError(ErrFieldNotFound)
}
// Close field.
if err := f.Close(); err != nil {
return errors.Wrap(err, "closing")
}
// Delete field directory.
if err := os.RemoveAll(i.fieldPath(name)); err != nil {
return errors.Wrap(err, "removing directory")
}
// If the field being deleted is the existence field,
// turn off existence tracking on the index.
if name == existenceFieldName {
i.trackExistence = false
i.existenceFld = nil
// Update meta data on disk.
if err := i.saveMeta(); err != nil {
return errors.Wrap(err, "saving existence meta data")
}
}
// Remove reference.
delete(i.fields, name)
return nil
}
|
[
"func",
"(",
"i",
"*",
"Index",
")",
"DeleteField",
"(",
"name",
"string",
")",
"error",
"{",
"i",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"i",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Confirm field exists.",
"f",
":=",
"i",
".",
"field",
"(",
"name",
")",
"\n",
"if",
"f",
"==",
"nil",
"{",
"return",
"newNotFoundError",
"(",
"ErrFieldNotFound",
")",
"\n",
"}",
"\n\n",
"// Close field.",
"if",
"err",
":=",
"f",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Delete field directory.",
"if",
"err",
":=",
"os",
".",
"RemoveAll",
"(",
"i",
".",
"fieldPath",
"(",
"name",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// If the field being deleted is the existence field,",
"// turn off existence tracking on the index.",
"if",
"name",
"==",
"existenceFieldName",
"{",
"i",
".",
"trackExistence",
"=",
"false",
"\n",
"i",
".",
"existenceFld",
"=",
"nil",
"\n\n",
"// Update meta data on disk.",
"if",
"err",
":=",
"i",
".",
"saveMeta",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Remove reference.",
"delete",
"(",
"i",
".",
"fields",
",",
"name",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// DeleteField removes a field from the index.
|
[
"DeleteField",
"removes",
"a",
"field",
"from",
"the",
"index",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/index.go#L415-L451
|
train
|
pilosa/pilosa
|
index.go
|
hasTime
|
func hasTime(a []*time.Time) bool {
for _, t := range a {
if t != nil {
return true
}
}
return false
}
|
go
|
func hasTime(a []*time.Time) bool {
for _, t := range a {
if t != nil {
return true
}
}
return false
}
|
[
"func",
"hasTime",
"(",
"a",
"[",
"]",
"*",
"time",
".",
"Time",
")",
"bool",
"{",
"for",
"_",
",",
"t",
":=",
"range",
"a",
"{",
"if",
"t",
"!=",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// hasTime returns true if a contains a non-nil time.
|
[
"hasTime",
"returns",
"true",
"if",
"a",
"contains",
"a",
"non",
"-",
"nil",
"time",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/index.go#L480-L487
|
train
|
pilosa/pilosa
|
tracing/tracing.go
|
StartSpanFromContext
|
func StartSpanFromContext(ctx context.Context, operationName string) (Span, context.Context) {
return GlobalTracer.StartSpanFromContext(ctx, operationName)
}
|
go
|
func StartSpanFromContext(ctx context.Context, operationName string) (Span, context.Context) {
return GlobalTracer.StartSpanFromContext(ctx, operationName)
}
|
[
"func",
"StartSpanFromContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"operationName",
"string",
")",
"(",
"Span",
",",
"context",
".",
"Context",
")",
"{",
"return",
"GlobalTracer",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"operationName",
")",
"\n",
"}"
] |
// StartSpanFromContext returnus a new child span and context from a given
// context using the global tracer.
|
[
"StartSpanFromContext",
"returnus",
"a",
"new",
"child",
"span",
"and",
"context",
"from",
"a",
"given",
"context",
"using",
"the",
"global",
"tracer",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/tracing/tracing.go#L27-L29
|
train
|
pilosa/pilosa
|
broadcast.go
|
MarshalInternalMessage
|
func MarshalInternalMessage(m Message, s Serializer) ([]byte, error) {
typ := getMessageType(m)
buf, err := s.Marshal(m)
if err != nil {
return nil, errors.Wrap(err, "marshaling")
}
return append([]byte{typ}, buf...), nil
}
|
go
|
func MarshalInternalMessage(m Message, s Serializer) ([]byte, error) {
typ := getMessageType(m)
buf, err := s.Marshal(m)
if err != nil {
return nil, errors.Wrap(err, "marshaling")
}
return append([]byte{typ}, buf...), nil
}
|
[
"func",
"MarshalInternalMessage",
"(",
"m",
"Message",
",",
"s",
"Serializer",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"typ",
":=",
"getMessageType",
"(",
"m",
")",
"\n",
"buf",
",",
"err",
":=",
"s",
".",
"Marshal",
"(",
"m",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"append",
"(",
"[",
"]",
"byte",
"{",
"typ",
"}",
",",
"buf",
"...",
")",
",",
"nil",
"\n",
"}"
] |
// MarshalInternalMessage serializes the pilosa message and adds pilosa internal
// type info which is used by the internal messaging stuff.
|
[
"MarshalInternalMessage",
"serializes",
"the",
"pilosa",
"message",
"and",
"adds",
"pilosa",
"internal",
"type",
"info",
"which",
"is",
"used",
"by",
"the",
"internal",
"messaging",
"stuff",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/broadcast.go#L76-L83
|
train
|
pilosa/pilosa
|
statsd/statsd.go
|
NewStatsClient
|
func NewStatsClient(host string) (*statsClient, error) {
c, err := statsd.NewBuffered(host, bufferLen)
if err != nil {
return nil, err
}
return &statsClient{
client: c,
logger: logger.NopLogger,
}, nil
}
|
go
|
func NewStatsClient(host string) (*statsClient, error) {
c, err := statsd.NewBuffered(host, bufferLen)
if err != nil {
return nil, err
}
return &statsClient{
client: c,
logger: logger.NopLogger,
}, nil
}
|
[
"func",
"NewStatsClient",
"(",
"host",
"string",
")",
"(",
"*",
"statsClient",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"statsd",
".",
"NewBuffered",
"(",
"host",
",",
"bufferLen",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"statsClient",
"{",
"client",
":",
"c",
",",
"logger",
":",
"logger",
".",
"NopLogger",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// NewStatsClient returns a new instance of StatsClient.
|
[
"NewStatsClient",
"returns",
"a",
"new",
"instance",
"of",
"StatsClient",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/statsd/statsd.go#L48-L58
|
train
|
pilosa/pilosa
|
statsd/statsd.go
|
Count
|
func (c *statsClient) Count(name string, value int64, rate float64) {
if err := c.client.Count(prefix+name, value, c.tags, rate); err != nil {
c.logger.Printf("statsd.StatsClient.Count error: %s", err)
}
}
|
go
|
func (c *statsClient) Count(name string, value int64, rate float64) {
if err := c.client.Count(prefix+name, value, c.tags, rate); err != nil {
c.logger.Printf("statsd.StatsClient.Count error: %s", err)
}
}
|
[
"func",
"(",
"c",
"*",
"statsClient",
")",
"Count",
"(",
"name",
"string",
",",
"value",
"int64",
",",
"rate",
"float64",
")",
"{",
"if",
"err",
":=",
"c",
".",
"client",
".",
"Count",
"(",
"prefix",
"+",
"name",
",",
"value",
",",
"c",
".",
"tags",
",",
"rate",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// Count tracks the number of times something occurs per second.
|
[
"Count",
"tracks",
"the",
"number",
"of",
"times",
"something",
"occurs",
"per",
"second",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/statsd/statsd.go#L83-L87
|
train
|
pilosa/pilosa
|
statsd/statsd.go
|
unionStringSlice
|
func unionStringSlice(a, b []string) []string {
// Sort both sets first.
sort.Strings(a)
sort.Strings(b)
// Find size of largest slice.
n := len(a)
if len(b) > n {
n = len(b)
}
// Exit if both sets are empty.
if n == 0 {
return nil
}
// Iterate over both in order and merge.
other := make([]string, 0, n)
for len(a) > 0 || len(b) > 0 {
if len(a) == 0 {
other, b = append(other, b[0]), b[1:]
} else if len(b) == 0 {
other, a = append(other, a[0]), a[1:]
} else if a[0] < b[0] {
other, a = append(other, a[0]), a[1:]
} else if b[0] < a[0] {
other, b = append(other, b[0]), b[1:]
} else {
other, a, b = append(other, a[0]), a[1:], b[1:]
}
}
return other
}
|
go
|
func unionStringSlice(a, b []string) []string {
// Sort both sets first.
sort.Strings(a)
sort.Strings(b)
// Find size of largest slice.
n := len(a)
if len(b) > n {
n = len(b)
}
// Exit if both sets are empty.
if n == 0 {
return nil
}
// Iterate over both in order and merge.
other := make([]string, 0, n)
for len(a) > 0 || len(b) > 0 {
if len(a) == 0 {
other, b = append(other, b[0]), b[1:]
} else if len(b) == 0 {
other, a = append(other, a[0]), a[1:]
} else if a[0] < b[0] {
other, a = append(other, a[0]), a[1:]
} else if b[0] < a[0] {
other, b = append(other, b[0]), b[1:]
} else {
other, a, b = append(other, a[0]), a[1:], b[1:]
}
}
return other
}
|
[
"func",
"unionStringSlice",
"(",
"a",
",",
"b",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"// Sort both sets first.",
"sort",
".",
"Strings",
"(",
"a",
")",
"\n",
"sort",
".",
"Strings",
"(",
"b",
")",
"\n\n",
"// Find size of largest slice.",
"n",
":=",
"len",
"(",
"a",
")",
"\n",
"if",
"len",
"(",
"b",
")",
">",
"n",
"{",
"n",
"=",
"len",
"(",
"b",
")",
"\n",
"}",
"\n\n",
"// Exit if both sets are empty.",
"if",
"n",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Iterate over both in order and merge.",
"other",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"n",
")",
"\n",
"for",
"len",
"(",
"a",
")",
">",
"0",
"||",
"len",
"(",
"b",
")",
">",
"0",
"{",
"if",
"len",
"(",
"a",
")",
"==",
"0",
"{",
"other",
",",
"b",
"=",
"append",
"(",
"other",
",",
"b",
"[",
"0",
"]",
")",
",",
"b",
"[",
"1",
":",
"]",
"\n",
"}",
"else",
"if",
"len",
"(",
"b",
")",
"==",
"0",
"{",
"other",
",",
"a",
"=",
"append",
"(",
"other",
",",
"a",
"[",
"0",
"]",
")",
",",
"a",
"[",
"1",
":",
"]",
"\n",
"}",
"else",
"if",
"a",
"[",
"0",
"]",
"<",
"b",
"[",
"0",
"]",
"{",
"other",
",",
"a",
"=",
"append",
"(",
"other",
",",
"a",
"[",
"0",
"]",
")",
",",
"a",
"[",
"1",
":",
"]",
"\n",
"}",
"else",
"if",
"b",
"[",
"0",
"]",
"<",
"a",
"[",
"0",
"]",
"{",
"other",
",",
"b",
"=",
"append",
"(",
"other",
",",
"b",
"[",
"0",
"]",
")",
",",
"b",
"[",
"1",
":",
"]",
"\n",
"}",
"else",
"{",
"other",
",",
"a",
",",
"b",
"=",
"append",
"(",
"other",
",",
"a",
"[",
"0",
"]",
")",
",",
"a",
"[",
"1",
":",
"]",
",",
"b",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"other",
"\n",
"}"
] |
// unionStringSlice returns a sorted set of tags which combine a & b.
|
[
"unionStringSlice",
"returns",
"a",
"sorted",
"set",
"of",
"tags",
"which",
"combine",
"a",
"&",
"b",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/statsd/statsd.go#L131-L163
|
train
|
pilosa/pilosa
|
attr.go
|
Diff
|
func (a attrBlocks) Diff(other []AttrBlock) []uint64 {
var ids []uint64
for {
// Read next block from each list.
var blk0, blk1 *AttrBlock
if len(a) > 0 {
blk0 = &a[0]
}
if len(other) > 0 {
blk1 = &other[0]
}
// Exit if "a" contains no more blocks.
if blk0 == nil {
return ids
}
// Add block ID if it's different or if it's only in "a".
if blk1 == nil || blk0.ID < blk1.ID {
ids = append(ids, blk0.ID)
a = a[1:]
} else if blk1.ID < blk0.ID {
other = other[1:]
} else {
if !bytes.Equal(blk0.Checksum, blk1.Checksum) {
ids = append(ids, blk0.ID)
}
a, other = a[1:], other[1:]
}
}
}
|
go
|
func (a attrBlocks) Diff(other []AttrBlock) []uint64 {
var ids []uint64
for {
// Read next block from each list.
var blk0, blk1 *AttrBlock
if len(a) > 0 {
blk0 = &a[0]
}
if len(other) > 0 {
blk1 = &other[0]
}
// Exit if "a" contains no more blocks.
if blk0 == nil {
return ids
}
// Add block ID if it's different or if it's only in "a".
if blk1 == nil || blk0.ID < blk1.ID {
ids = append(ids, blk0.ID)
a = a[1:]
} else if blk1.ID < blk0.ID {
other = other[1:]
} else {
if !bytes.Equal(blk0.Checksum, blk1.Checksum) {
ids = append(ids, blk0.ID)
}
a, other = a[1:], other[1:]
}
}
}
|
[
"func",
"(",
"a",
"attrBlocks",
")",
"Diff",
"(",
"other",
"[",
"]",
"AttrBlock",
")",
"[",
"]",
"uint64",
"{",
"var",
"ids",
"[",
"]",
"uint64",
"\n",
"for",
"{",
"// Read next block from each list.",
"var",
"blk0",
",",
"blk1",
"*",
"AttrBlock",
"\n",
"if",
"len",
"(",
"a",
")",
">",
"0",
"{",
"blk0",
"=",
"&",
"a",
"[",
"0",
"]",
"\n",
"}",
"\n",
"if",
"len",
"(",
"other",
")",
">",
"0",
"{",
"blk1",
"=",
"&",
"other",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"// Exit if \"a\" contains no more blocks.",
"if",
"blk0",
"==",
"nil",
"{",
"return",
"ids",
"\n",
"}",
"\n\n",
"// Add block ID if it's different or if it's only in \"a\".",
"if",
"blk1",
"==",
"nil",
"||",
"blk0",
".",
"ID",
"<",
"blk1",
".",
"ID",
"{",
"ids",
"=",
"append",
"(",
"ids",
",",
"blk0",
".",
"ID",
")",
"\n",
"a",
"=",
"a",
"[",
"1",
":",
"]",
"\n",
"}",
"else",
"if",
"blk1",
".",
"ID",
"<",
"blk0",
".",
"ID",
"{",
"other",
"=",
"other",
"[",
"1",
":",
"]",
"\n",
"}",
"else",
"{",
"if",
"!",
"bytes",
".",
"Equal",
"(",
"blk0",
".",
"Checksum",
",",
"blk1",
".",
"Checksum",
")",
"{",
"ids",
"=",
"append",
"(",
"ids",
",",
"blk0",
".",
"ID",
")",
"\n",
"}",
"\n",
"a",
",",
"other",
"=",
"a",
"[",
"1",
":",
"]",
",",
"other",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// Diff returns a list of block ids that are different or are new in other.
// Block lists must be in sorted order.
|
[
"Diff",
"returns",
"a",
"list",
"of",
"block",
"ids",
"that",
"are",
"different",
"or",
"are",
"new",
"in",
"other",
".",
"Block",
"lists",
"must",
"be",
"in",
"sorted",
"order",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/attr.go#L90-L120
|
train
|
pilosa/pilosa
|
attr.go
|
cloneAttrs
|
func cloneAttrs(m map[string]interface{}) map[string]interface{} {
other := make(map[string]interface{}, len(m))
for k, v := range m {
other[k] = v
}
return other
}
|
go
|
func cloneAttrs(m map[string]interface{}) map[string]interface{} {
other := make(map[string]interface{}, len(m))
for k, v := range m {
other[k] = v
}
return other
}
|
[
"func",
"cloneAttrs",
"(",
"m",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"other",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"m",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"m",
"{",
"other",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"return",
"other",
"\n",
"}"
] |
// cloneAttrs returns a shallow clone of m.
|
[
"cloneAttrs",
"returns",
"a",
"shallow",
"clone",
"of",
"m",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/attr.go#L185-L191
|
train
|
pilosa/pilosa
|
attr.go
|
EncodeAttrs
|
func EncodeAttrs(attr map[string]interface{}) ([]byte, error) {
return proto.Marshal(&internal.AttrMap{Attrs: encodeAttrs(attr)})
}
|
go
|
func EncodeAttrs(attr map[string]interface{}) ([]byte, error) {
return proto.Marshal(&internal.AttrMap{Attrs: encodeAttrs(attr)})
}
|
[
"func",
"EncodeAttrs",
"(",
"attr",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"proto",
".",
"Marshal",
"(",
"&",
"internal",
".",
"AttrMap",
"{",
"Attrs",
":",
"encodeAttrs",
"(",
"attr",
")",
"}",
")",
"\n",
"}"
] |
// EncodeAttrs encodes an attribute map into a byte slice.
|
[
"EncodeAttrs",
"encodes",
"an",
"attribute",
"map",
"into",
"a",
"byte",
"slice",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/attr.go#L194-L196
|
train
|
pilosa/pilosa
|
attr.go
|
DecodeAttrs
|
func DecodeAttrs(v []byte) (map[string]interface{}, error) {
var pb internal.AttrMap
if err := proto.Unmarshal(v, &pb); err != nil {
return nil, err
}
return decodeAttrs(pb.GetAttrs()), nil
}
|
go
|
func DecodeAttrs(v []byte) (map[string]interface{}, error) {
var pb internal.AttrMap
if err := proto.Unmarshal(v, &pb); err != nil {
return nil, err
}
return decodeAttrs(pb.GetAttrs()), nil
}
|
[
"func",
"DecodeAttrs",
"(",
"v",
"[",
"]",
"byte",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"var",
"pb",
"internal",
".",
"AttrMap",
"\n",
"if",
"err",
":=",
"proto",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"pb",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"decodeAttrs",
"(",
"pb",
".",
"GetAttrs",
"(",
")",
")",
",",
"nil",
"\n",
"}"
] |
// DecodeAttrs decodes a byte slice into an attribute map.
|
[
"DecodeAttrs",
"decodes",
"a",
"byte",
"slice",
"into",
"an",
"attribute",
"map",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/attr.go#L199-L205
|
train
|
pilosa/pilosa
|
uri.go
|
NewURIFromHostPort
|
func NewURIFromHostPort(host string, port uint16) (*URI, error) {
uri := defaultURI()
err := uri.setHost(host)
if err != nil {
return nil, errors.Wrap(err, "setting uri host")
}
uri.SetPort(port)
return uri, nil
}
|
go
|
func NewURIFromHostPort(host string, port uint16) (*URI, error) {
uri := defaultURI()
err := uri.setHost(host)
if err != nil {
return nil, errors.Wrap(err, "setting uri host")
}
uri.SetPort(port)
return uri, nil
}
|
[
"func",
"NewURIFromHostPort",
"(",
"host",
"string",
",",
"port",
"uint16",
")",
"(",
"*",
"URI",
",",
"error",
")",
"{",
"uri",
":=",
"defaultURI",
"(",
")",
"\n",
"err",
":=",
"uri",
".",
"setHost",
"(",
"host",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"uri",
".",
"SetPort",
"(",
"port",
")",
"\n",
"return",
"uri",
",",
"nil",
"\n",
"}"
] |
// NewURIFromHostPort returns a URI with specified host and port.
|
[
"NewURIFromHostPort",
"returns",
"a",
"URI",
"with",
"specified",
"host",
"and",
"port",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/uri.go#L73-L81
|
train
|
pilosa/pilosa
|
uri.go
|
setScheme
|
func (u *URI) setScheme(scheme string) error {
m := schemeRegexp.FindStringSubmatch(scheme)
if m == nil {
return errors.New("invalid scheme")
}
u.Scheme = scheme
return nil
}
|
go
|
func (u *URI) setScheme(scheme string) error {
m := schemeRegexp.FindStringSubmatch(scheme)
if m == nil {
return errors.New("invalid scheme")
}
u.Scheme = scheme
return nil
}
|
[
"func",
"(",
"u",
"*",
"URI",
")",
"setScheme",
"(",
"scheme",
"string",
")",
"error",
"{",
"m",
":=",
"schemeRegexp",
".",
"FindStringSubmatch",
"(",
"scheme",
")",
"\n",
"if",
"m",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"u",
".",
"Scheme",
"=",
"scheme",
"\n",
"return",
"nil",
"\n",
"}"
] |
// setScheme sets the scheme of this URI.
|
[
"setScheme",
"sets",
"the",
"scheme",
"of",
"this",
"URI",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/uri.go#L89-L96
|
train
|
pilosa/pilosa
|
uri.go
|
setHost
|
func (u *URI) setHost(host string) error {
m := hostRegexp.FindStringSubmatch(host)
if m == nil {
return errors.New("invalid host")
}
u.Host = host
return nil
}
|
go
|
func (u *URI) setHost(host string) error {
m := hostRegexp.FindStringSubmatch(host)
if m == nil {
return errors.New("invalid host")
}
u.Host = host
return nil
}
|
[
"func",
"(",
"u",
"*",
"URI",
")",
"setHost",
"(",
"host",
"string",
")",
"error",
"{",
"m",
":=",
"hostRegexp",
".",
"FindStringSubmatch",
"(",
"host",
")",
"\n",
"if",
"m",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"u",
".",
"Host",
"=",
"host",
"\n",
"return",
"nil",
"\n",
"}"
] |
// setHost sets the host of this URI.
|
[
"setHost",
"sets",
"the",
"host",
"of",
"this",
"URI",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/uri.go#L99-L106
|
train
|
pilosa/pilosa
|
uri.go
|
normalize
|
func (u *URI) normalize() string {
scheme := u.Scheme
index := strings.Index(scheme, "+")
if index >= 0 {
scheme = scheme[:index]
}
return fmt.Sprintf("%s://%s:%d", scheme, u.Host, u.Port)
}
|
go
|
func (u *URI) normalize() string {
scheme := u.Scheme
index := strings.Index(scheme, "+")
if index >= 0 {
scheme = scheme[:index]
}
return fmt.Sprintf("%s://%s:%d", scheme, u.Host, u.Port)
}
|
[
"func",
"(",
"u",
"*",
"URI",
")",
"normalize",
"(",
")",
"string",
"{",
"scheme",
":=",
"u",
".",
"Scheme",
"\n",
"index",
":=",
"strings",
".",
"Index",
"(",
"scheme",
",",
"\"",
"\"",
")",
"\n",
"if",
"index",
">=",
"0",
"{",
"scheme",
"=",
"scheme",
"[",
":",
"index",
"]",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"scheme",
",",
"u",
".",
"Host",
",",
"u",
".",
"Port",
")",
"\n",
"}"
] |
// normalize returns the address in a form usable by a HTTP client.
|
[
"normalize",
"returns",
"the",
"address",
"in",
"a",
"form",
"usable",
"by",
"a",
"HTTP",
"client",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/uri.go#L124-L131
|
train
|
pilosa/pilosa
|
uri.go
|
String
|
func (u URI) String() string {
return fmt.Sprintf("%s://%s:%d", u.Scheme, u.Host, u.Port)
}
|
go
|
func (u URI) String() string {
return fmt.Sprintf("%s://%s:%d", u.Scheme, u.Host, u.Port)
}
|
[
"func",
"(",
"u",
"URI",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"u",
".",
"Scheme",
",",
"u",
".",
"Host",
",",
"u",
".",
"Port",
")",
"\n",
"}"
] |
// String returns the address as a string.
|
[
"String",
"returns",
"the",
"address",
"as",
"a",
"string",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/uri.go#L134-L136
|
train
|
pilosa/pilosa
|
uri.go
|
Path
|
func (u *URI) Path(path string) string {
return fmt.Sprintf("%s%s", u.normalize(), path)
}
|
go
|
func (u *URI) Path(path string) string {
return fmt.Sprintf("%s%s", u.normalize(), path)
}
|
[
"func",
"(",
"u",
"*",
"URI",
")",
"Path",
"(",
"path",
"string",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"u",
".",
"normalize",
"(",
")",
",",
"path",
")",
"\n",
"}"
] |
// Path returns URI with path
|
[
"Path",
"returns",
"URI",
"with",
"path"
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/uri.go#L139-L141
|
train
|
pilosa/pilosa
|
uri.go
|
Set
|
func (u *URI) Set(value string) error {
uri, err := NewURIFromAddress(value)
if err != nil {
return err
}
*u = *uri
return nil
}
|
go
|
func (u *URI) Set(value string) error {
uri, err := NewURIFromAddress(value)
if err != nil {
return err
}
*u = *uri
return nil
}
|
[
"func",
"(",
"u",
"*",
"URI",
")",
"Set",
"(",
"value",
"string",
")",
"error",
"{",
"uri",
",",
"err",
":=",
"NewURIFromAddress",
"(",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"*",
"u",
"=",
"*",
"uri",
"\n",
"return",
"nil",
"\n",
"}"
] |
// The following methods are required to implement pflag Value interface.
// Set sets the uri value.
|
[
"The",
"following",
"methods",
"are",
"required",
"to",
"implement",
"pflag",
"Value",
"interface",
".",
"Set",
"sets",
"the",
"uri",
"value",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/uri.go#L146-L153
|
train
|
pilosa/pilosa
|
uri.go
|
MarshalJSON
|
func (u *URI) MarshalJSON() ([]byte, error) {
var output struct {
Scheme string `json:"scheme,omitempty"`
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
}
output.Scheme = u.Scheme
output.Host = u.Host
output.Port = u.Port
return json.Marshal(output)
}
|
go
|
func (u *URI) MarshalJSON() ([]byte, error) {
var output struct {
Scheme string `json:"scheme,omitempty"`
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
}
output.Scheme = u.Scheme
output.Host = u.Host
output.Port = u.Port
return json.Marshal(output)
}
|
[
"func",
"(",
"u",
"*",
"URI",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"output",
"struct",
"{",
"Scheme",
"string",
"`json:\"scheme,omitempty\"`",
"\n",
"Host",
"string",
"`json:\"host,omitempty\"`",
"\n",
"Port",
"uint16",
"`json:\"port,omitempty\"`",
"\n",
"}",
"\n",
"output",
".",
"Scheme",
"=",
"u",
".",
"Scheme",
"\n",
"output",
".",
"Host",
"=",
"u",
".",
"Host",
"\n",
"output",
".",
"Port",
"=",
"u",
".",
"Port",
"\n\n",
"return",
"json",
".",
"Marshal",
"(",
"output",
")",
"\n",
"}"
] |
// MarshalJSON marshals URI into a JSON-encoded byte slice.
|
[
"MarshalJSON",
"marshals",
"URI",
"into",
"a",
"JSON",
"-",
"encoded",
"byte",
"slice",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/uri.go#L192-L203
|
train
|
pilosa/pilosa
|
uri.go
|
UnmarshalJSON
|
func (u *URI) UnmarshalJSON(b []byte) error {
var input struct {
Scheme string `json:"scheme,omitempty"`
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
}
if err := json.Unmarshal(b, &input); err != nil {
return err
}
u.Scheme = input.Scheme
u.Host = input.Host
u.Port = input.Port
return nil
}
|
go
|
func (u *URI) UnmarshalJSON(b []byte) error {
var input struct {
Scheme string `json:"scheme,omitempty"`
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
}
if err := json.Unmarshal(b, &input); err != nil {
return err
}
u.Scheme = input.Scheme
u.Host = input.Host
u.Port = input.Port
return nil
}
|
[
"func",
"(",
"u",
"*",
"URI",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"input",
"struct",
"{",
"Scheme",
"string",
"`json:\"scheme,omitempty\"`",
"\n",
"Host",
"string",
"`json:\"host,omitempty\"`",
"\n",
"Port",
"uint16",
"`json:\"port,omitempty\"`",
"\n",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"input",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"u",
".",
"Scheme",
"=",
"input",
".",
"Scheme",
"\n",
"u",
".",
"Host",
"=",
"input",
".",
"Host",
"\n",
"u",
".",
"Port",
"=",
"input",
".",
"Port",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON unmarshals a byte slice to a URI.
|
[
"UnmarshalJSON",
"unmarshals",
"a",
"byte",
"slice",
"to",
"a",
"URI",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/uri.go#L206-L219
|
train
|
pilosa/pilosa
|
ctl/check.go
|
NewCheckCommand
|
func NewCheckCommand(stdin io.Reader, stdout, stderr io.Writer) *CheckCommand {
return &CheckCommand{
CmdIO: pilosa.NewCmdIO(stdin, stdout, stderr),
}
}
|
go
|
func NewCheckCommand(stdin io.Reader, stdout, stderr io.Writer) *CheckCommand {
return &CheckCommand{
CmdIO: pilosa.NewCmdIO(stdin, stdout, stderr),
}
}
|
[
"func",
"NewCheckCommand",
"(",
"stdin",
"io",
".",
"Reader",
",",
"stdout",
",",
"stderr",
"io",
".",
"Writer",
")",
"*",
"CheckCommand",
"{",
"return",
"&",
"CheckCommand",
"{",
"CmdIO",
":",
"pilosa",
".",
"NewCmdIO",
"(",
"stdin",
",",
"stdout",
",",
"stderr",
")",
",",
"}",
"\n",
"}"
] |
// NewCheckCommand returns a new instance of CheckCommand.
|
[
"NewCheckCommand",
"returns",
"a",
"new",
"instance",
"of",
"CheckCommand",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/ctl/check.go#L40-L44
|
train
|
pilosa/pilosa
|
ctl/check.go
|
Run
|
func (cmd *CheckCommand) Run(_ context.Context) error {
for _, path := range cmd.Paths {
switch filepath.Ext(path) {
case "":
if err := cmd.checkBitmapFile(path); err != nil {
return errors.Wrap(err, "checking bitmap")
}
case ".cache":
if err := cmd.checkCacheFile(path); err != nil {
return errors.Wrap(err, "checking cache")
}
case ".snapshotting":
if err := cmd.checkSnapshotFile(path); err != nil {
return errors.Wrap(err, "checking snapshot")
}
}
}
return nil
}
|
go
|
func (cmd *CheckCommand) Run(_ context.Context) error {
for _, path := range cmd.Paths {
switch filepath.Ext(path) {
case "":
if err := cmd.checkBitmapFile(path); err != nil {
return errors.Wrap(err, "checking bitmap")
}
case ".cache":
if err := cmd.checkCacheFile(path); err != nil {
return errors.Wrap(err, "checking cache")
}
case ".snapshotting":
if err := cmd.checkSnapshotFile(path); err != nil {
return errors.Wrap(err, "checking snapshot")
}
}
}
return nil
}
|
[
"func",
"(",
"cmd",
"*",
"CheckCommand",
")",
"Run",
"(",
"_",
"context",
".",
"Context",
")",
"error",
"{",
"for",
"_",
",",
"path",
":=",
"range",
"cmd",
".",
"Paths",
"{",
"switch",
"filepath",
".",
"Ext",
"(",
"path",
")",
"{",
"case",
"\"",
"\"",
":",
"if",
"err",
":=",
"cmd",
".",
"checkBitmapFile",
"(",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"case",
"\"",
"\"",
":",
"if",
"err",
":=",
"cmd",
".",
"checkCacheFile",
"(",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"case",
"\"",
"\"",
":",
"if",
"err",
":=",
"cmd",
".",
"checkSnapshotFile",
"(",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Run executes the check command.
|
[
"Run",
"executes",
"the",
"check",
"command",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/ctl/check.go#L47-L68
|
train
|
pilosa/pilosa
|
ctl/check.go
|
checkBitmapFile
|
func (cmd *CheckCommand) checkBitmapFile(path string) (err error) {
// Open file handle.
f, err := os.Open(path)
if err != nil {
return errors.Wrap(err, "opening file")
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
return errors.Wrap(err, "statting file")
}
// Memory map the file.
data, err := syscall.Mmap(int(f.Fd()), 0, int(fi.Size()), syscall.PROT_READ, syscall.MAP_SHARED)
if err != nil {
return errors.Wrap(err, "mmapping")
}
defer func() {
e := syscall.Munmap(data)
if e != nil {
fmt.Fprintf(cmd.Stderr, "WARNING: munmap failed: %v", e)
}
// don't overwrite another error with this, but also indicate
// this error.
if err == nil {
err = e
}
}()
// Attach the mmap file to the bitmap.
bm := roaring.NewBitmap()
if err := bm.UnmarshalBinary(data); err != nil {
return errors.Wrap(err, "unmarshalling")
}
// Perform consistency check.
if err := bm.Check(); err != nil {
// Print returned errors.
switch err := err.(type) {
case roaring.ErrorList:
for i := range err {
fmt.Fprintf(cmd.Stdout, "%s: %s\n", path, err[i].Error())
}
default:
fmt.Fprintf(cmd.Stdout, "%s: %s\n", path, err.Error())
}
}
// Print success message if no errors were found.
fmt.Fprintf(cmd.Stdout, "%s: ok\n", path)
return nil
}
|
go
|
func (cmd *CheckCommand) checkBitmapFile(path string) (err error) {
// Open file handle.
f, err := os.Open(path)
if err != nil {
return errors.Wrap(err, "opening file")
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
return errors.Wrap(err, "statting file")
}
// Memory map the file.
data, err := syscall.Mmap(int(f.Fd()), 0, int(fi.Size()), syscall.PROT_READ, syscall.MAP_SHARED)
if err != nil {
return errors.Wrap(err, "mmapping")
}
defer func() {
e := syscall.Munmap(data)
if e != nil {
fmt.Fprintf(cmd.Stderr, "WARNING: munmap failed: %v", e)
}
// don't overwrite another error with this, but also indicate
// this error.
if err == nil {
err = e
}
}()
// Attach the mmap file to the bitmap.
bm := roaring.NewBitmap()
if err := bm.UnmarshalBinary(data); err != nil {
return errors.Wrap(err, "unmarshalling")
}
// Perform consistency check.
if err := bm.Check(); err != nil {
// Print returned errors.
switch err := err.(type) {
case roaring.ErrorList:
for i := range err {
fmt.Fprintf(cmd.Stdout, "%s: %s\n", path, err[i].Error())
}
default:
fmt.Fprintf(cmd.Stdout, "%s: %s\n", path, err.Error())
}
}
// Print success message if no errors were found.
fmt.Fprintf(cmd.Stdout, "%s: ok\n", path)
return nil
}
|
[
"func",
"(",
"cmd",
"*",
"CheckCommand",
")",
"checkBitmapFile",
"(",
"path",
"string",
")",
"(",
"err",
"error",
")",
"{",
"// Open file handle.",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"fi",
",",
"err",
":=",
"f",
".",
"Stat",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Memory map the file.",
"data",
",",
"err",
":=",
"syscall",
".",
"Mmap",
"(",
"int",
"(",
"f",
".",
"Fd",
"(",
")",
")",
",",
"0",
",",
"int",
"(",
"fi",
".",
"Size",
"(",
")",
")",
",",
"syscall",
".",
"PROT_READ",
",",
"syscall",
".",
"MAP_SHARED",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"e",
":=",
"syscall",
".",
"Munmap",
"(",
"data",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintf",
"(",
"cmd",
".",
"Stderr",
",",
"\"",
"\"",
",",
"e",
")",
"\n",
"}",
"\n",
"// don't overwrite another error with this, but also indicate",
"// this error.",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"e",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"// Attach the mmap file to the bitmap.",
"bm",
":=",
"roaring",
".",
"NewBitmap",
"(",
")",
"\n",
"if",
"err",
":=",
"bm",
".",
"UnmarshalBinary",
"(",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Perform consistency check.",
"if",
"err",
":=",
"bm",
".",
"Check",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"// Print returned errors.",
"switch",
"err",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"roaring",
".",
"ErrorList",
":",
"for",
"i",
":=",
"range",
"err",
"{",
"fmt",
".",
"Fprintf",
"(",
"cmd",
".",
"Stdout",
",",
"\"",
"\\n",
"\"",
",",
"path",
",",
"err",
"[",
"i",
"]",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"default",
":",
"fmt",
".",
"Fprintf",
"(",
"cmd",
".",
"Stdout",
",",
"\"",
"\\n",
"\"",
",",
"path",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Print success message if no errors were found.",
"fmt",
".",
"Fprintf",
"(",
"cmd",
".",
"Stdout",
",",
"\"",
"\\n",
"\"",
",",
"path",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// checkBitmapFile performs a consistency check on path for a roaring bitmap file.
|
[
"checkBitmapFile",
"performs",
"a",
"consistency",
"check",
"on",
"path",
"for",
"a",
"roaring",
"bitmap",
"file",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/ctl/check.go#L71-L123
|
train
|
pilosa/pilosa
|
ctl/check.go
|
checkCacheFile
|
func (cmd *CheckCommand) checkCacheFile(path string) error {
fmt.Fprintf(cmd.Stderr, "%s: ignoring cache file\n", path)
return nil
}
|
go
|
func (cmd *CheckCommand) checkCacheFile(path string) error {
fmt.Fprintf(cmd.Stderr, "%s: ignoring cache file\n", path)
return nil
}
|
[
"func",
"(",
"cmd",
"*",
"CheckCommand",
")",
"checkCacheFile",
"(",
"path",
"string",
")",
"error",
"{",
"fmt",
".",
"Fprintf",
"(",
"cmd",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"path",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// checkCacheFile performs a consistency check on path for a cache file.
|
[
"checkCacheFile",
"performs",
"a",
"consistency",
"check",
"on",
"path",
"for",
"a",
"cache",
"file",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/ctl/check.go#L126-L129
|
train
|
pilosa/pilosa
|
inmem/translator.go
|
NewTranslateStore
|
func NewTranslateStore() *translateStore {
return &translateStore{
cols: make(map[string]*translateIndex),
rows: make(map[frameKey]*translateIndex),
}
}
|
go
|
func NewTranslateStore() *translateStore {
return &translateStore{
cols: make(map[string]*translateIndex),
rows: make(map[frameKey]*translateIndex),
}
}
|
[
"func",
"NewTranslateStore",
"(",
")",
"*",
"translateStore",
"{",
"return",
"&",
"translateStore",
"{",
"cols",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"translateIndex",
")",
",",
"rows",
":",
"make",
"(",
"map",
"[",
"frameKey",
"]",
"*",
"translateIndex",
")",
",",
"}",
"\n",
"}"
] |
// NewTranslateStore returns a new instance of TranslateStore.
|
[
"NewTranslateStore",
"returns",
"a",
"new",
"instance",
"of",
"TranslateStore",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/inmem/translator.go#L37-L42
|
train
|
pilosa/pilosa
|
inmem/translator.go
|
Reader
|
func (s *translateStore) Reader(ctx context.Context, offset int64) (io.ReadCloser, error) {
return nil, pilosa.ErrReplicationNotSupported
}
|
go
|
func (s *translateStore) Reader(ctx context.Context, offset int64) (io.ReadCloser, error) {
return nil, pilosa.ErrReplicationNotSupported
}
|
[
"func",
"(",
"s",
"*",
"translateStore",
")",
"Reader",
"(",
"ctx",
"context",
".",
"Context",
",",
"offset",
"int64",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"return",
"nil",
",",
"pilosa",
".",
"ErrReplicationNotSupported",
"\n",
"}"
] |
// Reader returns an error because it is not supported by the inmem store.
|
[
"Reader",
"returns",
"an",
"error",
"because",
"it",
"is",
"not",
"supported",
"by",
"the",
"inmem",
"store",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/inmem/translator.go#L45-L47
|
train
|
pilosa/pilosa
|
inmem/translator.go
|
TranslateColumnsToUint64
|
func (s *translateStore) TranslateColumnsToUint64(index string, values []string) ([]uint64, error) {
ret := make([]uint64, len(values))
// Read value under read lock.
s.mu.RLock()
if idx := s.cols[index]; idx != nil {
var writeRequired bool
for i := range values {
v, ok := idx.lookup[values[i]]
if !ok {
writeRequired = true
}
ret[i] = v
}
if !writeRequired {
s.mu.RUnlock()
return ret, nil
}
}
s.mu.RUnlock()
// If any values not found then recheck and then add under a write lock.
s.mu.Lock()
defer s.mu.Unlock()
// Recheck if value was created between the read lock and write lock.
idx := s.cols[index]
if idx != nil {
var writeRequired bool
for i := range values {
if ret[i] != 0 {
continue
}
v, ok := idx.lookup[values[i]]
if !ok {
writeRequired = true
continue
}
ret[i] = v
}
if !writeRequired {
return ret, nil
}
}
// Create index map if it doesn't exists.
if idx == nil {
idx = newTranslateIndex()
s.cols[index] = idx
}
// Add new identifiers.
for i := range values {
if ret[i] != 0 {
continue
}
idx.seq++
v := idx.seq
ret[i] = v
idx.lookup[values[i]] = v
idx.reverse[v] = values[i]
}
return ret, nil
}
|
go
|
func (s *translateStore) TranslateColumnsToUint64(index string, values []string) ([]uint64, error) {
ret := make([]uint64, len(values))
// Read value under read lock.
s.mu.RLock()
if idx := s.cols[index]; idx != nil {
var writeRequired bool
for i := range values {
v, ok := idx.lookup[values[i]]
if !ok {
writeRequired = true
}
ret[i] = v
}
if !writeRequired {
s.mu.RUnlock()
return ret, nil
}
}
s.mu.RUnlock()
// If any values not found then recheck and then add under a write lock.
s.mu.Lock()
defer s.mu.Unlock()
// Recheck if value was created between the read lock and write lock.
idx := s.cols[index]
if idx != nil {
var writeRequired bool
for i := range values {
if ret[i] != 0 {
continue
}
v, ok := idx.lookup[values[i]]
if !ok {
writeRequired = true
continue
}
ret[i] = v
}
if !writeRequired {
return ret, nil
}
}
// Create index map if it doesn't exists.
if idx == nil {
idx = newTranslateIndex()
s.cols[index] = idx
}
// Add new identifiers.
for i := range values {
if ret[i] != 0 {
continue
}
idx.seq++
v := idx.seq
ret[i] = v
idx.lookup[values[i]] = v
idx.reverse[v] = values[i]
}
return ret, nil
}
|
[
"func",
"(",
"s",
"*",
"translateStore",
")",
"TranslateColumnsToUint64",
"(",
"index",
"string",
",",
"values",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"uint64",
",",
"error",
")",
"{",
"ret",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"len",
"(",
"values",
")",
")",
"\n\n",
"// Read value under read lock.",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"if",
"idx",
":=",
"s",
".",
"cols",
"[",
"index",
"]",
";",
"idx",
"!=",
"nil",
"{",
"var",
"writeRequired",
"bool",
"\n",
"for",
"i",
":=",
"range",
"values",
"{",
"v",
",",
"ok",
":=",
"idx",
".",
"lookup",
"[",
"values",
"[",
"i",
"]",
"]",
"\n",
"if",
"!",
"ok",
"{",
"writeRequired",
"=",
"true",
"\n",
"}",
"\n",
"ret",
"[",
"i",
"]",
"=",
"v",
"\n",
"}",
"\n",
"if",
"!",
"writeRequired",
"{",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"ret",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"// If any values not found then recheck and then add under a write lock.",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Recheck if value was created between the read lock and write lock.",
"idx",
":=",
"s",
".",
"cols",
"[",
"index",
"]",
"\n",
"if",
"idx",
"!=",
"nil",
"{",
"var",
"writeRequired",
"bool",
"\n",
"for",
"i",
":=",
"range",
"values",
"{",
"if",
"ret",
"[",
"i",
"]",
"!=",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"v",
",",
"ok",
":=",
"idx",
".",
"lookup",
"[",
"values",
"[",
"i",
"]",
"]",
"\n",
"if",
"!",
"ok",
"{",
"writeRequired",
"=",
"true",
"\n",
"continue",
"\n",
"}",
"\n",
"ret",
"[",
"i",
"]",
"=",
"v",
"\n",
"}",
"\n",
"if",
"!",
"writeRequired",
"{",
"return",
"ret",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Create index map if it doesn't exists.",
"if",
"idx",
"==",
"nil",
"{",
"idx",
"=",
"newTranslateIndex",
"(",
")",
"\n",
"s",
".",
"cols",
"[",
"index",
"]",
"=",
"idx",
"\n",
"}",
"\n\n",
"// Add new identifiers.",
"for",
"i",
":=",
"range",
"values",
"{",
"if",
"ret",
"[",
"i",
"]",
"!=",
"0",
"{",
"continue",
"\n",
"}",
"\n\n",
"idx",
".",
"seq",
"++",
"\n",
"v",
":=",
"idx",
".",
"seq",
"\n",
"ret",
"[",
"i",
"]",
"=",
"v",
"\n",
"idx",
".",
"lookup",
"[",
"values",
"[",
"i",
"]",
"]",
"=",
"v",
"\n",
"idx",
".",
"reverse",
"[",
"v",
"]",
"=",
"values",
"[",
"i",
"]",
"\n",
"}",
"\n\n",
"return",
"ret",
",",
"nil",
"\n",
"}"
] |
// TranslateColumnsToUint64 converts value to a uint64 id.
// If value does not have an associated id then one is created.
|
[
"TranslateColumnsToUint64",
"converts",
"value",
"to",
"a",
"uint64",
"id",
".",
"If",
"value",
"does",
"not",
"have",
"an",
"associated",
"id",
"then",
"one",
"is",
"created",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/inmem/translator.go#L51-L116
|
train
|
pilosa/pilosa
|
ctl/export.go
|
NewExportCommand
|
func NewExportCommand(stdin io.Reader, stdout, stderr io.Writer) *ExportCommand {
return &ExportCommand{
CmdIO: pilosa.NewCmdIO(stdin, stdout, stderr),
}
}
|
go
|
func NewExportCommand(stdin io.Reader, stdout, stderr io.Writer) *ExportCommand {
return &ExportCommand{
CmdIO: pilosa.NewCmdIO(stdin, stdout, stderr),
}
}
|
[
"func",
"NewExportCommand",
"(",
"stdin",
"io",
".",
"Reader",
",",
"stdout",
",",
"stderr",
"io",
".",
"Writer",
")",
"*",
"ExportCommand",
"{",
"return",
"&",
"ExportCommand",
"{",
"CmdIO",
":",
"pilosa",
".",
"NewCmdIO",
"(",
"stdin",
",",
"stdout",
",",
"stderr",
")",
",",
"}",
"\n",
"}"
] |
// NewExportCommand returns a new instance of ExportCommand.
|
[
"NewExportCommand",
"returns",
"a",
"new",
"instance",
"of",
"ExportCommand",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/ctl/export.go#L47-L51
|
train
|
pilosa/pilosa
|
ctl/export.go
|
Run
|
func (cmd *ExportCommand) Run(ctx context.Context) error {
logger := log.New(cmd.Stderr, "", log.LstdFlags)
// Validate arguments.
if cmd.Index == "" {
return pilosa.ErrIndexRequired
} else if cmd.Field == "" {
return pilosa.ErrFieldRequired
}
// Use output file, if specified.
// Otherwise use STDOUT.
var w io.Writer = cmd.Stdout
if cmd.Path != "" {
f, err := os.Create(cmd.Path)
if err != nil {
return errors.Wrap(err, "creating file")
}
defer f.Close()
w = f
}
// Create a client to the server.
client, err := commandClient(cmd)
if err != nil {
return errors.Wrap(err, "creating client")
}
// Determine shard count.
maxShards, err := client.MaxShardByIndex(ctx)
if err != nil {
return errors.Wrap(err, "getting shard count")
}
// Export each shard.
for shard := uint64(0); shard <= maxShards[cmd.Index]; shard++ {
logger.Printf("exporting shard: %d", shard)
if err := client.ExportCSV(ctx, cmd.Index, cmd.Field, shard, w); err != nil {
return errors.Wrap(err, "exporting")
}
}
// Close writer, if applicable.
if w, ok := w.(io.Closer); ok {
if err := w.Close(); err != nil {
return errors.Wrap(err, "closing")
}
}
return nil
}
|
go
|
func (cmd *ExportCommand) Run(ctx context.Context) error {
logger := log.New(cmd.Stderr, "", log.LstdFlags)
// Validate arguments.
if cmd.Index == "" {
return pilosa.ErrIndexRequired
} else if cmd.Field == "" {
return pilosa.ErrFieldRequired
}
// Use output file, if specified.
// Otherwise use STDOUT.
var w io.Writer = cmd.Stdout
if cmd.Path != "" {
f, err := os.Create(cmd.Path)
if err != nil {
return errors.Wrap(err, "creating file")
}
defer f.Close()
w = f
}
// Create a client to the server.
client, err := commandClient(cmd)
if err != nil {
return errors.Wrap(err, "creating client")
}
// Determine shard count.
maxShards, err := client.MaxShardByIndex(ctx)
if err != nil {
return errors.Wrap(err, "getting shard count")
}
// Export each shard.
for shard := uint64(0); shard <= maxShards[cmd.Index]; shard++ {
logger.Printf("exporting shard: %d", shard)
if err := client.ExportCSV(ctx, cmd.Index, cmd.Field, shard, w); err != nil {
return errors.Wrap(err, "exporting")
}
}
// Close writer, if applicable.
if w, ok := w.(io.Closer); ok {
if err := w.Close(); err != nil {
return errors.Wrap(err, "closing")
}
}
return nil
}
|
[
"func",
"(",
"cmd",
"*",
"ExportCommand",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"logger",
":=",
"log",
".",
"New",
"(",
"cmd",
".",
"Stderr",
",",
"\"",
"\"",
",",
"log",
".",
"LstdFlags",
")",
"\n\n",
"// Validate arguments.",
"if",
"cmd",
".",
"Index",
"==",
"\"",
"\"",
"{",
"return",
"pilosa",
".",
"ErrIndexRequired",
"\n",
"}",
"else",
"if",
"cmd",
".",
"Field",
"==",
"\"",
"\"",
"{",
"return",
"pilosa",
".",
"ErrFieldRequired",
"\n",
"}",
"\n\n",
"// Use output file, if specified.",
"// Otherwise use STDOUT.",
"var",
"w",
"io",
".",
"Writer",
"=",
"cmd",
".",
"Stdout",
"\n",
"if",
"cmd",
".",
"Path",
"!=",
"\"",
"\"",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"cmd",
".",
"Path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"w",
"=",
"f",
"\n",
"}",
"\n\n",
"// Create a client to the server.",
"client",
",",
"err",
":=",
"commandClient",
"(",
"cmd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Determine shard count.",
"maxShards",
",",
"err",
":=",
"client",
".",
"MaxShardByIndex",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Export each shard.",
"for",
"shard",
":=",
"uint64",
"(",
"0",
")",
";",
"shard",
"<=",
"maxShards",
"[",
"cmd",
".",
"Index",
"]",
";",
"shard",
"++",
"{",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"shard",
")",
"\n",
"if",
"err",
":=",
"client",
".",
"ExportCSV",
"(",
"ctx",
",",
"cmd",
".",
"Index",
",",
"cmd",
".",
"Field",
",",
"shard",
",",
"w",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Close writer, if applicable.",
"if",
"w",
",",
"ok",
":=",
"w",
".",
"(",
"io",
".",
"Closer",
")",
";",
"ok",
"{",
"if",
"err",
":=",
"w",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Run executes the export.
|
[
"Run",
"executes",
"the",
"export",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/ctl/export.go#L54-L105
|
train
|
pilosa/pilosa
|
stats/stats.go
|
Count
|
func (c *expvarStatsClient) Count(name string, value int64, rate float64) {
c.m.Add(name, value)
}
|
go
|
func (c *expvarStatsClient) Count(name string, value int64, rate float64) {
c.m.Add(name, value)
}
|
[
"func",
"(",
"c",
"*",
"expvarStatsClient",
")",
"Count",
"(",
"name",
"string",
",",
"value",
"int64",
",",
"rate",
"float64",
")",
"{",
"c",
".",
"m",
".",
"Add",
"(",
"name",
",",
"value",
")",
"\n",
"}"
] |
// Count tracks the number of times something occurs.
|
[
"Count",
"tracks",
"the",
"number",
"of",
"times",
"something",
"occurs",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/stats/stats.go#L116-L118
|
train
|
pilosa/pilosa
|
stats/stats.go
|
Gauge
|
func (c *expvarStatsClient) Gauge(name string, value float64, rate float64) {
var f expvar.Float
f.Set(value)
c.m.Set(name, &f)
}
|
go
|
func (c *expvarStatsClient) Gauge(name string, value float64, rate float64) {
var f expvar.Float
f.Set(value)
c.m.Set(name, &f)
}
|
[
"func",
"(",
"c",
"*",
"expvarStatsClient",
")",
"Gauge",
"(",
"name",
"string",
",",
"value",
"float64",
",",
"rate",
"float64",
")",
"{",
"var",
"f",
"expvar",
".",
"Float",
"\n",
"f",
".",
"Set",
"(",
"value",
")",
"\n",
"c",
".",
"m",
".",
"Set",
"(",
"name",
",",
"&",
"f",
")",
"\n",
"}"
] |
// Gauge sets the value of a metric.
|
[
"Gauge",
"sets",
"the",
"value",
"of",
"a",
"metric",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/stats/stats.go#L126-L130
|
train
|
pilosa/pilosa
|
stats/stats.go
|
Histogram
|
func (c *expvarStatsClient) Histogram(name string, value float64, rate float64) {
c.Gauge(name, value, rate)
}
|
go
|
func (c *expvarStatsClient) Histogram(name string, value float64, rate float64) {
c.Gauge(name, value, rate)
}
|
[
"func",
"(",
"c",
"*",
"expvarStatsClient",
")",
"Histogram",
"(",
"name",
"string",
",",
"value",
"float64",
",",
"rate",
"float64",
")",
"{",
"c",
".",
"Gauge",
"(",
"name",
",",
"value",
",",
"rate",
")",
"\n",
"}"
] |
// Histogram tracks statistical distribution of a metric.
// This works the same as gauge for this client.
|
[
"Histogram",
"tracks",
"statistical",
"distribution",
"of",
"a",
"metric",
".",
"This",
"works",
"the",
"same",
"as",
"gauge",
"for",
"this",
"client",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/stats/stats.go#L134-L136
|
train
|
pilosa/pilosa
|
stats/stats.go
|
Set
|
func (c *expvarStatsClient) Set(name string, value string, rate float64) {
var s expvar.String
s.Set(value)
c.m.Set(name, &s)
}
|
go
|
func (c *expvarStatsClient) Set(name string, value string, rate float64) {
var s expvar.String
s.Set(value)
c.m.Set(name, &s)
}
|
[
"func",
"(",
"c",
"*",
"expvarStatsClient",
")",
"Set",
"(",
"name",
"string",
",",
"value",
"string",
",",
"rate",
"float64",
")",
"{",
"var",
"s",
"expvar",
".",
"String",
"\n",
"s",
".",
"Set",
"(",
"value",
")",
"\n",
"c",
".",
"m",
".",
"Set",
"(",
"name",
",",
"&",
"s",
")",
"\n",
"}"
] |
// Set tracks number of unique elements.
|
[
"Set",
"tracks",
"number",
"of",
"unique",
"elements",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/stats/stats.go#L139-L143
|
train
|
pilosa/pilosa
|
stats/stats.go
|
WithTags
|
func (a MultiStatsClient) WithTags(tags ...string) StatsClient {
other := make(MultiStatsClient, len(a))
for i := range a {
other[i] = a[i].WithTags(tags...)
}
return other
}
|
go
|
func (a MultiStatsClient) WithTags(tags ...string) StatsClient {
other := make(MultiStatsClient, len(a))
for i := range a {
other[i] = a[i].WithTags(tags...)
}
return other
}
|
[
"func",
"(",
"a",
"MultiStatsClient",
")",
"WithTags",
"(",
"tags",
"...",
"string",
")",
"StatsClient",
"{",
"other",
":=",
"make",
"(",
"MultiStatsClient",
",",
"len",
"(",
"a",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"a",
"{",
"other",
"[",
"i",
"]",
"=",
"a",
"[",
"i",
"]",
".",
"WithTags",
"(",
"tags",
"...",
")",
"\n",
"}",
"\n",
"return",
"other",
"\n",
"}"
] |
// WithTags returns a new set of clients with the additional tags.
|
[
"WithTags",
"returns",
"a",
"new",
"set",
"of",
"clients",
"with",
"the",
"additional",
"tags",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/stats/stats.go#L175-L181
|
train
|
pilosa/pilosa
|
stats/stats.go
|
Count
|
func (a MultiStatsClient) Count(name string, value int64, rate float64) {
for _, c := range a {
c.Count(name, value, rate)
}
}
|
go
|
func (a MultiStatsClient) Count(name string, value int64, rate float64) {
for _, c := range a {
c.Count(name, value, rate)
}
}
|
[
"func",
"(",
"a",
"MultiStatsClient",
")",
"Count",
"(",
"name",
"string",
",",
"value",
"int64",
",",
"rate",
"float64",
")",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"a",
"{",
"c",
".",
"Count",
"(",
"name",
",",
"value",
",",
"rate",
")",
"\n",
"}",
"\n",
"}"
] |
// Count tracks the number of times something occurs per second on all clients.
|
[
"Count",
"tracks",
"the",
"number",
"of",
"times",
"something",
"occurs",
"per",
"second",
"on",
"all",
"clients",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/stats/stats.go#L184-L188
|
train
|
pilosa/pilosa
|
stats/stats.go
|
Set
|
func (a MultiStatsClient) Set(name string, value string, rate float64) {
for _, c := range a {
c.Set(name, value, rate)
}
}
|
go
|
func (a MultiStatsClient) Set(name string, value string, rate float64) {
for _, c := range a {
c.Set(name, value, rate)
}
}
|
[
"func",
"(",
"a",
"MultiStatsClient",
")",
"Set",
"(",
"name",
"string",
",",
"value",
"string",
",",
"rate",
"float64",
")",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"a",
"{",
"c",
".",
"Set",
"(",
"name",
",",
"value",
",",
"rate",
")",
"\n",
"}",
"\n",
"}"
] |
// Set tracks number of unique elements on all clients.
|
[
"Set",
"tracks",
"number",
"of",
"unique",
"elements",
"on",
"all",
"clients",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/stats/stats.go#L212-L216
|
train
|
pilosa/pilosa
|
stats/stats.go
|
Timing
|
func (a MultiStatsClient) Timing(name string, value time.Duration, rate float64) {
for _, c := range a {
c.Timing(name, value, rate)
}
}
|
go
|
func (a MultiStatsClient) Timing(name string, value time.Duration, rate float64) {
for _, c := range a {
c.Timing(name, value, rate)
}
}
|
[
"func",
"(",
"a",
"MultiStatsClient",
")",
"Timing",
"(",
"name",
"string",
",",
"value",
"time",
".",
"Duration",
",",
"rate",
"float64",
")",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"a",
"{",
"c",
".",
"Timing",
"(",
"name",
",",
"value",
",",
"rate",
")",
"\n",
"}",
"\n",
"}"
] |
// Timing tracks timing information for a metric on all clients.
|
[
"Timing",
"tracks",
"timing",
"information",
"for",
"a",
"metric",
"on",
"all",
"clients",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/stats/stats.go#L219-L223
|
train
|
pilosa/pilosa
|
stats/stats.go
|
SetLogger
|
func (a MultiStatsClient) SetLogger(logger logger.Logger) {
for _, c := range a {
c.SetLogger(logger)
}
}
|
go
|
func (a MultiStatsClient) SetLogger(logger logger.Logger) {
for _, c := range a {
c.SetLogger(logger)
}
}
|
[
"func",
"(",
"a",
"MultiStatsClient",
")",
"SetLogger",
"(",
"logger",
"logger",
".",
"Logger",
")",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"a",
"{",
"c",
".",
"SetLogger",
"(",
"logger",
")",
"\n",
"}",
"\n",
"}"
] |
// SetLogger Sets the StatsD logger output type.
|
[
"SetLogger",
"Sets",
"the",
"StatsD",
"logger",
"output",
"type",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/stats/stats.go#L226-L230
|
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.