repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
pilosa/pilosa
cluster.go
updateCoordinator
func (c *cluster) updateCoordinator(n *Node) bool { // nolint: unparam c.mu.Lock() defer c.mu.Unlock() return c.unprotectedUpdateCoordinator(n) }
go
func (c *cluster) updateCoordinator(n *Node) bool { // nolint: unparam c.mu.Lock() defer c.mu.Unlock() return c.unprotectedUpdateCoordinator(n) }
[ "func", "(", "c", "*", "cluster", ")", "updateCoordinator", "(", "n", "*", "Node", ")", "bool", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "c", ".", "unprotectedUpdateCoordina...
// updateCoordinator updates this nodes Coordinator value as well as // changing the corresponding node's IsCoordinator value // to true, and sets all other nodes to false. Returns true if the value // changed.
[ "updateCoordinator", "updates", "this", "nodes", "Coordinator", "value", "as", "well", "as", "changing", "the", "corresponding", "node", "s", "IsCoordinator", "value", "to", "true", "and", "sets", "all", "other", "nodes", "to", "false", ".", "Returns", "true", ...
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L344-L348
train
pilosa/pilosa
cluster.go
addNode
func (c *cluster) addNode(node *Node) error { // If the node being added is the coordinator, set it for this node. if node.IsCoordinator { c.Coordinator = node.ID } // add to cluster if !c.addNodeBasicSorted(node) { return nil } // add to topology if c.Topology == nil { return fmt.Errorf("Cluster.Topology is nil") } if !c.Topology.addID(node.ID) { return nil } c.Topology.nodeStates[node.ID] = node.State // save topology return c.saveTopology() }
go
func (c *cluster) addNode(node *Node) error { // If the node being added is the coordinator, set it for this node. if node.IsCoordinator { c.Coordinator = node.ID } // add to cluster if !c.addNodeBasicSorted(node) { return nil } // add to topology if c.Topology == nil { return fmt.Errorf("Cluster.Topology is nil") } if !c.Topology.addID(node.ID) { return nil } c.Topology.nodeStates[node.ID] = node.State // save topology return c.saveTopology() }
[ "func", "(", "c", "*", "cluster", ")", "addNode", "(", "node", "*", "Node", ")", "error", "{", "if", "node", ".", "IsCoordinator", "{", "c", ".", "Coordinator", "=", "node", ".", "ID", "\n", "}", "\n", "if", "!", "c", ".", "addNodeBasicSorted", "("...
// addNode adds a node to the Cluster and updates and saves the // new topology. unprotected.
[ "addNode", "adds", "a", "node", "to", "the", "Cluster", "and", "updates", "and", "saves", "the", "new", "topology", ".", "unprotected", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L368-L390
train
pilosa/pilosa
cluster.go
removeNode
func (c *cluster) removeNode(nodeID string) error { // remove from cluster c.removeNodeBasicSorted(nodeID) // remove from topology if c.Topology == nil { return fmt.Errorf("Cluster.Topology is nil") } if !c.Topology.removeID(nodeID) { return nil } // save topology return c.saveTopology() }
go
func (c *cluster) removeNode(nodeID string) error { // remove from cluster c.removeNodeBasicSorted(nodeID) // remove from topology if c.Topology == nil { return fmt.Errorf("Cluster.Topology is nil") } if !c.Topology.removeID(nodeID) { return nil } // save topology return c.saveTopology() }
[ "func", "(", "c", "*", "cluster", ")", "removeNode", "(", "nodeID", "string", ")", "error", "{", "c", ".", "removeNodeBasicSorted", "(", "nodeID", ")", "\n", "if", "c", ".", "Topology", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Cluster....
// removeNode removes a node from the Cluster and updates and saves the // new topology. unprotected.
[ "removeNode", "removes", "a", "node", "from", "the", "Cluster", "and", "updates", "and", "saves", "the", "new", "topology", ".", "unprotected", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L394-L408
train
pilosa/pilosa
cluster.go
receiveNodeState
func (c *cluster) receiveNodeState(nodeID string, state string) error { c.mu.Lock() defer c.mu.Unlock() if !c.unprotectedIsCoordinator() { return nil } c.Topology.mu.Lock() changed := false if c.Topology.nodeStates[nodeID] != state { changed = true c.Topology.nodeStates[nodeID] = state for i, n := range c.nodes { if n.ID == nodeID { c.nodes[i].State = state } } } c.Topology.mu.Unlock() c.logger.Printf("received state %s (%s)", state, nodeID) if changed { return c.unprotectedSetStateAndBroadcast(c.determineClusterState()) } return nil }
go
func (c *cluster) receiveNodeState(nodeID string, state string) error { c.mu.Lock() defer c.mu.Unlock() if !c.unprotectedIsCoordinator() { return nil } c.Topology.mu.Lock() changed := false if c.Topology.nodeStates[nodeID] != state { changed = true c.Topology.nodeStates[nodeID] = state for i, n := range c.nodes { if n.ID == nodeID { c.nodes[i].State = state } } } c.Topology.mu.Unlock() c.logger.Printf("received state %s (%s)", state, nodeID) if changed { return c.unprotectedSetStateAndBroadcast(c.determineClusterState()) } return nil }
[ "func", "(", "c", "*", "cluster", ")", "receiveNodeState", "(", "nodeID", "string", ",", "state", "string", ")", "error", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "Unlock", "(", ")", "\n", "if", "!", "c", ...
// receiveNodeState sets node state in Topology in order for the // Coordinator to keep track of, during startup, which nodes have // finished opening their Holder.
[ "receiveNodeState", "sets", "node", "state", "in", "Topology", "in", "order", "for", "the", "Coordinator", "to", "keep", "track", "of", "during", "startup", "which", "nodes", "have", "finished", "opening", "their", "Holder", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L513-L538
train
pilosa/pilosa
cluster.go
determineClusterState
func (c *cluster) determineClusterState() (clusterState string) { if c.state == ClusterStateResizing { return ClusterStateResizing } if c.haveTopologyAgreement() && c.allNodesReady() { return ClusterStateNormal } if len(c.Topology.nodeIDs)-len(c.nodeIDs()) < c.ReplicaN && c.allNodesReady() { return ClusterStateDegraded } return ClusterStateStarting }
go
func (c *cluster) determineClusterState() (clusterState string) { if c.state == ClusterStateResizing { return ClusterStateResizing } if c.haveTopologyAgreement() && c.allNodesReady() { return ClusterStateNormal } if len(c.Topology.nodeIDs)-len(c.nodeIDs()) < c.ReplicaN && c.allNodesReady() { return ClusterStateDegraded } return ClusterStateStarting }
[ "func", "(", "c", "*", "cluster", ")", "determineClusterState", "(", ")", "(", "clusterState", "string", ")", "{", "if", "c", ".", "state", "==", "ClusterStateResizing", "{", "return", "ClusterStateResizing", "\n", "}", "\n", "if", "c", ".", "haveTopologyAgr...
// determineClusterState is unprotected.
[ "determineClusterState", "is", "unprotected", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L541-L552
train
pilosa/pilosa
cluster.go
unprotectedStatus
func (c *cluster) unprotectedStatus() *ClusterStatus { return &ClusterStatus{ ClusterID: c.id, State: c.state, Nodes: c.nodes, } }
go
func (c *cluster) unprotectedStatus() *ClusterStatus { return &ClusterStatus{ ClusterID: c.id, State: c.state, Nodes: c.nodes, } }
[ "func", "(", "c", "*", "cluster", ")", "unprotectedStatus", "(", ")", "*", "ClusterStatus", "{", "return", "&", "ClusterStatus", "{", "ClusterID", ":", "c", ".", "id", ",", "State", ":", "c", ".", "state", ",", "Nodes", ":", "c", ".", "nodes", ",", ...
// unprotectedStatus returns the the cluster's status including what nodes it contains, its ID, and current state.
[ "unprotectedStatus", "returns", "the", "the", "cluster", "s", "status", "including", "what", "nodes", "it", "contains", "its", "ID", "and", "current", "state", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L555-L561
train
pilosa/pilosa
cluster.go
unprotectedNodeByID
func (c *cluster) unprotectedNodeByID(id string) *Node { for _, n := range c.nodes { if n.ID == id { return n } } return nil }
go
func (c *cluster) unprotectedNodeByID(id string) *Node { for _, n := range c.nodes { if n.ID == id { return n } } return nil }
[ "func", "(", "c", "*", "cluster", ")", "unprotectedNodeByID", "(", "id", "string", ")", "*", "Node", "{", "for", "_", ",", "n", ":=", "range", "c", ".", "nodes", "{", "if", "n", ".", "ID", "==", "id", "{", "return", "n", "\n", "}", "\n", "}", ...
// unprotectedNodeByID returns a node reference by ID.
[ "unprotectedNodeByID", "returns", "a", "node", "reference", "by", "ID", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L570-L577
train
pilosa/pilosa
cluster.go
nodePositionByID
func (c *cluster) nodePositionByID(nodeID string) int { for i, n := range c.nodes { if n.ID == nodeID { return i } } return -1 }
go
func (c *cluster) nodePositionByID(nodeID string) int { for i, n := range c.nodes { if n.ID == nodeID { return i } } return -1 }
[ "func", "(", "c", "*", "cluster", ")", "nodePositionByID", "(", "nodeID", "string", ")", "int", "{", "for", "i", ",", "n", ":=", "range", "c", ".", "nodes", "{", "if", "n", ".", "ID", "==", "nodeID", "{", "return", "i", "\n", "}", "\n", "}", "\...
// nodePositionByID returns the position of the node in slice c.Nodes.
[ "nodePositionByID", "returns", "the", "position", "of", "the", "node", "in", "slice", "c", ".", "Nodes", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L591-L598
train
pilosa/pilosa
cluster.go
addNodeBasicSorted
func (c *cluster) addNodeBasicSorted(node *Node) bool { n := c.unprotectedNodeByID(node.ID) if n != nil { if n.State != node.State || n.IsCoordinator != node.IsCoordinator || n.URI != node.URI { n.State = node.State n.IsCoordinator = node.IsCoordinator n.URI = node.URI return true } return false } c.nodes = append(c.nodes, node) // All hosts must be merged in the same order on all nodes in the cluster. sort.Sort(byID(c.nodes)) return true }
go
func (c *cluster) addNodeBasicSorted(node *Node) bool { n := c.unprotectedNodeByID(node.ID) if n != nil { if n.State != node.State || n.IsCoordinator != node.IsCoordinator || n.URI != node.URI { n.State = node.State n.IsCoordinator = node.IsCoordinator n.URI = node.URI return true } return false } c.nodes = append(c.nodes, node) // All hosts must be merged in the same order on all nodes in the cluster. sort.Sort(byID(c.nodes)) return true }
[ "func", "(", "c", "*", "cluster", ")", "addNodeBasicSorted", "(", "node", "*", "Node", ")", "bool", "{", "n", ":=", "c", ".", "unprotectedNodeByID", "(", "node", ".", "ID", ")", "\n", "if", "n", "!=", "nil", "{", "if", "n", ".", "State", "!=", "n...
// addNodeBasicSorted adds a node to the cluster, sorted by id. Returns a // pointer to the node and true if the node was added. unprotected.
[ "addNodeBasicSorted", "adds", "a", "node", "to", "the", "cluster", "sorted", "by", "id", ".", "Returns", "a", "pointer", "to", "the", "node", "and", "true", "if", "the", "node", "was", "added", ".", "unprotected", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L602-L620
train
pilosa/pilosa
cluster.go
Nodes
func (c *cluster) Nodes() []*Node { c.mu.RLock() defer c.mu.RUnlock() ret := make([]*Node, len(c.nodes)) copy(ret, c.nodes) return ret }
go
func (c *cluster) Nodes() []*Node { c.mu.RLock() defer c.mu.RUnlock() ret := make([]*Node, len(c.nodes)) copy(ret, c.nodes) return ret }
[ "func", "(", "c", "*", "cluster", ")", "Nodes", "(", ")", "[", "]", "*", "Node", "{", "c", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "RUnlock", "(", ")", "\n", "ret", ":=", "make", "(", "[", "]", "*", "Node", ...
// Nodes returns a copy of the slice of nodes in the cluster. Safe for // concurrent use, result may be modified.
[ "Nodes", "returns", "a", "copy", "of", "the", "slice", "of", "nodes", "in", "the", "cluster", ".", "Safe", "for", "concurrent", "use", "result", "may", "be", "modified", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L624-L630
train
pilosa/pilosa
cluster.go
removeNodeBasicSorted
func (c *cluster) removeNodeBasicSorted(nodeID string) bool { i := c.nodePositionByID(nodeID) if i < 0 { return false } copy(c.nodes[i:], c.nodes[i+1:]) c.nodes[len(c.nodes)-1] = nil c.nodes = c.nodes[:len(c.nodes)-1] return true }
go
func (c *cluster) removeNodeBasicSorted(nodeID string) bool { i := c.nodePositionByID(nodeID) if i < 0 { return false } copy(c.nodes[i:], c.nodes[i+1:]) c.nodes[len(c.nodes)-1] = nil c.nodes = c.nodes[:len(c.nodes)-1] return true }
[ "func", "(", "c", "*", "cluster", ")", "removeNodeBasicSorted", "(", "nodeID", "string", ")", "bool", "{", "i", ":=", "c", ".", "nodePositionByID", "(", "nodeID", ")", "\n", "if", "i", "<", "0", "{", "return", "false", "\n", "}", "\n", "copy", "(", ...
// removeNodeBasicSorted removes a node from the cluster, maintaining the sort // order. Returns true if the node was removed. unprotected.
[ "removeNodeBasicSorted", "removes", "a", "node", "from", "the", "cluster", "maintaining", "the", "sort", "order", ".", "Returns", "true", "if", "the", "node", "was", "removed", ".", "unprotected", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L634-L645
train
pilosa/pilosa
cluster.go
diff
func (c *cluster) diff(other *cluster) (action string, nodeID string, err error) { lenFrom := len(c.nodes) lenTo := len(other.nodes) // Determine if a node is being added or removed. if lenFrom == lenTo { return "", "", errors.New("clusters are the same size") } if lenFrom < lenTo { // Adding a node. if lenTo-lenFrom > 1 { return "", "", errors.New("adding more than one node at a time is not supported") } action = resizeJobActionAdd // Determine the node ID that is being added. for _, n := range other.nodes { if c.unprotectedNodeByID(n.ID) == nil { nodeID = n.ID break } } } else if lenFrom > lenTo { // Removing a node. if lenFrom-lenTo > 1 { return "", "", errors.New("removing more than one node at a time is not supported") } action = resizeJobActionRemove // Determine the node ID that is being removed. for _, n := range c.nodes { if other.unprotectedNodeByID(n.ID) == nil { nodeID = n.ID break } } } return action, nodeID, nil }
go
func (c *cluster) diff(other *cluster) (action string, nodeID string, err error) { lenFrom := len(c.nodes) lenTo := len(other.nodes) // Determine if a node is being added or removed. if lenFrom == lenTo { return "", "", errors.New("clusters are the same size") } if lenFrom < lenTo { // Adding a node. if lenTo-lenFrom > 1 { return "", "", errors.New("adding more than one node at a time is not supported") } action = resizeJobActionAdd // Determine the node ID that is being added. for _, n := range other.nodes { if c.unprotectedNodeByID(n.ID) == nil { nodeID = n.ID break } } } else if lenFrom > lenTo { // Removing a node. if lenFrom-lenTo > 1 { return "", "", errors.New("removing more than one node at a time is not supported") } action = resizeJobActionRemove // Determine the node ID that is being removed. for _, n := range c.nodes { if other.unprotectedNodeByID(n.ID) == nil { nodeID = n.ID break } } } return action, nodeID, nil }
[ "func", "(", "c", "*", "cluster", ")", "diff", "(", "other", "*", "cluster", ")", "(", "action", "string", ",", "nodeID", "string", ",", "err", "error", ")", "{", "lenFrom", ":=", "len", "(", "c", ".", "nodes", ")", "\n", "lenTo", ":=", "len", "(...
// diff compares c with another cluster and determines if a node is being // added or removed. An error is returned for any case other than where // exactly one node is added or removed. unprotected.
[ "diff", "compares", "c", "with", "another", "cluster", "and", "determines", "if", "a", "node", "is", "being", "added", "or", "removed", ".", "An", "error", "is", "returned", "for", "any", "case", "other", "than", "where", "exactly", "one", "node", "is", ...
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L715-L750
train
pilosa/pilosa
cluster.go
fragSources
func (c *cluster) fragSources(to *cluster, idx *Index) (map[string][]*ResizeSource, error) { m := make(map[string][]*ResizeSource) // Determine if a node is being added or removed. action, diffNodeID, err := c.diff(to) if err != nil { return nil, errors.Wrap(err, "diffing") } // Initialize the map with all the nodes in `to`. for _, n := range to.nodes { m[n.ID] = nil } // If a node is being added, the source can be confined to the // primary fragments (i.e. no need to use replicas as source data). // In this case, source fragments can be based on a cluster with // replica = 1. // If a node is being removed, however, then it will most likely // require that a replica fragment be the source data. srcCluster := c if action == resizeJobActionAdd && c.ReplicaN > 1 { srcCluster = newCluster() srcCluster.nodes = Nodes(c.nodes).Clone() srcCluster.Hasher = c.Hasher srcCluster.partitionN = c.partitionN srcCluster.ReplicaN = 1 } // Represents the fragment location for the from/to clusters. fFrags := c.fragsByHost(idx) tFrags := to.fragsByHost(idx) // srcFrags is the frag map based on a source cluster of replica = 1. srcFrags := srcCluster.fragsByHost(idx) // srcNodesByFrag is the inverse representation of srcFrags. srcNodesByFrag := make(map[frag]string) for nodeID, frags := range srcFrags { // If a node is being removed, don't consider it as a source. if action == resizeJobActionRemove && nodeID == diffNodeID { continue } for _, frag := range frags { srcNodesByFrag[frag] = nodeID } } // Get the frag diff for each nodeID. diffs := make(fragsByHost) for nodeID, frags := range tFrags { if _, ok := fFrags[nodeID]; ok { diffs[nodeID] = fragsDiff(frags, fFrags[nodeID]) } else { diffs[nodeID] = frags } } // Get the ResizeSource for each diff. for nodeID, diff := range diffs { m[nodeID] = []*ResizeSource{} for _, frag := range diff { // If there is no valid source node ID for a fragment, // it likely means that the replica factor was not // high enough for the remaining nodes to contain // the fragment. srcNodeID, ok := srcNodesByFrag[frag] if !ok { return nil, errors.New("not enough data to perform resize (replica factor may need to be increased)") } src := &ResizeSource{ Node: c.unprotectedNodeByID(srcNodeID), Index: idx.Name(), Field: frag.field, View: frag.view, Shard: frag.shard, } m[nodeID] = append(m[nodeID], src) } } return m, nil }
go
func (c *cluster) fragSources(to *cluster, idx *Index) (map[string][]*ResizeSource, error) { m := make(map[string][]*ResizeSource) // Determine if a node is being added or removed. action, diffNodeID, err := c.diff(to) if err != nil { return nil, errors.Wrap(err, "diffing") } // Initialize the map with all the nodes in `to`. for _, n := range to.nodes { m[n.ID] = nil } // If a node is being added, the source can be confined to the // primary fragments (i.e. no need to use replicas as source data). // In this case, source fragments can be based on a cluster with // replica = 1. // If a node is being removed, however, then it will most likely // require that a replica fragment be the source data. srcCluster := c if action == resizeJobActionAdd && c.ReplicaN > 1 { srcCluster = newCluster() srcCluster.nodes = Nodes(c.nodes).Clone() srcCluster.Hasher = c.Hasher srcCluster.partitionN = c.partitionN srcCluster.ReplicaN = 1 } // Represents the fragment location for the from/to clusters. fFrags := c.fragsByHost(idx) tFrags := to.fragsByHost(idx) // srcFrags is the frag map based on a source cluster of replica = 1. srcFrags := srcCluster.fragsByHost(idx) // srcNodesByFrag is the inverse representation of srcFrags. srcNodesByFrag := make(map[frag]string) for nodeID, frags := range srcFrags { // If a node is being removed, don't consider it as a source. if action == resizeJobActionRemove && nodeID == diffNodeID { continue } for _, frag := range frags { srcNodesByFrag[frag] = nodeID } } // Get the frag diff for each nodeID. diffs := make(fragsByHost) for nodeID, frags := range tFrags { if _, ok := fFrags[nodeID]; ok { diffs[nodeID] = fragsDiff(frags, fFrags[nodeID]) } else { diffs[nodeID] = frags } } // Get the ResizeSource for each diff. for nodeID, diff := range diffs { m[nodeID] = []*ResizeSource{} for _, frag := range diff { // If there is no valid source node ID for a fragment, // it likely means that the replica factor was not // high enough for the remaining nodes to contain // the fragment. srcNodeID, ok := srcNodesByFrag[frag] if !ok { return nil, errors.New("not enough data to perform resize (replica factor may need to be increased)") } src := &ResizeSource{ Node: c.unprotectedNodeByID(srcNodeID), Index: idx.Name(), Field: frag.field, View: frag.view, Shard: frag.shard, } m[nodeID] = append(m[nodeID], src) } } return m, nil }
[ "func", "(", "c", "*", "cluster", ")", "fragSources", "(", "to", "*", "cluster", ",", "idx", "*", "Index", ")", "(", "map", "[", "string", "]", "[", "]", "*", "ResizeSource", ",", "error", ")", "{", "m", ":=", "make", "(", "map", "[", "string", ...
// fragSources returns a list of ResizeSources - for each node in the `to` cluster - // required to move from cluster `c` to cluster `to`. unprotected.
[ "fragSources", "returns", "a", "list", "of", "ResizeSources", "-", "for", "each", "node", "in", "the", "to", "cluster", "-", "required", "to", "move", "from", "cluster", "c", "to", "cluster", "to", ".", "unprotected", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L754-L838
train
pilosa/pilosa
cluster.go
partition
func (c *cluster) partition(index string, shard uint64) int { var buf [8]byte binary.BigEndian.PutUint64(buf[:], shard) // Hash the bytes and mod by partition count. h := fnv.New64a() _, _ = h.Write([]byte(index)) _, _ = h.Write(buf[:]) return int(h.Sum64() % uint64(c.partitionN)) }
go
func (c *cluster) partition(index string, shard uint64) int { var buf [8]byte binary.BigEndian.PutUint64(buf[:], shard) // Hash the bytes and mod by partition count. h := fnv.New64a() _, _ = h.Write([]byte(index)) _, _ = h.Write(buf[:]) return int(h.Sum64() % uint64(c.partitionN)) }
[ "func", "(", "c", "*", "cluster", ")", "partition", "(", "index", "string", ",", "shard", "uint64", ")", "int", "{", "var", "buf", "[", "8", "]", "byte", "\n", "binary", ".", "BigEndian", ".", "PutUint64", "(", "buf", "[", ":", "]", ",", "shard", ...
// partition returns the partition that a shard belongs to.
[ "partition", "returns", "the", "partition", "that", "a", "shard", "belongs", "to", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L841-L850
train
pilosa/pilosa
cluster.go
ShardNodes
func (c *cluster) ShardNodes(index string, shard uint64) []*Node { c.mu.RLock() defer c.mu.RUnlock() return c.shardNodes(index, shard) }
go
func (c *cluster) ShardNodes(index string, shard uint64) []*Node { c.mu.RLock() defer c.mu.RUnlock() return c.shardNodes(index, shard) }
[ "func", "(", "c", "*", "cluster", ")", "ShardNodes", "(", "index", "string", ",", "shard", "uint64", ")", "[", "]", "*", "Node", "{", "c", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "RUnlock", "(", ")", "\n", "return...
// ShardNodes returns a list of nodes that own a fragment. Safe for concurrent use.
[ "ShardNodes", "returns", "a", "list", "of", "nodes", "that", "own", "a", "fragment", ".", "Safe", "for", "concurrent", "use", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L853-L857
train
pilosa/pilosa
cluster.go
shardNodes
func (c *cluster) shardNodes(index string, shard uint64) []*Node { return c.partitionNodes(c.partition(index, shard)) }
go
func (c *cluster) shardNodes(index string, shard uint64) []*Node { return c.partitionNodes(c.partition(index, shard)) }
[ "func", "(", "c", "*", "cluster", ")", "shardNodes", "(", "index", "string", ",", "shard", "uint64", ")", "[", "]", "*", "Node", "{", "return", "c", ".", "partitionNodes", "(", "c", ".", "partition", "(", "index", ",", "shard", ")", ")", "\n", "}" ...
// shardNodes returns a list of nodes that own a fragment. unprotected
[ "shardNodes", "returns", "a", "list", "of", "nodes", "that", "own", "a", "fragment", ".", "unprotected" ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L860-L862
train
pilosa/pilosa
cluster.go
ownsShard
func (c *cluster) ownsShard(nodeID string, index string, shard uint64) bool { c.mu.RLock() defer c.mu.RUnlock() return Nodes(c.shardNodes(index, shard)).ContainsID(nodeID) }
go
func (c *cluster) ownsShard(nodeID string, index string, shard uint64) bool { c.mu.RLock() defer c.mu.RUnlock() return Nodes(c.shardNodes(index, shard)).ContainsID(nodeID) }
[ "func", "(", "c", "*", "cluster", ")", "ownsShard", "(", "nodeID", "string", ",", "index", "string", ",", "shard", "uint64", ")", "bool", "{", "c", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "RUnlock", "(", ")", "\n", ...
// ownsShard returns true if a host owns a fragment.
[ "ownsShard", "returns", "true", "if", "a", "host", "owns", "a", "fragment", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L865-L869
train
pilosa/pilosa
cluster.go
partitionNodes
func (c *cluster) partitionNodes(partitionID int) []*Node { // Default replica count to between one and the number of nodes. // The replica count can be zero if there are no nodes. replicaN := c.ReplicaN if replicaN > len(c.nodes) { replicaN = len(c.nodes) } else if replicaN == 0 { replicaN = 1 } // Determine primary owner node. nodeIndex := c.Hasher.Hash(uint64(partitionID), len(c.nodes)) // Collect nodes around the ring. nodes := make([]*Node, replicaN) for i := 0; i < replicaN; i++ { nodes[i] = c.nodes[(nodeIndex+i)%len(c.nodes)] } return nodes }
go
func (c *cluster) partitionNodes(partitionID int) []*Node { // Default replica count to between one and the number of nodes. // The replica count can be zero if there are no nodes. replicaN := c.ReplicaN if replicaN > len(c.nodes) { replicaN = len(c.nodes) } else if replicaN == 0 { replicaN = 1 } // Determine primary owner node. nodeIndex := c.Hasher.Hash(uint64(partitionID), len(c.nodes)) // Collect nodes around the ring. nodes := make([]*Node, replicaN) for i := 0; i < replicaN; i++ { nodes[i] = c.nodes[(nodeIndex+i)%len(c.nodes)] } return nodes }
[ "func", "(", "c", "*", "cluster", ")", "partitionNodes", "(", "partitionID", "int", ")", "[", "]", "*", "Node", "{", "replicaN", ":=", "c", ".", "ReplicaN", "\n", "if", "replicaN", ">", "len", "(", "c", ".", "nodes", ")", "{", "replicaN", "=", "len...
// partitionNodes returns a list of nodes that own a partition. unprotected.
[ "partitionNodes", "returns", "a", "list", "of", "nodes", "that", "own", "a", "partition", ".", "unprotected", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L872-L892
train
pilosa/pilosa
cluster.go
containsShards
func (c *cluster) containsShards(index string, availableShards *roaring.Bitmap, node *Node) []uint64 { var shards []uint64 availableShards.ForEach(func(i uint64) { p := c.partition(index, i) // Determine the nodes for partition. nodes := c.partitionNodes(p) for _, n := range nodes { if n.ID == node.ID { shards = append(shards, i) } } }) return shards }
go
func (c *cluster) containsShards(index string, availableShards *roaring.Bitmap, node *Node) []uint64 { var shards []uint64 availableShards.ForEach(func(i uint64) { p := c.partition(index, i) // Determine the nodes for partition. nodes := c.partitionNodes(p) for _, n := range nodes { if n.ID == node.ID { shards = append(shards, i) } } }) return shards }
[ "func", "(", "c", "*", "cluster", ")", "containsShards", "(", "index", "string", ",", "availableShards", "*", "roaring", ".", "Bitmap", ",", "node", "*", "Node", ")", "[", "]", "uint64", "{", "var", "shards", "[", "]", "uint64", "\n", "availableShards", ...
// containsShards is like OwnsShards, but it includes replicas.
[ "containsShards", "is", "like", "OwnsShards", "but", "it", "includes", "replicas", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L895-L908
train
pilosa/pilosa
cluster.go
needTopologyAgreement
func (c *cluster) needTopologyAgreement() bool { return (c.state == ClusterStateStarting || c.state == ClusterStateDegraded) && !stringSlicesAreEqual(c.Topology.nodeIDs, c.nodeIDs()) }
go
func (c *cluster) needTopologyAgreement() bool { return (c.state == ClusterStateStarting || c.state == ClusterStateDegraded) && !stringSlicesAreEqual(c.Topology.nodeIDs, c.nodeIDs()) }
[ "func", "(", "c", "*", "cluster", ")", "needTopologyAgreement", "(", ")", "bool", "{", "return", "(", "c", ".", "state", "==", "ClusterStateStarting", "||", "c", ".", "state", "==", "ClusterStateDegraded", ")", "&&", "!", "stringSlicesAreEqual", "(", "c", ...
// needTopologyAgreement is unprotected.
[ "needTopologyAgreement", "is", "unprotected", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1007-L1009
train
pilosa/pilosa
cluster.go
haveTopologyAgreement
func (c *cluster) haveTopologyAgreement() bool { if c.Static { return true } return stringSlicesAreEqual(c.Topology.nodeIDs, c.nodeIDs()) }
go
func (c *cluster) haveTopologyAgreement() bool { if c.Static { return true } return stringSlicesAreEqual(c.Topology.nodeIDs, c.nodeIDs()) }
[ "func", "(", "c", "*", "cluster", ")", "haveTopologyAgreement", "(", ")", "bool", "{", "if", "c", ".", "Static", "{", "return", "true", "\n", "}", "\n", "return", "stringSlicesAreEqual", "(", "c", ".", "Topology", ".", "nodeIDs", ",", "c", ".", "nodeID...
// haveTopologyAgreement is unprotected.
[ "haveTopologyAgreement", "is", "unprotected", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1012-L1017
train
pilosa/pilosa
cluster.go
allNodesReady
func (c *cluster) allNodesReady() (ret bool) { if c.Static { return true } for _, id := range c.nodeIDs() { if c.Topology.nodeStates[id] != nodeStateReady { return false } } return true }
go
func (c *cluster) allNodesReady() (ret bool) { if c.Static { return true } for _, id := range c.nodeIDs() { if c.Topology.nodeStates[id] != nodeStateReady { return false } } return true }
[ "func", "(", "c", "*", "cluster", ")", "allNodesReady", "(", ")", "(", "ret", "bool", ")", "{", "if", "c", ".", "Static", "{", "return", "true", "\n", "}", "\n", "for", "_", ",", "id", ":=", "range", "c", ".", "nodeIDs", "(", ")", "{", "if", ...
// allNodesReady is unprotected.
[ "allNodesReady", "is", "unprotected", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cluster.go#L1020-L1030
train
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", "var", "setNormal", "bool", "\n", "for...
// 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", ".", "unprotectedCompleteCurre...
// 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", "]", ...
// 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", "{", "ids", ":=", "make", "(", "map", "[", "string", "]", "bool", ")", "\n", "if", "action", "==", "resizeJ...
// 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", "(", "\"run resizeJob\"", ")", "\n", "j", ".", "setState", "(", "resizeJobStateRunning", ")", "\n", "if", "!", "j", ".", "nodesArePending", "(", ...
// 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", ")"...
// 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", ")", ...
// 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", "i", ":=", "t", ".", "positionByID", "(", "nodeI...
// 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", ",", "\".topology\"", ")", ")", "\n", "if", "os", ".", "IsNotExi...
// 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", ",", "\...
// 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", ")", "{", "if", "e", ".", "Node", ".", "ID", "==", "c", ".", "Node", ".", "ID", "{", "return", "nil", "\n", "}", "\n", "switch", "e", ...
// 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", "(", "\"no...
// 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", "if", "!", "c", ".", "unprotectedIsCoordinator", ...
// 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", "pos", ":=", "c", ".", "nodePositionByID", "(", "c", ".", "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"...
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",...
// 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", ...
// 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", "(", "\"DEPRECATED: OptServerPrimaryTranslateStore\"", ")", "\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", "="...
// 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", "="...
// 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", "(", "mapSi...
// 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", "(", "\"open server\"", ")", "\n", "err", ":=", "s", ".", "holder", ".", "logStartup", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ...
// 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", "{", "close", "(", "s", ".", "closing", ")", "\n", "s", ".", "wg", ".", "Wait", "(", ")", "\n", "var", "errh", "error", "\n", "var", "errc", "error", "\n", "if", "s", ".", "clu...
// 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", "(", ")", ...
// 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",...
// 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"...
// 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", ")", "{", "if", "s", ".", "cluster", ".", "State", "(", ")", "!=", "ClusterStateNormal", "{", "return", "\n", "}", "\n", "go", "func", "(", ")", "{", "s", ".", "holde...
// 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", "(", ")", "{", "if", "s", ".", "diagnosticInterval", "<", "time", ".", "Minute", "{", "s", ".", "logger", ".", "Printf", "(", "\"diagnostics disabled\"", ")", "\n", "return", "\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", "(", ")", "{", "if", "s", ".", "metricInterval", "<=", "0", "{", "return", "\n", "}", "\n", "var", "m", "runtime", ".", "MemStats", "\n", "ticker", ":=", "time", ".", "NewTicker", "(", "s", "....
// 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", "\"darwin\"", ",", "\"linux\"", ",", "\"unix\"", ",", "\"freebsd\"", ":", "pid", ":=", "os", ".", "Getpid", "(", ")", "\n", "out", ...
// 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", ...
// 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", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "cmd", ".", "Path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", ...
// 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", "{", "i", ".", "logger", ".", "Debugf", "(", "\"ensure index path exists: %s\"", ",", "i", ".", "path", ")", "\n", "if", "err", ":=", "os", ".", "MkdirAll", "(", "i", ".", "path", ",",...
// 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", ",", "\"opening d...
// 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", ...
// 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", "buf", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "filepath", ".", "Join", "(", "i", ".", "path", ",", "\".meta\"", ")"...
// 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", "{", "buf", ",", "err", ":=", "proto", ".", "Marshal", "(", "&", "internal", ".", "IndexMeta", "{", "Keys", ":", "i", ".", "keys", ",", "TrackExistence", ":", "i", ".", "trackExist...
// 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", "i", ".", "columnAttrs", ".", "Close", "(", ")", "\n", "for", "_", ",...
// 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", "i", ".", "mu", ".", "RLock", "(", ")", "\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", ")",...
// 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", "a", ":=", "make", "(", "[", "]", "*", "Field", "...
// 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", "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", "{...
// 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", "f", ":=", "i", ".", "field", "(", "name", ")",...
// 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"...
// 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", ",",...
// 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", ".", "tag...
// 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", ".", "Strings", "(", "a", ")", "\n", "sort", ".", "Strings", "(", "b", ")", "\n", "n", ":=", "len", "(", "a", ")", "\n", "if", "len", "(...
// 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", "{", "var", "blk0", ",", "blk1", "*", "AttrBlock", "\n", "if", "len", "(", "a", ")", ...
// 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", ")",...
// 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", "(", ...
// 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", ",", "&"...
// 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...
// 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", "(", "\"invalid sch...
// 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", "(", "\"invalid host\"", ...
// 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", "=", "sche...
// 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", "(", "\"%s://%s:%d\"", ",", "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