id int32 0 167k | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
2,800 | m3db/m3x | pool/bytes.go | AppendByte | func AppendByte(bytes []byte, b byte, pool BytesPool) []byte {
if len(bytes) == cap(bytes) {
newBytes := pool.Get(cap(bytes) * 2)
n := copy(newBytes[:len(bytes)], bytes)
pool.Put(bytes)
bytes = newBytes[:n]
}
return append(bytes, b)
} | go | func AppendByte(bytes []byte, b byte, pool BytesPool) []byte {
if len(bytes) == cap(bytes) {
newBytes := pool.Get(cap(bytes) * 2)
n := copy(newBytes[:len(bytes)], bytes)
pool.Put(bytes)
bytes = newBytes[:n]
}
return append(bytes, b)
} | [
"func",
"AppendByte",
"(",
"bytes",
"[",
"]",
"byte",
",",
"b",
"byte",
",",
"pool",
"BytesPool",
")",
"[",
"]",
"byte",
"{",
"if",
"len",
"(",
"bytes",
")",
"==",
"cap",
"(",
"bytes",
")",
"{",
"newBytes",
":=",
"pool",
".",
"Get",
"(",
"cap",
... | // AppendByte appends a byte to a byte slice getting a new slice from the
// BytesPool if the slice is at capacity | [
"AppendByte",
"appends",
"a",
"byte",
"to",
"a",
"byte",
"slice",
"getting",
"a",
"new",
"slice",
"from",
"the",
"BytesPool",
"if",
"the",
"slice",
"is",
"at",
"capacity"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/pool/bytes.go#L53-L62 |
2,801 | m3db/m3x | context/options.go | NewOptions | func NewOptions() Options {
return &opts{
contextPoolOpts: pool.NewObjectPoolOptions(),
finalizerPoolOpts: pool.NewObjectPoolOptions(),
maxPooledFinalizerCap: defaultMaxFinalizersCap,
initPooledFinalizerCap: defaultInitFinalizersCap,
}
} | go | func NewOptions() Options {
return &opts{
contextPoolOpts: pool.NewObjectPoolOptions(),
finalizerPoolOpts: pool.NewObjectPoolOptions(),
maxPooledFinalizerCap: defaultMaxFinalizersCap,
initPooledFinalizerCap: defaultInitFinalizersCap,
}
} | [
"func",
"NewOptions",
"(",
")",
"Options",
"{",
"return",
"&",
"opts",
"{",
"contextPoolOpts",
":",
"pool",
".",
"NewObjectPoolOptions",
"(",
")",
",",
"finalizerPoolOpts",
":",
"pool",
".",
"NewObjectPoolOptions",
"(",
")",
",",
"maxPooledFinalizerCap",
":",
... | // NewOptions returns a new Options object. | [
"NewOptions",
"returns",
"a",
"new",
"Options",
"object",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/context/options.go#L38-L45 |
2,802 | m3db/m3x | retry/config.go | NewOptions | func (c Configuration) NewOptions(scope tally.Scope) Options {
opts := NewOptions().SetMetricsScope(scope)
if c.InitialBackoff != 0 {
opts = opts.SetInitialBackoff(c.InitialBackoff)
}
if c.BackoffFactor != 0.0 {
opts = opts.SetBackoffFactor(c.BackoffFactor)
}
if c.MaxBackoff != 0 {
opts = opts.SetMaxBackoff(c.MaxBackoff)
}
if c.MaxRetries != 0 {
opts = opts.SetMaxRetries(c.MaxRetries)
}
if c.Forever != nil {
opts = opts.SetForever(*c.Forever)
}
if c.Jitter != nil {
opts = opts.SetJitter(*c.Jitter)
}
return opts
} | go | func (c Configuration) NewOptions(scope tally.Scope) Options {
opts := NewOptions().SetMetricsScope(scope)
if c.InitialBackoff != 0 {
opts = opts.SetInitialBackoff(c.InitialBackoff)
}
if c.BackoffFactor != 0.0 {
opts = opts.SetBackoffFactor(c.BackoffFactor)
}
if c.MaxBackoff != 0 {
opts = opts.SetMaxBackoff(c.MaxBackoff)
}
if c.MaxRetries != 0 {
opts = opts.SetMaxRetries(c.MaxRetries)
}
if c.Forever != nil {
opts = opts.SetForever(*c.Forever)
}
if c.Jitter != nil {
opts = opts.SetJitter(*c.Jitter)
}
return opts
} | [
"func",
"(",
"c",
"Configuration",
")",
"NewOptions",
"(",
"scope",
"tally",
".",
"Scope",
")",
"Options",
"{",
"opts",
":=",
"NewOptions",
"(",
")",
".",
"SetMetricsScope",
"(",
"scope",
")",
"\n",
"if",
"c",
".",
"InitialBackoff",
"!=",
"0",
"{",
"op... | // NewOptions creates a new retry options based on the configuration. | [
"NewOptions",
"creates",
"a",
"new",
"retry",
"options",
"based",
"on",
"the",
"configuration",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/retry/config.go#L52-L74 |
2,803 | m3db/m3x | retry/config.go | NewRetrier | func (c Configuration) NewRetrier(scope tally.Scope) Retrier {
return NewRetrier(c.NewOptions(scope))
} | go | func (c Configuration) NewRetrier(scope tally.Scope) Retrier {
return NewRetrier(c.NewOptions(scope))
} | [
"func",
"(",
"c",
"Configuration",
")",
"NewRetrier",
"(",
"scope",
"tally",
".",
"Scope",
")",
"Retrier",
"{",
"return",
"NewRetrier",
"(",
"c",
".",
"NewOptions",
"(",
"scope",
")",
")",
"\n",
"}"
] | // NewRetrier creates a new retrier based on the configuration. | [
"NewRetrier",
"creates",
"a",
"new",
"retrier",
"based",
"on",
"the",
"configuration",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/retry/config.go#L77-L79 |
2,804 | m3db/m3x | checked/checked_mock.go | NewMockBytes | func NewMockBytes(ctrl *gomock.Controller) *MockBytes {
mock := &MockBytes{ctrl: ctrl}
mock.recorder = &MockBytesMockRecorder{mock}
return mock
} | go | func NewMockBytes(ctrl *gomock.Controller) *MockBytes {
mock := &MockBytes{ctrl: ctrl}
mock.recorder = &MockBytesMockRecorder{mock}
return mock
} | [
"func",
"NewMockBytes",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockBytes",
"{",
"mock",
":=",
"&",
"MockBytes",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockBytesMockRecorder",
"{",
"mock",
"}",
"\n",
... | // NewMockBytes creates a new mock instance | [
"NewMockBytes",
"creates",
"a",
"new",
"mock",
"instance"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/checked_mock.go#L47-L51 |
2,805 | m3db/m3x | checked/checked_mock.go | Append | func (m *MockBytes) Append(arg0 byte) {
m.ctrl.Call(m, "Append", arg0)
} | go | func (m *MockBytes) Append(arg0 byte) {
m.ctrl.Call(m, "Append", arg0)
} | [
"func",
"(",
"m",
"*",
"MockBytes",
")",
"Append",
"(",
"arg0",
"byte",
")",
"{",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"}"
] | // Append mocks base method | [
"Append",
"mocks",
"base",
"method"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/checked_mock.go#L59-L61 |
2,806 | m3db/m3x | checked/checked_mock.go | Append | func (mr *MockBytesMockRecorder) Append(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Append", reflect.TypeOf((*MockBytes)(nil).Append), arg0)
} | go | func (mr *MockBytesMockRecorder) Append(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Append", reflect.TypeOf((*MockBytes)(nil).Append), arg0)
} | [
"func",
"(",
"mr",
"*",
"MockBytesMockRecorder",
")",
"Append",
"(",
"arg0",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\""... | // Append indicates an expected call of Append | [
"Append",
"indicates",
"an",
"expected",
"call",
"of",
"Append"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/checked_mock.go#L64-L66 |
2,807 | m3db/m3x | checked/checked_mock.go | AppendAll | func (m *MockBytes) AppendAll(arg0 []byte) {
m.ctrl.Call(m, "AppendAll", arg0)
} | go | func (m *MockBytes) AppendAll(arg0 []byte) {
m.ctrl.Call(m, "AppendAll", arg0)
} | [
"func",
"(",
"m",
"*",
"MockBytes",
")",
"AppendAll",
"(",
"arg0",
"[",
"]",
"byte",
")",
"{",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"}"
] | // AppendAll mocks base method | [
"AppendAll",
"mocks",
"base",
"method"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/checked_mock.go#L69-L71 |
2,808 | m3db/m3x | checked/checked_mock.go | Bytes | func (m *MockBytes) Bytes() []byte {
ret := m.ctrl.Call(m, "Bytes")
ret0, _ := ret[0].([]byte)
return ret0
} | go | func (m *MockBytes) Bytes() []byte {
ret := m.ctrl.Call(m, "Bytes")
ret0, _ := ret[0].([]byte)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockBytes",
")",
"Bytes",
"(",
")",
"[",
"]",
"byte",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"[",
"]",
"byte",... | // Bytes mocks base method | [
"Bytes",
"mocks",
"base",
"method"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/checked_mock.go#L79-L83 |
2,809 | m3db/m3x | checked/checked_mock.go | Finalizer | func (m *MockBytes) Finalizer() resource.Finalizer {
ret := m.ctrl.Call(m, "Finalizer")
ret0, _ := ret[0].(resource.Finalizer)
return ret0
} | go | func (m *MockBytes) Finalizer() resource.Finalizer {
ret := m.ctrl.Call(m, "Finalizer")
ret0, _ := ret[0].(resource.Finalizer)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockBytes",
")",
"Finalizer",
"(",
")",
"resource",
".",
"Finalizer",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"reso... | // Finalizer mocks base method | [
"Finalizer",
"mocks",
"base",
"method"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/checked_mock.go#L143-L147 |
2,810 | m3db/m3x | checked/checked_mock.go | Finalizer | func (mr *MockBytesMockRecorder) Finalizer() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Finalizer", reflect.TypeOf((*MockBytes)(nil).Finalizer))
} | go | func (mr *MockBytesMockRecorder) Finalizer() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Finalizer", reflect.TypeOf((*MockBytes)(nil).Finalizer))
} | [
"func",
"(",
"mr",
"*",
"MockBytesMockRecorder",
")",
"Finalizer",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"Type... | // Finalizer indicates an expected call of Finalizer | [
"Finalizer",
"indicates",
"an",
"expected",
"call",
"of",
"Finalizer"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/checked_mock.go#L150-L152 |
2,811 | m3db/m3x | checked/checked_mock.go | Reset | func (m *MockBytes) Reset(arg0 []byte) {
m.ctrl.Call(m, "Reset", arg0)
} | go | func (m *MockBytes) Reset(arg0 []byte) {
m.ctrl.Call(m, "Reset", arg0)
} | [
"func",
"(",
"m",
"*",
"MockBytes",
")",
"Reset",
"(",
"arg0",
"[",
"]",
"byte",
")",
"{",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"}"
] | // Reset mocks base method | [
"Reset",
"mocks",
"base",
"method"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/checked_mock.go#L243-L245 |
2,812 | m3db/m3x | checked/checked_mock.go | Resize | func (m *MockBytes) Resize(arg0 int) {
m.ctrl.Call(m, "Resize", arg0)
} | go | func (m *MockBytes) Resize(arg0 int) {
m.ctrl.Call(m, "Resize", arg0)
} | [
"func",
"(",
"m",
"*",
"MockBytes",
")",
"Resize",
"(",
"arg0",
"int",
")",
"{",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"}"
] | // Resize mocks base method | [
"Resize",
"mocks",
"base",
"method"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/checked_mock.go#L253-L255 |
2,813 | m3db/m3x | checked/checked_mock.go | SetFinalizer | func (m *MockBytes) SetFinalizer(arg0 resource.Finalizer) {
m.ctrl.Call(m, "SetFinalizer", arg0)
} | go | func (m *MockBytes) SetFinalizer(arg0 resource.Finalizer) {
m.ctrl.Call(m, "SetFinalizer", arg0)
} | [
"func",
"(",
"m",
"*",
"MockBytes",
")",
"SetFinalizer",
"(",
"arg0",
"resource",
".",
"Finalizer",
")",
"{",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"}"
] | // SetFinalizer mocks base method | [
"SetFinalizer",
"mocks",
"base",
"method"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/checked_mock.go#L263-L265 |
2,814 | m3db/m3x | pool/config.go | NewBuckets | func (c *BucketizedPoolConfiguration) NewBuckets() []Bucket {
buckets := make([]Bucket, 0, len(c.Buckets))
for _, bconfig := range c.Buckets {
bucket := bconfig.NewBucket()
buckets = append(buckets, bucket)
}
return buckets
} | go | func (c *BucketizedPoolConfiguration) NewBuckets() []Bucket {
buckets := make([]Bucket, 0, len(c.Buckets))
for _, bconfig := range c.Buckets {
bucket := bconfig.NewBucket()
buckets = append(buckets, bucket)
}
return buckets
} | [
"func",
"(",
"c",
"*",
"BucketizedPoolConfiguration",
")",
"NewBuckets",
"(",
")",
"[",
"]",
"Bucket",
"{",
"buckets",
":=",
"make",
"(",
"[",
"]",
"Bucket",
",",
"0",
",",
"len",
"(",
"c",
".",
"Buckets",
")",
")",
"\n",
"for",
"_",
",",
"bconfig"... | // NewBuckets create a new list of buckets. | [
"NewBuckets",
"create",
"a",
"new",
"list",
"of",
"buckets",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/pool/config.go#L69-L76 |
2,815 | m3db/m3x | pool/config.go | NewBucket | func (c *BucketConfiguration) NewBucket() Bucket {
return Bucket{
Capacity: c.Capacity,
Count: c.Count,
}
} | go | func (c *BucketConfiguration) NewBucket() Bucket {
return Bucket{
Capacity: c.Capacity,
Count: c.Count,
}
} | [
"func",
"(",
"c",
"*",
"BucketConfiguration",
")",
"NewBucket",
"(",
")",
"Bucket",
"{",
"return",
"Bucket",
"{",
"Capacity",
":",
"c",
".",
"Capacity",
",",
"Count",
":",
"c",
".",
"Count",
",",
"}",
"\n",
"}"
] | // NewBucket creates a new bucket. | [
"NewBucket",
"creates",
"a",
"new",
"bucket",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/pool/config.go#L88-L93 |
2,816 | m3db/m3x | unsafe/string.go | WithBytesAndArg | func WithBytesAndArg(s string, arg interface{}, fn BytesAndArgFn) {
fn(Bytes(s), arg)
} | go | func WithBytesAndArg(s string, arg interface{}, fn BytesAndArgFn) {
fn(Bytes(s), arg)
} | [
"func",
"WithBytesAndArg",
"(",
"s",
"string",
",",
"arg",
"interface",
"{",
"}",
",",
"fn",
"BytesAndArgFn",
")",
"{",
"fn",
"(",
"Bytes",
"(",
"s",
")",
",",
"arg",
")",
"\n",
"}"
] | // WithBytesAndArg converts a string to a byte slice with zero heap memory allocations,
// and calls a function to process the byte slice alongside one argument. It is the
// caller's responsibility to make sure the callback function passed in does not modify
// the byte slice in any way, and holds no reference to the byte slice after the function
// returns. | [
"WithBytesAndArg",
"converts",
"a",
"string",
"to",
"a",
"byte",
"slice",
"with",
"zero",
"heap",
"memory",
"allocations",
"and",
"calls",
"a",
"function",
"to",
"process",
"the",
"byte",
"slice",
"alongside",
"one",
"argument",
".",
"It",
"is",
"the",
"call... | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/unsafe/string.go#L54-L56 |
2,817 | m3db/m3x | unsafe/string.go | Bytes | func Bytes(s string) ImmutableBytes {
if len(s) == 0 {
return nil
}
// NB(xichen): We need to declare a real byte slice so internally the compiler
// knows to use an unsafe.Pointer to keep track of the underlying memory so that
// once the slice's array pointer is updated with the pointer to the string's
// underlying bytes, the compiler won't prematurely GC the memory when the string
// goes out of scope.
var b []byte
byteHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b))
// NB(xichen): This makes sure that even if GC relocates the string's underlying
// memory after this assignment, the corresponding unsafe.Pointer in the internal
// slice struct will be updated accordingly to reflect the memory relocation.
byteHeader.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data
// NB(xichen): It is important that we access s after we assign the Data
// pointer of the string header to the Data pointer of the slice header to
// make sure the string (and the underlying bytes backing the string) don't get
// GC'ed before the assignment happens.
l := len(s)
byteHeader.Len = l
byteHeader.Cap = l
return b
} | go | func Bytes(s string) ImmutableBytes {
if len(s) == 0 {
return nil
}
// NB(xichen): We need to declare a real byte slice so internally the compiler
// knows to use an unsafe.Pointer to keep track of the underlying memory so that
// once the slice's array pointer is updated with the pointer to the string's
// underlying bytes, the compiler won't prematurely GC the memory when the string
// goes out of scope.
var b []byte
byteHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b))
// NB(xichen): This makes sure that even if GC relocates the string's underlying
// memory after this assignment, the corresponding unsafe.Pointer in the internal
// slice struct will be updated accordingly to reflect the memory relocation.
byteHeader.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data
// NB(xichen): It is important that we access s after we assign the Data
// pointer of the string header to the Data pointer of the slice header to
// make sure the string (and the underlying bytes backing the string) don't get
// GC'ed before the assignment happens.
l := len(s)
byteHeader.Len = l
byteHeader.Cap = l
return b
} | [
"func",
"Bytes",
"(",
"s",
"string",
")",
"ImmutableBytes",
"{",
"if",
"len",
"(",
"s",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// NB(xichen): We need to declare a real byte slice so internally the compiler",
"// knows to use an unsafe.Pointer to keep tr... | // Bytes returns the bytes backing a string, it is the caller's responsibility
// not to mutate the bytes returned. It is much safer to use WithBytes and
// WithBytesAndArg if possible, which is more likely to force use of the result
// to just a small block of code. | [
"Bytes",
"returns",
"the",
"bytes",
"backing",
"a",
"string",
"it",
"is",
"the",
"caller",
"s",
"responsibility",
"not",
"to",
"mutate",
"the",
"bytes",
"returned",
".",
"It",
"is",
"much",
"safer",
"to",
"use",
"WithBytes",
"and",
"WithBytesAndArg",
"if",
... | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/unsafe/string.go#L62-L89 |
2,818 | m3db/m3x | clock/config.go | NewOptions | func (c Configuration) NewOptions() Options {
opts := NewOptions()
if c.MaxPositiveSkew != 0 {
opts = opts.SetMaxPositiveSkew(c.MaxPositiveSkew)
}
if c.MaxNegativeSkew != 0 {
opts = opts.SetMaxNegativeSkew(c.MaxNegativeSkew)
}
return opts
} | go | func (c Configuration) NewOptions() Options {
opts := NewOptions()
if c.MaxPositiveSkew != 0 {
opts = opts.SetMaxPositiveSkew(c.MaxPositiveSkew)
}
if c.MaxNegativeSkew != 0 {
opts = opts.SetMaxNegativeSkew(c.MaxNegativeSkew)
}
return opts
} | [
"func",
"(",
"c",
"Configuration",
")",
"NewOptions",
"(",
")",
"Options",
"{",
"opts",
":=",
"NewOptions",
"(",
")",
"\n",
"if",
"c",
".",
"MaxPositiveSkew",
"!=",
"0",
"{",
"opts",
"=",
"opts",
".",
"SetMaxPositiveSkew",
"(",
"c",
".",
"MaxPositiveSkew... | // NewOptions creates a new set of options. | [
"NewOptions",
"creates",
"a",
"new",
"set",
"of",
"options",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/clock/config.go#L37-L46 |
2,819 | m3db/m3x | generics/hashmap/idkey/map_gen.go | mapAlloc | func mapAlloc(opts mapOptions) *Map {
m := &Map{mapOptions: opts}
m.Reallocate()
return m
} | go | func mapAlloc(opts mapOptions) *Map {
m := &Map{mapOptions: opts}
m.Reallocate()
return m
} | [
"func",
"mapAlloc",
"(",
"opts",
"mapOptions",
")",
"*",
"Map",
"{",
"m",
":=",
"&",
"Map",
"{",
"mapOptions",
":",
"opts",
"}",
"\n",
"m",
".",
"Reallocate",
"(",
")",
"\n",
"return",
"m",
"\n",
"}"
] | // mapAlloc is a non-exported function so that when generating the source code
// for the map you can supply a public constructor that sets the correct
// hash, equals, copy, finalize options without users of the map needing to
// implement them themselves. | [
"mapAlloc",
"is",
"a",
"non",
"-",
"exported",
"function",
"so",
"that",
"when",
"generating",
"the",
"source",
"code",
"for",
"the",
"map",
"you",
"can",
"supply",
"a",
"public",
"constructor",
"that",
"sets",
"the",
"correct",
"hash",
"equals",
"copy",
"... | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/generics/hashmap/idkey/map_gen.go#L118-L122 |
2,820 | m3db/m3x | generics/hashmap/idkey/map_gen.go | Reset | func (m *Map) Reset() {
for hash, entry := range m.lookup {
m.removeMapKey(hash, entry.key)
}
} | go | func (m *Map) Reset() {
for hash, entry := range m.lookup {
m.removeMapKey(hash, entry.key)
}
} | [
"func",
"(",
"m",
"*",
"Map",
")",
"Reset",
"(",
")",
"{",
"for",
"hash",
",",
"entry",
":=",
"range",
"m",
".",
"lookup",
"{",
"m",
".",
"removeMapKey",
"(",
"hash",
",",
"entry",
".",
"key",
")",
"\n",
"}",
"\n",
"}"
] | // Reset will reset the map by simply deleting all keys to avoid
// allocating a new map. | [
"Reset",
"will",
"reset",
"the",
"map",
"by",
"simply",
"deleting",
"all",
"keys",
"to",
"avoid",
"allocating",
"a",
"new",
"map",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/generics/hashmap/idkey/map_gen.go#L238-L242 |
2,821 | m3db/m3x | generics/hashmap/idkey/map_gen.go | Reallocate | func (m *Map) Reallocate() {
if m.initialSize > 0 {
m.lookup = make(map[MapHash]MapEntry, m.initialSize)
} else {
m.lookup = make(map[MapHash]MapEntry)
}
} | go | func (m *Map) Reallocate() {
if m.initialSize > 0 {
m.lookup = make(map[MapHash]MapEntry, m.initialSize)
} else {
m.lookup = make(map[MapHash]MapEntry)
}
} | [
"func",
"(",
"m",
"*",
"Map",
")",
"Reallocate",
"(",
")",
"{",
"if",
"m",
".",
"initialSize",
">",
"0",
"{",
"m",
".",
"lookup",
"=",
"make",
"(",
"map",
"[",
"MapHash",
"]",
"MapEntry",
",",
"m",
".",
"initialSize",
")",
"\n",
"}",
"else",
"{... | // Reallocate will avoid deleting all keys and reallocate a new
// map, this is useful if you believe you have a large map and
// will not need to grow back to a similar size. | [
"Reallocate",
"will",
"avoid",
"deleting",
"all",
"keys",
"and",
"reallocate",
"a",
"new",
"map",
"this",
"is",
"useful",
"if",
"you",
"believe",
"you",
"have",
"a",
"large",
"map",
"and",
"will",
"not",
"need",
"to",
"grow",
"back",
"to",
"a",
"similar"... | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/generics/hashmap/idkey/map_gen.go#L247-L253 |
2,822 | m3db/m3x | debug/mutex.go | Lock | func (m *RWMutex) Lock() {
atomic.AddInt64(&m.pendingWriters, 1)
m.mutex.Lock()
atomic.AddInt64(&m.writers, 1)
atomic.AddInt64(&m.pendingWriters, -1)
stackBufLen := RWMutexStackBufferLength()
m.stateMutex.Lock()
if len(m.stackBuf) < stackBufLen {
m.stackBuf = make([]byte, stackBufLen)
}
n := runtime.Stack(m.stackBuf, false)
m.lastLockStack = m.stackBuf[:n]
m.stateMutex.Unlock()
} | go | func (m *RWMutex) Lock() {
atomic.AddInt64(&m.pendingWriters, 1)
m.mutex.Lock()
atomic.AddInt64(&m.writers, 1)
atomic.AddInt64(&m.pendingWriters, -1)
stackBufLen := RWMutexStackBufferLength()
m.stateMutex.Lock()
if len(m.stackBuf) < stackBufLen {
m.stackBuf = make([]byte, stackBufLen)
}
n := runtime.Stack(m.stackBuf, false)
m.lastLockStack = m.stackBuf[:n]
m.stateMutex.Unlock()
} | [
"func",
"(",
"m",
"*",
"RWMutex",
")",
"Lock",
"(",
")",
"{",
"atomic",
".",
"AddInt64",
"(",
"&",
"m",
".",
"pendingWriters",
",",
"1",
")",
"\n",
"m",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"atomic",
".",
"AddInt64",
"(",
"&",
"m",
".",
... | // Lock the mutex for writing | [
"Lock",
"the",
"mutex",
"for",
"writing"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/debug/mutex.go#L67-L82 |
2,823 | m3db/m3x | debug/mutex.go | Unlock | func (m *RWMutex) Unlock() {
m.mutex.Unlock()
atomic.AddInt64(&m.writers, -1)
} | go | func (m *RWMutex) Unlock() {
m.mutex.Unlock()
atomic.AddInt64(&m.writers, -1)
} | [
"func",
"(",
"m",
"*",
"RWMutex",
")",
"Unlock",
"(",
")",
"{",
"m",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"atomic",
".",
"AddInt64",
"(",
"&",
"m",
".",
"writers",
",",
"-",
"1",
")",
"\n",
"}"
] | // Unlock the mutex for writing | [
"Unlock",
"the",
"mutex",
"for",
"writing"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/debug/mutex.go#L85-L88 |
2,824 | m3db/m3x | debug/mutex.go | RLock | func (m *RWMutex) RLock() {
atomic.AddInt64(&m.readers, 1)
m.mutex.RLock()
} | go | func (m *RWMutex) RLock() {
atomic.AddInt64(&m.readers, 1)
m.mutex.RLock()
} | [
"func",
"(",
"m",
"*",
"RWMutex",
")",
"RLock",
"(",
")",
"{",
"atomic",
".",
"AddInt64",
"(",
"&",
"m",
".",
"readers",
",",
"1",
")",
"\n",
"m",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"}"
] | // RLock the mutex for reading | [
"RLock",
"the",
"mutex",
"for",
"reading"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/debug/mutex.go#L91-L94 |
2,825 | m3db/m3x | debug/mutex.go | RUnlock | func (m *RWMutex) RUnlock() {
m.mutex.RUnlock()
atomic.AddInt64(&m.readers, -1)
} | go | func (m *RWMutex) RUnlock() {
m.mutex.RUnlock()
atomic.AddInt64(&m.readers, -1)
} | [
"func",
"(",
"m",
"*",
"RWMutex",
")",
"RUnlock",
"(",
")",
"{",
"m",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n",
"atomic",
".",
"AddInt64",
"(",
"&",
"m",
".",
"readers",
",",
"-",
"1",
")",
"\n",
"}"
] | // RUnlock the mutex for reading | [
"RUnlock",
"the",
"mutex",
"for",
"reading"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/debug/mutex.go#L97-L100 |
2,826 | m3db/m3x | debug/mutex.go | Report | func (m *RWMutex) Report() {
writers := atomic.LoadInt64(&m.writers)
str := fmt.Sprintf(
"writers %d (pending %d) readers %d",
writers,
atomic.LoadInt64(&m.pendingWriters),
atomic.LoadInt64(&m.readers),
)
if writers > 0 {
m.stateMutex.RLock()
str += fmt.Sprintf(", stack: %s", string(m.lastLockStack))
m.stateMutex.RUnlock()
}
m.println(str)
} | go | func (m *RWMutex) Report() {
writers := atomic.LoadInt64(&m.writers)
str := fmt.Sprintf(
"writers %d (pending %d) readers %d",
writers,
atomic.LoadInt64(&m.pendingWriters),
atomic.LoadInt64(&m.readers),
)
if writers > 0 {
m.stateMutex.RLock()
str += fmt.Sprintf(", stack: %s", string(m.lastLockStack))
m.stateMutex.RUnlock()
}
m.println(str)
} | [
"func",
"(",
"m",
"*",
"RWMutex",
")",
"Report",
"(",
")",
"{",
"writers",
":=",
"atomic",
".",
"LoadInt64",
"(",
"&",
"m",
".",
"writers",
")",
"\n",
"str",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"writers",
",",
"atomic",
".",
"LoadI... | // Report reports the state of the RWMutex | [
"Report",
"reports",
"the",
"state",
"of",
"the",
"RWMutex"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/debug/mutex.go#L109-L123 |
2,827 | m3db/m3x | debug/mutex.go | ReportEvery | func (m *RWMutex) ReportEvery(interval time.Duration) close.SimpleCloser {
ticker := time.NewTicker(interval)
go func() {
for range ticker.C {
m.Report()
}
}()
return &tickerCloser{Ticker: ticker}
} | go | func (m *RWMutex) ReportEvery(interval time.Duration) close.SimpleCloser {
ticker := time.NewTicker(interval)
go func() {
for range ticker.C {
m.Report()
}
}()
return &tickerCloser{Ticker: ticker}
} | [
"func",
"(",
"m",
"*",
"RWMutex",
")",
"ReportEvery",
"(",
"interval",
"time",
".",
"Duration",
")",
"close",
".",
"SimpleCloser",
"{",
"ticker",
":=",
"time",
".",
"NewTicker",
"(",
"interval",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"for",
"range",
... | // ReportEvery will report the state of the RWMutex at a regular interval | [
"ReportEvery",
"will",
"report",
"the",
"state",
"of",
"the",
"RWMutex",
"at",
"a",
"regular",
"interval"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/debug/mutex.go#L126-L134 |
2,828 | m3db/m3x | instrument/process.go | NewProcessReporter | func NewProcessReporter(
scope tally.Scope,
reportInterval time.Duration,
) Reporter {
r := new(processReporter)
r.init(reportInterval, r.metrics.report)
processScope := scope.SubScope("process")
r.metrics.NumFDs = processScope.Gauge("num-fds")
r.metrics.NumFDErrors = processScope.Counter("num-fd-errors")
r.metrics.pid = os.Getpid()
return r
} | go | func NewProcessReporter(
scope tally.Scope,
reportInterval time.Duration,
) Reporter {
r := new(processReporter)
r.init(reportInterval, r.metrics.report)
processScope := scope.SubScope("process")
r.metrics.NumFDs = processScope.Gauge("num-fds")
r.metrics.NumFDErrors = processScope.Counter("num-fd-errors")
r.metrics.pid = os.Getpid()
return r
} | [
"func",
"NewProcessReporter",
"(",
"scope",
"tally",
".",
"Scope",
",",
"reportInterval",
"time",
".",
"Duration",
",",
")",
"Reporter",
"{",
"r",
":=",
"new",
"(",
"processReporter",
")",
"\n",
"r",
".",
"init",
"(",
"reportInterval",
",",
"r",
".",
"me... | // NewProcessReporter returns a new reporter that reports process
// metrics, currently just the process file descriptor count. | [
"NewProcessReporter",
"returns",
"a",
"new",
"reporter",
"that",
"reports",
"process",
"metrics",
"currently",
"just",
"the",
"process",
"file",
"descriptor",
"count",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/instrument/process.go#L55-L68 |
2,829 | m3db/m3x | sync/options.go | NewPooledWorkerPoolOptions | func NewPooledWorkerPoolOptions() PooledWorkerPoolOptions {
return &pooledWorkerPoolOptions{
growOnDemand: defaultGrowOnDemand,
numShards: defaultNumShards,
killWorkerProbability: defaultKillWorkerProbability,
nowFn: defaultNowFn,
iOpts: instrument.NewOptions(),
}
} | go | func NewPooledWorkerPoolOptions() PooledWorkerPoolOptions {
return &pooledWorkerPoolOptions{
growOnDemand: defaultGrowOnDemand,
numShards: defaultNumShards,
killWorkerProbability: defaultKillWorkerProbability,
nowFn: defaultNowFn,
iOpts: instrument.NewOptions(),
}
} | [
"func",
"NewPooledWorkerPoolOptions",
"(",
")",
"PooledWorkerPoolOptions",
"{",
"return",
"&",
"pooledWorkerPoolOptions",
"{",
"growOnDemand",
":",
"defaultGrowOnDemand",
",",
"numShards",
":",
"defaultNumShards",
",",
"killWorkerProbability",
":",
"defaultKillWorkerProbabili... | // NewPooledWorkerPoolOptions returns a new PooledWorkerPoolOptions with default options | [
"NewPooledWorkerPoolOptions",
"returns",
"a",
"new",
"PooledWorkerPoolOptions",
"with",
"default",
"options"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/sync/options.go#L44-L52 |
2,830 | m3db/m3x | checked/debug.go | DumpLeaks | func DumpLeaks() []string {
var r []string
leaks.RLock()
for k, v := range leaks.m {
r = append(r, fmt.Sprintf("leaked %d bytes, origin:\n%s", v, k))
}
leaks.RUnlock()
return r
} | go | func DumpLeaks() []string {
var r []string
leaks.RLock()
for k, v := range leaks.m {
r = append(r, fmt.Sprintf("leaked %d bytes, origin:\n%s", v, k))
}
leaks.RUnlock()
return r
} | [
"func",
"DumpLeaks",
"(",
")",
"[",
"]",
"string",
"{",
"var",
"r",
"[",
"]",
"string",
"\n\n",
"leaks",
".",
"RLock",
"(",
")",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"leaks",
".",
"m",
"{",
"r",
"=",
"append",
"(",
"r",
",",
"fmt",
".... | // DumpLeaks returns all detected leaks so far. | [
"DumpLeaks",
"returns",
"all",
"detected",
"leaks",
"so",
"far",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/debug.go#L120-L132 |
2,831 | m3db/m3x | pool/checked_object.go | NewCheckedObjectPool | func NewCheckedObjectPool(opts ObjectPoolOptions) CheckedObjectPool {
if opts == nil {
opts = NewObjectPoolOptions()
}
return &checkedObjectPool{
pool: NewObjectPool(opts),
finalizerPool: NewObjectPool(opts.SetInstrumentOptions(opts.InstrumentOptions().
SetMetricsScope(opts.InstrumentOptions().
MetricsScope().
SubScope("finalizer-pool")))),
}
} | go | func NewCheckedObjectPool(opts ObjectPoolOptions) CheckedObjectPool {
if opts == nil {
opts = NewObjectPoolOptions()
}
return &checkedObjectPool{
pool: NewObjectPool(opts),
finalizerPool: NewObjectPool(opts.SetInstrumentOptions(opts.InstrumentOptions().
SetMetricsScope(opts.InstrumentOptions().
MetricsScope().
SubScope("finalizer-pool")))),
}
} | [
"func",
"NewCheckedObjectPool",
"(",
"opts",
"ObjectPoolOptions",
")",
"CheckedObjectPool",
"{",
"if",
"opts",
"==",
"nil",
"{",
"opts",
"=",
"NewObjectPoolOptions",
"(",
")",
"\n",
"}",
"\n",
"return",
"&",
"checkedObjectPool",
"{",
"pool",
":",
"NewObjectPool"... | // NewCheckedObjectPool creates a new checked pool | [
"NewCheckedObjectPool",
"creates",
"a",
"new",
"checked",
"pool"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/pool/checked_object.go#L46-L57 |
2,832 | m3db/m3x | unsafe/bytes.go | WithStringAndArg | func WithStringAndArg(b []byte, arg interface{}, fn StringAndArgFn) {
fn(String(b), arg)
} | go | func WithStringAndArg(b []byte, arg interface{}, fn StringAndArgFn) {
fn(String(b), arg)
} | [
"func",
"WithStringAndArg",
"(",
"b",
"[",
"]",
"byte",
",",
"arg",
"interface",
"{",
"}",
",",
"fn",
"StringAndArgFn",
")",
"{",
"fn",
"(",
"String",
"(",
"b",
")",
",",
"arg",
")",
"\n",
"}"
] | // WithStringAndArg converts a byte slice to a string with zero heap memory
// allocations, and calls a function to process the string with one argument.
// It is the caller's responsibility to make sure it holds no reference to the
// string after the function returns. | [
"WithStringAndArg",
"converts",
"a",
"byte",
"slice",
"to",
"a",
"string",
"with",
"zero",
"heap",
"memory",
"allocations",
"and",
"calls",
"a",
"function",
"to",
"process",
"the",
"string",
"with",
"one",
"argument",
".",
"It",
"is",
"the",
"caller",
"s",
... | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/unsafe/bytes.go#L50-L52 |
2,833 | m3db/m3x | unsafe/bytes.go | String | func String(b []byte) string {
var s string
if len(b) == 0 {
return s
}
// NB(r): We need to declare a real string so internally the compiler
// knows to use an unsafe.Pointer to keep track of the underlying memory so that
// once the strings's array pointer is updated with the pointer to the byte slices's
// underlying bytes, the compiler won't prematurely GC the memory when the byte slice
// goes out of scope.
stringHeader := (*reflect.StringHeader)(unsafe.Pointer(&s))
// NB(r): This makes sure that even if GC relocates the byte slices's underlying
// memory after this assignment, the corresponding unsafe.Pointer in the internal
// string struct will be updated accordingly to reflect the memory relocation.
stringHeader.Data = (*reflect.SliceHeader)(unsafe.Pointer(&b)).Data
// NB(r): It is important that we access b after we assign the Data
// pointer of the byte slice header to the Data pointer of the string header to
// make sure the bytes don't get GC'ed before the assignment happens.
l := len(b)
stringHeader.Len = l
return s
} | go | func String(b []byte) string {
var s string
if len(b) == 0 {
return s
}
// NB(r): We need to declare a real string so internally the compiler
// knows to use an unsafe.Pointer to keep track of the underlying memory so that
// once the strings's array pointer is updated with the pointer to the byte slices's
// underlying bytes, the compiler won't prematurely GC the memory when the byte slice
// goes out of scope.
stringHeader := (*reflect.StringHeader)(unsafe.Pointer(&s))
// NB(r): This makes sure that even if GC relocates the byte slices's underlying
// memory after this assignment, the corresponding unsafe.Pointer in the internal
// string struct will be updated accordingly to reflect the memory relocation.
stringHeader.Data = (*reflect.SliceHeader)(unsafe.Pointer(&b)).Data
// NB(r): It is important that we access b after we assign the Data
// pointer of the byte slice header to the Data pointer of the string header to
// make sure the bytes don't get GC'ed before the assignment happens.
l := len(b)
stringHeader.Len = l
return s
} | [
"func",
"String",
"(",
"b",
"[",
"]",
"byte",
")",
"string",
"{",
"var",
"s",
"string",
"\n",
"if",
"len",
"(",
"b",
")",
"==",
"0",
"{",
"return",
"s",
"\n",
"}",
"\n\n",
"// NB(r): We need to declare a real string so internally the compiler",
"// knows to us... | // String returns a string backed by a byte slice, it is the caller's
// responsibility not to mutate the bytes while using the string returned. It
// is much safer to use WithString and WithStringAndArg if possible, which is
// more likely to force use of the result to just a small block of code. | [
"String",
"returns",
"a",
"string",
"backed",
"by",
"a",
"byte",
"slice",
"it",
"is",
"the",
"caller",
"s",
"responsibility",
"not",
"to",
"mutate",
"the",
"bytes",
"while",
"using",
"the",
"string",
"returned",
".",
"It",
"is",
"much",
"safer",
"to",
"u... | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/unsafe/bytes.go#L58-L83 |
2,834 | m3db/m3x | ident/bytes_id.go | Equal | func (v BytesID) Equal(value ID) bool {
return bytes.Equal(value.Bytes(), v)
} | go | func (v BytesID) Equal(value ID) bool {
return bytes.Equal(value.Bytes(), v)
} | [
"func",
"(",
"v",
"BytesID",
")",
"Equal",
"(",
"value",
"ID",
")",
"bool",
"{",
"return",
"bytes",
".",
"Equal",
"(",
"value",
".",
"Bytes",
"(",
")",
",",
"v",
")",
"\n",
"}"
] | // Equal returns whether the bytes ID is equal to a given ID. | [
"Equal",
"returns",
"whether",
"the",
"bytes",
"ID",
"is",
"equal",
"to",
"a",
"given",
"ID",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/ident/bytes_id.go#L45-L47 |
2,835 | m3db/m3x | ident/iterator.go | NewIDSliceIterator | func NewIDSliceIterator(ids []ID) Iterator {
iter := &idSliceIter{
backingSlice: ids,
currentIdx: -1,
}
return iter
} | go | func NewIDSliceIterator(ids []ID) Iterator {
iter := &idSliceIter{
backingSlice: ids,
currentIdx: -1,
}
return iter
} | [
"func",
"NewIDSliceIterator",
"(",
"ids",
"[",
"]",
"ID",
")",
"Iterator",
"{",
"iter",
":=",
"&",
"idSliceIter",
"{",
"backingSlice",
":",
"ids",
",",
"currentIdx",
":",
"-",
"1",
",",
"}",
"\n",
"return",
"iter",
"\n",
"}"
] | // NewIDSliceIterator returns a new Iterator over a slice. | [
"NewIDSliceIterator",
"returns",
"a",
"new",
"Iterator",
"over",
"a",
"slice",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/ident/iterator.go#L29-L35 |
2,836 | m3db/m3x | ident/iterator.go | NewStringIDsSliceIterator | func NewStringIDsSliceIterator(ids []string) Iterator {
iter := &stringSliceIter{
backingSlice: ids,
currentIdx: -1,
}
return iter
} | go | func NewStringIDsSliceIterator(ids []string) Iterator {
iter := &stringSliceIter{
backingSlice: ids,
currentIdx: -1,
}
return iter
} | [
"func",
"NewStringIDsSliceIterator",
"(",
"ids",
"[",
"]",
"string",
")",
"Iterator",
"{",
"iter",
":=",
"&",
"stringSliceIter",
"{",
"backingSlice",
":",
"ids",
",",
"currentIdx",
":",
"-",
"1",
",",
"}",
"\n",
"return",
"iter",
"\n",
"}"
] | // NewStringIDsSliceIterator returns a new Iterator over a slice of strings. | [
"NewStringIDsSliceIterator",
"returns",
"a",
"new",
"Iterator",
"over",
"a",
"slice",
"of",
"strings",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/ident/iterator.go#L99-L105 |
2,837 | m3db/m3x | retry/options.go | NewOptions | func NewOptions() Options {
return &options{
scope: tally.NoopScope,
initialBackoff: defaultInitialBackoff,
backoffFactor: defaultBackoffFactor,
maxBackoff: defaultMaxBackoff,
maxRetries: defaultMaxRetries,
forever: defaultForever,
jitter: defaultJitter,
rngFn: rand.Int63n,
}
} | go | func NewOptions() Options {
return &options{
scope: tally.NoopScope,
initialBackoff: defaultInitialBackoff,
backoffFactor: defaultBackoffFactor,
maxBackoff: defaultMaxBackoff,
maxRetries: defaultMaxRetries,
forever: defaultForever,
jitter: defaultJitter,
rngFn: rand.Int63n,
}
} | [
"func",
"NewOptions",
"(",
")",
"Options",
"{",
"return",
"&",
"options",
"{",
"scope",
":",
"tally",
".",
"NoopScope",
",",
"initialBackoff",
":",
"defaultInitialBackoff",
",",
"backoffFactor",
":",
"defaultBackoffFactor",
",",
"maxBackoff",
":",
"defaultMaxBacko... | // NewOptions creates new retry options. | [
"NewOptions",
"creates",
"new",
"retry",
"options",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/retry/options.go#L52-L63 |
2,838 | m3db/m3x | time/duration.go | ParseExtendedDuration | func ParseExtendedDuration(s string) (time.Duration, error) {
if len(s) == 0 {
return 0, errDurationEmpty
}
var isNegative bool
if s[0] == '-' {
isNegative = true
s = s[1:]
}
var d time.Duration
i := 0
for i < len(s) {
if !isDigit(s[i]) {
return 0, fmt.Errorf("invalid duration %s, no value specified", s)
}
// Consume [0-9]+
n := 0
for i < len(s) && isDigit(s[i]) {
n *= 10
n += int(s[i]) - int('0')
i++
}
// Consume [^0-9]+ and convert into a unit
if i == len(s) {
return 0, fmt.Errorf("invalid duration %s, no unit", s)
}
unitStart := i
for i < len(s) && !isDigit(s[i]) {
i++
}
unitText := s[unitStart:i]
unit, unitExists := durationUnits[unitText]
if !unitExists {
return 0, fmt.Errorf("invalid duration %s, invalid unit %s", s, unitText)
}
d += time.Duration(n) * unit
}
if isNegative {
d = -d
}
return d, nil
} | go | func ParseExtendedDuration(s string) (time.Duration, error) {
if len(s) == 0 {
return 0, errDurationEmpty
}
var isNegative bool
if s[0] == '-' {
isNegative = true
s = s[1:]
}
var d time.Duration
i := 0
for i < len(s) {
if !isDigit(s[i]) {
return 0, fmt.Errorf("invalid duration %s, no value specified", s)
}
// Consume [0-9]+
n := 0
for i < len(s) && isDigit(s[i]) {
n *= 10
n += int(s[i]) - int('0')
i++
}
// Consume [^0-9]+ and convert into a unit
if i == len(s) {
return 0, fmt.Errorf("invalid duration %s, no unit", s)
}
unitStart := i
for i < len(s) && !isDigit(s[i]) {
i++
}
unitText := s[unitStart:i]
unit, unitExists := durationUnits[unitText]
if !unitExists {
return 0, fmt.Errorf("invalid duration %s, invalid unit %s", s, unitText)
}
d += time.Duration(n) * unit
}
if isNegative {
d = -d
}
return d, nil
} | [
"func",
"ParseExtendedDuration",
"(",
"s",
"string",
")",
"(",
"time",
".",
"Duration",
",",
"error",
")",
"{",
"if",
"len",
"(",
"s",
")",
"==",
"0",
"{",
"return",
"0",
",",
"errDurationEmpty",
"\n",
"}",
"\n",
"var",
"isNegative",
"bool",
"\n",
"i... | // ParseExtendedDuration parses a duration, with the ability to specify time
// units in days, weeks, months, and years. | [
"ParseExtendedDuration",
"parses",
"a",
"duration",
"with",
"the",
"ability",
"to",
"specify",
"time",
"units",
"in",
"days",
"weeks",
"months",
"and",
"years",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/duration.go#L49-L99 |
2,839 | m3db/m3x | time/duration.go | ToExtendedString | func ToExtendedString(d time.Duration) string {
if d == 0 {
return d.String()
}
var (
b bytes.Buffer
dUnixNanos = d.Nanoseconds()
)
if dUnixNanos < 0 {
dUnixNanos = -dUnixNanos
b.WriteString("-")
}
for _, u := range unitsByDurationDesc {
// The unit is guaranteed to be valid so it's safe to ignore error here.
v, _ := u.Value()
valueNanos := int64(v)
if dUnixNanos < valueNanos {
continue
}
quotient := dUnixNanos / valueNanos
dUnixNanos -= quotient * valueNanos
b.WriteString(strconv.Itoa(int(quotient)))
b.WriteString(u.String())
if dUnixNanos == 0 {
break
}
}
return b.String()
} | go | func ToExtendedString(d time.Duration) string {
if d == 0 {
return d.String()
}
var (
b bytes.Buffer
dUnixNanos = d.Nanoseconds()
)
if dUnixNanos < 0 {
dUnixNanos = -dUnixNanos
b.WriteString("-")
}
for _, u := range unitsByDurationDesc {
// The unit is guaranteed to be valid so it's safe to ignore error here.
v, _ := u.Value()
valueNanos := int64(v)
if dUnixNanos < valueNanos {
continue
}
quotient := dUnixNanos / valueNanos
dUnixNanos -= quotient * valueNanos
b.WriteString(strconv.Itoa(int(quotient)))
b.WriteString(u.String())
if dUnixNanos == 0 {
break
}
}
return b.String()
} | [
"func",
"ToExtendedString",
"(",
"d",
"time",
".",
"Duration",
")",
"string",
"{",
"if",
"d",
"==",
"0",
"{",
"return",
"d",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"var",
"(",
"b",
"bytes",
".",
"Buffer",
"\n",
"dUnixNanos",
"=",
"d",
".",
"Na... | // ToExtendedString converts a duration to an extended string. | [
"ToExtendedString",
"converts",
"a",
"duration",
"to",
"an",
"extended",
"string",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/duration.go#L102-L130 |
2,840 | m3db/m3x | instrument/build.go | LogBuildInfo | func LogBuildInfo() {
log.Printf("Go Runtime version: %s\n", goVersion)
log.Printf("Build Version: %s\n", Version)
log.Printf("Build Revision: %s\n", Revision)
log.Printf("Build Branch: %s\n", Branch)
log.Printf("Build Date: %s\n", BuildDate)
log.Printf("Build TimeUnix: %s\n", BuildTimeUnix)
} | go | func LogBuildInfo() {
log.Printf("Go Runtime version: %s\n", goVersion)
log.Printf("Build Version: %s\n", Version)
log.Printf("Build Revision: %s\n", Revision)
log.Printf("Build Branch: %s\n", Branch)
log.Printf("Build Date: %s\n", BuildDate)
log.Printf("Build TimeUnix: %s\n", BuildTimeUnix)
} | [
"func",
"LogBuildInfo",
"(",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"goVersion",
")",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"Version",
")",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"Revisio... | // LogBuildInfo logs the build information to the provided logger. | [
"LogBuildInfo",
"logs",
"the",
"build",
"information",
"to",
"the",
"provided",
"logger",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/instrument/build.go#L72-L79 |
2,841 | m3db/m3x | instrument/sanitize.go | UnmarshalYAML | func (t *MetricSanitizationType) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
if err := unmarshal(&str); err != nil {
return err
}
if str == "" {
*t = defaultMetricSanitization
return nil
}
strs := make([]string, len(validMetricSanitizationTypes))
for _, valid := range validMetricSanitizationTypes {
if str == valid.String() {
*t = valid
return nil
}
strs = append(strs, "'"+valid.String()+"'")
}
return fmt.Errorf("invalid MetricSanitizationType '%s' valid types are: %s",
str, strings.Join(strs, ", "))
} | go | func (t *MetricSanitizationType) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
if err := unmarshal(&str); err != nil {
return err
}
if str == "" {
*t = defaultMetricSanitization
return nil
}
strs := make([]string, len(validMetricSanitizationTypes))
for _, valid := range validMetricSanitizationTypes {
if str == valid.String() {
*t = valid
return nil
}
strs = append(strs, "'"+valid.String()+"'")
}
return fmt.Errorf("invalid MetricSanitizationType '%s' valid types are: %s",
str, strings.Join(strs, ", "))
} | [
"func",
"(",
"t",
"*",
"MetricSanitizationType",
")",
"UnmarshalYAML",
"(",
"unmarshal",
"func",
"(",
"interface",
"{",
"}",
")",
"error",
")",
"error",
"{",
"var",
"str",
"string",
"\n",
"if",
"err",
":=",
"unmarshal",
"(",
"&",
"str",
")",
";",
"err"... | // UnmarshalYAML unmarshals a MetricSanitizationType into a valid type from string. | [
"UnmarshalYAML",
"unmarshals",
"a",
"MetricSanitizationType",
"into",
"a",
"valid",
"type",
"from",
"string",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/instrument/sanitize.go#L70-L89 |
2,842 | m3db/m3x | instrument/sanitize.go | NewOptions | func (t *MetricSanitizationType) NewOptions() *tally.SanitizeOptions {
switch *t {
case NoMetricSanitization:
return nil
case M3MetricSanitization:
return &m3.DefaultSanitizerOpts
case PrometheusMetricSanitization:
return &prometheus.DefaultSanitizerOpts
}
return nil
} | go | func (t *MetricSanitizationType) NewOptions() *tally.SanitizeOptions {
switch *t {
case NoMetricSanitization:
return nil
case M3MetricSanitization:
return &m3.DefaultSanitizerOpts
case PrometheusMetricSanitization:
return &prometheus.DefaultSanitizerOpts
}
return nil
} | [
"func",
"(",
"t",
"*",
"MetricSanitizationType",
")",
"NewOptions",
"(",
")",
"*",
"tally",
".",
"SanitizeOptions",
"{",
"switch",
"*",
"t",
"{",
"case",
"NoMetricSanitization",
":",
"return",
"nil",
"\n",
"case",
"M3MetricSanitization",
":",
"return",
"&",
... | // NewOptions returns a new set of sanitization options for the sanitization type. | [
"NewOptions",
"returns",
"a",
"new",
"set",
"of",
"sanitization",
"options",
"for",
"the",
"sanitization",
"type",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/instrument/sanitize.go#L92-L102 |
2,843 | m3db/m3x | ident/identifier_pool.go | NewPool | func NewPool(
bytesPool pool.CheckedBytesPool,
opts PoolOptions,
) Pool {
opts = opts.defaultsIfNotSet()
p := &simplePool{
bytesPool: bytesPool,
pool: pool.NewObjectPool(opts.IDPoolOptions),
tagArrayPool: newTagArrayPool(tagArrayPoolOpts{
Options: opts.TagsPoolOptions,
Capacity: opts.TagsCapacity,
MaxCapacity: opts.TagsMaxCapacity,
}),
itersPool: pool.NewObjectPool(opts.TagsIteratorPoolOptions),
}
p.pool.Init(func() interface{} {
return &id{pool: p}
})
p.tagArrayPool.Init()
p.itersPool.Init(func() interface{} {
return newTagSliceIter(Tags{}, p)
})
return p
} | go | func NewPool(
bytesPool pool.CheckedBytesPool,
opts PoolOptions,
) Pool {
opts = opts.defaultsIfNotSet()
p := &simplePool{
bytesPool: bytesPool,
pool: pool.NewObjectPool(opts.IDPoolOptions),
tagArrayPool: newTagArrayPool(tagArrayPoolOpts{
Options: opts.TagsPoolOptions,
Capacity: opts.TagsCapacity,
MaxCapacity: opts.TagsMaxCapacity,
}),
itersPool: pool.NewObjectPool(opts.TagsIteratorPoolOptions),
}
p.pool.Init(func() interface{} {
return &id{pool: p}
})
p.tagArrayPool.Init()
p.itersPool.Init(func() interface{} {
return newTagSliceIter(Tags{}, p)
})
return p
} | [
"func",
"NewPool",
"(",
"bytesPool",
"pool",
".",
"CheckedBytesPool",
",",
"opts",
"PoolOptions",
",",
")",
"Pool",
"{",
"opts",
"=",
"opts",
".",
"defaultsIfNotSet",
"(",
")",
"\n\n",
"p",
":=",
"&",
"simplePool",
"{",
"bytesPool",
":",
"bytesPool",
",",
... | // NewPool constructs a new simple Pool. | [
"NewPool",
"constructs",
"a",
"new",
"simple",
"Pool",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/ident/identifier_pool.go#L63-L88 |
2,844 | m3db/m3x | server/config.go | NewOptions | func (c Configuration) NewOptions(iOpts instrument.Options) Options {
opts := NewOptions().
SetRetryOptions(c.Retry.NewOptions(iOpts.MetricsScope())).
SetInstrumentOptions(iOpts)
if c.KeepAliveEnabled != nil {
opts = opts.SetTCPConnectionKeepAlive(*c.KeepAliveEnabled)
}
if c.KeepAlivePeriod != nil {
opts = opts.SetTCPConnectionKeepAlivePeriod(*c.KeepAlivePeriod)
}
return opts
} | go | func (c Configuration) NewOptions(iOpts instrument.Options) Options {
opts := NewOptions().
SetRetryOptions(c.Retry.NewOptions(iOpts.MetricsScope())).
SetInstrumentOptions(iOpts)
if c.KeepAliveEnabled != nil {
opts = opts.SetTCPConnectionKeepAlive(*c.KeepAliveEnabled)
}
if c.KeepAlivePeriod != nil {
opts = opts.SetTCPConnectionKeepAlivePeriod(*c.KeepAlivePeriod)
}
return opts
} | [
"func",
"(",
"c",
"Configuration",
")",
"NewOptions",
"(",
"iOpts",
"instrument",
".",
"Options",
")",
"Options",
"{",
"opts",
":=",
"NewOptions",
"(",
")",
".",
"SetRetryOptions",
"(",
"c",
".",
"Retry",
".",
"NewOptions",
"(",
"iOpts",
".",
"MetricsScope... | // NewOptions creates server options. | [
"NewOptions",
"creates",
"server",
"options",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/server/config.go#L46-L57 |
2,845 | m3db/m3x | ident/tag_iterator.go | MustNewTagStringsIterator | func MustNewTagStringsIterator(inputs ...string) TagIterator {
iter, err := NewTagStringsIterator(inputs...)
if err != nil {
panic(err.Error())
}
return iter
} | go | func MustNewTagStringsIterator(inputs ...string) TagIterator {
iter, err := NewTagStringsIterator(inputs...)
if err != nil {
panic(err.Error())
}
return iter
} | [
"func",
"MustNewTagStringsIterator",
"(",
"inputs",
"...",
"string",
")",
"TagIterator",
"{",
"iter",
",",
"err",
":=",
"NewTagStringsIterator",
"(",
"inputs",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
".",
"Error",
"(",
")",
... | // MustNewTagStringsIterator returns a TagIterator over a slice of strings,
// panic'ing if it encounters an error. | [
"MustNewTagStringsIterator",
"returns",
"a",
"TagIterator",
"over",
"a",
"slice",
"of",
"strings",
"panic",
"ing",
"if",
"it",
"encounters",
"an",
"error",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/ident/tag_iterator.go#L33-L39 |
2,846 | m3db/m3x | ident/tag_iterator.go | NewTagStringsIterator | func NewTagStringsIterator(inputs ...string) (TagIterator, error) {
if len(inputs)%2 != 0 {
return nil, errInvalidNumberInputsToIteratorMatcher
}
tags := make([]Tag, 0, len(inputs)/2)
for i := 0; i < len(inputs); i += 2 {
tags = append(tags, StringTag(inputs[i], inputs[i+1]))
}
return NewTagsIterator(NewTags(tags...)), nil
} | go | func NewTagStringsIterator(inputs ...string) (TagIterator, error) {
if len(inputs)%2 != 0 {
return nil, errInvalidNumberInputsToIteratorMatcher
}
tags := make([]Tag, 0, len(inputs)/2)
for i := 0; i < len(inputs); i += 2 {
tags = append(tags, StringTag(inputs[i], inputs[i+1]))
}
return NewTagsIterator(NewTags(tags...)), nil
} | [
"func",
"NewTagStringsIterator",
"(",
"inputs",
"...",
"string",
")",
"(",
"TagIterator",
",",
"error",
")",
"{",
"if",
"len",
"(",
"inputs",
")",
"%",
"2",
"!=",
"0",
"{",
"return",
"nil",
",",
"errInvalidNumberInputsToIteratorMatcher",
"\n",
"}",
"\n",
"... | // NewTagStringsIterator returns a TagIterator over a slice of strings. | [
"NewTagStringsIterator",
"returns",
"a",
"TagIterator",
"over",
"a",
"slice",
"of",
"strings",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/ident/tag_iterator.go#L42-L51 |
2,847 | m3db/m3x | pool/checked_bytes.go | NewCheckedBytesPool | func NewCheckedBytesPool(
sizes []Bucket,
opts ObjectPoolOptions,
newBackingBytesPool NewBytesPoolFn,
) CheckedBytesPool {
return &checkedBytesPool{
bytesPool: newBackingBytesPool(sizes),
pool: NewBucketizedObjectPool(sizes, opts),
}
} | go | func NewCheckedBytesPool(
sizes []Bucket,
opts ObjectPoolOptions,
newBackingBytesPool NewBytesPoolFn,
) CheckedBytesPool {
return &checkedBytesPool{
bytesPool: newBackingBytesPool(sizes),
pool: NewBucketizedObjectPool(sizes, opts),
}
} | [
"func",
"NewCheckedBytesPool",
"(",
"sizes",
"[",
"]",
"Bucket",
",",
"opts",
"ObjectPoolOptions",
",",
"newBackingBytesPool",
"NewBytesPoolFn",
",",
")",
"CheckedBytesPool",
"{",
"return",
"&",
"checkedBytesPool",
"{",
"bytesPool",
":",
"newBackingBytesPool",
"(",
... | // NewCheckedBytesPool creates a new checked bytes pool | [
"NewCheckedBytesPool",
"creates",
"a",
"new",
"checked",
"bytes",
"pool"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/pool/checked_bytes.go#L34-L43 |
2,848 | m3db/m3x | pool/checked_bytes.go | AppendByteChecked | func AppendByteChecked(
bytes checked.Bytes,
b byte,
pool CheckedBytesPool,
) (
result checked.Bytes,
swapped bool,
) {
orig := bytes
if bytes.Len() == bytes.Cap() {
newBytes := pool.Get(bytes.Cap() * 2)
// Inc the ref to read/write to it
newBytes.IncRef()
newBytes.Resize(bytes.Len())
copy(newBytes.Bytes(), bytes.Bytes())
bytes = newBytes
}
bytes.Append(b)
result = bytes
swapped = orig != bytes
if swapped {
// No longer holding reference from the inc
result.DecRef()
}
return
} | go | func AppendByteChecked(
bytes checked.Bytes,
b byte,
pool CheckedBytesPool,
) (
result checked.Bytes,
swapped bool,
) {
orig := bytes
if bytes.Len() == bytes.Cap() {
newBytes := pool.Get(bytes.Cap() * 2)
// Inc the ref to read/write to it
newBytes.IncRef()
newBytes.Resize(bytes.Len())
copy(newBytes.Bytes(), bytes.Bytes())
bytes = newBytes
}
bytes.Append(b)
result = bytes
swapped = orig != bytes
if swapped {
// No longer holding reference from the inc
result.DecRef()
}
return
} | [
"func",
"AppendByteChecked",
"(",
"bytes",
"checked",
".",
"Bytes",
",",
"b",
"byte",
",",
"pool",
"CheckedBytesPool",
",",
")",
"(",
"result",
"checked",
".",
"Bytes",
",",
"swapped",
"bool",
",",
")",
"{",
"orig",
":=",
"bytes",
"\n\n",
"if",
"bytes",
... | // AppendByteChecked appends a byte to a byte slice getting a new slice from
// the CheckedBytesPool if the slice is at capacity | [
"AppendByteChecked",
"appends",
"a",
"byte",
"to",
"a",
"byte",
"slice",
"getting",
"a",
"new",
"slice",
"from",
"the",
"CheckedBytesPool",
"if",
"the",
"slice",
"is",
"at",
"capacity"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/pool/checked_bytes.go#L74-L107 |
2,849 | m3db/m3x | instrument/options.go | NewOptions | func NewOptions() Options {
logger := log.NewLevelLogger(log.SimpleLogger, log.LevelInfo)
return &options{
logger: logger,
zap: zap.L(),
scope: tally.NoopScope,
samplingRate: defaultSamplingRate,
reportInterval: defaultReportingInterval,
}
} | go | func NewOptions() Options {
logger := log.NewLevelLogger(log.SimpleLogger, log.LevelInfo)
return &options{
logger: logger,
zap: zap.L(),
scope: tally.NoopScope,
samplingRate: defaultSamplingRate,
reportInterval: defaultReportingInterval,
}
} | [
"func",
"NewOptions",
"(",
")",
"Options",
"{",
"logger",
":=",
"log",
".",
"NewLevelLogger",
"(",
"log",
".",
"SimpleLogger",
",",
"log",
".",
"LevelInfo",
")",
"\n",
"return",
"&",
"options",
"{",
"logger",
":",
"logger",
",",
"zap",
":",
"zap",
".",... | // NewOptions creates new instrument options. | [
"NewOptions",
"creates",
"new",
"instrument",
"options",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/instrument/options.go#L48-L57 |
2,850 | m3db/m3x | time/unit.go | Value | func (tu Unit) Value() (time.Duration, error) {
if d, found := unitsToDuration[tu]; found {
return d, nil
}
return 0, errUnrecognizedTimeUnit
} | go | func (tu Unit) Value() (time.Duration, error) {
if d, found := unitsToDuration[tu]; found {
return d, nil
}
return 0, errUnrecognizedTimeUnit
} | [
"func",
"(",
"tu",
"Unit",
")",
"Value",
"(",
")",
"(",
"time",
".",
"Duration",
",",
"error",
")",
"{",
"if",
"d",
",",
"found",
":=",
"unitsToDuration",
"[",
"tu",
"]",
";",
"found",
"{",
"return",
"d",
",",
"nil",
"\n",
"}",
"\n",
"return",
... | // Value is the time duration of the time unit. | [
"Value",
"is",
"the",
"time",
"duration",
"of",
"the",
"time",
"unit",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/unit.go#L55-L60 |
2,851 | m3db/m3x | time/unit.go | Count | func (tu Unit) Count(d time.Duration) (int, error) {
if d < 0 {
return 0, errNegativeDuraton
}
if dur, found := unitsToDuration[tu]; found {
return int(d / dur), nil
}
// Invalid unit.
return 0, errUnrecognizedTimeUnit
} | go | func (tu Unit) Count(d time.Duration) (int, error) {
if d < 0 {
return 0, errNegativeDuraton
}
if dur, found := unitsToDuration[tu]; found {
return int(d / dur), nil
}
// Invalid unit.
return 0, errUnrecognizedTimeUnit
} | [
"func",
"(",
"tu",
"Unit",
")",
"Count",
"(",
"d",
"time",
".",
"Duration",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"d",
"<",
"0",
"{",
"return",
"0",
",",
"errNegativeDuraton",
"\n",
"}",
"\n\n",
"if",
"dur",
",",
"found",
":=",
"unitsToD... | // Count returns the number of units contained within the duration. | [
"Count",
"returns",
"the",
"number",
"of",
"units",
"contained",
"within",
"the",
"duration",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/unit.go#L63-L74 |
2,852 | m3db/m3x | time/unit.go | MustCount | func (tu Unit) MustCount(d time.Duration) int {
c, err := tu.Count(d)
if err != nil {
panic(err)
}
return c
} | go | func (tu Unit) MustCount(d time.Duration) int {
c, err := tu.Count(d)
if err != nil {
panic(err)
}
return c
} | [
"func",
"(",
"tu",
"Unit",
")",
"MustCount",
"(",
"d",
"time",
".",
"Duration",
")",
"int",
"{",
"c",
",",
"err",
":=",
"tu",
".",
"Count",
"(",
"d",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"retu... | // MustCount is like Count but panics if d is negative or if tu is not
// a valid Unit. | [
"MustCount",
"is",
"like",
"Count",
"but",
"panics",
"if",
"d",
"is",
"negative",
"or",
"if",
"tu",
"is",
"not",
"a",
"valid",
"Unit",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/unit.go#L78-L85 |
2,853 | m3db/m3x | time/unit.go | String | func (tu Unit) String() string {
if s, found := unitStrings[tu]; found {
return s
}
return "unknown"
} | go | func (tu Unit) String() string {
if s, found := unitStrings[tu]; found {
return s
}
return "unknown"
} | [
"func",
"(",
"tu",
"Unit",
")",
"String",
"(",
")",
"string",
"{",
"if",
"s",
",",
"found",
":=",
"unitStrings",
"[",
"tu",
"]",
";",
"found",
"{",
"return",
"s",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // String returns the string representation for the time unit | [
"String",
"returns",
"the",
"string",
"representation",
"for",
"the",
"time",
"unit"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/unit.go#L94-L100 |
2,854 | m3db/m3x | time/unit.go | UnitFromDuration | func UnitFromDuration(d time.Duration) (Unit, error) {
if unit, found := durationsToUnit[d]; found {
return unit, nil
}
return None, errConvertDurationToUnit
} | go | func UnitFromDuration(d time.Duration) (Unit, error) {
if unit, found := durationsToUnit[d]; found {
return unit, nil
}
return None, errConvertDurationToUnit
} | [
"func",
"UnitFromDuration",
"(",
"d",
"time",
".",
"Duration",
")",
"(",
"Unit",
",",
"error",
")",
"{",
"if",
"unit",
",",
"found",
":=",
"durationsToUnit",
"[",
"d",
"]",
";",
"found",
"{",
"return",
"unit",
",",
"nil",
"\n",
"}",
"\n\n",
"return",... | // UnitFromDuration creates a time unit from a time duration. | [
"UnitFromDuration",
"creates",
"a",
"time",
"unit",
"from",
"a",
"time",
"duration",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/unit.go#L103-L109 |
2,855 | m3db/m3x | time/unit.go | DurationFromUnit | func DurationFromUnit(u Unit) (time.Duration, error) {
if duration, found := unitsToDuration[u]; found {
return duration, nil
}
return 0, errConvertUnitToDuration
} | go | func DurationFromUnit(u Unit) (time.Duration, error) {
if duration, found := unitsToDuration[u]; found {
return duration, nil
}
return 0, errConvertUnitToDuration
} | [
"func",
"DurationFromUnit",
"(",
"u",
"Unit",
")",
"(",
"time",
".",
"Duration",
",",
"error",
")",
"{",
"if",
"duration",
",",
"found",
":=",
"unitsToDuration",
"[",
"u",
"]",
";",
"found",
"{",
"return",
"duration",
",",
"nil",
"\n",
"}",
"\n\n",
"... | // DurationFromUnit creates a time duration from a time unit. | [
"DurationFromUnit",
"creates",
"a",
"time",
"duration",
"from",
"a",
"time",
"unit",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/unit.go#L112-L118 |
2,856 | m3db/m3x | time/unit.go | MaxUnitForDuration | func MaxUnitForDuration(d time.Duration) (int64, Unit) {
var (
currMultiple int64
currUnit = Nanosecond
dUnixNanos = d.Nanoseconds()
isNegative bool
)
if dUnixNanos < 0 {
dUnixNanos = -dUnixNanos
isNegative = true
}
for _, u := range unitsByDurationDesc {
// The unit is guaranteed to be valid so it's safe to ignore error here.
duration, _ := u.Value()
if dUnixNanos < duration.Nanoseconds() {
continue
}
durationUnixNanos := int64(duration)
quotient := dUnixNanos / durationUnixNanos
remainder := dUnixNanos - quotient*durationUnixNanos
if remainder != 0 {
continue
}
currMultiple = quotient
currUnit = u
break
}
if isNegative {
currMultiple = -currMultiple
}
return currMultiple, currUnit
} | go | func MaxUnitForDuration(d time.Duration) (int64, Unit) {
var (
currMultiple int64
currUnit = Nanosecond
dUnixNanos = d.Nanoseconds()
isNegative bool
)
if dUnixNanos < 0 {
dUnixNanos = -dUnixNanos
isNegative = true
}
for _, u := range unitsByDurationDesc {
// The unit is guaranteed to be valid so it's safe to ignore error here.
duration, _ := u.Value()
if dUnixNanos < duration.Nanoseconds() {
continue
}
durationUnixNanos := int64(duration)
quotient := dUnixNanos / durationUnixNanos
remainder := dUnixNanos - quotient*durationUnixNanos
if remainder != 0 {
continue
}
currMultiple = quotient
currUnit = u
break
}
if isNegative {
currMultiple = -currMultiple
}
return currMultiple, currUnit
} | [
"func",
"MaxUnitForDuration",
"(",
"d",
"time",
".",
"Duration",
")",
"(",
"int64",
",",
"Unit",
")",
"{",
"var",
"(",
"currMultiple",
"int64",
"\n",
"currUnit",
"=",
"Nanosecond",
"\n",
"dUnixNanos",
"=",
"d",
".",
"Nanoseconds",
"(",
")",
"\n",
"isNega... | // MaxUnitForDuration determines the maximum unit for which
// the input duration is a multiple of. | [
"MaxUnitForDuration",
"determines",
"the",
"maximum",
"unit",
"for",
"which",
"the",
"input",
"duration",
"is",
"a",
"multiple",
"of",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/unit.go#L122-L153 |
2,857 | m3db/m3x | errors/errors.go | FirstError | func FirstError(errs ...error) error {
for i := range errs {
if errs[i] != nil {
return errs[i]
}
}
return nil
} | go | func FirstError(errs ...error) error {
for i := range errs {
if errs[i] != nil {
return errs[i]
}
}
return nil
} | [
"func",
"FirstError",
"(",
"errs",
"...",
"error",
")",
"error",
"{",
"for",
"i",
":=",
"range",
"errs",
"{",
"if",
"errs",
"[",
"i",
"]",
"!=",
"nil",
"{",
"return",
"errs",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"... | // FirstError returns the first non nil error. | [
"FirstError",
"returns",
"the",
"first",
"non",
"nil",
"error",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/errors/errors.go#L31-L38 |
2,858 | m3db/m3x | errors/errors.go | InnerError | func InnerError(err error) error {
contained, ok := err.(ContainedError)
if !ok {
return nil
}
return contained.InnerError()
} | go | func InnerError(err error) error {
contained, ok := err.(ContainedError)
if !ok {
return nil
}
return contained.InnerError()
} | [
"func",
"InnerError",
"(",
"err",
"error",
")",
"error",
"{",
"contained",
",",
"ok",
":=",
"err",
".",
"(",
"ContainedError",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"contained",
".",
"InnerError",
"(",
")",
"\n"... | // InnerError returns the packaged inner error if this is an error that
// contains another. | [
"InnerError",
"returns",
"the",
"packaged",
"inner",
"error",
"if",
"this",
"is",
"an",
"error",
"that",
"contains",
"another",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/errors/errors.go#L59-L65 |
2,859 | m3db/m3x | errors/errors.go | Wrap | func Wrap(err error, msg string) error {
renamed := errors.New(msg + ": " + err.Error())
return NewRenamedError(err, renamed)
} | go | func Wrap(err error, msg string) error {
renamed := errors.New(msg + ": " + err.Error())
return NewRenamedError(err, renamed)
} | [
"func",
"Wrap",
"(",
"err",
"error",
",",
"msg",
"string",
")",
"error",
"{",
"renamed",
":=",
"errors",
".",
"New",
"(",
"msg",
"+",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"NewRenamedError",
"(",
"err",
",",
"renamed"... | // Wrap wraps an error with a message but preserves the type of the error. | [
"Wrap",
"wraps",
"an",
"error",
"with",
"a",
"message",
"but",
"preserves",
"the",
"type",
"of",
"the",
"error",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/errors/errors.go#L91-L94 |
2,860 | m3db/m3x | errors/errors.go | Wrapf | func Wrapf(err error, format string, args ...interface{}) error {
msg := fmt.Sprintf(format, args...)
return Wrap(err, msg)
} | go | func Wrapf(err error, format string, args ...interface{}) error {
msg := fmt.Sprintf(format, args...)
return Wrap(err, msg)
} | [
"func",
"Wrapf",
"(",
"err",
"error",
",",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"args",
"...",
")",
"\n",
"return",
"Wrap",
"(",
"err",
",",
"msg",... | // Wrapf formats according to a format specifier and uses that string to
// wrap an error while still preserving the type of the error. | [
"Wrapf",
"formats",
"according",
"to",
"a",
"format",
"specifier",
"and",
"uses",
"that",
"string",
"to",
"wrap",
"an",
"error",
"while",
"still",
"preserving",
"the",
"type",
"of",
"the",
"error",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/errors/errors.go#L98-L101 |
2,861 | m3db/m3x | errors/errors.go | GetInnerInvalidParamsError | func GetInnerInvalidParamsError(err error) error {
for err != nil {
if _, ok := err.(invalidParamsError); ok {
return InnerError(err)
}
err = InnerError(err)
}
return nil
} | go | func GetInnerInvalidParamsError(err error) error {
for err != nil {
if _, ok := err.(invalidParamsError); ok {
return InnerError(err)
}
err = InnerError(err)
}
return nil
} | [
"func",
"GetInnerInvalidParamsError",
"(",
"err",
"error",
")",
"error",
"{",
"for",
"err",
"!=",
"nil",
"{",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"invalidParamsError",
")",
";",
"ok",
"{",
"return",
"InnerError",
"(",
"err",
")",
"\n",
"}",
... | // GetInnerInvalidParamsError returns an inner invalid params error
// if contained by this error, nil otherwise. | [
"GetInnerInvalidParamsError",
"returns",
"an",
"inner",
"invalid",
"params",
"error",
"if",
"contained",
"by",
"this",
"error",
"nil",
"otherwise",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/errors/errors.go#L123-L131 |
2,862 | m3db/m3x | errors/errors.go | GetInnerRetryableError | func GetInnerRetryableError(err error) error {
for err != nil {
if _, ok := err.(retryableError); ok {
return InnerError(err)
}
err = InnerError(err)
}
return nil
} | go | func GetInnerRetryableError(err error) error {
for err != nil {
if _, ok := err.(retryableError); ok {
return InnerError(err)
}
err = InnerError(err)
}
return nil
} | [
"func",
"GetInnerRetryableError",
"(",
"err",
"error",
")",
"error",
"{",
"for",
"err",
"!=",
"nil",
"{",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"retryableError",
")",
";",
"ok",
"{",
"return",
"InnerError",
"(",
"err",
")",
"\n",
"}",
"\n",
... | // GetInnerRetryableError returns an inner retryable error
// if contained by this error, nil otherwise. | [
"GetInnerRetryableError",
"returns",
"an",
"inner",
"retryable",
"error",
"if",
"contained",
"by",
"this",
"error",
"nil",
"otherwise",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/errors/errors.go#L157-L165 |
2,863 | m3db/m3x | errors/errors.go | GetInnerNonRetryableError | func GetInnerNonRetryableError(err error) error {
for err != nil {
if _, ok := err.(nonRetryableError); ok {
return InnerError(err)
}
err = InnerError(err)
}
return nil
} | go | func GetInnerNonRetryableError(err error) error {
for err != nil {
if _, ok := err.(nonRetryableError); ok {
return InnerError(err)
}
err = InnerError(err)
}
return nil
} | [
"func",
"GetInnerNonRetryableError",
"(",
"err",
"error",
")",
"error",
"{",
"for",
"err",
"!=",
"nil",
"{",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"nonRetryableError",
")",
";",
"ok",
"{",
"return",
"InnerError",
"(",
"err",
")",
"\n",
"}",
"\... | // GetInnerNonRetryableError returns an inner non-retryable error
// if contained by this error, nil otherwise. | [
"GetInnerNonRetryableError",
"returns",
"an",
"inner",
"non",
"-",
"retryable",
"error",
"if",
"contained",
"by",
"this",
"error",
"nil",
"otherwise",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/errors/errors.go#L191-L199 |
2,864 | m3db/m3x | errors/errors.go | Add | func (e MultiError) Add(err error) MultiError {
if err == nil {
return e
}
me := e
if me.err == nil {
me.err = err
return me
}
me.errors = append(me.errors, me.err)
me.err = err
return me
} | go | func (e MultiError) Add(err error) MultiError {
if err == nil {
return e
}
me := e
if me.err == nil {
me.err = err
return me
}
me.errors = append(me.errors, me.err)
me.err = err
return me
} | [
"func",
"(",
"e",
"MultiError",
")",
"Add",
"(",
"err",
"error",
")",
"MultiError",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"e",
"\n",
"}",
"\n",
"me",
":=",
"e",
"\n",
"if",
"me",
".",
"err",
"==",
"nil",
"{",
"me",
".",
"err",
"=",
"e... | // Add adds an error returns a new MultiError object. | [
"Add",
"adds",
"an",
"error",
"returns",
"a",
"new",
"MultiError",
"object",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/errors/errors.go#L236-L248 |
2,865 | m3db/m3x | errors/errors.go | LastError | func (e MultiError) LastError() error {
if e.err == nil {
return nil
}
return e.err
} | go | func (e MultiError) LastError() error {
if e.err == nil {
return nil
}
return e.err
} | [
"func",
"(",
"e",
"MultiError",
")",
"LastError",
"(",
")",
"error",
"{",
"if",
"e",
".",
"err",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"e",
".",
"err",
"\n",
"}"
] | // LastError returns the last received error if any. | [
"LastError",
"returns",
"the",
"last",
"received",
"error",
"if",
"any",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/errors/errors.go#L259-L264 |
2,866 | m3db/m3x | errors/errors.go | NumErrors | func (e MultiError) NumErrors() int {
if e.err == nil {
return 0
}
return len(e.errors) + 1
} | go | func (e MultiError) NumErrors() int {
if e.err == nil {
return 0
}
return len(e.errors) + 1
} | [
"func",
"(",
"e",
"MultiError",
")",
"NumErrors",
"(",
")",
"int",
"{",
"if",
"e",
".",
"err",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"len",
"(",
"e",
".",
"errors",
")",
"+",
"1",
"\n",
"}"
] | // NumErrors returns the total number of errors. | [
"NumErrors",
"returns",
"the",
"total",
"number",
"of",
"errors",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/errors/errors.go#L267-L272 |
2,867 | m3db/m3x | sync/pooled_worker_pool.go | NewPooledWorkerPool | func NewPooledWorkerPool(size int, opts PooledWorkerPoolOptions) (PooledWorkerPool, error) {
if size <= 0 {
return nil, fmt.Errorf("pooled worker pool size too small: %d", size)
}
numShards := opts.NumShards()
if int64(size) < numShards {
numShards = int64(size)
}
workChs := make([]chan Work, numShards)
for i := range workChs {
workChs[i] = make(chan Work, int64(size)/numShards)
}
return &pooledWorkerPool{
numRoutinesAtomic: 0,
numRoutinesGauge: opts.InstrumentOptions().MetricsScope().Gauge("num-routines"),
growOnDemand: opts.GrowOnDemand(),
workChs: workChs,
numShards: numShards,
killWorkerProbability: opts.KillWorkerProbability(),
nowFn: opts.NowFn(),
}, nil
} | go | func NewPooledWorkerPool(size int, opts PooledWorkerPoolOptions) (PooledWorkerPool, error) {
if size <= 0 {
return nil, fmt.Errorf("pooled worker pool size too small: %d", size)
}
numShards := opts.NumShards()
if int64(size) < numShards {
numShards = int64(size)
}
workChs := make([]chan Work, numShards)
for i := range workChs {
workChs[i] = make(chan Work, int64(size)/numShards)
}
return &pooledWorkerPool{
numRoutinesAtomic: 0,
numRoutinesGauge: opts.InstrumentOptions().MetricsScope().Gauge("num-routines"),
growOnDemand: opts.GrowOnDemand(),
workChs: workChs,
numShards: numShards,
killWorkerProbability: opts.KillWorkerProbability(),
nowFn: opts.NowFn(),
}, nil
} | [
"func",
"NewPooledWorkerPool",
"(",
"size",
"int",
",",
"opts",
"PooledWorkerPoolOptions",
")",
"(",
"PooledWorkerPool",
",",
"error",
")",
"{",
"if",
"size",
"<=",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"size",
")",
... | // NewPooledWorkerPool creates a new worker pool. | [
"NewPooledWorkerPool",
"creates",
"a",
"new",
"worker",
"pool",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/sync/pooled_worker_pool.go#L49-L73 |
2,868 | m3db/m3x | context/pool.go | NewPool | func NewPool(opts Options) Pool {
p := &poolOfContexts{
ctxPool: pool.NewObjectPool(opts.ContextPoolOptions()),
finalizersPool: newFinalizeablesArrayPool(finalizeablesArrayPoolOpts{
Capacity: opts.InitPooledFinalizerCapacity(),
MaxCapacity: opts.MaxPooledFinalizerCapacity(),
Options: opts.FinalizerPoolOptions(),
}),
}
p.finalizersPool.Init()
p.ctxPool.Init(func() interface{} {
return newPooledContext(p)
})
return p
} | go | func NewPool(opts Options) Pool {
p := &poolOfContexts{
ctxPool: pool.NewObjectPool(opts.ContextPoolOptions()),
finalizersPool: newFinalizeablesArrayPool(finalizeablesArrayPoolOpts{
Capacity: opts.InitPooledFinalizerCapacity(),
MaxCapacity: opts.MaxPooledFinalizerCapacity(),
Options: opts.FinalizerPoolOptions(),
}),
}
p.finalizersPool.Init()
p.ctxPool.Init(func() interface{} {
return newPooledContext(p)
})
return p
} | [
"func",
"NewPool",
"(",
"opts",
"Options",
")",
"Pool",
"{",
"p",
":=",
"&",
"poolOfContexts",
"{",
"ctxPool",
":",
"pool",
".",
"NewObjectPool",
"(",
"opts",
".",
"ContextPoolOptions",
"(",
")",
")",
",",
"finalizersPool",
":",
"newFinalizeablesArrayPool",
... | // NewPool creates a new context pool. | [
"NewPool",
"creates",
"a",
"new",
"context",
"pool",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/context/pool.go#L33-L49 |
2,869 | m3db/m3x | instrument/config.go | NewRootScope | func (mc *MetricsConfiguration) NewRootScope() (tally.Scope, io.Closer, error) {
var reporters []tally.CachedStatsReporter
if mc.M3Reporter != nil {
r, err := mc.M3Reporter.NewReporter()
if err != nil {
return nil, nil, err
}
reporters = append(reporters, r)
}
if mc.PrometheusReporter != nil {
var opts prometheus.ConfigurationOptions
r, err := mc.PrometheusReporter.NewReporter(opts)
if err != nil {
return nil, nil, err
}
reporters = append(reporters, r)
}
if len(reporters) == 0 {
return nil, nil, errNoReporterConfigured
}
var r tally.CachedStatsReporter
if len(reporters) == 1 {
r = reporters[0]
} else {
r = multi.NewMultiCachedReporter(reporters...)
}
scope, closer := mc.NewRootScopeReporter(r)
return scope, closer, nil
} | go | func (mc *MetricsConfiguration) NewRootScope() (tally.Scope, io.Closer, error) {
var reporters []tally.CachedStatsReporter
if mc.M3Reporter != nil {
r, err := mc.M3Reporter.NewReporter()
if err != nil {
return nil, nil, err
}
reporters = append(reporters, r)
}
if mc.PrometheusReporter != nil {
var opts prometheus.ConfigurationOptions
r, err := mc.PrometheusReporter.NewReporter(opts)
if err != nil {
return nil, nil, err
}
reporters = append(reporters, r)
}
if len(reporters) == 0 {
return nil, nil, errNoReporterConfigured
}
var r tally.CachedStatsReporter
if len(reporters) == 1 {
r = reporters[0]
} else {
r = multi.NewMultiCachedReporter(reporters...)
}
scope, closer := mc.NewRootScopeReporter(r)
return scope, closer, nil
} | [
"func",
"(",
"mc",
"*",
"MetricsConfiguration",
")",
"NewRootScope",
"(",
")",
"(",
"tally",
".",
"Scope",
",",
"io",
".",
"Closer",
",",
"error",
")",
"{",
"var",
"reporters",
"[",
"]",
"tally",
".",
"CachedStatsReporter",
"\n",
"if",
"mc",
".",
"M3Re... | // NewRootScope creates a new tally.Scope based on a tally.CachedStatsReporter
// based on the the the config. | [
"NewRootScope",
"creates",
"a",
"new",
"tally",
".",
"Scope",
"based",
"on",
"a",
"tally",
".",
"CachedStatsReporter",
"based",
"on",
"the",
"the",
"the",
"config",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/instrument/config.go#L73-L103 |
2,870 | m3db/m3x | instrument/config.go | NewRootScopeReporter | func (mc *MetricsConfiguration) NewRootScopeReporter(
r tally.CachedStatsReporter,
) (tally.Scope, io.Closer) {
var (
prefix string
tags map[string]string
)
if mc.RootScope != nil {
if mc.RootScope.Prefix != "" {
prefix = mc.RootScope.Prefix
}
if mc.RootScope.CommonTags != nil {
tags = mc.RootScope.CommonTags
}
}
var sanitizeOpts *tally.SanitizeOptions
if mc.Sanitization != nil {
sanitizeOpts = mc.Sanitization.NewOptions()
}
scopeOpts := tally.ScopeOptions{
Tags: tags,
Prefix: prefix,
CachedReporter: r,
SanitizeOptions: sanitizeOpts,
}
reportInterval := mc.ReportInterval()
scope, closer := tally.NewRootScope(scopeOpts, reportInterval)
if mc.ExtendedMetrics != nil {
StartReportingExtendedMetrics(scope, reportInterval, *mc.ExtendedMetrics)
}
return scope, closer
} | go | func (mc *MetricsConfiguration) NewRootScopeReporter(
r tally.CachedStatsReporter,
) (tally.Scope, io.Closer) {
var (
prefix string
tags map[string]string
)
if mc.RootScope != nil {
if mc.RootScope.Prefix != "" {
prefix = mc.RootScope.Prefix
}
if mc.RootScope.CommonTags != nil {
tags = mc.RootScope.CommonTags
}
}
var sanitizeOpts *tally.SanitizeOptions
if mc.Sanitization != nil {
sanitizeOpts = mc.Sanitization.NewOptions()
}
scopeOpts := tally.ScopeOptions{
Tags: tags,
Prefix: prefix,
CachedReporter: r,
SanitizeOptions: sanitizeOpts,
}
reportInterval := mc.ReportInterval()
scope, closer := tally.NewRootScope(scopeOpts, reportInterval)
if mc.ExtendedMetrics != nil {
StartReportingExtendedMetrics(scope, reportInterval, *mc.ExtendedMetrics)
}
return scope, closer
} | [
"func",
"(",
"mc",
"*",
"MetricsConfiguration",
")",
"NewRootScopeReporter",
"(",
"r",
"tally",
".",
"CachedStatsReporter",
",",
")",
"(",
"tally",
".",
"Scope",
",",
"io",
".",
"Closer",
")",
"{",
"var",
"(",
"prefix",
"string",
"\n",
"tags",
"map",
"["... | // NewRootScopeReporter creates a new tally.Scope based on a given tally.CachedStatsReporter
// and given root scope config. In most cases NewRootScope should be used, but for cases such
// as hooking into the reporter to manually flush it. | [
"NewRootScopeReporter",
"creates",
"a",
"new",
"tally",
".",
"Scope",
"based",
"on",
"a",
"given",
"tally",
".",
"CachedStatsReporter",
"and",
"given",
"root",
"scope",
"config",
".",
"In",
"most",
"cases",
"NewRootScope",
"should",
"be",
"used",
"but",
"for",... | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/instrument/config.go#L108-L143 |
2,871 | m3db/m3x | instrument/config.go | SampleRate | func (mc *MetricsConfiguration) SampleRate() float64 {
if mc.SamplingRate > 0.0 && mc.SamplingRate <= 1.0 {
return mc.SamplingRate
}
return defaultSamplingRate
} | go | func (mc *MetricsConfiguration) SampleRate() float64 {
if mc.SamplingRate > 0.0 && mc.SamplingRate <= 1.0 {
return mc.SamplingRate
}
return defaultSamplingRate
} | [
"func",
"(",
"mc",
"*",
"MetricsConfiguration",
")",
"SampleRate",
"(",
")",
"float64",
"{",
"if",
"mc",
".",
"SamplingRate",
">",
"0.0",
"&&",
"mc",
".",
"SamplingRate",
"<=",
"1.0",
"{",
"return",
"mc",
".",
"SamplingRate",
"\n",
"}",
"\n",
"return",
... | // SampleRate returns the metrics sampling rate. | [
"SampleRate",
"returns",
"the",
"metrics",
"sampling",
"rate",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/instrument/config.go#L146-L151 |
2,872 | m3db/m3x | instrument/config.go | ReportInterval | func (mc *MetricsConfiguration) ReportInterval() time.Duration {
if mc.RootScope != nil && mc.RootScope.ReportingInterval != 0 {
return mc.RootScope.ReportingInterval
}
return defaultReportingInterval
} | go | func (mc *MetricsConfiguration) ReportInterval() time.Duration {
if mc.RootScope != nil && mc.RootScope.ReportingInterval != 0 {
return mc.RootScope.ReportingInterval
}
return defaultReportingInterval
} | [
"func",
"(",
"mc",
"*",
"MetricsConfiguration",
")",
"ReportInterval",
"(",
")",
"time",
".",
"Duration",
"{",
"if",
"mc",
".",
"RootScope",
"!=",
"nil",
"&&",
"mc",
".",
"RootScope",
".",
"ReportingInterval",
"!=",
"0",
"{",
"return",
"mc",
".",
"RootSc... | // ReportInterval returns the metrics reporting interval. | [
"ReportInterval",
"returns",
"the",
"metrics",
"reporting",
"interval",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/instrument/config.go#L154-L159 |
2,873 | m3db/m3x | instrument/extended.go | UnmarshalYAML | func (t *ExtendedMetricsType) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
if err := unmarshal(&str); err != nil {
return err
}
if str == "" {
*t = DefaultExtendedMetricsType
return nil
}
strs := make([]string, len(validExtendedMetricsTypes))
for _, valid := range validExtendedMetricsTypes {
if str == valid.String() {
*t = valid
return nil
}
strs = append(strs, "'"+valid.String()+"'")
}
return fmt.Errorf("invalid ExtendedMetricsType '%s' valid types are: %s",
str, strings.Join(strs, ", "))
} | go | func (t *ExtendedMetricsType) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
if err := unmarshal(&str); err != nil {
return err
}
if str == "" {
*t = DefaultExtendedMetricsType
return nil
}
strs := make([]string, len(validExtendedMetricsTypes))
for _, valid := range validExtendedMetricsTypes {
if str == valid.String() {
*t = valid
return nil
}
strs = append(strs, "'"+valid.String()+"'")
}
return fmt.Errorf("invalid ExtendedMetricsType '%s' valid types are: %s",
str, strings.Join(strs, ", "))
} | [
"func",
"(",
"t",
"*",
"ExtendedMetricsType",
")",
"UnmarshalYAML",
"(",
"unmarshal",
"func",
"(",
"interface",
"{",
"}",
")",
"error",
")",
"error",
"{",
"var",
"str",
"string",
"\n",
"if",
"err",
":=",
"unmarshal",
"(",
"&",
"str",
")",
";",
"err",
... | // UnmarshalYAML unmarshals an ExtendedMetricsType into a valid type from string. | [
"UnmarshalYAML",
"unmarshals",
"an",
"ExtendedMetricsType",
"into",
"a",
"valid",
"type",
"from",
"string",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/instrument/extended.go#L93-L112 |
2,874 | m3db/m3x | instrument/extended.go | StartReportingExtendedMetrics | func StartReportingExtendedMetrics(
scope tally.Scope,
reportInterval time.Duration,
metricsType ExtendedMetricsType,
) (Reporter, error) {
reporter := NewExtendedMetricsReporter(scope, reportInterval, metricsType)
if err := reporter.Start(); err != nil {
return nil, err
}
return reporter, nil
} | go | func StartReportingExtendedMetrics(
scope tally.Scope,
reportInterval time.Duration,
metricsType ExtendedMetricsType,
) (Reporter, error) {
reporter := NewExtendedMetricsReporter(scope, reportInterval, metricsType)
if err := reporter.Start(); err != nil {
return nil, err
}
return reporter, nil
} | [
"func",
"StartReportingExtendedMetrics",
"(",
"scope",
"tally",
".",
"Scope",
",",
"reportInterval",
"time",
".",
"Duration",
",",
"metricsType",
"ExtendedMetricsType",
",",
")",
"(",
"Reporter",
",",
"error",
")",
"{",
"reporter",
":=",
"NewExtendedMetricsReporter"... | // StartReportingExtendedMetrics creates a extend metrics reporter and starts
// the reporter returning it so it may be stopped if successfully started. | [
"StartReportingExtendedMetrics",
"creates",
"a",
"extend",
"metrics",
"reporter",
"and",
"starts",
"the",
"reporter",
"returning",
"it",
"so",
"it",
"may",
"be",
"stopped",
"if",
"successfully",
"started",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/instrument/extended.go#L116-L126 |
2,875 | m3db/m3x | instrument/extended.go | NewExtendedMetricsReporter | func NewExtendedMetricsReporter(
scope tally.Scope,
reportInterval time.Duration,
metricsType ExtendedMetricsType,
) Reporter {
r := new(extendedMetricsReporter)
r.metricsType = metricsType
r.init(reportInterval, func() {
r.runtime.report(r.metricsType)
if r.metricsType >= ModerateExtendedMetrics {
r.process.report()
}
})
if r.metricsType == NoExtendedMetrics {
return r
}
runtimeScope := scope.SubScope("runtime")
processScope := scope.SubScope("process")
r.runtime.NumGoRoutines = runtimeScope.Gauge("num-goroutines")
r.runtime.GoMaxProcs = runtimeScope.Gauge("gomaxprocs")
r.process.NumFDs = processScope.Gauge("num-fds")
r.process.NumFDErrors = processScope.Counter("num-fd-errors")
r.process.pid = os.Getpid()
if r.metricsType < DetailedExtendedMetrics {
return r
}
var memstats runtime.MemStats
runtime.ReadMemStats(&memstats)
memoryScope := runtimeScope.SubScope("memory")
r.runtime.MemoryAllocated = memoryScope.Gauge("allocated")
r.runtime.MemoryHeap = memoryScope.Gauge("heap")
r.runtime.MemoryHeapIdle = memoryScope.Gauge("heapidle")
r.runtime.MemoryHeapInuse = memoryScope.Gauge("heapinuse")
r.runtime.MemoryStack = memoryScope.Gauge("stack")
r.runtime.GCCPUFraction = memoryScope.Gauge("gc-cpu-fraction")
r.runtime.NumGC = memoryScope.Counter("num-gc")
r.runtime.GcPauseMs = memoryScope.Timer("gc-pause-ms")
r.runtime.lastNumGC = memstats.NumGC
return r
} | go | func NewExtendedMetricsReporter(
scope tally.Scope,
reportInterval time.Duration,
metricsType ExtendedMetricsType,
) Reporter {
r := new(extendedMetricsReporter)
r.metricsType = metricsType
r.init(reportInterval, func() {
r.runtime.report(r.metricsType)
if r.metricsType >= ModerateExtendedMetrics {
r.process.report()
}
})
if r.metricsType == NoExtendedMetrics {
return r
}
runtimeScope := scope.SubScope("runtime")
processScope := scope.SubScope("process")
r.runtime.NumGoRoutines = runtimeScope.Gauge("num-goroutines")
r.runtime.GoMaxProcs = runtimeScope.Gauge("gomaxprocs")
r.process.NumFDs = processScope.Gauge("num-fds")
r.process.NumFDErrors = processScope.Counter("num-fd-errors")
r.process.pid = os.Getpid()
if r.metricsType < DetailedExtendedMetrics {
return r
}
var memstats runtime.MemStats
runtime.ReadMemStats(&memstats)
memoryScope := runtimeScope.SubScope("memory")
r.runtime.MemoryAllocated = memoryScope.Gauge("allocated")
r.runtime.MemoryHeap = memoryScope.Gauge("heap")
r.runtime.MemoryHeapIdle = memoryScope.Gauge("heapidle")
r.runtime.MemoryHeapInuse = memoryScope.Gauge("heapinuse")
r.runtime.MemoryStack = memoryScope.Gauge("stack")
r.runtime.GCCPUFraction = memoryScope.Gauge("gc-cpu-fraction")
r.runtime.NumGC = memoryScope.Counter("num-gc")
r.runtime.GcPauseMs = memoryScope.Timer("gc-pause-ms")
r.runtime.lastNumGC = memstats.NumGC
return r
} | [
"func",
"NewExtendedMetricsReporter",
"(",
"scope",
"tally",
".",
"Scope",
",",
"reportInterval",
"time",
".",
"Duration",
",",
"metricsType",
"ExtendedMetricsType",
",",
")",
"Reporter",
"{",
"r",
":=",
"new",
"(",
"extendedMetricsReporter",
")",
"\n",
"r",
"."... | // NewExtendedMetricsReporter creates a new extended metrics reporter
// that reports runtime and process metrics. | [
"NewExtendedMetricsReporter",
"creates",
"a",
"new",
"extended",
"metrics",
"reporter",
"that",
"reports",
"runtime",
"and",
"process",
"metrics",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/instrument/extended.go#L188-L230 |
2,876 | m3db/m3x | generics/leakcheckpool/pool.go | newLeakcheckElemTypePool | func newLeakcheckElemTypePool(opts leakcheckElemTypePoolOpts, backingPool elemTypePool) *leakcheckElemTypePool {
if opts.EqualsFn == nil {
// NB(prateek): fall-back to == in the worst case
opts.EqualsFn = func(a, b elemType) bool {
return a == b
}
}
return &leakcheckElemTypePool{opts: opts, elemTypePool: backingPool}
} | go | func newLeakcheckElemTypePool(opts leakcheckElemTypePoolOpts, backingPool elemTypePool) *leakcheckElemTypePool {
if opts.EqualsFn == nil {
// NB(prateek): fall-back to == in the worst case
opts.EqualsFn = func(a, b elemType) bool {
return a == b
}
}
return &leakcheckElemTypePool{opts: opts, elemTypePool: backingPool}
} | [
"func",
"newLeakcheckElemTypePool",
"(",
"opts",
"leakcheckElemTypePoolOpts",
",",
"backingPool",
"elemTypePool",
")",
"*",
"leakcheckElemTypePool",
"{",
"if",
"opts",
".",
"EqualsFn",
"==",
"nil",
"{",
"// NB(prateek): fall-back to == in the worst case",
"opts",
".",
"Eq... | // newLeakcheckElemTypePool returns a new leakcheckElemTypePool.
// nolint | [
"newLeakcheckElemTypePool",
"returns",
"a",
"new",
"leakcheckElemTypePool",
".",
"nolint"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/generics/leakcheckpool/pool.go#L63-L71 |
2,877 | m3db/m3x | generics/leakcheckpool/pool.go | Check | func (p *leakcheckElemTypePool) Check(t *testing.T) {
p.Lock()
defer p.Unlock()
require.Equal(t, p.NumGets, p.NumPuts)
require.Empty(t, p.PendingItems)
} | go | func (p *leakcheckElemTypePool) Check(t *testing.T) {
p.Lock()
defer p.Unlock()
require.Equal(t, p.NumGets, p.NumPuts)
require.Empty(t, p.PendingItems)
} | [
"func",
"(",
"p",
"*",
"leakcheckElemTypePool",
")",
"Check",
"(",
"t",
"*",
"testing",
".",
"T",
")",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n\n",
"require",
".",
"Equal",
"(",
"t",
",",
"p",
".",
"NumG... | // Check ensures there are no leaks. | [
"Check",
"ensures",
"there",
"are",
"no",
"leaks",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/generics/leakcheckpool/pool.go#L144-L150 |
2,878 | m3db/m3x | generics/leakcheckpool/pool.go | CheckExtended | func (p *leakcheckElemTypePool) CheckExtended(t *testing.T, fn leakcheckElemTypeFn) {
p.Check(t)
p.Lock()
defer p.Unlock()
for _, e := range p.AllGetItems {
fn(e)
}
} | go | func (p *leakcheckElemTypePool) CheckExtended(t *testing.T, fn leakcheckElemTypeFn) {
p.Check(t)
p.Lock()
defer p.Unlock()
for _, e := range p.AllGetItems {
fn(e)
}
} | [
"func",
"(",
"p",
"*",
"leakcheckElemTypePool",
")",
"CheckExtended",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"fn",
"leakcheckElemTypeFn",
")",
"{",
"p",
".",
"Check",
"(",
"t",
")",
"\n",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlo... | // CheckExtended ensures there are no leaks, and executes the specified fn | [
"CheckExtended",
"ensures",
"there",
"are",
"no",
"leaks",
"and",
"executes",
"the",
"specified",
"fn"
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/generics/leakcheckpool/pool.go#L155-L162 |
2,879 | m3db/m3x | config/pooling.go | Options | func (w WorkerPoolPolicy) Options() (sync.PooledWorkerPoolOptions, int) {
opts := sync.NewPooledWorkerPoolOptions()
grow := w.GrowOnDemand
opts = opts.SetGrowOnDemand(grow)
if w.KillWorkerProbability != 0 {
opts = opts.SetKillWorkerProbability(w.KillWorkerProbability)
} else if grow {
// NB: if using a growing pool, default kill probability is too low, causing
// the pool to quickly grow out of control. Use a higher default kill probability
opts = opts.SetKillWorkerProbability(defaultGrowKillProbability)
}
if w.NumShards != 0 {
opts = opts.SetNumShards(w.NumShards)
}
if w.Size == 0 {
if grow {
w.Size = int(opts.NumShards())
} else {
w.Size = defaultWorkerPoolStaticSize
}
}
return opts, w.Size
} | go | func (w WorkerPoolPolicy) Options() (sync.PooledWorkerPoolOptions, int) {
opts := sync.NewPooledWorkerPoolOptions()
grow := w.GrowOnDemand
opts = opts.SetGrowOnDemand(grow)
if w.KillWorkerProbability != 0 {
opts = opts.SetKillWorkerProbability(w.KillWorkerProbability)
} else if grow {
// NB: if using a growing pool, default kill probability is too low, causing
// the pool to quickly grow out of control. Use a higher default kill probability
opts = opts.SetKillWorkerProbability(defaultGrowKillProbability)
}
if w.NumShards != 0 {
opts = opts.SetNumShards(w.NumShards)
}
if w.Size == 0 {
if grow {
w.Size = int(opts.NumShards())
} else {
w.Size = defaultWorkerPoolStaticSize
}
}
return opts, w.Size
} | [
"func",
"(",
"w",
"WorkerPoolPolicy",
")",
"Options",
"(",
")",
"(",
"sync",
".",
"PooledWorkerPoolOptions",
",",
"int",
")",
"{",
"opts",
":=",
"sync",
".",
"NewPooledWorkerPoolOptions",
"(",
")",
"\n",
"grow",
":=",
"w",
".",
"GrowOnDemand",
"\n",
"opts"... | // Options converts the worker pool policy to options, providing
// the options, as well as the default size for the worker pool. | [
"Options",
"converts",
"the",
"worker",
"pool",
"policy",
"to",
"options",
"providing",
"the",
"options",
"as",
"well",
"as",
"the",
"default",
"size",
"for",
"the",
"worker",
"pool",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/config/pooling.go#L47-L72 |
2,880 | m3db/m3x | config/hostid/hostid.go | Resolve | func (c Configuration) Resolve() (string, error) {
r, err := c.resolver()
if err != nil {
return "", err
}
return r.ID()
} | go | func (c Configuration) Resolve() (string, error) {
r, err := c.resolver()
if err != nil {
return "", err
}
return r.ID()
} | [
"func",
"(",
"c",
"Configuration",
")",
"Resolve",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"r",
",",
"err",
":=",
"c",
".",
"resolver",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
... | // Resolve returns the resolved host ID given the configuration. | [
"Resolve",
"returns",
"the",
"resolved",
"host",
"ID",
"given",
"the",
"configuration",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/config/hostid/hostid.go#L108-L114 |
2,881 | m3db/m3x | config/hostid/hostid.go | ID | func (c *file) ID() (string, error) {
checkF := func() (string, error) {
f, err := os.Open(c.path)
if err != nil {
return "", err
}
data, err := ioutil.ReadAll(f)
if err != nil {
return "", err
}
val := strings.TrimSpace(string(data))
if len(val) == 0 {
return "", errHostIDFileEmpty
}
return val, nil
}
if c.timeout == nil {
return checkF()
}
interval := c.interval
if interval == 0 {
interval = defaultFileCheckInterval
}
startT := time.Now()
for time.Since(startT) < *c.timeout {
v, err := checkF()
if err == nil {
return v, nil
}
time.Sleep(interval)
}
return "", fmt.Errorf("did not find value in %s within %s", c.path, c.timeout)
} | go | func (c *file) ID() (string, error) {
checkF := func() (string, error) {
f, err := os.Open(c.path)
if err != nil {
return "", err
}
data, err := ioutil.ReadAll(f)
if err != nil {
return "", err
}
val := strings.TrimSpace(string(data))
if len(val) == 0 {
return "", errHostIDFileEmpty
}
return val, nil
}
if c.timeout == nil {
return checkF()
}
interval := c.interval
if interval == 0 {
interval = defaultFileCheckInterval
}
startT := time.Now()
for time.Since(startT) < *c.timeout {
v, err := checkF()
if err == nil {
return v, nil
}
time.Sleep(interval)
}
return "", fmt.Errorf("did not find value in %s within %s", c.path, c.timeout)
} | [
"func",
"(",
"c",
"*",
"file",
")",
"ID",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"checkF",
":=",
"func",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"c",
".",
"path",
")",
"\n",
... | // ID attempts to parse an ID from a file. It will optionally wait a timeout to
// find the value, as in some environments the file may be dynamically generated
// from external metadata and not immediately available when the instance starts
// up. | [
"ID",
"attempts",
"to",
"parse",
"an",
"ID",
"from",
"a",
"file",
".",
"It",
"will",
"optionally",
"wait",
"a",
"timeout",
"to",
"find",
"the",
"value",
"as",
"in",
"some",
"environments",
"the",
"file",
"may",
"be",
"dynamically",
"generated",
"from",
"... | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/config/hostid/hostid.go#L163-L203 |
2,882 | m3db/m3x | time/ranges.go | NewRanges | func NewRanges(ranges ...Range) Ranges {
var result Ranges
for _, r := range ranges {
result = result.AddRange(r)
}
return result
} | go | func NewRanges(ranges ...Range) Ranges {
var result Ranges
for _, r := range ranges {
result = result.AddRange(r)
}
return result
} | [
"func",
"NewRanges",
"(",
"ranges",
"...",
"Range",
")",
"Ranges",
"{",
"var",
"result",
"Ranges",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"ranges",
"{",
"result",
"=",
"result",
".",
"AddRange",
"(",
"r",
")",
"\n",
"}",
"\n",
"return",
"result",... | // NewRanges constructs a new Ranges object comprising the provided ranges. | [
"NewRanges",
"constructs",
"a",
"new",
"Ranges",
"object",
"comprising",
"the",
"provided",
"ranges",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/ranges.go#L34-L40 |
2,883 | m3db/m3x | time/ranges.go | Len | func (tr Ranges) Len() int {
if tr.sortedRanges == nil {
return 0
}
return tr.sortedRanges.Len()
} | go | func (tr Ranges) Len() int {
if tr.sortedRanges == nil {
return 0
}
return tr.sortedRanges.Len()
} | [
"func",
"(",
"tr",
"Ranges",
")",
"Len",
"(",
")",
"int",
"{",
"if",
"tr",
".",
"sortedRanges",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"tr",
".",
"sortedRanges",
".",
"Len",
"(",
")",
"\n",
"}"
] | // Len returns the number of ranges included. | [
"Len",
"returns",
"the",
"number",
"of",
"ranges",
"included",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/ranges.go#L43-L48 |
2,884 | m3db/m3x | time/ranges.go | Overlaps | func (tr Ranges) Overlaps(r Range) bool {
if r.IsEmpty() {
return false
}
e := tr.findFirstNotBefore(r)
if e == nil {
return false
}
lr := e.Value.(Range)
return lr.Overlaps(r)
} | go | func (tr Ranges) Overlaps(r Range) bool {
if r.IsEmpty() {
return false
}
e := tr.findFirstNotBefore(r)
if e == nil {
return false
}
lr := e.Value.(Range)
return lr.Overlaps(r)
} | [
"func",
"(",
"tr",
"Ranges",
")",
"Overlaps",
"(",
"r",
"Range",
")",
"bool",
"{",
"if",
"r",
".",
"IsEmpty",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"e",
":=",
"tr",
".",
"findFirstNotBefore",
"(",
"r",
")",
"\n",
"if",
"e",
"==",
"... | // Overlaps checks if the range overlaps with any of the ranges in the collection. | [
"Overlaps",
"checks",
"if",
"the",
"range",
"overlaps",
"with",
"any",
"of",
"the",
"ranges",
"in",
"the",
"collection",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/ranges.go#L56-L66 |
2,885 | m3db/m3x | time/ranges.go | AddRange | func (tr Ranges) AddRange(r Range) Ranges {
res := tr.clone()
res.addRangeInPlace(r)
return res
} | go | func (tr Ranges) AddRange(r Range) Ranges {
res := tr.clone()
res.addRangeInPlace(r)
return res
} | [
"func",
"(",
"tr",
"Ranges",
")",
"AddRange",
"(",
"r",
"Range",
")",
"Ranges",
"{",
"res",
":=",
"tr",
".",
"clone",
"(",
")",
"\n",
"res",
".",
"addRangeInPlace",
"(",
"r",
")",
"\n",
"return",
"res",
"\n",
"}"
] | // AddRange adds the time range to the collection of ranges. | [
"AddRange",
"adds",
"the",
"time",
"range",
"to",
"the",
"collection",
"of",
"ranges",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/ranges.go#L69-L73 |
2,886 | m3db/m3x | time/ranges.go | AddRanges | func (tr Ranges) AddRanges(other Ranges) Ranges {
res := tr.clone()
it := other.Iter()
for it.Next() {
res.addRangeInPlace(it.Value())
}
return res
} | go | func (tr Ranges) AddRanges(other Ranges) Ranges {
res := tr.clone()
it := other.Iter()
for it.Next() {
res.addRangeInPlace(it.Value())
}
return res
} | [
"func",
"(",
"tr",
"Ranges",
")",
"AddRanges",
"(",
"other",
"Ranges",
")",
"Ranges",
"{",
"res",
":=",
"tr",
".",
"clone",
"(",
")",
"\n",
"it",
":=",
"other",
".",
"Iter",
"(",
")",
"\n",
"for",
"it",
".",
"Next",
"(",
")",
"{",
"res",
".",
... | // AddRanges adds the time ranges. | [
"AddRanges",
"adds",
"the",
"time",
"ranges",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/ranges.go#L76-L83 |
2,887 | m3db/m3x | time/ranges.go | RemoveRange | func (tr Ranges) RemoveRange(r Range) Ranges {
res := tr.clone()
res.removeRangeInPlace(r)
return res
} | go | func (tr Ranges) RemoveRange(r Range) Ranges {
res := tr.clone()
res.removeRangeInPlace(r)
return res
} | [
"func",
"(",
"tr",
"Ranges",
")",
"RemoveRange",
"(",
"r",
"Range",
")",
"Ranges",
"{",
"res",
":=",
"tr",
".",
"clone",
"(",
")",
"\n",
"res",
".",
"removeRangeInPlace",
"(",
"r",
")",
"\n",
"return",
"res",
"\n",
"}"
] | // RemoveRange removes the time range from the collection of ranges. | [
"RemoveRange",
"removes",
"the",
"time",
"range",
"from",
"the",
"collection",
"of",
"ranges",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/ranges.go#L86-L90 |
2,888 | m3db/m3x | time/ranges.go | RemoveRanges | func (tr Ranges) RemoveRanges(other Ranges) Ranges {
res := tr.clone()
it := other.Iter()
for it.Next() {
res.removeRangeInPlace(it.Value())
}
return res
} | go | func (tr Ranges) RemoveRanges(other Ranges) Ranges {
res := tr.clone()
it := other.Iter()
for it.Next() {
res.removeRangeInPlace(it.Value())
}
return res
} | [
"func",
"(",
"tr",
"Ranges",
")",
"RemoveRanges",
"(",
"other",
"Ranges",
")",
"Ranges",
"{",
"res",
":=",
"tr",
".",
"clone",
"(",
")",
"\n",
"it",
":=",
"other",
".",
"Iter",
"(",
")",
"\n",
"for",
"it",
".",
"Next",
"(",
")",
"{",
"res",
"."... | // RemoveRanges removes the given time ranges from the current one. | [
"RemoveRanges",
"removes",
"the",
"given",
"time",
"ranges",
"from",
"the",
"current",
"one",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/ranges.go#L93-L100 |
2,889 | m3db/m3x | time/ranges.go | addRangeInPlace | func (tr Ranges) addRangeInPlace(r Range) {
if r.IsEmpty() {
return
}
e := tr.findFirstNotBefore(r)
for e != nil {
lr := e.Value.(Range)
ne := e.Next()
if !lr.Overlaps(r) {
break
}
r = r.Merge(lr)
tr.sortedRanges.Remove(e)
e = ne
}
if e == nil {
tr.sortedRanges.PushBack(r)
return
}
tr.sortedRanges.InsertBefore(r, e)
} | go | func (tr Ranges) addRangeInPlace(r Range) {
if r.IsEmpty() {
return
}
e := tr.findFirstNotBefore(r)
for e != nil {
lr := e.Value.(Range)
ne := e.Next()
if !lr.Overlaps(r) {
break
}
r = r.Merge(lr)
tr.sortedRanges.Remove(e)
e = ne
}
if e == nil {
tr.sortedRanges.PushBack(r)
return
}
tr.sortedRanges.InsertBefore(r, e)
} | [
"func",
"(",
"tr",
"Ranges",
")",
"addRangeInPlace",
"(",
"r",
"Range",
")",
"{",
"if",
"r",
".",
"IsEmpty",
"(",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"e",
":=",
"tr",
".",
"findFirstNotBefore",
"(",
"r",
")",
"\n",
"for",
"e",
"!=",
"nil",
"{"... | // addRangeInPlace adds r to tr in place without creating a new copy. | [
"addRangeInPlace",
"adds",
"r",
"to",
"tr",
"in",
"place",
"without",
"creating",
"a",
"new",
"copy",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/ranges.go#L124-L145 |
2,890 | m3db/m3x | time/ranges.go | findFirstNotBefore | func (tr Ranges) findFirstNotBefore(r Range) *list.Element {
if tr.sortedRanges == nil {
return nil
}
for e := tr.sortedRanges.Front(); e != nil; e = e.Next() {
if !e.Value.(Range).Before(r) {
return e
}
}
return nil
} | go | func (tr Ranges) findFirstNotBefore(r Range) *list.Element {
if tr.sortedRanges == nil {
return nil
}
for e := tr.sortedRanges.Front(); e != nil; e = e.Next() {
if !e.Value.(Range).Before(r) {
return e
}
}
return nil
} | [
"func",
"(",
"tr",
"Ranges",
")",
"findFirstNotBefore",
"(",
"r",
"Range",
")",
"*",
"list",
".",
"Element",
"{",
"if",
"tr",
".",
"sortedRanges",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"e",
":=",
"tr",
".",
"sortedRanges",
".",
... | // findFirstNotBefore finds the first interval that's not before r. | [
"findFirstNotBefore",
"finds",
"the",
"first",
"interval",
"that",
"s",
"not",
"before",
"r",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/ranges.go#L172-L182 |
2,891 | m3db/m3x | time/ranges.go | clone | func (tr Ranges) clone() Ranges {
res := Ranges{sortedRanges: list.New()}
if tr.sortedRanges == nil {
return res
}
for e := tr.sortedRanges.Front(); e != nil; e = e.Next() {
res.sortedRanges.PushBack(e.Value.(Range))
}
return res
} | go | func (tr Ranges) clone() Ranges {
res := Ranges{sortedRanges: list.New()}
if tr.sortedRanges == nil {
return res
}
for e := tr.sortedRanges.Front(); e != nil; e = e.Next() {
res.sortedRanges.PushBack(e.Value.(Range))
}
return res
} | [
"func",
"(",
"tr",
"Ranges",
")",
"clone",
"(",
")",
"Ranges",
"{",
"res",
":=",
"Ranges",
"{",
"sortedRanges",
":",
"list",
".",
"New",
"(",
")",
"}",
"\n",
"if",
"tr",
".",
"sortedRanges",
"==",
"nil",
"{",
"return",
"res",
"\n",
"}",
"\n",
"fo... | // clone returns a copy of the time ranges. | [
"clone",
"returns",
"a",
"copy",
"of",
"the",
"time",
"ranges",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/time/ranges.go#L185-L194 |
2,892 | m3db/m3x | checked/ref.go | IncRef | func (c *RefCount) IncRef() {
n := atomic.AddInt32(&c.ref, 1)
tracebackEvent(c, int(n), incRefEvent)
} | go | func (c *RefCount) IncRef() {
n := atomic.AddInt32(&c.ref, 1)
tracebackEvent(c, int(n), incRefEvent)
} | [
"func",
"(",
"c",
"*",
"RefCount",
")",
"IncRef",
"(",
")",
"{",
"n",
":=",
"atomic",
".",
"AddInt32",
"(",
"&",
"c",
".",
"ref",
",",
"1",
")",
"\n",
"tracebackEvent",
"(",
"c",
",",
"int",
"(",
"n",
")",
",",
"incRefEvent",
")",
"\n",
"}"
] | // IncRef increments the reference count to this entity. | [
"IncRef",
"increments",
"the",
"reference",
"count",
"to",
"this",
"entity",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/ref.go#L42-L45 |
2,893 | m3db/m3x | checked/ref.go | DecRef | func (c *RefCount) DecRef() {
n := atomic.AddInt32(&c.ref, -1)
tracebackEvent(c, int(n), decRefEvent)
if n < 0 {
err := fmt.Errorf("negative ref count, ref=%d", n)
panicRef(c, err)
}
} | go | func (c *RefCount) DecRef() {
n := atomic.AddInt32(&c.ref, -1)
tracebackEvent(c, int(n), decRefEvent)
if n < 0 {
err := fmt.Errorf("negative ref count, ref=%d", n)
panicRef(c, err)
}
} | [
"func",
"(",
"c",
"*",
"RefCount",
")",
"DecRef",
"(",
")",
"{",
"n",
":=",
"atomic",
".",
"AddInt32",
"(",
"&",
"c",
".",
"ref",
",",
"-",
"1",
")",
"\n",
"tracebackEvent",
"(",
"c",
",",
"int",
"(",
"n",
")",
",",
"decRefEvent",
")",
"\n\n",
... | // DecRef decrements the reference count to this entity. | [
"DecRef",
"decrements",
"the",
"reference",
"count",
"to",
"this",
"entity",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/ref.go#L48-L56 |
2,894 | m3db/m3x | checked/ref.go | Finalize | func (c *RefCount) Finalize() {
n := c.NumRef()
tracebackEvent(c, n, finalizeEvent)
if n != 0 {
err := fmt.Errorf("finalize before zero ref count, ref=%d", n)
panicRef(c, err)
}
if f := c.Finalizer(); f != nil {
f.Finalize()
}
} | go | func (c *RefCount) Finalize() {
n := c.NumRef()
tracebackEvent(c, n, finalizeEvent)
if n != 0 {
err := fmt.Errorf("finalize before zero ref count, ref=%d", n)
panicRef(c, err)
}
if f := c.Finalizer(); f != nil {
f.Finalize()
}
} | [
"func",
"(",
"c",
"*",
"RefCount",
")",
"Finalize",
"(",
")",
"{",
"n",
":=",
"c",
".",
"NumRef",
"(",
")",
"\n",
"tracebackEvent",
"(",
"c",
",",
"n",
",",
"finalizeEvent",
")",
"\n\n",
"if",
"n",
"!=",
"0",
"{",
"err",
":=",
"fmt",
".",
"Erro... | // Finalize will call the finalizer if any, ref count must be zero. | [
"Finalize",
"will",
"call",
"the",
"finalizer",
"if",
"any",
"ref",
"count",
"must",
"be",
"zero",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/ref.go#L69-L81 |
2,895 | m3db/m3x | checked/ref.go | Finalizer | func (c *RefCount) Finalizer() resource.Finalizer {
finalizerPtr := (*resource.Finalizer)(atomic.LoadPointer(&c.finalizer))
if finalizerPtr == nil {
return nil
}
return *finalizerPtr
} | go | func (c *RefCount) Finalizer() resource.Finalizer {
finalizerPtr := (*resource.Finalizer)(atomic.LoadPointer(&c.finalizer))
if finalizerPtr == nil {
return nil
}
return *finalizerPtr
} | [
"func",
"(",
"c",
"*",
"RefCount",
")",
"Finalizer",
"(",
")",
"resource",
".",
"Finalizer",
"{",
"finalizerPtr",
":=",
"(",
"*",
"resource",
".",
"Finalizer",
")",
"(",
"atomic",
".",
"LoadPointer",
"(",
"&",
"c",
".",
"finalizer",
")",
")",
"\n",
"... | // Finalizer returns the finalizer if any or nil otherwise. | [
"Finalizer",
"returns",
"the",
"finalizer",
"if",
"any",
"or",
"nil",
"otherwise",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/ref.go#L84-L90 |
2,896 | m3db/m3x | checked/ref.go | SetFinalizer | func (c *RefCount) SetFinalizer(f resource.Finalizer) {
atomic.StorePointer(&c.finalizer, unsafe.Pointer(&f))
} | go | func (c *RefCount) SetFinalizer(f resource.Finalizer) {
atomic.StorePointer(&c.finalizer, unsafe.Pointer(&f))
} | [
"func",
"(",
"c",
"*",
"RefCount",
")",
"SetFinalizer",
"(",
"f",
"resource",
".",
"Finalizer",
")",
"{",
"atomic",
".",
"StorePointer",
"(",
"&",
"c",
".",
"finalizer",
",",
"unsafe",
".",
"Pointer",
"(",
"&",
"f",
")",
")",
"\n",
"}"
] | // SetFinalizer sets the finalizer. | [
"SetFinalizer",
"sets",
"the",
"finalizer",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/ref.go#L93-L95 |
2,897 | m3db/m3x | checked/ref.go | IncReads | func (c *RefCount) IncReads() {
tracebackEvent(c, c.NumRef(), incReadsEvent)
n := atomic.AddInt32(&c.reads, 1)
if ref := c.NumRef(); n > 0 && ref < 1 {
err := fmt.Errorf("read after free: reads=%d, ref=%d", n, ref)
panicRef(c, err)
}
} | go | func (c *RefCount) IncReads() {
tracebackEvent(c, c.NumRef(), incReadsEvent)
n := atomic.AddInt32(&c.reads, 1)
if ref := c.NumRef(); n > 0 && ref < 1 {
err := fmt.Errorf("read after free: reads=%d, ref=%d", n, ref)
panicRef(c, err)
}
} | [
"func",
"(",
"c",
"*",
"RefCount",
")",
"IncReads",
"(",
")",
"{",
"tracebackEvent",
"(",
"c",
",",
"c",
".",
"NumRef",
"(",
")",
",",
"incReadsEvent",
")",
"\n",
"n",
":=",
"atomic",
".",
"AddInt32",
"(",
"&",
"c",
".",
"reads",
",",
"1",
")",
... | // IncReads increments the reads count to this entity. | [
"IncReads",
"increments",
"the",
"reads",
"count",
"to",
"this",
"entity",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/ref.go#L98-L106 |
2,898 | m3db/m3x | checked/ref.go | DecReads | func (c *RefCount) DecReads() {
tracebackEvent(c, c.NumRef(), decReadsEvent)
n := atomic.AddInt32(&c.reads, -1)
if ref := c.NumRef(); ref < 1 {
err := fmt.Errorf("read finish after free: reads=%d, ref=%d", n, ref)
panicRef(c, err)
}
} | go | func (c *RefCount) DecReads() {
tracebackEvent(c, c.NumRef(), decReadsEvent)
n := atomic.AddInt32(&c.reads, -1)
if ref := c.NumRef(); ref < 1 {
err := fmt.Errorf("read finish after free: reads=%d, ref=%d", n, ref)
panicRef(c, err)
}
} | [
"func",
"(",
"c",
"*",
"RefCount",
")",
"DecReads",
"(",
")",
"{",
"tracebackEvent",
"(",
"c",
",",
"c",
".",
"NumRef",
"(",
")",
",",
"decReadsEvent",
")",
"\n",
"n",
":=",
"atomic",
".",
"AddInt32",
"(",
"&",
"c",
".",
"reads",
",",
"-",
"1",
... | // DecReads decrements the reads count to this entity. | [
"DecReads",
"decrements",
"the",
"reads",
"count",
"to",
"this",
"entity",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/ref.go#L109-L117 |
2,899 | m3db/m3x | checked/ref.go | IncWrites | func (c *RefCount) IncWrites() {
tracebackEvent(c, c.NumRef(), incWritesEvent)
n := atomic.AddInt32(&c.writes, 1)
ref := c.NumRef()
if n > 0 && ref < 1 {
err := fmt.Errorf("write after free: writes=%d, ref=%d", n, ref)
panicRef(c, err)
}
if n > 1 {
err := fmt.Errorf("double write: writes=%d, ref=%d", n, ref)
panicRef(c, err)
}
} | go | func (c *RefCount) IncWrites() {
tracebackEvent(c, c.NumRef(), incWritesEvent)
n := atomic.AddInt32(&c.writes, 1)
ref := c.NumRef()
if n > 0 && ref < 1 {
err := fmt.Errorf("write after free: writes=%d, ref=%d", n, ref)
panicRef(c, err)
}
if n > 1 {
err := fmt.Errorf("double write: writes=%d, ref=%d", n, ref)
panicRef(c, err)
}
} | [
"func",
"(",
"c",
"*",
"RefCount",
")",
"IncWrites",
"(",
")",
"{",
"tracebackEvent",
"(",
"c",
",",
"c",
".",
"NumRef",
"(",
")",
",",
"incWritesEvent",
")",
"\n",
"n",
":=",
"atomic",
".",
"AddInt32",
"(",
"&",
"c",
".",
"writes",
",",
"1",
")"... | // IncWrites increments the writes count to this entity. | [
"IncWrites",
"increments",
"the",
"writes",
"count",
"to",
"this",
"entity",
"."
] | ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e | https://github.com/m3db/m3x/blob/ebf3c7b94afd62bad2aaa3ad20bb2d4142aa342e/checked/ref.go#L125-L139 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.