repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
list | docstring
stringlengths 6
2.61k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
pilosa/pilosa
|
http/client.go
|
marshalImportPayload
|
func (c *InternalClient) marshalImportPayload(index, field string, shard uint64, bits []pilosa.Bit) ([]byte, error) {
// Separate row and column IDs to reduce allocations.
rowIDs := Bits(bits).RowIDs()
rowKeys := Bits(bits).RowKeys()
columnIDs := Bits(bits).ColumnIDs()
columnKeys := Bits(bits).ColumnKeys()
timestamps := Bits(bits).Timestamps()
// Marshal data to protobuf.
buf, err := c.serializer.Marshal(&pilosa.ImportRequest{
Index: index,
Field: field,
Shard: shard,
RowIDs: rowIDs,
RowKeys: rowKeys,
ColumnIDs: columnIDs,
ColumnKeys: columnKeys,
Timestamps: timestamps,
})
if err != nil {
return nil, fmt.Errorf("marshal import request: %s", err)
}
return buf, nil
}
|
go
|
func (c *InternalClient) marshalImportPayload(index, field string, shard uint64, bits []pilosa.Bit) ([]byte, error) {
// Separate row and column IDs to reduce allocations.
rowIDs := Bits(bits).RowIDs()
rowKeys := Bits(bits).RowKeys()
columnIDs := Bits(bits).ColumnIDs()
columnKeys := Bits(bits).ColumnKeys()
timestamps := Bits(bits).Timestamps()
// Marshal data to protobuf.
buf, err := c.serializer.Marshal(&pilosa.ImportRequest{
Index: index,
Field: field,
Shard: shard,
RowIDs: rowIDs,
RowKeys: rowKeys,
ColumnIDs: columnIDs,
ColumnKeys: columnKeys,
Timestamps: timestamps,
})
if err != nil {
return nil, fmt.Errorf("marshal import request: %s", err)
}
return buf, nil
}
|
[
"func",
"(",
"c",
"*",
"InternalClient",
")",
"marshalImportPayload",
"(",
"index",
",",
"field",
"string",
",",
"shard",
"uint64",
",",
"bits",
"[",
"]",
"pilosa",
".",
"Bit",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// Separate row and column IDs to reduce allocations.",
"rowIDs",
":=",
"Bits",
"(",
"bits",
")",
".",
"RowIDs",
"(",
")",
"\n",
"rowKeys",
":=",
"Bits",
"(",
"bits",
")",
".",
"RowKeys",
"(",
")",
"\n",
"columnIDs",
":=",
"Bits",
"(",
"bits",
")",
".",
"ColumnIDs",
"(",
")",
"\n",
"columnKeys",
":=",
"Bits",
"(",
"bits",
")",
".",
"ColumnKeys",
"(",
")",
"\n",
"timestamps",
":=",
"Bits",
"(",
"bits",
")",
".",
"Timestamps",
"(",
")",
"\n\n",
"// Marshal data to protobuf.",
"buf",
",",
"err",
":=",
"c",
".",
"serializer",
".",
"Marshal",
"(",
"&",
"pilosa",
".",
"ImportRequest",
"{",
"Index",
":",
"index",
",",
"Field",
":",
"field",
",",
"Shard",
":",
"shard",
",",
"RowIDs",
":",
"rowIDs",
",",
"RowKeys",
":",
"rowKeys",
",",
"ColumnIDs",
":",
"columnIDs",
",",
"ColumnKeys",
":",
"columnKeys",
",",
"Timestamps",
":",
"timestamps",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"buf",
",",
"nil",
"\n",
"}"
] |
// marshalImportPayload marshalls the import parameters into a protobuf byte slice.
|
[
"marshalImportPayload",
"marshalls",
"the",
"import",
"parameters",
"into",
"a",
"protobuf",
"byte",
"slice",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L440-L463
|
train
|
pilosa/pilosa
|
http/client.go
|
importNode
|
func (c *InternalClient) importNode(ctx context.Context, node *pilosa.Node, index, field string, buf []byte, opts *pilosa.ImportOptions) error {
span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.importNode")
defer span.Finish()
// Create URL & HTTP request.
path := fmt.Sprintf("/index/%s/field/%s/import", index, field)
u := nodePathToURL(node, path)
vals := url.Values{}
if opts.Clear {
vals.Set("clear", "true")
}
if opts.IgnoreKeyCheck {
vals.Set("ignoreKeyCheck", "true")
}
url := fmt.Sprintf("%s?%s", u.String(), vals.Encode())
req, err := http.NewRequest("POST", url, bytes.NewReader(buf))
if err != nil {
return errors.Wrap(err, "creating request")
}
req.Header.Set("Content-Length", strconv.Itoa(len(buf)))
req.Header.Set("Content-Type", "application/x-protobuf")
req.Header.Set("Accept", "application/x-protobuf")
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
// Execute request against the host.
resp, err := c.executeRequest(req.WithContext(ctx))
if err != nil {
return err
}
defer resp.Body.Close()
// Read body and unmarshal response.
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return errors.Wrap(err, "reading")
}
var isresp pilosa.ImportResponse
if err := c.serializer.Unmarshal(body, &isresp); err != nil {
return fmt.Errorf("unmarshal import response: %s", err)
} else if s := isresp.Err; s != "" {
return errors.New(s)
}
return nil
}
|
go
|
func (c *InternalClient) importNode(ctx context.Context, node *pilosa.Node, index, field string, buf []byte, opts *pilosa.ImportOptions) error {
span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.importNode")
defer span.Finish()
// Create URL & HTTP request.
path := fmt.Sprintf("/index/%s/field/%s/import", index, field)
u := nodePathToURL(node, path)
vals := url.Values{}
if opts.Clear {
vals.Set("clear", "true")
}
if opts.IgnoreKeyCheck {
vals.Set("ignoreKeyCheck", "true")
}
url := fmt.Sprintf("%s?%s", u.String(), vals.Encode())
req, err := http.NewRequest("POST", url, bytes.NewReader(buf))
if err != nil {
return errors.Wrap(err, "creating request")
}
req.Header.Set("Content-Length", strconv.Itoa(len(buf)))
req.Header.Set("Content-Type", "application/x-protobuf")
req.Header.Set("Accept", "application/x-protobuf")
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
// Execute request against the host.
resp, err := c.executeRequest(req.WithContext(ctx))
if err != nil {
return err
}
defer resp.Body.Close()
// Read body and unmarshal response.
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return errors.Wrap(err, "reading")
}
var isresp pilosa.ImportResponse
if err := c.serializer.Unmarshal(body, &isresp); err != nil {
return fmt.Errorf("unmarshal import response: %s", err)
} else if s := isresp.Err; s != "" {
return errors.New(s)
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"InternalClient",
")",
"importNode",
"(",
"ctx",
"context",
".",
"Context",
",",
"node",
"*",
"pilosa",
".",
"Node",
",",
"index",
",",
"field",
"string",
",",
"buf",
"[",
"]",
"byte",
",",
"opts",
"*",
"pilosa",
".",
"ImportOptions",
")",
"error",
"{",
"span",
",",
"ctx",
":=",
"tracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"// Create URL & HTTP request.",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"index",
",",
"field",
")",
"\n",
"u",
":=",
"nodePathToURL",
"(",
"node",
",",
"path",
")",
"\n\n",
"vals",
":=",
"url",
".",
"Values",
"{",
"}",
"\n",
"if",
"opts",
".",
"Clear",
"{",
"vals",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"opts",
".",
"IgnoreKeyCheck",
"{",
"vals",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"u",
".",
"String",
"(",
")",
",",
"vals",
".",
"Encode",
"(",
")",
")",
"\n\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"bytes",
".",
"NewReader",
"(",
"buf",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"len",
"(",
"buf",
")",
")",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"pilosa",
".",
"Version",
")",
"\n\n",
"// Execute request against the host.",
"resp",
",",
"err",
":=",
"c",
".",
"executeRequest",
"(",
"req",
".",
"WithContext",
"(",
"ctx",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"// Read body and unmarshal response.",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"isresp",
"pilosa",
".",
"ImportResponse",
"\n",
"if",
"err",
":=",
"c",
".",
"serializer",
".",
"Unmarshal",
"(",
"body",
",",
"&",
"isresp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"if",
"s",
":=",
"isresp",
".",
"Err",
";",
"s",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"s",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// importNode sends a pre-marshaled import request to a node.
|
[
"importNode",
"sends",
"a",
"pre",
"-",
"marshaled",
"import",
"request",
"to",
"a",
"node",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L466-L513
|
train
|
pilosa/pilosa
|
http/client.go
|
ImportValueK
|
func (c *InternalClient) ImportValueK(ctx context.Context, index, field string, vals []pilosa.FieldValue, opts ...pilosa.ImportOption) error {
span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.ImportValueK")
defer span.Finish()
buf, err := c.marshalImportValuePayload(index, field, 0, vals)
if err != nil {
return fmt.Errorf("Error Creating Payload: %s", err)
}
// Set up import options.
options := &pilosa.ImportOptions{}
for _, opt := range opts {
err := opt(options)
if err != nil {
return errors.Wrap(err, "applying option")
}
}
// Get the coordinator node; all bits are sent to the
// primary translate store (i.e. coordinator).
nodes, err := c.Nodes(ctx)
if err != nil {
return fmt.Errorf("getting nodes: %s", err)
}
coord := getCoordinatorNode(nodes)
if coord == nil {
return fmt.Errorf("could not find the coordinator node")
}
// Import to node.
if err := c.importNode(ctx, coord, index, field, buf, options); err != nil {
return fmt.Errorf("import node: host=%s, err=%s", coord.URI, err)
}
return nil
}
|
go
|
func (c *InternalClient) ImportValueK(ctx context.Context, index, field string, vals []pilosa.FieldValue, opts ...pilosa.ImportOption) error {
span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.ImportValueK")
defer span.Finish()
buf, err := c.marshalImportValuePayload(index, field, 0, vals)
if err != nil {
return fmt.Errorf("Error Creating Payload: %s", err)
}
// Set up import options.
options := &pilosa.ImportOptions{}
for _, opt := range opts {
err := opt(options)
if err != nil {
return errors.Wrap(err, "applying option")
}
}
// Get the coordinator node; all bits are sent to the
// primary translate store (i.e. coordinator).
nodes, err := c.Nodes(ctx)
if err != nil {
return fmt.Errorf("getting nodes: %s", err)
}
coord := getCoordinatorNode(nodes)
if coord == nil {
return fmt.Errorf("could not find the coordinator node")
}
// Import to node.
if err := c.importNode(ctx, coord, index, field, buf, options); err != nil {
return fmt.Errorf("import node: host=%s, err=%s", coord.URI, err)
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"InternalClient",
")",
"ImportValueK",
"(",
"ctx",
"context",
".",
"Context",
",",
"index",
",",
"field",
"string",
",",
"vals",
"[",
"]",
"pilosa",
".",
"FieldValue",
",",
"opts",
"...",
"pilosa",
".",
"ImportOption",
")",
"error",
"{",
"span",
",",
"ctx",
":=",
"tracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"buf",
",",
"err",
":=",
"c",
".",
"marshalImportValuePayload",
"(",
"index",
",",
"field",
",",
"0",
",",
"vals",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Set up import options.",
"options",
":=",
"&",
"pilosa",
".",
"ImportOptions",
"{",
"}",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"err",
":=",
"opt",
"(",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Get the coordinator node; all bits are sent to the",
"// primary translate store (i.e. coordinator).",
"nodes",
",",
"err",
":=",
"c",
".",
"Nodes",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"coord",
":=",
"getCoordinatorNode",
"(",
"nodes",
")",
"\n",
"if",
"coord",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Import to node.",
"if",
"err",
":=",
"c",
".",
"importNode",
"(",
"ctx",
",",
"coord",
",",
"index",
",",
"field",
",",
"buf",
",",
"options",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"coord",
".",
"URI",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// ImportValueK bulk imports keyed field values to a host.
|
[
"ImportValueK",
"bulk",
"imports",
"keyed",
"field",
"values",
"to",
"a",
"host",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L557-L592
|
train
|
pilosa/pilosa
|
http/client.go
|
marshalImportValuePayload
|
func (c *InternalClient) marshalImportValuePayload(index, field string, shard uint64, vals []pilosa.FieldValue) ([]byte, error) {
// Separate row and column IDs to reduce allocations.
columnIDs := FieldValues(vals).ColumnIDs()
columnKeys := FieldValues(vals).ColumnKeys()
values := FieldValues(vals).Values()
// Marshal data to protobuf.
buf, err := c.serializer.Marshal(&pilosa.ImportValueRequest{
Index: index,
Field: field,
Shard: shard,
ColumnIDs: columnIDs,
ColumnKeys: columnKeys,
Values: values,
})
if err != nil {
return nil, fmt.Errorf("marshal import request: %s", err)
}
return buf, nil
}
|
go
|
func (c *InternalClient) marshalImportValuePayload(index, field string, shard uint64, vals []pilosa.FieldValue) ([]byte, error) {
// Separate row and column IDs to reduce allocations.
columnIDs := FieldValues(vals).ColumnIDs()
columnKeys := FieldValues(vals).ColumnKeys()
values := FieldValues(vals).Values()
// Marshal data to protobuf.
buf, err := c.serializer.Marshal(&pilosa.ImportValueRequest{
Index: index,
Field: field,
Shard: shard,
ColumnIDs: columnIDs,
ColumnKeys: columnKeys,
Values: values,
})
if err != nil {
return nil, fmt.Errorf("marshal import request: %s", err)
}
return buf, nil
}
|
[
"func",
"(",
"c",
"*",
"InternalClient",
")",
"marshalImportValuePayload",
"(",
"index",
",",
"field",
"string",
",",
"shard",
"uint64",
",",
"vals",
"[",
"]",
"pilosa",
".",
"FieldValue",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// Separate row and column IDs to reduce allocations.",
"columnIDs",
":=",
"FieldValues",
"(",
"vals",
")",
".",
"ColumnIDs",
"(",
")",
"\n",
"columnKeys",
":=",
"FieldValues",
"(",
"vals",
")",
".",
"ColumnKeys",
"(",
")",
"\n",
"values",
":=",
"FieldValues",
"(",
"vals",
")",
".",
"Values",
"(",
")",
"\n\n",
"// Marshal data to protobuf.",
"buf",
",",
"err",
":=",
"c",
".",
"serializer",
".",
"Marshal",
"(",
"&",
"pilosa",
".",
"ImportValueRequest",
"{",
"Index",
":",
"index",
",",
"Field",
":",
"field",
",",
"Shard",
":",
"shard",
",",
"ColumnIDs",
":",
"columnIDs",
",",
"ColumnKeys",
":",
"columnKeys",
",",
"Values",
":",
"values",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"buf",
",",
"nil",
"\n",
"}"
] |
// marshalImportValuePayload marshalls the import parameters into a protobuf byte slice.
|
[
"marshalImportValuePayload",
"marshalls",
"the",
"import",
"parameters",
"into",
"a",
"protobuf",
"byte",
"slice",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L595-L614
|
train
|
pilosa/pilosa
|
http/client.go
|
ExportCSV
|
func (c *InternalClient) ExportCSV(ctx context.Context, index, field string, shard uint64, w io.Writer) error {
span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.ExportCSV")
defer span.Finish()
if index == "" {
return pilosa.ErrIndexRequired
} else if field == "" {
return pilosa.ErrFieldRequired
}
// Retrieve a list of nodes that own the shard.
nodes, err := c.FragmentNodes(ctx, index, shard)
if err != nil {
return fmt.Errorf("shard nodes: %s", err)
}
// Attempt nodes in random order.
var e error
for _, i := range rand.Perm(len(nodes)) {
node := nodes[i]
if err := c.exportNodeCSV(ctx, node, index, field, shard, w); err != nil {
e = fmt.Errorf("export node: host=%s, err=%s", node.URI, err)
continue
} else {
return nil
}
}
return e
}
|
go
|
func (c *InternalClient) ExportCSV(ctx context.Context, index, field string, shard uint64, w io.Writer) error {
span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.ExportCSV")
defer span.Finish()
if index == "" {
return pilosa.ErrIndexRequired
} else if field == "" {
return pilosa.ErrFieldRequired
}
// Retrieve a list of nodes that own the shard.
nodes, err := c.FragmentNodes(ctx, index, shard)
if err != nil {
return fmt.Errorf("shard nodes: %s", err)
}
// Attempt nodes in random order.
var e error
for _, i := range rand.Perm(len(nodes)) {
node := nodes[i]
if err := c.exportNodeCSV(ctx, node, index, field, shard, w); err != nil {
e = fmt.Errorf("export node: host=%s, err=%s", node.URI, err)
continue
} else {
return nil
}
}
return e
}
|
[
"func",
"(",
"c",
"*",
"InternalClient",
")",
"ExportCSV",
"(",
"ctx",
"context",
".",
"Context",
",",
"index",
",",
"field",
"string",
",",
"shard",
"uint64",
",",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"span",
",",
"ctx",
":=",
"tracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"if",
"index",
"==",
"\"",
"\"",
"{",
"return",
"pilosa",
".",
"ErrIndexRequired",
"\n",
"}",
"else",
"if",
"field",
"==",
"\"",
"\"",
"{",
"return",
"pilosa",
".",
"ErrFieldRequired",
"\n",
"}",
"\n\n",
"// Retrieve a list of nodes that own the shard.",
"nodes",
",",
"err",
":=",
"c",
".",
"FragmentNodes",
"(",
"ctx",
",",
"index",
",",
"shard",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Attempt nodes in random order.",
"var",
"e",
"error",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"rand",
".",
"Perm",
"(",
"len",
"(",
"nodes",
")",
")",
"{",
"node",
":=",
"nodes",
"[",
"i",
"]",
"\n\n",
"if",
"err",
":=",
"c",
".",
"exportNodeCSV",
"(",
"ctx",
",",
"node",
",",
"index",
",",
"field",
",",
"shard",
",",
"w",
")",
";",
"err",
"!=",
"nil",
"{",
"e",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"node",
".",
"URI",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"else",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"e",
"\n",
"}"
] |
// ExportCSV bulk exports data for a single shard from a host to CSV format.
|
[
"ExportCSV",
"bulk",
"exports",
"data",
"for",
"a",
"single",
"shard",
"from",
"a",
"host",
"to",
"CSV",
"format",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L671-L701
|
train
|
pilosa/pilosa
|
http/client.go
|
exportNodeCSV
|
func (c *InternalClient) exportNodeCSV(ctx context.Context, node *pilosa.Node, index, field string, shard uint64, w io.Writer) error {
span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.exportNodeCSV")
defer span.Finish()
// Create URL.
u := nodePathToURL(node, "/export")
u.RawQuery = url.Values{
"index": {index},
"field": {field},
"shard": {strconv.FormatUint(shard, 10)},
}.Encode()
// Generate HTTP request.
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
return errors.Wrap(err, "creating request")
}
req.Header.Set("Accept", "text/csv")
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
// Execute request against the host.
resp, err := c.executeRequest(req.WithContext(ctx))
if err != nil {
return err
}
defer resp.Body.Close()
// Copy body to writer.
if _, err := io.Copy(w, resp.Body); err != nil {
return errors.Wrap(err, "copying")
}
return nil
}
|
go
|
func (c *InternalClient) exportNodeCSV(ctx context.Context, node *pilosa.Node, index, field string, shard uint64, w io.Writer) error {
span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.exportNodeCSV")
defer span.Finish()
// Create URL.
u := nodePathToURL(node, "/export")
u.RawQuery = url.Values{
"index": {index},
"field": {field},
"shard": {strconv.FormatUint(shard, 10)},
}.Encode()
// Generate HTTP request.
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
return errors.Wrap(err, "creating request")
}
req.Header.Set("Accept", "text/csv")
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
// Execute request against the host.
resp, err := c.executeRequest(req.WithContext(ctx))
if err != nil {
return err
}
defer resp.Body.Close()
// Copy body to writer.
if _, err := io.Copy(w, resp.Body); err != nil {
return errors.Wrap(err, "copying")
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"InternalClient",
")",
"exportNodeCSV",
"(",
"ctx",
"context",
".",
"Context",
",",
"node",
"*",
"pilosa",
".",
"Node",
",",
"index",
",",
"field",
"string",
",",
"shard",
"uint64",
",",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"span",
",",
"ctx",
":=",
"tracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"// Create URL.",
"u",
":=",
"nodePathToURL",
"(",
"node",
",",
"\"",
"\"",
")",
"\n",
"u",
".",
"RawQuery",
"=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"index",
"}",
",",
"\"",
"\"",
":",
"{",
"field",
"}",
",",
"\"",
"\"",
":",
"{",
"strconv",
".",
"FormatUint",
"(",
"shard",
",",
"10",
")",
"}",
",",
"}",
".",
"Encode",
"(",
")",
"\n\n",
"// Generate HTTP request.",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"u",
".",
"String",
"(",
")",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"pilosa",
".",
"Version",
")",
"\n\n",
"// Execute request against the host.",
"resp",
",",
"err",
":=",
"c",
".",
"executeRequest",
"(",
"req",
".",
"WithContext",
"(",
"ctx",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"// Copy body to writer.",
"if",
"_",
",",
"err",
":=",
"io",
".",
"Copy",
"(",
"w",
",",
"resp",
".",
"Body",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// exportNode copies a CSV export from a node to w.
|
[
"exportNode",
"copies",
"a",
"CSV",
"export",
"from",
"a",
"node",
"to",
"w",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L704-L737
|
train
|
pilosa/pilosa
|
http/client.go
|
CreateFieldWithOptions
|
func (c *InternalClient) CreateFieldWithOptions(ctx context.Context, index, field string, opt pilosa.FieldOptions) error {
span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.CreateFieldWithOptions")
defer span.Finish()
if index == "" {
return pilosa.ErrIndexRequired
}
// convert pilosa.FieldOptions to fieldOptions
fieldOpt := fieldOptions{
Type: opt.Type,
Keys: &opt.Keys,
}
if fieldOpt.Type == "set" {
fieldOpt.CacheType = &opt.CacheType
fieldOpt.CacheSize = &opt.CacheSize
} else if fieldOpt.Type == "int" {
fieldOpt.Min = &opt.Min
fieldOpt.Max = &opt.Max
} else if fieldOpt.Type == "time" {
fieldOpt.TimeQuantum = &opt.TimeQuantum
}
// TODO: remove buf completely? (depends on whether importer needs to create specific field types)
// Encode query request.
buf, err := json.Marshal(&postFieldRequest{
Options: fieldOpt,
})
if err != nil {
return errors.Wrap(err, "marshaling")
}
// Create URL & HTTP request.
u := uriPathToURL(c.defaultURI, fmt.Sprintf("/index/%s/field/%s", index, field))
req, err := http.NewRequest("POST", u.String(), bytes.NewReader(buf))
if err != nil {
return errors.Wrap(err, "creating request")
}
req.Header.Set("Content-Length", strconv.Itoa(len(buf)))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
// Execute request against the host.
resp, err := c.executeRequest(req.WithContext(ctx))
if err != nil {
if resp != nil && resp.StatusCode == http.StatusConflict {
return pilosa.ErrFieldExists
}
return err
}
return errors.Wrap(resp.Body.Close(), "closing response body")
}
|
go
|
func (c *InternalClient) CreateFieldWithOptions(ctx context.Context, index, field string, opt pilosa.FieldOptions) error {
span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.CreateFieldWithOptions")
defer span.Finish()
if index == "" {
return pilosa.ErrIndexRequired
}
// convert pilosa.FieldOptions to fieldOptions
fieldOpt := fieldOptions{
Type: opt.Type,
Keys: &opt.Keys,
}
if fieldOpt.Type == "set" {
fieldOpt.CacheType = &opt.CacheType
fieldOpt.CacheSize = &opt.CacheSize
} else if fieldOpt.Type == "int" {
fieldOpt.Min = &opt.Min
fieldOpt.Max = &opt.Max
} else if fieldOpt.Type == "time" {
fieldOpt.TimeQuantum = &opt.TimeQuantum
}
// TODO: remove buf completely? (depends on whether importer needs to create specific field types)
// Encode query request.
buf, err := json.Marshal(&postFieldRequest{
Options: fieldOpt,
})
if err != nil {
return errors.Wrap(err, "marshaling")
}
// Create URL & HTTP request.
u := uriPathToURL(c.defaultURI, fmt.Sprintf("/index/%s/field/%s", index, field))
req, err := http.NewRequest("POST", u.String(), bytes.NewReader(buf))
if err != nil {
return errors.Wrap(err, "creating request")
}
req.Header.Set("Content-Length", strconv.Itoa(len(buf)))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
// Execute request against the host.
resp, err := c.executeRequest(req.WithContext(ctx))
if err != nil {
if resp != nil && resp.StatusCode == http.StatusConflict {
return pilosa.ErrFieldExists
}
return err
}
return errors.Wrap(resp.Body.Close(), "closing response body")
}
|
[
"func",
"(",
"c",
"*",
"InternalClient",
")",
"CreateFieldWithOptions",
"(",
"ctx",
"context",
".",
"Context",
",",
"index",
",",
"field",
"string",
",",
"opt",
"pilosa",
".",
"FieldOptions",
")",
"error",
"{",
"span",
",",
"ctx",
":=",
"tracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"if",
"index",
"==",
"\"",
"\"",
"{",
"return",
"pilosa",
".",
"ErrIndexRequired",
"\n",
"}",
"\n\n",
"// convert pilosa.FieldOptions to fieldOptions",
"fieldOpt",
":=",
"fieldOptions",
"{",
"Type",
":",
"opt",
".",
"Type",
",",
"Keys",
":",
"&",
"opt",
".",
"Keys",
",",
"}",
"\n",
"if",
"fieldOpt",
".",
"Type",
"==",
"\"",
"\"",
"{",
"fieldOpt",
".",
"CacheType",
"=",
"&",
"opt",
".",
"CacheType",
"\n",
"fieldOpt",
".",
"CacheSize",
"=",
"&",
"opt",
".",
"CacheSize",
"\n",
"}",
"else",
"if",
"fieldOpt",
".",
"Type",
"==",
"\"",
"\"",
"{",
"fieldOpt",
".",
"Min",
"=",
"&",
"opt",
".",
"Min",
"\n",
"fieldOpt",
".",
"Max",
"=",
"&",
"opt",
".",
"Max",
"\n",
"}",
"else",
"if",
"fieldOpt",
".",
"Type",
"==",
"\"",
"\"",
"{",
"fieldOpt",
".",
"TimeQuantum",
"=",
"&",
"opt",
".",
"TimeQuantum",
"\n",
"}",
"\n\n",
"// TODO: remove buf completely? (depends on whether importer needs to create specific field types)",
"// Encode query request.",
"buf",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"&",
"postFieldRequest",
"{",
"Options",
":",
"fieldOpt",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Create URL & HTTP request.",
"u",
":=",
"uriPathToURL",
"(",
"c",
".",
"defaultURI",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"index",
",",
"field",
")",
")",
"\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"u",
".",
"String",
"(",
")",
",",
"bytes",
".",
"NewReader",
"(",
"buf",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"len",
"(",
"buf",
")",
")",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"pilosa",
".",
"Version",
")",
"\n\n",
"// Execute request against the host.",
"resp",
",",
"err",
":=",
"c",
".",
"executeRequest",
"(",
"req",
".",
"WithContext",
"(",
"ctx",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"resp",
"!=",
"nil",
"&&",
"resp",
".",
"StatusCode",
"==",
"http",
".",
"StatusConflict",
"{",
"return",
"pilosa",
".",
"ErrFieldExists",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"errors",
".",
"Wrap",
"(",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// CreateField creates a new field on the server.
|
[
"CreateField",
"creates",
"a",
"new",
"field",
"on",
"the",
"server",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L785-L838
|
train
|
pilosa/pilosa
|
http/client.go
|
FragmentBlocks
|
func (c *InternalClient) FragmentBlocks(ctx context.Context, uri *pilosa.URI, index, field, view string, shard uint64) ([]pilosa.FragmentBlock, error) {
span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.FragmentBlocks")
defer span.Finish()
if uri == nil {
uri = c.defaultURI
}
u := uriPathToURL(uri, "/internal/fragment/blocks")
u.RawQuery = url.Values{
"index": {index},
"field": {field},
"view": {view},
"shard": {strconv.FormatUint(shard, 10)},
}.Encode()
// Build request.
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
return nil, errors.Wrap(err, "creating request")
}
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
req.Header.Set("Accept", "application/json")
// Execute request.
resp, err := c.executeRequest(req.WithContext(ctx))
if err != nil {
// Return the appropriate error.
if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, pilosa.ErrFragmentNotFound
}
return nil, err
}
defer resp.Body.Close()
// Decode response object.
var rsp getFragmentBlocksResponse
if err := json.NewDecoder(resp.Body).Decode(&rsp); err != nil {
return nil, errors.Wrap(err, "decoding")
}
return rsp.Blocks, nil
}
|
go
|
func (c *InternalClient) FragmentBlocks(ctx context.Context, uri *pilosa.URI, index, field, view string, shard uint64) ([]pilosa.FragmentBlock, error) {
span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.FragmentBlocks")
defer span.Finish()
if uri == nil {
uri = c.defaultURI
}
u := uriPathToURL(uri, "/internal/fragment/blocks")
u.RawQuery = url.Values{
"index": {index},
"field": {field},
"view": {view},
"shard": {strconv.FormatUint(shard, 10)},
}.Encode()
// Build request.
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
return nil, errors.Wrap(err, "creating request")
}
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
req.Header.Set("Accept", "application/json")
// Execute request.
resp, err := c.executeRequest(req.WithContext(ctx))
if err != nil {
// Return the appropriate error.
if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, pilosa.ErrFragmentNotFound
}
return nil, err
}
defer resp.Body.Close()
// Decode response object.
var rsp getFragmentBlocksResponse
if err := json.NewDecoder(resp.Body).Decode(&rsp); err != nil {
return nil, errors.Wrap(err, "decoding")
}
return rsp.Blocks, nil
}
|
[
"func",
"(",
"c",
"*",
"InternalClient",
")",
"FragmentBlocks",
"(",
"ctx",
"context",
".",
"Context",
",",
"uri",
"*",
"pilosa",
".",
"URI",
",",
"index",
",",
"field",
",",
"view",
"string",
",",
"shard",
"uint64",
")",
"(",
"[",
"]",
"pilosa",
".",
"FragmentBlock",
",",
"error",
")",
"{",
"span",
",",
"ctx",
":=",
"tracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"if",
"uri",
"==",
"nil",
"{",
"uri",
"=",
"c",
".",
"defaultURI",
"\n",
"}",
"\n",
"u",
":=",
"uriPathToURL",
"(",
"uri",
",",
"\"",
"\"",
")",
"\n",
"u",
".",
"RawQuery",
"=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"index",
"}",
",",
"\"",
"\"",
":",
"{",
"field",
"}",
",",
"\"",
"\"",
":",
"{",
"view",
"}",
",",
"\"",
"\"",
":",
"{",
"strconv",
".",
"FormatUint",
"(",
"shard",
",",
"10",
")",
"}",
",",
"}",
".",
"Encode",
"(",
")",
"\n\n",
"// Build request.",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"u",
".",
"String",
"(",
")",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"pilosa",
".",
"Version",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n\n",
"// Execute request.",
"resp",
",",
"err",
":=",
"c",
".",
"executeRequest",
"(",
"req",
".",
"WithContext",
"(",
"ctx",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Return the appropriate error.",
"if",
"resp",
"!=",
"nil",
"&&",
"resp",
".",
"StatusCode",
"==",
"http",
".",
"StatusNotFound",
"{",
"return",
"nil",
",",
"pilosa",
".",
"ErrFragmentNotFound",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"// Decode response object.",
"var",
"rsp",
"getFragmentBlocksResponse",
"\n",
"if",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"resp",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"rsp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"rsp",
".",
"Blocks",
",",
"nil",
"\n",
"}"
] |
// FragmentBlocks returns a list of block checksums for a fragment on a host.
// Only returns blocks which contain data.
|
[
"FragmentBlocks",
"returns",
"a",
"list",
"of",
"block",
"checksums",
"for",
"a",
"fragment",
"on",
"a",
"host",
".",
"Only",
"returns",
"blocks",
"which",
"contain",
"data",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L842-L883
|
train
|
pilosa/pilosa
|
http/client.go
|
RowAttrDiff
|
func (c *InternalClient) RowAttrDiff(ctx context.Context, uri *pilosa.URI, index, field string, blks []pilosa.AttrBlock) (map[uint64]map[string]interface{}, error) {
span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.RowAttrDiff")
defer span.Finish()
if uri == nil {
uri = c.defaultURI
}
u := uriPathToURL(uri, fmt.Sprintf("/internal/index/%s/field/%s/attr/diff", index, field))
// Encode request.
buf, err := json.Marshal(postFieldAttrDiffRequest{Blocks: blks})
if err != nil {
return nil, errors.Wrap(err, "marshaling")
}
// Build request.
req, err := http.NewRequest("POST", u.String(), bytes.NewReader(buf))
if err != nil {
return nil, errors.Wrap(err, "creating request")
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
req.Header.Set("Accept", "application/json")
// Execute request.
resp, err := c.executeRequest(req.WithContext(ctx))
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, pilosa.ErrFieldNotFound
}
return nil, err
}
defer resp.Body.Close()
// Decode response object.
var rsp postFieldAttrDiffResponse
if err := json.NewDecoder(resp.Body).Decode(&rsp); err != nil {
return nil, errors.Wrap(err, "decoding")
}
return rsp.Attrs, nil
}
|
go
|
func (c *InternalClient) RowAttrDiff(ctx context.Context, uri *pilosa.URI, index, field string, blks []pilosa.AttrBlock) (map[uint64]map[string]interface{}, error) {
span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.RowAttrDiff")
defer span.Finish()
if uri == nil {
uri = c.defaultURI
}
u := uriPathToURL(uri, fmt.Sprintf("/internal/index/%s/field/%s/attr/diff", index, field))
// Encode request.
buf, err := json.Marshal(postFieldAttrDiffRequest{Blocks: blks})
if err != nil {
return nil, errors.Wrap(err, "marshaling")
}
// Build request.
req, err := http.NewRequest("POST", u.String(), bytes.NewReader(buf))
if err != nil {
return nil, errors.Wrap(err, "creating request")
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
req.Header.Set("Accept", "application/json")
// Execute request.
resp, err := c.executeRequest(req.WithContext(ctx))
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, pilosa.ErrFieldNotFound
}
return nil, err
}
defer resp.Body.Close()
// Decode response object.
var rsp postFieldAttrDiffResponse
if err := json.NewDecoder(resp.Body).Decode(&rsp); err != nil {
return nil, errors.Wrap(err, "decoding")
}
return rsp.Attrs, nil
}
|
[
"func",
"(",
"c",
"*",
"InternalClient",
")",
"RowAttrDiff",
"(",
"ctx",
"context",
".",
"Context",
",",
"uri",
"*",
"pilosa",
".",
"URI",
",",
"index",
",",
"field",
"string",
",",
"blks",
"[",
"]",
"pilosa",
".",
"AttrBlock",
")",
"(",
"map",
"[",
"uint64",
"]",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"span",
",",
"ctx",
":=",
"tracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"if",
"uri",
"==",
"nil",
"{",
"uri",
"=",
"c",
".",
"defaultURI",
"\n",
"}",
"\n",
"u",
":=",
"uriPathToURL",
"(",
"uri",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"index",
",",
"field",
")",
")",
"\n\n",
"// Encode request.",
"buf",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"postFieldAttrDiffRequest",
"{",
"Blocks",
":",
"blks",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Build request.",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"u",
".",
"String",
"(",
")",
",",
"bytes",
".",
"NewReader",
"(",
"buf",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"pilosa",
".",
"Version",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n\n",
"// Execute request.",
"resp",
",",
"err",
":=",
"c",
".",
"executeRequest",
"(",
"req",
".",
"WithContext",
"(",
"ctx",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"resp",
"!=",
"nil",
"&&",
"resp",
".",
"StatusCode",
"==",
"http",
".",
"StatusNotFound",
"{",
"return",
"nil",
",",
"pilosa",
".",
"ErrFieldNotFound",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"// Decode response object.",
"var",
"rsp",
"postFieldAttrDiffResponse",
"\n",
"if",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"resp",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"rsp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"rsp",
".",
"Attrs",
",",
"nil",
"\n",
"}"
] |
// RowAttrDiff returns data from differing blocks on a remote host.
|
[
"RowAttrDiff",
"returns",
"data",
"from",
"differing",
"blocks",
"on",
"a",
"remote",
"host",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L974-L1014
|
train
|
pilosa/pilosa
|
http/client.go
|
SendMessage
|
func (c *InternalClient) SendMessage(ctx context.Context, uri *pilosa.URI, msg []byte) error {
span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.SendMessage")
defer span.Finish()
u := uriPathToURL(uri, "/internal/cluster/message")
req, err := http.NewRequest("POST", u.String(), bytes.NewReader(msg))
if err != nil {
return errors.Wrap(err, "making new request")
}
req.Header.Set("Content-Type", "application/x-protobuf")
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
req.Header.Set("Accept", "application/json")
// Execute request.
resp, err := c.executeRequest(req.WithContext(ctx))
if err != nil {
return errors.Wrap(err, "executing request")
}
return errors.Wrap(resp.Body.Close(), "closing response body")
}
|
go
|
func (c *InternalClient) SendMessage(ctx context.Context, uri *pilosa.URI, msg []byte) error {
span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.SendMessage")
defer span.Finish()
u := uriPathToURL(uri, "/internal/cluster/message")
req, err := http.NewRequest("POST", u.String(), bytes.NewReader(msg))
if err != nil {
return errors.Wrap(err, "making new request")
}
req.Header.Set("Content-Type", "application/x-protobuf")
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
req.Header.Set("Accept", "application/json")
// Execute request.
resp, err := c.executeRequest(req.WithContext(ctx))
if err != nil {
return errors.Wrap(err, "executing request")
}
return errors.Wrap(resp.Body.Close(), "closing response body")
}
|
[
"func",
"(",
"c",
"*",
"InternalClient",
")",
"SendMessage",
"(",
"ctx",
"context",
".",
"Context",
",",
"uri",
"*",
"pilosa",
".",
"URI",
",",
"msg",
"[",
"]",
"byte",
")",
"error",
"{",
"span",
",",
"ctx",
":=",
"tracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"u",
":=",
"uriPathToURL",
"(",
"uri",
",",
"\"",
"\"",
")",
"\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"u",
".",
"String",
"(",
")",
",",
"bytes",
".",
"NewReader",
"(",
"msg",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"pilosa",
".",
"Version",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n\n",
"// Execute request.",
"resp",
",",
"err",
":=",
"c",
".",
"executeRequest",
"(",
"req",
".",
"WithContext",
"(",
"ctx",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Wrap",
"(",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// SendMessage posts a message synchronously.
|
[
"SendMessage",
"posts",
"a",
"message",
"synchronously",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L1017-L1036
|
train
|
pilosa/pilosa
|
http/client.go
|
executeRequest
|
func (c *InternalClient) executeRequest(req *http.Request) (*http.Response, error) {
tracing.GlobalTracer.InjectHTTPHeaders(req)
resp, err := c.httpClient.Do(req)
if err != nil {
if resp != nil {
resp.Body.Close()
}
return nil, errors.Wrap(err, "getting response")
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
defer resp.Body.Close()
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
return resp, errors.Wrapf(err, "bad status '%s' and err reading body", resp.Status)
}
var msg string
// try to decode a JSON response
var sr successResponse
if err = json.Unmarshal(buf, &sr); err == nil {
msg = sr.Error.Error()
} else {
msg = string(buf)
}
return resp, errors.Errorf("server error %s: '%s'", resp.Status, msg)
}
return resp, nil
}
|
go
|
func (c *InternalClient) executeRequest(req *http.Request) (*http.Response, error) {
tracing.GlobalTracer.InjectHTTPHeaders(req)
resp, err := c.httpClient.Do(req)
if err != nil {
if resp != nil {
resp.Body.Close()
}
return nil, errors.Wrap(err, "getting response")
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
defer resp.Body.Close()
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
return resp, errors.Wrapf(err, "bad status '%s' and err reading body", resp.Status)
}
var msg string
// try to decode a JSON response
var sr successResponse
if err = json.Unmarshal(buf, &sr); err == nil {
msg = sr.Error.Error()
} else {
msg = string(buf)
}
return resp, errors.Errorf("server error %s: '%s'", resp.Status, msg)
}
return resp, nil
}
|
[
"func",
"(",
"c",
"*",
"InternalClient",
")",
"executeRequest",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"tracing",
".",
"GlobalTracer",
".",
"InjectHTTPHeaders",
"(",
"req",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"httpClient",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"resp",
"!=",
"nil",
"{",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"resp",
".",
"StatusCode",
"<",
"200",
"||",
"resp",
".",
"StatusCode",
">=",
"300",
"{",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"resp",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"resp",
".",
"Status",
")",
"\n",
"}",
"\n",
"var",
"msg",
"string",
"\n",
"// try to decode a JSON response",
"var",
"sr",
"successResponse",
"\n",
"if",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"buf",
",",
"&",
"sr",
")",
";",
"err",
"==",
"nil",
"{",
"msg",
"=",
"sr",
".",
"Error",
".",
"Error",
"(",
")",
"\n",
"}",
"else",
"{",
"msg",
"=",
"string",
"(",
"buf",
")",
"\n",
"}",
"\n",
"return",
"resp",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"Status",
",",
"msg",
")",
"\n",
"}",
"\n",
"return",
"resp",
",",
"nil",
"\n",
"}"
] |
// executeRequest executes the given request and checks the Response. For
// responses with non-2XX status, the body is read and closed, and an error is
// returned. If the error is nil, the caller must ensure that the response body
// is closed.
|
[
"executeRequest",
"executes",
"the",
"given",
"request",
"and",
"checks",
"the",
"Response",
".",
"For",
"responses",
"with",
"non",
"-",
"2XX",
"status",
"the",
"body",
"is",
"read",
"and",
"closed",
"and",
"an",
"error",
"is",
"returned",
".",
"If",
"the",
"error",
"is",
"nil",
"the",
"caller",
"must",
"ensure",
"that",
"the",
"response",
"body",
"is",
"closed",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L1042-L1068
|
train
|
pilosa/pilosa
|
http/client.go
|
HasRowKeys
|
func (p Bits) HasRowKeys() bool {
for i := range p {
if p[i].RowKey != "" {
return true
}
}
return false
}
|
go
|
func (p Bits) HasRowKeys() bool {
for i := range p {
if p[i].RowKey != "" {
return true
}
}
return false
}
|
[
"func",
"(",
"p",
"Bits",
")",
"HasRowKeys",
"(",
")",
"bool",
"{",
"for",
"i",
":=",
"range",
"p",
"{",
"if",
"p",
"[",
"i",
"]",
".",
"RowKey",
"!=",
"\"",
"\"",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// HasRowKeys returns true if any values use a row key.
|
[
"HasRowKeys",
"returns",
"true",
"if",
"any",
"values",
"use",
"a",
"row",
"key",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L1087-L1094
|
train
|
pilosa/pilosa
|
http/client.go
|
RowIDs
|
func (p Bits) RowIDs() []uint64 {
if p.HasRowKeys() {
return nil
}
other := make([]uint64, len(p))
for i := range p {
other[i] = p[i].RowID
}
return other
}
|
go
|
func (p Bits) RowIDs() []uint64 {
if p.HasRowKeys() {
return nil
}
other := make([]uint64, len(p))
for i := range p {
other[i] = p[i].RowID
}
return other
}
|
[
"func",
"(",
"p",
"Bits",
")",
"RowIDs",
"(",
")",
"[",
"]",
"uint64",
"{",
"if",
"p",
".",
"HasRowKeys",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"other",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"len",
"(",
"p",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"p",
"{",
"other",
"[",
"i",
"]",
"=",
"p",
"[",
"i",
"]",
".",
"RowID",
"\n",
"}",
"\n",
"return",
"other",
"\n",
"}"
] |
// RowIDs returns a slice of all the row IDs.
|
[
"RowIDs",
"returns",
"a",
"slice",
"of",
"all",
"the",
"row",
"IDs",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L1107-L1116
|
train
|
pilosa/pilosa
|
http/client.go
|
ColumnIDs
|
func (p Bits) ColumnIDs() []uint64 {
if p.HasColumnKeys() {
return nil
}
other := make([]uint64, len(p))
for i := range p {
other[i] = p[i].ColumnID
}
return other
}
|
go
|
func (p Bits) ColumnIDs() []uint64 {
if p.HasColumnKeys() {
return nil
}
other := make([]uint64, len(p))
for i := range p {
other[i] = p[i].ColumnID
}
return other
}
|
[
"func",
"(",
"p",
"Bits",
")",
"ColumnIDs",
"(",
")",
"[",
"]",
"uint64",
"{",
"if",
"p",
".",
"HasColumnKeys",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"other",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"len",
"(",
"p",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"p",
"{",
"other",
"[",
"i",
"]",
"=",
"p",
"[",
"i",
"]",
".",
"ColumnID",
"\n",
"}",
"\n",
"return",
"other",
"\n",
"}"
] |
// ColumnIDs returns a slice of all the column IDs.
|
[
"ColumnIDs",
"returns",
"a",
"slice",
"of",
"all",
"the",
"column",
"IDs",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L1119-L1128
|
train
|
pilosa/pilosa
|
http/client.go
|
RowKeys
|
func (p Bits) RowKeys() []string {
if !p.HasRowKeys() {
return nil
}
other := make([]string, len(p))
for i := range p {
other[i] = p[i].RowKey
}
return other
}
|
go
|
func (p Bits) RowKeys() []string {
if !p.HasRowKeys() {
return nil
}
other := make([]string, len(p))
for i := range p {
other[i] = p[i].RowKey
}
return other
}
|
[
"func",
"(",
"p",
"Bits",
")",
"RowKeys",
"(",
")",
"[",
"]",
"string",
"{",
"if",
"!",
"p",
".",
"HasRowKeys",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"other",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"p",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"p",
"{",
"other",
"[",
"i",
"]",
"=",
"p",
"[",
"i",
"]",
".",
"RowKey",
"\n",
"}",
"\n",
"return",
"other",
"\n",
"}"
] |
// RowKeys returns a slice of all the row keys.
|
[
"RowKeys",
"returns",
"a",
"slice",
"of",
"all",
"the",
"row",
"keys",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L1131-L1140
|
train
|
pilosa/pilosa
|
http/client.go
|
Timestamps
|
func (p Bits) Timestamps() []int64 {
other := make([]int64, len(p))
for i := range p {
other[i] = p[i].Timestamp
}
return other
}
|
go
|
func (p Bits) Timestamps() []int64 {
other := make([]int64, len(p))
for i := range p {
other[i] = p[i].Timestamp
}
return other
}
|
[
"func",
"(",
"p",
"Bits",
")",
"Timestamps",
"(",
")",
"[",
"]",
"int64",
"{",
"other",
":=",
"make",
"(",
"[",
"]",
"int64",
",",
"len",
"(",
"p",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"p",
"{",
"other",
"[",
"i",
"]",
"=",
"p",
"[",
"i",
"]",
".",
"Timestamp",
"\n",
"}",
"\n",
"return",
"other",
"\n",
"}"
] |
// Timestamps returns a slice of all the timestamps.
|
[
"Timestamps",
"returns",
"a",
"slice",
"of",
"all",
"the",
"timestamps",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L1155-L1161
|
train
|
pilosa/pilosa
|
http/client.go
|
GroupByShard
|
func (p Bits) GroupByShard() map[uint64][]pilosa.Bit {
m := make(map[uint64][]pilosa.Bit)
for _, bit := range p {
shard := bit.ColumnID / pilosa.ShardWidth
m[shard] = append(m[shard], bit)
}
for shard, bits := range m {
sort.Sort(Bits(bits))
m[shard] = bits
}
return m
}
|
go
|
func (p Bits) GroupByShard() map[uint64][]pilosa.Bit {
m := make(map[uint64][]pilosa.Bit)
for _, bit := range p {
shard := bit.ColumnID / pilosa.ShardWidth
m[shard] = append(m[shard], bit)
}
for shard, bits := range m {
sort.Sort(Bits(bits))
m[shard] = bits
}
return m
}
|
[
"func",
"(",
"p",
"Bits",
")",
"GroupByShard",
"(",
")",
"map",
"[",
"uint64",
"]",
"[",
"]",
"pilosa",
".",
"Bit",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"uint64",
"]",
"[",
"]",
"pilosa",
".",
"Bit",
")",
"\n",
"for",
"_",
",",
"bit",
":=",
"range",
"p",
"{",
"shard",
":=",
"bit",
".",
"ColumnID",
"/",
"pilosa",
".",
"ShardWidth",
"\n",
"m",
"[",
"shard",
"]",
"=",
"append",
"(",
"m",
"[",
"shard",
"]",
",",
"bit",
")",
"\n",
"}",
"\n\n",
"for",
"shard",
",",
"bits",
":=",
"range",
"m",
"{",
"sort",
".",
"Sort",
"(",
"Bits",
"(",
"bits",
")",
")",
"\n",
"m",
"[",
"shard",
"]",
"=",
"bits",
"\n",
"}",
"\n\n",
"return",
"m",
"\n",
"}"
] |
// GroupByShard returns a map of bits by shard.
|
[
"GroupByShard",
"returns",
"a",
"map",
"of",
"bits",
"by",
"shard",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L1164-L1177
|
train
|
pilosa/pilosa
|
http/client.go
|
ColumnKeys
|
func (p FieldValues) ColumnKeys() []string {
if !p.HasColumnKeys() {
return nil
}
other := make([]string, len(p))
for i := range p {
other[i] = p[i].ColumnKey
}
return other
}
|
go
|
func (p FieldValues) ColumnKeys() []string {
if !p.HasColumnKeys() {
return nil
}
other := make([]string, len(p))
for i := range p {
other[i] = p[i].ColumnKey
}
return other
}
|
[
"func",
"(",
"p",
"FieldValues",
")",
"ColumnKeys",
"(",
")",
"[",
"]",
"string",
"{",
"if",
"!",
"p",
".",
"HasColumnKeys",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"other",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"p",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"p",
"{",
"other",
"[",
"i",
"]",
"=",
"p",
"[",
"i",
"]",
".",
"ColumnKey",
"\n",
"}",
"\n",
"return",
"other",
"\n",
"}"
] |
// ColumnKeys returns a slice of all the column keys.
|
[
"ColumnKeys",
"returns",
"a",
"slice",
"of",
"all",
"the",
"column",
"keys",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L1212-L1221
|
train
|
pilosa/pilosa
|
http/client.go
|
Values
|
func (p FieldValues) Values() []int64 {
other := make([]int64, len(p))
for i := range p {
other[i] = p[i].Value
}
return other
}
|
go
|
func (p FieldValues) Values() []int64 {
other := make([]int64, len(p))
for i := range p {
other[i] = p[i].Value
}
return other
}
|
[
"func",
"(",
"p",
"FieldValues",
")",
"Values",
"(",
")",
"[",
"]",
"int64",
"{",
"other",
":=",
"make",
"(",
"[",
"]",
"int64",
",",
"len",
"(",
"p",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"p",
"{",
"other",
"[",
"i",
"]",
"=",
"p",
"[",
"i",
"]",
".",
"Value",
"\n",
"}",
"\n",
"return",
"other",
"\n",
"}"
] |
// Values returns a slice of all the values.
|
[
"Values",
"returns",
"a",
"slice",
"of",
"all",
"the",
"values",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L1224-L1230
|
train
|
pilosa/pilosa
|
http/client.go
|
GroupByShard
|
func (p FieldValues) GroupByShard() map[uint64][]pilosa.FieldValue {
m := make(map[uint64][]pilosa.FieldValue)
for _, val := range p {
shard := val.ColumnID / pilosa.ShardWidth
m[shard] = append(m[shard], val)
}
for shard, vals := range m {
sort.Sort(FieldValues(vals))
m[shard] = vals
}
return m
}
|
go
|
func (p FieldValues) GroupByShard() map[uint64][]pilosa.FieldValue {
m := make(map[uint64][]pilosa.FieldValue)
for _, val := range p {
shard := val.ColumnID / pilosa.ShardWidth
m[shard] = append(m[shard], val)
}
for shard, vals := range m {
sort.Sort(FieldValues(vals))
m[shard] = vals
}
return m
}
|
[
"func",
"(",
"p",
"FieldValues",
")",
"GroupByShard",
"(",
")",
"map",
"[",
"uint64",
"]",
"[",
"]",
"pilosa",
".",
"FieldValue",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"uint64",
"]",
"[",
"]",
"pilosa",
".",
"FieldValue",
")",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"p",
"{",
"shard",
":=",
"val",
".",
"ColumnID",
"/",
"pilosa",
".",
"ShardWidth",
"\n",
"m",
"[",
"shard",
"]",
"=",
"append",
"(",
"m",
"[",
"shard",
"]",
",",
"val",
")",
"\n",
"}",
"\n\n",
"for",
"shard",
",",
"vals",
":=",
"range",
"m",
"{",
"sort",
".",
"Sort",
"(",
"FieldValues",
"(",
"vals",
")",
")",
"\n",
"m",
"[",
"shard",
"]",
"=",
"vals",
"\n",
"}",
"\n\n",
"return",
"m",
"\n",
"}"
] |
// GroupByShard returns a map of field values by shard.
|
[
"GroupByShard",
"returns",
"a",
"map",
"of",
"field",
"values",
"by",
"shard",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L1233-L1246
|
train
|
pilosa/pilosa
|
syswrap/os.go
|
OpenFile
|
func OpenFile(name string, flag int, perm os.FileMode) (file *os.File, mustClose bool, err error) {
file, err = os.OpenFile(name, flag, perm)
fileMu.RLock()
defer fileMu.RUnlock()
if newCount := atomic.AddUint64(&fileCount, 1); newCount > maxFileCount {
mustClose = true
}
return file, mustClose, err
}
|
go
|
func OpenFile(name string, flag int, perm os.FileMode) (file *os.File, mustClose bool, err error) {
file, err = os.OpenFile(name, flag, perm)
fileMu.RLock()
defer fileMu.RUnlock()
if newCount := atomic.AddUint64(&fileCount, 1); newCount > maxFileCount {
mustClose = true
}
return file, mustClose, err
}
|
[
"func",
"OpenFile",
"(",
"name",
"string",
",",
"flag",
"int",
",",
"perm",
"os",
".",
"FileMode",
")",
"(",
"file",
"*",
"os",
".",
"File",
",",
"mustClose",
"bool",
",",
"err",
"error",
")",
"{",
"file",
",",
"err",
"=",
"os",
".",
"OpenFile",
"(",
"name",
",",
"flag",
",",
"perm",
")",
"\n",
"fileMu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"fileMu",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"newCount",
":=",
"atomic",
".",
"AddUint64",
"(",
"&",
"fileCount",
",",
"1",
")",
";",
"newCount",
">",
"maxFileCount",
"{",
"mustClose",
"=",
"true",
"\n",
"}",
"\n",
"return",
"file",
",",
"mustClose",
",",
"err",
"\n",
"}"
] |
// OpenFile passes the arguments along to os.OpenFile while incrementing a
// counter. If the counter is above the maximum, it returns mustClose true to
// signal the calling function that it should not keep the file open
// indefinitely. Files opened with this function should be closed by
// syswrap.CloseFile.
|
[
"OpenFile",
"passes",
"the",
"arguments",
"along",
"to",
"os",
".",
"OpenFile",
"while",
"incrementing",
"a",
"counter",
".",
"If",
"the",
"counter",
"is",
"above",
"the",
"maximum",
"it",
"returns",
"mustClose",
"true",
"to",
"signal",
"the",
"calling",
"function",
"that",
"it",
"should",
"not",
"keep",
"the",
"file",
"open",
"indefinitely",
".",
"Files",
"opened",
"with",
"this",
"function",
"should",
"be",
"closed",
"by",
"syswrap",
".",
"CloseFile",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/syswrap/os.go#L41-L49
|
train
|
pilosa/pilosa
|
syswrap/os.go
|
CloseFile
|
func CloseFile(f *os.File) error {
atomic.AddUint64(&fileCount, ^uint64(0)) // decrement
return f.Close()
}
|
go
|
func CloseFile(f *os.File) error {
atomic.AddUint64(&fileCount, ^uint64(0)) // decrement
return f.Close()
}
|
[
"func",
"CloseFile",
"(",
"f",
"*",
"os",
".",
"File",
")",
"error",
"{",
"atomic",
".",
"AddUint64",
"(",
"&",
"fileCount",
",",
"^",
"uint64",
"(",
"0",
")",
")",
"// decrement",
"\n",
"return",
"f",
".",
"Close",
"(",
")",
"\n",
"}"
] |
// CloseFile decrements the global count of open files and closes the file.
|
[
"CloseFile",
"decrements",
"the",
"global",
"count",
"of",
"open",
"files",
"and",
"closes",
"the",
"file",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/syswrap/os.go#L52-L55
|
train
|
pilosa/pilosa
|
syswrap/mmap.go
|
Mmap
|
func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
mu.RLock()
defer mu.RUnlock()
if newCount := atomic.AddUint64(&mapCount, 1); newCount > maxMapCount {
atomic.AddUint64(&mapCount, ^uint64(0)) // decrement
return nil, ErrMaxMapCountReached
}
data, err = syscall.Mmap(fd, offset, length, prot, flags)
if err != nil {
atomic.AddUint64(&mapCount, ^uint64(0)) // decrement
}
return data, err
}
|
go
|
func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
mu.RLock()
defer mu.RUnlock()
if newCount := atomic.AddUint64(&mapCount, 1); newCount > maxMapCount {
atomic.AddUint64(&mapCount, ^uint64(0)) // decrement
return nil, ErrMaxMapCountReached
}
data, err = syscall.Mmap(fd, offset, length, prot, flags)
if err != nil {
atomic.AddUint64(&mapCount, ^uint64(0)) // decrement
}
return data, err
}
|
[
"func",
"Mmap",
"(",
"fd",
"int",
",",
"offset",
"int64",
",",
"length",
"int",
",",
"prot",
"int",
",",
"flags",
"int",
")",
"(",
"data",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"newCount",
":=",
"atomic",
".",
"AddUint64",
"(",
"&",
"mapCount",
",",
"1",
")",
";",
"newCount",
">",
"maxMapCount",
"{",
"atomic",
".",
"AddUint64",
"(",
"&",
"mapCount",
",",
"^",
"uint64",
"(",
"0",
")",
")",
"// decrement",
"\n",
"return",
"nil",
",",
"ErrMaxMapCountReached",
"\n",
"}",
"\n",
"data",
",",
"err",
"=",
"syscall",
".",
"Mmap",
"(",
"fd",
",",
"offset",
",",
"length",
",",
"prot",
",",
"flags",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"atomic",
".",
"AddUint64",
"(",
"&",
"mapCount",
",",
"^",
"uint64",
"(",
"0",
")",
")",
"// decrement",
"\n",
"}",
"\n",
"return",
"data",
",",
"err",
"\n",
"}"
] |
// Mmap increments the global map count, and then calls syscall.Mmap. It
// decrements the map count and returns an error if the count was over the
// limit. If syscall.Mmap returns an error it also decrements the count.
|
[
"Mmap",
"increments",
"the",
"global",
"map",
"count",
"and",
"then",
"calls",
"syscall",
".",
"Mmap",
".",
"It",
"decrements",
"the",
"map",
"count",
"and",
"returns",
"an",
"error",
"if",
"the",
"count",
"was",
"over",
"the",
"limit",
".",
"If",
"syscall",
".",
"Mmap",
"returns",
"an",
"error",
"it",
"also",
"decrements",
"the",
"count",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/syswrap/mmap.go#L46-L58
|
train
|
pilosa/pilosa
|
syswrap/mmap.go
|
Munmap
|
func Munmap(b []byte) (err error) {
err = syscall.Munmap(b)
if err == nil {
atomic.AddUint64(&mapCount, ^uint64(0)) // decrement
}
return err
}
|
go
|
func Munmap(b []byte) (err error) {
err = syscall.Munmap(b)
if err == nil {
atomic.AddUint64(&mapCount, ^uint64(0)) // decrement
}
return err
}
|
[
"func",
"Munmap",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"err",
"=",
"syscall",
".",
"Munmap",
"(",
"b",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"atomic",
".",
"AddUint64",
"(",
"&",
"mapCount",
",",
"^",
"uint64",
"(",
"0",
")",
")",
"// decrement",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// Munmap calls sycall.Munmap, and then decrements the global map count if there
// was no error.
|
[
"Munmap",
"calls",
"sycall",
".",
"Munmap",
"and",
"then",
"decrements",
"the",
"global",
"map",
"count",
"if",
"there",
"was",
"no",
"error",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/syswrap/mmap.go#L62-L68
|
train
|
pilosa/pilosa
|
time.go
|
Set
|
func (q *TimeQuantum) Set(value string) error {
*q = TimeQuantum(value)
return nil
}
|
go
|
func (q *TimeQuantum) Set(value string) error {
*q = TimeQuantum(value)
return nil
}
|
[
"func",
"(",
"q",
"*",
"TimeQuantum",
")",
"Set",
"(",
"value",
"string",
")",
"error",
"{",
"*",
"q",
"=",
"TimeQuantum",
"(",
"value",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// The following methods are required to implement pflag Value interface.
// Set sets the time quantum value.
|
[
"The",
"following",
"methods",
"are",
"required",
"to",
"implement",
"pflag",
"Value",
"interface",
".",
"Set",
"sets",
"the",
"time",
"quantum",
"value",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/time.go#L60-L63
|
train
|
pilosa/pilosa
|
time.go
|
viewByTimeUnit
|
func viewByTimeUnit(name string, t time.Time, unit rune) string {
switch unit {
case 'Y':
return fmt.Sprintf("%s_%s", name, t.Format("2006"))
case 'M':
return fmt.Sprintf("%s_%s", name, t.Format("200601"))
case 'D':
return fmt.Sprintf("%s_%s", name, t.Format("20060102"))
case 'H':
return fmt.Sprintf("%s_%s", name, t.Format("2006010215"))
default:
return ""
}
}
|
go
|
func viewByTimeUnit(name string, t time.Time, unit rune) string {
switch unit {
case 'Y':
return fmt.Sprintf("%s_%s", name, t.Format("2006"))
case 'M':
return fmt.Sprintf("%s_%s", name, t.Format("200601"))
case 'D':
return fmt.Sprintf("%s_%s", name, t.Format("20060102"))
case 'H':
return fmt.Sprintf("%s_%s", name, t.Format("2006010215"))
default:
return ""
}
}
|
[
"func",
"viewByTimeUnit",
"(",
"name",
"string",
",",
"t",
"time",
".",
"Time",
",",
"unit",
"rune",
")",
"string",
"{",
"switch",
"unit",
"{",
"case",
"'Y'",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
",",
"t",
".",
"Format",
"(",
"\"",
"\"",
")",
")",
"\n",
"case",
"'M'",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
",",
"t",
".",
"Format",
"(",
"\"",
"\"",
")",
")",
"\n",
"case",
"'D'",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
",",
"t",
".",
"Format",
"(",
"\"",
"\"",
")",
")",
"\n",
"case",
"'H'",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
",",
"t",
".",
"Format",
"(",
"\"",
"\"",
")",
")",
"\n",
"default",
":",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"}"
] |
// viewByTimeUnit returns the view name for time with a given quantum unit.
|
[
"viewByTimeUnit",
"returns",
"the",
"view",
"name",
"for",
"time",
"with",
"a",
"given",
"quantum",
"unit",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/time.go#L75-L88
|
train
|
pilosa/pilosa
|
time.go
|
viewsByTime
|
func viewsByTime(name string, t time.Time, q TimeQuantum) []string { // nolint: unparam
a := make([]string, 0, len(q))
for _, unit := range q {
view := viewByTimeUnit(name, t, unit)
if view == "" {
continue
}
a = append(a, view)
}
return a
}
|
go
|
func viewsByTime(name string, t time.Time, q TimeQuantum) []string { // nolint: unparam
a := make([]string, 0, len(q))
for _, unit := range q {
view := viewByTimeUnit(name, t, unit)
if view == "" {
continue
}
a = append(a, view)
}
return a
}
|
[
"func",
"viewsByTime",
"(",
"name",
"string",
",",
"t",
"time",
".",
"Time",
",",
"q",
"TimeQuantum",
")",
"[",
"]",
"string",
"{",
"// nolint: unparam",
"a",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"q",
")",
")",
"\n",
"for",
"_",
",",
"unit",
":=",
"range",
"q",
"{",
"view",
":=",
"viewByTimeUnit",
"(",
"name",
",",
"t",
",",
"unit",
")",
"\n",
"if",
"view",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n",
"a",
"=",
"append",
"(",
"a",
",",
"view",
")",
"\n",
"}",
"\n",
"return",
"a",
"\n",
"}"
] |
// viewsByTime returns a list of views for a given timestamp.
|
[
"viewsByTime",
"returns",
"a",
"list",
"of",
"views",
"for",
"a",
"given",
"timestamp",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/time.go#L91-L101
|
train
|
pilosa/pilosa
|
time.go
|
viewsByTimeRange
|
func viewsByTimeRange(name string, start, end time.Time, q TimeQuantum) []string { // nolint: unparam
t := start
// Save flags for performance.
hasYear := q.HasYear()
hasMonth := q.HasMonth()
hasDay := q.HasDay()
hasHour := q.HasHour()
var results []string
// Walk up from smallest units to largest units.
if hasHour || hasDay || hasMonth {
for t.Before(end) {
if hasHour {
if !nextDayGTE(t, end) {
break
} else if t.Hour() != 0 {
results = append(results, viewByTimeUnit(name, t, 'H'))
t = t.Add(time.Hour)
continue
}
}
if hasDay {
if !nextMonthGTE(t, end) {
break
} else if t.Day() != 1 {
results = append(results, viewByTimeUnit(name, t, 'D'))
t = t.AddDate(0, 0, 1)
continue
}
}
if hasMonth {
if !nextYearGTE(t, end) {
break
} else if t.Month() != 1 {
results = append(results, viewByTimeUnit(name, t, 'M'))
t = addMonth(t)
continue
}
}
// If a unit exists but isn't set and there are no larger units
// available then we need to exit the loop because we are no longer
// making progress.
break
}
}
// Walk back down from largest units to smallest units.
for t.Before(end) {
if hasYear && nextYearGTE(t, end) {
results = append(results, viewByTimeUnit(name, t, 'Y'))
t = t.AddDate(1, 0, 0)
} else if hasMonth && nextMonthGTE(t, end) {
results = append(results, viewByTimeUnit(name, t, 'M'))
t = addMonth(t)
} else if hasDay && nextDayGTE(t, end) {
results = append(results, viewByTimeUnit(name, t, 'D'))
t = t.AddDate(0, 0, 1)
} else if hasHour {
results = append(results, viewByTimeUnit(name, t, 'H'))
t = t.Add(time.Hour)
} else {
break
}
}
return results
}
|
go
|
func viewsByTimeRange(name string, start, end time.Time, q TimeQuantum) []string { // nolint: unparam
t := start
// Save flags for performance.
hasYear := q.HasYear()
hasMonth := q.HasMonth()
hasDay := q.HasDay()
hasHour := q.HasHour()
var results []string
// Walk up from smallest units to largest units.
if hasHour || hasDay || hasMonth {
for t.Before(end) {
if hasHour {
if !nextDayGTE(t, end) {
break
} else if t.Hour() != 0 {
results = append(results, viewByTimeUnit(name, t, 'H'))
t = t.Add(time.Hour)
continue
}
}
if hasDay {
if !nextMonthGTE(t, end) {
break
} else if t.Day() != 1 {
results = append(results, viewByTimeUnit(name, t, 'D'))
t = t.AddDate(0, 0, 1)
continue
}
}
if hasMonth {
if !nextYearGTE(t, end) {
break
} else if t.Month() != 1 {
results = append(results, viewByTimeUnit(name, t, 'M'))
t = addMonth(t)
continue
}
}
// If a unit exists but isn't set and there are no larger units
// available then we need to exit the loop because we are no longer
// making progress.
break
}
}
// Walk back down from largest units to smallest units.
for t.Before(end) {
if hasYear && nextYearGTE(t, end) {
results = append(results, viewByTimeUnit(name, t, 'Y'))
t = t.AddDate(1, 0, 0)
} else if hasMonth && nextMonthGTE(t, end) {
results = append(results, viewByTimeUnit(name, t, 'M'))
t = addMonth(t)
} else if hasDay && nextDayGTE(t, end) {
results = append(results, viewByTimeUnit(name, t, 'D'))
t = t.AddDate(0, 0, 1)
} else if hasHour {
results = append(results, viewByTimeUnit(name, t, 'H'))
t = t.Add(time.Hour)
} else {
break
}
}
return results
}
|
[
"func",
"viewsByTimeRange",
"(",
"name",
"string",
",",
"start",
",",
"end",
"time",
".",
"Time",
",",
"q",
"TimeQuantum",
")",
"[",
"]",
"string",
"{",
"// nolint: unparam",
"t",
":=",
"start",
"\n\n",
"// Save flags for performance.",
"hasYear",
":=",
"q",
".",
"HasYear",
"(",
")",
"\n",
"hasMonth",
":=",
"q",
".",
"HasMonth",
"(",
")",
"\n",
"hasDay",
":=",
"q",
".",
"HasDay",
"(",
")",
"\n",
"hasHour",
":=",
"q",
".",
"HasHour",
"(",
")",
"\n\n",
"var",
"results",
"[",
"]",
"string",
"\n\n",
"// Walk up from smallest units to largest units.",
"if",
"hasHour",
"||",
"hasDay",
"||",
"hasMonth",
"{",
"for",
"t",
".",
"Before",
"(",
"end",
")",
"{",
"if",
"hasHour",
"{",
"if",
"!",
"nextDayGTE",
"(",
"t",
",",
"end",
")",
"{",
"break",
"\n",
"}",
"else",
"if",
"t",
".",
"Hour",
"(",
")",
"!=",
"0",
"{",
"results",
"=",
"append",
"(",
"results",
",",
"viewByTimeUnit",
"(",
"name",
",",
"t",
",",
"'H'",
")",
")",
"\n",
"t",
"=",
"t",
".",
"Add",
"(",
"time",
".",
"Hour",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"}",
"\n\n",
"if",
"hasDay",
"{",
"if",
"!",
"nextMonthGTE",
"(",
"t",
",",
"end",
")",
"{",
"break",
"\n",
"}",
"else",
"if",
"t",
".",
"Day",
"(",
")",
"!=",
"1",
"{",
"results",
"=",
"append",
"(",
"results",
",",
"viewByTimeUnit",
"(",
"name",
",",
"t",
",",
"'D'",
")",
")",
"\n",
"t",
"=",
"t",
".",
"AddDate",
"(",
"0",
",",
"0",
",",
"1",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"hasMonth",
"{",
"if",
"!",
"nextYearGTE",
"(",
"t",
",",
"end",
")",
"{",
"break",
"\n",
"}",
"else",
"if",
"t",
".",
"Month",
"(",
")",
"!=",
"1",
"{",
"results",
"=",
"append",
"(",
"results",
",",
"viewByTimeUnit",
"(",
"name",
",",
"t",
",",
"'M'",
")",
")",
"\n",
"t",
"=",
"addMonth",
"(",
"t",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n\n",
"// If a unit exists but isn't set and there are no larger units",
"// available then we need to exit the loop because we are no longer",
"// making progress.",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Walk back down from largest units to smallest units.",
"for",
"t",
".",
"Before",
"(",
"end",
")",
"{",
"if",
"hasYear",
"&&",
"nextYearGTE",
"(",
"t",
",",
"end",
")",
"{",
"results",
"=",
"append",
"(",
"results",
",",
"viewByTimeUnit",
"(",
"name",
",",
"t",
",",
"'Y'",
")",
")",
"\n",
"t",
"=",
"t",
".",
"AddDate",
"(",
"1",
",",
"0",
",",
"0",
")",
"\n",
"}",
"else",
"if",
"hasMonth",
"&&",
"nextMonthGTE",
"(",
"t",
",",
"end",
")",
"{",
"results",
"=",
"append",
"(",
"results",
",",
"viewByTimeUnit",
"(",
"name",
",",
"t",
",",
"'M'",
")",
")",
"\n",
"t",
"=",
"addMonth",
"(",
"t",
")",
"\n",
"}",
"else",
"if",
"hasDay",
"&&",
"nextDayGTE",
"(",
"t",
",",
"end",
")",
"{",
"results",
"=",
"append",
"(",
"results",
",",
"viewByTimeUnit",
"(",
"name",
",",
"t",
",",
"'D'",
")",
")",
"\n",
"t",
"=",
"t",
".",
"AddDate",
"(",
"0",
",",
"0",
",",
"1",
")",
"\n",
"}",
"else",
"if",
"hasHour",
"{",
"results",
"=",
"append",
"(",
"results",
",",
"viewByTimeUnit",
"(",
"name",
",",
"t",
",",
"'H'",
")",
")",
"\n",
"t",
"=",
"t",
".",
"Add",
"(",
"time",
".",
"Hour",
")",
"\n",
"}",
"else",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"results",
"\n",
"}"
] |
// viewsByTimeRange returns a list of views to traverse to query a time range.
|
[
"viewsByTimeRange",
"returns",
"a",
"list",
"of",
"views",
"to",
"traverse",
"to",
"query",
"a",
"time",
"range",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/time.go#L104-L176
|
train
|
pilosa/pilosa
|
time.go
|
parseTime
|
func parseTime(t interface{}) (time.Time, error) {
var err error
var calcTime time.Time
switch v := t.(type) {
case string:
if calcTime, err = time.Parse(TimeFormat, v); err != nil {
return time.Time{}, errors.New("cannot parse string time")
}
case int64:
calcTime = time.Unix(v, 0).UTC()
default:
return time.Time{}, errors.New("arg must be a timestamp")
}
return calcTime, nil
}
|
go
|
func parseTime(t interface{}) (time.Time, error) {
var err error
var calcTime time.Time
switch v := t.(type) {
case string:
if calcTime, err = time.Parse(TimeFormat, v); err != nil {
return time.Time{}, errors.New("cannot parse string time")
}
case int64:
calcTime = time.Unix(v, 0).UTC()
default:
return time.Time{}, errors.New("arg must be a timestamp")
}
return calcTime, nil
}
|
[
"func",
"parseTime",
"(",
"t",
"interface",
"{",
"}",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"calcTime",
"time",
".",
"Time",
"\n",
"switch",
"v",
":=",
"t",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"if",
"calcTime",
",",
"err",
"=",
"time",
".",
"Parse",
"(",
"TimeFormat",
",",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"case",
"int64",
":",
"calcTime",
"=",
"time",
".",
"Unix",
"(",
"v",
",",
"0",
")",
".",
"UTC",
"(",
")",
"\n",
"default",
":",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"calcTime",
",",
"nil",
"\n",
"}"
] |
// parseTime parses a string or int64 into a time.Time value.
|
[
"parseTime",
"parses",
"a",
"string",
"or",
"int64",
"into",
"a",
"time",
".",
"Time",
"value",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/time.go#L220-L234
|
train
|
pilosa/pilosa
|
time.go
|
timeOfView
|
func timeOfView(v string, adj bool) (time.Time, error) {
if v == "" {
return time.Time{}, nil
}
layout := "2006010203"
timePart := viewTimePart(v)
switch len(timePart) {
case 4: // year
t, err := time.Parse(layout[:4], timePart)
if err != nil {
return time.Time{}, err
}
if adj {
t = t.AddDate(1, 0, 0)
}
return t, nil
case 6: // month
t, err := time.Parse(layout[:6], timePart)
if err != nil {
return time.Time{}, err
}
if adj {
t = addMonth(t)
}
return t, nil
case 8: // day
t, err := time.Parse(layout[:8], timePart)
if err != nil {
return time.Time{}, err
}
if adj {
t = t.AddDate(0, 0, 1)
}
return t, nil
case 10: // hour
t, err := time.Parse(layout[:10], timePart)
if err != nil {
return time.Time{}, err
}
if adj {
t = t.Add(time.Hour)
}
return t, nil
}
return time.Time{}, fmt.Errorf("invalid time format on view: %s", v)
}
|
go
|
func timeOfView(v string, adj bool) (time.Time, error) {
if v == "" {
return time.Time{}, nil
}
layout := "2006010203"
timePart := viewTimePart(v)
switch len(timePart) {
case 4: // year
t, err := time.Parse(layout[:4], timePart)
if err != nil {
return time.Time{}, err
}
if adj {
t = t.AddDate(1, 0, 0)
}
return t, nil
case 6: // month
t, err := time.Parse(layout[:6], timePart)
if err != nil {
return time.Time{}, err
}
if adj {
t = addMonth(t)
}
return t, nil
case 8: // day
t, err := time.Parse(layout[:8], timePart)
if err != nil {
return time.Time{}, err
}
if adj {
t = t.AddDate(0, 0, 1)
}
return t, nil
case 10: // hour
t, err := time.Parse(layout[:10], timePart)
if err != nil {
return time.Time{}, err
}
if adj {
t = t.Add(time.Hour)
}
return t, nil
}
return time.Time{}, fmt.Errorf("invalid time format on view: %s", v)
}
|
[
"func",
"timeOfView",
"(",
"v",
"string",
",",
"adj",
"bool",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"if",
"v",
"==",
"\"",
"\"",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"layout",
":=",
"\"",
"\"",
"\n",
"timePart",
":=",
"viewTimePart",
"(",
"v",
")",
"\n\n",
"switch",
"len",
"(",
"timePart",
")",
"{",
"case",
"4",
":",
"// year",
"t",
",",
"err",
":=",
"time",
".",
"Parse",
"(",
"layout",
"[",
":",
"4",
"]",
",",
"timePart",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"if",
"adj",
"{",
"t",
"=",
"t",
".",
"AddDate",
"(",
"1",
",",
"0",
",",
"0",
")",
"\n",
"}",
"\n",
"return",
"t",
",",
"nil",
"\n",
"case",
"6",
":",
"// month",
"t",
",",
"err",
":=",
"time",
".",
"Parse",
"(",
"layout",
"[",
":",
"6",
"]",
",",
"timePart",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"if",
"adj",
"{",
"t",
"=",
"addMonth",
"(",
"t",
")",
"\n",
"}",
"\n",
"return",
"t",
",",
"nil",
"\n",
"case",
"8",
":",
"// day",
"t",
",",
"err",
":=",
"time",
".",
"Parse",
"(",
"layout",
"[",
":",
"8",
"]",
",",
"timePart",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"if",
"adj",
"{",
"t",
"=",
"t",
".",
"AddDate",
"(",
"0",
",",
"0",
",",
"1",
")",
"\n",
"}",
"\n",
"return",
"t",
",",
"nil",
"\n",
"case",
"10",
":",
"// hour",
"t",
",",
"err",
":=",
"time",
".",
"Parse",
"(",
"layout",
"[",
":",
"10",
"]",
",",
"timePart",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"if",
"adj",
"{",
"t",
"=",
"t",
".",
"Add",
"(",
"time",
".",
"Hour",
")",
"\n",
"}",
"\n",
"return",
"t",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}"
] |
// timeOfView returns a valid time.Time based on the view string.
// For upper bound use, the result can be adjusted by one by setting
// the `adj` argument to `true`.
|
[
"timeOfView",
"returns",
"a",
"valid",
"time",
".",
"Time",
"based",
"on",
"the",
"view",
"string",
".",
"For",
"upper",
"bound",
"use",
"the",
"result",
"can",
"be",
"adjusted",
"by",
"one",
"by",
"setting",
"the",
"adj",
"argument",
"to",
"true",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/time.go#L279-L327
|
train
|
pilosa/pilosa
|
cmd.go
|
NewCmdIO
|
func NewCmdIO(stdin io.Reader, stdout, stderr io.Writer) *CmdIO {
return &CmdIO{
Stdin: stdin,
Stdout: stdout,
Stderr: stderr,
}
}
|
go
|
func NewCmdIO(stdin io.Reader, stdout, stderr io.Writer) *CmdIO {
return &CmdIO{
Stdin: stdin,
Stdout: stdout,
Stderr: stderr,
}
}
|
[
"func",
"NewCmdIO",
"(",
"stdin",
"io",
".",
"Reader",
",",
"stdout",
",",
"stderr",
"io",
".",
"Writer",
")",
"*",
"CmdIO",
"{",
"return",
"&",
"CmdIO",
"{",
"Stdin",
":",
"stdin",
",",
"Stdout",
":",
"stdout",
",",
"Stderr",
":",
"stderr",
",",
"}",
"\n",
"}"
] |
// NewCmdIO returns a new instance of CmdIO with inputs and outputs set to the
// arguments.
|
[
"NewCmdIO",
"returns",
"a",
"new",
"instance",
"of",
"CmdIO",
"with",
"inputs",
"and",
"outputs",
"set",
"to",
"the",
"arguments",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cmd.go#L28-L34
|
train
|
pilosa/pilosa
|
executor.go
|
newExecutor
|
func newExecutor(opts ...executorOption) *executor {
e := &executor{
client: newNopInternalQueryClient(),
}
for _, opt := range opts {
err := opt(e)
if err != nil {
panic(err)
}
}
return e
}
|
go
|
func newExecutor(opts ...executorOption) *executor {
e := &executor{
client: newNopInternalQueryClient(),
}
for _, opt := range opts {
err := opt(e)
if err != nil {
panic(err)
}
}
return e
}
|
[
"func",
"newExecutor",
"(",
"opts",
"...",
"executorOption",
")",
"*",
"executor",
"{",
"e",
":=",
"&",
"executor",
"{",
"client",
":",
"newNopInternalQueryClient",
"(",
")",
",",
"}",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"err",
":=",
"opt",
"(",
"e",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"e",
"\n",
"}"
] |
// newExecutor returns a new instance of Executor.
|
[
"newExecutor",
"returns",
"a",
"new",
"instance",
"of",
"Executor",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L71-L82
|
train
|
pilosa/pilosa
|
executor.go
|
Execute
|
func (e *executor) Execute(ctx context.Context, index string, q *pql.Query, shards []uint64, opt *execOptions) (QueryResponse, error) {
span, ctx := tracing.StartSpanFromContext(ctx, "Executor.Execute")
defer span.Finish()
resp := QueryResponse{}
// Check for query cancellation.
if err := validateQueryContext(ctx); err != nil {
return resp, err
}
// Verify that an index is set.
if index == "" {
return resp, ErrIndexRequired
}
idx := e.Holder.Index(index)
if idx == nil {
return resp, ErrIndexNotFound
}
// Verify that the number of writes do not exceed the maximum.
if e.MaxWritesPerRequest > 0 && q.WriteCallN() > e.MaxWritesPerRequest {
return resp, ErrTooManyWrites
}
// Default options.
if opt == nil {
opt = &execOptions{}
}
// Translate query keys to ids, if necessary.
// No need to translate a remote call.
if !opt.Remote {
if err := e.translateCalls(ctx, index, idx, q.Calls); err != nil {
return resp, err
} else if err := validateQueryContext(ctx); err != nil {
return resp, err
}
}
results, err := e.execute(ctx, index, q, shards, opt)
if err != nil {
return resp, err
} else if err := validateQueryContext(ctx); err != nil {
return resp, err
}
resp.Results = results
// Fill column attributes if requested.
if opt.ColumnAttrs {
// Consolidate all column ids across all calls.
var columnIDs []uint64
for _, result := range results {
bm, ok := result.(*Row)
if !ok {
continue
}
columnIDs = uint64Slice(columnIDs).merge(bm.Columns())
}
// Retrieve column attributes across all calls.
columnAttrSets, err := e.readColumnAttrSets(e.Holder.Index(index), columnIDs)
if err != nil {
return resp, errors.Wrap(err, "reading column attrs")
}
// Translate column attributes, if necessary.
if idx.Keys() {
for _, col := range columnAttrSets {
v, err := e.Holder.translateFile.TranslateColumnToString(index, col.ID)
if err != nil {
return resp, err
}
col.Key, col.ID = v, 0
}
}
resp.ColumnAttrSets = columnAttrSets
}
// Translate response objects from ids to keys, if necessary.
// No need to translate a remote call.
if !opt.Remote {
if err := e.translateResults(ctx, index, idx, q.Calls, results); err != nil {
return resp, err
} else if err := validateQueryContext(ctx); err != nil {
return resp, err
}
}
return resp, nil
}
|
go
|
func (e *executor) Execute(ctx context.Context, index string, q *pql.Query, shards []uint64, opt *execOptions) (QueryResponse, error) {
span, ctx := tracing.StartSpanFromContext(ctx, "Executor.Execute")
defer span.Finish()
resp := QueryResponse{}
// Check for query cancellation.
if err := validateQueryContext(ctx); err != nil {
return resp, err
}
// Verify that an index is set.
if index == "" {
return resp, ErrIndexRequired
}
idx := e.Holder.Index(index)
if idx == nil {
return resp, ErrIndexNotFound
}
// Verify that the number of writes do not exceed the maximum.
if e.MaxWritesPerRequest > 0 && q.WriteCallN() > e.MaxWritesPerRequest {
return resp, ErrTooManyWrites
}
// Default options.
if opt == nil {
opt = &execOptions{}
}
// Translate query keys to ids, if necessary.
// No need to translate a remote call.
if !opt.Remote {
if err := e.translateCalls(ctx, index, idx, q.Calls); err != nil {
return resp, err
} else if err := validateQueryContext(ctx); err != nil {
return resp, err
}
}
results, err := e.execute(ctx, index, q, shards, opt)
if err != nil {
return resp, err
} else if err := validateQueryContext(ctx); err != nil {
return resp, err
}
resp.Results = results
// Fill column attributes if requested.
if opt.ColumnAttrs {
// Consolidate all column ids across all calls.
var columnIDs []uint64
for _, result := range results {
bm, ok := result.(*Row)
if !ok {
continue
}
columnIDs = uint64Slice(columnIDs).merge(bm.Columns())
}
// Retrieve column attributes across all calls.
columnAttrSets, err := e.readColumnAttrSets(e.Holder.Index(index), columnIDs)
if err != nil {
return resp, errors.Wrap(err, "reading column attrs")
}
// Translate column attributes, if necessary.
if idx.Keys() {
for _, col := range columnAttrSets {
v, err := e.Holder.translateFile.TranslateColumnToString(index, col.ID)
if err != nil {
return resp, err
}
col.Key, col.ID = v, 0
}
}
resp.ColumnAttrSets = columnAttrSets
}
// Translate response objects from ids to keys, if necessary.
// No need to translate a remote call.
if !opt.Remote {
if err := e.translateResults(ctx, index, idx, q.Calls, results); err != nil {
return resp, err
} else if err := validateQueryContext(ctx); err != nil {
return resp, err
}
}
return resp, nil
}
|
[
"func",
"(",
"e",
"*",
"executor",
")",
"Execute",
"(",
"ctx",
"context",
".",
"Context",
",",
"index",
"string",
",",
"q",
"*",
"pql",
".",
"Query",
",",
"shards",
"[",
"]",
"uint64",
",",
"opt",
"*",
"execOptions",
")",
"(",
"QueryResponse",
",",
"error",
")",
"{",
"span",
",",
"ctx",
":=",
"tracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"resp",
":=",
"QueryResponse",
"{",
"}",
"\n\n",
"// Check for query cancellation.",
"if",
"err",
":=",
"validateQueryContext",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"resp",
",",
"err",
"\n",
"}",
"\n\n",
"// Verify that an index is set.",
"if",
"index",
"==",
"\"",
"\"",
"{",
"return",
"resp",
",",
"ErrIndexRequired",
"\n",
"}",
"\n\n",
"idx",
":=",
"e",
".",
"Holder",
".",
"Index",
"(",
"index",
")",
"\n",
"if",
"idx",
"==",
"nil",
"{",
"return",
"resp",
",",
"ErrIndexNotFound",
"\n",
"}",
"\n\n",
"// Verify that the number of writes do not exceed the maximum.",
"if",
"e",
".",
"MaxWritesPerRequest",
">",
"0",
"&&",
"q",
".",
"WriteCallN",
"(",
")",
">",
"e",
".",
"MaxWritesPerRequest",
"{",
"return",
"resp",
",",
"ErrTooManyWrites",
"\n",
"}",
"\n\n",
"// Default options.",
"if",
"opt",
"==",
"nil",
"{",
"opt",
"=",
"&",
"execOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"// Translate query keys to ids, if necessary.",
"// No need to translate a remote call.",
"if",
"!",
"opt",
".",
"Remote",
"{",
"if",
"err",
":=",
"e",
".",
"translateCalls",
"(",
"ctx",
",",
"index",
",",
"idx",
",",
"q",
".",
"Calls",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"resp",
",",
"err",
"\n",
"}",
"else",
"if",
"err",
":=",
"validateQueryContext",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"resp",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"results",
",",
"err",
":=",
"e",
".",
"execute",
"(",
"ctx",
",",
"index",
",",
"q",
",",
"shards",
",",
"opt",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"resp",
",",
"err",
"\n",
"}",
"else",
"if",
"err",
":=",
"validateQueryContext",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"resp",
",",
"err",
"\n",
"}",
"\n\n",
"resp",
".",
"Results",
"=",
"results",
"\n\n",
"// Fill column attributes if requested.",
"if",
"opt",
".",
"ColumnAttrs",
"{",
"// Consolidate all column ids across all calls.",
"var",
"columnIDs",
"[",
"]",
"uint64",
"\n",
"for",
"_",
",",
"result",
":=",
"range",
"results",
"{",
"bm",
",",
"ok",
":=",
"result",
".",
"(",
"*",
"Row",
")",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n",
"columnIDs",
"=",
"uint64Slice",
"(",
"columnIDs",
")",
".",
"merge",
"(",
"bm",
".",
"Columns",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// Retrieve column attributes across all calls.",
"columnAttrSets",
",",
"err",
":=",
"e",
".",
"readColumnAttrSets",
"(",
"e",
".",
"Holder",
".",
"Index",
"(",
"index",
")",
",",
"columnIDs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"resp",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Translate column attributes, if necessary.",
"if",
"idx",
".",
"Keys",
"(",
")",
"{",
"for",
"_",
",",
"col",
":=",
"range",
"columnAttrSets",
"{",
"v",
",",
"err",
":=",
"e",
".",
"Holder",
".",
"translateFile",
".",
"TranslateColumnToString",
"(",
"index",
",",
"col",
".",
"ID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"resp",
",",
"err",
"\n",
"}",
"\n",
"col",
".",
"Key",
",",
"col",
".",
"ID",
"=",
"v",
",",
"0",
"\n",
"}",
"\n",
"}",
"\n\n",
"resp",
".",
"ColumnAttrSets",
"=",
"columnAttrSets",
"\n",
"}",
"\n\n",
"// Translate response objects from ids to keys, if necessary.",
"// No need to translate a remote call.",
"if",
"!",
"opt",
".",
"Remote",
"{",
"if",
"err",
":=",
"e",
".",
"translateResults",
"(",
"ctx",
",",
"index",
",",
"idx",
",",
"q",
".",
"Calls",
",",
"results",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"resp",
",",
"err",
"\n",
"}",
"else",
"if",
"err",
":=",
"validateQueryContext",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"resp",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"resp",
",",
"nil",
"\n",
"}"
] |
// Execute executes a PQL query.
|
[
"Execute",
"executes",
"a",
"PQL",
"query",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L85-L178
|
train
|
pilosa/pilosa
|
executor.go
|
readColumnAttrSets
|
func (e *executor) readColumnAttrSets(index *Index, ids []uint64) ([]*ColumnAttrSet, error) {
if index == nil {
return nil, nil
}
ax := make([]*ColumnAttrSet, 0, len(ids))
for _, id := range ids {
// Read attributes for column. Skip column if empty.
attrs, err := index.ColumnAttrStore().Attrs(id)
if err != nil {
return nil, errors.Wrap(err, "getting attrs")
} else if len(attrs) == 0 {
continue
}
// Append column with attributes.
ax = append(ax, &ColumnAttrSet{ID: id, Attrs: attrs})
}
return ax, nil
}
|
go
|
func (e *executor) readColumnAttrSets(index *Index, ids []uint64) ([]*ColumnAttrSet, error) {
if index == nil {
return nil, nil
}
ax := make([]*ColumnAttrSet, 0, len(ids))
for _, id := range ids {
// Read attributes for column. Skip column if empty.
attrs, err := index.ColumnAttrStore().Attrs(id)
if err != nil {
return nil, errors.Wrap(err, "getting attrs")
} else if len(attrs) == 0 {
continue
}
// Append column with attributes.
ax = append(ax, &ColumnAttrSet{ID: id, Attrs: attrs})
}
return ax, nil
}
|
[
"func",
"(",
"e",
"*",
"executor",
")",
"readColumnAttrSets",
"(",
"index",
"*",
"Index",
",",
"ids",
"[",
"]",
"uint64",
")",
"(",
"[",
"]",
"*",
"ColumnAttrSet",
",",
"error",
")",
"{",
"if",
"index",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"ax",
":=",
"make",
"(",
"[",
"]",
"*",
"ColumnAttrSet",
",",
"0",
",",
"len",
"(",
"ids",
")",
")",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"ids",
"{",
"// Read attributes for column. Skip column if empty.",
"attrs",
",",
"err",
":=",
"index",
".",
"ColumnAttrStore",
"(",
")",
".",
"Attrs",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"attrs",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n\n",
"// Append column with attributes.",
"ax",
"=",
"append",
"(",
"ax",
",",
"&",
"ColumnAttrSet",
"{",
"ID",
":",
"id",
",",
"Attrs",
":",
"attrs",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"ax",
",",
"nil",
"\n",
"}"
] |
// readColumnAttrSets returns a list of column attribute objects by id.
|
[
"readColumnAttrSets",
"returns",
"a",
"list",
"of",
"column",
"attribute",
"objects",
"by",
"id",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L181-L201
|
train
|
pilosa/pilosa
|
executor.go
|
validateCallArgs
|
func (e *executor) validateCallArgs(c *pql.Call) error {
if _, ok := c.Args["ids"]; ok {
switch v := c.Args["ids"].(type) {
case []int64, []uint64:
// noop
case []interface{}:
b := make([]int64, len(v))
for i := range v {
b[i] = v[i].(int64)
}
c.Args["ids"] = b
default:
return fmt.Errorf("invalid call.Args[ids]: %s", v)
}
}
return nil
}
|
go
|
func (e *executor) validateCallArgs(c *pql.Call) error {
if _, ok := c.Args["ids"]; ok {
switch v := c.Args["ids"].(type) {
case []int64, []uint64:
// noop
case []interface{}:
b := make([]int64, len(v))
for i := range v {
b[i] = v[i].(int64)
}
c.Args["ids"] = b
default:
return fmt.Errorf("invalid call.Args[ids]: %s", v)
}
}
return nil
}
|
[
"func",
"(",
"e",
"*",
"executor",
")",
"validateCallArgs",
"(",
"c",
"*",
"pql",
".",
"Call",
")",
"error",
"{",
"if",
"_",
",",
"ok",
":=",
"c",
".",
"Args",
"[",
"\"",
"\"",
"]",
";",
"ok",
"{",
"switch",
"v",
":=",
"c",
".",
"Args",
"[",
"\"",
"\"",
"]",
".",
"(",
"type",
")",
"{",
"case",
"[",
"]",
"int64",
",",
"[",
"]",
"uint64",
":",
"// noop",
"case",
"[",
"]",
"interface",
"{",
"}",
":",
"b",
":=",
"make",
"(",
"[",
"]",
"int64",
",",
"len",
"(",
"v",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"v",
"{",
"b",
"[",
"i",
"]",
"=",
"v",
"[",
"i",
"]",
".",
"(",
"int64",
")",
"\n",
"}",
"\n",
"c",
".",
"Args",
"[",
"\"",
"\"",
"]",
"=",
"b",
"\n",
"default",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// validateCallArgs ensures that the value types in call.Args are expected.
|
[
"validateCallArgs",
"ensures",
"that",
"the",
"value",
"types",
"in",
"call",
".",
"Args",
"are",
"expected",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L300-L316
|
train
|
pilosa/pilosa
|
executor.go
|
executeBitmapCall
|
func (e *executor) executeBitmapCall(ctx context.Context, index string, c *pql.Call, shards []uint64, opt *execOptions) (*Row, error) {
span, ctx := tracing.StartSpanFromContext(ctx, "Executor.executeBitmapCall")
defer span.Finish()
// Execute calls in bulk on each remote node and merge.
mapFn := func(shard uint64) (interface{}, error) {
return e.executeBitmapCallShard(ctx, index, c, shard)
}
// Merge returned results at coordinating node.
reduceFn := func(prev, v interface{}) interface{} {
other, _ := prev.(*Row)
if other == nil {
other = NewRow()
}
other.Merge(v.(*Row))
return other
}
other, err := e.mapReduce(ctx, index, shards, c, opt, mapFn, reduceFn)
if err != nil {
return nil, errors.Wrap(err, "map reduce")
}
// Attach attributes for non-BSI Row() calls.
// If the column label is used then return column attributes.
// If the row label is used then return bitmap attributes.
row, _ := other.(*Row)
if c.Name == "Row" && !c.HasConditionArg() {
if opt.ExcludeRowAttrs {
row.Attrs = map[string]interface{}{}
} else {
idx := e.Holder.Index(index)
if idx != nil {
if columnID, ok, err := c.UintArg("_" + columnLabel); ok && err == nil {
attrs, err := idx.ColumnAttrStore().Attrs(columnID)
if err != nil {
return nil, errors.Wrap(err, "getting column attrs")
}
row.Attrs = attrs
} else if err != nil {
return nil, err
} else {
// field, _ := c.Args["field"].(string)
fieldName, _ := c.FieldArg()
if fr := idx.Field(fieldName); fr != nil {
rowID, _, err := c.UintArg(fieldName)
if err != nil {
return nil, errors.Wrap(err, "getting row")
}
attrs, err := fr.RowAttrStore().Attrs(rowID)
if err != nil {
return nil, errors.Wrap(err, "getting row attrs")
}
row.Attrs = attrs
}
}
}
}
}
if opt.ExcludeColumns {
row.segments = []rowSegment{}
}
return row, nil
}
|
go
|
func (e *executor) executeBitmapCall(ctx context.Context, index string, c *pql.Call, shards []uint64, opt *execOptions) (*Row, error) {
span, ctx := tracing.StartSpanFromContext(ctx, "Executor.executeBitmapCall")
defer span.Finish()
// Execute calls in bulk on each remote node and merge.
mapFn := func(shard uint64) (interface{}, error) {
return e.executeBitmapCallShard(ctx, index, c, shard)
}
// Merge returned results at coordinating node.
reduceFn := func(prev, v interface{}) interface{} {
other, _ := prev.(*Row)
if other == nil {
other = NewRow()
}
other.Merge(v.(*Row))
return other
}
other, err := e.mapReduce(ctx, index, shards, c, opt, mapFn, reduceFn)
if err != nil {
return nil, errors.Wrap(err, "map reduce")
}
// Attach attributes for non-BSI Row() calls.
// If the column label is used then return column attributes.
// If the row label is used then return bitmap attributes.
row, _ := other.(*Row)
if c.Name == "Row" && !c.HasConditionArg() {
if opt.ExcludeRowAttrs {
row.Attrs = map[string]interface{}{}
} else {
idx := e.Holder.Index(index)
if idx != nil {
if columnID, ok, err := c.UintArg("_" + columnLabel); ok && err == nil {
attrs, err := idx.ColumnAttrStore().Attrs(columnID)
if err != nil {
return nil, errors.Wrap(err, "getting column attrs")
}
row.Attrs = attrs
} else if err != nil {
return nil, err
} else {
// field, _ := c.Args["field"].(string)
fieldName, _ := c.FieldArg()
if fr := idx.Field(fieldName); fr != nil {
rowID, _, err := c.UintArg(fieldName)
if err != nil {
return nil, errors.Wrap(err, "getting row")
}
attrs, err := fr.RowAttrStore().Attrs(rowID)
if err != nil {
return nil, errors.Wrap(err, "getting row attrs")
}
row.Attrs = attrs
}
}
}
}
}
if opt.ExcludeColumns {
row.segments = []rowSegment{}
}
return row, nil
}
|
[
"func",
"(",
"e",
"*",
"executor",
")",
"executeBitmapCall",
"(",
"ctx",
"context",
".",
"Context",
",",
"index",
"string",
",",
"c",
"*",
"pql",
".",
"Call",
",",
"shards",
"[",
"]",
"uint64",
",",
"opt",
"*",
"execOptions",
")",
"(",
"*",
"Row",
",",
"error",
")",
"{",
"span",
",",
"ctx",
":=",
"tracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"// Execute calls in bulk on each remote node and merge.",
"mapFn",
":=",
"func",
"(",
"shard",
"uint64",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"return",
"e",
".",
"executeBitmapCallShard",
"(",
"ctx",
",",
"index",
",",
"c",
",",
"shard",
")",
"\n",
"}",
"\n\n",
"// Merge returned results at coordinating node.",
"reduceFn",
":=",
"func",
"(",
"prev",
",",
"v",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"other",
",",
"_",
":=",
"prev",
".",
"(",
"*",
"Row",
")",
"\n",
"if",
"other",
"==",
"nil",
"{",
"other",
"=",
"NewRow",
"(",
")",
"\n",
"}",
"\n",
"other",
".",
"Merge",
"(",
"v",
".",
"(",
"*",
"Row",
")",
")",
"\n",
"return",
"other",
"\n",
"}",
"\n\n",
"other",
",",
"err",
":=",
"e",
".",
"mapReduce",
"(",
"ctx",
",",
"index",
",",
"shards",
",",
"c",
",",
"opt",
",",
"mapFn",
",",
"reduceFn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Attach attributes for non-BSI Row() calls.",
"// If the column label is used then return column attributes.",
"// If the row label is used then return bitmap attributes.",
"row",
",",
"_",
":=",
"other",
".",
"(",
"*",
"Row",
")",
"\n",
"if",
"c",
".",
"Name",
"==",
"\"",
"\"",
"&&",
"!",
"c",
".",
"HasConditionArg",
"(",
")",
"{",
"if",
"opt",
".",
"ExcludeRowAttrs",
"{",
"row",
".",
"Attrs",
"=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"}",
"else",
"{",
"idx",
":=",
"e",
".",
"Holder",
".",
"Index",
"(",
"index",
")",
"\n",
"if",
"idx",
"!=",
"nil",
"{",
"if",
"columnID",
",",
"ok",
",",
"err",
":=",
"c",
".",
"UintArg",
"(",
"\"",
"\"",
"+",
"columnLabel",
")",
";",
"ok",
"&&",
"err",
"==",
"nil",
"{",
"attrs",
",",
"err",
":=",
"idx",
".",
"ColumnAttrStore",
"(",
")",
".",
"Attrs",
"(",
"columnID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"row",
".",
"Attrs",
"=",
"attrs",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"{",
"// field, _ := c.Args[\"field\"].(string)",
"fieldName",
",",
"_",
":=",
"c",
".",
"FieldArg",
"(",
")",
"\n",
"if",
"fr",
":=",
"idx",
".",
"Field",
"(",
"fieldName",
")",
";",
"fr",
"!=",
"nil",
"{",
"rowID",
",",
"_",
",",
"err",
":=",
"c",
".",
"UintArg",
"(",
"fieldName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"attrs",
",",
"err",
":=",
"fr",
".",
"RowAttrStore",
"(",
")",
".",
"Attrs",
"(",
"rowID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"row",
".",
"Attrs",
"=",
"attrs",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"opt",
".",
"ExcludeColumns",
"{",
"row",
".",
"segments",
"=",
"[",
"]",
"rowSegment",
"{",
"}",
"\n",
"}",
"\n\n",
"return",
"row",
",",
"nil",
"\n",
"}"
] |
// executeBitmapCall executes a call that returns a bitmap.
|
[
"executeBitmapCall",
"executes",
"a",
"call",
"that",
"returns",
"a",
"bitmap",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L472-L538
|
train
|
pilosa/pilosa
|
executor.go
|
executeBitmapCallShard
|
func (e *executor) executeBitmapCallShard(ctx context.Context, index string, c *pql.Call, shard uint64) (*Row, error) {
if err := validateQueryContext(ctx); err != nil {
return nil, err
}
span, ctx := tracing.StartSpanFromContext(ctx, "Executor.executeBitmapCallShard")
defer span.Finish()
switch c.Name {
case "Row", "Range":
return e.executeRowShard(ctx, index, c, shard)
case "Difference":
return e.executeDifferenceShard(ctx, index, c, shard)
case "Intersect":
return e.executeIntersectShard(ctx, index, c, shard)
case "Union":
return e.executeUnionShard(ctx, index, c, shard)
case "Xor":
return e.executeXorShard(ctx, index, c, shard)
case "Not":
return e.executeNotShard(ctx, index, c, shard)
case "Shift":
return e.executeShiftShard(ctx, index, c, shard)
default:
return nil, fmt.Errorf("unknown call: %s", c.Name)
}
}
|
go
|
func (e *executor) executeBitmapCallShard(ctx context.Context, index string, c *pql.Call, shard uint64) (*Row, error) {
if err := validateQueryContext(ctx); err != nil {
return nil, err
}
span, ctx := tracing.StartSpanFromContext(ctx, "Executor.executeBitmapCallShard")
defer span.Finish()
switch c.Name {
case "Row", "Range":
return e.executeRowShard(ctx, index, c, shard)
case "Difference":
return e.executeDifferenceShard(ctx, index, c, shard)
case "Intersect":
return e.executeIntersectShard(ctx, index, c, shard)
case "Union":
return e.executeUnionShard(ctx, index, c, shard)
case "Xor":
return e.executeXorShard(ctx, index, c, shard)
case "Not":
return e.executeNotShard(ctx, index, c, shard)
case "Shift":
return e.executeShiftShard(ctx, index, c, shard)
default:
return nil, fmt.Errorf("unknown call: %s", c.Name)
}
}
|
[
"func",
"(",
"e",
"*",
"executor",
")",
"executeBitmapCallShard",
"(",
"ctx",
"context",
".",
"Context",
",",
"index",
"string",
",",
"c",
"*",
"pql",
".",
"Call",
",",
"shard",
"uint64",
")",
"(",
"*",
"Row",
",",
"error",
")",
"{",
"if",
"err",
":=",
"validateQueryContext",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"span",
",",
"ctx",
":=",
"tracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"switch",
"c",
".",
"Name",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"e",
".",
"executeRowShard",
"(",
"ctx",
",",
"index",
",",
"c",
",",
"shard",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"e",
".",
"executeDifferenceShard",
"(",
"ctx",
",",
"index",
",",
"c",
",",
"shard",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"e",
".",
"executeIntersectShard",
"(",
"ctx",
",",
"index",
",",
"c",
",",
"shard",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"e",
".",
"executeUnionShard",
"(",
"ctx",
",",
"index",
",",
"c",
",",
"shard",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"e",
".",
"executeXorShard",
"(",
"ctx",
",",
"index",
",",
"c",
",",
"shard",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"e",
".",
"executeNotShard",
"(",
"ctx",
",",
"index",
",",
"c",
",",
"shard",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"e",
".",
"executeShiftShard",
"(",
"ctx",
",",
"index",
",",
"c",
",",
"shard",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"c",
".",
"Name",
")",
"\n",
"}",
"\n",
"}"
] |
// executeBitmapCallShard executes a bitmap call for a single shard.
|
[
"executeBitmapCallShard",
"executes",
"a",
"bitmap",
"call",
"for",
"a",
"single",
"shard",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L541-L567
|
train
|
pilosa/pilosa
|
executor.go
|
executeSumCountShard
|
func (e *executor) executeSumCountShard(ctx context.Context, index string, c *pql.Call, shard uint64) (ValCount, error) {
span, ctx := tracing.StartSpanFromContext(ctx, "Executor.executeSumCountShard")
defer span.Finish()
var filter *Row
if len(c.Children) == 1 {
row, err := e.executeBitmapCallShard(ctx, index, c.Children[0], shard)
if err != nil {
return ValCount{}, errors.Wrap(err, "executing bitmap call")
}
filter = row
}
fieldName, _ := c.Args["field"].(string)
field := e.Holder.Field(index, fieldName)
if field == nil {
return ValCount{}, nil
}
bsig := field.bsiGroup(fieldName)
if bsig == nil {
return ValCount{}, nil
}
fragment := e.Holder.fragment(index, fieldName, viewBSIGroupPrefix+fieldName, shard)
if fragment == nil {
return ValCount{}, nil
}
vsum, vcount, err := fragment.sum(filter, bsig.BitDepth())
if err != nil {
return ValCount{}, errors.Wrap(err, "computing sum")
}
return ValCount{
Val: int64(vsum) + (int64(vcount) * bsig.Min),
Count: int64(vcount),
}, nil
}
|
go
|
func (e *executor) executeSumCountShard(ctx context.Context, index string, c *pql.Call, shard uint64) (ValCount, error) {
span, ctx := tracing.StartSpanFromContext(ctx, "Executor.executeSumCountShard")
defer span.Finish()
var filter *Row
if len(c.Children) == 1 {
row, err := e.executeBitmapCallShard(ctx, index, c.Children[0], shard)
if err != nil {
return ValCount{}, errors.Wrap(err, "executing bitmap call")
}
filter = row
}
fieldName, _ := c.Args["field"].(string)
field := e.Holder.Field(index, fieldName)
if field == nil {
return ValCount{}, nil
}
bsig := field.bsiGroup(fieldName)
if bsig == nil {
return ValCount{}, nil
}
fragment := e.Holder.fragment(index, fieldName, viewBSIGroupPrefix+fieldName, shard)
if fragment == nil {
return ValCount{}, nil
}
vsum, vcount, err := fragment.sum(filter, bsig.BitDepth())
if err != nil {
return ValCount{}, errors.Wrap(err, "computing sum")
}
return ValCount{
Val: int64(vsum) + (int64(vcount) * bsig.Min),
Count: int64(vcount),
}, nil
}
|
[
"func",
"(",
"e",
"*",
"executor",
")",
"executeSumCountShard",
"(",
"ctx",
"context",
".",
"Context",
",",
"index",
"string",
",",
"c",
"*",
"pql",
".",
"Call",
",",
"shard",
"uint64",
")",
"(",
"ValCount",
",",
"error",
")",
"{",
"span",
",",
"ctx",
":=",
"tracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"var",
"filter",
"*",
"Row",
"\n",
"if",
"len",
"(",
"c",
".",
"Children",
")",
"==",
"1",
"{",
"row",
",",
"err",
":=",
"e",
".",
"executeBitmapCallShard",
"(",
"ctx",
",",
"index",
",",
"c",
".",
"Children",
"[",
"0",
"]",
",",
"shard",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ValCount",
"{",
"}",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"filter",
"=",
"row",
"\n",
"}",
"\n\n",
"fieldName",
",",
"_",
":=",
"c",
".",
"Args",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
"\n\n",
"field",
":=",
"e",
".",
"Holder",
".",
"Field",
"(",
"index",
",",
"fieldName",
")",
"\n",
"if",
"field",
"==",
"nil",
"{",
"return",
"ValCount",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"bsig",
":=",
"field",
".",
"bsiGroup",
"(",
"fieldName",
")",
"\n",
"if",
"bsig",
"==",
"nil",
"{",
"return",
"ValCount",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"fragment",
":=",
"e",
".",
"Holder",
".",
"fragment",
"(",
"index",
",",
"fieldName",
",",
"viewBSIGroupPrefix",
"+",
"fieldName",
",",
"shard",
")",
"\n",
"if",
"fragment",
"==",
"nil",
"{",
"return",
"ValCount",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"vsum",
",",
"vcount",
",",
"err",
":=",
"fragment",
".",
"sum",
"(",
"filter",
",",
"bsig",
".",
"BitDepth",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ValCount",
"{",
"}",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"ValCount",
"{",
"Val",
":",
"int64",
"(",
"vsum",
")",
"+",
"(",
"int64",
"(",
"vcount",
")",
"*",
"bsig",
".",
"Min",
")",
",",
"Count",
":",
"int64",
"(",
"vcount",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// executeSumCountShard calculates the sum and count for bsiGroups on a shard.
|
[
"executeSumCountShard",
"calculates",
"the",
"sum",
"and",
"count",
"for",
"bsiGroups",
"on",
"a",
"shard",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L570-L608
|
train
|
pilosa/pilosa
|
executor.go
|
executeTopNShard
|
func (e *executor) executeTopNShard(ctx context.Context, index string, c *pql.Call, shard uint64) ([]Pair, error) {
span, ctx := tracing.StartSpanFromContext(ctx, "Executor.executeTopNShard")
defer span.Finish()
field, _ := c.Args["_field"].(string)
n, _, err := c.UintArg("n")
if err != nil {
return nil, fmt.Errorf("executeTopNShard: %v", err)
}
attrName, _ := c.Args["attrName"].(string)
rowIDs, _, err := c.UintSliceArg("ids")
if err != nil {
return nil, fmt.Errorf("executeTopNShard: %v", err)
}
minThreshold, _, err := c.UintArg("threshold")
if err != nil {
return nil, fmt.Errorf("executeTopNShard: %v", err)
}
attrValues, _ := c.Args["attrValues"].([]interface{})
tanimotoThreshold, _, err := c.UintArg("tanimotoThreshold")
if err != nil {
return nil, fmt.Errorf("executeTopNShard: %v", err)
}
// Retrieve bitmap used to intersect.
var src *Row
if len(c.Children) == 1 {
row, err := e.executeBitmapCallShard(ctx, index, c.Children[0], shard)
if err != nil {
return nil, err
}
src = row
} else if len(c.Children) > 1 {
return nil, errors.New("TopN() can only have one input bitmap")
}
// Set default field.
if field == "" {
field = defaultField
}
f := e.Holder.fragment(index, field, viewStandard, shard)
if f == nil {
return nil, nil
}
if minThreshold == 0 {
minThreshold = defaultMinThreshold
}
if tanimotoThreshold > 100 {
return nil, errors.New("Tanimoto Threshold is from 1 to 100 only")
}
return f.top(topOptions{
N: int(n),
Src: src,
RowIDs: rowIDs,
FilterName: attrName,
FilterValues: attrValues,
MinThreshold: minThreshold,
TanimotoThreshold: tanimotoThreshold,
})
}
|
go
|
func (e *executor) executeTopNShard(ctx context.Context, index string, c *pql.Call, shard uint64) ([]Pair, error) {
span, ctx := tracing.StartSpanFromContext(ctx, "Executor.executeTopNShard")
defer span.Finish()
field, _ := c.Args["_field"].(string)
n, _, err := c.UintArg("n")
if err != nil {
return nil, fmt.Errorf("executeTopNShard: %v", err)
}
attrName, _ := c.Args["attrName"].(string)
rowIDs, _, err := c.UintSliceArg("ids")
if err != nil {
return nil, fmt.Errorf("executeTopNShard: %v", err)
}
minThreshold, _, err := c.UintArg("threshold")
if err != nil {
return nil, fmt.Errorf("executeTopNShard: %v", err)
}
attrValues, _ := c.Args["attrValues"].([]interface{})
tanimotoThreshold, _, err := c.UintArg("tanimotoThreshold")
if err != nil {
return nil, fmt.Errorf("executeTopNShard: %v", err)
}
// Retrieve bitmap used to intersect.
var src *Row
if len(c.Children) == 1 {
row, err := e.executeBitmapCallShard(ctx, index, c.Children[0], shard)
if err != nil {
return nil, err
}
src = row
} else if len(c.Children) > 1 {
return nil, errors.New("TopN() can only have one input bitmap")
}
// Set default field.
if field == "" {
field = defaultField
}
f := e.Holder.fragment(index, field, viewStandard, shard)
if f == nil {
return nil, nil
}
if minThreshold == 0 {
minThreshold = defaultMinThreshold
}
if tanimotoThreshold > 100 {
return nil, errors.New("Tanimoto Threshold is from 1 to 100 only")
}
return f.top(topOptions{
N: int(n),
Src: src,
RowIDs: rowIDs,
FilterName: attrName,
FilterValues: attrValues,
MinThreshold: minThreshold,
TanimotoThreshold: tanimotoThreshold,
})
}
|
[
"func",
"(",
"e",
"*",
"executor",
")",
"executeTopNShard",
"(",
"ctx",
"context",
".",
"Context",
",",
"index",
"string",
",",
"c",
"*",
"pql",
".",
"Call",
",",
"shard",
"uint64",
")",
"(",
"[",
"]",
"Pair",
",",
"error",
")",
"{",
"span",
",",
"ctx",
":=",
"tracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"field",
",",
"_",
":=",
"c",
".",
"Args",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
"\n",
"n",
",",
"_",
",",
"err",
":=",
"c",
".",
"UintArg",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"attrName",
",",
"_",
":=",
"c",
".",
"Args",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
"\n",
"rowIDs",
",",
"_",
",",
"err",
":=",
"c",
".",
"UintSliceArg",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"minThreshold",
",",
"_",
",",
"err",
":=",
"c",
".",
"UintArg",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"attrValues",
",",
"_",
":=",
"c",
".",
"Args",
"[",
"\"",
"\"",
"]",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"\n",
"tanimotoThreshold",
",",
"_",
",",
"err",
":=",
"c",
".",
"UintArg",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Retrieve bitmap used to intersect.",
"var",
"src",
"*",
"Row",
"\n",
"if",
"len",
"(",
"c",
".",
"Children",
")",
"==",
"1",
"{",
"row",
",",
"err",
":=",
"e",
".",
"executeBitmapCallShard",
"(",
"ctx",
",",
"index",
",",
"c",
".",
"Children",
"[",
"0",
"]",
",",
"shard",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"src",
"=",
"row",
"\n",
"}",
"else",
"if",
"len",
"(",
"c",
".",
"Children",
")",
">",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Set default field.",
"if",
"field",
"==",
"\"",
"\"",
"{",
"field",
"=",
"defaultField",
"\n",
"}",
"\n\n",
"f",
":=",
"e",
".",
"Holder",
".",
"fragment",
"(",
"index",
",",
"field",
",",
"viewStandard",
",",
"shard",
")",
"\n",
"if",
"f",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"minThreshold",
"==",
"0",
"{",
"minThreshold",
"=",
"defaultMinThreshold",
"\n",
"}",
"\n\n",
"if",
"tanimotoThreshold",
">",
"100",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"f",
".",
"top",
"(",
"topOptions",
"{",
"N",
":",
"int",
"(",
"n",
")",
",",
"Src",
":",
"src",
",",
"RowIDs",
":",
"rowIDs",
",",
"FilterName",
":",
"attrName",
",",
"FilterValues",
":",
"attrValues",
",",
"MinThreshold",
":",
"minThreshold",
",",
"TanimotoThreshold",
":",
"tanimotoThreshold",
",",
"}",
")",
"\n",
"}"
] |
// executeTopNShard executes a TopN call for a single shard.
|
[
"executeTopNShard",
"executes",
"a",
"TopN",
"call",
"for",
"a",
"single",
"shard",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L765-L827
|
train
|
pilosa/pilosa
|
executor.go
|
MarshalJSON
|
func (fr FieldRow) MarshalJSON() ([]byte, error) {
if fr.RowKey != "" {
return json.Marshal(struct {
Field string `json:"field"`
RowKey string `json:"rowKey"`
}{
Field: fr.Field,
RowKey: fr.RowKey,
})
}
return json.Marshal(struct {
Field string `json:"field"`
RowID uint64 `json:"rowID"`
}{
Field: fr.Field,
RowID: fr.RowID,
})
}
|
go
|
func (fr FieldRow) MarshalJSON() ([]byte, error) {
if fr.RowKey != "" {
return json.Marshal(struct {
Field string `json:"field"`
RowKey string `json:"rowKey"`
}{
Field: fr.Field,
RowKey: fr.RowKey,
})
}
return json.Marshal(struct {
Field string `json:"field"`
RowID uint64 `json:"rowID"`
}{
Field: fr.Field,
RowID: fr.RowID,
})
}
|
[
"func",
"(",
"fr",
"FieldRow",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"fr",
".",
"RowKey",
"!=",
"\"",
"\"",
"{",
"return",
"json",
".",
"Marshal",
"(",
"struct",
"{",
"Field",
"string",
"`json:\"field\"`",
"\n",
"RowKey",
"string",
"`json:\"rowKey\"`",
"\n",
"}",
"{",
"Field",
":",
"fr",
".",
"Field",
",",
"RowKey",
":",
"fr",
".",
"RowKey",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"struct",
"{",
"Field",
"string",
"`json:\"field\"`",
"\n",
"RowID",
"uint64",
"`json:\"rowID\"`",
"\n",
"}",
"{",
"Field",
":",
"fr",
".",
"Field",
",",
"RowID",
":",
"fr",
".",
"RowID",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON marshals FieldRow to JSON such that
// either a Key or an ID is included.
|
[
"MarshalJSON",
"marshals",
"FieldRow",
"to",
"JSON",
"such",
"that",
"either",
"a",
"Key",
"or",
"an",
"ID",
"is",
"included",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L992-L1009
|
train
|
pilosa/pilosa
|
executor.go
|
String
|
func (fr FieldRow) String() string {
return fmt.Sprintf("%s.%d.%s", fr.Field, fr.RowID, fr.RowKey)
}
|
go
|
func (fr FieldRow) String() string {
return fmt.Sprintf("%s.%d.%s", fr.Field, fr.RowID, fr.RowKey)
}
|
[
"func",
"(",
"fr",
"FieldRow",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"fr",
".",
"Field",
",",
"fr",
".",
"RowID",
",",
"fr",
".",
"RowKey",
")",
"\n",
"}"
] |
// String is the FieldRow stringer.
|
[
"String",
"is",
"the",
"FieldRow",
"stringer",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L1012-L1014
|
train
|
pilosa/pilosa
|
executor.go
|
mergeGroupCounts
|
func mergeGroupCounts(a, b []GroupCount, limit int) []GroupCount {
if limit > len(a)+len(b) {
limit = len(a) + len(b)
}
ret := make([]GroupCount, 0, limit)
i, j := 0, 0
for i < len(a) && j < len(b) && len(ret) < limit {
switch a[i].Compare(b[j]) {
case -1:
ret = append(ret, a[i])
i++
case 0:
a[i].Count += b[j].Count
ret = append(ret, a[i])
i++
j++
case 1:
ret = append(ret, b[j])
j++
}
}
for ; i < len(a) && len(ret) < limit; i++ {
ret = append(ret, a[i])
}
for ; j < len(b) && len(ret) < limit; j++ {
ret = append(ret, b[j])
}
return ret
}
|
go
|
func mergeGroupCounts(a, b []GroupCount, limit int) []GroupCount {
if limit > len(a)+len(b) {
limit = len(a) + len(b)
}
ret := make([]GroupCount, 0, limit)
i, j := 0, 0
for i < len(a) && j < len(b) && len(ret) < limit {
switch a[i].Compare(b[j]) {
case -1:
ret = append(ret, a[i])
i++
case 0:
a[i].Count += b[j].Count
ret = append(ret, a[i])
i++
j++
case 1:
ret = append(ret, b[j])
j++
}
}
for ; i < len(a) && len(ret) < limit; i++ {
ret = append(ret, a[i])
}
for ; j < len(b) && len(ret) < limit; j++ {
ret = append(ret, b[j])
}
return ret
}
|
[
"func",
"mergeGroupCounts",
"(",
"a",
",",
"b",
"[",
"]",
"GroupCount",
",",
"limit",
"int",
")",
"[",
"]",
"GroupCount",
"{",
"if",
"limit",
">",
"len",
"(",
"a",
")",
"+",
"len",
"(",
"b",
")",
"{",
"limit",
"=",
"len",
"(",
"a",
")",
"+",
"len",
"(",
"b",
")",
"\n",
"}",
"\n",
"ret",
":=",
"make",
"(",
"[",
"]",
"GroupCount",
",",
"0",
",",
"limit",
")",
"\n",
"i",
",",
"j",
":=",
"0",
",",
"0",
"\n",
"for",
"i",
"<",
"len",
"(",
"a",
")",
"&&",
"j",
"<",
"len",
"(",
"b",
")",
"&&",
"len",
"(",
"ret",
")",
"<",
"limit",
"{",
"switch",
"a",
"[",
"i",
"]",
".",
"Compare",
"(",
"b",
"[",
"j",
"]",
")",
"{",
"case",
"-",
"1",
":",
"ret",
"=",
"append",
"(",
"ret",
",",
"a",
"[",
"i",
"]",
")",
"\n",
"i",
"++",
"\n",
"case",
"0",
":",
"a",
"[",
"i",
"]",
".",
"Count",
"+=",
"b",
"[",
"j",
"]",
".",
"Count",
"\n",
"ret",
"=",
"append",
"(",
"ret",
",",
"a",
"[",
"i",
"]",
")",
"\n",
"i",
"++",
"\n",
"j",
"++",
"\n",
"case",
"1",
":",
"ret",
"=",
"append",
"(",
"ret",
",",
"b",
"[",
"j",
"]",
")",
"\n",
"j",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"for",
";",
"i",
"<",
"len",
"(",
"a",
")",
"&&",
"len",
"(",
"ret",
")",
"<",
"limit",
";",
"i",
"++",
"{",
"ret",
"=",
"append",
"(",
"ret",
",",
"a",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"for",
";",
"j",
"<",
"len",
"(",
"b",
")",
"&&",
"len",
"(",
"ret",
")",
"<",
"limit",
";",
"j",
"++",
"{",
"ret",
"=",
"append",
"(",
"ret",
",",
"b",
"[",
"j",
"]",
")",
"\n",
"}",
"\n",
"return",
"ret",
"\n",
"}"
] |
// mergeGroupCounts merges two slices of GroupCounts throwing away any that go
// beyond the limit. It assume that the two slices are sorted by the row ids in
// the fields of the group counts. It may modify its arguments.
|
[
"mergeGroupCounts",
"merges",
"two",
"slices",
"of",
"GroupCounts",
"throwing",
"away",
"any",
"that",
"go",
"beyond",
"the",
"limit",
".",
"It",
"assume",
"that",
"the",
"two",
"slices",
"are",
"sorted",
"by",
"the",
"row",
"ids",
"in",
"the",
"fields",
"of",
"the",
"group",
"counts",
".",
"It",
"may",
"modify",
"its",
"arguments",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L1025-L1053
|
train
|
pilosa/pilosa
|
executor.go
|
Compare
|
func (g GroupCount) Compare(o GroupCount) int {
for i := range g.Group {
if g.Group[i].RowID < o.Group[i].RowID {
return -1
}
if g.Group[i].RowID > o.Group[i].RowID {
return 1
}
}
return 0
}
|
go
|
func (g GroupCount) Compare(o GroupCount) int {
for i := range g.Group {
if g.Group[i].RowID < o.Group[i].RowID {
return -1
}
if g.Group[i].RowID > o.Group[i].RowID {
return 1
}
}
return 0
}
|
[
"func",
"(",
"g",
"GroupCount",
")",
"Compare",
"(",
"o",
"GroupCount",
")",
"int",
"{",
"for",
"i",
":=",
"range",
"g",
".",
"Group",
"{",
"if",
"g",
".",
"Group",
"[",
"i",
"]",
".",
"RowID",
"<",
"o",
".",
"Group",
"[",
"i",
"]",
".",
"RowID",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"if",
"g",
".",
"Group",
"[",
"i",
"]",
".",
"RowID",
">",
"o",
".",
"Group",
"[",
"i",
"]",
".",
"RowID",
"{",
"return",
"1",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}"
] |
// Compare is used in ordering two GroupCount objects.
|
[
"Compare",
"is",
"used",
"in",
"ordering",
"two",
"GroupCount",
"objects",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L1056-L1066
|
train
|
pilosa/pilosa
|
executor.go
|
remoteExec
|
func (e *executor) remoteExec(ctx context.Context, node *Node, index string, q *pql.Query, shards []uint64) (results []interface{}, err error) { // nolint: interfacer
span, ctx := tracing.StartSpanFromContext(ctx, "Executor.executeExec")
defer span.Finish()
// Encode request object.
pbreq := &QueryRequest{
Query: q.String(),
Shards: shards,
Remote: true,
}
pb, err := e.client.QueryNode(ctx, &node.URI, index, pbreq)
if err != nil {
return nil, err
}
return pb.Results, pb.Err
}
|
go
|
func (e *executor) remoteExec(ctx context.Context, node *Node, index string, q *pql.Query, shards []uint64) (results []interface{}, err error) { // nolint: interfacer
span, ctx := tracing.StartSpanFromContext(ctx, "Executor.executeExec")
defer span.Finish()
// Encode request object.
pbreq := &QueryRequest{
Query: q.String(),
Shards: shards,
Remote: true,
}
pb, err := e.client.QueryNode(ctx, &node.URI, index, pbreq)
if err != nil {
return nil, err
}
return pb.Results, pb.Err
}
|
[
"func",
"(",
"e",
"*",
"executor",
")",
"remoteExec",
"(",
"ctx",
"context",
".",
"Context",
",",
"node",
"*",
"Node",
",",
"index",
"string",
",",
"q",
"*",
"pql",
".",
"Query",
",",
"shards",
"[",
"]",
"uint64",
")",
"(",
"results",
"[",
"]",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"// nolint: interfacer",
"span",
",",
"ctx",
":=",
"tracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"// Encode request object.",
"pbreq",
":=",
"&",
"QueryRequest",
"{",
"Query",
":",
"q",
".",
"String",
"(",
")",
",",
"Shards",
":",
"shards",
",",
"Remote",
":",
"true",
",",
"}",
"\n\n",
"pb",
",",
"err",
":=",
"e",
".",
"client",
".",
"QueryNode",
"(",
"ctx",
",",
"&",
"node",
".",
"URI",
",",
"index",
",",
"pbreq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"pb",
".",
"Results",
",",
"pb",
".",
"Err",
"\n",
"}"
] |
// remoteExec executes a PQL query remotely for a set of shards on a node.
|
[
"remoteExec",
"executes",
"a",
"PQL",
"query",
"remotely",
"for",
"a",
"set",
"of",
"shards",
"on",
"a",
"node",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L2242-L2259
|
train
|
pilosa/pilosa
|
executor.go
|
shardsByNode
|
func (e *executor) shardsByNode(nodes []*Node, index string, shards []uint64) (map[*Node][]uint64, error) {
m := make(map[*Node][]uint64)
loop:
for _, shard := range shards {
for _, node := range e.Cluster.ShardNodes(index, shard) {
if Nodes(nodes).Contains(node) {
m[node] = append(m[node], shard)
continue loop
}
}
return nil, errShardUnavailable
}
return m, nil
}
|
go
|
func (e *executor) shardsByNode(nodes []*Node, index string, shards []uint64) (map[*Node][]uint64, error) {
m := make(map[*Node][]uint64)
loop:
for _, shard := range shards {
for _, node := range e.Cluster.ShardNodes(index, shard) {
if Nodes(nodes).Contains(node) {
m[node] = append(m[node], shard)
continue loop
}
}
return nil, errShardUnavailable
}
return m, nil
}
|
[
"func",
"(",
"e",
"*",
"executor",
")",
"shardsByNode",
"(",
"nodes",
"[",
"]",
"*",
"Node",
",",
"index",
"string",
",",
"shards",
"[",
"]",
"uint64",
")",
"(",
"map",
"[",
"*",
"Node",
"]",
"[",
"]",
"uint64",
",",
"error",
")",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"*",
"Node",
"]",
"[",
"]",
"uint64",
")",
"\n\n",
"loop",
":",
"for",
"_",
",",
"shard",
":=",
"range",
"shards",
"{",
"for",
"_",
",",
"node",
":=",
"range",
"e",
".",
"Cluster",
".",
"ShardNodes",
"(",
"index",
",",
"shard",
")",
"{",
"if",
"Nodes",
"(",
"nodes",
")",
".",
"Contains",
"(",
"node",
")",
"{",
"m",
"[",
"node",
"]",
"=",
"append",
"(",
"m",
"[",
"node",
"]",
",",
"shard",
")",
"\n",
"continue",
"loop",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errShardUnavailable",
"\n",
"}",
"\n",
"return",
"m",
",",
"nil",
"\n",
"}"
] |
// shardsByNode returns a mapping of nodes to shards.
// Returns errShardUnavailable if a shard cannot be allocated to a node.
|
[
"shardsByNode",
"returns",
"a",
"mapping",
"of",
"nodes",
"to",
"shards",
".",
"Returns",
"errShardUnavailable",
"if",
"a",
"shard",
"cannot",
"be",
"allocated",
"to",
"a",
"node",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L2263-L2277
|
train
|
pilosa/pilosa
|
executor.go
|
mapReduce
|
func (e *executor) mapReduce(ctx context.Context, index string, shards []uint64, c *pql.Call, opt *execOptions, mapFn mapFunc, reduceFn reduceFunc) (interface{}, error) {
span, ctx := tracing.StartSpanFromContext(ctx, "Executor.mapReduce")
defer span.Finish()
ch := make(chan mapResponse)
// Wrap context with a cancel to kill goroutines on exit.
ctx, cancel := context.WithCancel(ctx)
defer cancel()
// If this is the coordinating node then start with all nodes in the cluster.
//
// However, if this request is being sent from the coordinator then all
// processing should be done locally so we start with just the local node.
var nodes []*Node
if !opt.Remote {
nodes = Nodes(e.Cluster.nodes).Clone()
} else {
nodes = []*Node{e.Cluster.nodeByID(e.Node.ID)}
}
// Start mapping across all primary owners.
if err := e.mapper(ctx, ch, nodes, index, shards, c, opt, mapFn, reduceFn); err != nil {
return nil, errors.Wrap(err, "starting mapper")
}
// Iterate over all map responses and reduce.
var result interface{}
var shardN int
for {
select {
case <-ctx.Done():
return nil, errors.Wrap(ctx.Err(), "context done")
case resp := <-ch:
// On error retry against remaining nodes. If an error returns then
// the context will cancel and cause all open goroutines to return.
if resp.err != nil {
// Filter out unavailable nodes.
nodes = Nodes(nodes).Filter(resp.node)
// Begin mapper against secondary nodes.
if err := e.mapper(ctx, ch, nodes, index, resp.shards, c, opt, mapFn, reduceFn); errors.Cause(err) == errShardUnavailable {
return nil, resp.err
} else if err != nil {
return nil, errors.Wrap(err, "calling mapper")
}
continue
}
// Reduce value.
result = reduceFn(result, resp.result)
// If all shards have been processed then return.
shardN += len(resp.shards)
if shardN >= len(shards) {
return result, nil
}
}
}
}
|
go
|
func (e *executor) mapReduce(ctx context.Context, index string, shards []uint64, c *pql.Call, opt *execOptions, mapFn mapFunc, reduceFn reduceFunc) (interface{}, error) {
span, ctx := tracing.StartSpanFromContext(ctx, "Executor.mapReduce")
defer span.Finish()
ch := make(chan mapResponse)
// Wrap context with a cancel to kill goroutines on exit.
ctx, cancel := context.WithCancel(ctx)
defer cancel()
// If this is the coordinating node then start with all nodes in the cluster.
//
// However, if this request is being sent from the coordinator then all
// processing should be done locally so we start with just the local node.
var nodes []*Node
if !opt.Remote {
nodes = Nodes(e.Cluster.nodes).Clone()
} else {
nodes = []*Node{e.Cluster.nodeByID(e.Node.ID)}
}
// Start mapping across all primary owners.
if err := e.mapper(ctx, ch, nodes, index, shards, c, opt, mapFn, reduceFn); err != nil {
return nil, errors.Wrap(err, "starting mapper")
}
// Iterate over all map responses and reduce.
var result interface{}
var shardN int
for {
select {
case <-ctx.Done():
return nil, errors.Wrap(ctx.Err(), "context done")
case resp := <-ch:
// On error retry against remaining nodes. If an error returns then
// the context will cancel and cause all open goroutines to return.
if resp.err != nil {
// Filter out unavailable nodes.
nodes = Nodes(nodes).Filter(resp.node)
// Begin mapper against secondary nodes.
if err := e.mapper(ctx, ch, nodes, index, resp.shards, c, opt, mapFn, reduceFn); errors.Cause(err) == errShardUnavailable {
return nil, resp.err
} else if err != nil {
return nil, errors.Wrap(err, "calling mapper")
}
continue
}
// Reduce value.
result = reduceFn(result, resp.result)
// If all shards have been processed then return.
shardN += len(resp.shards)
if shardN >= len(shards) {
return result, nil
}
}
}
}
|
[
"func",
"(",
"e",
"*",
"executor",
")",
"mapReduce",
"(",
"ctx",
"context",
".",
"Context",
",",
"index",
"string",
",",
"shards",
"[",
"]",
"uint64",
",",
"c",
"*",
"pql",
".",
"Call",
",",
"opt",
"*",
"execOptions",
",",
"mapFn",
"mapFunc",
",",
"reduceFn",
"reduceFunc",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"span",
",",
"ctx",
":=",
"tracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"ch",
":=",
"make",
"(",
"chan",
"mapResponse",
")",
"\n\n",
"// Wrap context with a cancel to kill goroutines on exit.",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithCancel",
"(",
"ctx",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n\n",
"// If this is the coordinating node then start with all nodes in the cluster.",
"//",
"// However, if this request is being sent from the coordinator then all",
"// processing should be done locally so we start with just the local node.",
"var",
"nodes",
"[",
"]",
"*",
"Node",
"\n",
"if",
"!",
"opt",
".",
"Remote",
"{",
"nodes",
"=",
"Nodes",
"(",
"e",
".",
"Cluster",
".",
"nodes",
")",
".",
"Clone",
"(",
")",
"\n",
"}",
"else",
"{",
"nodes",
"=",
"[",
"]",
"*",
"Node",
"{",
"e",
".",
"Cluster",
".",
"nodeByID",
"(",
"e",
".",
"Node",
".",
"ID",
")",
"}",
"\n",
"}",
"\n\n",
"// Start mapping across all primary owners.",
"if",
"err",
":=",
"e",
".",
"mapper",
"(",
"ctx",
",",
"ch",
",",
"nodes",
",",
"index",
",",
"shards",
",",
"c",
",",
"opt",
",",
"mapFn",
",",
"reduceFn",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Iterate over all map responses and reduce.",
"var",
"result",
"interface",
"{",
"}",
"\n",
"var",
"shardN",
"int",
"\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"ctx",
".",
"Err",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"case",
"resp",
":=",
"<-",
"ch",
":",
"// On error retry against remaining nodes. If an error returns then",
"// the context will cancel and cause all open goroutines to return.",
"if",
"resp",
".",
"err",
"!=",
"nil",
"{",
"// Filter out unavailable nodes.",
"nodes",
"=",
"Nodes",
"(",
"nodes",
")",
".",
"Filter",
"(",
"resp",
".",
"node",
")",
"\n\n",
"// Begin mapper against secondary nodes.",
"if",
"err",
":=",
"e",
".",
"mapper",
"(",
"ctx",
",",
"ch",
",",
"nodes",
",",
"index",
",",
"resp",
".",
"shards",
",",
"c",
",",
"opt",
",",
"mapFn",
",",
"reduceFn",
")",
";",
"errors",
".",
"Cause",
"(",
"err",
")",
"==",
"errShardUnavailable",
"{",
"return",
"nil",
",",
"resp",
".",
"err",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"continue",
"\n",
"}",
"\n\n",
"// Reduce value.",
"result",
"=",
"reduceFn",
"(",
"result",
",",
"resp",
".",
"result",
")",
"\n\n",
"// If all shards have been processed then return.",
"shardN",
"+=",
"len",
"(",
"resp",
".",
"shards",
")",
"\n",
"if",
"shardN",
">=",
"len",
"(",
"shards",
")",
"{",
"return",
"result",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// mapReduce maps and reduces data across the cluster.
//
// If a mapping of shards to a node fails then the shards are resplit across
// secondary nodes and retried. This continues to occur until all nodes are exhausted.
|
[
"mapReduce",
"maps",
"and",
"reduces",
"data",
"across",
"the",
"cluster",
".",
"If",
"a",
"mapping",
"of",
"shards",
"to",
"a",
"node",
"fails",
"then",
"the",
"shards",
"are",
"resplit",
"across",
"secondary",
"nodes",
"and",
"retried",
".",
"This",
"continues",
"to",
"occur",
"until",
"all",
"nodes",
"are",
"exhausted",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L2283-L2343
|
train
|
pilosa/pilosa
|
executor.go
|
mapperLocal
|
func (e *executor) mapperLocal(ctx context.Context, shards []uint64, mapFn mapFunc, reduceFn reduceFunc) (interface{}, error) {
span, ctx := tracing.StartSpanFromContext(ctx, "Executor.mapperLocal")
defer span.Finish()
ch := make(chan mapResponse, len(shards))
for _, shard := range shards {
go func(shard uint64) {
result, err := mapFn(shard)
// Return response to the channel.
select {
case <-ctx.Done():
case ch <- mapResponse{result: result, err: err}:
}
}(shard)
}
// Reduce results
var maxShard int
var result interface{}
for {
select {
case <-ctx.Done():
return nil, ctx.Err()
case resp := <-ch:
if resp.err != nil {
return nil, resp.err
}
result = reduceFn(result, resp.result)
maxShard++
}
// Exit once all shards are processed.
if maxShard == len(shards) {
return result, nil
}
}
}
|
go
|
func (e *executor) mapperLocal(ctx context.Context, shards []uint64, mapFn mapFunc, reduceFn reduceFunc) (interface{}, error) {
span, ctx := tracing.StartSpanFromContext(ctx, "Executor.mapperLocal")
defer span.Finish()
ch := make(chan mapResponse, len(shards))
for _, shard := range shards {
go func(shard uint64) {
result, err := mapFn(shard)
// Return response to the channel.
select {
case <-ctx.Done():
case ch <- mapResponse{result: result, err: err}:
}
}(shard)
}
// Reduce results
var maxShard int
var result interface{}
for {
select {
case <-ctx.Done():
return nil, ctx.Err()
case resp := <-ch:
if resp.err != nil {
return nil, resp.err
}
result = reduceFn(result, resp.result)
maxShard++
}
// Exit once all shards are processed.
if maxShard == len(shards) {
return result, nil
}
}
}
|
[
"func",
"(",
"e",
"*",
"executor",
")",
"mapperLocal",
"(",
"ctx",
"context",
".",
"Context",
",",
"shards",
"[",
"]",
"uint64",
",",
"mapFn",
"mapFunc",
",",
"reduceFn",
"reduceFunc",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"span",
",",
"ctx",
":=",
"tracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"Finish",
"(",
")",
"\n\n",
"ch",
":=",
"make",
"(",
"chan",
"mapResponse",
",",
"len",
"(",
"shards",
")",
")",
"\n\n",
"for",
"_",
",",
"shard",
":=",
"range",
"shards",
"{",
"go",
"func",
"(",
"shard",
"uint64",
")",
"{",
"result",
",",
"err",
":=",
"mapFn",
"(",
"shard",
")",
"\n\n",
"// Return response to the channel.",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"case",
"ch",
"<-",
"mapResponse",
"{",
"result",
":",
"result",
",",
"err",
":",
"err",
"}",
":",
"}",
"\n",
"}",
"(",
"shard",
")",
"\n",
"}",
"\n\n",
"// Reduce results",
"var",
"maxShard",
"int",
"\n",
"var",
"result",
"interface",
"{",
"}",
"\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"nil",
",",
"ctx",
".",
"Err",
"(",
")",
"\n",
"case",
"resp",
":=",
"<-",
"ch",
":",
"if",
"resp",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"resp",
".",
"err",
"\n",
"}",
"\n",
"result",
"=",
"reduceFn",
"(",
"result",
",",
"resp",
".",
"result",
")",
"\n",
"maxShard",
"++",
"\n",
"}",
"\n\n",
"// Exit once all shards are processed.",
"if",
"maxShard",
"==",
"len",
"(",
"shards",
")",
"{",
"return",
"result",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// mapperLocal performs map & reduce entirely on the local node.
|
[
"mapperLocal",
"performs",
"map",
"&",
"reduce",
"entirely",
"on",
"the",
"local",
"node",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L2383-L2421
|
train
|
pilosa/pilosa
|
executor.go
|
validateQueryContext
|
func validateQueryContext(ctx context.Context) error {
select {
case <-ctx.Done():
switch err := ctx.Err(); err {
case context.Canceled:
return ErrQueryCancelled
case context.DeadlineExceeded:
return ErrQueryTimeout
default:
return err
}
default:
return nil
}
}
|
go
|
func validateQueryContext(ctx context.Context) error {
select {
case <-ctx.Done():
switch err := ctx.Err(); err {
case context.Canceled:
return ErrQueryCancelled
case context.DeadlineExceeded:
return ErrQueryTimeout
default:
return err
}
default:
return nil
}
}
|
[
"func",
"validateQueryContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"switch",
"err",
":=",
"ctx",
".",
"Err",
"(",
")",
";",
"err",
"{",
"case",
"context",
".",
"Canceled",
":",
"return",
"ErrQueryCancelled",
"\n",
"case",
"context",
".",
"DeadlineExceeded",
":",
"return",
"ErrQueryTimeout",
"\n",
"default",
":",
"return",
"err",
"\n",
"}",
"\n",
"default",
":",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// validateQueryContext returns a query-appropriate error if the context is done.
|
[
"validateQueryContext",
"returns",
"a",
"query",
"-",
"appropriate",
"error",
"if",
"the",
"context",
"is",
"done",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L2691-L2705
|
train
|
pilosa/pilosa
|
executor.go
|
smaller
|
func (vc *ValCount) smaller(other ValCount) ValCount {
if vc.Count == 0 || (other.Val < vc.Val && other.Count > 0) {
return other
}
return ValCount{
Val: vc.Val,
Count: vc.Count,
}
}
|
go
|
func (vc *ValCount) smaller(other ValCount) ValCount {
if vc.Count == 0 || (other.Val < vc.Val && other.Count > 0) {
return other
}
return ValCount{
Val: vc.Val,
Count: vc.Count,
}
}
|
[
"func",
"(",
"vc",
"*",
"ValCount",
")",
"smaller",
"(",
"other",
"ValCount",
")",
"ValCount",
"{",
"if",
"vc",
".",
"Count",
"==",
"0",
"||",
"(",
"other",
".",
"Val",
"<",
"vc",
".",
"Val",
"&&",
"other",
".",
"Count",
">",
"0",
")",
"{",
"return",
"other",
"\n",
"}",
"\n",
"return",
"ValCount",
"{",
"Val",
":",
"vc",
".",
"Val",
",",
"Count",
":",
"vc",
".",
"Count",
",",
"}",
"\n",
"}"
] |
// smaller returns the smaller of the two ValCounts.
|
[
"smaller",
"returns",
"the",
"smaller",
"of",
"the",
"two",
"ValCounts",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L2776-L2784
|
train
|
pilosa/pilosa
|
executor.go
|
larger
|
func (vc *ValCount) larger(other ValCount) ValCount {
if vc.Count == 0 || (other.Val > vc.Val && other.Count > 0) {
return other
}
return ValCount{
Val: vc.Val,
Count: vc.Count,
}
}
|
go
|
func (vc *ValCount) larger(other ValCount) ValCount {
if vc.Count == 0 || (other.Val > vc.Val && other.Count > 0) {
return other
}
return ValCount{
Val: vc.Val,
Count: vc.Count,
}
}
|
[
"func",
"(",
"vc",
"*",
"ValCount",
")",
"larger",
"(",
"other",
"ValCount",
")",
"ValCount",
"{",
"if",
"vc",
".",
"Count",
"==",
"0",
"||",
"(",
"other",
".",
"Val",
">",
"vc",
".",
"Val",
"&&",
"other",
".",
"Count",
">",
"0",
")",
"{",
"return",
"other",
"\n",
"}",
"\n",
"return",
"ValCount",
"{",
"Val",
":",
"vc",
".",
"Val",
",",
"Count",
":",
"vc",
".",
"Count",
",",
"}",
"\n",
"}"
] |
// larger returns the larger of the two ValCounts.
|
[
"larger",
"returns",
"the",
"larger",
"of",
"the",
"two",
"ValCounts",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L2787-L2795
|
train
|
pilosa/pilosa
|
executor.go
|
nextAtIdx
|
func (gbi *groupByIterator) nextAtIdx(i int) {
// loop until we find a non-empty row. This is an optimization - the loop and if/break can be removed.
for {
nr, rowID, wrapped := gbi.rowIters[i].Next()
if nr == nil {
gbi.done = true
return
}
if wrapped && i != 0 {
gbi.nextAtIdx(i - 1)
}
if i == 0 && gbi.filter != nil {
gbi.rows[i].row = nr.Intersect(gbi.filter)
} else if i == 0 || i == len(gbi.rows)-1 {
gbi.rows[i].row = nr
} else {
gbi.rows[i].row = nr.Intersect(gbi.rows[i-1].row)
}
gbi.rows[i].id = rowID
if !gbi.rows[i].row.IsEmpty() {
break
}
}
}
|
go
|
func (gbi *groupByIterator) nextAtIdx(i int) {
// loop until we find a non-empty row. This is an optimization - the loop and if/break can be removed.
for {
nr, rowID, wrapped := gbi.rowIters[i].Next()
if nr == nil {
gbi.done = true
return
}
if wrapped && i != 0 {
gbi.nextAtIdx(i - 1)
}
if i == 0 && gbi.filter != nil {
gbi.rows[i].row = nr.Intersect(gbi.filter)
} else if i == 0 || i == len(gbi.rows)-1 {
gbi.rows[i].row = nr
} else {
gbi.rows[i].row = nr.Intersect(gbi.rows[i-1].row)
}
gbi.rows[i].id = rowID
if !gbi.rows[i].row.IsEmpty() {
break
}
}
}
|
[
"func",
"(",
"gbi",
"*",
"groupByIterator",
")",
"nextAtIdx",
"(",
"i",
"int",
")",
"{",
"// loop until we find a non-empty row. This is an optimization - the loop and if/break can be removed.",
"for",
"{",
"nr",
",",
"rowID",
",",
"wrapped",
":=",
"gbi",
".",
"rowIters",
"[",
"i",
"]",
".",
"Next",
"(",
")",
"\n",
"if",
"nr",
"==",
"nil",
"{",
"gbi",
".",
"done",
"=",
"true",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"wrapped",
"&&",
"i",
"!=",
"0",
"{",
"gbi",
".",
"nextAtIdx",
"(",
"i",
"-",
"1",
")",
"\n",
"}",
"\n",
"if",
"i",
"==",
"0",
"&&",
"gbi",
".",
"filter",
"!=",
"nil",
"{",
"gbi",
".",
"rows",
"[",
"i",
"]",
".",
"row",
"=",
"nr",
".",
"Intersect",
"(",
"gbi",
".",
"filter",
")",
"\n",
"}",
"else",
"if",
"i",
"==",
"0",
"||",
"i",
"==",
"len",
"(",
"gbi",
".",
"rows",
")",
"-",
"1",
"{",
"gbi",
".",
"rows",
"[",
"i",
"]",
".",
"row",
"=",
"nr",
"\n",
"}",
"else",
"{",
"gbi",
".",
"rows",
"[",
"i",
"]",
".",
"row",
"=",
"nr",
".",
"Intersect",
"(",
"gbi",
".",
"rows",
"[",
"i",
"-",
"1",
"]",
".",
"row",
")",
"\n",
"}",
"\n",
"gbi",
".",
"rows",
"[",
"i",
"]",
".",
"id",
"=",
"rowID",
"\n\n",
"if",
"!",
"gbi",
".",
"rows",
"[",
"i",
"]",
".",
"row",
".",
"IsEmpty",
"(",
")",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// nextAtIdx is a recursive helper method for getting the next row for the field
// at index i, and then updating the rows in the "higher" fields if it wraps.
|
[
"nextAtIdx",
"is",
"a",
"recursive",
"helper",
"method",
"for",
"getting",
"the",
"next",
"row",
"for",
"the",
"field",
"at",
"index",
"i",
"and",
"then",
"updating",
"the",
"rows",
"in",
"the",
"higher",
"fields",
"if",
"it",
"wraps",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L2939-L2963
|
train
|
pilosa/pilosa
|
executor.go
|
Next
|
func (gbi *groupByIterator) Next() (ret GroupCount, done bool) {
// loop until we find a result with count > 0
for {
if gbi.done {
return ret, true
}
if len(gbi.rows) == 1 {
ret.Count = gbi.rows[len(gbi.rows)-1].row.Count()
} else {
ret.Count = gbi.rows[len(gbi.rows)-1].row.intersectionCount(gbi.rows[len(gbi.rows)-2].row)
}
if ret.Count == 0 {
gbi.nextAtIdx(len(gbi.rows) - 1)
continue
}
break
}
ret.Group = make([]FieldRow, len(gbi.rows))
copy(ret.Group, gbi.fields)
for i, r := range gbi.rows {
ret.Group[i].RowID = r.id
}
// set up for next call
gbi.nextAtIdx(len(gbi.rows) - 1)
return ret, false
}
|
go
|
func (gbi *groupByIterator) Next() (ret GroupCount, done bool) {
// loop until we find a result with count > 0
for {
if gbi.done {
return ret, true
}
if len(gbi.rows) == 1 {
ret.Count = gbi.rows[len(gbi.rows)-1].row.Count()
} else {
ret.Count = gbi.rows[len(gbi.rows)-1].row.intersectionCount(gbi.rows[len(gbi.rows)-2].row)
}
if ret.Count == 0 {
gbi.nextAtIdx(len(gbi.rows) - 1)
continue
}
break
}
ret.Group = make([]FieldRow, len(gbi.rows))
copy(ret.Group, gbi.fields)
for i, r := range gbi.rows {
ret.Group[i].RowID = r.id
}
// set up for next call
gbi.nextAtIdx(len(gbi.rows) - 1)
return ret, false
}
|
[
"func",
"(",
"gbi",
"*",
"groupByIterator",
")",
"Next",
"(",
")",
"(",
"ret",
"GroupCount",
",",
"done",
"bool",
")",
"{",
"// loop until we find a result with count > 0",
"for",
"{",
"if",
"gbi",
".",
"done",
"{",
"return",
"ret",
",",
"true",
"\n",
"}",
"\n",
"if",
"len",
"(",
"gbi",
".",
"rows",
")",
"==",
"1",
"{",
"ret",
".",
"Count",
"=",
"gbi",
".",
"rows",
"[",
"len",
"(",
"gbi",
".",
"rows",
")",
"-",
"1",
"]",
".",
"row",
".",
"Count",
"(",
")",
"\n",
"}",
"else",
"{",
"ret",
".",
"Count",
"=",
"gbi",
".",
"rows",
"[",
"len",
"(",
"gbi",
".",
"rows",
")",
"-",
"1",
"]",
".",
"row",
".",
"intersectionCount",
"(",
"gbi",
".",
"rows",
"[",
"len",
"(",
"gbi",
".",
"rows",
")",
"-",
"2",
"]",
".",
"row",
")",
"\n",
"}",
"\n",
"if",
"ret",
".",
"Count",
"==",
"0",
"{",
"gbi",
".",
"nextAtIdx",
"(",
"len",
"(",
"gbi",
".",
"rows",
")",
"-",
"1",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n\n",
"ret",
".",
"Group",
"=",
"make",
"(",
"[",
"]",
"FieldRow",
",",
"len",
"(",
"gbi",
".",
"rows",
")",
")",
"\n",
"copy",
"(",
"ret",
".",
"Group",
",",
"gbi",
".",
"fields",
")",
"\n",
"for",
"i",
",",
"r",
":=",
"range",
"gbi",
".",
"rows",
"{",
"ret",
".",
"Group",
"[",
"i",
"]",
".",
"RowID",
"=",
"r",
".",
"id",
"\n",
"}",
"\n\n",
"// set up for next call",
"gbi",
".",
"nextAtIdx",
"(",
"len",
"(",
"gbi",
".",
"rows",
")",
"-",
"1",
")",
"\n\n",
"return",
"ret",
",",
"false",
"\n",
"}"
] |
// Next returns a GroupCount representing the next group by record. When there
// are no more records it will return an empty GroupCount and done==true.
|
[
"Next",
"returns",
"a",
"GroupCount",
"representing",
"the",
"next",
"group",
"by",
"record",
".",
"When",
"there",
"are",
"no",
"more",
"records",
"it",
"will",
"return",
"an",
"empty",
"GroupCount",
"and",
"done",
"==",
"true",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/executor.go#L2967-L2996
|
train
|
pilosa/pilosa
|
diagnostics.go
|
SetVersion
|
func (d *diagnosticsCollector) SetVersion(v string) {
d.version = v
d.Set("Version", v)
}
|
go
|
func (d *diagnosticsCollector) SetVersion(v string) {
d.version = v
d.Set("Version", v)
}
|
[
"func",
"(",
"d",
"*",
"diagnosticsCollector",
")",
"SetVersion",
"(",
"v",
"string",
")",
"{",
"d",
".",
"version",
"=",
"v",
"\n",
"d",
".",
"Set",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}"
] |
// SetVersion of locally running Pilosa Cluster to check against master.
|
[
"SetVersion",
"of",
"locally",
"running",
"Pilosa",
"Cluster",
"to",
"check",
"against",
"master",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/diagnostics.go#L74-L77
|
train
|
pilosa/pilosa
|
diagnostics.go
|
Flush
|
func (d *diagnosticsCollector) Flush() error {
d.mu.Lock()
defer d.mu.Unlock()
d.metrics["Uptime"] = (time.Now().Unix() - d.startTime)
buf, err := d.encode()
if err != nil {
return errors.Wrap(err, "encoding")
}
req, err := http.NewRequest("POST", d.host, bytes.NewReader(buf))
if err != nil {
return errors.Wrap(err, "making new request")
}
req.Header.Set("Content-Type", "application/json")
resp, err := d.client.Do(req)
if err != nil {
return errors.Wrap(err, "posting")
}
// Intentionally ignoring response body, as user does not need to be notified of error.
defer resp.Body.Close()
return nil
}
|
go
|
func (d *diagnosticsCollector) Flush() error {
d.mu.Lock()
defer d.mu.Unlock()
d.metrics["Uptime"] = (time.Now().Unix() - d.startTime)
buf, err := d.encode()
if err != nil {
return errors.Wrap(err, "encoding")
}
req, err := http.NewRequest("POST", d.host, bytes.NewReader(buf))
if err != nil {
return errors.Wrap(err, "making new request")
}
req.Header.Set("Content-Type", "application/json")
resp, err := d.client.Do(req)
if err != nil {
return errors.Wrap(err, "posting")
}
// Intentionally ignoring response body, as user does not need to be notified of error.
defer resp.Body.Close()
return nil
}
|
[
"func",
"(",
"d",
"*",
"diagnosticsCollector",
")",
"Flush",
"(",
")",
"error",
"{",
"d",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"d",
".",
"metrics",
"[",
"\"",
"\"",
"]",
"=",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Unix",
"(",
")",
"-",
"d",
".",
"startTime",
")",
"\n",
"buf",
",",
"err",
":=",
"d",
".",
"encode",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"d",
".",
"host",
",",
"bytes",
".",
"NewReader",
"(",
"buf",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"resp",
",",
"err",
":=",
"d",
".",
"client",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// Intentionally ignoring response body, as user does not need to be notified of error.",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Flush sends the current metrics.
|
[
"Flush",
"sends",
"the",
"current",
"metrics",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/diagnostics.go#L80-L100
|
train
|
pilosa/pilosa
|
diagnostics.go
|
CheckVersion
|
func (d *diagnosticsCollector) CheckVersion() error {
var rsp versionResponse
req, err := http.NewRequest("GET", d.VersionURL, nil)
if err != nil {
return errors.Wrap(err, "making request")
}
resp, err := d.client.Do(req)
if err != nil {
return errors.Wrap(err, "getting version")
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("http: status=%d", resp.StatusCode)
} else if err := json.NewDecoder(resp.Body).Decode(&rsp); err != nil {
return fmt.Errorf("json decode: %s", err)
}
// If version has not changed since the last check, return
if rsp.Version == d.lastVersion {
return nil
}
d.lastVersion = rsp.Version
if err := d.compareVersion(rsp.Version); err != nil {
d.Logger.Printf("%s\n", err.Error())
}
return nil
}
|
go
|
func (d *diagnosticsCollector) CheckVersion() error {
var rsp versionResponse
req, err := http.NewRequest("GET", d.VersionURL, nil)
if err != nil {
return errors.Wrap(err, "making request")
}
resp, err := d.client.Do(req)
if err != nil {
return errors.Wrap(err, "getting version")
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("http: status=%d", resp.StatusCode)
} else if err := json.NewDecoder(resp.Body).Decode(&rsp); err != nil {
return fmt.Errorf("json decode: %s", err)
}
// If version has not changed since the last check, return
if rsp.Version == d.lastVersion {
return nil
}
d.lastVersion = rsp.Version
if err := d.compareVersion(rsp.Version); err != nil {
d.Logger.Printf("%s\n", err.Error())
}
return nil
}
|
[
"func",
"(",
"d",
"*",
"diagnosticsCollector",
")",
"CheckVersion",
"(",
")",
"error",
"{",
"var",
"rsp",
"versionResponse",
"\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"d",
".",
"VersionURL",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"resp",
",",
"err",
":=",
"d",
".",
"client",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"StatusCode",
")",
"\n",
"}",
"else",
"if",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"resp",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"rsp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// If version has not changed since the last check, return",
"if",
"rsp",
".",
"Version",
"==",
"d",
".",
"lastVersion",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"d",
".",
"lastVersion",
"=",
"rsp",
".",
"Version",
"\n",
"if",
"err",
":=",
"d",
".",
"compareVersion",
"(",
"rsp",
".",
"Version",
")",
";",
"err",
"!=",
"nil",
"{",
"d",
".",
"Logger",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// CheckVersion of the local build against Pilosa master.
|
[
"CheckVersion",
"of",
"the",
"local",
"build",
"against",
"Pilosa",
"master",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/diagnostics.go#L103-L132
|
train
|
pilosa/pilosa
|
diagnostics.go
|
compareVersion
|
func (d *diagnosticsCollector) compareVersion(value string) error {
currentVersion := versionSegments(value)
localVersion := versionSegments(d.version)
if localVersion[0] < currentVersion[0] { //Major
return fmt.Errorf("you are running Pilosa %s, a newer version (%s) is available: https://github.com/pilosa/pilosa/releases", d.version, value)
} else if localVersion[1] < currentVersion[1] && localVersion[0] == currentVersion[0] { // Minor
return fmt.Errorf("you are running Pilosa %s, the latest minor release is %s: https://github.com/pilosa/pilosa/releases", d.version, value)
} else if localVersion[2] < currentVersion[2] && localVersion[0] == currentVersion[0] && localVersion[1] == currentVersion[1] { // Patch
return fmt.Errorf("there is a new patch release of Pilosa available: %s: https://github.com/pilosa/pilosa/releases", value)
}
return nil
}
|
go
|
func (d *diagnosticsCollector) compareVersion(value string) error {
currentVersion := versionSegments(value)
localVersion := versionSegments(d.version)
if localVersion[0] < currentVersion[0] { //Major
return fmt.Errorf("you are running Pilosa %s, a newer version (%s) is available: https://github.com/pilosa/pilosa/releases", d.version, value)
} else if localVersion[1] < currentVersion[1] && localVersion[0] == currentVersion[0] { // Minor
return fmt.Errorf("you are running Pilosa %s, the latest minor release is %s: https://github.com/pilosa/pilosa/releases", d.version, value)
} else if localVersion[2] < currentVersion[2] && localVersion[0] == currentVersion[0] && localVersion[1] == currentVersion[1] { // Patch
return fmt.Errorf("there is a new patch release of Pilosa available: %s: https://github.com/pilosa/pilosa/releases", value)
}
return nil
}
|
[
"func",
"(",
"d",
"*",
"diagnosticsCollector",
")",
"compareVersion",
"(",
"value",
"string",
")",
"error",
"{",
"currentVersion",
":=",
"versionSegments",
"(",
"value",
")",
"\n",
"localVersion",
":=",
"versionSegments",
"(",
"d",
".",
"version",
")",
"\n\n",
"if",
"localVersion",
"[",
"0",
"]",
"<",
"currentVersion",
"[",
"0",
"]",
"{",
"//Major",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"d",
".",
"version",
",",
"value",
")",
"\n",
"}",
"else",
"if",
"localVersion",
"[",
"1",
"]",
"<",
"currentVersion",
"[",
"1",
"]",
"&&",
"localVersion",
"[",
"0",
"]",
"==",
"currentVersion",
"[",
"0",
"]",
"{",
"// Minor",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"d",
".",
"version",
",",
"value",
")",
"\n",
"}",
"else",
"if",
"localVersion",
"[",
"2",
"]",
"<",
"currentVersion",
"[",
"2",
"]",
"&&",
"localVersion",
"[",
"0",
"]",
"==",
"currentVersion",
"[",
"0",
"]",
"&&",
"localVersion",
"[",
"1",
"]",
"==",
"currentVersion",
"[",
"1",
"]",
"{",
"// Patch",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"value",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// compareVersion check version strings.
|
[
"compareVersion",
"check",
"version",
"strings",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/diagnostics.go#L135-L148
|
train
|
pilosa/pilosa
|
diagnostics.go
|
Set
|
func (d *diagnosticsCollector) Set(name string, value interface{}) {
switch v := value.(type) {
case string:
if v == "" {
// Do not set empty string
return
}
}
d.mu.Lock()
defer d.mu.Unlock()
d.metrics[name] = value
}
|
go
|
func (d *diagnosticsCollector) Set(name string, value interface{}) {
switch v := value.(type) {
case string:
if v == "" {
// Do not set empty string
return
}
}
d.mu.Lock()
defer d.mu.Unlock()
d.metrics[name] = value
}
|
[
"func",
"(",
"d",
"*",
"diagnosticsCollector",
")",
"Set",
"(",
"name",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"switch",
"v",
":=",
"value",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"if",
"v",
"==",
"\"",
"\"",
"{",
"// Do not set empty string",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"d",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"d",
".",
"metrics",
"[",
"name",
"]",
"=",
"value",
"\n",
"}"
] |
// Set adds a key value metric.
|
[
"Set",
"adds",
"a",
"key",
"value",
"metric",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/diagnostics.go#L156-L167
|
train
|
pilosa/pilosa
|
diagnostics.go
|
logErr
|
func (d *diagnosticsCollector) logErr(err error) bool {
if err != nil {
d.Logger.Printf("%v", err)
return true
}
return false
}
|
go
|
func (d *diagnosticsCollector) logErr(err error) bool {
if err != nil {
d.Logger.Printf("%v", err)
return true
}
return false
}
|
[
"func",
"(",
"d",
"*",
"diagnosticsCollector",
")",
"logErr",
"(",
"err",
"error",
")",
"bool",
"{",
"if",
"err",
"!=",
"nil",
"{",
"d",
".",
"Logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// logErr logs the error and returns true if an error exists
|
[
"logErr",
"logs",
"the",
"error",
"and",
"returns",
"true",
"if",
"an",
"error",
"exists"
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/diagnostics.go#L170-L176
|
train
|
pilosa/pilosa
|
diagnostics.go
|
EnrichWithOSInfo
|
func (d *diagnosticsCollector) EnrichWithOSInfo() {
uptime, err := d.server.systemInfo.Uptime()
if !d.logErr(err) {
d.Set("HostUptime", uptime)
}
platform, err := d.server.systemInfo.Platform()
if !d.logErr(err) {
d.Set("OSPlatform", platform)
}
family, err := d.server.systemInfo.Family()
if !d.logErr(err) {
d.Set("OSFamily", family)
}
version, err := d.server.systemInfo.OSVersion()
if !d.logErr(err) {
d.Set("OSVersion", version)
}
kernelVersion, err := d.server.systemInfo.KernelVersion()
if !d.logErr(err) {
d.Set("OSKernelVersion", kernelVersion)
}
}
|
go
|
func (d *diagnosticsCollector) EnrichWithOSInfo() {
uptime, err := d.server.systemInfo.Uptime()
if !d.logErr(err) {
d.Set("HostUptime", uptime)
}
platform, err := d.server.systemInfo.Platform()
if !d.logErr(err) {
d.Set("OSPlatform", platform)
}
family, err := d.server.systemInfo.Family()
if !d.logErr(err) {
d.Set("OSFamily", family)
}
version, err := d.server.systemInfo.OSVersion()
if !d.logErr(err) {
d.Set("OSVersion", version)
}
kernelVersion, err := d.server.systemInfo.KernelVersion()
if !d.logErr(err) {
d.Set("OSKernelVersion", kernelVersion)
}
}
|
[
"func",
"(",
"d",
"*",
"diagnosticsCollector",
")",
"EnrichWithOSInfo",
"(",
")",
"{",
"uptime",
",",
"err",
":=",
"d",
".",
"server",
".",
"systemInfo",
".",
"Uptime",
"(",
")",
"\n",
"if",
"!",
"d",
".",
"logErr",
"(",
"err",
")",
"{",
"d",
".",
"Set",
"(",
"\"",
"\"",
",",
"uptime",
")",
"\n",
"}",
"\n",
"platform",
",",
"err",
":=",
"d",
".",
"server",
".",
"systemInfo",
".",
"Platform",
"(",
")",
"\n",
"if",
"!",
"d",
".",
"logErr",
"(",
"err",
")",
"{",
"d",
".",
"Set",
"(",
"\"",
"\"",
",",
"platform",
")",
"\n",
"}",
"\n",
"family",
",",
"err",
":=",
"d",
".",
"server",
".",
"systemInfo",
".",
"Family",
"(",
")",
"\n",
"if",
"!",
"d",
".",
"logErr",
"(",
"err",
")",
"{",
"d",
".",
"Set",
"(",
"\"",
"\"",
",",
"family",
")",
"\n",
"}",
"\n",
"version",
",",
"err",
":=",
"d",
".",
"server",
".",
"systemInfo",
".",
"OSVersion",
"(",
")",
"\n",
"if",
"!",
"d",
".",
"logErr",
"(",
"err",
")",
"{",
"d",
".",
"Set",
"(",
"\"",
"\"",
",",
"version",
")",
"\n",
"}",
"\n",
"kernelVersion",
",",
"err",
":=",
"d",
".",
"server",
".",
"systemInfo",
".",
"KernelVersion",
"(",
")",
"\n",
"if",
"!",
"d",
".",
"logErr",
"(",
"err",
")",
"{",
"d",
".",
"Set",
"(",
"\"",
"\"",
",",
"kernelVersion",
")",
"\n",
"}",
"\n",
"}"
] |
// EnrichWithOSInfo adds OS information to the diagnostics payload.
|
[
"EnrichWithOSInfo",
"adds",
"OS",
"information",
"to",
"the",
"diagnostics",
"payload",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/diagnostics.go#L184-L205
|
train
|
pilosa/pilosa
|
diagnostics.go
|
EnrichWithMemoryInfo
|
func (d *diagnosticsCollector) EnrichWithMemoryInfo() {
memFree, err := d.server.systemInfo.MemFree()
if !d.logErr(err) {
d.Set("MemFree", memFree)
}
memTotal, err := d.server.systemInfo.MemTotal()
if !d.logErr(err) {
d.Set("MemTotal", memTotal)
}
memUsed, err := d.server.systemInfo.MemUsed()
if !d.logErr(err) {
d.Set("MemUsed", memUsed)
}
}
|
go
|
func (d *diagnosticsCollector) EnrichWithMemoryInfo() {
memFree, err := d.server.systemInfo.MemFree()
if !d.logErr(err) {
d.Set("MemFree", memFree)
}
memTotal, err := d.server.systemInfo.MemTotal()
if !d.logErr(err) {
d.Set("MemTotal", memTotal)
}
memUsed, err := d.server.systemInfo.MemUsed()
if !d.logErr(err) {
d.Set("MemUsed", memUsed)
}
}
|
[
"func",
"(",
"d",
"*",
"diagnosticsCollector",
")",
"EnrichWithMemoryInfo",
"(",
")",
"{",
"memFree",
",",
"err",
":=",
"d",
".",
"server",
".",
"systemInfo",
".",
"MemFree",
"(",
")",
"\n",
"if",
"!",
"d",
".",
"logErr",
"(",
"err",
")",
"{",
"d",
".",
"Set",
"(",
"\"",
"\"",
",",
"memFree",
")",
"\n",
"}",
"\n",
"memTotal",
",",
"err",
":=",
"d",
".",
"server",
".",
"systemInfo",
".",
"MemTotal",
"(",
")",
"\n",
"if",
"!",
"d",
".",
"logErr",
"(",
"err",
")",
"{",
"d",
".",
"Set",
"(",
"\"",
"\"",
",",
"memTotal",
")",
"\n",
"}",
"\n",
"memUsed",
",",
"err",
":=",
"d",
".",
"server",
".",
"systemInfo",
".",
"MemUsed",
"(",
")",
"\n",
"if",
"!",
"d",
".",
"logErr",
"(",
"err",
")",
"{",
"d",
".",
"Set",
"(",
"\"",
"\"",
",",
"memUsed",
")",
"\n",
"}",
"\n",
"}"
] |
// EnrichWithMemoryInfo adds memory information to the diagnostics payload.
|
[
"EnrichWithMemoryInfo",
"adds",
"memory",
"information",
"to",
"the",
"diagnostics",
"payload",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/diagnostics.go#L208-L221
|
train
|
pilosa/pilosa
|
diagnostics.go
|
EnrichWithSchemaProperties
|
func (d *diagnosticsCollector) EnrichWithSchemaProperties() {
var numShards uint64
numFields := 0
numIndexes := 0
bsiFieldCount := 0
timeQuantumEnabled := false
for _, index := range d.server.holder.Indexes() {
numShards += index.AvailableShards().Count()
numIndexes++
for _, field := range index.Fields() {
numFields++
if field.Type() == FieldTypeInt {
bsiFieldCount++
}
if field.TimeQuantum() != "" {
timeQuantumEnabled = true
}
}
}
d.Set("NumIndexes", numIndexes)
d.Set("NumFields", numFields)
d.Set("NumShards", numShards)
d.Set("BSIFieldCount", bsiFieldCount)
d.Set("TimeQuantumEnabled", timeQuantumEnabled)
}
|
go
|
func (d *diagnosticsCollector) EnrichWithSchemaProperties() {
var numShards uint64
numFields := 0
numIndexes := 0
bsiFieldCount := 0
timeQuantumEnabled := false
for _, index := range d.server.holder.Indexes() {
numShards += index.AvailableShards().Count()
numIndexes++
for _, field := range index.Fields() {
numFields++
if field.Type() == FieldTypeInt {
bsiFieldCount++
}
if field.TimeQuantum() != "" {
timeQuantumEnabled = true
}
}
}
d.Set("NumIndexes", numIndexes)
d.Set("NumFields", numFields)
d.Set("NumShards", numShards)
d.Set("BSIFieldCount", bsiFieldCount)
d.Set("TimeQuantumEnabled", timeQuantumEnabled)
}
|
[
"func",
"(",
"d",
"*",
"diagnosticsCollector",
")",
"EnrichWithSchemaProperties",
"(",
")",
"{",
"var",
"numShards",
"uint64",
"\n",
"numFields",
":=",
"0",
"\n",
"numIndexes",
":=",
"0",
"\n",
"bsiFieldCount",
":=",
"0",
"\n",
"timeQuantumEnabled",
":=",
"false",
"\n\n",
"for",
"_",
",",
"index",
":=",
"range",
"d",
".",
"server",
".",
"holder",
".",
"Indexes",
"(",
")",
"{",
"numShards",
"+=",
"index",
".",
"AvailableShards",
"(",
")",
".",
"Count",
"(",
")",
"\n",
"numIndexes",
"++",
"\n",
"for",
"_",
",",
"field",
":=",
"range",
"index",
".",
"Fields",
"(",
")",
"{",
"numFields",
"++",
"\n",
"if",
"field",
".",
"Type",
"(",
")",
"==",
"FieldTypeInt",
"{",
"bsiFieldCount",
"++",
"\n",
"}",
"\n",
"if",
"field",
".",
"TimeQuantum",
"(",
")",
"!=",
"\"",
"\"",
"{",
"timeQuantumEnabled",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"d",
".",
"Set",
"(",
"\"",
"\"",
",",
"numIndexes",
")",
"\n",
"d",
".",
"Set",
"(",
"\"",
"\"",
",",
"numFields",
")",
"\n",
"d",
".",
"Set",
"(",
"\"",
"\"",
",",
"numShards",
")",
"\n",
"d",
".",
"Set",
"(",
"\"",
"\"",
",",
"bsiFieldCount",
")",
"\n",
"d",
".",
"Set",
"(",
"\"",
"\"",
",",
"timeQuantumEnabled",
")",
"\n",
"}"
] |
// EnrichWithSchemaProperties adds schema info to the diagnostics payload.
|
[
"EnrichWithSchemaProperties",
"adds",
"schema",
"info",
"to",
"the",
"diagnostics",
"payload",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/diagnostics.go#L224-L250
|
train
|
pilosa/pilosa
|
diagnostics.go
|
versionSegments
|
func versionSegments(segments string) []int {
segments = strings.Trim(segments, "v")
segments = strings.Split(segments, "-")[0]
s := strings.Split(segments, ".")
segmentSlice := make([]int, len(s))
for i, v := range s {
segmentSlice[i], _ = strconv.Atoi(v)
}
return segmentSlice
}
|
go
|
func versionSegments(segments string) []int {
segments = strings.Trim(segments, "v")
segments = strings.Split(segments, "-")[0]
s := strings.Split(segments, ".")
segmentSlice := make([]int, len(s))
for i, v := range s {
segmentSlice[i], _ = strconv.Atoi(v)
}
return segmentSlice
}
|
[
"func",
"versionSegments",
"(",
"segments",
"string",
")",
"[",
"]",
"int",
"{",
"segments",
"=",
"strings",
".",
"Trim",
"(",
"segments",
",",
"\"",
"\"",
")",
"\n",
"segments",
"=",
"strings",
".",
"Split",
"(",
"segments",
",",
"\"",
"\"",
")",
"[",
"0",
"]",
"\n",
"s",
":=",
"strings",
".",
"Split",
"(",
"segments",
",",
"\"",
"\"",
")",
"\n",
"segmentSlice",
":=",
"make",
"(",
"[",
"]",
"int",
",",
"len",
"(",
"s",
")",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"s",
"{",
"segmentSlice",
"[",
"i",
"]",
",",
"_",
"=",
"strconv",
".",
"Atoi",
"(",
"v",
")",
"\n",
"}",
"\n",
"return",
"segmentSlice",
"\n",
"}"
] |
// versionSegments returns the numeric segments of the version as a slice of ints.
|
[
"versionSegments",
"returns",
"the",
"numeric",
"segments",
"of",
"the",
"version",
"as",
"a",
"slice",
"of",
"ints",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/diagnostics.go#L253-L262
|
train
|
pilosa/pilosa
|
roaring/container_stash.go
|
NewContainer
|
func NewContainer() *Container {
statsHit("NewContainer")
c := &Container{typ: containerArray, len: 0, cap: stashedArraySize}
c.pointer = (*uint16)(unsafe.Pointer(&c.data[0]))
return c
}
|
go
|
func NewContainer() *Container {
statsHit("NewContainer")
c := &Container{typ: containerArray, len: 0, cap: stashedArraySize}
c.pointer = (*uint16)(unsafe.Pointer(&c.data[0]))
return c
}
|
[
"func",
"NewContainer",
"(",
")",
"*",
"Container",
"{",
"statsHit",
"(",
"\"",
"\"",
")",
"\n",
"c",
":=",
"&",
"Container",
"{",
"typ",
":",
"containerArray",
",",
"len",
":",
"0",
",",
"cap",
":",
"stashedArraySize",
"}",
"\n",
"c",
".",
"pointer",
"=",
"(",
"*",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"c",
".",
"data",
"[",
"0",
"]",
")",
")",
"\n",
"return",
"c",
"\n",
"}"
] |
// NewContainer returns a new instance of container. This trivial function
// may later become more interesting.
|
[
"NewContainer",
"returns",
"a",
"new",
"instance",
"of",
"container",
".",
"This",
"trivial",
"function",
"may",
"later",
"become",
"more",
"interesting",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/container_stash.go#L49-L54
|
train
|
pilosa/pilosa
|
roaring/container_stash.go
|
NewContainerBitmap
|
func NewContainerBitmap(n int32, bitmap []uint64) *Container {
if bitmap == nil {
bitmap = make([]uint64, bitmapN)
}
// pad to required length
if len(bitmap) < bitmapN {
bm2 := make([]uint64, bitmapN)
copy(bm2, bitmap)
bitmap = bm2
}
c := &Container{typ: containerBitmap, n: n}
c.setBitmap(bitmap)
return c
}
|
go
|
func NewContainerBitmap(n int32, bitmap []uint64) *Container {
if bitmap == nil {
bitmap = make([]uint64, bitmapN)
}
// pad to required length
if len(bitmap) < bitmapN {
bm2 := make([]uint64, bitmapN)
copy(bm2, bitmap)
bitmap = bm2
}
c := &Container{typ: containerBitmap, n: n}
c.setBitmap(bitmap)
return c
}
|
[
"func",
"NewContainerBitmap",
"(",
"n",
"int32",
",",
"bitmap",
"[",
"]",
"uint64",
")",
"*",
"Container",
"{",
"if",
"bitmap",
"==",
"nil",
"{",
"bitmap",
"=",
"make",
"(",
"[",
"]",
"uint64",
",",
"bitmapN",
")",
"\n",
"}",
"\n",
"// pad to required length",
"if",
"len",
"(",
"bitmap",
")",
"<",
"bitmapN",
"{",
"bm2",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"bitmapN",
")",
"\n",
"copy",
"(",
"bm2",
",",
"bitmap",
")",
"\n",
"bitmap",
"=",
"bm2",
"\n",
"}",
"\n",
"c",
":=",
"&",
"Container",
"{",
"typ",
":",
"containerBitmap",
",",
"n",
":",
"n",
"}",
"\n",
"c",
".",
"setBitmap",
"(",
"bitmap",
")",
"\n",
"return",
"c",
"\n",
"}"
] |
// NewContainerBitmap makes a bitmap container using the provided bitmap, or
// an empty one if provided bitmap is nil. If the provided bitmap is too short,
// it will be padded.
|
[
"NewContainerBitmap",
"makes",
"a",
"bitmap",
"container",
"using",
"the",
"provided",
"bitmap",
"or",
"an",
"empty",
"one",
"if",
"provided",
"bitmap",
"is",
"nil",
".",
"If",
"the",
"provided",
"bitmap",
"is",
"too",
"short",
"it",
"will",
"be",
"padded",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/container_stash.go#L59-L72
|
train
|
pilosa/pilosa
|
roaring/container_stash.go
|
NewContainerArray
|
func NewContainerArray(set []uint16) *Container {
c := &Container{typ: containerArray, n: int32(len(set))}
c.setArray(set)
return c
}
|
go
|
func NewContainerArray(set []uint16) *Container {
c := &Container{typ: containerArray, n: int32(len(set))}
c.setArray(set)
return c
}
|
[
"func",
"NewContainerArray",
"(",
"set",
"[",
"]",
"uint16",
")",
"*",
"Container",
"{",
"c",
":=",
"&",
"Container",
"{",
"typ",
":",
"containerArray",
",",
"n",
":",
"int32",
"(",
"len",
"(",
"set",
")",
")",
"}",
"\n",
"c",
".",
"setArray",
"(",
"set",
")",
"\n",
"return",
"c",
"\n",
"}"
] |
// NewContainerArray returns an array using the provided set of values. It's
// okay if the slice is nil; that's a length of zero.
|
[
"NewContainerArray",
"returns",
"an",
"array",
"using",
"the",
"provided",
"set",
"of",
"values",
".",
"It",
"s",
"okay",
"if",
"the",
"slice",
"is",
"nil",
";",
"that",
"s",
"a",
"length",
"of",
"zero",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/container_stash.go#L76-L80
|
train
|
pilosa/pilosa
|
roaring/container_stash.go
|
array
|
func (c *Container) array() []uint16 {
if roaringParanoia {
if c.typ != containerArray {
panic("attempt to read non-array's array")
}
}
return *(*[]uint16)(unsafe.Pointer(&reflect.SliceHeader{Data: uintptr(unsafe.Pointer(c.pointer)), Len: int(c.len), Cap: int(c.cap)}))
}
|
go
|
func (c *Container) array() []uint16 {
if roaringParanoia {
if c.typ != containerArray {
panic("attempt to read non-array's array")
}
}
return *(*[]uint16)(unsafe.Pointer(&reflect.SliceHeader{Data: uintptr(unsafe.Pointer(c.pointer)), Len: int(c.len), Cap: int(c.cap)}))
}
|
[
"func",
"(",
"c",
"*",
"Container",
")",
"array",
"(",
")",
"[",
"]",
"uint16",
"{",
"if",
"roaringParanoia",
"{",
"if",
"c",
".",
"typ",
"!=",
"containerArray",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"*",
"(",
"*",
"[",
"]",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"reflect",
".",
"SliceHeader",
"{",
"Data",
":",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"c",
".",
"pointer",
")",
")",
",",
"Len",
":",
"int",
"(",
"c",
".",
"len",
")",
",",
"Cap",
":",
"int",
"(",
"c",
".",
"cap",
")",
"}",
")",
")",
"\n",
"}"
] |
// array yields the data viewed as a slice of uint16 values.
|
[
"array",
"yields",
"the",
"data",
"viewed",
"as",
"a",
"slice",
"of",
"uint16",
"values",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/container_stash.go#L106-L113
|
train
|
pilosa/pilosa
|
roaring/container_stash.go
|
setArray
|
func (c *Container) setArray(array []uint16) {
if roaringParanoia {
if c.typ != containerArray {
panic("attempt to write non-array's array")
}
}
// no array: start with our default 5-value array
if array == nil {
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(&c.data[0])), 0, stashedArraySize
return
}
h := (*reflect.SliceHeader)(unsafe.Pointer(&array))
if h.Data == uintptr(unsafe.Pointer(c.pointer)) {
// nothing to do but update length
c.len = int32(h.Len)
return
}
// array we can fit in data store:
if len(array) <= stashedArraySize {
copy(c.data[:stashedArraySize], array)
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(&c.data[0])), int32(len(array)), stashedArraySize
c.mapped = false // this is no longer using a hypothetical mmapped input array
return
}
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(h.Data)), int32(h.Len), int32(h.Cap)
runtime.KeepAlive(&array)
}
|
go
|
func (c *Container) setArray(array []uint16) {
if roaringParanoia {
if c.typ != containerArray {
panic("attempt to write non-array's array")
}
}
// no array: start with our default 5-value array
if array == nil {
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(&c.data[0])), 0, stashedArraySize
return
}
h := (*reflect.SliceHeader)(unsafe.Pointer(&array))
if h.Data == uintptr(unsafe.Pointer(c.pointer)) {
// nothing to do but update length
c.len = int32(h.Len)
return
}
// array we can fit in data store:
if len(array) <= stashedArraySize {
copy(c.data[:stashedArraySize], array)
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(&c.data[0])), int32(len(array)), stashedArraySize
c.mapped = false // this is no longer using a hypothetical mmapped input array
return
}
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(h.Data)), int32(h.Len), int32(h.Cap)
runtime.KeepAlive(&array)
}
|
[
"func",
"(",
"c",
"*",
"Container",
")",
"setArray",
"(",
"array",
"[",
"]",
"uint16",
")",
"{",
"if",
"roaringParanoia",
"{",
"if",
"c",
".",
"typ",
"!=",
"containerArray",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// no array: start with our default 5-value array",
"if",
"array",
"==",
"nil",
"{",
"c",
".",
"pointer",
",",
"c",
".",
"len",
",",
"c",
".",
"cap",
"=",
"(",
"*",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"c",
".",
"data",
"[",
"0",
"]",
")",
")",
",",
"0",
",",
"stashedArraySize",
"\n",
"return",
"\n",
"}",
"\n",
"h",
":=",
"(",
"*",
"reflect",
".",
"SliceHeader",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"array",
")",
")",
"\n",
"if",
"h",
".",
"Data",
"==",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"c",
".",
"pointer",
")",
")",
"{",
"// nothing to do but update length",
"c",
".",
"len",
"=",
"int32",
"(",
"h",
".",
"Len",
")",
"\n",
"return",
"\n",
"}",
"\n",
"// array we can fit in data store:",
"if",
"len",
"(",
"array",
")",
"<=",
"stashedArraySize",
"{",
"copy",
"(",
"c",
".",
"data",
"[",
":",
"stashedArraySize",
"]",
",",
"array",
")",
"\n",
"c",
".",
"pointer",
",",
"c",
".",
"len",
",",
"c",
".",
"cap",
"=",
"(",
"*",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"c",
".",
"data",
"[",
"0",
"]",
")",
")",
",",
"int32",
"(",
"len",
"(",
"array",
")",
")",
",",
"stashedArraySize",
"\n",
"c",
".",
"mapped",
"=",
"false",
"// this is no longer using a hypothetical mmapped input array",
"\n",
"return",
"\n",
"}",
"\n",
"c",
".",
"pointer",
",",
"c",
".",
"len",
",",
"c",
".",
"cap",
"=",
"(",
"*",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"h",
".",
"Data",
")",
")",
",",
"int32",
"(",
"h",
".",
"Len",
")",
",",
"int32",
"(",
"h",
".",
"Cap",
")",
"\n",
"runtime",
".",
"KeepAlive",
"(",
"&",
"array",
")",
"\n",
"}"
] |
// setArray stores a set of uint16s as data.
|
[
"setArray",
"stores",
"a",
"set",
"of",
"uint16s",
"as",
"data",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/container_stash.go#L116-L142
|
train
|
pilosa/pilosa
|
roaring/container_stash.go
|
bitmap
|
func (c *Container) bitmap() []uint64 {
if roaringParanoia {
if c.typ != containerBitmap {
panic("attempt to read non-bitmap's bitmap")
}
}
return *(*[]uint64)(unsafe.Pointer(&reflect.SliceHeader{Data: uintptr(unsafe.Pointer(c.pointer)), Len: int(c.len), Cap: int(c.cap)}))
}
|
go
|
func (c *Container) bitmap() []uint64 {
if roaringParanoia {
if c.typ != containerBitmap {
panic("attempt to read non-bitmap's bitmap")
}
}
return *(*[]uint64)(unsafe.Pointer(&reflect.SliceHeader{Data: uintptr(unsafe.Pointer(c.pointer)), Len: int(c.len), Cap: int(c.cap)}))
}
|
[
"func",
"(",
"c",
"*",
"Container",
")",
"bitmap",
"(",
")",
"[",
"]",
"uint64",
"{",
"if",
"roaringParanoia",
"{",
"if",
"c",
".",
"typ",
"!=",
"containerBitmap",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"*",
"(",
"*",
"[",
"]",
"uint64",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"reflect",
".",
"SliceHeader",
"{",
"Data",
":",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"c",
".",
"pointer",
")",
")",
",",
"Len",
":",
"int",
"(",
"c",
".",
"len",
")",
",",
"Cap",
":",
"int",
"(",
"c",
".",
"cap",
")",
"}",
")",
")",
"\n",
"}"
] |
// bitmap yields the data viewed as a slice of uint64s holding bits.
|
[
"bitmap",
"yields",
"the",
"data",
"viewed",
"as",
"a",
"slice",
"of",
"uint64s",
"holding",
"bits",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/container_stash.go#L145-L152
|
train
|
pilosa/pilosa
|
roaring/container_stash.go
|
setBitmap
|
func (c *Container) setBitmap(bitmap []uint64) {
if roaringParanoia {
if c.typ != containerBitmap {
panic("attempt to write non-bitmap's bitmap")
}
}
h := (*reflect.SliceHeader)(unsafe.Pointer(&bitmap))
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(h.Data)), int32(h.Len), int32(h.Cap)
runtime.KeepAlive(&bitmap)
}
|
go
|
func (c *Container) setBitmap(bitmap []uint64) {
if roaringParanoia {
if c.typ != containerBitmap {
panic("attempt to write non-bitmap's bitmap")
}
}
h := (*reflect.SliceHeader)(unsafe.Pointer(&bitmap))
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(h.Data)), int32(h.Len), int32(h.Cap)
runtime.KeepAlive(&bitmap)
}
|
[
"func",
"(",
"c",
"*",
"Container",
")",
"setBitmap",
"(",
"bitmap",
"[",
"]",
"uint64",
")",
"{",
"if",
"roaringParanoia",
"{",
"if",
"c",
".",
"typ",
"!=",
"containerBitmap",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"h",
":=",
"(",
"*",
"reflect",
".",
"SliceHeader",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"bitmap",
")",
")",
"\n",
"c",
".",
"pointer",
",",
"c",
".",
"len",
",",
"c",
".",
"cap",
"=",
"(",
"*",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"h",
".",
"Data",
")",
")",
",",
"int32",
"(",
"h",
".",
"Len",
")",
",",
"int32",
"(",
"h",
".",
"Cap",
")",
"\n",
"runtime",
".",
"KeepAlive",
"(",
"&",
"bitmap",
")",
"\n",
"}"
] |
// setBitmap stores a set of uint64s as data.
|
[
"setBitmap",
"stores",
"a",
"set",
"of",
"uint64s",
"as",
"data",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/container_stash.go#L155-L164
|
train
|
pilosa/pilosa
|
roaring/container_stash.go
|
runs
|
func (c *Container) runs() []interval16 {
if roaringParanoia {
if c.typ != containerRun {
panic("attempt to read non-run's runs")
}
}
return *(*[]interval16)(unsafe.Pointer(&reflect.SliceHeader{Data: uintptr(unsafe.Pointer(c.pointer)), Len: int(c.len), Cap: int(c.cap)}))
}
|
go
|
func (c *Container) runs() []interval16 {
if roaringParanoia {
if c.typ != containerRun {
panic("attempt to read non-run's runs")
}
}
return *(*[]interval16)(unsafe.Pointer(&reflect.SliceHeader{Data: uintptr(unsafe.Pointer(c.pointer)), Len: int(c.len), Cap: int(c.cap)}))
}
|
[
"func",
"(",
"c",
"*",
"Container",
")",
"runs",
"(",
")",
"[",
"]",
"interval16",
"{",
"if",
"roaringParanoia",
"{",
"if",
"c",
".",
"typ",
"!=",
"containerRun",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"*",
"(",
"*",
"[",
"]",
"interval16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"reflect",
".",
"SliceHeader",
"{",
"Data",
":",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"c",
".",
"pointer",
")",
")",
",",
"Len",
":",
"int",
"(",
"c",
".",
"len",
")",
",",
"Cap",
":",
"int",
"(",
"c",
".",
"cap",
")",
"}",
")",
")",
"\n",
"}"
] |
// runs yields the data viewed as a slice of intervals.
|
[
"runs",
"yields",
"the",
"data",
"viewed",
"as",
"a",
"slice",
"of",
"intervals",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/container_stash.go#L167-L174
|
train
|
pilosa/pilosa
|
roaring/container_stash.go
|
setRuns
|
func (c *Container) setRuns(runs []interval16) {
if roaringParanoia {
if c.typ != containerRun {
panic("attempt to write non-run's runs")
}
}
// no array: start with our default 2-value array
if runs == nil {
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(&c.data[0])), 0, stashedRunSize
return
}
h := (*reflect.SliceHeader)(unsafe.Pointer(&runs))
if h.Data == uintptr(unsafe.Pointer(c.pointer)) {
// nothing to do but update length
c.len = int32(h.Len)
return
}
// array we can fit in data store:
if len(runs) <= stashedRunSize {
newRuns := *(*[]interval16)(unsafe.Pointer(&reflect.SliceHeader{Data: uintptr(unsafe.Pointer(&c.data[0])), Len: stashedRunSize, Cap: stashedRunSize}))
copy(newRuns, runs)
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(&c.data[0])), int32(len(runs)), stashedRunSize
c.mapped = false // this is no longer using a hypothetical mmapped input array
return
}
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(h.Data)), int32(h.Len), int32(h.Cap)
runtime.KeepAlive(&runs)
}
|
go
|
func (c *Container) setRuns(runs []interval16) {
if roaringParanoia {
if c.typ != containerRun {
panic("attempt to write non-run's runs")
}
}
// no array: start with our default 2-value array
if runs == nil {
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(&c.data[0])), 0, stashedRunSize
return
}
h := (*reflect.SliceHeader)(unsafe.Pointer(&runs))
if h.Data == uintptr(unsafe.Pointer(c.pointer)) {
// nothing to do but update length
c.len = int32(h.Len)
return
}
// array we can fit in data store:
if len(runs) <= stashedRunSize {
newRuns := *(*[]interval16)(unsafe.Pointer(&reflect.SliceHeader{Data: uintptr(unsafe.Pointer(&c.data[0])), Len: stashedRunSize, Cap: stashedRunSize}))
copy(newRuns, runs)
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(&c.data[0])), int32(len(runs)), stashedRunSize
c.mapped = false // this is no longer using a hypothetical mmapped input array
return
}
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(h.Data)), int32(h.Len), int32(h.Cap)
runtime.KeepAlive(&runs)
}
|
[
"func",
"(",
"c",
"*",
"Container",
")",
"setRuns",
"(",
"runs",
"[",
"]",
"interval16",
")",
"{",
"if",
"roaringParanoia",
"{",
"if",
"c",
".",
"typ",
"!=",
"containerRun",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// no array: start with our default 2-value array",
"if",
"runs",
"==",
"nil",
"{",
"c",
".",
"pointer",
",",
"c",
".",
"len",
",",
"c",
".",
"cap",
"=",
"(",
"*",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"c",
".",
"data",
"[",
"0",
"]",
")",
")",
",",
"0",
",",
"stashedRunSize",
"\n",
"return",
"\n",
"}",
"\n",
"h",
":=",
"(",
"*",
"reflect",
".",
"SliceHeader",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"runs",
")",
")",
"\n",
"if",
"h",
".",
"Data",
"==",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"c",
".",
"pointer",
")",
")",
"{",
"// nothing to do but update length",
"c",
".",
"len",
"=",
"int32",
"(",
"h",
".",
"Len",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// array we can fit in data store:",
"if",
"len",
"(",
"runs",
")",
"<=",
"stashedRunSize",
"{",
"newRuns",
":=",
"*",
"(",
"*",
"[",
"]",
"interval16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"reflect",
".",
"SliceHeader",
"{",
"Data",
":",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"c",
".",
"data",
"[",
"0",
"]",
")",
")",
",",
"Len",
":",
"stashedRunSize",
",",
"Cap",
":",
"stashedRunSize",
"}",
")",
")",
"\n",
"copy",
"(",
"newRuns",
",",
"runs",
")",
"\n",
"c",
".",
"pointer",
",",
"c",
".",
"len",
",",
"c",
".",
"cap",
"=",
"(",
"*",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"c",
".",
"data",
"[",
"0",
"]",
")",
")",
",",
"int32",
"(",
"len",
"(",
"runs",
")",
")",
",",
"stashedRunSize",
"\n",
"c",
".",
"mapped",
"=",
"false",
"// this is no longer using a hypothetical mmapped input array",
"\n",
"return",
"\n",
"}",
"\n",
"c",
".",
"pointer",
",",
"c",
".",
"len",
",",
"c",
".",
"cap",
"=",
"(",
"*",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"h",
".",
"Data",
")",
")",
",",
"int32",
"(",
"h",
".",
"Len",
")",
",",
"int32",
"(",
"h",
".",
"Cap",
")",
"\n",
"runtime",
".",
"KeepAlive",
"(",
"&",
"runs",
")",
"\n",
"}"
] |
// setRuns stores a set of intervals as data.
|
[
"setRuns",
"stores",
"a",
"set",
"of",
"intervals",
"as",
"data",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/container_stash.go#L177-L205
|
train
|
pilosa/pilosa
|
roaring/container_stash.go
|
Update
|
func (c *Container) Update(typ byte, n int32, mapped bool) {
c.typ = typ
c.n = n
c.mapped = mapped
// we don't know that any existing slice is usable, so let's ditch it
switch c.typ {
case containerArray:
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(&c.data[0])), int32(0), stashedArraySize
case containerRun:
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(&c.data[0])), 0, stashedRunSize
default:
c.pointer, c.len, c.cap = nil, 0, 0
}
}
|
go
|
func (c *Container) Update(typ byte, n int32, mapped bool) {
c.typ = typ
c.n = n
c.mapped = mapped
// we don't know that any existing slice is usable, so let's ditch it
switch c.typ {
case containerArray:
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(&c.data[0])), int32(0), stashedArraySize
case containerRun:
c.pointer, c.len, c.cap = (*uint16)(unsafe.Pointer(&c.data[0])), 0, stashedRunSize
default:
c.pointer, c.len, c.cap = nil, 0, 0
}
}
|
[
"func",
"(",
"c",
"*",
"Container",
")",
"Update",
"(",
"typ",
"byte",
",",
"n",
"int32",
",",
"mapped",
"bool",
")",
"{",
"c",
".",
"typ",
"=",
"typ",
"\n",
"c",
".",
"n",
"=",
"n",
"\n",
"c",
".",
"mapped",
"=",
"mapped",
"\n",
"// we don't know that any existing slice is usable, so let's ditch it",
"switch",
"c",
".",
"typ",
"{",
"case",
"containerArray",
":",
"c",
".",
"pointer",
",",
"c",
".",
"len",
",",
"c",
".",
"cap",
"=",
"(",
"*",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"c",
".",
"data",
"[",
"0",
"]",
")",
")",
",",
"int32",
"(",
"0",
")",
",",
"stashedArraySize",
"\n",
"case",
"containerRun",
":",
"c",
".",
"pointer",
",",
"c",
".",
"len",
",",
"c",
".",
"cap",
"=",
"(",
"*",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"c",
".",
"data",
"[",
"0",
"]",
")",
")",
",",
"0",
",",
"stashedRunSize",
"\n",
"default",
":",
"c",
".",
"pointer",
",",
"c",
".",
"len",
",",
"c",
".",
"cap",
"=",
"nil",
",",
"0",
",",
"0",
"\n",
"}",
"\n",
"}"
] |
// Update updates the container
|
[
"Update",
"updates",
"the",
"container"
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/container_stash.go#L208-L221
|
train
|
pilosa/pilosa
|
roaring/container_stash.go
|
unmapArray
|
func (c *Container) unmapArray() {
if !c.mapped {
return
}
array := c.array()
tmp := make([]uint16, c.len)
copy(tmp, array)
h := (*reflect.SliceHeader)(unsafe.Pointer(&tmp))
c.pointer, c.cap = (*uint16)(unsafe.Pointer(h.Data)), int32(h.Cap)
runtime.KeepAlive(&tmp)
c.mapped = false
}
|
go
|
func (c *Container) unmapArray() {
if !c.mapped {
return
}
array := c.array()
tmp := make([]uint16, c.len)
copy(tmp, array)
h := (*reflect.SliceHeader)(unsafe.Pointer(&tmp))
c.pointer, c.cap = (*uint16)(unsafe.Pointer(h.Data)), int32(h.Cap)
runtime.KeepAlive(&tmp)
c.mapped = false
}
|
[
"func",
"(",
"c",
"*",
"Container",
")",
"unmapArray",
"(",
")",
"{",
"if",
"!",
"c",
".",
"mapped",
"{",
"return",
"\n",
"}",
"\n",
"array",
":=",
"c",
".",
"array",
"(",
")",
"\n",
"tmp",
":=",
"make",
"(",
"[",
"]",
"uint16",
",",
"c",
".",
"len",
")",
"\n",
"copy",
"(",
"tmp",
",",
"array",
")",
"\n",
"h",
":=",
"(",
"*",
"reflect",
".",
"SliceHeader",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"tmp",
")",
")",
"\n",
"c",
".",
"pointer",
",",
"c",
".",
"cap",
"=",
"(",
"*",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"h",
".",
"Data",
")",
")",
",",
"int32",
"(",
"h",
".",
"Cap",
")",
"\n",
"runtime",
".",
"KeepAlive",
"(",
"&",
"tmp",
")",
"\n",
"c",
".",
"mapped",
"=",
"false",
"\n",
"}"
] |
// unmapArray ensures that the container is not using mmapped storage.
|
[
"unmapArray",
"ensures",
"that",
"the",
"container",
"is",
"not",
"using",
"mmapped",
"storage",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/container_stash.go#L239-L250
|
train
|
pilosa/pilosa
|
roaring/container_stash.go
|
unmapRun
|
func (c *Container) unmapRun() {
if !c.mapped {
return
}
runs := c.runs()
tmp := make([]interval16, c.len)
copy(tmp, runs)
h := (*reflect.SliceHeader)(unsafe.Pointer(&tmp))
c.pointer, c.cap = (*uint16)(unsafe.Pointer(h.Data)), int32(h.Cap)
c.mapped = false
}
|
go
|
func (c *Container) unmapRun() {
if !c.mapped {
return
}
runs := c.runs()
tmp := make([]interval16, c.len)
copy(tmp, runs)
h := (*reflect.SliceHeader)(unsafe.Pointer(&tmp))
c.pointer, c.cap = (*uint16)(unsafe.Pointer(h.Data)), int32(h.Cap)
c.mapped = false
}
|
[
"func",
"(",
"c",
"*",
"Container",
")",
"unmapRun",
"(",
")",
"{",
"if",
"!",
"c",
".",
"mapped",
"{",
"return",
"\n",
"}",
"\n",
"runs",
":=",
"c",
".",
"runs",
"(",
")",
"\n",
"tmp",
":=",
"make",
"(",
"[",
"]",
"interval16",
",",
"c",
".",
"len",
")",
"\n",
"copy",
"(",
"tmp",
",",
"runs",
")",
"\n",
"h",
":=",
"(",
"*",
"reflect",
".",
"SliceHeader",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"tmp",
")",
")",
"\n",
"c",
".",
"pointer",
",",
"c",
".",
"cap",
"=",
"(",
"*",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"h",
".",
"Data",
")",
")",
",",
"int32",
"(",
"h",
".",
"Cap",
")",
"\n",
"c",
".",
"mapped",
"=",
"false",
"\n",
"}"
] |
// unmapRun ensures that the container is not using mmapped storage.
|
[
"unmapRun",
"ensures",
"that",
"the",
"container",
"is",
"not",
"using",
"mmapped",
"storage",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/container_stash.go#L267-L277
|
train
|
pilosa/pilosa
|
server/config.go
|
NewConfig
|
func NewConfig() *Config {
c := &Config{
DataDir: "~/.pilosa",
Bind: ":10101",
MaxWritesPerRequest: 5000,
// We default these Max File/Map counts very high. This is basically a
// backwards compatibility thing where we don't want to cause different
// behavior for those who had previously set their system limits high,
// and weren't experiencing any bad behavior. Ideally you want these set
// a bit below your system limits.
MaxMapCount: 1000000,
MaxFileCount: 1000000,
TLS: TLSConfig{},
}
// Cluster config.
c.Cluster.Disabled = false
c.Cluster.ReplicaN = 1
c.Cluster.Hosts = []string{}
c.Cluster.LongQueryTime = toml.Duration(time.Minute)
// Gossip config.
c.Gossip.Port = "14000"
c.Gossip.StreamTimeout = toml.Duration(10 * time.Second)
c.Gossip.SuspicionMult = 4
c.Gossip.PushPullInterval = toml.Duration(30 * time.Second)
c.Gossip.ProbeInterval = toml.Duration(1 * time.Second)
c.Gossip.ProbeTimeout = toml.Duration(500 * time.Millisecond)
c.Gossip.Interval = toml.Duration(200 * time.Millisecond)
c.Gossip.Nodes = 3
c.Gossip.ToTheDeadTime = toml.Duration(30 * time.Second)
// AntiEntropy config.
c.AntiEntropy.Interval = toml.Duration(10 * time.Minute)
// Metric config.
c.Metric.Service = "none"
c.Metric.PollInterval = toml.Duration(0 * time.Minute)
c.Metric.Diagnostics = true
// Tracing config.
c.Tracing.SamplerType = jaeger.SamplerTypeRemote
c.Tracing.SamplerParam = 0.001
c.Profile.BlockRate = 10000000 // 1 sample per 10 ms
c.Profile.MutexFraction = 100 // 1% sampling
return c
}
|
go
|
func NewConfig() *Config {
c := &Config{
DataDir: "~/.pilosa",
Bind: ":10101",
MaxWritesPerRequest: 5000,
// We default these Max File/Map counts very high. This is basically a
// backwards compatibility thing where we don't want to cause different
// behavior for those who had previously set their system limits high,
// and weren't experiencing any bad behavior. Ideally you want these set
// a bit below your system limits.
MaxMapCount: 1000000,
MaxFileCount: 1000000,
TLS: TLSConfig{},
}
// Cluster config.
c.Cluster.Disabled = false
c.Cluster.ReplicaN = 1
c.Cluster.Hosts = []string{}
c.Cluster.LongQueryTime = toml.Duration(time.Minute)
// Gossip config.
c.Gossip.Port = "14000"
c.Gossip.StreamTimeout = toml.Duration(10 * time.Second)
c.Gossip.SuspicionMult = 4
c.Gossip.PushPullInterval = toml.Duration(30 * time.Second)
c.Gossip.ProbeInterval = toml.Duration(1 * time.Second)
c.Gossip.ProbeTimeout = toml.Duration(500 * time.Millisecond)
c.Gossip.Interval = toml.Duration(200 * time.Millisecond)
c.Gossip.Nodes = 3
c.Gossip.ToTheDeadTime = toml.Duration(30 * time.Second)
// AntiEntropy config.
c.AntiEntropy.Interval = toml.Duration(10 * time.Minute)
// Metric config.
c.Metric.Service = "none"
c.Metric.PollInterval = toml.Duration(0 * time.Minute)
c.Metric.Diagnostics = true
// Tracing config.
c.Tracing.SamplerType = jaeger.SamplerTypeRemote
c.Tracing.SamplerParam = 0.001
c.Profile.BlockRate = 10000000 // 1 sample per 10 ms
c.Profile.MutexFraction = 100 // 1% sampling
return c
}
|
[
"func",
"NewConfig",
"(",
")",
"*",
"Config",
"{",
"c",
":=",
"&",
"Config",
"{",
"DataDir",
":",
"\"",
"\"",
",",
"Bind",
":",
"\"",
"\"",
",",
"MaxWritesPerRequest",
":",
"5000",
",",
"// We default these Max File/Map counts very high. This is basically a",
"// backwards compatibility thing where we don't want to cause different",
"// behavior for those who had previously set their system limits high,",
"// and weren't experiencing any bad behavior. Ideally you want these set",
"// a bit below your system limits.",
"MaxMapCount",
":",
"1000000",
",",
"MaxFileCount",
":",
"1000000",
",",
"TLS",
":",
"TLSConfig",
"{",
"}",
",",
"}",
"\n\n",
"// Cluster config.",
"c",
".",
"Cluster",
".",
"Disabled",
"=",
"false",
"\n",
"c",
".",
"Cluster",
".",
"ReplicaN",
"=",
"1",
"\n",
"c",
".",
"Cluster",
".",
"Hosts",
"=",
"[",
"]",
"string",
"{",
"}",
"\n",
"c",
".",
"Cluster",
".",
"LongQueryTime",
"=",
"toml",
".",
"Duration",
"(",
"time",
".",
"Minute",
")",
"\n\n",
"// Gossip config.",
"c",
".",
"Gossip",
".",
"Port",
"=",
"\"",
"\"",
"\n",
"c",
".",
"Gossip",
".",
"StreamTimeout",
"=",
"toml",
".",
"Duration",
"(",
"10",
"*",
"time",
".",
"Second",
")",
"\n",
"c",
".",
"Gossip",
".",
"SuspicionMult",
"=",
"4",
"\n",
"c",
".",
"Gossip",
".",
"PushPullInterval",
"=",
"toml",
".",
"Duration",
"(",
"30",
"*",
"time",
".",
"Second",
")",
"\n",
"c",
".",
"Gossip",
".",
"ProbeInterval",
"=",
"toml",
".",
"Duration",
"(",
"1",
"*",
"time",
".",
"Second",
")",
"\n",
"c",
".",
"Gossip",
".",
"ProbeTimeout",
"=",
"toml",
".",
"Duration",
"(",
"500",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"c",
".",
"Gossip",
".",
"Interval",
"=",
"toml",
".",
"Duration",
"(",
"200",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"c",
".",
"Gossip",
".",
"Nodes",
"=",
"3",
"\n",
"c",
".",
"Gossip",
".",
"ToTheDeadTime",
"=",
"toml",
".",
"Duration",
"(",
"30",
"*",
"time",
".",
"Second",
")",
"\n\n",
"// AntiEntropy config.",
"c",
".",
"AntiEntropy",
".",
"Interval",
"=",
"toml",
".",
"Duration",
"(",
"10",
"*",
"time",
".",
"Minute",
")",
"\n\n",
"// Metric config.",
"c",
".",
"Metric",
".",
"Service",
"=",
"\"",
"\"",
"\n",
"c",
".",
"Metric",
".",
"PollInterval",
"=",
"toml",
".",
"Duration",
"(",
"0",
"*",
"time",
".",
"Minute",
")",
"\n",
"c",
".",
"Metric",
".",
"Diagnostics",
"=",
"true",
"\n\n",
"// Tracing config.",
"c",
".",
"Tracing",
".",
"SamplerType",
"=",
"jaeger",
".",
"SamplerTypeRemote",
"\n",
"c",
".",
"Tracing",
".",
"SamplerParam",
"=",
"0.001",
"\n\n",
"c",
".",
"Profile",
".",
"BlockRate",
"=",
"10000000",
"// 1 sample per 10 ms",
"\n",
"c",
".",
"Profile",
".",
"MutexFraction",
"=",
"100",
"// 1% sampling",
"\n\n",
"return",
"c",
"\n",
"}"
] |
// NewConfig returns an instance of Config with default options.
|
[
"NewConfig",
"returns",
"an",
"instance",
"of",
"Config",
"with",
"default",
"options",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server/config.go#L141-L190
|
train
|
pilosa/pilosa
|
server/config.go
|
validateAddrs
|
func (cfg *Config) validateAddrs(ctx context.Context) error {
// Validate the advertise address.
advScheme, advHost, advPort, err := validateAdvertiseAddr(ctx, cfg.Advertise, cfg.Bind)
if err != nil {
return errors.Wrapf(err, "validating advertise address")
}
cfg.Advertise = schemeHostPortString(advScheme, advHost, advPort)
// Validate the listen address.
listenScheme, listenHost, listenPort, err := validateListenAddr(ctx, cfg.Bind)
if err != nil {
return errors.Wrap(err, "validating listen address")
}
cfg.Bind = schemeHostPortString(listenScheme, listenHost, listenPort)
return nil
}
|
go
|
func (cfg *Config) validateAddrs(ctx context.Context) error {
// Validate the advertise address.
advScheme, advHost, advPort, err := validateAdvertiseAddr(ctx, cfg.Advertise, cfg.Bind)
if err != nil {
return errors.Wrapf(err, "validating advertise address")
}
cfg.Advertise = schemeHostPortString(advScheme, advHost, advPort)
// Validate the listen address.
listenScheme, listenHost, listenPort, err := validateListenAddr(ctx, cfg.Bind)
if err != nil {
return errors.Wrap(err, "validating listen address")
}
cfg.Bind = schemeHostPortString(listenScheme, listenHost, listenPort)
return nil
}
|
[
"func",
"(",
"cfg",
"*",
"Config",
")",
"validateAddrs",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"// Validate the advertise address.",
"advScheme",
",",
"advHost",
",",
"advPort",
",",
"err",
":=",
"validateAdvertiseAddr",
"(",
"ctx",
",",
"cfg",
".",
"Advertise",
",",
"cfg",
".",
"Bind",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"cfg",
".",
"Advertise",
"=",
"schemeHostPortString",
"(",
"advScheme",
",",
"advHost",
",",
"advPort",
")",
"\n\n",
"// Validate the listen address.",
"listenScheme",
",",
"listenHost",
",",
"listenPort",
",",
"err",
":=",
"validateListenAddr",
"(",
"ctx",
",",
"cfg",
".",
"Bind",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"cfg",
".",
"Bind",
"=",
"schemeHostPortString",
"(",
"listenScheme",
",",
"listenHost",
",",
"listenPort",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// validateAddrs controls the address fields in the Config object
// and fills in any blanks.
// The addresses fields must be guaranteed by the caller to either be
// completely empty, or have both a host part and a port part
// separated by a colon. In the latter case either can be empty to
// indicate it's left unspecified.
|
[
"validateAddrs",
"controls",
"the",
"address",
"fields",
"in",
"the",
"Config",
"object",
"and",
"fills",
"in",
"any",
"blanks",
".",
"The",
"addresses",
"fields",
"must",
"be",
"guaranteed",
"by",
"the",
"caller",
"to",
"either",
"be",
"completely",
"empty",
"or",
"have",
"both",
"a",
"host",
"part",
"and",
"a",
"port",
"part",
"separated",
"by",
"a",
"colon",
".",
"In",
"the",
"latter",
"case",
"either",
"can",
"be",
"empty",
"to",
"indicate",
"it",
"s",
"left",
"unspecified",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server/config.go#L198-L214
|
train
|
pilosa/pilosa
|
server/config.go
|
validateAdvertiseAddr
|
func validateAdvertiseAddr(ctx context.Context, advAddr, listenAddr string) (string, string, string, error) {
listenScheme, listenHost, listenPort, err := splitAddr(listenAddr)
if err != nil {
return "", "", "", errors.Wrap(err, "getting listen address")
}
advScheme, advHostPort := splitScheme(advAddr)
advHost, advPort := "", ""
if advHostPort != "" {
var err error
advHost, advPort, err = net.SplitHostPort(advHostPort)
if err != nil {
return "", "", "", errors.Wrapf(err, "splitting host port: %s", advHostPort)
}
}
// If no advertise scheme was specified, use the one from
// the listen address.
if advScheme == "" {
advScheme = listenScheme
}
// If there was no port number, reuse the one from the listen
// address.
if advPort == "" || advPort == "0" {
advPort = listenPort
}
// Resolve non-numeric to numeric.
portNumber, err := net.DefaultResolver.LookupPort(ctx, "tcp", advPort)
if err != nil {
return "", "", "", errors.Wrapf(err, "looking up non-numeric port: %v", advPort)
}
advPort = strconv.Itoa(portNumber)
// If the advertise host is empty, then we have two cases.
if advHost == "" {
if listenHost == "0.0.0.0" {
advHost = outboundIP().String()
} else {
advHost = listenHost
}
}
return advScheme, advHost, advPort, nil
}
|
go
|
func validateAdvertiseAddr(ctx context.Context, advAddr, listenAddr string) (string, string, string, error) {
listenScheme, listenHost, listenPort, err := splitAddr(listenAddr)
if err != nil {
return "", "", "", errors.Wrap(err, "getting listen address")
}
advScheme, advHostPort := splitScheme(advAddr)
advHost, advPort := "", ""
if advHostPort != "" {
var err error
advHost, advPort, err = net.SplitHostPort(advHostPort)
if err != nil {
return "", "", "", errors.Wrapf(err, "splitting host port: %s", advHostPort)
}
}
// If no advertise scheme was specified, use the one from
// the listen address.
if advScheme == "" {
advScheme = listenScheme
}
// If there was no port number, reuse the one from the listen
// address.
if advPort == "" || advPort == "0" {
advPort = listenPort
}
// Resolve non-numeric to numeric.
portNumber, err := net.DefaultResolver.LookupPort(ctx, "tcp", advPort)
if err != nil {
return "", "", "", errors.Wrapf(err, "looking up non-numeric port: %v", advPort)
}
advPort = strconv.Itoa(portNumber)
// If the advertise host is empty, then we have two cases.
if advHost == "" {
if listenHost == "0.0.0.0" {
advHost = outboundIP().String()
} else {
advHost = listenHost
}
}
return advScheme, advHost, advPort, nil
}
|
[
"func",
"validateAdvertiseAddr",
"(",
"ctx",
"context",
".",
"Context",
",",
"advAddr",
",",
"listenAddr",
"string",
")",
"(",
"string",
",",
"string",
",",
"string",
",",
"error",
")",
"{",
"listenScheme",
",",
"listenHost",
",",
"listenPort",
",",
"err",
":=",
"splitAddr",
"(",
"listenAddr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"advScheme",
",",
"advHostPort",
":=",
"splitScheme",
"(",
"advAddr",
")",
"\n",
"advHost",
",",
"advPort",
":=",
"\"",
"\"",
",",
"\"",
"\"",
"\n",
"if",
"advHostPort",
"!=",
"\"",
"\"",
"{",
"var",
"err",
"error",
"\n",
"advHost",
",",
"advPort",
",",
"err",
"=",
"net",
".",
"SplitHostPort",
"(",
"advHostPort",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"advHostPort",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// If no advertise scheme was specified, use the one from",
"// the listen address.",
"if",
"advScheme",
"==",
"\"",
"\"",
"{",
"advScheme",
"=",
"listenScheme",
"\n",
"}",
"\n",
"// If there was no port number, reuse the one from the listen",
"// address.",
"if",
"advPort",
"==",
"\"",
"\"",
"||",
"advPort",
"==",
"\"",
"\"",
"{",
"advPort",
"=",
"listenPort",
"\n",
"}",
"\n",
"// Resolve non-numeric to numeric.",
"portNumber",
",",
"err",
":=",
"net",
".",
"DefaultResolver",
".",
"LookupPort",
"(",
"ctx",
",",
"\"",
"\"",
",",
"advPort",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"advPort",
")",
"\n",
"}",
"\n",
"advPort",
"=",
"strconv",
".",
"Itoa",
"(",
"portNumber",
")",
"\n\n",
"// If the advertise host is empty, then we have two cases.",
"if",
"advHost",
"==",
"\"",
"\"",
"{",
"if",
"listenHost",
"==",
"\"",
"\"",
"{",
"advHost",
"=",
"outboundIP",
"(",
")",
".",
"String",
"(",
")",
"\n",
"}",
"else",
"{",
"advHost",
"=",
"listenHost",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"advScheme",
",",
"advHost",
",",
"advPort",
",",
"nil",
"\n",
"}"
] |
// validateAdvertiseAddr validates and normalizes an address accessible
// Ensures that if the "host" part is empty, it gets filled in with
// the configured listen address if any, otherwise it makes a best
// guess at the outbound IP address.
// Returns scheme, host, port as strings.
|
[
"validateAdvertiseAddr",
"validates",
"and",
"normalizes",
"an",
"address",
"accessible",
"Ensures",
"that",
"if",
"the",
"host",
"part",
"is",
"empty",
"it",
"gets",
"filled",
"in",
"with",
"the",
"configured",
"listen",
"address",
"if",
"any",
"otherwise",
"it",
"makes",
"a",
"best",
"guess",
"at",
"the",
"outbound",
"IP",
"address",
".",
"Returns",
"scheme",
"host",
"port",
"as",
"strings",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server/config.go#L221-L262
|
train
|
pilosa/pilosa
|
server/config.go
|
outboundIP
|
func outboundIP() net.IP {
// This is not actually making a connection to 8.8.8.8.
// net.Dial() selects the IP address that would be used
// if an actual connection to 8.8.8.8 were made, so this
// choice of address is just meant to ensure that an
// external address is returned (as opposed to a local
// address like 127.0.0.1).
conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil {
log.Fatal(err)
}
defer conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr)
return localAddr.IP
}
|
go
|
func outboundIP() net.IP {
// This is not actually making a connection to 8.8.8.8.
// net.Dial() selects the IP address that would be used
// if an actual connection to 8.8.8.8 were made, so this
// choice of address is just meant to ensure that an
// external address is returned (as opposed to a local
// address like 127.0.0.1).
conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil {
log.Fatal(err)
}
defer conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr)
return localAddr.IP
}
|
[
"func",
"outboundIP",
"(",
")",
"net",
".",
"IP",
"{",
"// This is not actually making a connection to 8.8.8.8.",
"// net.Dial() selects the IP address that would be used",
"// if an actual connection to 8.8.8.8 were made, so this",
"// choice of address is just meant to ensure that an",
"// external address is returned (as opposed to a local",
"// address like 127.0.0.1).",
"conn",
",",
"err",
":=",
"net",
".",
"Dial",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"conn",
".",
"Close",
"(",
")",
"\n\n",
"localAddr",
":=",
"conn",
".",
"LocalAddr",
"(",
")",
".",
"(",
"*",
"net",
".",
"UDPAddr",
")",
"\n\n",
"return",
"localAddr",
".",
"IP",
"\n",
"}"
] |
// outboundIP gets the preferred outbound ip of this machine.
|
[
"outboundIP",
"gets",
"the",
"preferred",
"outbound",
"ip",
"of",
"this",
"machine",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server/config.go#L265-L281
|
train
|
pilosa/pilosa
|
server/config.go
|
splitAddr
|
func splitAddr(addr string) (string, string, string, error) {
scheme, hostPort := splitScheme(addr)
host, port := "", ""
if hostPort != "" {
var err error
host, port, err = net.SplitHostPort(hostPort)
if err != nil {
return "", "", "", errors.Wrapf(err, "splitting host port: %s", hostPort)
}
}
// It's not ideal to have a default here, but the alterative
// results in a port of 0, which causes Pilosa to listen on
// a random port.
if port == "" {
port = "10101"
}
return scheme, host, port, nil
}
|
go
|
func splitAddr(addr string) (string, string, string, error) {
scheme, hostPort := splitScheme(addr)
host, port := "", ""
if hostPort != "" {
var err error
host, port, err = net.SplitHostPort(hostPort)
if err != nil {
return "", "", "", errors.Wrapf(err, "splitting host port: %s", hostPort)
}
}
// It's not ideal to have a default here, but the alterative
// results in a port of 0, which causes Pilosa to listen on
// a random port.
if port == "" {
port = "10101"
}
return scheme, host, port, nil
}
|
[
"func",
"splitAddr",
"(",
"addr",
"string",
")",
"(",
"string",
",",
"string",
",",
"string",
",",
"error",
")",
"{",
"scheme",
",",
"hostPort",
":=",
"splitScheme",
"(",
"addr",
")",
"\n",
"host",
",",
"port",
":=",
"\"",
"\"",
",",
"\"",
"\"",
"\n",
"if",
"hostPort",
"!=",
"\"",
"\"",
"{",
"var",
"err",
"error",
"\n",
"host",
",",
"port",
",",
"err",
"=",
"net",
".",
"SplitHostPort",
"(",
"hostPort",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"hostPort",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// It's not ideal to have a default here, but the alterative",
"// results in a port of 0, which causes Pilosa to listen on",
"// a random port.",
"if",
"port",
"==",
"\"",
"\"",
"{",
"port",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"scheme",
",",
"host",
",",
"port",
",",
"nil",
"\n",
"}"
] |
// splitAddr returns scheme, host, port as strings.
|
[
"splitAddr",
"returns",
"scheme",
"host",
"port",
"as",
"strings",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server/config.go#L318-L335
|
train
|
pilosa/pilosa
|
ctl/generate_config.go
|
NewGenerateConfigCommand
|
func NewGenerateConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *GenerateConfigCommand {
return &GenerateConfigCommand{
CmdIO: pilosa.NewCmdIO(stdin, stdout, stderr),
}
}
|
go
|
func NewGenerateConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *GenerateConfigCommand {
return &GenerateConfigCommand{
CmdIO: pilosa.NewCmdIO(stdin, stdout, stderr),
}
}
|
[
"func",
"NewGenerateConfigCommand",
"(",
"stdin",
"io",
".",
"Reader",
",",
"stdout",
",",
"stderr",
"io",
".",
"Writer",
")",
"*",
"GenerateConfigCommand",
"{",
"return",
"&",
"GenerateConfigCommand",
"{",
"CmdIO",
":",
"pilosa",
".",
"NewCmdIO",
"(",
"stdin",
",",
"stdout",
",",
"stderr",
")",
",",
"}",
"\n",
"}"
] |
// NewGenerateConfigCommand returns a new instance of GenerateConfigCommand.
|
[
"NewGenerateConfigCommand",
"returns",
"a",
"new",
"instance",
"of",
"GenerateConfigCommand",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/ctl/generate_config.go#L34-L38
|
train
|
pilosa/pilosa
|
cmd/server.go
|
newServeCmd
|
func newServeCmd(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
Server = server.NewCommand(stdin, stdout, stderr)
serveCmd := &cobra.Command{
Use: "server",
Short: "Run Pilosa.",
Long: `pilosa server runs Pilosa.
It will load existing data from the configured
directory and start listening for client connections
on the configured port.`,
RunE: func(cmd *cobra.Command, args []string) error {
// Start & run the server.
if err := Server.Start(); err != nil {
return errors.Wrap(err, "running server")
}
// Initialize tracing in the command since it is global.
var cfg jaegercfg.Configuration
cfg.ServiceName = "pilosa"
cfg.Sampler = &jaegercfg.SamplerConfig{
Type: Server.Config.Tracing.SamplerType,
Param: Server.Config.Tracing.SamplerParam,
}
cfg.Reporter = &jaegercfg.ReporterConfig{
LocalAgentHostPort: Server.Config.Tracing.AgentHostPort,
}
tracer, closer, err := cfg.NewTracer()
if err != nil {
return errors.Wrap(err, "initializing jaeger tracer")
}
defer closer.Close()
tracing.GlobalTracer = opentracing.NewTracer(tracer)
return errors.Wrap(Server.Wait(), "waiting on Server")
},
}
// Attach flags to the command.
ctl.BuildServerFlags(serveCmd, Server)
return serveCmd
}
|
go
|
func newServeCmd(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
Server = server.NewCommand(stdin, stdout, stderr)
serveCmd := &cobra.Command{
Use: "server",
Short: "Run Pilosa.",
Long: `pilosa server runs Pilosa.
It will load existing data from the configured
directory and start listening for client connections
on the configured port.`,
RunE: func(cmd *cobra.Command, args []string) error {
// Start & run the server.
if err := Server.Start(); err != nil {
return errors.Wrap(err, "running server")
}
// Initialize tracing in the command since it is global.
var cfg jaegercfg.Configuration
cfg.ServiceName = "pilosa"
cfg.Sampler = &jaegercfg.SamplerConfig{
Type: Server.Config.Tracing.SamplerType,
Param: Server.Config.Tracing.SamplerParam,
}
cfg.Reporter = &jaegercfg.ReporterConfig{
LocalAgentHostPort: Server.Config.Tracing.AgentHostPort,
}
tracer, closer, err := cfg.NewTracer()
if err != nil {
return errors.Wrap(err, "initializing jaeger tracer")
}
defer closer.Close()
tracing.GlobalTracer = opentracing.NewTracer(tracer)
return errors.Wrap(Server.Wait(), "waiting on Server")
},
}
// Attach flags to the command.
ctl.BuildServerFlags(serveCmd, Server)
return serveCmd
}
|
[
"func",
"newServeCmd",
"(",
"stdin",
"io",
".",
"Reader",
",",
"stdout",
",",
"stderr",
"io",
".",
"Writer",
")",
"*",
"cobra",
".",
"Command",
"{",
"Server",
"=",
"server",
".",
"NewCommand",
"(",
"stdin",
",",
"stdout",
",",
"stderr",
")",
"\n",
"serveCmd",
":=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"",
",",
"Long",
":",
"`pilosa server runs Pilosa.\n\nIt will load existing data from the configured\ndirectory and start listening for client connections\non the configured port.`",
",",
"RunE",
":",
"func",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"// Start & run the server.",
"if",
"err",
":=",
"Server",
".",
"Start",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Initialize tracing in the command since it is global.",
"var",
"cfg",
"jaegercfg",
".",
"Configuration",
"\n",
"cfg",
".",
"ServiceName",
"=",
"\"",
"\"",
"\n",
"cfg",
".",
"Sampler",
"=",
"&",
"jaegercfg",
".",
"SamplerConfig",
"{",
"Type",
":",
"Server",
".",
"Config",
".",
"Tracing",
".",
"SamplerType",
",",
"Param",
":",
"Server",
".",
"Config",
".",
"Tracing",
".",
"SamplerParam",
",",
"}",
"\n",
"cfg",
".",
"Reporter",
"=",
"&",
"jaegercfg",
".",
"ReporterConfig",
"{",
"LocalAgentHostPort",
":",
"Server",
".",
"Config",
".",
"Tracing",
".",
"AgentHostPort",
",",
"}",
"\n",
"tracer",
",",
"closer",
",",
"err",
":=",
"cfg",
".",
"NewTracer",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"closer",
".",
"Close",
"(",
")",
"\n",
"tracing",
".",
"GlobalTracer",
"=",
"opentracing",
".",
"NewTracer",
"(",
"tracer",
")",
"\n\n",
"return",
"errors",
".",
"Wrap",
"(",
"Server",
".",
"Wait",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"}",
",",
"}",
"\n\n",
"// Attach flags to the command.",
"ctl",
".",
"BuildServerFlags",
"(",
"serveCmd",
",",
"Server",
")",
"\n",
"return",
"serveCmd",
"\n",
"}"
] |
// newServeCmd creates a pilosa server and runs it with command line flags.
|
[
"newServeCmd",
"creates",
"a",
"pilosa",
"server",
"and",
"runs",
"it",
"with",
"command",
"line",
"flags",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/cmd/server.go#L33-L73
|
train
|
pilosa/pilosa
|
boltdb/attrstore.go
|
Get
|
func (c *attrCache) Get(id uint64) map[string]interface{} {
c.mu.RLock()
defer c.mu.RUnlock()
attrs := c.attrs[id]
if attrs == nil {
return nil
}
// Make a copy for safety
ret := make(map[string]interface{})
for k, v := range attrs {
ret[k] = v
}
return ret
}
|
go
|
func (c *attrCache) Get(id uint64) map[string]interface{} {
c.mu.RLock()
defer c.mu.RUnlock()
attrs := c.attrs[id]
if attrs == nil {
return nil
}
// Make a copy for safety
ret := make(map[string]interface{})
for k, v := range attrs {
ret[k] = v
}
return ret
}
|
[
"func",
"(",
"c",
"*",
"attrCache",
")",
"Get",
"(",
"id",
"uint64",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"attrs",
":=",
"c",
".",
"attrs",
"[",
"id",
"]",
"\n",
"if",
"attrs",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Make a copy for safety",
"ret",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"attrs",
"{",
"ret",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"return",
"ret",
"\n",
"}"
] |
// Get returns the cached attributes for a given id.
|
[
"Get",
"returns",
"the",
"cached",
"attributes",
"for",
"a",
"given",
"id",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/boltdb/attrstore.go#L43-L57
|
train
|
pilosa/pilosa
|
boltdb/attrstore.go
|
Set
|
func (c *attrCache) Set(id uint64, attrs map[string]interface{}) {
c.mu.Lock()
defer c.mu.Unlock()
c.attrs[id] = attrs
}
|
go
|
func (c *attrCache) Set(id uint64, attrs map[string]interface{}) {
c.mu.Lock()
defer c.mu.Unlock()
c.attrs[id] = attrs
}
|
[
"func",
"(",
"c",
"*",
"attrCache",
")",
"Set",
"(",
"id",
"uint64",
",",
"attrs",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"c",
".",
"attrs",
"[",
"id",
"]",
"=",
"attrs",
"\n",
"}"
] |
// Set updates the cached attributes for a given id.
|
[
"Set",
"updates",
"the",
"cached",
"attributes",
"for",
"a",
"given",
"id",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/boltdb/attrstore.go#L60-L64
|
train
|
pilosa/pilosa
|
boltdb/attrstore.go
|
NewAttrStore
|
func NewAttrStore(path string) pilosa.AttrStore {
return &attrStore{
path: path,
attrCache: newAttrCache(),
}
}
|
go
|
func NewAttrStore(path string) pilosa.AttrStore {
return &attrStore{
path: path,
attrCache: newAttrCache(),
}
}
|
[
"func",
"NewAttrStore",
"(",
"path",
"string",
")",
"pilosa",
".",
"AttrStore",
"{",
"return",
"&",
"attrStore",
"{",
"path",
":",
"path",
",",
"attrCache",
":",
"newAttrCache",
"(",
")",
",",
"}",
"\n",
"}"
] |
// NewAttrStore returns a new instance of AttrStore.
|
[
"NewAttrStore",
"returns",
"a",
"new",
"instance",
"of",
"AttrStore",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/boltdb/attrstore.go#L82-L87
|
train
|
pilosa/pilosa
|
boltdb/attrstore.go
|
Open
|
func (s *attrStore) Open() error {
// Open storage.
db, err := bolt.Open(s.path, 0666, &bolt.Options{Timeout: 1 * time.Second})
if err != nil {
return errors.Wrap(err, "opening storage")
}
s.db = db
// Initialize database.
if err := s.db.Update(func(tx *bolt.Tx) error {
_, err := tx.CreateBucketIfNotExists([]byte("attrs"))
return err
}); err != nil {
return errors.Wrap(err, "initializing")
}
return nil
}
|
go
|
func (s *attrStore) Open() error {
// Open storage.
db, err := bolt.Open(s.path, 0666, &bolt.Options{Timeout: 1 * time.Second})
if err != nil {
return errors.Wrap(err, "opening storage")
}
s.db = db
// Initialize database.
if err := s.db.Update(func(tx *bolt.Tx) error {
_, err := tx.CreateBucketIfNotExists([]byte("attrs"))
return err
}); err != nil {
return errors.Wrap(err, "initializing")
}
return nil
}
|
[
"func",
"(",
"s",
"*",
"attrStore",
")",
"Open",
"(",
")",
"error",
"{",
"// Open storage.",
"db",
",",
"err",
":=",
"bolt",
".",
"Open",
"(",
"s",
".",
"path",
",",
"0666",
",",
"&",
"bolt",
".",
"Options",
"{",
"Timeout",
":",
"1",
"*",
"time",
".",
"Second",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"s",
".",
"db",
"=",
"db",
"\n\n",
"// Initialize database.",
"if",
"err",
":=",
"s",
".",
"db",
".",
"Update",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"_",
",",
"err",
":=",
"tx",
".",
"CreateBucketIfNotExists",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"\n",
"return",
"err",
"\n",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Open opens and initializes the store.
|
[
"Open",
"opens",
"and",
"initializes",
"the",
"store",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/boltdb/attrstore.go#L93-L110
|
train
|
pilosa/pilosa
|
boltdb/attrstore.go
|
Attrs
|
func (s *attrStore) Attrs(id uint64) (m map[string]interface{}, err error) {
s.mu.RLock()
defer s.mu.RUnlock()
// Check cache for map.
if m = s.attrCache.Get(id); m != nil {
return m, nil
}
// Find attributes from storage.
if err = s.db.View(func(tx *bolt.Tx) error {
m, err = txAttrs(tx, id)
return err
}); err != nil {
return nil, errors.Wrap(err, "finding attributes")
}
// Add to cache.
s.attrCache.Set(id, m)
return m, nil
}
|
go
|
func (s *attrStore) Attrs(id uint64) (m map[string]interface{}, err error) {
s.mu.RLock()
defer s.mu.RUnlock()
// Check cache for map.
if m = s.attrCache.Get(id); m != nil {
return m, nil
}
// Find attributes from storage.
if err = s.db.View(func(tx *bolt.Tx) error {
m, err = txAttrs(tx, id)
return err
}); err != nil {
return nil, errors.Wrap(err, "finding attributes")
}
// Add to cache.
s.attrCache.Set(id, m)
return m, nil
}
|
[
"func",
"(",
"s",
"*",
"attrStore",
")",
"Attrs",
"(",
"id",
"uint64",
")",
"(",
"m",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"// Check cache for map.",
"if",
"m",
"=",
"s",
".",
"attrCache",
".",
"Get",
"(",
"id",
")",
";",
"m",
"!=",
"nil",
"{",
"return",
"m",
",",
"nil",
"\n",
"}",
"\n\n",
"// Find attributes from storage.",
"if",
"err",
"=",
"s",
".",
"db",
".",
"View",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"m",
",",
"err",
"=",
"txAttrs",
"(",
"tx",
",",
"id",
")",
"\n",
"return",
"err",
"\n",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Add to cache.",
"s",
".",
"attrCache",
".",
"Set",
"(",
"id",
",",
"m",
")",
"\n\n",
"return",
"m",
",",
"nil",
"\n",
"}"
] |
// Attrs returns a set of attributes by ID.
|
[
"Attrs",
"returns",
"a",
"set",
"of",
"attributes",
"by",
"ID",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/boltdb/attrstore.go#L121-L142
|
train
|
pilosa/pilosa
|
boltdb/attrstore.go
|
SetAttrs
|
func (s *attrStore) SetAttrs(id uint64, m map[string]interface{}) error {
// Ignore empty maps.
if len(m) == 0 {
return nil
}
// Check if the attributes already exist under a read-only lock.
if attr, err := s.Attrs(id); err != nil {
return errors.Wrap(err, "checking attrs")
} else if attr != nil && mapContains(attr, m) {
return nil
}
// Obtain write lock.
s.mu.Lock()
defer s.mu.Unlock()
var attr map[string]interface{}
if err := s.db.Update(func(tx *bolt.Tx) error {
tmp, err := txUpdateAttrs(tx, id, m)
if err != nil {
return err
}
attr = tmp
return nil
}); err != nil {
return errors.Wrap(err, "updating store")
}
// Swap attributes map in cache.
s.attrCache.Set(id, attr)
return nil
}
|
go
|
func (s *attrStore) SetAttrs(id uint64, m map[string]interface{}) error {
// Ignore empty maps.
if len(m) == 0 {
return nil
}
// Check if the attributes already exist under a read-only lock.
if attr, err := s.Attrs(id); err != nil {
return errors.Wrap(err, "checking attrs")
} else if attr != nil && mapContains(attr, m) {
return nil
}
// Obtain write lock.
s.mu.Lock()
defer s.mu.Unlock()
var attr map[string]interface{}
if err := s.db.Update(func(tx *bolt.Tx) error {
tmp, err := txUpdateAttrs(tx, id, m)
if err != nil {
return err
}
attr = tmp
return nil
}); err != nil {
return errors.Wrap(err, "updating store")
}
// Swap attributes map in cache.
s.attrCache.Set(id, attr)
return nil
}
|
[
"func",
"(",
"s",
"*",
"attrStore",
")",
"SetAttrs",
"(",
"id",
"uint64",
",",
"m",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"// Ignore empty maps.",
"if",
"len",
"(",
"m",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Check if the attributes already exist under a read-only lock.",
"if",
"attr",
",",
"err",
":=",
"s",
".",
"Attrs",
"(",
"id",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"attr",
"!=",
"nil",
"&&",
"mapContains",
"(",
"attr",
",",
"m",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Obtain write lock.",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"var",
"attr",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"if",
"err",
":=",
"s",
".",
"db",
".",
"Update",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"tmp",
",",
"err",
":=",
"txUpdateAttrs",
"(",
"tx",
",",
"id",
",",
"m",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"attr",
"=",
"tmp",
"\n\n",
"return",
"nil",
"\n",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Swap attributes map in cache.",
"s",
".",
"attrCache",
".",
"Set",
"(",
"id",
",",
"attr",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// SetAttrs sets attribute values for a given ID.
|
[
"SetAttrs",
"sets",
"attribute",
"values",
"for",
"a",
"given",
"ID",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/boltdb/attrstore.go#L145-L179
|
train
|
pilosa/pilosa
|
boltdb/attrstore.go
|
SetBulkAttrs
|
func (s *attrStore) SetBulkAttrs(m map[uint64]map[string]interface{}) error {
s.mu.Lock()
defer s.mu.Unlock()
attrs := make(map[uint64]map[string]interface{})
if err := s.db.Update(func(tx *bolt.Tx) error {
// Collect and sort keys.
ids := make([]uint64, 0, len(m))
for id := range m {
ids = append(ids, id)
}
sort.Slice(ids, func(i, j int) bool { return ids[i] < ids[j] })
// Update attributes for each id.
for _, id := range ids {
attr, err := txUpdateAttrs(tx, id, m[id])
if err != nil {
return err
}
attrs[id] = attr
}
return nil
}); err != nil {
return err
}
// Swap attributes map in cache.
for id, attr := range attrs {
s.attrCache.Set(id, attr)
}
return nil
}
|
go
|
func (s *attrStore) SetBulkAttrs(m map[uint64]map[string]interface{}) error {
s.mu.Lock()
defer s.mu.Unlock()
attrs := make(map[uint64]map[string]interface{})
if err := s.db.Update(func(tx *bolt.Tx) error {
// Collect and sort keys.
ids := make([]uint64, 0, len(m))
for id := range m {
ids = append(ids, id)
}
sort.Slice(ids, func(i, j int) bool { return ids[i] < ids[j] })
// Update attributes for each id.
for _, id := range ids {
attr, err := txUpdateAttrs(tx, id, m[id])
if err != nil {
return err
}
attrs[id] = attr
}
return nil
}); err != nil {
return err
}
// Swap attributes map in cache.
for id, attr := range attrs {
s.attrCache.Set(id, attr)
}
return nil
}
|
[
"func",
"(",
"s",
"*",
"attrStore",
")",
"SetBulkAttrs",
"(",
"m",
"map",
"[",
"uint64",
"]",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"attrs",
":=",
"make",
"(",
"map",
"[",
"uint64",
"]",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"err",
":=",
"s",
".",
"db",
".",
"Update",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"// Collect and sort keys.",
"ids",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"0",
",",
"len",
"(",
"m",
")",
")",
"\n",
"for",
"id",
":=",
"range",
"m",
"{",
"ids",
"=",
"append",
"(",
"ids",
",",
"id",
")",
"\n",
"}",
"\n",
"sort",
".",
"Slice",
"(",
"ids",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"ids",
"[",
"i",
"]",
"<",
"ids",
"[",
"j",
"]",
"}",
")",
"\n\n",
"// Update attributes for each id.",
"for",
"_",
",",
"id",
":=",
"range",
"ids",
"{",
"attr",
",",
"err",
":=",
"txUpdateAttrs",
"(",
"tx",
",",
"id",
",",
"m",
"[",
"id",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"attrs",
"[",
"id",
"]",
"=",
"attr",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Swap attributes map in cache.",
"for",
"id",
",",
"attr",
":=",
"range",
"attrs",
"{",
"s",
".",
"attrCache",
".",
"Set",
"(",
"id",
",",
"attr",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// SetBulkAttrs sets attribute values for a set of ids.
|
[
"SetBulkAttrs",
"sets",
"attribute",
"values",
"for",
"a",
"set",
"of",
"ids",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/boltdb/attrstore.go#L182-L215
|
train
|
pilosa/pilosa
|
boltdb/attrstore.go
|
Blocks
|
func (s *attrStore) Blocks() (blocks []pilosa.AttrBlock, err error) {
err = s.db.View(func(tx *bolt.Tx) error {
// Wrap cursor to segment by block.
cur := newBlockCursor(tx.Bucket([]byte("attrs")).Cursor(), attrBlockSize)
// Iterate over each block.
for cur.nextBlock() {
block := pilosa.AttrBlock{ID: cur.blockID()}
// Compute checksum of every key/value in block.
h := xxhash.New()
for k, v := cur.next(); k != nil; k, v = cur.next() {
// hash function writes don't usually need to be checked
_, _ = h.Write(k)
_, _ = h.Write(v)
}
block.Checksum = h.Sum(nil)
// Append block.
blocks = append(blocks, block)
}
return nil
})
if err != nil {
return nil, errors.Wrap(err, "getting blocks")
}
return blocks, nil
}
|
go
|
func (s *attrStore) Blocks() (blocks []pilosa.AttrBlock, err error) {
err = s.db.View(func(tx *bolt.Tx) error {
// Wrap cursor to segment by block.
cur := newBlockCursor(tx.Bucket([]byte("attrs")).Cursor(), attrBlockSize)
// Iterate over each block.
for cur.nextBlock() {
block := pilosa.AttrBlock{ID: cur.blockID()}
// Compute checksum of every key/value in block.
h := xxhash.New()
for k, v := cur.next(); k != nil; k, v = cur.next() {
// hash function writes don't usually need to be checked
_, _ = h.Write(k)
_, _ = h.Write(v)
}
block.Checksum = h.Sum(nil)
// Append block.
blocks = append(blocks, block)
}
return nil
})
if err != nil {
return nil, errors.Wrap(err, "getting blocks")
}
return blocks, nil
}
|
[
"func",
"(",
"s",
"*",
"attrStore",
")",
"Blocks",
"(",
")",
"(",
"blocks",
"[",
"]",
"pilosa",
".",
"AttrBlock",
",",
"err",
"error",
")",
"{",
"err",
"=",
"s",
".",
"db",
".",
"View",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"// Wrap cursor to segment by block.",
"cur",
":=",
"newBlockCursor",
"(",
"tx",
".",
"Bucket",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
".",
"Cursor",
"(",
")",
",",
"attrBlockSize",
")",
"\n\n",
"// Iterate over each block.",
"for",
"cur",
".",
"nextBlock",
"(",
")",
"{",
"block",
":=",
"pilosa",
".",
"AttrBlock",
"{",
"ID",
":",
"cur",
".",
"blockID",
"(",
")",
"}",
"\n\n",
"// Compute checksum of every key/value in block.",
"h",
":=",
"xxhash",
".",
"New",
"(",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"cur",
".",
"next",
"(",
")",
";",
"k",
"!=",
"nil",
";",
"k",
",",
"v",
"=",
"cur",
".",
"next",
"(",
")",
"{",
"// hash function writes don't usually need to be checked",
"_",
",",
"_",
"=",
"h",
".",
"Write",
"(",
"k",
")",
"\n",
"_",
",",
"_",
"=",
"h",
".",
"Write",
"(",
"v",
")",
"\n",
"}",
"\n",
"block",
".",
"Checksum",
"=",
"h",
".",
"Sum",
"(",
"nil",
")",
"\n\n",
"// Append block.",
"blocks",
"=",
"append",
"(",
"blocks",
",",
"block",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"blocks",
",",
"nil",
"\n",
"}"
] |
// Blocks returns a list of all blocks in the store.
|
[
"Blocks",
"returns",
"a",
"list",
"of",
"all",
"blocks",
"in",
"the",
"store",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/boltdb/attrstore.go#L218-L245
|
train
|
pilosa/pilosa
|
boltdb/attrstore.go
|
BlockData
|
func (s *attrStore) BlockData(i uint64) (m map[uint64]map[string]interface{}, err error) {
m = make(map[uint64]map[string]interface{})
// Start read-only transaction.
err = s.db.View(func(tx *bolt.Tx) error {
// Move to the start of the block.
min := u64tob(i * attrBlockSize)
max := u64tob((i + 1) * attrBlockSize)
cur := tx.Bucket([]byte("attrs")).Cursor()
for k, v := cur.Seek(min); k != nil; k, v = cur.Next() {
// Exit if we're past the end of the block.
if bytes.Compare(k, max) != -1 {
break
}
// Decode attribute map and associate with id.
attrs, err := pilosa.DecodeAttrs(v)
if err != nil {
return errors.Wrap(err, "decoding attrs")
}
m[btou64(k)] = attrs
}
return nil
})
if err != nil {
return nil, errors.Wrap(err, "getting block data")
}
return m, nil
}
|
go
|
func (s *attrStore) BlockData(i uint64) (m map[uint64]map[string]interface{}, err error) {
m = make(map[uint64]map[string]interface{})
// Start read-only transaction.
err = s.db.View(func(tx *bolt.Tx) error {
// Move to the start of the block.
min := u64tob(i * attrBlockSize)
max := u64tob((i + 1) * attrBlockSize)
cur := tx.Bucket([]byte("attrs")).Cursor()
for k, v := cur.Seek(min); k != nil; k, v = cur.Next() {
// Exit if we're past the end of the block.
if bytes.Compare(k, max) != -1 {
break
}
// Decode attribute map and associate with id.
attrs, err := pilosa.DecodeAttrs(v)
if err != nil {
return errors.Wrap(err, "decoding attrs")
}
m[btou64(k)] = attrs
}
return nil
})
if err != nil {
return nil, errors.Wrap(err, "getting block data")
}
return m, nil
}
|
[
"func",
"(",
"s",
"*",
"attrStore",
")",
"BlockData",
"(",
"i",
"uint64",
")",
"(",
"m",
"map",
"[",
"uint64",
"]",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"m",
"=",
"make",
"(",
"map",
"[",
"uint64",
"]",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n\n",
"// Start read-only transaction.",
"err",
"=",
"s",
".",
"db",
".",
"View",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"// Move to the start of the block.",
"min",
":=",
"u64tob",
"(",
"i",
"*",
"attrBlockSize",
")",
"\n",
"max",
":=",
"u64tob",
"(",
"(",
"i",
"+",
"1",
")",
"*",
"attrBlockSize",
")",
"\n",
"cur",
":=",
"tx",
".",
"Bucket",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
".",
"Cursor",
"(",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"cur",
".",
"Seek",
"(",
"min",
")",
";",
"k",
"!=",
"nil",
";",
"k",
",",
"v",
"=",
"cur",
".",
"Next",
"(",
")",
"{",
"// Exit if we're past the end of the block.",
"if",
"bytes",
".",
"Compare",
"(",
"k",
",",
"max",
")",
"!=",
"-",
"1",
"{",
"break",
"\n",
"}",
"\n\n",
"// Decode attribute map and associate with id.",
"attrs",
",",
"err",
":=",
"pilosa",
".",
"DecodeAttrs",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"m",
"[",
"btou64",
"(",
"k",
")",
"]",
"=",
"attrs",
"\n\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"m",
",",
"nil",
"\n",
"}"
] |
// BlockData returns all data for a single block.
|
[
"BlockData",
"returns",
"all",
"data",
"for",
"a",
"single",
"block",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/boltdb/attrstore.go#L248-L277
|
train
|
pilosa/pilosa
|
boltdb/attrstore.go
|
txAttrs
|
func txAttrs(tx *bolt.Tx, id uint64) (map[string]interface{}, error) {
v := tx.Bucket([]byte("attrs")).Get(u64tob(id))
if v == nil {
return emptyMap, nil
}
return pilosa.DecodeAttrs(v)
}
|
go
|
func txAttrs(tx *bolt.Tx, id uint64) (map[string]interface{}, error) {
v := tx.Bucket([]byte("attrs")).Get(u64tob(id))
if v == nil {
return emptyMap, nil
}
return pilosa.DecodeAttrs(v)
}
|
[
"func",
"txAttrs",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
",",
"id",
"uint64",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"v",
":=",
"tx",
".",
"Bucket",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
".",
"Get",
"(",
"u64tob",
"(",
"id",
")",
")",
"\n",
"if",
"v",
"==",
"nil",
"{",
"return",
"emptyMap",
",",
"nil",
"\n",
"}",
"\n",
"return",
"pilosa",
".",
"DecodeAttrs",
"(",
"v",
")",
"\n",
"}"
] |
// txAttrs returns a map of attributes for an id.
|
[
"txAttrs",
"returns",
"a",
"map",
"of",
"attributes",
"for",
"an",
"id",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/boltdb/attrstore.go#L280-L286
|
train
|
pilosa/pilosa
|
boltdb/attrstore.go
|
txUpdateAttrs
|
func txUpdateAttrs(tx *bolt.Tx, id uint64, m map[string]interface{}) (map[string]interface{}, error) {
attr, err := txAttrs(tx, id)
if err != nil {
return nil, err
}
// Create a new map if it is empty so we don't update emptyMap.
if len(attr) == 0 {
attr = make(map[string]interface{}, len(m))
}
// Merge attributes with original values.
// Nil values should delete keys.
for k, v := range m {
if v == nil {
delete(attr, k)
continue
}
switch v := v.(type) {
case int:
attr[k] = int64(v)
case uint:
attr[k] = int64(v)
case uint64:
attr[k] = int64(v)
case string, int64, bool, float64:
attr[k] = v
default:
return nil, fmt.Errorf("invalid attr type: %T", v)
}
}
// Marshal and save new values.
buf, err := pilosa.EncodeAttrs(attr)
if err != nil {
return nil, errors.Wrap(err, "encoding attrs")
}
if err := tx.Bucket([]byte("attrs")).Put(u64tob(id), buf); err != nil {
return nil, errors.Wrap(err, "saving attrs")
}
return attr, nil
}
|
go
|
func txUpdateAttrs(tx *bolt.Tx, id uint64, m map[string]interface{}) (map[string]interface{}, error) {
attr, err := txAttrs(tx, id)
if err != nil {
return nil, err
}
// Create a new map if it is empty so we don't update emptyMap.
if len(attr) == 0 {
attr = make(map[string]interface{}, len(m))
}
// Merge attributes with original values.
// Nil values should delete keys.
for k, v := range m {
if v == nil {
delete(attr, k)
continue
}
switch v := v.(type) {
case int:
attr[k] = int64(v)
case uint:
attr[k] = int64(v)
case uint64:
attr[k] = int64(v)
case string, int64, bool, float64:
attr[k] = v
default:
return nil, fmt.Errorf("invalid attr type: %T", v)
}
}
// Marshal and save new values.
buf, err := pilosa.EncodeAttrs(attr)
if err != nil {
return nil, errors.Wrap(err, "encoding attrs")
}
if err := tx.Bucket([]byte("attrs")).Put(u64tob(id), buf); err != nil {
return nil, errors.Wrap(err, "saving attrs")
}
return attr, nil
}
|
[
"func",
"txUpdateAttrs",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
",",
"id",
"uint64",
",",
"m",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"attr",
",",
"err",
":=",
"txAttrs",
"(",
"tx",
",",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Create a new map if it is empty so we don't update emptyMap.",
"if",
"len",
"(",
"attr",
")",
"==",
"0",
"{",
"attr",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"m",
")",
")",
"\n",
"}",
"\n\n",
"// Merge attributes with original values.",
"// Nil values should delete keys.",
"for",
"k",
",",
"v",
":=",
"range",
"m",
"{",
"if",
"v",
"==",
"nil",
"{",
"delete",
"(",
"attr",
",",
"k",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"switch",
"v",
":=",
"v",
".",
"(",
"type",
")",
"{",
"case",
"int",
":",
"attr",
"[",
"k",
"]",
"=",
"int64",
"(",
"v",
")",
"\n",
"case",
"uint",
":",
"attr",
"[",
"k",
"]",
"=",
"int64",
"(",
"v",
")",
"\n",
"case",
"uint64",
":",
"attr",
"[",
"k",
"]",
"=",
"int64",
"(",
"v",
")",
"\n",
"case",
"string",
",",
"int64",
",",
"bool",
",",
"float64",
":",
"attr",
"[",
"k",
"]",
"=",
"v",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Marshal and save new values.",
"buf",
",",
"err",
":=",
"pilosa",
".",
"EncodeAttrs",
"(",
"attr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"tx",
".",
"Bucket",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
".",
"Put",
"(",
"u64tob",
"(",
"id",
")",
",",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"attr",
",",
"nil",
"\n",
"}"
] |
// txUpdateAttrs updates the attributes for an id.
// Returns the new combined set of attributes for the id.
|
[
"txUpdateAttrs",
"updates",
"the",
"attributes",
"for",
"an",
"id",
".",
"Returns",
"the",
"new",
"combined",
"set",
"of",
"attributes",
"for",
"the",
"id",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/boltdb/attrstore.go#L290-L332
|
train
|
pilosa/pilosa
|
boltdb/attrstore.go
|
mapContains
|
func mapContains(m, subset map[string]interface{}) bool {
for k, v := range subset {
value, ok := m[k]
if !ok || value != v {
return false
}
}
return true
}
|
go
|
func mapContains(m, subset map[string]interface{}) bool {
for k, v := range subset {
value, ok := m[k]
if !ok || value != v {
return false
}
}
return true
}
|
[
"func",
"mapContains",
"(",
"m",
",",
"subset",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"bool",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"subset",
"{",
"value",
",",
"ok",
":=",
"m",
"[",
"k",
"]",
"\n",
"if",
"!",
"ok",
"||",
"value",
"!=",
"v",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] |
// mapContains returns true if all keys & values of subset are in m.
|
[
"mapContains",
"returns",
"true",
"if",
"all",
"keys",
"&",
"values",
"of",
"subset",
"are",
"in",
"m",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/boltdb/attrstore.go#L348-L356
|
train
|
pilosa/pilosa
|
boltdb/attrstore.go
|
newBlockCursor
|
func newBlockCursor(c *bolt.Cursor, n int) blockCursor { // nolint: unparam
cur := blockCursor{
cur: c,
n: uint64(n),
}
cur.buf.key, cur.buf.value = c.First()
cur.buf.filled = true
return cur
}
|
go
|
func newBlockCursor(c *bolt.Cursor, n int) blockCursor { // nolint: unparam
cur := blockCursor{
cur: c,
n: uint64(n),
}
cur.buf.key, cur.buf.value = c.First()
cur.buf.filled = true
return cur
}
|
[
"func",
"newBlockCursor",
"(",
"c",
"*",
"bolt",
".",
"Cursor",
",",
"n",
"int",
")",
"blockCursor",
"{",
"// nolint: unparam",
"cur",
":=",
"blockCursor",
"{",
"cur",
":",
"c",
",",
"n",
":",
"uint64",
"(",
"n",
")",
",",
"}",
"\n",
"cur",
".",
"buf",
".",
"key",
",",
"cur",
".",
"buf",
".",
"value",
"=",
"c",
".",
"First",
"(",
")",
"\n",
"cur",
".",
"buf",
".",
"filled",
"=",
"true",
"\n",
"return",
"cur",
"\n",
"}"
] |
// newBlockCursor returns a new block cursor that wraps cur using n sized blocks.
|
[
"newBlockCursor",
"returns",
"a",
"new",
"block",
"cursor",
"that",
"wraps",
"cur",
"using",
"n",
"sized",
"blocks",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/boltdb/attrstore.go#L372-L380
|
train
|
pilosa/pilosa
|
boltdb/attrstore.go
|
nextBlock
|
func (cur *blockCursor) nextBlock() bool {
if cur.buf.key == nil {
return false
}
cur.base = binary.BigEndian.Uint64(cur.buf.key) / cur.n
return true
}
|
go
|
func (cur *blockCursor) nextBlock() bool {
if cur.buf.key == nil {
return false
}
cur.base = binary.BigEndian.Uint64(cur.buf.key) / cur.n
return true
}
|
[
"func",
"(",
"cur",
"*",
"blockCursor",
")",
"nextBlock",
"(",
")",
"bool",
"{",
"if",
"cur",
".",
"buf",
".",
"key",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"cur",
".",
"base",
"=",
"binary",
".",
"BigEndian",
".",
"Uint64",
"(",
"cur",
".",
"buf",
".",
"key",
")",
"/",
"cur",
".",
"n",
"\n",
"return",
"true",
"\n",
"}"
] |
// nextBlock moves the cursor to the next block.
// Returns true if another block exists, otherwise returns false.
|
[
"nextBlock",
"moves",
"the",
"cursor",
"to",
"the",
"next",
"block",
".",
"Returns",
"true",
"if",
"another",
"block",
"exists",
"otherwise",
"returns",
"false",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/boltdb/attrstore.go#L387-L394
|
train
|
pilosa/pilosa
|
ctl/import.go
|
NewImportCommand
|
func NewImportCommand(stdin io.Reader, stdout, stderr io.Writer) *ImportCommand {
return &ImportCommand{
CmdIO: pilosa.NewCmdIO(stdin, stdout, stderr),
BufferSize: 10000000,
}
}
|
go
|
func NewImportCommand(stdin io.Reader, stdout, stderr io.Writer) *ImportCommand {
return &ImportCommand{
CmdIO: pilosa.NewCmdIO(stdin, stdout, stderr),
BufferSize: 10000000,
}
}
|
[
"func",
"NewImportCommand",
"(",
"stdin",
"io",
".",
"Reader",
",",
"stdout",
",",
"stderr",
"io",
".",
"Writer",
")",
"*",
"ImportCommand",
"{",
"return",
"&",
"ImportCommand",
"{",
"CmdIO",
":",
"pilosa",
".",
"NewCmdIO",
"(",
"stdin",
",",
"stdout",
",",
"stderr",
")",
",",
"BufferSize",
":",
"10000000",
",",
"}",
"\n",
"}"
] |
// NewImportCommand returns a new instance of ImportCommand.
|
[
"NewImportCommand",
"returns",
"a",
"new",
"instance",
"of",
"ImportCommand",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/ctl/import.go#L74-L79
|
train
|
pilosa/pilosa
|
ctl/import.go
|
Run
|
func (cmd *ImportCommand) Run(ctx context.Context) error {
logger := log.New(cmd.Stderr, "", log.LstdFlags)
// Validate arguments.
// Index and field are validated early before the files are parsed.
if cmd.Index == "" {
return pilosa.ErrIndexRequired
} else if cmd.Field == "" {
return pilosa.ErrFieldRequired
} else if len(cmd.Paths) == 0 {
return errors.New("path required")
}
// Create a client to the server.
client, err := commandClient(cmd)
if err != nil {
return errors.Wrap(err, "creating client")
}
cmd.client = client
if cmd.CreateSchema {
if cmd.FieldOptions.Type == "" {
// set the correct type for the field
if cmd.FieldOptions.TimeQuantum != "" {
cmd.FieldOptions.Type = "time"
} else if cmd.FieldOptions.Min != 0 || cmd.FieldOptions.Max != 0 {
cmd.FieldOptions.Type = "int"
} else {
cmd.FieldOptions.Type = "set"
}
}
err := cmd.ensureSchema(ctx)
if err != nil {
return errors.Wrap(err, "ensuring schema")
}
}
// Determine the field type in order to correctly handle the input data.
fieldType := pilosa.DefaultFieldType
schema, err := cmd.client.Schema(ctx)
if err != nil {
return errors.Wrap(err, "getting schema")
}
var useColumnKeys, useRowKeys bool
for _, index := range schema {
if index.Name == cmd.Index {
useColumnKeys = index.Options.Keys
for _, field := range index.Fields {
if field.Name == cmd.Field {
useRowKeys = field.Options.Keys
fieldType = field.Options.Type
break
}
}
break
}
}
// Import each path and import by shard.
for _, path := range cmd.Paths {
logger.Printf("parsing: %s", path)
if err := cmd.importPath(ctx, fieldType, useColumnKeys, useRowKeys, path); err != nil {
return err
}
}
return nil
}
|
go
|
func (cmd *ImportCommand) Run(ctx context.Context) error {
logger := log.New(cmd.Stderr, "", log.LstdFlags)
// Validate arguments.
// Index and field are validated early before the files are parsed.
if cmd.Index == "" {
return pilosa.ErrIndexRequired
} else if cmd.Field == "" {
return pilosa.ErrFieldRequired
} else if len(cmd.Paths) == 0 {
return errors.New("path required")
}
// Create a client to the server.
client, err := commandClient(cmd)
if err != nil {
return errors.Wrap(err, "creating client")
}
cmd.client = client
if cmd.CreateSchema {
if cmd.FieldOptions.Type == "" {
// set the correct type for the field
if cmd.FieldOptions.TimeQuantum != "" {
cmd.FieldOptions.Type = "time"
} else if cmd.FieldOptions.Min != 0 || cmd.FieldOptions.Max != 0 {
cmd.FieldOptions.Type = "int"
} else {
cmd.FieldOptions.Type = "set"
}
}
err := cmd.ensureSchema(ctx)
if err != nil {
return errors.Wrap(err, "ensuring schema")
}
}
// Determine the field type in order to correctly handle the input data.
fieldType := pilosa.DefaultFieldType
schema, err := cmd.client.Schema(ctx)
if err != nil {
return errors.Wrap(err, "getting schema")
}
var useColumnKeys, useRowKeys bool
for _, index := range schema {
if index.Name == cmd.Index {
useColumnKeys = index.Options.Keys
for _, field := range index.Fields {
if field.Name == cmd.Field {
useRowKeys = field.Options.Keys
fieldType = field.Options.Type
break
}
}
break
}
}
// Import each path and import by shard.
for _, path := range cmd.Paths {
logger.Printf("parsing: %s", path)
if err := cmd.importPath(ctx, fieldType, useColumnKeys, useRowKeys, path); err != nil {
return err
}
}
return nil
}
|
[
"func",
"(",
"cmd",
"*",
"ImportCommand",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"logger",
":=",
"log",
".",
"New",
"(",
"cmd",
".",
"Stderr",
",",
"\"",
"\"",
",",
"log",
".",
"LstdFlags",
")",
"\n\n",
"// Validate arguments.",
"// Index and field are validated early before the files are parsed.",
"if",
"cmd",
".",
"Index",
"==",
"\"",
"\"",
"{",
"return",
"pilosa",
".",
"ErrIndexRequired",
"\n",
"}",
"else",
"if",
"cmd",
".",
"Field",
"==",
"\"",
"\"",
"{",
"return",
"pilosa",
".",
"ErrFieldRequired",
"\n",
"}",
"else",
"if",
"len",
"(",
"cmd",
".",
"Paths",
")",
"==",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// Create a client to the server.",
"client",
",",
"err",
":=",
"commandClient",
"(",
"cmd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"cmd",
".",
"client",
"=",
"client",
"\n\n",
"if",
"cmd",
".",
"CreateSchema",
"{",
"if",
"cmd",
".",
"FieldOptions",
".",
"Type",
"==",
"\"",
"\"",
"{",
"// set the correct type for the field",
"if",
"cmd",
".",
"FieldOptions",
".",
"TimeQuantum",
"!=",
"\"",
"\"",
"{",
"cmd",
".",
"FieldOptions",
".",
"Type",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"if",
"cmd",
".",
"FieldOptions",
".",
"Min",
"!=",
"0",
"||",
"cmd",
".",
"FieldOptions",
".",
"Max",
"!=",
"0",
"{",
"cmd",
".",
"FieldOptions",
".",
"Type",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"cmd",
".",
"FieldOptions",
".",
"Type",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n",
"err",
":=",
"cmd",
".",
"ensureSchema",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Determine the field type in order to correctly handle the input data.",
"fieldType",
":=",
"pilosa",
".",
"DefaultFieldType",
"\n",
"schema",
",",
"err",
":=",
"cmd",
".",
"client",
".",
"Schema",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"useColumnKeys",
",",
"useRowKeys",
"bool",
"\n",
"for",
"_",
",",
"index",
":=",
"range",
"schema",
"{",
"if",
"index",
".",
"Name",
"==",
"cmd",
".",
"Index",
"{",
"useColumnKeys",
"=",
"index",
".",
"Options",
".",
"Keys",
"\n",
"for",
"_",
",",
"field",
":=",
"range",
"index",
".",
"Fields",
"{",
"if",
"field",
".",
"Name",
"==",
"cmd",
".",
"Field",
"{",
"useRowKeys",
"=",
"field",
".",
"Options",
".",
"Keys",
"\n",
"fieldType",
"=",
"field",
".",
"Options",
".",
"Type",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Import each path and import by shard.",
"for",
"_",
",",
"path",
":=",
"range",
"cmd",
".",
"Paths",
"{",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"path",
")",
"\n",
"if",
"err",
":=",
"cmd",
".",
"importPath",
"(",
"ctx",
",",
"fieldType",
",",
"useColumnKeys",
",",
"useRowKeys",
",",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Run executes the main program execution.
|
[
"Run",
"executes",
"the",
"main",
"program",
"execution",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/ctl/import.go#L82-L149
|
train
|
pilosa/pilosa
|
ctl/import.go
|
importPath
|
func (cmd *ImportCommand) importPath(ctx context.Context, fieldType string, useColumnKeys, useRowKeys bool, path string) error {
// If fieldType is `int`, treat the import data as values to be range-encoded.
if fieldType == pilosa.FieldTypeInt {
return cmd.bufferValues(ctx, useColumnKeys, path)
}
return cmd.bufferBits(ctx, useColumnKeys, useRowKeys, path)
}
|
go
|
func (cmd *ImportCommand) importPath(ctx context.Context, fieldType string, useColumnKeys, useRowKeys bool, path string) error {
// If fieldType is `int`, treat the import data as values to be range-encoded.
if fieldType == pilosa.FieldTypeInt {
return cmd.bufferValues(ctx, useColumnKeys, path)
}
return cmd.bufferBits(ctx, useColumnKeys, useRowKeys, path)
}
|
[
"func",
"(",
"cmd",
"*",
"ImportCommand",
")",
"importPath",
"(",
"ctx",
"context",
".",
"Context",
",",
"fieldType",
"string",
",",
"useColumnKeys",
",",
"useRowKeys",
"bool",
",",
"path",
"string",
")",
"error",
"{",
"// If fieldType is `int`, treat the import data as values to be range-encoded.",
"if",
"fieldType",
"==",
"pilosa",
".",
"FieldTypeInt",
"{",
"return",
"cmd",
".",
"bufferValues",
"(",
"ctx",
",",
"useColumnKeys",
",",
"path",
")",
"\n",
"}",
"\n",
"return",
"cmd",
".",
"bufferBits",
"(",
"ctx",
",",
"useColumnKeys",
",",
"useRowKeys",
",",
"path",
")",
"\n",
"}"
] |
// importPath parses a path into bits and imports it to the server.
|
[
"importPath",
"parses",
"a",
"path",
"into",
"bits",
"and",
"imports",
"it",
"to",
"the",
"server",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/ctl/import.go#L164-L170
|
train
|
pilosa/pilosa
|
ctl/import.go
|
bufferBits
|
func (cmd *ImportCommand) bufferBits(ctx context.Context, useColumnKeys, useRowKeys bool, path string) error {
a := make([]pilosa.Bit, 0, cmd.BufferSize)
var r *csv.Reader
if path != "-" {
// Open file for reading.
f, err := os.Open(path)
if err != nil {
return errors.Wrap(err, "opening file")
}
defer f.Close()
// Read rows as bits.
r = csv.NewReader(f)
} else {
r = csv.NewReader(cmd.Stdin)
}
r.FieldsPerRecord = -1
rnum := 0
for {
rnum++
// Read CSV row.
record, err := r.Read()
if err == io.EOF {
break
} else if err != nil {
return errors.Wrap(err, "reading")
}
// Ignore blank rows.
if record[0] == "" {
continue
} else if len(record) < 2 {
return fmt.Errorf("bad column count on row %d: col=%d", rnum, len(record))
}
var bit pilosa.Bit
// Parse row id.
if useRowKeys {
bit.RowKey = record[0]
} else {
if bit.RowID, err = strconv.ParseUint(record[0], 10, 64); err != nil {
return fmt.Errorf("invalid row id on row %d: %q", rnum, record[0])
}
}
// Parse column id.
if useColumnKeys {
bit.ColumnKey = record[1]
} else {
if bit.ColumnID, err = strconv.ParseUint(record[1], 10, 64); err != nil {
return fmt.Errorf("invalid column id on row %d: %q", rnum, record[1])
}
}
// Parse time, if exists.
if len(record) > 2 && record[2] != "" {
t, err := time.Parse(pilosa.TimeFormat, record[2])
if err != nil {
return fmt.Errorf("invalid timestamp on row %d: %q", rnum, record[2])
}
bit.Timestamp = t.UnixNano()
}
a = append(a, bit)
// If we've reached the buffer size then import bits.
if len(a) == cmd.BufferSize {
if err := cmd.importBits(ctx, useColumnKeys, useRowKeys, a); err != nil {
return err
}
a = a[:0]
}
}
// If there are still bits in the buffer then flush them.
return cmd.importBits(ctx, useColumnKeys, useRowKeys, a)
}
|
go
|
func (cmd *ImportCommand) bufferBits(ctx context.Context, useColumnKeys, useRowKeys bool, path string) error {
a := make([]pilosa.Bit, 0, cmd.BufferSize)
var r *csv.Reader
if path != "-" {
// Open file for reading.
f, err := os.Open(path)
if err != nil {
return errors.Wrap(err, "opening file")
}
defer f.Close()
// Read rows as bits.
r = csv.NewReader(f)
} else {
r = csv.NewReader(cmd.Stdin)
}
r.FieldsPerRecord = -1
rnum := 0
for {
rnum++
// Read CSV row.
record, err := r.Read()
if err == io.EOF {
break
} else if err != nil {
return errors.Wrap(err, "reading")
}
// Ignore blank rows.
if record[0] == "" {
continue
} else if len(record) < 2 {
return fmt.Errorf("bad column count on row %d: col=%d", rnum, len(record))
}
var bit pilosa.Bit
// Parse row id.
if useRowKeys {
bit.RowKey = record[0]
} else {
if bit.RowID, err = strconv.ParseUint(record[0], 10, 64); err != nil {
return fmt.Errorf("invalid row id on row %d: %q", rnum, record[0])
}
}
// Parse column id.
if useColumnKeys {
bit.ColumnKey = record[1]
} else {
if bit.ColumnID, err = strconv.ParseUint(record[1], 10, 64); err != nil {
return fmt.Errorf("invalid column id on row %d: %q", rnum, record[1])
}
}
// Parse time, if exists.
if len(record) > 2 && record[2] != "" {
t, err := time.Parse(pilosa.TimeFormat, record[2])
if err != nil {
return fmt.Errorf("invalid timestamp on row %d: %q", rnum, record[2])
}
bit.Timestamp = t.UnixNano()
}
a = append(a, bit)
// If we've reached the buffer size then import bits.
if len(a) == cmd.BufferSize {
if err := cmd.importBits(ctx, useColumnKeys, useRowKeys, a); err != nil {
return err
}
a = a[:0]
}
}
// If there are still bits in the buffer then flush them.
return cmd.importBits(ctx, useColumnKeys, useRowKeys, a)
}
|
[
"func",
"(",
"cmd",
"*",
"ImportCommand",
")",
"bufferBits",
"(",
"ctx",
"context",
".",
"Context",
",",
"useColumnKeys",
",",
"useRowKeys",
"bool",
",",
"path",
"string",
")",
"error",
"{",
"a",
":=",
"make",
"(",
"[",
"]",
"pilosa",
".",
"Bit",
",",
"0",
",",
"cmd",
".",
"BufferSize",
")",
"\n\n",
"var",
"r",
"*",
"csv",
".",
"Reader",
"\n\n",
"if",
"path",
"!=",
"\"",
"\"",
"{",
"// Open file for reading.",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"// Read rows as bits.",
"r",
"=",
"csv",
".",
"NewReader",
"(",
"f",
")",
"\n",
"}",
"else",
"{",
"r",
"=",
"csv",
".",
"NewReader",
"(",
"cmd",
".",
"Stdin",
")",
"\n",
"}",
"\n\n",
"r",
".",
"FieldsPerRecord",
"=",
"-",
"1",
"\n",
"rnum",
":=",
"0",
"\n",
"for",
"{",
"rnum",
"++",
"\n\n",
"// Read CSV row.",
"record",
",",
"err",
":=",
"r",
".",
"Read",
"(",
")",
"\n",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"break",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Ignore blank rows.",
"if",
"record",
"[",
"0",
"]",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"else",
"if",
"len",
"(",
"record",
")",
"<",
"2",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rnum",
",",
"len",
"(",
"record",
")",
")",
"\n",
"}",
"\n\n",
"var",
"bit",
"pilosa",
".",
"Bit",
"\n\n",
"// Parse row id.",
"if",
"useRowKeys",
"{",
"bit",
".",
"RowKey",
"=",
"record",
"[",
"0",
"]",
"\n",
"}",
"else",
"{",
"if",
"bit",
".",
"RowID",
",",
"err",
"=",
"strconv",
".",
"ParseUint",
"(",
"record",
"[",
"0",
"]",
",",
"10",
",",
"64",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rnum",
",",
"record",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Parse column id.",
"if",
"useColumnKeys",
"{",
"bit",
".",
"ColumnKey",
"=",
"record",
"[",
"1",
"]",
"\n",
"}",
"else",
"{",
"if",
"bit",
".",
"ColumnID",
",",
"err",
"=",
"strconv",
".",
"ParseUint",
"(",
"record",
"[",
"1",
"]",
",",
"10",
",",
"64",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rnum",
",",
"record",
"[",
"1",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Parse time, if exists.",
"if",
"len",
"(",
"record",
")",
">",
"2",
"&&",
"record",
"[",
"2",
"]",
"!=",
"\"",
"\"",
"{",
"t",
",",
"err",
":=",
"time",
".",
"Parse",
"(",
"pilosa",
".",
"TimeFormat",
",",
"record",
"[",
"2",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rnum",
",",
"record",
"[",
"2",
"]",
")",
"\n",
"}",
"\n",
"bit",
".",
"Timestamp",
"=",
"t",
".",
"UnixNano",
"(",
")",
"\n",
"}",
"\n\n",
"a",
"=",
"append",
"(",
"a",
",",
"bit",
")",
"\n\n",
"// If we've reached the buffer size then import bits.",
"if",
"len",
"(",
"a",
")",
"==",
"cmd",
".",
"BufferSize",
"{",
"if",
"err",
":=",
"cmd",
".",
"importBits",
"(",
"ctx",
",",
"useColumnKeys",
",",
"useRowKeys",
",",
"a",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"a",
"=",
"a",
"[",
":",
"0",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"// If there are still bits in the buffer then flush them.",
"return",
"cmd",
".",
"importBits",
"(",
"ctx",
",",
"useColumnKeys",
",",
"useRowKeys",
",",
"a",
")",
"\n",
"}"
] |
// bufferBits buffers slices of bits to be imported as a batch.
|
[
"bufferBits",
"buffers",
"slices",
"of",
"bits",
"to",
"be",
"imported",
"as",
"a",
"batch",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/ctl/import.go#L173-L254
|
train
|
pilosa/pilosa
|
ctl/import.go
|
importBits
|
func (cmd *ImportCommand) importBits(ctx context.Context, useColumnKeys, useRowKeys bool, bits []pilosa.Bit) error {
logger := log.New(cmd.Stderr, "", log.LstdFlags)
// If keys are used, all bits are sent to the primary translate store (i.e. coordinator).
if useColumnKeys || useRowKeys {
logger.Printf("importing keys: n=%d", len(bits))
if err := cmd.client.ImportK(ctx, cmd.Index, cmd.Field, bits, pilosa.OptImportOptionsClear(cmd.Clear)); err != nil {
return errors.Wrap(err, "importing keys")
}
return nil
}
// Group bits by shard.
logger.Printf("grouping %d bits", len(bits))
bitsByShard := http.Bits(bits).GroupByShard()
// Parse path into bits.
for shard, chunk := range bitsByShard {
if cmd.Sort {
sort.Sort(http.BitsByPos(chunk))
}
logger.Printf("importing shard: %d, n=%d", shard, len(chunk))
if err := cmd.client.Import(ctx, cmd.Index, cmd.Field, shard, chunk, pilosa.OptImportOptionsClear(cmd.Clear)); err != nil {
return errors.Wrap(err, "importing")
}
}
return nil
}
|
go
|
func (cmd *ImportCommand) importBits(ctx context.Context, useColumnKeys, useRowKeys bool, bits []pilosa.Bit) error {
logger := log.New(cmd.Stderr, "", log.LstdFlags)
// If keys are used, all bits are sent to the primary translate store (i.e. coordinator).
if useColumnKeys || useRowKeys {
logger.Printf("importing keys: n=%d", len(bits))
if err := cmd.client.ImportK(ctx, cmd.Index, cmd.Field, bits, pilosa.OptImportOptionsClear(cmd.Clear)); err != nil {
return errors.Wrap(err, "importing keys")
}
return nil
}
// Group bits by shard.
logger.Printf("grouping %d bits", len(bits))
bitsByShard := http.Bits(bits).GroupByShard()
// Parse path into bits.
for shard, chunk := range bitsByShard {
if cmd.Sort {
sort.Sort(http.BitsByPos(chunk))
}
logger.Printf("importing shard: %d, n=%d", shard, len(chunk))
if err := cmd.client.Import(ctx, cmd.Index, cmd.Field, shard, chunk, pilosa.OptImportOptionsClear(cmd.Clear)); err != nil {
return errors.Wrap(err, "importing")
}
}
return nil
}
|
[
"func",
"(",
"cmd",
"*",
"ImportCommand",
")",
"importBits",
"(",
"ctx",
"context",
".",
"Context",
",",
"useColumnKeys",
",",
"useRowKeys",
"bool",
",",
"bits",
"[",
"]",
"pilosa",
".",
"Bit",
")",
"error",
"{",
"logger",
":=",
"log",
".",
"New",
"(",
"cmd",
".",
"Stderr",
",",
"\"",
"\"",
",",
"log",
".",
"LstdFlags",
")",
"\n\n",
"// If keys are used, all bits are sent to the primary translate store (i.e. coordinator).",
"if",
"useColumnKeys",
"||",
"useRowKeys",
"{",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"len",
"(",
"bits",
")",
")",
"\n",
"if",
"err",
":=",
"cmd",
".",
"client",
".",
"ImportK",
"(",
"ctx",
",",
"cmd",
".",
"Index",
",",
"cmd",
".",
"Field",
",",
"bits",
",",
"pilosa",
".",
"OptImportOptionsClear",
"(",
"cmd",
".",
"Clear",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Group bits by shard.",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"len",
"(",
"bits",
")",
")",
"\n",
"bitsByShard",
":=",
"http",
".",
"Bits",
"(",
"bits",
")",
".",
"GroupByShard",
"(",
")",
"\n\n",
"// Parse path into bits.",
"for",
"shard",
",",
"chunk",
":=",
"range",
"bitsByShard",
"{",
"if",
"cmd",
".",
"Sort",
"{",
"sort",
".",
"Sort",
"(",
"http",
".",
"BitsByPos",
"(",
"chunk",
")",
")",
"\n",
"}",
"\n\n",
"logger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"shard",
",",
"len",
"(",
"chunk",
")",
")",
"\n",
"if",
"err",
":=",
"cmd",
".",
"client",
".",
"Import",
"(",
"ctx",
",",
"cmd",
".",
"Index",
",",
"cmd",
".",
"Field",
",",
"shard",
",",
"chunk",
",",
"pilosa",
".",
"OptImportOptionsClear",
"(",
"cmd",
".",
"Clear",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// importBits sends batches of bits to the server.
|
[
"importBits",
"sends",
"batches",
"of",
"bits",
"to",
"the",
"server",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/ctl/import.go#L257-L286
|
train
|
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.