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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
grafana/metrictank | tracing/tracing.go | Error | func Error(span opentracing.Span, err error) {
span.LogFields(log.Error(err))
} | go | func Error(span opentracing.Span, err error) {
span.LogFields(log.Error(err))
} | [
"func",
"Error",
"(",
"span",
"opentracing",
".",
"Span",
",",
"err",
"error",
")",
"{",
"span",
".",
"LogFields",
"(",
"log",
".",
"Error",
"(",
"err",
")",
")",
"\n",
"}"
] | // Error logs error | [
"Error",
"logs",
"error"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/tracing/tracing.go#L26-L28 | train |
grafana/metrictank | tracing/tracing.go | Errorf | func Errorf(span opentracing.Span, format string, a ...interface{}) {
span.LogFields(log.Error(fmt.Errorf(format, a...)))
} | go | func Errorf(span opentracing.Span, format string, a ...interface{}) {
span.LogFields(log.Error(fmt.Errorf(format, a...)))
} | [
"func",
"Errorf",
"(",
"span",
"opentracing",
".",
"Span",
",",
"format",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"{",
"span",
".",
"LogFields",
"(",
"log",
".",
"Error",
"(",
"fmt",
".",
"Errorf",
"(",
"format",
",",
"a",
"...",
")"... | // Errorf logs error | [
"Errorf",
"logs",
"error"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/tracing/tracing.go#L31-L33 | train |
grafana/metrictank | clock/clock.go | AlignedTick | func AlignedTick(period time.Duration) <-chan time.Time {
// note that time.Ticker is not an interface,
// and that if we instantiate one, we can't write to its channel
// hence we can't leverage that type.
c := make(chan time.Time)
go func() {
for {
unix := time.Now().UnixNano()
diff := time.Duration(peri... | go | func AlignedTick(period time.Duration) <-chan time.Time {
// note that time.Ticker is not an interface,
// and that if we instantiate one, we can't write to its channel
// hence we can't leverage that type.
c := make(chan time.Time)
go func() {
for {
unix := time.Now().UnixNano()
diff := time.Duration(peri... | [
"func",
"AlignedTick",
"(",
"period",
"time",
".",
"Duration",
")",
"<-",
"chan",
"time",
".",
"Time",
"{",
"// note that time.Ticker is not an interface,",
"// and that if we instantiate one, we can't write to its channel",
"// hence we can't leverage that type.",
"c",
":=",
"... | // AlignedTick returns a tick channel so that, let's say interval is a second
// then it will tick at every whole second, or if it's 60s than it's every whole
// minute. Note that in my testing this is about .0001 to 0.0002 seconds later due
// to scheduling etc. | [
"AlignedTick",
"returns",
"a",
"tick",
"channel",
"so",
"that",
"let",
"s",
"say",
"interval",
"is",
"a",
"second",
"then",
"it",
"will",
"tick",
"at",
"every",
"whole",
"second",
"or",
"if",
"it",
"s",
"60s",
"than",
"it",
"s",
"every",
"whole",
"minu... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/clock/clock.go#L9-L26 | train |
grafana/metrictank | api/middleware/tracer.go | Tracer | func Tracer(tracer opentracing.Tracer) macaron.Handler {
return func(macCtx *macaron.Context) {
path := pathSlug(macCtx.Req.URL.Path)
// graphite cluster requests use local=1
// this way we can differentiate "full" render requests from client to MT (encompassing data processing, proxing to graphite, etc)
// fr... | go | func Tracer(tracer opentracing.Tracer) macaron.Handler {
return func(macCtx *macaron.Context) {
path := pathSlug(macCtx.Req.URL.Path)
// graphite cluster requests use local=1
// this way we can differentiate "full" render requests from client to MT (encompassing data processing, proxing to graphite, etc)
// fr... | [
"func",
"Tracer",
"(",
"tracer",
"opentracing",
".",
"Tracer",
")",
"macaron",
".",
"Handler",
"{",
"return",
"func",
"(",
"macCtx",
"*",
"macaron",
".",
"Context",
")",
"{",
"path",
":=",
"pathSlug",
"(",
"macCtx",
".",
"Req",
".",
"URL",
".",
"Path",... | // Tracer returns a middleware that traces requests | [
"Tracer",
"returns",
"a",
"middleware",
"that",
"traces",
"requests"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/middleware/tracer.go#L32-L88 | train |
grafana/metrictank | conf/schemas.go | Get | func (s Schemas) Get(i uint16) Schema {
if i+1 > uint16(len(s.index)) {
return s.DefaultSchema
}
return s.index[i]
} | go | func (s Schemas) Get(i uint16) Schema {
if i+1 > uint16(len(s.index)) {
return s.DefaultSchema
}
return s.index[i]
} | [
"func",
"(",
"s",
"Schemas",
")",
"Get",
"(",
"i",
"uint16",
")",
"Schema",
"{",
"if",
"i",
"+",
"1",
">",
"uint16",
"(",
"len",
"(",
"s",
".",
"index",
")",
")",
"{",
"return",
"s",
".",
"DefaultSchema",
"\n",
"}",
"\n",
"return",
"s",
".",
... | // Get returns the schema setting corresponding to the given index | [
"Get",
"returns",
"the",
"schema",
"setting",
"corresponding",
"to",
"the",
"given",
"index"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/conf/schemas.go#L215-L220 | train |
grafana/metrictank | conf/schemas.go | TTLs | func (schemas Schemas) TTLs() []uint32 {
ttls := make(map[uint32]struct{})
for _, s := range schemas.raw {
for _, r := range s.Retentions {
ttls[uint32(r.MaxRetention())] = struct{}{}
}
}
for _, r := range schemas.DefaultSchema.Retentions {
ttls[uint32(r.MaxRetention())] = struct{}{}
}
var ttlSlice []uin... | go | func (schemas Schemas) TTLs() []uint32 {
ttls := make(map[uint32]struct{})
for _, s := range schemas.raw {
for _, r := range s.Retentions {
ttls[uint32(r.MaxRetention())] = struct{}{}
}
}
for _, r := range schemas.DefaultSchema.Retentions {
ttls[uint32(r.MaxRetention())] = struct{}{}
}
var ttlSlice []uin... | [
"func",
"(",
"schemas",
"Schemas",
")",
"TTLs",
"(",
")",
"[",
"]",
"uint32",
"{",
"ttls",
":=",
"make",
"(",
"map",
"[",
"uint32",
"]",
"struct",
"{",
"}",
")",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"schemas",
".",
"raw",
"{",
"for",
"_",... | // TTLs returns a slice of all TTL's seen amongst all archives of all schemas | [
"TTLs",
"returns",
"a",
"slice",
"of",
"all",
"TTL",
"s",
"seen",
"amongst",
"all",
"archives",
"of",
"all",
"schemas"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/conf/schemas.go#L223-L238 | train |
grafana/metrictank | conf/schemas.go | MaxChunkSpan | func (schemas Schemas) MaxChunkSpan() uint32 {
max := uint32(0)
for _, s := range schemas.raw {
for _, r := range s.Retentions {
max = util.Max(max, r.ChunkSpan)
}
}
for _, r := range schemas.DefaultSchema.Retentions {
max = util.Max(max, r.ChunkSpan)
}
return max
} | go | func (schemas Schemas) MaxChunkSpan() uint32 {
max := uint32(0)
for _, s := range schemas.raw {
for _, r := range s.Retentions {
max = util.Max(max, r.ChunkSpan)
}
}
for _, r := range schemas.DefaultSchema.Retentions {
max = util.Max(max, r.ChunkSpan)
}
return max
} | [
"func",
"(",
"schemas",
"Schemas",
")",
"MaxChunkSpan",
"(",
")",
"uint32",
"{",
"max",
":=",
"uint32",
"(",
"0",
")",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"schemas",
".",
"raw",
"{",
"for",
"_",
",",
"r",
":=",
"range",
"s",
".",
"Retentio... | // MaxChunkSpan returns the largest chunkspan seen amongst all archives of all schemas | [
"MaxChunkSpan",
"returns",
"the",
"largest",
"chunkspan",
"seen",
"amongst",
"all",
"archives",
"of",
"all",
"schemas"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/conf/schemas.go#L241-L252 | train |
grafana/metrictank | cmd/mt-index-cat/out/tpl_pattern_custom.go | patternCustom | func patternCustom(in ...interface{}) string {
usage := func() {
PatternCustomUsage("")
os.Exit(-1)
}
// one or more of "<chance> <operation>" followed by an input string at the end.
if len(in) < 3 || len(in)%2 != 1 {
usage()
}
input, ok := in[len(in)-1].(string)
if !ok {
usage()
}
var buckets []bucke... | go | func patternCustom(in ...interface{}) string {
usage := func() {
PatternCustomUsage("")
os.Exit(-1)
}
// one or more of "<chance> <operation>" followed by an input string at the end.
if len(in) < 3 || len(in)%2 != 1 {
usage()
}
input, ok := in[len(in)-1].(string)
if !ok {
usage()
}
var buckets []bucke... | [
"func",
"patternCustom",
"(",
"in",
"...",
"interface",
"{",
"}",
")",
"string",
"{",
"usage",
":=",
"func",
"(",
")",
"{",
"PatternCustomUsage",
"(",
"\"",
"\"",
")",
"\n",
"os",
".",
"Exit",
"(",
"-",
"1",
")",
"\n",
"}",
"\n\n",
"// one or more of... | // percentage chance, and function | [
"percentage",
"chance",
"and",
"function"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cmd/mt-index-cat/out/tpl_pattern_custom.go#L28-L95 | train |
grafana/metrictank | cmd/mt-index-cat/out/tpl_pattern_custom.go | ReplaceRandomConsecutiveNodesWildcard | func ReplaceRandomConsecutiveNodesWildcard(num int) func(in string) string {
return func(in string) string {
parts := strings.Split(in, ".")
if len(parts) < num {
log.Fatalf("metric %q has not enough nodes to replace %d nodes", in, num)
}
pos := rand.Intn(len(parts) - num + 1)
for i := pos; i < pos+num; i... | go | func ReplaceRandomConsecutiveNodesWildcard(num int) func(in string) string {
return func(in string) string {
parts := strings.Split(in, ".")
if len(parts) < num {
log.Fatalf("metric %q has not enough nodes to replace %d nodes", in, num)
}
pos := rand.Intn(len(parts) - num + 1)
for i := pos; i < pos+num; i... | [
"func",
"ReplaceRandomConsecutiveNodesWildcard",
"(",
"num",
"int",
")",
"func",
"(",
"in",
"string",
")",
"string",
"{",
"return",
"func",
"(",
"in",
"string",
")",
"string",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"in",
",",
"\"",
"\"",
")",
... | // ReplaceRandomConsecutiveNodesWildcard returns a function that will replace num consecutive random nodes with wildcards
// the implementation is rather naive and can be optimized | [
"ReplaceRandomConsecutiveNodesWildcard",
"returns",
"a",
"function",
"that",
"will",
"replace",
"num",
"consecutive",
"random",
"nodes",
"with",
"wildcards",
"the",
"implementation",
"is",
"rather",
"naive",
"and",
"can",
"be",
"optimized"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cmd/mt-index-cat/out/tpl_pattern_custom.go#L103-L115 | train |
grafana/metrictank | cmd/mt-store-cat/series.go | printPointSummary | func printPointSummary(ctx context.Context, store *cassandra.CassandraStore, tables []cassandra.Table, metrics []Metric, fromUnix, toUnix, fix uint32) {
for _, metric := range metrics {
fmt.Println("## Metric", metric)
for _, table := range tables {
fmt.Println("### Table", table.Name)
if fix != 0 {
poin... | go | func printPointSummary(ctx context.Context, store *cassandra.CassandraStore, tables []cassandra.Table, metrics []Metric, fromUnix, toUnix, fix uint32) {
for _, metric := range metrics {
fmt.Println("## Metric", metric)
for _, table := range tables {
fmt.Println("### Table", table.Name)
if fix != 0 {
poin... | [
"func",
"printPointSummary",
"(",
"ctx",
"context",
".",
"Context",
",",
"store",
"*",
"cassandra",
".",
"CassandraStore",
",",
"tables",
"[",
"]",
"cassandra",
".",
"Table",
",",
"metrics",
"[",
"]",
"Metric",
",",
"fromUnix",
",",
"toUnix",
",",
"fix",
... | // printPointSummary prints a summarized view of the points in the store corresponding to the given requirements | [
"printPointSummary",
"prints",
"a",
"summarized",
"view",
"of",
"the",
"points",
"in",
"the",
"store",
"corresponding",
"to",
"the",
"given",
"requirements"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cmd/mt-store-cat/series.go#L36-L53 | train |
grafana/metrictank | cmd/mt-index-cat/out/template_functions.go | pattern | func pattern(in string) string {
mode := rand.Intn(3)
if mode == 0 {
// in this mode, replaces a node with a wildcard
parts := strings.Split(in, ".")
parts[rand.Intn(len(parts))] = "*"
return strings.Join(parts, ".")
} else if mode == 1 {
// randomly replace chars with a *
// note that in 1/5 cases, noth... | go | func pattern(in string) string {
mode := rand.Intn(3)
if mode == 0 {
// in this mode, replaces a node with a wildcard
parts := strings.Split(in, ".")
parts[rand.Intn(len(parts))] = "*"
return strings.Join(parts, ".")
} else if mode == 1 {
// randomly replace chars with a *
// note that in 1/5 cases, noth... | [
"func",
"pattern",
"(",
"in",
"string",
")",
"string",
"{",
"mode",
":=",
"rand",
".",
"Intn",
"(",
"3",
")",
"\n",
"if",
"mode",
"==",
"0",
"{",
"// in this mode, replaces a node with a wildcard",
"parts",
":=",
"strings",
".",
"Split",
"(",
"in",
",",
... | // random choice between replacing a node with a wildcard, a char with a wildcard, and passthrough | [
"random",
"choice",
"between",
"replacing",
"a",
"node",
"with",
"a",
"wildcard",
"a",
"char",
"with",
"a",
"wildcard",
"and",
"passthrough"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cmd/mt-index-cat/out/template_functions.go#L10-L31 | train |
grafana/metrictank | cmd/mt-index-cat/out/template_functions.go | roundDuration | func roundDuration(in int64) int64 {
abs := in
if abs < 0 {
abs = -abs
}
if abs <= 10 { // 10s -> don't round
return in
} else if abs <= 60 { // 1min -> round to 10s
return round(in, 10)
} else if abs <= 600 { // 10min -> round to 1min
return round(in, 60)
} else if abs <= 3600 { // 1h -> round to 10min
... | go | func roundDuration(in int64) int64 {
abs := in
if abs < 0 {
abs = -abs
}
if abs <= 10 { // 10s -> don't round
return in
} else if abs <= 60 { // 1min -> round to 10s
return round(in, 10)
} else if abs <= 600 { // 10min -> round to 1min
return round(in, 60)
} else if abs <= 3600 { // 1h -> round to 10min
... | [
"func",
"roundDuration",
"(",
"in",
"int64",
")",
"int64",
"{",
"abs",
":=",
"in",
"\n",
"if",
"abs",
"<",
"0",
"{",
"abs",
"=",
"-",
"abs",
"\n",
"}",
"\n",
"if",
"abs",
"<=",
"10",
"{",
"// 10s -> don't round",
"return",
"in",
"\n",
"}",
"else",
... | // roundDuration rounds a second-specified duration for rough classification | [
"roundDuration",
"rounds",
"a",
"second",
"-",
"specified",
"duration",
"for",
"rough",
"classification"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cmd/mt-index-cat/out/template_functions.go#L39-L61 | train |
grafana/metrictank | cmd/mt-index-cat/out/template_functions.go | round | func round(d, r int64) int64 {
neg := d < 0
if neg {
d = -d
}
if m := d % r; m+m < r {
d = d - m
} else {
d = d + r - m
}
if neg {
return -d
}
return d
} | go | func round(d, r int64) int64 {
neg := d < 0
if neg {
d = -d
}
if m := d % r; m+m < r {
d = d - m
} else {
d = d + r - m
}
if neg {
return -d
}
return d
} | [
"func",
"round",
"(",
"d",
",",
"r",
"int64",
")",
"int64",
"{",
"neg",
":=",
"d",
"<",
"0",
"\n",
"if",
"neg",
"{",
"d",
"=",
"-",
"d",
"\n",
"}",
"\n",
"if",
"m",
":=",
"d",
"%",
"r",
";",
"m",
"+",
"m",
"<",
"r",
"{",
"d",
"=",
"d"... | // round rounds number d to the nearest r-boundary | [
"round",
"rounds",
"number",
"d",
"to",
"the",
"nearest",
"r",
"-",
"boundary"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cmd/mt-index-cat/out/template_functions.go#L64-L78 | train |
grafana/metrictank | cmd/mt-store-cat/chunk_by_ttl.go | showKeyTTL | func showKeyTTL(iter *gocql.Iter, groupTTL string) {
roundTTL := 1
switch groupTTL {
case "m":
roundTTL = 60
case "h":
roundTTL = 60 * 60
case "d":
roundTTL = 60 * 60 * 24
}
var b bucket
bucketMap := make(map[bucket]int)
for iter.Scan(&b.key, &b.ttl) {
b.ttl /= roundTTL
bucketMap[b] += 1
}
var bu... | go | func showKeyTTL(iter *gocql.Iter, groupTTL string) {
roundTTL := 1
switch groupTTL {
case "m":
roundTTL = 60
case "h":
roundTTL = 60 * 60
case "d":
roundTTL = 60 * 60 * 24
}
var b bucket
bucketMap := make(map[bucket]int)
for iter.Scan(&b.key, &b.ttl) {
b.ttl /= roundTTL
bucketMap[b] += 1
}
var bu... | [
"func",
"showKeyTTL",
"(",
"iter",
"*",
"gocql",
".",
"Iter",
",",
"groupTTL",
"string",
")",
"{",
"roundTTL",
":=",
"1",
"\n",
"switch",
"groupTTL",
"{",
"case",
"\"",
"\"",
":",
"roundTTL",
"=",
"60",
"\n",
"case",
"\"",
"\"",
":",
"roundTTL",
"=",... | // shows an overview of all keys and their ttls and closes the iter
// iter must return rows of key and ttl. | [
"shows",
"an",
"overview",
"of",
"all",
"keys",
"and",
"their",
"ttls",
"and",
"closes",
"the",
"iter",
"iter",
"must",
"return",
"rows",
"of",
"key",
"and",
"ttl",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cmd/mt-store-cat/chunk_by_ttl.go#L30-L65 | train |
grafana/metrictank | conf/retention.go | ParseRetentions | func ParseRetentions(defs string) (Retentions, error) {
retentions := make(Retentions, 0)
for i, def := range strings.Split(defs, ",") {
def = strings.TrimSpace(def)
parts := strings.Split(def, ":")
if len(parts) < 2 || len(parts) > 5 {
return nil, fmt.Errorf("bad retentions spec %q", def)
}
// try old ... | go | func ParseRetentions(defs string) (Retentions, error) {
retentions := make(Retentions, 0)
for i, def := range strings.Split(defs, ",") {
def = strings.TrimSpace(def)
parts := strings.Split(def, ":")
if len(parts) < 2 || len(parts) > 5 {
return nil, fmt.Errorf("bad retentions spec %q", def)
}
// try old ... | [
"func",
"ParseRetentions",
"(",
"defs",
"string",
")",
"(",
"Retentions",
",",
"error",
")",
"{",
"retentions",
":=",
"make",
"(",
"Retentions",
",",
"0",
")",
"\n",
"for",
"i",
",",
"def",
":=",
"range",
"strings",
".",
"Split",
"(",
"defs",
",",
"\... | // ParseRetentions parses retention definitions into a Retentions structure | [
"ParseRetentions",
"parses",
"retention",
"definitions",
"into",
"a",
"Retentions",
"structure"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/conf/retention.go#L92-L173 | train |
grafana/metrictank | cmd/mt-store-cat/metrics.go | getMetrics | func getMetrics(store *cassandra.CassandraStore, prefix, substr, glob string, archive schema.Archive) ([]Metric, error) {
var metrics []Metric
iter := store.Session.Query("select id, name from metric_idx").Iter()
var m Metric
var idString string
for iter.Scan(&idString, &m.name) {
if match(prefix, substr, glob, ... | go | func getMetrics(store *cassandra.CassandraStore, prefix, substr, glob string, archive schema.Archive) ([]Metric, error) {
var metrics []Metric
iter := store.Session.Query("select id, name from metric_idx").Iter()
var m Metric
var idString string
for iter.Scan(&idString, &m.name) {
if match(prefix, substr, glob, ... | [
"func",
"getMetrics",
"(",
"store",
"*",
"cassandra",
".",
"CassandraStore",
",",
"prefix",
",",
"substr",
",",
"glob",
"string",
",",
"archive",
"schema",
".",
"Archive",
")",
"(",
"[",
"]",
"Metric",
",",
"error",
")",
"{",
"var",
"metrics",
"[",
"]"... | // getMetrics lists all metrics from the store matching the given condition. | [
"getMetrics",
"lists",
"all",
"metrics",
"from",
"the",
"store",
"matching",
"the",
"given",
"condition",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cmd/mt-store-cat/metrics.go#L53-L77 | train |
grafana/metrictank | cmd/mt-store-cat/metrics.go | getMetric | func getMetric(store *cassandra.CassandraStore, amkey schema.AMKey) ([]Metric, error) {
var metrics []Metric
// index only stores MKey's, not AMKey's.
iter := store.Session.Query("select name from metric_idx where id=? ALLOW FILTERING", amkey.MKey.String()).Iter()
var m Metric
for iter.Scan(&m.name) {
m.AMKey = ... | go | func getMetric(store *cassandra.CassandraStore, amkey schema.AMKey) ([]Metric, error) {
var metrics []Metric
// index only stores MKey's, not AMKey's.
iter := store.Session.Query("select name from metric_idx where id=? ALLOW FILTERING", amkey.MKey.String()).Iter()
var m Metric
for iter.Scan(&m.name) {
m.AMKey = ... | [
"func",
"getMetric",
"(",
"store",
"*",
"cassandra",
".",
"CassandraStore",
",",
"amkey",
"schema",
".",
"AMKey",
")",
"(",
"[",
"]",
"Metric",
",",
"error",
")",
"{",
"var",
"metrics",
"[",
"]",
"Metric",
"\n",
"// index only stores MKey's, not AMKey's.",
"... | // getMetric returns the metric for the given AMKey | [
"getMetric",
"returns",
"the",
"metric",
"for",
"the",
"given",
"AMKey"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cmd/mt-store-cat/metrics.go#L80-L97 | train |
grafana/metrictank | consolidation/consolidate.go | ConsolidateStable | func ConsolidateStable(points []schema.Point, interval, maxDataPoints uint32, consolidator Consolidator) ([]schema.Point, uint32) {
aggNum := AggEvery(uint32(len(points)), maxDataPoints)
// note that the amount of points to strip is always < 1 postAggInterval's worth.
// there's 2 important considerations here:
// ... | go | func ConsolidateStable(points []schema.Point, interval, maxDataPoints uint32, consolidator Consolidator) ([]schema.Point, uint32) {
aggNum := AggEvery(uint32(len(points)), maxDataPoints)
// note that the amount of points to strip is always < 1 postAggInterval's worth.
// there's 2 important considerations here:
// ... | [
"func",
"ConsolidateStable",
"(",
"points",
"[",
"]",
"schema",
".",
"Point",
",",
"interval",
",",
"maxDataPoints",
"uint32",
",",
"consolidator",
"Consolidator",
")",
"(",
"[",
"]",
"schema",
".",
"Point",
",",
"uint32",
")",
"{",
"aggNum",
":=",
"AggEve... | // ConsolidateStable consolidates points in a "stable" way, meaning if you run the same function again so that the input
// receives new points at the end and old points get removed at the beginning, we keep picking the same points to consolidate together
// interval is the interval between the input points | [
"ConsolidateStable",
"consolidates",
"points",
"in",
"a",
"stable",
"way",
"meaning",
"if",
"you",
"run",
"the",
"same",
"function",
"again",
"so",
"that",
"the",
"input",
"receives",
"new",
"points",
"at",
"the",
"end",
"and",
"old",
"points",
"get",
"remov... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/consolidation/consolidate.go#L79-L108 | train |
grafana/metrictank | api/dataprocessor.go | doRecover | func doRecover(errp *error) {
e := recover()
if e != nil {
if _, ok := e.(runtime.Error); ok {
panic(e)
}
if err, ok := e.(error); ok {
*errp = err
} else if errStr, ok := e.(string); ok {
*errp = errors.New(errStr)
} else {
*errp = fmt.Errorf("%v", e)
}
}
return
} | go | func doRecover(errp *error) {
e := recover()
if e != nil {
if _, ok := e.(runtime.Error); ok {
panic(e)
}
if err, ok := e.(error); ok {
*errp = err
} else if errStr, ok := e.(string); ok {
*errp = errors.New(errStr)
} else {
*errp = fmt.Errorf("%v", e)
}
}
return
} | [
"func",
"doRecover",
"(",
"errp",
"*",
"error",
")",
"{",
"e",
":=",
"recover",
"(",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"if",
"_",
",",
"ok",
":=",
"e",
".",
"(",
"runtime",
".",
"Error",
")",
";",
"ok",
"{",
"panic",
"(",
"e",
")",
"\... | // doRecover is the handler that turns panics into returns from the top level of getTarget. | [
"doRecover",
"is",
"the",
"handler",
"that",
"turns",
"panics",
"into",
"returns",
"from",
"the",
"top",
"level",
"of",
"getTarget",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/dataprocessor.go#L25-L40 | train |
grafana/metrictank | api/dataprocessor.go | getTargetsRemote | func (s *Server) getTargetsRemote(ctx context.Context, remoteReqs map[string][]models.Req) ([]models.Series, error) {
responses := make(chan getTargetsResp, len(remoteReqs))
rCtx, cancel := context.WithCancel(ctx)
defer cancel()
wg := sync.WaitGroup{}
wg.Add(len(remoteReqs))
for _, nodeReqs := range remoteReqs {
... | go | func (s *Server) getTargetsRemote(ctx context.Context, remoteReqs map[string][]models.Req) ([]models.Series, error) {
responses := make(chan getTargetsResp, len(remoteReqs))
rCtx, cancel := context.WithCancel(ctx)
defer cancel()
wg := sync.WaitGroup{}
wg.Add(len(remoteReqs))
for _, nodeReqs := range remoteReqs {
... | [
"func",
"(",
"s",
"*",
"Server",
")",
"getTargetsRemote",
"(",
"ctx",
"context",
".",
"Context",
",",
"remoteReqs",
"map",
"[",
"string",
"]",
"[",
"]",
"models",
".",
"Req",
")",
"(",
"[",
"]",
"models",
".",
"Series",
",",
"error",
")",
"{",
"res... | // getTargetsRemote issues the requests on other nodes
// it's nothing more than a thin network wrapper around getTargetsLocal of a peer. | [
"getTargetsRemote",
"issues",
"the",
"requests",
"on",
"other",
"nodes",
"it",
"s",
"nothing",
"more",
"than",
"a",
"thin",
"network",
"wrapper",
"around",
"getTargetsLocal",
"of",
"a",
"peer",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/dataprocessor.go#L194-L239 | train |
grafana/metrictank | api/dataprocessor.go | getTargetsLocal | func (s *Server) getTargetsLocal(ctx context.Context, reqs []models.Req) ([]models.Series, error) {
log.Debugf("DP getTargetsLocal: handling %d reqs locally", len(reqs))
responses := make(chan getTargetsResp, len(reqs))
var wg sync.WaitGroup
reqLimiter := util.NewLimiter(getTargetsConcurrency)
rCtx, cancel := co... | go | func (s *Server) getTargetsLocal(ctx context.Context, reqs []models.Req) ([]models.Series, error) {
log.Debugf("DP getTargetsLocal: handling %d reqs locally", len(reqs))
responses := make(chan getTargetsResp, len(reqs))
var wg sync.WaitGroup
reqLimiter := util.NewLimiter(getTargetsConcurrency)
rCtx, cancel := co... | [
"func",
"(",
"s",
"*",
"Server",
")",
"getTargetsLocal",
"(",
"ctx",
"context",
".",
"Context",
",",
"reqs",
"[",
"]",
"models",
".",
"Req",
")",
"(",
"[",
"]",
"models",
".",
"Series",
",",
"error",
")",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"... | // error is the error of the first failing target request | [
"error",
"is",
"the",
"error",
"of",
"the",
"first",
"failing",
"target",
"request"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/dataprocessor.go#L242-L302 | train |
grafana/metrictank | api/dataprocessor.go | mergeSeries | func mergeSeries(in []models.Series) []models.Series {
type segment struct {
target string
query string
from uint32
to uint32
con consolidation.Consolidator
}
seriesByTarget := make(map[segment][]models.Series)
for _, series := range in {
s := segment{
series.Target,
series.QueryPatt,
... | go | func mergeSeries(in []models.Series) []models.Series {
type segment struct {
target string
query string
from uint32
to uint32
con consolidation.Consolidator
}
seriesByTarget := make(map[segment][]models.Series)
for _, series := range in {
s := segment{
series.Target,
series.QueryPatt,
... | [
"func",
"mergeSeries",
"(",
"in",
"[",
"]",
"models",
".",
"Series",
")",
"[",
"]",
"models",
".",
"Series",
"{",
"type",
"segment",
"struct",
"{",
"target",
"string",
"\n",
"query",
"string",
"\n",
"from",
"uint32",
"\n",
"to",
"uint32",
"\n",
"con",
... | // check for duplicate series names for the same query. If found merge the results. | [
"check",
"for",
"duplicate",
"series",
"names",
"for",
"the",
"same",
"query",
".",
"If",
"found",
"merge",
"the",
"results",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/dataprocessor.go#L592-L634 | train |
grafana/metrictank | mdata/cwr.go | NewChunkWriteRequest | func NewChunkWriteRequest(metric *AggMetric, key schema.AMKey, chunk *chunk.Chunk, ttl, span uint32, ts time.Time) ChunkWriteRequest {
return ChunkWriteRequest{metric, key, chunk, ttl, span, ts}
} | go | func NewChunkWriteRequest(metric *AggMetric, key schema.AMKey, chunk *chunk.Chunk, ttl, span uint32, ts time.Time) ChunkWriteRequest {
return ChunkWriteRequest{metric, key, chunk, ttl, span, ts}
} | [
"func",
"NewChunkWriteRequest",
"(",
"metric",
"*",
"AggMetric",
",",
"key",
"schema",
".",
"AMKey",
",",
"chunk",
"*",
"chunk",
".",
"Chunk",
",",
"ttl",
",",
"span",
"uint32",
",",
"ts",
"time",
".",
"Time",
")",
"ChunkWriteRequest",
"{",
"return",
"Ch... | // NewChunkWriteRequest creates a new ChunkWriteRequest | [
"NewChunkWriteRequest",
"creates",
"a",
"new",
"ChunkWriteRequest"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/cwr.go#L21-L23 | train |
grafana/metrictank | mdata/chunk/tsz/tszlong.go | Iter | func (s *SeriesLong) Iter() *IterLong {
s.Lock()
w := s.bw.clone()
s.Unlock()
finishV2(w)
iter, _ := bstreamIteratorLong(s.T0, w)
return iter
} | go | func (s *SeriesLong) Iter() *IterLong {
s.Lock()
w := s.bw.clone()
s.Unlock()
finishV2(w)
iter, _ := bstreamIteratorLong(s.T0, w)
return iter
} | [
"func",
"(",
"s",
"*",
"SeriesLong",
")",
"Iter",
"(",
")",
"*",
"IterLong",
"{",
"s",
".",
"Lock",
"(",
")",
"\n",
"w",
":=",
"s",
".",
"bw",
".",
"clone",
"(",
")",
"\n",
"s",
".",
"Unlock",
"(",
")",
"\n\n",
"finishV2",
"(",
"w",
")",
"\... | // IterLong lets you iterate over a series. It is not concurrency-safe. | [
"IterLong",
"lets",
"you",
"iterate",
"over",
"a",
"series",
".",
"It",
"is",
"not",
"concurrency",
"-",
"safe",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/chunk/tsz/tszlong.go#L143-L151 | train |
grafana/metrictank | mdata/chunk/tsz/tszlong.go | NewIteratorLong | func NewIteratorLong(t0 uint32, b []byte) (*IterLong, error) {
return bstreamIteratorLong(t0, newBReader(b))
} | go | func NewIteratorLong(t0 uint32, b []byte) (*IterLong, error) {
return bstreamIteratorLong(t0, newBReader(b))
} | [
"func",
"NewIteratorLong",
"(",
"t0",
"uint32",
",",
"b",
"[",
"]",
"byte",
")",
"(",
"*",
"IterLong",
",",
"error",
")",
"{",
"return",
"bstreamIteratorLong",
"(",
"t0",
",",
"newBReader",
"(",
"b",
")",
")",
"\n",
"}"
] | // NewIteratorLong for the series | [
"NewIteratorLong",
"for",
"the",
"series"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/chunk/tsz/tszlong.go#L182-L184 | train |
grafana/metrictank | mdata/chunk/tsz/tszlong.go | Next | func (it *IterLong) Next() bool {
if it.err != nil || it.finished {
return false
}
var first bool
if it.t == 0 {
it.t = it.T0
first = true
}
// read delta-of-delta
dod, ok := it.dod()
if !ok {
return false
}
it.tDelta += uint32(dod)
it.t = it.t + it.tDelta
if first {
// first point. read the ... | go | func (it *IterLong) Next() bool {
if it.err != nil || it.finished {
return false
}
var first bool
if it.t == 0 {
it.t = it.T0
first = true
}
// read delta-of-delta
dod, ok := it.dod()
if !ok {
return false
}
it.tDelta += uint32(dod)
it.t = it.t + it.tDelta
if first {
// first point. read the ... | [
"func",
"(",
"it",
"*",
"IterLong",
")",
"Next",
"(",
")",
"bool",
"{",
"if",
"it",
".",
"err",
"!=",
"nil",
"||",
"it",
".",
"finished",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"var",
"first",
"bool",
"\n",
"if",
"it",
".",
"t",
"==",
"0",
... | // Next iteration of the series iterator | [
"Next",
"iteration",
"of",
"the",
"series",
"iterator"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/chunk/tsz/tszlong.go#L241-L325 | train |
grafana/metrictank | stats/tick.go | tick | func tick(period time.Duration) chan time.Time {
ch := make(chan time.Time)
go func() {
for {
now := time.Now()
nowUnix := now.UnixNano()
diff := period - (time.Duration(nowUnix) % period)
ideal := now.Add(diff)
time.Sleep(diff)
// try to write, if it blocks, skip the tick
select {
case ch ... | go | func tick(period time.Duration) chan time.Time {
ch := make(chan time.Time)
go func() {
for {
now := time.Now()
nowUnix := now.UnixNano()
diff := period - (time.Duration(nowUnix) % period)
ideal := now.Add(diff)
time.Sleep(diff)
// try to write, if it blocks, skip the tick
select {
case ch ... | [
"func",
"tick",
"(",
"period",
"time",
".",
"Duration",
")",
"chan",
"time",
".",
"Time",
"{",
"ch",
":=",
"make",
"(",
"chan",
"time",
".",
"Time",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"for",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
... | // provides "clean" ticks at precise intervals, and delivers them shortly after | [
"provides",
"clean",
"ticks",
"at",
"precise",
"intervals",
"and",
"delivers",
"them",
"shortly",
"after"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/stats/tick.go#L6-L24 | train |
grafana/metrictank | api/models/request.go | Trace | func (r Req) Trace(span opentracing.Span) {
span.SetTag("key", r.MKey)
span.SetTag("target", r.Target)
span.SetTag("pattern", r.Pattern)
span.SetTag("from", r.From)
span.SetTag("to", r.To)
span.SetTag("span", r.To-r.From-1)
span.SetTag("mdp", r.MaxPoints)
span.SetTag("rawInterval", r.RawInterval)
span.SetTag("... | go | func (r Req) Trace(span opentracing.Span) {
span.SetTag("key", r.MKey)
span.SetTag("target", r.Target)
span.SetTag("pattern", r.Pattern)
span.SetTag("from", r.From)
span.SetTag("to", r.To)
span.SetTag("span", r.To-r.From-1)
span.SetTag("mdp", r.MaxPoints)
span.SetTag("rawInterval", r.RawInterval)
span.SetTag("... | [
"func",
"(",
"r",
"Req",
")",
"Trace",
"(",
"span",
"opentracing",
".",
"Span",
")",
"{",
"span",
".",
"SetTag",
"(",
"\"",
"\"",
",",
"r",
".",
"MKey",
")",
"\n",
"span",
".",
"SetTag",
"(",
"\"",
"\"",
",",
"r",
".",
"Target",
")",
"\n",
"s... | // Trace puts all request properties as tags in a span
// good for when a span deals with 1 request | [
"Trace",
"puts",
"all",
"request",
"properties",
"as",
"tags",
"in",
"a",
"span",
"good",
"for",
"when",
"a",
"span",
"deals",
"with",
"1",
"request"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/models/request.go#L75-L93 | train |
grafana/metrictank | api/models/request.go | TraceLog | func (r Req) TraceLog(span opentracing.Span) {
span.LogFields(
log.Object("key", r.MKey),
log.String("target", r.Target),
log.String("pattern", r.Pattern),
log.Int("from", int(r.From)),
log.Int("to", int(r.To)),
log.Int("span", int(r.To-r.From-1)),
log.Int("mdp", int(r.MaxPoints)),
log.Int("rawInterval... | go | func (r Req) TraceLog(span opentracing.Span) {
span.LogFields(
log.Object("key", r.MKey),
log.String("target", r.Target),
log.String("pattern", r.Pattern),
log.Int("from", int(r.From)),
log.Int("to", int(r.To)),
log.Int("span", int(r.To-r.From-1)),
log.Int("mdp", int(r.MaxPoints)),
log.Int("rawInterval... | [
"func",
"(",
"r",
"Req",
")",
"TraceLog",
"(",
"span",
"opentracing",
".",
"Span",
")",
"{",
"span",
".",
"LogFields",
"(",
"log",
".",
"Object",
"(",
"\"",
"\"",
",",
"r",
".",
"MKey",
")",
",",
"log",
".",
"String",
"(",
"\"",
"\"",
",",
"r",... | // TraceLog puts all request properties in a span log entry
// good for when a span deals with multiple requests
// note that the amount of data generated here can be up to
// 1000~1500 bytes | [
"TraceLog",
"puts",
"all",
"request",
"properties",
"in",
"a",
"span",
"log",
"entry",
"good",
"for",
"when",
"a",
"span",
"deals",
"with",
"multiple",
"requests",
"note",
"that",
"the",
"amount",
"of",
"data",
"generated",
"here",
"can",
"be",
"up",
"to",... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/models/request.go#L99-L119 | train |
grafana/metrictank | conf/aggregations.go | NewAggregations | func NewAggregations() Aggregations {
return Aggregations{
Data: make([]Aggregation, 0),
DefaultAggregation: Aggregation{
Name: "default",
Pattern: regexp.MustCompile(".*"),
XFilesFactor: 0.5,
AggregationMethod: []Method{Avg},
},
}
} | go | func NewAggregations() Aggregations {
return Aggregations{
Data: make([]Aggregation, 0),
DefaultAggregation: Aggregation{
Name: "default",
Pattern: regexp.MustCompile(".*"),
XFilesFactor: 0.5,
AggregationMethod: []Method{Avg},
},
}
} | [
"func",
"NewAggregations",
"(",
")",
"Aggregations",
"{",
"return",
"Aggregations",
"{",
"Data",
":",
"make",
"(",
"[",
"]",
"Aggregation",
",",
"0",
")",
",",
"DefaultAggregation",
":",
"Aggregation",
"{",
"Name",
":",
"\"",
"\"",
",",
"Pattern",
":",
"... | // NewAggregations create instance of Aggregations | [
"NewAggregations",
"create",
"instance",
"of",
"Aggregations"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/conf/aggregations.go#L26-L36 | train |
grafana/metrictank | conf/aggregations.go | ReadAggregations | func ReadAggregations(file string) (Aggregations, error) {
config, err := configparser.Read(file)
if err != nil {
return Aggregations{}, err
}
sections, err := config.AllSections()
if err != nil {
return Aggregations{}, err
}
result := NewAggregations()
for _, s := range sections {
item := Aggregation{}... | go | func ReadAggregations(file string) (Aggregations, error) {
config, err := configparser.Read(file)
if err != nil {
return Aggregations{}, err
}
sections, err := config.AllSections()
if err != nil {
return Aggregations{}, err
}
result := NewAggregations()
for _, s := range sections {
item := Aggregation{}... | [
"func",
"ReadAggregations",
"(",
"file",
"string",
")",
"(",
"Aggregations",
",",
"error",
")",
"{",
"config",
",",
"err",
":=",
"configparser",
".",
"Read",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Aggregations",
"{",
"}",
","... | // ReadAggregations returns the defined aggregations from a storage-aggregation.conf file
// and adds the default | [
"ReadAggregations",
"returns",
"the",
"defined",
"aggregations",
"from",
"a",
"storage",
"-",
"aggregation",
".",
"conf",
"file",
"and",
"adds",
"the",
"default"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/conf/aggregations.go#L40-L92 | train |
grafana/metrictank | conf/aggregations.go | Match | func (a Aggregations) Match(metric string) (uint16, Aggregation) {
for i, s := range a.Data {
if s.Pattern.MatchString(metric) {
return uint16(i), s
}
}
return uint16(len(a.Data)), a.DefaultAggregation
} | go | func (a Aggregations) Match(metric string) (uint16, Aggregation) {
for i, s := range a.Data {
if s.Pattern.MatchString(metric) {
return uint16(i), s
}
}
return uint16(len(a.Data)), a.DefaultAggregation
} | [
"func",
"(",
"a",
"Aggregations",
")",
"Match",
"(",
"metric",
"string",
")",
"(",
"uint16",
",",
"Aggregation",
")",
"{",
"for",
"i",
",",
"s",
":=",
"range",
"a",
".",
"Data",
"{",
"if",
"s",
".",
"Pattern",
".",
"MatchString",
"(",
"metric",
")"... | // Match returns the correct aggregation setting for the given metric
// it can always find a valid setting, because there's a default catch all
// also returns the index of the setting, to efficiently reference it | [
"Match",
"returns",
"the",
"correct",
"aggregation",
"setting",
"for",
"the",
"given",
"metric",
"it",
"can",
"always",
"find",
"a",
"valid",
"setting",
"because",
"there",
"s",
"a",
"default",
"catch",
"all",
"also",
"returns",
"the",
"index",
"of",
"the",
... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/conf/aggregations.go#L97-L104 | train |
grafana/metrictank | conf/aggregations.go | Get | func (a Aggregations) Get(i uint16) Aggregation {
if i+1 > uint16(len(a.Data)) {
return a.DefaultAggregation
}
return a.Data[i]
} | go | func (a Aggregations) Get(i uint16) Aggregation {
if i+1 > uint16(len(a.Data)) {
return a.DefaultAggregation
}
return a.Data[i]
} | [
"func",
"(",
"a",
"Aggregations",
")",
"Get",
"(",
"i",
"uint16",
")",
"Aggregation",
"{",
"if",
"i",
"+",
"1",
">",
"uint16",
"(",
"len",
"(",
"a",
".",
"Data",
")",
")",
"{",
"return",
"a",
".",
"DefaultAggregation",
"\n",
"}",
"\n",
"return",
... | // Get returns the aggregation setting corresponding to the given index | [
"Get",
"returns",
"the",
"aggregation",
"setting",
"corresponding",
"to",
"the",
"given",
"index"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/conf/aggregations.go#L107-L112 | train |
grafana/metrictank | idx/idx.go | NewArchiveBare | func NewArchiveBare(name string) Archive {
return Archive{
MetricDefinition: schema.MetricDefinition{
Name: name,
},
}
} | go | func NewArchiveBare(name string) Archive {
return Archive{
MetricDefinition: schema.MetricDefinition{
Name: name,
},
}
} | [
"func",
"NewArchiveBare",
"(",
"name",
"string",
")",
"Archive",
"{",
"return",
"Archive",
"{",
"MetricDefinition",
":",
"schema",
".",
"MetricDefinition",
"{",
"Name",
":",
"name",
",",
"}",
",",
"}",
"\n",
"}"
] | // used primarily by tests, for convenience | [
"used",
"primarily",
"by",
"tests",
"for",
"convenience"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/idx.go#L30-L36 | train |
grafana/metrictank | api/middleware/stats.go | RequestStats | func RequestStats() macaron.Handler {
stats := requestStats{
responseCounts: make(map[string]map[int]*stats.Counter32),
latencyHistograms: make(map[string]*stats.LatencyHistogram15s32),
sizeMeters: make(map[string]*stats.Meter32),
}
return func(ctx *macaron.Context) {
start := time.Now()
rw := c... | go | func RequestStats() macaron.Handler {
stats := requestStats{
responseCounts: make(map[string]map[int]*stats.Counter32),
latencyHistograms: make(map[string]*stats.LatencyHistogram15s32),
sizeMeters: make(map[string]*stats.Meter32),
}
return func(ctx *macaron.Context) {
start := time.Now()
rw := c... | [
"func",
"RequestStats",
"(",
")",
"macaron",
".",
"Handler",
"{",
"stats",
":=",
"requestStats",
"{",
"responseCounts",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"int",
"]",
"*",
"stats",
".",
"Counter32",
")",
",",
"latencyHistograms",
":... | // RequestStats returns a middleware that tracks request metrics. | [
"RequestStats",
"returns",
"a",
"middleware",
"that",
"tracks",
"request",
"metrics",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/middleware/stats.go#L64-L92 | train |
grafana/metrictank | api/response/error.go | WrapErrorForTagDB | func WrapErrorForTagDB(e error) *ErrorResp {
b, err := json.Marshal(TagDBError{Error: e.Error()})
if err != nil {
return &ErrorResp{
err: "{\"error\": \"failed to encode error message\"}",
code: http.StatusInternalServerError,
}
}
resp := &ErrorResp{
err: string(b),
code: http.StatusInternalServerE... | go | func WrapErrorForTagDB(e error) *ErrorResp {
b, err := json.Marshal(TagDBError{Error: e.Error()})
if err != nil {
return &ErrorResp{
err: "{\"error\": \"failed to encode error message\"}",
code: http.StatusInternalServerError,
}
}
resp := &ErrorResp{
err: string(b),
code: http.StatusInternalServerE... | [
"func",
"WrapErrorForTagDB",
"(",
"e",
"error",
")",
"*",
"ErrorResp",
"{",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"TagDBError",
"{",
"Error",
":",
"e",
".",
"Error",
"(",
")",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // graphite's http tagdb client requires a specific error format | [
"graphite",
"s",
"http",
"tagdb",
"client",
"requires",
"a",
"specific",
"error",
"format"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/response/error.go#L43-L63 | train |
grafana/metrictank | idx/cassandra/config.go | NewIdxConfig | func NewIdxConfig() *IdxConfig {
return &IdxConfig{
Enabled: true,
hosts: "localhost:9042",
keyspace: "metrictank",
consistency: "one",
timeout: time.Second,
numConns: 10,
writeQueueSize: 100000,
... | go | func NewIdxConfig() *IdxConfig {
return &IdxConfig{
Enabled: true,
hosts: "localhost:9042",
keyspace: "metrictank",
consistency: "one",
timeout: time.Second,
numConns: 10,
writeQueueSize: 100000,
... | [
"func",
"NewIdxConfig",
"(",
")",
"*",
"IdxConfig",
"{",
"return",
"&",
"IdxConfig",
"{",
"Enabled",
":",
"true",
",",
"hosts",
":",
"\"",
"\"",
",",
"keyspace",
":",
"\"",
"\"",
",",
"consistency",
":",
"\"",
"\"",
",",
"timeout",
":",
"time",
".",
... | // NewIdxConfig returns IdxConfig with default values set. | [
"NewIdxConfig",
"returns",
"IdxConfig",
"with",
"default",
"values",
"set",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/cassandra/config.go#L46-L70 | train |
grafana/metrictank | idx/cassandra/config.go | Validate | func (cfg *IdxConfig) Validate() error {
if cfg.pruneInterval == 0 {
return errors.New("pruneInterval must be greater then 0. " + timeUnits)
}
if cfg.timeout == 0 {
return errors.New("timeout must be greater than 0. " + timeUnits)
}
return nil
} | go | func (cfg *IdxConfig) Validate() error {
if cfg.pruneInterval == 0 {
return errors.New("pruneInterval must be greater then 0. " + timeUnits)
}
if cfg.timeout == 0 {
return errors.New("timeout must be greater than 0. " + timeUnits)
}
return nil
} | [
"func",
"(",
"cfg",
"*",
"IdxConfig",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"cfg",
".",
"pruneInterval",
"==",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"timeUnits",
")",
"\n",
"}",
"\n",
"if",
"cfg",
".",
"timeout",
... | // Validate validates IdxConfig settings | [
"Validate",
"validates",
"IdxConfig",
"settings"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/cassandra/config.go#L73-L81 | train |
grafana/metrictank | mdata/aggmetric.go | NewAggMetric | func NewAggMetric(store Store, cachePusher cache.CachePusher, key schema.AMKey, retentions conf.Retentions, reorderWindow, interval uint32, agg *conf.Aggregation, dropFirstChunk bool) *AggMetric {
// note: during parsing of retentions, we assure there's at least 1.
ret := retentions[0]
m := AggMetric{
cachePushe... | go | func NewAggMetric(store Store, cachePusher cache.CachePusher, key schema.AMKey, retentions conf.Retentions, reorderWindow, interval uint32, agg *conf.Aggregation, dropFirstChunk bool) *AggMetric {
// note: during parsing of retentions, we assure there's at least 1.
ret := retentions[0]
m := AggMetric{
cachePushe... | [
"func",
"NewAggMetric",
"(",
"store",
"Store",
",",
"cachePusher",
"cache",
".",
"CachePusher",
",",
"key",
"schema",
".",
"AMKey",
",",
"retentions",
"conf",
".",
"Retentions",
",",
"reorderWindow",
",",
"interval",
"uint32",
",",
"agg",
"*",
"conf",
".",
... | // NewAggMetric creates a metric with given key, it retains the given number of chunks each chunkSpan seconds long
// it optionally also creates aggregations with the given settings
// the 0th retention is the native archive of this metric. if there's several others, we create aggregators, using agg.
// it's the caller... | [
"NewAggMetric",
"creates",
"a",
"metric",
"with",
"given",
"key",
"it",
"retains",
"the",
"given",
"number",
"of",
"chunks",
"each",
"chunkSpan",
"seconds",
"long",
"it",
"optionally",
"also",
"creates",
"aggregations",
"with",
"the",
"given",
"settings",
"the",... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/aggmetric.go#L53-L80 | train |
grafana/metrictank | mdata/aggmetric.go | addAggregators | func (a *AggMetric) addAggregators(ts uint32, val float64) {
for _, agg := range a.aggregators {
log.Debugf("AM: %s pushing %d,%f to aggregator %d", a.key, ts, val, agg.span)
agg.Add(ts, val)
}
} | go | func (a *AggMetric) addAggregators(ts uint32, val float64) {
for _, agg := range a.aggregators {
log.Debugf("AM: %s pushing %d,%f to aggregator %d", a.key, ts, val, agg.span)
agg.Add(ts, val)
}
} | [
"func",
"(",
"a",
"*",
"AggMetric",
")",
"addAggregators",
"(",
"ts",
"uint32",
",",
"val",
"float64",
")",
"{",
"for",
"_",
",",
"agg",
":=",
"range",
"a",
".",
"aggregators",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"a",
".",
"key",
","... | // caller must hold lock | [
"caller",
"must",
"hold",
"lock"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/aggmetric.go#L315-L320 | train |
grafana/metrictank | mdata/aggmetric.go | pushToCache | func (a *AggMetric) pushToCache(c *chunk.Chunk) {
if a.cachePusher == nil {
return
}
// push into cache
intervalHint := a.key.Archive.Span()
itergen, err := chunk.NewIterGen(c.Series.T0, intervalHint, c.Encode(a.chunkSpan))
if err != nil {
log.Errorf("AM: %s failed to generate IterGen. this should never happ... | go | func (a *AggMetric) pushToCache(c *chunk.Chunk) {
if a.cachePusher == nil {
return
}
// push into cache
intervalHint := a.key.Archive.Span()
itergen, err := chunk.NewIterGen(c.Series.T0, intervalHint, c.Encode(a.chunkSpan))
if err != nil {
log.Errorf("AM: %s failed to generate IterGen. this should never happ... | [
"func",
"(",
"a",
"*",
"AggMetric",
")",
"pushToCache",
"(",
"c",
"*",
"chunk",
".",
"Chunk",
")",
"{",
"if",
"a",
".",
"cachePusher",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"// push into cache",
"intervalHint",
":=",
"a",
".",
"key",
".",
"Arc... | // pushToCache adds the chunk into the cache if it is hot
// caller must hold lock | [
"pushToCache",
"adds",
"the",
"chunk",
"into",
"the",
"cache",
"if",
"it",
"is",
"hot",
"caller",
"must",
"hold",
"lock"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/aggmetric.go#L324-L336 | train |
grafana/metrictank | mdata/aggmetric.go | Add | func (a *AggMetric) Add(ts uint32, val float64) {
a.Lock()
defer a.Unlock()
if a.rob == nil {
// write directly
a.add(ts, val)
} else {
// write through reorder buffer
res, err := a.rob.Add(ts, val)
if err == nil {
if len(res) == 0 {
a.lastWrite = uint32(time.Now().Unix())
} else {
for _, ... | go | func (a *AggMetric) Add(ts uint32, val float64) {
a.Lock()
defer a.Unlock()
if a.rob == nil {
// write directly
a.add(ts, val)
} else {
// write through reorder buffer
res, err := a.rob.Add(ts, val)
if err == nil {
if len(res) == 0 {
a.lastWrite = uint32(time.Now().Unix())
} else {
for _, ... | [
"func",
"(",
"a",
"*",
"AggMetric",
")",
"Add",
"(",
"ts",
"uint32",
",",
"val",
"float64",
")",
"{",
"a",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"a",
".",
"rob",
"==",
"nil",
"{",
"// write directly",
... | // don't ever call with a ts of 0, cause we use 0 to mean not initialized! | [
"don",
"t",
"ever",
"call",
"with",
"a",
"ts",
"of",
"0",
"cause",
"we",
"use",
"0",
"to",
"mean",
"not",
"initialized!"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/aggmetric.go#L405-L429 | train |
grafana/metrictank | mdata/aggmetric.go | GC | func (a *AggMetric) GC(now, chunkMinTs, metricMinTs uint32) (uint32, bool) {
a.Lock()
defer a.Unlock()
// unless it looks like the AggMetric is collectable, abort and mark as not stale
if !a.collectable(now, chunkMinTs) {
return 0, false
}
// make sure any points in the reorderBuffer are moved into our chunks... | go | func (a *AggMetric) GC(now, chunkMinTs, metricMinTs uint32) (uint32, bool) {
a.Lock()
defer a.Unlock()
// unless it looks like the AggMetric is collectable, abort and mark as not stale
if !a.collectable(now, chunkMinTs) {
return 0, false
}
// make sure any points in the reorderBuffer are moved into our chunks... | [
"func",
"(",
"a",
"*",
"AggMetric",
")",
"GC",
"(",
"now",
",",
"chunkMinTs",
",",
"metricMinTs",
"uint32",
")",
"(",
"uint32",
",",
"bool",
")",
"{",
"a",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"Unlock",
"(",
")",
"\n\n",
"// unless it lo... | // GC returns whether or not this AggMetric is stale and can be removed, and its pointcount if so
// chunkMinTs -> min timestamp of a chunk before to be considered stale and to be persisted to Cassandra
// metricMinTs -> min timestamp for a metric before to be considered stale and to be purged from the tank | [
"GC",
"returns",
"whether",
"or",
"not",
"this",
"AggMetric",
"is",
"stale",
"and",
"can",
"be",
"removed",
"and",
"its",
"pointcount",
"if",
"so",
"chunkMinTs",
"-",
">",
"min",
"timestamp",
"of",
"a",
"chunk",
"before",
"to",
"be",
"considered",
"stale",... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/aggmetric.go#L558-L614 | train |
grafana/metrictank | mdata/aggmetric.go | gcAggregators | func (a *AggMetric) gcAggregators(now, chunkMinTs, metricMinTs uint32) (uint32, bool) {
var points uint32
stale := true
for _, agg := range a.aggregators {
p, s := agg.GC(now, chunkMinTs, metricMinTs, a.lastWrite)
points += p
stale = stale && s
}
return points, stale
} | go | func (a *AggMetric) gcAggregators(now, chunkMinTs, metricMinTs uint32) (uint32, bool) {
var points uint32
stale := true
for _, agg := range a.aggregators {
p, s := agg.GC(now, chunkMinTs, metricMinTs, a.lastWrite)
points += p
stale = stale && s
}
return points, stale
} | [
"func",
"(",
"a",
"*",
"AggMetric",
")",
"gcAggregators",
"(",
"now",
",",
"chunkMinTs",
",",
"metricMinTs",
"uint32",
")",
"(",
"uint32",
",",
"bool",
")",
"{",
"var",
"points",
"uint32",
"\n",
"stale",
":=",
"true",
"\n",
"for",
"_",
",",
"agg",
":... | // gcAggregators returns whether all aggregators are stale and can be removed, and their pointcount if so | [
"gcAggregators",
"returns",
"whether",
"all",
"aggregators",
"are",
"stale",
"and",
"can",
"be",
"removed",
"and",
"their",
"pointcount",
"if",
"so"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/mdata/aggmetric.go#L617-L626 | train |
grafana/metrictank | idx/memory/find_cache.go | Purge | func (c *FindCache) Purge(orgId uint32) {
c.RLock()
cache, ok := c.cache[orgId]
c.RUnlock()
if !ok {
return
}
cache.Purge()
} | go | func (c *FindCache) Purge(orgId uint32) {
c.RLock()
cache, ok := c.cache[orgId]
c.RUnlock()
if !ok {
return
}
cache.Purge()
} | [
"func",
"(",
"c",
"*",
"FindCache",
")",
"Purge",
"(",
"orgId",
"uint32",
")",
"{",
"c",
".",
"RLock",
"(",
")",
"\n",
"cache",
",",
"ok",
":=",
"c",
".",
"cache",
"[",
"orgId",
"]",
"\n",
"c",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"!",
"ok",... | // Purge clears the cache for the specified orgId | [
"Purge",
"clears",
"the",
"cache",
"for",
"the",
"specified",
"orgId"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/find_cache.go#L129-L137 | train |
grafana/metrictank | idx/memory/find_cache.go | PurgeAll | func (c *FindCache) PurgeAll() {
c.RLock()
orgs := make([]uint32, len(c.cache))
i := 0
for k := range c.cache {
orgs[i] = k
i++
}
c.RUnlock()
for _, org := range orgs {
c.Purge(org)
}
} | go | func (c *FindCache) PurgeAll() {
c.RLock()
orgs := make([]uint32, len(c.cache))
i := 0
for k := range c.cache {
orgs[i] = k
i++
}
c.RUnlock()
for _, org := range orgs {
c.Purge(org)
}
} | [
"func",
"(",
"c",
"*",
"FindCache",
")",
"PurgeAll",
"(",
")",
"{",
"c",
".",
"RLock",
"(",
")",
"\n",
"orgs",
":=",
"make",
"(",
"[",
"]",
"uint32",
",",
"len",
"(",
"c",
".",
"cache",
")",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
"k",
":="... | // PurgeAll clears the caches for all orgIds | [
"PurgeAll",
"clears",
"the",
"caches",
"for",
"all",
"orgIds"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/find_cache.go#L140-L152 | train |
grafana/metrictank | idx/memory/find_cache.go | InvalidateFor | func (c *FindCache) InvalidateFor(orgId uint32, path string) {
c.Lock()
findCacheInvalidationsReceived.Inc()
defer c.Unlock()
if c.backoff {
findCacheInvalidationsDropped.Inc()
return
}
cache, ok := c.cache[orgId]
if !ok || cache.Len() < 1 {
findCacheInvalidationsDropped.Inc()
return
}
req := invalid... | go | func (c *FindCache) InvalidateFor(orgId uint32, path string) {
c.Lock()
findCacheInvalidationsReceived.Inc()
defer c.Unlock()
if c.backoff {
findCacheInvalidationsDropped.Inc()
return
}
cache, ok := c.cache[orgId]
if !ok || cache.Len() < 1 {
findCacheInvalidationsDropped.Inc()
return
}
req := invalid... | [
"func",
"(",
"c",
"*",
"FindCache",
")",
"InvalidateFor",
"(",
"orgId",
"uint32",
",",
"path",
"string",
")",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"findCacheInvalidationsReceived",
".",
"Inc",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
... | // InvalidateFor removes entries from the cache for 'orgId'
// that match the provided path. If lots of InvalidateFor calls
// are made at once and we end up with `invalidateQueueSize` concurrent
// goroutines processing the invalidations, we purge the cache and
// disable it for `backoffTime`. Future InvalidateFor cal... | [
"InvalidateFor",
"removes",
"entries",
"from",
"the",
"cache",
"for",
"orgId",
"that",
"match",
"the",
"provided",
"path",
".",
"If",
"lots",
"of",
"InvalidateFor",
"calls",
"are",
"made",
"at",
"once",
"and",
"we",
"end",
"up",
"with",
"invalidateQueueSize",
... | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/find_cache.go#L160-L184 | train |
grafana/metrictank | idx/memory/find_cache.go | triggerBackoff | func (c *FindCache) triggerBackoff() {
log.Infof("memory-idx: findCache invalidate-queue full. Disabling cache for %s", c.backoffTime.String())
findCacheBackoff.Inc()
c.backoff = true
time.AfterFunc(c.backoffTime, func() {
findCacheBackoff.Dec()
c.Lock()
c.backoff = false
c.Unlock()
})
c.cache = make(map[... | go | func (c *FindCache) triggerBackoff() {
log.Infof("memory-idx: findCache invalidate-queue full. Disabling cache for %s", c.backoffTime.String())
findCacheBackoff.Inc()
c.backoff = true
time.AfterFunc(c.backoffTime, func() {
findCacheBackoff.Dec()
c.Lock()
c.backoff = false
c.Unlock()
})
c.cache = make(map[... | [
"func",
"(",
"c",
"*",
"FindCache",
")",
"triggerBackoff",
"(",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"c",
".",
"backoffTime",
".",
"String",
"(",
")",
")",
"\n",
"findCacheBackoff",
".",
"Inc",
"(",
")",
"\n",
"c",
".",
"backoff",
... | // caller must hold lock! | [
"caller",
"must",
"hold",
"lock!"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/find_cache.go#L187-L207 | train |
grafana/metrictank | idx/memory/find_cache.go | PurgeFindCache | func (p *PartitionedMemoryIdx) PurgeFindCache() {
for _, m := range p.Partition {
if m.findCache != nil {
m.findCache.PurgeAll()
}
}
} | go | func (p *PartitionedMemoryIdx) PurgeFindCache() {
for _, m := range p.Partition {
if m.findCache != nil {
m.findCache.PurgeAll()
}
}
} | [
"func",
"(",
"p",
"*",
"PartitionedMemoryIdx",
")",
"PurgeFindCache",
"(",
")",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"p",
".",
"Partition",
"{",
"if",
"m",
".",
"findCache",
"!=",
"nil",
"{",
"m",
".",
"findCache",
".",
"PurgeAll",
"(",
")",
"... | // PurgeFindCache purges the findCaches for all orgIds
// across all partitions | [
"PurgeFindCache",
"purges",
"the",
"findCaches",
"for",
"all",
"orgIds",
"across",
"all",
"partitions"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/find_cache.go#L351-L357 | train |
grafana/metrictank | idx/memory/find_cache.go | ForceInvalidationFindCache | func (p *PartitionedMemoryIdx) ForceInvalidationFindCache() {
for _, m := range p.Partition {
if m.findCache != nil {
m.findCache.forceInvalidation()
}
}
} | go | func (p *PartitionedMemoryIdx) ForceInvalidationFindCache() {
for _, m := range p.Partition {
if m.findCache != nil {
m.findCache.forceInvalidation()
}
}
} | [
"func",
"(",
"p",
"*",
"PartitionedMemoryIdx",
")",
"ForceInvalidationFindCache",
"(",
")",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"p",
".",
"Partition",
"{",
"if",
"m",
".",
"findCache",
"!=",
"nil",
"{",
"m",
".",
"findCache",
".",
"forceInvalidatio... | // ForceInvalidationFindCache forces a full invalidation cycle of the find cache | [
"ForceInvalidationFindCache",
"forces",
"a",
"full",
"invalidation",
"cycle",
"of",
"the",
"find",
"cache"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/idx/memory/find_cache.go#L360-L366 | train |
grafana/metrictank | cmd/mt-store-cat/tables.go | getTables | func getTables(store *cassandra.CassandraStore, match string) ([]cassandra.Table, error) {
var tables []cassandra.Table
if match == "*" || match == "" {
for _, table := range store.TTLTables {
if table.Name == "metric_idx" || !strings.HasPrefix(table.Name, "metric_") {
continue
}
tables = append(tables... | go | func getTables(store *cassandra.CassandraStore, match string) ([]cassandra.Table, error) {
var tables []cassandra.Table
if match == "*" || match == "" {
for _, table := range store.TTLTables {
if table.Name == "metric_idx" || !strings.HasPrefix(table.Name, "metric_") {
continue
}
tables = append(tables... | [
"func",
"getTables",
"(",
"store",
"*",
"cassandra",
".",
"CassandraStore",
",",
"match",
"string",
")",
"(",
"[",
"]",
"cassandra",
".",
"Table",
",",
"error",
")",
"{",
"var",
"tables",
"[",
"]",
"cassandra",
".",
"Table",
"\n",
"if",
"match",
"==",
... | // getTables returns the requested cassandra store tables in TTL asc order based on match string | [
"getTables",
"returns",
"the",
"requested",
"cassandra",
"store",
"tables",
"in",
"TTL",
"asc",
"order",
"based",
"on",
"match",
"string"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cmd/mt-store-cat/tables.go#L19-L39 | train |
grafana/metrictank | cmd/mt-store-cat/tables.go | printTables | func printTables(store *cassandra.CassandraStore) {
tables, err := getTables(store, "")
if err != nil {
log.Fatal(err.Error())
}
for _, table := range tables {
fmt.Printf("%s (%d hours <= ttl < %d hours)\n", table.Name, table.TTL, table.TTL*2)
}
} | go | func printTables(store *cassandra.CassandraStore) {
tables, err := getTables(store, "")
if err != nil {
log.Fatal(err.Error())
}
for _, table := range tables {
fmt.Printf("%s (%d hours <= ttl < %d hours)\n", table.Name, table.TTL, table.TTL*2)
}
} | [
"func",
"printTables",
"(",
"store",
"*",
"cassandra",
".",
"CassandraStore",
")",
"{",
"tables",
",",
"err",
":=",
"getTables",
"(",
"store",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
".",
"Error",
... | //printTables prints all tables in the store | [
"printTables",
"prints",
"all",
"tables",
"in",
"the",
"store"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/cmd/mt-store-cat/tables.go#L42-L50 | train |
grafana/metrictank | api/prometheus_querier.go | Querier | func (s *Server) Querier(ctx context.Context, min, max int64) (storage.Querier, error) {
from := uint32(min / 1000)
to := uint32(max / 1000)
return NewQuerier(ctx, s, from, to, ctx.Value(orgID("org-id")).(uint32), false), nil
} | go | func (s *Server) Querier(ctx context.Context, min, max int64) (storage.Querier, error) {
from := uint32(min / 1000)
to := uint32(max / 1000)
return NewQuerier(ctx, s, from, to, ctx.Value(orgID("org-id")).(uint32), false), nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Querier",
"(",
"ctx",
"context",
".",
"Context",
",",
"min",
",",
"max",
"int64",
")",
"(",
"storage",
".",
"Querier",
",",
"error",
")",
"{",
"from",
":=",
"uint32",
"(",
"min",
"/",
"1000",
")",
"\n",
"to"... | // Querier creates a new querier that will operate on the subject server
// it needs the org-id stored in a context value | [
"Querier",
"creates",
"a",
"new",
"querier",
"that",
"will",
"operate",
"on",
"the",
"subject",
"server",
"it",
"needs",
"the",
"org",
"-",
"id",
"stored",
"in",
"a",
"context",
"value"
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/prometheus_querier.go#L21-L25 | train |
grafana/metrictank | api/prometheus_querier.go | Select | func (q *querier) Select(matchers ...*labels.Matcher) (storage.SeriesSet, error) {
minFrom := uint32(math.MaxUint32)
var maxTo uint32
var target string
var reqs []models.Req
expressions := []string{}
for _, matcher := range matchers {
if matcher.Name == model.MetricNameLabel {
matcher.Name = "name"
}
if... | go | func (q *querier) Select(matchers ...*labels.Matcher) (storage.SeriesSet, error) {
minFrom := uint32(math.MaxUint32)
var maxTo uint32
var target string
var reqs []models.Req
expressions := []string{}
for _, matcher := range matchers {
if matcher.Name == model.MetricNameLabel {
matcher.Name = "name"
}
if... | [
"func",
"(",
"q",
"*",
"querier",
")",
"Select",
"(",
"matchers",
"...",
"*",
"labels",
".",
"Matcher",
")",
"(",
"storage",
".",
"SeriesSet",
",",
"error",
")",
"{",
"minFrom",
":=",
"uint32",
"(",
"math",
".",
"MaxUint32",
")",
"\n",
"var",
"maxTo"... | // Select returns a set of series that matches the given label matchers. | [
"Select",
"returns",
"a",
"set",
"of",
"series",
"that",
"matches",
"the",
"given",
"label",
"matchers",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/prometheus_querier.go#L49-L117 | train |
grafana/metrictank | api/prometheus_querier.go | LabelValues | func (q *querier) LabelValues(name string) ([]string, error) {
expressions := []string{"name=~[a-zA-Z_][a-zA-Z0-9_]*$"}
if name == model.MetricNameLabel {
name = "name"
expressions = append(expressions, "name=~[a-zA-Z_:][a-zA-Z0-9_:]*$")
}
return q.MetricIndex.FindTagValues(q.OrgID, name, "", expressions, 0, 10... | go | func (q *querier) LabelValues(name string) ([]string, error) {
expressions := []string{"name=~[a-zA-Z_][a-zA-Z0-9_]*$"}
if name == model.MetricNameLabel {
name = "name"
expressions = append(expressions, "name=~[a-zA-Z_:][a-zA-Z0-9_:]*$")
}
return q.MetricIndex.FindTagValues(q.OrgID, name, "", expressions, 0, 10... | [
"func",
"(",
"q",
"*",
"querier",
")",
"LabelValues",
"(",
"name",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"expressions",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"\n",
"if",
"name",
"==",
"model",
".",
"MetricNameLab... | // LabelValues returns all potential values for a label name. | [
"LabelValues",
"returns",
"all",
"potential",
"values",
"for",
"a",
"label",
"name",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/prometheus_querier.go#L120-L127 | train |
grafana/metrictank | api/graphite.go | closestAggMethod | func closestAggMethod(requested consolidation.Consolidator, available []conf.Method) consolidation.Consolidator {
// if there is only 1 consolidation method available, then that is all we can return.
if len(available) == 1 {
return consolidation.Consolidator(available[0])
}
avail := map[consolidation.Consolidato... | go | func closestAggMethod(requested consolidation.Consolidator, available []conf.Method) consolidation.Consolidator {
// if there is only 1 consolidation method available, then that is all we can return.
if len(available) == 1 {
return consolidation.Consolidator(available[0])
}
avail := map[consolidation.Consolidato... | [
"func",
"closestAggMethod",
"(",
"requested",
"consolidation",
".",
"Consolidator",
",",
"available",
"[",
"]",
"conf",
".",
"Method",
")",
"consolidation",
".",
"Consolidator",
"{",
"// if there is only 1 consolidation method available, then that is all we can return.",
"if"... | // find the best consolidation method based on what was requested and what aggregations are available. | [
"find",
"the",
"best",
"consolidation",
"method",
"based",
"on",
"what",
"was",
"requested",
"and",
"what",
"aggregations",
"are",
"available",
"."
] | dd9b92db72d27553d9a8214bff5f01d2531f63b0 | https://github.com/grafana/metrictank/blob/dd9b92db72d27553d9a8214bff5f01d2531f63b0/api/graphite.go#L760-L782 | train |
lightninglabs/neutrino | mock_store.go | newMockBlockHeaderStore | func newMockBlockHeaderStore() headerfs.BlockHeaderStore {
return &mockBlockHeaderStore{
headers: make(map[chainhash.Hash]wire.BlockHeader),
}
} | go | func newMockBlockHeaderStore() headerfs.BlockHeaderStore {
return &mockBlockHeaderStore{
headers: make(map[chainhash.Hash]wire.BlockHeader),
}
} | [
"func",
"newMockBlockHeaderStore",
"(",
")",
"headerfs",
".",
"BlockHeaderStore",
"{",
"return",
"&",
"mockBlockHeaderStore",
"{",
"headers",
":",
"make",
"(",
"map",
"[",
"chainhash",
".",
"Hash",
"]",
"wire",
".",
"BlockHeader",
")",
",",
"}",
"\n",
"}"
] | // NewMockBlockHeaderStore returns a version of the BlockHeaderStore that's
// backed by an in-memory map. This instance is meant to be used by callers
// outside the package to unit test components that require a BlockHeaderStore
// interface. | [
"NewMockBlockHeaderStore",
"returns",
"a",
"version",
"of",
"the",
"BlockHeaderStore",
"that",
"s",
"backed",
"by",
"an",
"in",
"-",
"memory",
"map",
".",
"This",
"instance",
"is",
"meant",
"to",
"be",
"used",
"by",
"callers",
"outside",
"the",
"package",
"t... | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/mock_store.go#L27-L31 | train |
lightninglabs/neutrino | cache/cacheable_block.go | Size | func (c *CacheableBlock) Size() (uint64, error) {
return uint64(c.Block.MsgBlock().SerializeSize()), nil
} | go | func (c *CacheableBlock) Size() (uint64, error) {
return uint64(c.Block.MsgBlock().SerializeSize()), nil
} | [
"func",
"(",
"c",
"*",
"CacheableBlock",
")",
"Size",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"return",
"uint64",
"(",
"c",
".",
"Block",
".",
"MsgBlock",
"(",
")",
".",
"SerializeSize",
"(",
")",
")",
",",
"nil",
"\n",
"}"
] | // Size returns size of this block in bytes. | [
"Size",
"returns",
"size",
"of",
"this",
"block",
"in",
"bytes",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/cache/cacheable_block.go#L12-L14 | train |
lightninglabs/neutrino | headerfs/index.go | newHeaderIndex | func newHeaderIndex(db walletdb.DB, indexType HeaderType) (*headerIndex, error) {
// As an initially step, we'll attempt to create all the buckets
// necessary for functioning of the index. If these buckets has already
// been created, then we can exit early.
err := walletdb.Update(db, func(tx walletdb.ReadWriteTx)... | go | func newHeaderIndex(db walletdb.DB, indexType HeaderType) (*headerIndex, error) {
// As an initially step, we'll attempt to create all the buckets
// necessary for functioning of the index. If these buckets has already
// been created, then we can exit early.
err := walletdb.Update(db, func(tx walletdb.ReadWriteTx)... | [
"func",
"newHeaderIndex",
"(",
"db",
"walletdb",
".",
"DB",
",",
"indexType",
"HeaderType",
")",
"(",
"*",
"headerIndex",
",",
"error",
")",
"{",
"// As an initially step, we'll attempt to create all the buckets",
"// necessary for functioning of the index. If these buckets has... | // newHeaderIndex creates a new headerIndex given an already open database, and
// a particular header type. | [
"newHeaderIndex",
"creates",
"a",
"new",
"headerIndex",
"given",
"an",
"already",
"open",
"database",
"and",
"a",
"particular",
"header",
"type",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/index.go#L83-L100 | train |
lightninglabs/neutrino | headerfs/index.go | addHeaders | func (h *headerIndex) addHeaders(batch headerBatch) error {
// If we're writing a 0-length batch, make no changes and return.
if len(batch) == 0 {
return nil
}
// In order to ensure optimal write performance, we'll ensure that the
// items are sorted by their hash before insertion into the database.
sort.Sort(... | go | func (h *headerIndex) addHeaders(batch headerBatch) error {
// If we're writing a 0-length batch, make no changes and return.
if len(batch) == 0 {
return nil
}
// In order to ensure optimal write performance, we'll ensure that the
// items are sorted by their hash before insertion into the database.
sort.Sort(... | [
"func",
"(",
"h",
"*",
"headerIndex",
")",
"addHeaders",
"(",
"batch",
"headerBatch",
")",
"error",
"{",
"// If we're writing a 0-length batch, make no changes and return.",
"if",
"len",
"(",
"batch",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// ... | // addHeaders writes a batch of header entries in a single atomic batch | [
"addHeaders",
"writes",
"a",
"batch",
"of",
"header",
"entries",
"in",
"a",
"single",
"atomic",
"batch"
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/index.go#L139-L191 | train |
lightninglabs/neutrino | headerfs/index.go | heightFromHash | func (h *headerIndex) heightFromHash(hash *chainhash.Hash) (uint32, error) {
var height uint32
err := walletdb.View(h.db, func(tx walletdb.ReadTx) error {
rootBucket := tx.ReadBucket(indexBucket)
heightBytes := rootBucket.Get(hash[:])
if heightBytes == nil {
// If the hash wasn't found, then we don't know o... | go | func (h *headerIndex) heightFromHash(hash *chainhash.Hash) (uint32, error) {
var height uint32
err := walletdb.View(h.db, func(tx walletdb.ReadTx) error {
rootBucket := tx.ReadBucket(indexBucket)
heightBytes := rootBucket.Get(hash[:])
if heightBytes == nil {
// If the hash wasn't found, then we don't know o... | [
"func",
"(",
"h",
"*",
"headerIndex",
")",
"heightFromHash",
"(",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"uint32",
",",
"error",
")",
"{",
"var",
"height",
"uint32",
"\n",
"err",
":=",
"walletdb",
".",
"View",
"(",
"h",
".",
"db",
",",
"f... | // heightFromHash returns the height of the entry that matches the specified
// height. With this height, the caller is then able to seek to the appropriate
// spot in the flat files in order to extract the true header. | [
"heightFromHash",
"returns",
"the",
"height",
"of",
"the",
"entry",
"that",
"matches",
"the",
"specified",
"height",
".",
"With",
"this",
"height",
"the",
"caller",
"is",
"then",
"able",
"to",
"seek",
"to",
"the",
"appropriate",
"spot",
"in",
"the",
"flat",
... | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/index.go#L196-L216 | train |
lightninglabs/neutrino | headerfs/index.go | chainTip | func (h *headerIndex) chainTip() (*chainhash.Hash, uint32, error) {
var (
tipHeight uint32
tipHash *chainhash.Hash
)
err := walletdb.View(h.db, func(tx walletdb.ReadTx) error {
rootBucket := tx.ReadBucket(indexBucket)
var tipKey []byte
// Based on the specified index type of this instance of the
// ... | go | func (h *headerIndex) chainTip() (*chainhash.Hash, uint32, error) {
var (
tipHeight uint32
tipHash *chainhash.Hash
)
err := walletdb.View(h.db, func(tx walletdb.ReadTx) error {
rootBucket := tx.ReadBucket(indexBucket)
var tipKey []byte
// Based on the specified index type of this instance of the
// ... | [
"func",
"(",
"h",
"*",
"headerIndex",
")",
"chainTip",
"(",
")",
"(",
"*",
"chainhash",
".",
"Hash",
",",
"uint32",
",",
"error",
")",
"{",
"var",
"(",
"tipHeight",
"uint32",
"\n",
"tipHash",
"*",
"chainhash",
".",
"Hash",
"\n",
")",
"\n\n",
"err",
... | // chainTip returns the best hash and height that the index knows of. | [
"chainTip",
"returns",
"the",
"best",
"hash",
"and",
"height",
"that",
"the",
"index",
"knows",
"of",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/index.go#L219-L267 | train |
lightninglabs/neutrino | headerfs/index.go | truncateIndex | func (h *headerIndex) truncateIndex(newTip *chainhash.Hash, delete bool) error {
return walletdb.Update(h.db, func(tx walletdb.ReadWriteTx) error {
rootBucket := tx.ReadWriteBucket(indexBucket)
var tipKey []byte
// Based on the specified index type of this instance of the
// index, we'll grab the key that tr... | go | func (h *headerIndex) truncateIndex(newTip *chainhash.Hash, delete bool) error {
return walletdb.Update(h.db, func(tx walletdb.ReadWriteTx) error {
rootBucket := tx.ReadWriteBucket(indexBucket)
var tipKey []byte
// Based on the specified index type of this instance of the
// index, we'll grab the key that tr... | [
"func",
"(",
"h",
"*",
"headerIndex",
")",
"truncateIndex",
"(",
"newTip",
"*",
"chainhash",
".",
"Hash",
",",
"delete",
"bool",
")",
"error",
"{",
"return",
"walletdb",
".",
"Update",
"(",
"h",
".",
"db",
",",
"func",
"(",
"tx",
"walletdb",
".",
"Re... | // truncateIndex truncates the index for a particluar header type by a single
// header entry. The passed newTip pointer should point to the hash of the new
// chain tip. Optionally, if the entry is to be deleted as well, then the
// delete flag should be set to true. | [
"truncateIndex",
"truncates",
"the",
"index",
"for",
"a",
"particluar",
"header",
"type",
"by",
"a",
"single",
"header",
"entry",
".",
"The",
"passed",
"newTip",
"pointer",
"should",
"point",
"to",
"the",
"hash",
"of",
"the",
"new",
"chain",
"tip",
".",
"O... | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/index.go#L273-L305 | train |
lightninglabs/neutrino | batch_spend_reporter.go | newBatchSpendReporter | func newBatchSpendReporter() *batchSpendReporter {
return &batchSpendReporter{
requests: make(map[wire.OutPoint][]*GetUtxoRequest),
initialTxns: make(map[wire.OutPoint]*SpendReport),
outpoints: make(map[wire.OutPoint][]byte),
}
} | go | func newBatchSpendReporter() *batchSpendReporter {
return &batchSpendReporter{
requests: make(map[wire.OutPoint][]*GetUtxoRequest),
initialTxns: make(map[wire.OutPoint]*SpendReport),
outpoints: make(map[wire.OutPoint][]byte),
}
} | [
"func",
"newBatchSpendReporter",
"(",
")",
"*",
"batchSpendReporter",
"{",
"return",
"&",
"batchSpendReporter",
"{",
"requests",
":",
"make",
"(",
"map",
"[",
"wire",
".",
"OutPoint",
"]",
"[",
"]",
"*",
"GetUtxoRequest",
")",
",",
"initialTxns",
":",
"make"... | // newBatchSpendReporter instantiates a fresh batchSpendReporter. | [
"newBatchSpendReporter",
"instantiates",
"a",
"fresh",
"batchSpendReporter",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/batch_spend_reporter.go#L37-L43 | train |
lightninglabs/neutrino | batch_spend_reporter.go | NotifyUnspentAndUnfound | func (b *batchSpendReporter) NotifyUnspentAndUnfound() {
log.Debugf("Finished batch, %d unspent outpoints", len(b.requests))
for outpoint, requests := range b.requests {
// A nil SpendReport indicates the output was not found.
tx, ok := b.initialTxns[outpoint]
if !ok {
log.Warnf("Unknown initial txn for get... | go | func (b *batchSpendReporter) NotifyUnspentAndUnfound() {
log.Debugf("Finished batch, %d unspent outpoints", len(b.requests))
for outpoint, requests := range b.requests {
// A nil SpendReport indicates the output was not found.
tx, ok := b.initialTxns[outpoint]
if !ok {
log.Warnf("Unknown initial txn for get... | [
"func",
"(",
"b",
"*",
"batchSpendReporter",
")",
"NotifyUnspentAndUnfound",
"(",
")",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"len",
"(",
"b",
".",
"requests",
")",
")",
"\n\n",
"for",
"outpoint",
",",
"requests",
":=",
"range",
"b",
".",
"... | // NotifyUnspentAndUnfound iterates through any requests for which no spends
// were detected. If we were able to find the initial output, this will be
// delivered signaling that no spend was detected. If the original output could
// not be found, a nil spend report is returned. | [
"NotifyUnspentAndUnfound",
"iterates",
"through",
"any",
"requests",
"for",
"which",
"no",
"spends",
"were",
"detected",
".",
"If",
"we",
"were",
"able",
"to",
"find",
"the",
"initial",
"output",
"this",
"will",
"be",
"delivered",
"signaling",
"that",
"no",
"s... | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/batch_spend_reporter.go#L49-L62 | train |
lightninglabs/neutrino | batch_spend_reporter.go | ProcessBlock | func (b *batchSpendReporter) ProcessBlock(blk *wire.MsgBlock,
newReqs []*GetUtxoRequest, height uint32) {
// If any requests want the UTXOs at this height, scan the block to find
// the original outputs that might be spent from.
if len(newReqs) > 0 {
b.addNewRequests(newReqs)
b.findInitialTransactions(blk, new... | go | func (b *batchSpendReporter) ProcessBlock(blk *wire.MsgBlock,
newReqs []*GetUtxoRequest, height uint32) {
// If any requests want the UTXOs at this height, scan the block to find
// the original outputs that might be spent from.
if len(newReqs) > 0 {
b.addNewRequests(newReqs)
b.findInitialTransactions(blk, new... | [
"func",
"(",
"b",
"*",
"batchSpendReporter",
")",
"ProcessBlock",
"(",
"blk",
"*",
"wire",
".",
"MsgBlock",
",",
"newReqs",
"[",
"]",
"*",
"GetUtxoRequest",
",",
"height",
"uint32",
")",
"{",
"// If any requests want the UTXOs at this height, scan the block to find",
... | // ProcessBlock accepts a block, block height, and any new requests whose start
// height matches the provided height. If a non-zero number of new requests are
// presented, the block will first be checked for the initial outputs from which
// spends may occur. Afterwards, any spends detected in the block are
// immedi... | [
"ProcessBlock",
"accepts",
"a",
"block",
"block",
"height",
"and",
"any",
"new",
"requests",
"whose",
"start",
"height",
"matches",
"the",
"provided",
"height",
".",
"If",
"a",
"non",
"-",
"zero",
"number",
"of",
"new",
"requests",
"are",
"presented",
"the",... | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/batch_spend_reporter.go#L100-L124 | train |
lightninglabs/neutrino | batch_spend_reporter.go | addNewRequests | func (b *batchSpendReporter) addNewRequests(reqs []*GetUtxoRequest) {
for _, req := range reqs {
outpoint := req.Input.OutPoint
log.Debugf("Adding outpoint=%s height=%d to watchlist",
outpoint, req.BirthHeight)
b.requests[outpoint] = append(b.requests[outpoint], req)
// Build the filter entry only if it ... | go | func (b *batchSpendReporter) addNewRequests(reqs []*GetUtxoRequest) {
for _, req := range reqs {
outpoint := req.Input.OutPoint
log.Debugf("Adding outpoint=%s height=%d to watchlist",
outpoint, req.BirthHeight)
b.requests[outpoint] = append(b.requests[outpoint], req)
// Build the filter entry only if it ... | [
"func",
"(",
"b",
"*",
"batchSpendReporter",
")",
"addNewRequests",
"(",
"reqs",
"[",
"]",
"*",
"GetUtxoRequest",
")",
"{",
"for",
"_",
",",
"req",
":=",
"range",
"reqs",
"{",
"outpoint",
":=",
"req",
".",
"Input",
".",
"OutPoint",
"\n\n",
"log",
".",
... | // addNewRequests adds a set of new GetUtxoRequests to the spend reporter's
// state. This method immediately adds the request's outpoints to the reporter's
// watchlist. | [
"addNewRequests",
"adds",
"a",
"set",
"of",
"new",
"GetUtxoRequests",
"to",
"the",
"spend",
"reporter",
"s",
"state",
".",
"This",
"method",
"immediately",
"adds",
"the",
"request",
"s",
"outpoints",
"to",
"the",
"reporter",
"s",
"watchlist",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/batch_spend_reporter.go#L129-L146 | train |
lightninglabs/neutrino | batch_spend_reporter.go | findInitialTransactions | func (b *batchSpendReporter) findInitialTransactions(block *wire.MsgBlock,
newReqs []*GetUtxoRequest, height uint32) map[wire.OutPoint]*SpendReport {
// First, construct a reverse index from txid to all a list of requests
// whose outputs share the same txid.
txidReverseIndex := make(map[chainhash.Hash][]*GetUtxo... | go | func (b *batchSpendReporter) findInitialTransactions(block *wire.MsgBlock,
newReqs []*GetUtxoRequest, height uint32) map[wire.OutPoint]*SpendReport {
// First, construct a reverse index from txid to all a list of requests
// whose outputs share the same txid.
txidReverseIndex := make(map[chainhash.Hash][]*GetUtxo... | [
"func",
"(",
"b",
"*",
"batchSpendReporter",
")",
"findInitialTransactions",
"(",
"block",
"*",
"wire",
".",
"MsgBlock",
",",
"newReqs",
"[",
"]",
"*",
"GetUtxoRequest",
",",
"height",
"uint32",
")",
"map",
"[",
"wire",
".",
"OutPoint",
"]",
"*",
"SpendRep... | // findInitialTransactions searches the given block for the creation of the
// UTXOs that are supposed to be birthed in this block. If any are found, a
// spend report containing the initial outpoint will be saved in case the
// outpoint is not spent later on. Requests corresponding to outpoints that are
// not found i... | [
"findInitialTransactions",
"searches",
"the",
"given",
"block",
"for",
"the",
"creation",
"of",
"the",
"UTXOs",
"that",
"are",
"supposed",
"to",
"be",
"birthed",
"in",
"this",
"block",
".",
"If",
"any",
"are",
"found",
"a",
"spend",
"report",
"containing",
"... | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/batch_spend_reporter.go#L154-L226 | train |
lightninglabs/neutrino | batch_spend_reporter.go | notifySpends | func (b *batchSpendReporter) notifySpends(block *wire.MsgBlock,
height uint32) map[wire.OutPoint]*SpendReport {
spends := make(map[wire.OutPoint]*SpendReport)
for _, tx := range block.Transactions {
// Check each input to see if this transaction spends one of our
// watched outpoints.
for i, ti := range tx.Tx... | go | func (b *batchSpendReporter) notifySpends(block *wire.MsgBlock,
height uint32) map[wire.OutPoint]*SpendReport {
spends := make(map[wire.OutPoint]*SpendReport)
for _, tx := range block.Transactions {
// Check each input to see if this transaction spends one of our
// watched outpoints.
for i, ti := range tx.Tx... | [
"func",
"(",
"b",
"*",
"batchSpendReporter",
")",
"notifySpends",
"(",
"block",
"*",
"wire",
".",
"MsgBlock",
",",
"height",
"uint32",
")",
"map",
"[",
"wire",
".",
"OutPoint",
"]",
"*",
"SpendReport",
"{",
"spends",
":=",
"make",
"(",
"map",
"[",
"wir... | // notifySpends finds any transactions in the block that spend from our watched
// outpoints. If a spend is detected, it is immediately delivered and cleaned up
// from the reporter's internal state. | [
"notifySpends",
"finds",
"any",
"transactions",
"in",
"the",
"block",
"that",
"spend",
"from",
"our",
"watched",
"outpoints",
".",
"If",
"a",
"spend",
"is",
"detected",
"it",
"is",
"immediately",
"delivered",
"and",
"cleaned",
"up",
"from",
"the",
"reporter",
... | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/batch_spend_reporter.go#L231-L267 | train |
lightninglabs/neutrino | headerfs/file.go | appendRaw | func (h *headerStore) appendRaw(header []byte) error {
if _, err := h.file.Write(header); err != nil {
return err
}
return nil
} | go | func (h *headerStore) appendRaw(header []byte) error {
if _, err := h.file.Write(header); err != nil {
return err
}
return nil
} | [
"func",
"(",
"h",
"*",
"headerStore",
")",
"appendRaw",
"(",
"header",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"_",
",",
"err",
":=",
"h",
".",
"file",
".",
"Write",
"(",
"header",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}... | // appendRaw appends a new raw header to the end of the flat file. | [
"appendRaw",
"appends",
"a",
"new",
"raw",
"header",
"to",
"the",
"end",
"of",
"the",
"flat",
"file",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/file.go#L13-L19 | train |
lightninglabs/neutrino | headerfs/file.go | readRaw | func (h *headerStore) readRaw(seekDist uint64) ([]byte, error) {
var headerSize uint32
// Based on the defined header type, we'll determine the number of
// bytes that we need to read past the sync point.
switch h.indexType {
case Block:
headerSize = 80
case RegularFilter:
headerSize = 32
default:
retur... | go | func (h *headerStore) readRaw(seekDist uint64) ([]byte, error) {
var headerSize uint32
// Based on the defined header type, we'll determine the number of
// bytes that we need to read past the sync point.
switch h.indexType {
case Block:
headerSize = 80
case RegularFilter:
headerSize = 32
default:
retur... | [
"func",
"(",
"h",
"*",
"headerStore",
")",
"readRaw",
"(",
"seekDist",
"uint64",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"headerSize",
"uint32",
"\n\n",
"// Based on the defined header type, we'll determine the number of",
"// bytes that we need to ... | // readRaw reads a raw header from disk from a particular seek distance. The
// amount of bytes read past the seek distance is determined by the specified
// header type. | [
"readRaw",
"reads",
"a",
"raw",
"header",
"from",
"disk",
"from",
"a",
"particular",
"seek",
"distance",
".",
"The",
"amount",
"of",
"bytes",
"read",
"past",
"the",
"seek",
"distance",
"is",
"determined",
"by",
"the",
"specified",
"header",
"type",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/file.go#L24-L51 | train |
lightninglabs/neutrino | headerfs/file.go | readHeader | func (h *blockHeaderStore) readHeader(height uint32) (wire.BlockHeader, error) {
var header wire.BlockHeader
// Each header is 80 bytes, so using this information, we'll seek a
// distance to cover that height based on the size of block headers.
seekDistance := uint64(height) * 80
// With the distance calculated... | go | func (h *blockHeaderStore) readHeader(height uint32) (wire.BlockHeader, error) {
var header wire.BlockHeader
// Each header is 80 bytes, so using this information, we'll seek a
// distance to cover that height based on the size of block headers.
seekDistance := uint64(height) * 80
// With the distance calculated... | [
"func",
"(",
"h",
"*",
"blockHeaderStore",
")",
"readHeader",
"(",
"height",
"uint32",
")",
"(",
"wire",
".",
"BlockHeader",
",",
"error",
")",
"{",
"var",
"header",
"wire",
".",
"BlockHeader",
"\n\n",
"// Each header is 80 bytes, so using this information, we'll se... | // readHeader reads a full block header from the flat-file. The header read is
// determined by the hight value. | [
"readHeader",
"reads",
"a",
"full",
"block",
"header",
"from",
"the",
"flat",
"-",
"file",
".",
"The",
"header",
"read",
"is",
"determined",
"by",
"the",
"hight",
"value",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/file.go#L90-L111 | train |
lightninglabs/neutrino | headerfs/file.go | readHeader | func (f *FilterHeaderStore) readHeader(height uint32) (*chainhash.Hash, error) {
seekDistance := uint64(height) * 32
rawHeader, err := f.readRaw(seekDistance)
if err != nil {
return nil, err
}
return chainhash.NewHash(rawHeader)
} | go | func (f *FilterHeaderStore) readHeader(height uint32) (*chainhash.Hash, error) {
seekDistance := uint64(height) * 32
rawHeader, err := f.readRaw(seekDistance)
if err != nil {
return nil, err
}
return chainhash.NewHash(rawHeader)
} | [
"func",
"(",
"f",
"*",
"FilterHeaderStore",
")",
"readHeader",
"(",
"height",
"uint32",
")",
"(",
"*",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"seekDistance",
":=",
"uint64",
"(",
"height",
")",
"*",
"32",
"\n\n",
"rawHeader",
",",
"err",
":=... | // readHeader reads a single filter header at the specified height from the
// flat files on disk. | [
"readHeader",
"reads",
"a",
"single",
"filter",
"header",
"at",
"the",
"specified",
"height",
"from",
"the",
"flat",
"files",
"on",
"disk",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/file.go#L115-L124 | train |
lightninglabs/neutrino | headerfs/file.go | readHeadersFromFile | func readHeadersFromFile(f *os.File, headerSize, startHeight,
endHeight uint32) (*bytes.Reader, error) {
// Each header is headerSize bytes, so using this information, we'll
// seek a distance to cover that height based on the size the headers.
seekDistance := uint64(startHeight) * uint64(headerSize)
// Based on... | go | func readHeadersFromFile(f *os.File, headerSize, startHeight,
endHeight uint32) (*bytes.Reader, error) {
// Each header is headerSize bytes, so using this information, we'll
// seek a distance to cover that height based on the size the headers.
seekDistance := uint64(startHeight) * uint64(headerSize)
// Based on... | [
"func",
"readHeadersFromFile",
"(",
"f",
"*",
"os",
".",
"File",
",",
"headerSize",
",",
"startHeight",
",",
"endHeight",
"uint32",
")",
"(",
"*",
"bytes",
".",
"Reader",
",",
"error",
")",
"{",
"// Each header is headerSize bytes, so using this information, we'll",... | // readHeadersFromFile reads a chunk of headers, each of size headerSize, from
// the given file, from startHeight to endHeight. | [
"readHeadersFromFile",
"reads",
"a",
"chunk",
"of",
"headers",
"each",
"of",
"size",
"headerSize",
"from",
"the",
"given",
"file",
"from",
"startHeight",
"to",
"endHeight",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/headerfs/file.go#L163-L183 | train |
lightninglabs/neutrino | neutrino.go | Count | func (ps *peerState) Count() int {
return len(ps.outboundPeers) + len(ps.persistentPeers)
} | go | func (ps *peerState) Count() int {
return len(ps.outboundPeers) + len(ps.persistentPeers)
} | [
"func",
"(",
"ps",
"*",
"peerState",
")",
"Count",
"(",
")",
"int",
"{",
"return",
"len",
"(",
"ps",
".",
"outboundPeers",
")",
"+",
"len",
"(",
"ps",
".",
"persistentPeers",
")",
"\n",
"}"
] | // Count returns the count of all known peers. | [
"Count",
"returns",
"the",
"count",
"of",
"all",
"known",
"peers",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L108-L110 | train |
lightninglabs/neutrino | neutrino.go | forAllOutboundPeers | func (ps *peerState) forAllOutboundPeers(closure func(sp *ServerPeer)) {
for _, e := range ps.outboundPeers {
closure(e)
}
for _, e := range ps.persistentPeers {
closure(e)
}
} | go | func (ps *peerState) forAllOutboundPeers(closure func(sp *ServerPeer)) {
for _, e := range ps.outboundPeers {
closure(e)
}
for _, e := range ps.persistentPeers {
closure(e)
}
} | [
"func",
"(",
"ps",
"*",
"peerState",
")",
"forAllOutboundPeers",
"(",
"closure",
"func",
"(",
"sp",
"*",
"ServerPeer",
")",
")",
"{",
"for",
"_",
",",
"e",
":=",
"range",
"ps",
".",
"outboundPeers",
"{",
"closure",
"(",
"e",
")",
"\n",
"}",
"\n",
"... | // forAllOutboundPeers is a helper function that runs closure on all outbound
// peers known to peerState. | [
"forAllOutboundPeers",
"is",
"a",
"helper",
"function",
"that",
"runs",
"closure",
"on",
"all",
"outbound",
"peers",
"known",
"to",
"peerState",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L114-L121 | train |
lightninglabs/neutrino | neutrino.go | newServerPeer | func newServerPeer(s *ChainService, isPersistent bool) *ServerPeer {
return &ServerPeer{
server: s,
persistent: isPersistent,
knownAddresses: make(map[string]struct{}),
quit: make(chan struct{}),
recvSubscribers: make(map[spMsgSubscription]struct{}),
}
} | go | func newServerPeer(s *ChainService, isPersistent bool) *ServerPeer {
return &ServerPeer{
server: s,
persistent: isPersistent,
knownAddresses: make(map[string]struct{}),
quit: make(chan struct{}),
recvSubscribers: make(map[spMsgSubscription]struct{}),
}
} | [
"func",
"newServerPeer",
"(",
"s",
"*",
"ChainService",
",",
"isPersistent",
"bool",
")",
"*",
"ServerPeer",
"{",
"return",
"&",
"ServerPeer",
"{",
"server",
":",
"s",
",",
"persistent",
":",
"isPersistent",
",",
"knownAddresses",
":",
"make",
"(",
"map",
... | // newServerPeer returns a new ServerPeer instance. The peer needs to be set by
// the caller. | [
"newServerPeer",
"returns",
"a",
"new",
"ServerPeer",
"instance",
".",
"The",
"peer",
"needs",
"to",
"be",
"set",
"by",
"the",
"caller",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L171-L179 | train |
lightninglabs/neutrino | neutrino.go | addKnownAddresses | func (sp *ServerPeer) addKnownAddresses(addresses []*wire.NetAddress) {
for _, na := range addresses {
sp.knownAddresses[addrmgr.NetAddressKey(na)] = struct{}{}
}
} | go | func (sp *ServerPeer) addKnownAddresses(addresses []*wire.NetAddress) {
for _, na := range addresses {
sp.knownAddresses[addrmgr.NetAddressKey(na)] = struct{}{}
}
} | [
"func",
"(",
"sp",
"*",
"ServerPeer",
")",
"addKnownAddresses",
"(",
"addresses",
"[",
"]",
"*",
"wire",
".",
"NetAddress",
")",
"{",
"for",
"_",
",",
"na",
":=",
"range",
"addresses",
"{",
"sp",
".",
"knownAddresses",
"[",
"addrmgr",
".",
"NetAddressKey... | // addKnownAddresses adds the given addresses to the set of known addresses to
// the peer to prevent sending duplicate addresses. | [
"addKnownAddresses",
"adds",
"the",
"given",
"addresses",
"to",
"the",
"set",
"of",
"known",
"addresses",
"to",
"the",
"peer",
"to",
"prevent",
"sending",
"duplicate",
"addresses",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L194-L198 | train |
lightninglabs/neutrino | neutrino.go | pushSendHeadersMsg | func (sp *ServerPeer) pushSendHeadersMsg() error {
if sp.VersionKnown() {
if sp.ProtocolVersion() > wire.SendHeadersVersion {
sp.QueueMessage(wire.NewMsgSendHeaders(), nil)
}
}
return nil
} | go | func (sp *ServerPeer) pushSendHeadersMsg() error {
if sp.VersionKnown() {
if sp.ProtocolVersion() > wire.SendHeadersVersion {
sp.QueueMessage(wire.NewMsgSendHeaders(), nil)
}
}
return nil
} | [
"func",
"(",
"sp",
"*",
"ServerPeer",
")",
"pushSendHeadersMsg",
"(",
")",
"error",
"{",
"if",
"sp",
".",
"VersionKnown",
"(",
")",
"{",
"if",
"sp",
".",
"ProtocolVersion",
"(",
")",
">",
"wire",
".",
"SendHeadersVersion",
"{",
"sp",
".",
"QueueMessage",... | // pushSendHeadersMsg sends a sendheaders message to the connected peer. | [
"pushSendHeadersMsg",
"sends",
"a",
"sendheaders",
"message",
"to",
"the",
"connected",
"peer",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L238-L245 | train |
lightninglabs/neutrino | neutrino.go | OnVerAck | func (sp *ServerPeer) OnVerAck(_ *peer.Peer, msg *wire.MsgVerAck) {
sp.pushSendHeadersMsg()
} | go | func (sp *ServerPeer) OnVerAck(_ *peer.Peer, msg *wire.MsgVerAck) {
sp.pushSendHeadersMsg()
} | [
"func",
"(",
"sp",
"*",
"ServerPeer",
")",
"OnVerAck",
"(",
"_",
"*",
"peer",
".",
"Peer",
",",
"msg",
"*",
"wire",
".",
"MsgVerAck",
")",
"{",
"sp",
".",
"pushSendHeadersMsg",
"(",
")",
"\n",
"}"
] | // OnVerAck is invoked when a peer receives a verack bitcoin message and is used
// to send the "sendheaders" command to peers that are of a sufficienty new
// protocol version. | [
"OnVerAck",
"is",
"invoked",
"when",
"a",
"peer",
"receives",
"a",
"verack",
"bitcoin",
"message",
"and",
"is",
"used",
"to",
"send",
"the",
"sendheaders",
"command",
"to",
"peers",
"that",
"are",
"of",
"a",
"sufficienty",
"new",
"protocol",
"version",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L250-L252 | train |
lightninglabs/neutrino | neutrino.go | OnHeaders | func (sp *ServerPeer) OnHeaders(p *peer.Peer, msg *wire.MsgHeaders) {
log.Tracef("Got headers with %d items from %s", len(msg.Headers),
p.Addr())
sp.server.blockManager.QueueHeaders(msg, sp)
} | go | func (sp *ServerPeer) OnHeaders(p *peer.Peer, msg *wire.MsgHeaders) {
log.Tracef("Got headers with %d items from %s", len(msg.Headers),
p.Addr())
sp.server.blockManager.QueueHeaders(msg, sp)
} | [
"func",
"(",
"sp",
"*",
"ServerPeer",
")",
"OnHeaders",
"(",
"p",
"*",
"peer",
".",
"Peer",
",",
"msg",
"*",
"wire",
".",
"MsgHeaders",
")",
"{",
"log",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"len",
"(",
"msg",
".",
"Headers",
")",
",",
"p",
".",... | // OnHeaders is invoked when a peer receives a headers bitcoin
// message. The message is passed down to the block manager. | [
"OnHeaders",
"is",
"invoked",
"when",
"a",
"peer",
"receives",
"a",
"headers",
"bitcoin",
"message",
".",
"The",
"message",
"is",
"passed",
"down",
"to",
"the",
"block",
"manager",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L357-L361 | train |
lightninglabs/neutrino | neutrino.go | subscribeRecvMsg | func (sp *ServerPeer) subscribeRecvMsg(subscription spMsgSubscription) {
sp.mtxSubscribers.Lock()
defer sp.mtxSubscribers.Unlock()
sp.recvSubscribers[subscription] = struct{}{}
} | go | func (sp *ServerPeer) subscribeRecvMsg(subscription spMsgSubscription) {
sp.mtxSubscribers.Lock()
defer sp.mtxSubscribers.Unlock()
sp.recvSubscribers[subscription] = struct{}{}
} | [
"func",
"(",
"sp",
"*",
"ServerPeer",
")",
"subscribeRecvMsg",
"(",
"subscription",
"spMsgSubscription",
")",
"{",
"sp",
".",
"mtxSubscribers",
".",
"Lock",
"(",
")",
"\n",
"defer",
"sp",
".",
"mtxSubscribers",
".",
"Unlock",
"(",
")",
"\n",
"sp",
".",
"... | // subscribeRecvMsg handles adding OnRead subscriptions to the server peer. | [
"subscribeRecvMsg",
"handles",
"adding",
"OnRead",
"subscriptions",
"to",
"the",
"server",
"peer",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L476-L480 | train |
lightninglabs/neutrino | neutrino.go | unsubscribeRecvMsgs | func (sp *ServerPeer) unsubscribeRecvMsgs(subscription spMsgSubscription) {
sp.mtxSubscribers.Lock()
defer sp.mtxSubscribers.Unlock()
delete(sp.recvSubscribers, subscription)
} | go | func (sp *ServerPeer) unsubscribeRecvMsgs(subscription spMsgSubscription) {
sp.mtxSubscribers.Lock()
defer sp.mtxSubscribers.Unlock()
delete(sp.recvSubscribers, subscription)
} | [
"func",
"(",
"sp",
"*",
"ServerPeer",
")",
"unsubscribeRecvMsgs",
"(",
"subscription",
"spMsgSubscription",
")",
"{",
"sp",
".",
"mtxSubscribers",
".",
"Lock",
"(",
")",
"\n",
"defer",
"sp",
".",
"mtxSubscribers",
".",
"Unlock",
"(",
")",
"\n",
"delete",
"... | // unsubscribeRecvMsgs handles removing OnRead subscriptions from the server
// peer. | [
"unsubscribeRecvMsgs",
"handles",
"removing",
"OnRead",
"subscriptions",
"from",
"the",
"server",
"peer",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L484-L488 | train |
lightninglabs/neutrino | neutrino.go | BestBlock | func (s *ChainService) BestBlock() (*waddrmgr.BlockStamp, error) {
bestHeader, bestHeight, err := s.BlockHeaders.ChainTip()
if err != nil {
return nil, err
}
_, filterHeight, err := s.RegFilterHeaders.ChainTip()
if err != nil {
return nil, err
}
// Filter headers might lag behind block headers, so we can c... | go | func (s *ChainService) BestBlock() (*waddrmgr.BlockStamp, error) {
bestHeader, bestHeight, err := s.BlockHeaders.ChainTip()
if err != nil {
return nil, err
}
_, filterHeight, err := s.RegFilterHeaders.ChainTip()
if err != nil {
return nil, err
}
// Filter headers might lag behind block headers, so we can c... | [
"func",
"(",
"s",
"*",
"ChainService",
")",
"BestBlock",
"(",
")",
"(",
"*",
"waddrmgr",
".",
"BlockStamp",
",",
"error",
")",
"{",
"bestHeader",
",",
"bestHeight",
",",
"err",
":=",
"s",
".",
"BlockHeaders",
".",
"ChainTip",
"(",
")",
"\n",
"if",
"e... | // BestBlock retrieves the most recent block's height and hash where we
// have both the header and filter header ready. | [
"BestBlock",
"retrieves",
"the",
"most",
"recent",
"block",
"s",
"height",
"and",
"hash",
"where",
"we",
"have",
"both",
"the",
"header",
"and",
"filter",
"header",
"ready",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L838-L865 | train |
lightninglabs/neutrino | neutrino.go | GetBlockHash | func (s *ChainService) GetBlockHash(height int64) (*chainhash.Hash, error) {
header, err := s.BlockHeaders.FetchHeaderByHeight(uint32(height))
if err != nil {
return nil, err
}
hash := header.BlockHash()
return &hash, err
} | go | func (s *ChainService) GetBlockHash(height int64) (*chainhash.Hash, error) {
header, err := s.BlockHeaders.FetchHeaderByHeight(uint32(height))
if err != nil {
return nil, err
}
hash := header.BlockHash()
return &hash, err
} | [
"func",
"(",
"s",
"*",
"ChainService",
")",
"GetBlockHash",
"(",
"height",
"int64",
")",
"(",
"*",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"header",
",",
"err",
":=",
"s",
".",
"BlockHeaders",
".",
"FetchHeaderByHeight",
"(",
"uint32",
"(",
"... | // GetBlockHash returns the block hash at the given height. | [
"GetBlockHash",
"returns",
"the",
"block",
"hash",
"at",
"the",
"given",
"height",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L868-L875 | train |
lightninglabs/neutrino | neutrino.go | GetBlockHeader | func (s *ChainService) GetBlockHeader(
blockHash *chainhash.Hash) (*wire.BlockHeader, error) {
header, _, err := s.BlockHeaders.FetchHeader(blockHash)
return header, err
} | go | func (s *ChainService) GetBlockHeader(
blockHash *chainhash.Hash) (*wire.BlockHeader, error) {
header, _, err := s.BlockHeaders.FetchHeader(blockHash)
return header, err
} | [
"func",
"(",
"s",
"*",
"ChainService",
")",
"GetBlockHeader",
"(",
"blockHash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"*",
"wire",
".",
"BlockHeader",
",",
"error",
")",
"{",
"header",
",",
"_",
",",
"err",
":=",
"s",
".",
"BlockHeaders",
".",
"Fe... | // GetBlockHeader returns the block header for the given block hash, or an
// error if the hash doesn't exist or is unknown. | [
"GetBlockHeader",
"returns",
"the",
"block",
"header",
"for",
"the",
"given",
"block",
"hash",
"or",
"an",
"error",
"if",
"the",
"hash",
"doesn",
"t",
"exist",
"or",
"is",
"unknown",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L879-L883 | train |
lightninglabs/neutrino | neutrino.go | GetBlockHeight | func (s *ChainService) GetBlockHeight(hash *chainhash.Hash) (int32, error) {
_, height, err := s.BlockHeaders.FetchHeader(hash)
if err != nil {
return 0, err
}
return int32(height), nil
} | go | func (s *ChainService) GetBlockHeight(hash *chainhash.Hash) (int32, error) {
_, height, err := s.BlockHeaders.FetchHeader(hash)
if err != nil {
return 0, err
}
return int32(height), nil
} | [
"func",
"(",
"s",
"*",
"ChainService",
")",
"GetBlockHeight",
"(",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"int32",
",",
"error",
")",
"{",
"_",
",",
"height",
",",
"err",
":=",
"s",
".",
"BlockHeaders",
".",
"FetchHeader",
"(",
"hash",
")",... | // GetBlockHeight gets the height of a block by its hash. An error is returned
// if the given block hash is unknown. | [
"GetBlockHeight",
"gets",
"the",
"height",
"of",
"a",
"block",
"by",
"its",
"hash",
".",
"An",
"error",
"is",
"returned",
"if",
"the",
"given",
"block",
"hash",
"is",
"unknown",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L887-L893 | train |
lightninglabs/neutrino | neutrino.go | BanPeer | func (s *ChainService) BanPeer(sp *ServerPeer) {
select {
case s.banPeers <- sp:
case <-s.quit:
return
}
} | go | func (s *ChainService) BanPeer(sp *ServerPeer) {
select {
case s.banPeers <- sp:
case <-s.quit:
return
}
} | [
"func",
"(",
"s",
"*",
"ChainService",
")",
"BanPeer",
"(",
"sp",
"*",
"ServerPeer",
")",
"{",
"select",
"{",
"case",
"s",
".",
"banPeers",
"<-",
"sp",
":",
"case",
"<-",
"s",
".",
"quit",
":",
"return",
"\n",
"}",
"\n",
"}"
] | // BanPeer bans a peer that has already been connected to the server by ip. | [
"BanPeer",
"bans",
"a",
"peer",
"that",
"has",
"already",
"been",
"connected",
"to",
"the",
"server",
"by",
"ip",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L896-L902 | train |
lightninglabs/neutrino | neutrino.go | AddPeer | func (s *ChainService) AddPeer(sp *ServerPeer) {
select {
case s.newPeers <- sp:
case <-s.quit:
return
}
} | go | func (s *ChainService) AddPeer(sp *ServerPeer) {
select {
case s.newPeers <- sp:
case <-s.quit:
return
}
} | [
"func",
"(",
"s",
"*",
"ChainService",
")",
"AddPeer",
"(",
"sp",
"*",
"ServerPeer",
")",
"{",
"select",
"{",
"case",
"s",
".",
"newPeers",
"<-",
"sp",
":",
"case",
"<-",
"s",
".",
"quit",
":",
"return",
"\n",
"}",
"\n",
"}"
] | // AddPeer adds a new peer that has already been connected to the server. | [
"AddPeer",
"adds",
"a",
"new",
"peer",
"that",
"has",
"already",
"been",
"connected",
"to",
"the",
"server",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L905-L911 | train |
lightninglabs/neutrino | neutrino.go | rollBackToHeight | func (s *ChainService) rollBackToHeight(height uint32) (*waddrmgr.BlockStamp, error) {
header, headerHeight, err := s.BlockHeaders.ChainTip()
if err != nil {
return nil, err
}
bs := &waddrmgr.BlockStamp{
Height: int32(headerHeight),
Hash: header.BlockHash(),
}
_, regHeight, err := s.RegFilterHeaders.Chai... | go | func (s *ChainService) rollBackToHeight(height uint32) (*waddrmgr.BlockStamp, error) {
header, headerHeight, err := s.BlockHeaders.ChainTip()
if err != nil {
return nil, err
}
bs := &waddrmgr.BlockStamp{
Height: int32(headerHeight),
Hash: header.BlockHash(),
}
_, regHeight, err := s.RegFilterHeaders.Chai... | [
"func",
"(",
"s",
"*",
"ChainService",
")",
"rollBackToHeight",
"(",
"height",
"uint32",
")",
"(",
"*",
"waddrmgr",
".",
"BlockStamp",
",",
"error",
")",
"{",
"header",
",",
"headerHeight",
",",
"err",
":=",
"s",
".",
"BlockHeaders",
".",
"ChainTip",
"("... | // rollBackToHeight rolls back all blocks until it hits the specified height.
// It sends notifications along the way. | [
"rollBackToHeight",
"rolls",
"back",
"all",
"blocks",
"until",
"it",
"hits",
"the",
"specified",
"height",
".",
"It",
"sends",
"notifications",
"along",
"the",
"way",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L934-L986 | train |
lightninglabs/neutrino | neutrino.go | isBanned | func (s *ChainService) isBanned(addr string, state *peerState) bool {
// First, we'll extract the host so we can consider it without taking
// into account the target port.
host, _, err := net.SplitHostPort(addr)
if err != nil {
log.Debugf("can't split host/port: %s", err)
return false
}
// With the host obt... | go | func (s *ChainService) isBanned(addr string, state *peerState) bool {
// First, we'll extract the host so we can consider it without taking
// into account the target port.
host, _, err := net.SplitHostPort(addr)
if err != nil {
log.Debugf("can't split host/port: %s", err)
return false
}
// With the host obt... | [
"func",
"(",
"s",
"*",
"ChainService",
")",
"isBanned",
"(",
"addr",
"string",
",",
"state",
"*",
"peerState",
")",
"bool",
"{",
"// First, we'll extract the host so we can consider it without taking",
"// into account the target port.",
"host",
",",
"_",
",",
"err",
... | // isBanned returns true if the passed peer address is still considered to be
// banned. | [
"isBanned",
"returns",
"true",
"if",
"the",
"passed",
"peer",
"address",
"is",
"still",
"considered",
"to",
"be",
"banned",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L1146-L1174 | train |
lightninglabs/neutrino | neutrino.go | SendTransaction | func (s *ChainService) SendTransaction(tx *wire.MsgTx) error {
// TODO(roasbeef): pipe through querying interface
return s.broadcaster.Broadcast(tx)
} | go | func (s *ChainService) SendTransaction(tx *wire.MsgTx) error {
// TODO(roasbeef): pipe through querying interface
return s.broadcaster.Broadcast(tx)
} | [
"func",
"(",
"s",
"*",
"ChainService",
")",
"SendTransaction",
"(",
"tx",
"*",
"wire",
".",
"MsgTx",
")",
"error",
"{",
"// TODO(roasbeef): pipe through querying interface",
"return",
"s",
".",
"broadcaster",
".",
"Broadcast",
"(",
"tx",
")",
"\n",
"}"
] | // SendTransaction broadcasts the transaction to all currently active peers so
// it can be propagated to other nodes and eventually mined. An error won't be
// returned if the transaction already exists within the mempool. Any
// transaction broadcast through this method will be rebroadcast upon every
// change of the... | [
"SendTransaction",
"broadcasts",
"the",
"transaction",
"to",
"all",
"currently",
"active",
"peers",
"so",
"it",
"can",
"be",
"propagated",
"to",
"other",
"nodes",
"and",
"eventually",
"mined",
".",
"An",
"error",
"won",
"t",
"be",
"returned",
"if",
"the",
"t... | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L1311-L1314 | train |
lightninglabs/neutrino | neutrino.go | newPeerConfig | func newPeerConfig(sp *ServerPeer) *peer.Config {
return &peer.Config{
Listeners: peer.MessageListeners{
OnVersion: sp.OnVersion,
//OnVerAck: sp.OnVerAck, // Don't use sendheaders yet
OnInv: sp.OnInv,
OnHeaders: sp.OnHeaders,
OnReject: sp.OnReject,
OnFeeFilter: sp.OnFeeFilter,
OnAd... | go | func newPeerConfig(sp *ServerPeer) *peer.Config {
return &peer.Config{
Listeners: peer.MessageListeners{
OnVersion: sp.OnVersion,
//OnVerAck: sp.OnVerAck, // Don't use sendheaders yet
OnInv: sp.OnInv,
OnHeaders: sp.OnHeaders,
OnReject: sp.OnReject,
OnFeeFilter: sp.OnFeeFilter,
OnAd... | [
"func",
"newPeerConfig",
"(",
"sp",
"*",
"ServerPeer",
")",
"*",
"peer",
".",
"Config",
"{",
"return",
"&",
"peer",
".",
"Config",
"{",
"Listeners",
":",
"peer",
".",
"MessageListeners",
"{",
"OnVersion",
":",
"sp",
".",
"OnVersion",
",",
"//OnVerAck: s... | // newPeerConfig returns the configuration for the given ServerPeer. | [
"newPeerConfig",
"returns",
"the",
"configuration",
"for",
"the",
"given",
"ServerPeer",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L1317-L1345 | train |
lightninglabs/neutrino | neutrino.go | Start | func (s *ChainService) Start() error {
// Already started?
if atomic.AddInt32(&s.started, 1) != 1 {
return nil
}
// Start the address manager and block manager, both of which are
// needed by peers.
s.addrManager.Start()
s.blockManager.Start()
s.blockSubscriptionMgr.Start()
s.utxoScanner.Start()
if err :... | go | func (s *ChainService) Start() error {
// Already started?
if atomic.AddInt32(&s.started, 1) != 1 {
return nil
}
// Start the address manager and block manager, both of which are
// needed by peers.
s.addrManager.Start()
s.blockManager.Start()
s.blockSubscriptionMgr.Start()
s.utxoScanner.Start()
if err :... | [
"func",
"(",
"s",
"*",
"ChainService",
")",
"Start",
"(",
")",
"error",
"{",
"// Already started?",
"if",
"atomic",
".",
"AddInt32",
"(",
"&",
"s",
".",
"started",
",",
"1",
")",
"!=",
"1",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Start the address... | // Start begins connecting to peers and syncing the blockchain. | [
"Start",
"begins",
"connecting",
"to",
"peers",
"and",
"syncing",
"the",
"blockchain",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L1423-L1450 | train |
lightninglabs/neutrino | neutrino.go | PeerByAddr | func (s *ChainService) PeerByAddr(addr string) *ServerPeer {
for _, peer := range s.Peers() {
if peer.Addr() == addr {
return peer
}
}
return nil
} | go | func (s *ChainService) PeerByAddr(addr string) *ServerPeer {
for _, peer := range s.Peers() {
if peer.Addr() == addr {
return peer
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"ChainService",
")",
"PeerByAddr",
"(",
"addr",
"string",
")",
"*",
"ServerPeer",
"{",
"for",
"_",
",",
"peer",
":=",
"range",
"s",
".",
"Peers",
"(",
")",
"{",
"if",
"peer",
".",
"Addr",
"(",
")",
"==",
"addr",
"{",
"retur... | // PeerByAddr lets the caller look up a peer address in the service's peer
// table, if connected to that peer address. | [
"PeerByAddr",
"lets",
"the",
"caller",
"look",
"up",
"a",
"peer",
"address",
"in",
"the",
"service",
"s",
"peer",
"table",
"if",
"connected",
"to",
"that",
"peer",
"address",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L1481-L1488 | train |
lightninglabs/neutrino | neutrino.go | GetBlockHeaderByHeight | func (s *RescanChainSource) GetBlockHeaderByHeight(
height uint32) (*wire.BlockHeader, error) {
return s.BlockHeaders.FetchHeaderByHeight(height)
} | go | func (s *RescanChainSource) GetBlockHeaderByHeight(
height uint32) (*wire.BlockHeader, error) {
return s.BlockHeaders.FetchHeaderByHeight(height)
} | [
"func",
"(",
"s",
"*",
"RescanChainSource",
")",
"GetBlockHeaderByHeight",
"(",
"height",
"uint32",
")",
"(",
"*",
"wire",
".",
"BlockHeader",
",",
"error",
")",
"{",
"return",
"s",
".",
"BlockHeaders",
".",
"FetchHeaderByHeight",
"(",
"height",
")",
"\n",
... | // GetBlockHeaderByHeight returns the header of the block with the given height. | [
"GetBlockHeaderByHeight",
"returns",
"the",
"header",
"of",
"the",
"block",
"with",
"the",
"given",
"height",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L1501-L1504 | train |
lightninglabs/neutrino | neutrino.go | GetBlockHeader | func (s *RescanChainSource) GetBlockHeader(
hash *chainhash.Hash) (*wire.BlockHeader, uint32, error) {
return s.BlockHeaders.FetchHeader(hash)
} | go | func (s *RescanChainSource) GetBlockHeader(
hash *chainhash.Hash) (*wire.BlockHeader, uint32, error) {
return s.BlockHeaders.FetchHeader(hash)
} | [
"func",
"(",
"s",
"*",
"RescanChainSource",
")",
"GetBlockHeader",
"(",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"*",
"wire",
".",
"BlockHeader",
",",
"uint32",
",",
"error",
")",
"{",
"return",
"s",
".",
"BlockHeaders",
".",
"FetchHeader",
"(",
... | // GetBlockHeader returns the header of the block with the given hash. | [
"GetBlockHeader",
"returns",
"the",
"header",
"of",
"the",
"block",
"with",
"the",
"given",
"hash",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L1507-L1510 | train |
lightninglabs/neutrino | neutrino.go | GetFilterHeaderByHeight | func (s *RescanChainSource) GetFilterHeaderByHeight(
height uint32) (*chainhash.Hash, error) {
return s.RegFilterHeaders.FetchHeaderByHeight(height)
} | go | func (s *RescanChainSource) GetFilterHeaderByHeight(
height uint32) (*chainhash.Hash, error) {
return s.RegFilterHeaders.FetchHeaderByHeight(height)
} | [
"func",
"(",
"s",
"*",
"RescanChainSource",
")",
"GetFilterHeaderByHeight",
"(",
"height",
"uint32",
")",
"(",
"*",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"return",
"s",
".",
"RegFilterHeaders",
".",
"FetchHeaderByHeight",
"(",
"height",
")",
"\n"... | // GetFilterHeaderByHeight returns the filter header of the block with the given
// height. | [
"GetFilterHeaderByHeight",
"returns",
"the",
"filter",
"header",
"of",
"the",
"block",
"with",
"the",
"given",
"height",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L1514-L1517 | train |
lightninglabs/neutrino | neutrino.go | Subscribe | func (s *RescanChainSource) Subscribe(
bestHeight uint32) (*blockntfns.Subscription, error) {
return s.blockSubscriptionMgr.NewSubscription(bestHeight)
} | go | func (s *RescanChainSource) Subscribe(
bestHeight uint32) (*blockntfns.Subscription, error) {
return s.blockSubscriptionMgr.NewSubscription(bestHeight)
} | [
"func",
"(",
"s",
"*",
"RescanChainSource",
")",
"Subscribe",
"(",
"bestHeight",
"uint32",
")",
"(",
"*",
"blockntfns",
".",
"Subscription",
",",
"error",
")",
"{",
"return",
"s",
".",
"blockSubscriptionMgr",
".",
"NewSubscription",
"(",
"bestHeight",
")",
"... | // Subscribe returns a block subscription that delivers block notifications in
// order. The bestHeight parameter can be used to signal that a backlog of
// notifications should be delivered from this height. When providing a height
// of 0, a backlog will not be delivered. | [
"Subscribe",
"returns",
"a",
"block",
"subscription",
"that",
"delivers",
"block",
"notifications",
"in",
"order",
".",
"The",
"bestHeight",
"parameter",
"can",
"be",
"used",
"to",
"signal",
"that",
"a",
"backlog",
"of",
"notifications",
"should",
"be",
"deliver... | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/neutrino.go#L1523-L1526 | train |
lightninglabs/neutrino | blockntfns/notification.go | NewBlockConnected | func NewBlockConnected(header wire.BlockHeader, height uint32) *Connected {
return &Connected{header: header, height: height}
} | go | func NewBlockConnected(header wire.BlockHeader, height uint32) *Connected {
return &Connected{header: header, height: height}
} | [
"func",
"NewBlockConnected",
"(",
"header",
"wire",
".",
"BlockHeader",
",",
"height",
"uint32",
")",
"*",
"Connected",
"{",
"return",
"&",
"Connected",
"{",
"header",
":",
"header",
",",
"height",
":",
"height",
"}",
"\n",
"}"
] | // NewBlockConnected creates a new Connected notification for the given block. | [
"NewBlockConnected",
"creates",
"a",
"new",
"Connected",
"notification",
"for",
"the",
"given",
"block",
"."
] | a655679fe131a5d1b4417872cc834fc3862ac70e | https://github.com/lightninglabs/neutrino/blob/a655679fe131a5d1b4417872cc834fc3862ac70e/blockntfns/notification.go#L36-L38 | 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.