repo stringlengths 5 67 | path stringlengths 4 218 | func_name stringlengths 0 151 | original_string stringlengths 52 373k | language stringclasses 6 values | code stringlengths 52 373k | code_tokens listlengths 10 512 | docstring stringlengths 3 47.2k | docstring_tokens listlengths 3 234 | sha stringlengths 40 40 | url stringlengths 85 339 | partition stringclasses 3 values |
|---|---|---|---|---|---|---|---|---|---|---|---|
pilosa/pilosa | roaring/roaring.go | xorRunRun | func xorRunRun(a, b *Container) *Container {
statsHit("xor/RunRun")
ra, rb := a.runs(), b.runs()
na, nb := len(ra), len(rb)
if na == 0 {
return b.Clone()
}
if nb == 0 {
return a.Clone()
}
output := NewContainerRun(nil)
lastI, lastJ := -1, -1
state := &xorstm{}
for i, j := 0, 0; i < na || j < nb; {
if i < na && lastI != i {
state.va = ra[i]
state.vaValid = true
}
if j < nb && lastJ != j {
state.vb = rb[j]
state.vbValid = true
}
lastI, lastJ = i, j
r1, ok := xorCompare(state)
if ok {
output.n += output.runAppendInterval(r1)
}
if !state.vaValid {
i++
}
if !state.vbValid {
j++
}
}
l := len(output.runs())
if output.n < ArrayMaxSize && int32(l) > output.n/2 {
output.runToArray()
} else if l > runMaxSize {
output.runToBitmap()
}
return output
} | go | func xorRunRun(a, b *Container) *Container {
statsHit("xor/RunRun")
ra, rb := a.runs(), b.runs()
na, nb := len(ra), len(rb)
if na == 0 {
return b.Clone()
}
if nb == 0 {
return a.Clone()
}
output := NewContainerRun(nil)
lastI, lastJ := -1, -1
state := &xorstm{}
for i, j := 0, 0; i < na || j < nb; {
if i < na && lastI != i {
state.va = ra[i]
state.vaValid = true
}
if j < nb && lastJ != j {
state.vb = rb[j]
state.vbValid = true
}
lastI, lastJ = i, j
r1, ok := xorCompare(state)
if ok {
output.n += output.runAppendInterval(r1)
}
if !state.vaValid {
i++
}
if !state.vbValid {
j++
}
}
l := len(output.runs())
if output.n < ArrayMaxSize && int32(l) > output.n/2 {
output.runToArray()
} else if l > runMaxSize {
output.runToBitmap()
}
return output
} | [
"func",
"xorRunRun",
"(",
"a",
",",
"b",
"*",
"Container",
")",
"*",
"Container",
"{",
"statsHit",
"(",
"\"xor/RunRun\"",
")",
"\n",
"ra",
",",
"rb",
":=",
"a",
".",
"runs",
"(",
")",
",",
"b",
".",
"runs",
"(",
")",
"\n",
"na",
",",
"nb",
":="... | // xorRunRun computes the exclusive or of two run containers. | [
"xorRunRun",
"computes",
"the",
"exclusive",
"or",
"of",
"two",
"run",
"containers",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/roaring.go#L4054-L4102 | train |
pilosa/pilosa | roaring/roaring.go | xorBitmapRun | func xorBitmapRun(a, b *Container) *Container {
statsHit("xor/BitmapRun")
output := a.Clone()
for _, run := range b.runs() {
output.bitmapXorRange(uint64(run.start), uint64(run.last)+1)
}
return output
} | go | func xorBitmapRun(a, b *Container) *Container {
statsHit("xor/BitmapRun")
output := a.Clone()
for _, run := range b.runs() {
output.bitmapXorRange(uint64(run.start), uint64(run.last)+1)
}
return output
} | [
"func",
"xorBitmapRun",
"(",
"a",
",",
"b",
"*",
"Container",
")",
"*",
"Container",
"{",
"statsHit",
"(",
"\"xor/BitmapRun\"",
")",
"\n",
"output",
":=",
"a",
".",
"Clone",
"(",
")",
"\n",
"for",
"_",
",",
"run",
":=",
"range",
"b",
".",
"runs",
"... | // xorRunRun computes the exclusive or of a bitmap and a run container. | [
"xorRunRun",
"computes",
"the",
"exclusive",
"or",
"of",
"a",
"bitmap",
"and",
"a",
"run",
"container",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/roaring.go#L4105-L4114 | train |
pilosa/pilosa | roaring/roaring.go | UnmarshalBinary | func (b *Bitmap) UnmarshalBinary(data []byte) error {
if data == nil {
// Nothing to unmarshal
return nil
}
statsHit("Bitmap/UnmarshalBinary")
b.opN = 0 // reset opN since we're reading new data.
fileMagic := uint32(binary.LittleEndian.Uint16(data[0:2]))
if fileMagic == MagicNumber { // if pilosa roaring
return errors.Wrap(b.unmarshalPilosaRoaring(data), "unmarshaling as pilosa roaring")
}
keyN, containerTyper, header, pos, haveRuns, err := readOfficialHeader(data)
if err != nil {
return errors.Wrap(err, "reading roaring header")
}
b.Containers.Reset()
// Descriptive header section: Read container keys and cardinalities.
for i, buf := uint(0), data[header:]; i < uint(keyN); i, buf = i+1, buf[4:] {
card := int(binary.LittleEndian.Uint16(buf[2:4])) + 1
b.Containers.PutContainerValues(
uint64(binary.LittleEndian.Uint16(buf[0:2])),
containerTyper(i, card), /// container type voodo with isRunBitmap
card,
true)
}
// Read container offsets and attach data.
if haveRuns {
readWithRuns(b, data, pos, keyN)
} else {
err := readOffsets(b, data, pos, keyN)
if err != nil {
return errors.Wrap(err, "reading offsets from official roaring format")
}
}
return nil
} | go | func (b *Bitmap) UnmarshalBinary(data []byte) error {
if data == nil {
// Nothing to unmarshal
return nil
}
statsHit("Bitmap/UnmarshalBinary")
b.opN = 0 // reset opN since we're reading new data.
fileMagic := uint32(binary.LittleEndian.Uint16(data[0:2]))
if fileMagic == MagicNumber { // if pilosa roaring
return errors.Wrap(b.unmarshalPilosaRoaring(data), "unmarshaling as pilosa roaring")
}
keyN, containerTyper, header, pos, haveRuns, err := readOfficialHeader(data)
if err != nil {
return errors.Wrap(err, "reading roaring header")
}
b.Containers.Reset()
// Descriptive header section: Read container keys and cardinalities.
for i, buf := uint(0), data[header:]; i < uint(keyN); i, buf = i+1, buf[4:] {
card := int(binary.LittleEndian.Uint16(buf[2:4])) + 1
b.Containers.PutContainerValues(
uint64(binary.LittleEndian.Uint16(buf[0:2])),
containerTyper(i, card), /// container type voodo with isRunBitmap
card,
true)
}
// Read container offsets and attach data.
if haveRuns {
readWithRuns(b, data, pos, keyN)
} else {
err := readOffsets(b, data, pos, keyN)
if err != nil {
return errors.Wrap(err, "reading offsets from official roaring format")
}
}
return nil
} | [
"func",
"(",
"b",
"*",
"Bitmap",
")",
"UnmarshalBinary",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"data",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"statsHit",
"(",
"\"Bitmap/UnmarshalBinary\"",
")",
"\n",
"b",
".",
"opN",
"=... | // UnmarshalBinary decodes b from a binary-encoded byte slice. data can be in
// either official roaring format or Pilosa's roaring format. | [
"UnmarshalBinary",
"decodes",
"b",
"from",
"a",
"binary",
"-",
"encoded",
"byte",
"slice",
".",
"data",
"can",
"be",
"in",
"either",
"official",
"roaring",
"format",
"or",
"Pilosa",
"s",
"roaring",
"format",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/roaring.go#L4231-L4269 | train |
pilosa/pilosa | roaring/roaring.go | markItersWithKeyAsHandled | func (w handledIters) markItersWithKeyAsHandled(startIdx int, key uint64) {
for i := startIdx; i < len(w); i++ {
wrapped := w[i]
currKey, _ := wrapped.iter.Value()
if currKey == key {
w[i].handled = true
}
}
} | go | func (w handledIters) markItersWithKeyAsHandled(startIdx int, key uint64) {
for i := startIdx; i < len(w); i++ {
wrapped := w[i]
currKey, _ := wrapped.iter.Value()
if currKey == key {
w[i].handled = true
}
}
} | [
"func",
"(",
"w",
"handledIters",
")",
"markItersWithKeyAsHandled",
"(",
"startIdx",
"int",
",",
"key",
"uint64",
")",
"{",
"for",
"i",
":=",
"startIdx",
";",
"i",
"<",
"len",
"(",
"w",
")",
";",
"i",
"++",
"{",
"wrapped",
":=",
"w",
"[",
"i",
"]",... | // Check all the iters from startIdx and up to see whether their next
// key is the given key; if it is, mark them as handled. | [
"Check",
"all",
"the",
"iters",
"from",
"startIdx",
"and",
"up",
"to",
"see",
"whether",
"their",
"next",
"key",
"is",
"the",
"given",
"key",
";",
"if",
"it",
"is",
"mark",
"them",
"as",
"handled",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/roaring.go#L4349-L4357 | train |
pilosa/pilosa | roaring/btree.go | Seek | func (t *tree) Seek(k uint64) (e *enumerator, ok bool) {
q := t.r
if q == nil {
e = btEPool.get(nil, false, 0, k, nil, t, t.ver)
return
}
for {
var i int
if i, ok = t.find(q, k); ok {
switch x := q.(type) {
case *x:
q = x.x[i+1].ch
continue
case *d:
return btEPool.get(nil, ok, i, k, x, t, t.ver), true
}
}
switch x := q.(type) {
case *x:
q = x.x[i].ch
case *d:
return btEPool.get(nil, ok, i, k, x, t, t.ver), false
}
}
} | go | func (t *tree) Seek(k uint64) (e *enumerator, ok bool) {
q := t.r
if q == nil {
e = btEPool.get(nil, false, 0, k, nil, t, t.ver)
return
}
for {
var i int
if i, ok = t.find(q, k); ok {
switch x := q.(type) {
case *x:
q = x.x[i+1].ch
continue
case *d:
return btEPool.get(nil, ok, i, k, x, t, t.ver), true
}
}
switch x := q.(type) {
case *x:
q = x.x[i].ch
case *d:
return btEPool.get(nil, ok, i, k, x, t, t.ver), false
}
}
} | [
"func",
"(",
"t",
"*",
"tree",
")",
"Seek",
"(",
"k",
"uint64",
")",
"(",
"e",
"*",
"enumerator",
",",
"ok",
"bool",
")",
"{",
"q",
":=",
"t",
".",
"r",
"\n",
"if",
"q",
"==",
"nil",
"{",
"e",
"=",
"btEPool",
".",
"get",
"(",
"nil",
",",
... | // Seek returns an Enumerator positioned on an item such that k >= item's key.
// ok reports if k == item.key The Enumerator's position is possibly after the
// last item in the tree. | [
"Seek",
"returns",
"an",
"Enumerator",
"positioned",
"on",
"an",
"item",
"such",
"that",
"k",
">",
"=",
"item",
"s",
"key",
".",
"ok",
"reports",
"if",
"k",
"==",
"item",
".",
"key",
"The",
"Enumerator",
"s",
"position",
"is",
"possibly",
"after",
"the... | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/btree.go#L517-L543 | train |
pilosa/pilosa | roaring/btree.go | Prev | func (e *enumerator) Prev() (k uint64, v *Container, err error) {
if err = e.err; err != nil {
return 0, nil, err
}
if e.ver != e.t.ver {
f, _ := e.t.Seek(e.k)
*e = *f
f.Close()
}
if e.q == nil {
e.err, err = io.EOF, io.EOF
return 0, nil, err
}
if !e.hit {
// move to previous because Seek overshoots if there's no hit
if err = e.prev(); err != nil {
return 0, nil, err
}
}
if e.i >= e.q.c {
if err = e.prev(); err != nil {
return 0, nil, err
}
}
i := e.q.d[e.i]
k, v = i.k, i.v
e.k, e.hit = k, true
// Any error returned would be stashed in e.err, and would come up
// on the next call.
_ = e.prev()
return k, v, err
} | go | func (e *enumerator) Prev() (k uint64, v *Container, err error) {
if err = e.err; err != nil {
return 0, nil, err
}
if e.ver != e.t.ver {
f, _ := e.t.Seek(e.k)
*e = *f
f.Close()
}
if e.q == nil {
e.err, err = io.EOF, io.EOF
return 0, nil, err
}
if !e.hit {
// move to previous because Seek overshoots if there's no hit
if err = e.prev(); err != nil {
return 0, nil, err
}
}
if e.i >= e.q.c {
if err = e.prev(); err != nil {
return 0, nil, err
}
}
i := e.q.d[e.i]
k, v = i.k, i.v
e.k, e.hit = k, true
// Any error returned would be stashed in e.err, and would come up
// on the next call.
_ = e.prev()
return k, v, err
} | [
"func",
"(",
"e",
"*",
"enumerator",
")",
"Prev",
"(",
")",
"(",
"k",
"uint64",
",",
"v",
"*",
"Container",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"e",
".",
"err",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"nil",
",",
"err",... | // Prev returns the currently enumerated item, if it exists and moves to the
// previous item in the key collation order. If there is no item to return, err
// == io.EOF is returned. | [
"Prev",
"returns",
"the",
"currently",
"enumerated",
"item",
"if",
"it",
"exists",
"and",
"moves",
"to",
"the",
"previous",
"item",
"in",
"the",
"key",
"collation",
"order",
".",
"If",
"there",
"is",
"no",
"item",
"to",
"return",
"err",
"==",
"io",
".",
... | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/roaring/btree.go#L899-L934 | train |
pilosa/pilosa | translate.go | OptTranslateFileMapSize | func OptTranslateFileMapSize(mapSize int) TranslateFileOption {
return func(f *TranslateFile) error {
f.mapSize = mapSize
return nil
}
} | go | func OptTranslateFileMapSize(mapSize int) TranslateFileOption {
return func(f *TranslateFile) error {
f.mapSize = mapSize
return nil
}
} | [
"func",
"OptTranslateFileMapSize",
"(",
"mapSize",
"int",
")",
"TranslateFileOption",
"{",
"return",
"func",
"(",
"f",
"*",
"TranslateFile",
")",
"error",
"{",
"f",
".",
"mapSize",
"=",
"mapSize",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // OptTranslateFileMapSize is a functional option on TranslateFile
// used to set the map size. | [
"OptTranslateFileMapSize",
"is",
"a",
"functional",
"option",
"on",
"TranslateFile",
"used",
"to",
"set",
"the",
"map",
"size",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L106-L111 | train |
pilosa/pilosa | translate.go | OptTranslateFileLogger | func OptTranslateFileLogger(l logger.Logger) TranslateFileOption {
return func(s *TranslateFile) error {
s.logger = l
return nil
}
} | go | func OptTranslateFileLogger(l logger.Logger) TranslateFileOption {
return func(s *TranslateFile) error {
s.logger = l
return nil
}
} | [
"func",
"OptTranslateFileLogger",
"(",
"l",
"logger",
".",
"Logger",
")",
"TranslateFileOption",
"{",
"return",
"func",
"(",
"s",
"*",
"TranslateFile",
")",
"error",
"{",
"s",
".",
"logger",
"=",
"l",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // OptTranslateFileLogger is a functional option on TranslateFile
// used to set the file logger. | [
"OptTranslateFileLogger",
"is",
"a",
"functional",
"option",
"on",
"TranslateFile",
"used",
"to",
"set",
"the",
"file",
"logger",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L115-L120 | train |
pilosa/pilosa | translate.go | NewTranslateFile | func NewTranslateFile(opts ...TranslateFileOption) *TranslateFile {
var defaultMapSize64 int64 = 10 * (1 << 30)
var defaultMapSize int
if ^uint(0)>>32 > 0 {
// 10GB default map size
defaultMapSize = int(defaultMapSize64)
} else {
// Use 2GB default map size on 32-bit systems
defaultMapSize = (1 << 31) - 1
}
f := &TranslateFile{
writeNotify: make(chan struct{}),
closing: make(chan struct{}),
cols: make(map[string]*index),
rows: make(map[fieldKey]*index),
mapSize: defaultMapSize,
logger: logger.NopLogger,
replicationClosing: make(chan struct{}),
primaryStoreEvents: make(chan primaryStoreEvent),
replicationRetryInterval: defaultReplicationRetryInterval,
}
for _, opt := range opts {
err := opt(f)
if err != nil {
// TODO (2.0): Change func signature to return error
panic(errors.Wrap(err, "applying option"))
}
}
return f
} | go | func NewTranslateFile(opts ...TranslateFileOption) *TranslateFile {
var defaultMapSize64 int64 = 10 * (1 << 30)
var defaultMapSize int
if ^uint(0)>>32 > 0 {
// 10GB default map size
defaultMapSize = int(defaultMapSize64)
} else {
// Use 2GB default map size on 32-bit systems
defaultMapSize = (1 << 31) - 1
}
f := &TranslateFile{
writeNotify: make(chan struct{}),
closing: make(chan struct{}),
cols: make(map[string]*index),
rows: make(map[fieldKey]*index),
mapSize: defaultMapSize,
logger: logger.NopLogger,
replicationClosing: make(chan struct{}),
primaryStoreEvents: make(chan primaryStoreEvent),
replicationRetryInterval: defaultReplicationRetryInterval,
}
for _, opt := range opts {
err := opt(f)
if err != nil {
// TODO (2.0): Change func signature to return error
panic(errors.Wrap(err, "applying option"))
}
}
return f
} | [
"func",
"NewTranslateFile",
"(",
"opts",
"...",
"TranslateFileOption",
")",
"*",
"TranslateFile",
"{",
"var",
"defaultMapSize64",
"int64",
"=",
"10",
"*",
"(",
"1",
"<<",
"30",
")",
"\n",
"var",
"defaultMapSize",
"int",
"\n",
"if",
"^",
"uint",
"(",
"0",
... | // NewTranslateFile returns a new instance of TranslateFile. | [
"NewTranslateFile",
"returns",
"a",
"new",
"instance",
"of",
"TranslateFile",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L123-L159 | train |
pilosa/pilosa | translate.go | Open | func (s *TranslateFile) Open() (err error) {
// Open writer & buffered writer.
if err := os.MkdirAll(filepath.Dir(s.Path), 0777); err != nil {
return errors.Wrapf(err, "mkdir %s", filepath.Dir(s.Path))
} else if s.file, err = os.OpenFile(s.Path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666); err != nil {
return errors.Wrapf(err, "open file %s", s.Path)
}
s.w = bufio.NewWriter(s.file)
// Memory map data file.
if s.data, err = syscall.Mmap(int(s.file.Fd()), 0, s.mapSize, syscall.PROT_READ, syscall.MAP_SHARED); err != nil {
return errors.Wrapf(err, "creating Mmap (size: %d)", s.mapSize)
}
// Replay the log.
if err := s.replayEntries(); err != nil {
return errors.Wrap(err, "replaying log entries")
}
// Listen to primaryStoreEvents channel.
s.wg.Add(1)
go func() { defer s.wg.Done(); s.monitorPrimaryStoreEvents() }()
return nil
} | go | func (s *TranslateFile) Open() (err error) {
// Open writer & buffered writer.
if err := os.MkdirAll(filepath.Dir(s.Path), 0777); err != nil {
return errors.Wrapf(err, "mkdir %s", filepath.Dir(s.Path))
} else if s.file, err = os.OpenFile(s.Path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666); err != nil {
return errors.Wrapf(err, "open file %s", s.Path)
}
s.w = bufio.NewWriter(s.file)
// Memory map data file.
if s.data, err = syscall.Mmap(int(s.file.Fd()), 0, s.mapSize, syscall.PROT_READ, syscall.MAP_SHARED); err != nil {
return errors.Wrapf(err, "creating Mmap (size: %d)", s.mapSize)
}
// Replay the log.
if err := s.replayEntries(); err != nil {
return errors.Wrap(err, "replaying log entries")
}
// Listen to primaryStoreEvents channel.
s.wg.Add(1)
go func() { defer s.wg.Done(); s.monitorPrimaryStoreEvents() }()
return nil
} | [
"func",
"(",
"s",
"*",
"TranslateFile",
")",
"Open",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"filepath",
".",
"Dir",
"(",
"s",
".",
"Path",
")",
",",
"0777",
")",
";",
"err",
"!=",
"nil",
"{",
"... | // Open opens the translate file. | [
"Open",
"opens",
"the",
"translate",
"file",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L162-L186 | train |
pilosa/pilosa | translate.go | handlePrimaryStoreEvent | func (s *TranslateFile) handlePrimaryStoreEvent(ev primaryStoreEvent) error {
s.mu.Lock()
defer s.mu.Unlock()
if ev.id == s.primaryID {
return nil
}
// Stop translate store replication.
close(s.replicationClosing)
s.repWG.Wait()
// Set the primary node for translate store replication.
s.logger.Debugf("set primary translate store to %s", ev.id)
s.primaryID = ev.id
if ev.id == "" {
s.PrimaryTranslateStore = nil
} else {
s.PrimaryTranslateStore = ev.ts
}
// Start translate store replication. Stream from primary, if available.
if s.PrimaryTranslateStore != nil {
s.replicationClosing = make(chan struct{})
s.repWG.Add(1)
go func() { defer s.repWG.Done(); s.monitorReplication() }()
}
return nil
} | go | func (s *TranslateFile) handlePrimaryStoreEvent(ev primaryStoreEvent) error {
s.mu.Lock()
defer s.mu.Unlock()
if ev.id == s.primaryID {
return nil
}
// Stop translate store replication.
close(s.replicationClosing)
s.repWG.Wait()
// Set the primary node for translate store replication.
s.logger.Debugf("set primary translate store to %s", ev.id)
s.primaryID = ev.id
if ev.id == "" {
s.PrimaryTranslateStore = nil
} else {
s.PrimaryTranslateStore = ev.ts
}
// Start translate store replication. Stream from primary, if available.
if s.PrimaryTranslateStore != nil {
s.replicationClosing = make(chan struct{})
s.repWG.Add(1)
go func() { defer s.repWG.Done(); s.monitorReplication() }()
}
return nil
} | [
"func",
"(",
"s",
"*",
"TranslateFile",
")",
"handlePrimaryStoreEvent",
"(",
"ev",
"primaryStoreEvent",
")",
"error",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"ev",
".",
"id",
"... | // handlePrimaryStoreEvent changes the PrimaryTranslateStore
// used for replication by TranslateFile. | [
"handlePrimaryStoreEvent",
"changes",
"the",
"PrimaryTranslateStore",
"used",
"for",
"replication",
"by",
"TranslateFile",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L212-L241 | train |
pilosa/pilosa | translate.go | Close | func (s *TranslateFile) Close() (err error) {
s.once.Do(func() {
close(s.closing)
if s.file != nil {
if e := s.file.Close(); e != nil && err == nil {
err = e
}
}
if s.data != nil {
if e := syscall.Munmap(s.data); e != nil && err == nil {
err = e
}
}
})
s.wg.Wait()
return err
} | go | func (s *TranslateFile) Close() (err error) {
s.once.Do(func() {
close(s.closing)
if s.file != nil {
if e := s.file.Close(); e != nil && err == nil {
err = e
}
}
if s.data != nil {
if e := syscall.Munmap(s.data); e != nil && err == nil {
err = e
}
}
})
s.wg.Wait()
return err
} | [
"func",
"(",
"s",
"*",
"TranslateFile",
")",
"Close",
"(",
")",
"(",
"err",
"error",
")",
"{",
"s",
".",
"once",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"close",
"(",
"s",
".",
"closing",
")",
"\n",
"if",
"s",
".",
"file",
"!=",
"nil",
"{",
... | // Close closes the translate file. | [
"Close",
"closes",
"the",
"translate",
"file",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L244-L261 | train |
pilosa/pilosa | translate.go | size | func (s *TranslateFile) size() int64 {
s.mu.RLock()
n := s.n
s.mu.RUnlock()
return n
} | go | func (s *TranslateFile) size() int64 {
s.mu.RLock()
n := s.n
s.mu.RUnlock()
return n
} | [
"func",
"(",
"s",
"*",
"TranslateFile",
")",
"size",
"(",
")",
"int64",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"n",
":=",
"s",
".",
"n",
"\n",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"n",
"\n",
"}"
] | // size returns the number of bytes in use in the data file. | [
"size",
"returns",
"the",
"number",
"of",
"bytes",
"in",
"use",
"in",
"the",
"data",
"file",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L269-L274 | train |
pilosa/pilosa | translate.go | WriteNotify | func (s *TranslateFile) WriteNotify() <-chan struct{} {
s.mu.RLock()
ch := s.writeNotify
s.mu.RUnlock()
return ch
} | go | func (s *TranslateFile) WriteNotify() <-chan struct{} {
s.mu.RLock()
ch := s.writeNotify
s.mu.RUnlock()
return ch
} | [
"func",
"(",
"s",
"*",
"TranslateFile",
")",
"WriteNotify",
"(",
")",
"<-",
"chan",
"struct",
"{",
"}",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"ch",
":=",
"s",
".",
"writeNotify",
"\n",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n"... | // WriteNotify returns a channel that is closed when a new entry is written. | [
"WriteNotify",
"returns",
"a",
"channel",
"that",
"is",
"closed",
"when",
"a",
"new",
"entry",
"is",
"written",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L282-L287 | train |
pilosa/pilosa | translate.go | monitorReplication | func (s *TranslateFile) monitorReplication() {
// Create context that will cancel on close.
ctx, cancel := context.WithCancel(context.Background())
go func() {
select {
case <-s.closing:
case <-s.replicationClosing:
}
cancel()
}()
// Keep attempting to replicate until the store closes.
for {
if err := s.replicate(ctx); err != nil {
s.logger.Printf("pilosa: replication error: %s", err)
}
select {
case <-ctx.Done():
return
case <-time.After(s.replicationRetryInterval):
s.logger.Printf("pilosa: reconnecting to primary replica")
}
}
} | go | func (s *TranslateFile) monitorReplication() {
// Create context that will cancel on close.
ctx, cancel := context.WithCancel(context.Background())
go func() {
select {
case <-s.closing:
case <-s.replicationClosing:
}
cancel()
}()
// Keep attempting to replicate until the store closes.
for {
if err := s.replicate(ctx); err != nil {
s.logger.Printf("pilosa: replication error: %s", err)
}
select {
case <-ctx.Done():
return
case <-time.After(s.replicationRetryInterval):
s.logger.Printf("pilosa: reconnecting to primary replica")
}
}
} | [
"func",
"(",
"s",
"*",
"TranslateFile",
")",
"monitorReplication",
"(",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithCancel",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"select",
"{",
"case",
"<... | // monitorReplication is executed in a separate goroutine and continually streams
// from the primary store until this store is closed. | [
"monitorReplication",
"is",
"executed",
"in",
"a",
"separate",
"goroutine",
"and",
"continually",
"streams",
"from",
"the",
"primary",
"store",
"until",
"this",
"store",
"is",
"closed",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L382-L405 | train |
pilosa/pilosa | translate.go | monitorPrimaryStoreEvents | func (s *TranslateFile) monitorPrimaryStoreEvents() {
// Keep handling events until the store closes.
for {
select {
case <-s.closing:
return
case ev := <-s.primaryStoreEvents:
if err := s.handlePrimaryStoreEvent(ev); err != nil {
s.logger.Printf("handle primary store event")
}
}
}
} | go | func (s *TranslateFile) monitorPrimaryStoreEvents() {
// Keep handling events until the store closes.
for {
select {
case <-s.closing:
return
case ev := <-s.primaryStoreEvents:
if err := s.handlePrimaryStoreEvent(ev); err != nil {
s.logger.Printf("handle primary store event")
}
}
}
} | [
"func",
"(",
"s",
"*",
"TranslateFile",
")",
"monitorPrimaryStoreEvents",
"(",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"<-",
"s",
".",
"closing",
":",
"return",
"\n",
"case",
"ev",
":=",
"<-",
"s",
".",
"primaryStoreEvents",
":",
"if",
"err",
":="... | // monitorPrimaryStoreEvents is executed in a separate goroutine and listens for changes
// to the primary store assignment. | [
"monitorPrimaryStoreEvents",
"is",
"executed",
"in",
"a",
"separate",
"goroutine",
"and",
"listens",
"for",
"changes",
"to",
"the",
"primary",
"store",
"assignment",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L409-L421 | train |
pilosa/pilosa | translate.go | TranslateColumnsToUint64 | func (s *TranslateFile) TranslateColumnsToUint64(index string, values []string) ([]uint64, error) {
ret := make([]uint64, len(values))
// Read value under read lock.
s.mu.RLock()
if idx := s.cols[index]; idx != nil {
var writeRequired bool
for i := range values {
v, ok := idx.idByKey([]byte(values[i]))
if !ok {
writeRequired = true
}
ret[i] = v
}
if !writeRequired {
s.mu.RUnlock()
return ret, nil
}
}
s.mu.RUnlock()
// Return error if not all values could be translated and this store is read-only.
if s.isReadOnly() {
return ret, ErrTranslateStoreReadOnly
}
// If any values not found then recheck and then add under a write lock.
s.mu.Lock()
defer s.mu.Unlock()
// Recheck if value was created between the read lock and write lock.
idx := s.cols[index]
if idx != nil {
var writeRequired bool
for i := range values {
if ret[i] != 0 {
continue
}
v, ok := idx.idByKey([]byte(values[i]))
if !ok {
writeRequired = true
continue
}
ret[i] = v
}
if !writeRequired {
return ret, nil
}
}
// Create index map if it doesn't exists.
if idx == nil {
idx = newIndex(s.data)
s.cols[index] = idx
}
// Append new identifiers to log.
entry := &LogEntry{
Type: LogEntryTypeInsertColumn,
Index: []byte(index),
IDs: make([]uint64, 0, len(values)),
Keys: make([][]byte, 0, len(values)),
}
check := make(map[string]uint64)
for i := range values {
if ret[i] != 0 {
continue
}
v, found := check[values[i]]
if !found {
idx.seq++
v = idx.seq
check[values[i]] = v
}
ret[i] = v
entry.IDs = append(entry.IDs, v)
entry.Keys = append(entry.Keys, []byte(values[i]))
}
// Write entry.
if err := s.appendEntry(entry); err != nil {
return nil, err
}
return ret, nil
} | go | func (s *TranslateFile) TranslateColumnsToUint64(index string, values []string) ([]uint64, error) {
ret := make([]uint64, len(values))
// Read value under read lock.
s.mu.RLock()
if idx := s.cols[index]; idx != nil {
var writeRequired bool
for i := range values {
v, ok := idx.idByKey([]byte(values[i]))
if !ok {
writeRequired = true
}
ret[i] = v
}
if !writeRequired {
s.mu.RUnlock()
return ret, nil
}
}
s.mu.RUnlock()
// Return error if not all values could be translated and this store is read-only.
if s.isReadOnly() {
return ret, ErrTranslateStoreReadOnly
}
// If any values not found then recheck and then add under a write lock.
s.mu.Lock()
defer s.mu.Unlock()
// Recheck if value was created between the read lock and write lock.
idx := s.cols[index]
if idx != nil {
var writeRequired bool
for i := range values {
if ret[i] != 0 {
continue
}
v, ok := idx.idByKey([]byte(values[i]))
if !ok {
writeRequired = true
continue
}
ret[i] = v
}
if !writeRequired {
return ret, nil
}
}
// Create index map if it doesn't exists.
if idx == nil {
idx = newIndex(s.data)
s.cols[index] = idx
}
// Append new identifiers to log.
entry := &LogEntry{
Type: LogEntryTypeInsertColumn,
Index: []byte(index),
IDs: make([]uint64, 0, len(values)),
Keys: make([][]byte, 0, len(values)),
}
check := make(map[string]uint64)
for i := range values {
if ret[i] != 0 {
continue
}
v, found := check[values[i]]
if !found {
idx.seq++
v = idx.seq
check[values[i]] = v
}
ret[i] = v
entry.IDs = append(entry.IDs, v)
entry.Keys = append(entry.Keys, []byte(values[i]))
}
// Write entry.
if err := s.appendEntry(entry); err != nil {
return nil, err
}
return ret, nil
} | [
"func",
"(",
"s",
"*",
"TranslateFile",
")",
"TranslateColumnsToUint64",
"(",
"index",
"string",
",",
"values",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"uint64",
",",
"error",
")",
"{",
"ret",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"len",
"(",
... | // TranslateColumnsToUint64 converts values to a uint64 id.
// If value does not have an associated id then one is created. | [
"TranslateColumnsToUint64",
"converts",
"values",
"to",
"a",
"uint64",
"id",
".",
"If",
"value",
"does",
"not",
"have",
"an",
"associated",
"id",
"then",
"one",
"is",
"created",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L496-L584 | train |
pilosa/pilosa | translate.go | TranslateRowToString | func (s *TranslateFile) TranslateRowToString(index, field string, id uint64) (string, error) {
s.mu.RLock()
if idx := s.rows[fieldKey{index, field}]; idx != nil {
if ret, ok := idx.keyByID(id); ok {
s.mu.RUnlock()
return string(ret), nil
}
}
s.mu.RUnlock()
return "", nil
} | go | func (s *TranslateFile) TranslateRowToString(index, field string, id uint64) (string, error) {
s.mu.RLock()
if idx := s.rows[fieldKey{index, field}]; idx != nil {
if ret, ok := idx.keyByID(id); ok {
s.mu.RUnlock()
return string(ret), nil
}
}
s.mu.RUnlock()
return "", nil
} | [
"func",
"(",
"s",
"*",
"TranslateFile",
")",
"TranslateRowToString",
"(",
"index",
",",
"field",
"string",
",",
"id",
"uint64",
")",
"(",
"string",
",",
"error",
")",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"if",
"idx",
":=",
"s",
".",
... | // TranslateRowToString translates a row ID to a string key. | [
"TranslateRowToString",
"translates",
"a",
"row",
"ID",
"to",
"a",
"string",
"key",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L693-L703 | train |
pilosa/pilosa | translate.go | Reader | func (s *TranslateFile) Reader(ctx context.Context, offset int64) (io.ReadCloser, error) {
rc := newTranslateFileReader(ctx, s, offset)
if err := rc.Open(); err != nil {
return nil, err
}
return rc, nil
} | go | func (s *TranslateFile) Reader(ctx context.Context, offset int64) (io.ReadCloser, error) {
rc := newTranslateFileReader(ctx, s, offset)
if err := rc.Open(); err != nil {
return nil, err
}
return rc, nil
} | [
"func",
"(",
"s",
"*",
"TranslateFile",
")",
"Reader",
"(",
"ctx",
"context",
".",
"Context",
",",
"offset",
"int64",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"rc",
":=",
"newTranslateFileReader",
"(",
"ctx",
",",
"s",
",",
"offset",
... | // Reader returns a reader that streams the underlying data file. | [
"Reader",
"returns",
"a",
"reader",
"that",
"streams",
"the",
"underlying",
"data",
"file",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L706-L712 | train |
pilosa/pilosa | translate.go | headerSize | func (e *LogEntry) headerSize() int64 {
sz := uVarintSize(e.Length) + // total entry length
1 + // type
uVarintSize(uint64(len(e.Index))) + len(e.Index) + // Index length and data
uVarintSize(uint64(len(e.Field))) + len(e.Field) + // Field length and data
uVarintSize(uint64(len(e.IDs))) // ID/Key pair count
return int64(sz)
} | go | func (e *LogEntry) headerSize() int64 {
sz := uVarintSize(e.Length) + // total entry length
1 + // type
uVarintSize(uint64(len(e.Index))) + len(e.Index) + // Index length and data
uVarintSize(uint64(len(e.Field))) + len(e.Field) + // Field length and data
uVarintSize(uint64(len(e.IDs))) // ID/Key pair count
return int64(sz)
} | [
"func",
"(",
"e",
"*",
"LogEntry",
")",
"headerSize",
"(",
")",
"int64",
"{",
"sz",
":=",
"uVarintSize",
"(",
"e",
".",
"Length",
")",
"+",
"1",
"+",
"uVarintSize",
"(",
"uint64",
"(",
"len",
"(",
"e",
".",
"Index",
")",
")",
")",
"+",
"len",
"... | // headerSize returns the number of bytes required for size, type, index, field, & pair count. | [
"headerSize",
"returns",
"the",
"number",
"of",
"bytes",
"required",
"for",
"size",
"type",
"index",
"field",
"&",
"pair",
"count",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L730-L737 | train |
pilosa/pilosa | translate.go | WriteTo | func (e *LogEntry) WriteTo(w io.Writer) (_ int64, err error) {
var buf bytes.Buffer
b := make([]byte, binary.MaxVarintLen64)
// Write the entry type.
if err := binary.Write(&buf, binary.BigEndian, e.Type); err != nil {
return 0, err
}
// Write the index name.
sz := binary.PutUvarint(b, uint64(len(e.Index)))
if _, err := buf.Write(b[:sz]); err != nil {
return 0, err
} else if _, err := buf.Write(e.Index); err != nil {
return 0, err
}
// Write field name.
sz = binary.PutUvarint(b, uint64(len(e.Field)))
if _, err := buf.Write(b[:sz]); err != nil {
return 0, err
} else if _, err := buf.Write(e.Field); err != nil {
return 0, err
}
// Write key count.
sz = binary.PutUvarint(b, uint64(len(e.IDs)))
if _, err := buf.Write(b[:sz]); err != nil {
return 0, err
}
// Write each id/key pairs.
for i := range e.Keys {
// Write identifier.
sz = binary.PutUvarint(b, e.IDs[i])
if _, err := buf.Write(b[:sz]); err != nil {
return 0, err
}
// Write key.
sz = binary.PutUvarint(b, uint64(len(e.Keys[i])))
if _, err := buf.Write(b[:sz]); err != nil {
return 0, err
} else if _, err := buf.Write(e.Keys[i]); err != nil {
return 0, err
}
}
// Write buffer size.
e.Length = uint64(buf.Len())
sz = binary.PutUvarint(b, e.Length)
if n, err := w.Write(b[:sz]); err != nil {
return int64(n), err
}
// Write buffer.
n, err := buf.WriteTo(w)
return int64(sz) + n, err
} | go | func (e *LogEntry) WriteTo(w io.Writer) (_ int64, err error) {
var buf bytes.Buffer
b := make([]byte, binary.MaxVarintLen64)
// Write the entry type.
if err := binary.Write(&buf, binary.BigEndian, e.Type); err != nil {
return 0, err
}
// Write the index name.
sz := binary.PutUvarint(b, uint64(len(e.Index)))
if _, err := buf.Write(b[:sz]); err != nil {
return 0, err
} else if _, err := buf.Write(e.Index); err != nil {
return 0, err
}
// Write field name.
sz = binary.PutUvarint(b, uint64(len(e.Field)))
if _, err := buf.Write(b[:sz]); err != nil {
return 0, err
} else if _, err := buf.Write(e.Field); err != nil {
return 0, err
}
// Write key count.
sz = binary.PutUvarint(b, uint64(len(e.IDs)))
if _, err := buf.Write(b[:sz]); err != nil {
return 0, err
}
// Write each id/key pairs.
for i := range e.Keys {
// Write identifier.
sz = binary.PutUvarint(b, e.IDs[i])
if _, err := buf.Write(b[:sz]); err != nil {
return 0, err
}
// Write key.
sz = binary.PutUvarint(b, uint64(len(e.Keys[i])))
if _, err := buf.Write(b[:sz]); err != nil {
return 0, err
} else if _, err := buf.Write(e.Keys[i]); err != nil {
return 0, err
}
}
// Write buffer size.
e.Length = uint64(buf.Len())
sz = binary.PutUvarint(b, e.Length)
if n, err := w.Write(b[:sz]); err != nil {
return int64(n), err
}
// Write buffer.
n, err := buf.WriteTo(w)
return int64(sz) + n, err
} | [
"func",
"(",
"e",
"*",
"LogEntry",
")",
"WriteTo",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"_",
"int64",
",",
"err",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"binary",
".",
... | // WriteTo serializes a LogEntry to w. | [
"WriteTo",
"serializes",
"a",
"LogEntry",
"to",
"w",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L817-L875 | train |
pilosa/pilosa | translate.go | validLogEntriesLen | func validLogEntriesLen(p []byte) (n int) {
r := bytes.NewReader(p)
for {
if sz, err := binary.ReadUvarint(r); err != nil {
return n
} else if off, err := r.Seek(int64(sz), io.SeekCurrent); err != nil {
return n
} else if off > int64(len(p)) {
return n
} else {
n = int(off)
}
}
} | go | func validLogEntriesLen(p []byte) (n int) {
r := bytes.NewReader(p)
for {
if sz, err := binary.ReadUvarint(r); err != nil {
return n
} else if off, err := r.Seek(int64(sz), io.SeekCurrent); err != nil {
return n
} else if off > int64(len(p)) {
return n
} else {
n = int(off)
}
}
} | [
"func",
"validLogEntriesLen",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
")",
"{",
"r",
":=",
"bytes",
".",
"NewReader",
"(",
"p",
")",
"\n",
"for",
"{",
"if",
"sz",
",",
"err",
":=",
"binary",
".",
"ReadUvarint",
"(",
"r",
")",
";",
"er... | // validLogEntriesLen returns the maximum length of p that contains valid entries. | [
"validLogEntriesLen",
"returns",
"the",
"maximum",
"length",
"of",
"p",
"that",
"contains",
"valid",
"entries",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L878-L891 | train |
pilosa/pilosa | translate.go | keyByID | func (idx *index) keyByID(id uint64) ([]byte, bool) {
offset, ok := idx.offsetsByID[id]
if !ok {
return nil, false
}
return idx.lookupKey(offset), true
} | go | func (idx *index) keyByID(id uint64) ([]byte, bool) {
offset, ok := idx.offsetsByID[id]
if !ok {
return nil, false
}
return idx.lookupKey(offset), true
} | [
"func",
"(",
"idx",
"*",
"index",
")",
"keyByID",
"(",
"id",
"uint64",
")",
"(",
"[",
"]",
"byte",
",",
"bool",
")",
"{",
"offset",
",",
"ok",
":=",
"idx",
".",
"offsetsByID",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
... | // keyByID returns the key for a given ID, if it exists. | [
"keyByID",
"returns",
"the",
"key",
"for",
"a",
"given",
"ID",
"if",
"it",
"exists",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L930-L936 | train |
pilosa/pilosa | translate.go | idByKey | func (idx *index) idByKey(key []byte) (uint64, bool) {
hash := hashKey(key)
pos := hash & idx.mask
var dist uint64
for {
if e := &idx.elems[pos]; e.hash == 0 {
return 0, false
} else if dist > idx.dist(e.hash, pos) {
return 0, false
} else if e.hash == hash && bytes.Equal(idx.lookupKey(e.offset), key) {
return e.id, true
}
pos = (pos + 1) & idx.mask
dist++
}
} | go | func (idx *index) idByKey(key []byte) (uint64, bool) {
hash := hashKey(key)
pos := hash & idx.mask
var dist uint64
for {
if e := &idx.elems[pos]; e.hash == 0 {
return 0, false
} else if dist > idx.dist(e.hash, pos) {
return 0, false
} else if e.hash == hash && bytes.Equal(idx.lookupKey(e.offset), key) {
return e.id, true
}
pos = (pos + 1) & idx.mask
dist++
}
} | [
"func",
"(",
"idx",
"*",
"index",
")",
"idByKey",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"uint64",
",",
"bool",
")",
"{",
"hash",
":=",
"hashKey",
"(",
"key",
")",
"\n",
"pos",
":=",
"hash",
"&",
"idx",
".",
"mask",
"\n",
"var",
"dist",
"uint6... | // idByKey returns the ID for a given key, if it exists. | [
"idByKey",
"returns",
"the",
"ID",
"for",
"a",
"given",
"key",
"if",
"it",
"exists",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L939-L956 | train |
pilosa/pilosa | translate.go | insertIDbyOffset | func (idx *index) insertIDbyOffset(offset int64, id uint64) (overwritten bool) {
key := idx.lookupKey(offset)
hash := hashKey(key)
pos := hash & idx.mask
var dist uint64
for {
e := &idx.elems[pos]
// Exit if a matching or empty slot exists.
if e.hash == 0 {
e.hash, e.offset, e.id = hash, offset, id
return false
} else if bytes.Equal(idx.lookupKey(e.offset), key) {
e.hash, e.offset, e.id = hash, offset, id
return true
}
// Swap if current element has a lower probe distance.
d := idx.dist(e.hash, pos)
if d < dist {
hash, e.hash = e.hash, hash
offset, e.offset = e.offset, offset
id, e.id = e.id, id
dist = d
}
// Move position forward.
pos = (pos + 1) & idx.mask
dist++
}
} | go | func (idx *index) insertIDbyOffset(offset int64, id uint64) (overwritten bool) {
key := idx.lookupKey(offset)
hash := hashKey(key)
pos := hash & idx.mask
var dist uint64
for {
e := &idx.elems[pos]
// Exit if a matching or empty slot exists.
if e.hash == 0 {
e.hash, e.offset, e.id = hash, offset, id
return false
} else if bytes.Equal(idx.lookupKey(e.offset), key) {
e.hash, e.offset, e.id = hash, offset, id
return true
}
// Swap if current element has a lower probe distance.
d := idx.dist(e.hash, pos)
if d < dist {
hash, e.hash = e.hash, hash
offset, e.offset = e.offset, offset
id, e.id = e.id, id
dist = d
}
// Move position forward.
pos = (pos + 1) & idx.mask
dist++
}
} | [
"func",
"(",
"idx",
"*",
"index",
")",
"insertIDbyOffset",
"(",
"offset",
"int64",
",",
"id",
"uint64",
")",
"(",
"overwritten",
"bool",
")",
"{",
"key",
":=",
"idx",
".",
"lookupKey",
"(",
"offset",
")",
"\n",
"hash",
":=",
"hashKey",
"(",
"key",
")... | // insertIDbyOffset writes to the RHH id-by-offset map. | [
"insertIDbyOffset",
"writes",
"to",
"the",
"RHH",
"id",
"-",
"by",
"-",
"offset",
"map",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L987-L1018 | train |
pilosa/pilosa | translate.go | lookupKey | func (idx *index) lookupKey(offset int64) []byte {
data := idx.data[offset:]
n, sz := binary.Uvarint(data)
if sz == 0 {
return nil
}
return data[sz : sz+int(n)]
} | go | func (idx *index) lookupKey(offset int64) []byte {
data := idx.data[offset:]
n, sz := binary.Uvarint(data)
if sz == 0 {
return nil
}
return data[sz : sz+int(n)]
} | [
"func",
"(",
"idx",
"*",
"index",
")",
"lookupKey",
"(",
"offset",
"int64",
")",
"[",
"]",
"byte",
"{",
"data",
":=",
"idx",
".",
"data",
"[",
"offset",
":",
"]",
"\n",
"n",
",",
"sz",
":=",
"binary",
".",
"Uvarint",
"(",
"data",
")",
"\n",
"if... | // lookupKey returns the key at the given offset in the memory-mapped file. | [
"lookupKey",
"returns",
"the",
"key",
"at",
"the",
"given",
"offset",
"in",
"the",
"memory",
"-",
"mapped",
"file",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1021-L1028 | train |
pilosa/pilosa | translate.go | newTranslateFileReader | func newTranslateFileReader(ctx context.Context, store *TranslateFile, offset int64) *translateFileReader {
return &translateFileReader{
ctx: ctx,
store: store,
offset: offset,
notify: store.WriteNotify(),
closing: make(chan struct{}),
}
} | go | func newTranslateFileReader(ctx context.Context, store *TranslateFile, offset int64) *translateFileReader {
return &translateFileReader{
ctx: ctx,
store: store,
offset: offset,
notify: store.WriteNotify(),
closing: make(chan struct{}),
}
} | [
"func",
"newTranslateFileReader",
"(",
"ctx",
"context",
".",
"Context",
",",
"store",
"*",
"TranslateFile",
",",
"offset",
"int64",
")",
"*",
"translateFileReader",
"{",
"return",
"&",
"translateFileReader",
"{",
"ctx",
":",
"ctx",
",",
"store",
":",
"store",... | // newTranslateFileReader returns a new instance of translateFileReader. | [
"newTranslateFileReader",
"returns",
"a",
"new",
"instance",
"of",
"translateFileReader",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1076-L1084 | train |
pilosa/pilosa | translate.go | Open | func (r *translateFileReader) Open() (err error) {
r.file, err = os.Open(r.store.Path)
return err
} | go | func (r *translateFileReader) Open() (err error) {
r.file, err = os.Open(r.store.Path)
return err
} | [
"func",
"(",
"r",
"*",
"translateFileReader",
")",
"Open",
"(",
")",
"(",
"err",
"error",
")",
"{",
"r",
".",
"file",
",",
"err",
"=",
"os",
".",
"Open",
"(",
"r",
".",
"store",
".",
"Path",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Open initializes the reader. | [
"Open",
"initializes",
"the",
"reader",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1087-L1090 | train |
pilosa/pilosa | translate.go | Close | func (r *translateFileReader) Close() error {
r.once.Do(func() { close(r.closing) })
if r.file != nil {
return r.file.Close()
}
return nil
} | go | func (r *translateFileReader) Close() error {
r.once.Do(func() { close(r.closing) })
if r.file != nil {
return r.file.Close()
}
return nil
} | [
"func",
"(",
"r",
"*",
"translateFileReader",
")",
"Close",
"(",
")",
"error",
"{",
"r",
".",
"once",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"close",
"(",
"r",
".",
"closing",
")",
"}",
")",
"\n",
"if",
"r",
".",
"file",
"!=",
"nil",
"{",
"re... | // Close closes the underlying file reader. | [
"Close",
"closes",
"the",
"underlying",
"file",
"reader",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1093-L1100 | train |
pilosa/pilosa | translate.go | Read | func (r *translateFileReader) Read(p []byte) (n int, err error) {
for {
// Obtain notification channel before we check for new data.
notify := r.store.WriteNotify()
// Exit if we can read one or more valid entries or we receive an error.
if n, err = r.read(p); n > 0 || err != nil {
return n, err
}
// Wait for new data or close.
select {
case <-r.ctx.Done():
return 0, r.ctx.Err()
case <-r.closing:
return 0, ErrTranslateStoreReaderClosed
case <-r.store.Closing():
return 0, ErrTranslateStoreClosed
case <-notify:
continue
}
}
} | go | func (r *translateFileReader) Read(p []byte) (n int, err error) {
for {
// Obtain notification channel before we check for new data.
notify := r.store.WriteNotify()
// Exit if we can read one or more valid entries or we receive an error.
if n, err = r.read(p); n > 0 || err != nil {
return n, err
}
// Wait for new data or close.
select {
case <-r.ctx.Done():
return 0, r.ctx.Err()
case <-r.closing:
return 0, ErrTranslateStoreReaderClosed
case <-r.store.Closing():
return 0, ErrTranslateStoreClosed
case <-notify:
continue
}
}
} | [
"func",
"(",
"r",
"*",
"translateFileReader",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"for",
"{",
"notify",
":=",
"r",
".",
"store",
".",
"WriteNotify",
"(",
")",
"\n",
"if",
"n",
",",
"err"... | // Read reads the next section of the available data to p. This should always
// read from the start of an entry and read n bytes to the end of another entry. | [
"Read",
"reads",
"the",
"next",
"section",
"of",
"the",
"available",
"data",
"to",
"p",
".",
"This",
"should",
"always",
"read",
"from",
"the",
"start",
"of",
"an",
"entry",
"and",
"read",
"n",
"bytes",
"to",
"the",
"end",
"of",
"another",
"entry",
"."... | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1104-L1126 | train |
pilosa/pilosa | translate.go | read | func (r *translateFileReader) read(p []byte) (n int, err error) {
sz := r.store.size()
// Exit if there is no new data.
if sz < r.offset {
return 0, fmt.Errorf("pilosa: translate store reader past file size: sz=%d off=%d", sz, r.offset)
} else if sz == r.offset {
return 0, nil
}
if max := sz - r.offset; max > int64(len(p)) {
// If p is not large enough to hold a single entry,
// return an error so the client can increase the
// size of p and try again.
return 0, ErrTranslateReadTargetUndersized
} else if int64(len(p)) > max {
// Shorten buffer to maximum read size.
p = p[:max]
}
// Read data from file at offset.
// Limit the number of bytes read to only whole entries.
n, err = r.file.ReadAt(p, r.offset)
n = validLogEntriesLen(p[:n])
r.offset += int64(n)
return n, err
} | go | func (r *translateFileReader) read(p []byte) (n int, err error) {
sz := r.store.size()
// Exit if there is no new data.
if sz < r.offset {
return 0, fmt.Errorf("pilosa: translate store reader past file size: sz=%d off=%d", sz, r.offset)
} else if sz == r.offset {
return 0, nil
}
if max := sz - r.offset; max > int64(len(p)) {
// If p is not large enough to hold a single entry,
// return an error so the client can increase the
// size of p and try again.
return 0, ErrTranslateReadTargetUndersized
} else if int64(len(p)) > max {
// Shorten buffer to maximum read size.
p = p[:max]
}
// Read data from file at offset.
// Limit the number of bytes read to only whole entries.
n, err = r.file.ReadAt(p, r.offset)
n = validLogEntriesLen(p[:n])
r.offset += int64(n)
return n, err
} | [
"func",
"(",
"r",
"*",
"translateFileReader",
")",
"read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"sz",
":=",
"r",
".",
"store",
".",
"size",
"(",
")",
"\n",
"if",
"sz",
"<",
"r",
".",
"offset",
"{",
... | // read writes the bytes for zero or more valid entries to p. | [
"read",
"writes",
"the",
"bytes",
"for",
"zero",
"or",
"more",
"valid",
"entries",
"to",
"p",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1129-L1155 | train |
pilosa/pilosa | translate.go | TranslateColumnToString | func (s nopTranslateStore) TranslateColumnToString(index string, values uint64) (string, error) {
return "", nil
} | go | func (s nopTranslateStore) TranslateColumnToString(index string, values uint64) (string, error) {
return "", nil
} | [
"func",
"(",
"s",
"nopTranslateStore",
")",
"TranslateColumnToString",
"(",
"index",
"string",
",",
"values",
"uint64",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"\"\"",
",",
"nil",
"\n",
"}"
] | // TranslateColumnToString is a no-op implementation of the TranslateStore TranslateColumnToString method. | [
"TranslateColumnToString",
"is",
"a",
"no",
"-",
"op",
"implementation",
"of",
"the",
"TranslateStore",
"TranslateColumnToString",
"method",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1182-L1184 | train |
pilosa/pilosa | translate.go | TranslateRowsToUint64 | func (s nopTranslateStore) TranslateRowsToUint64(index, field string, values []string) ([]uint64, error) {
return []uint64{}, nil
} | go | func (s nopTranslateStore) TranslateRowsToUint64(index, field string, values []string) ([]uint64, error) {
return []uint64{}, nil
} | [
"func",
"(",
"s",
"nopTranslateStore",
")",
"TranslateRowsToUint64",
"(",
"index",
",",
"field",
"string",
",",
"values",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"uint64",
",",
"error",
")",
"{",
"return",
"[",
"]",
"uint64",
"{",
"}",
",",
"nil",
"\... | // TranslateRowsToUint64 is a no-op implementation of the TranslateStore TranslateRowsToUint64 method. | [
"TranslateRowsToUint64",
"is",
"a",
"no",
"-",
"op",
"implementation",
"of",
"the",
"TranslateStore",
"TranslateRowsToUint64",
"method",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1187-L1189 | train |
pilosa/pilosa | translate.go | Reader | func (s nopTranslateStore) Reader(ctx context.Context, off int64) (io.ReadCloser, error) {
return ioutil.NopCloser(bytes.NewReader(nil)), nil
} | go | func (s nopTranslateStore) Reader(ctx context.Context, off int64) (io.ReadCloser, error) {
return ioutil.NopCloser(bytes.NewReader(nil)), nil
} | [
"func",
"(",
"s",
"nopTranslateStore",
")",
"Reader",
"(",
"ctx",
"context",
".",
"Context",
",",
"off",
"int64",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"return",
"ioutil",
".",
"NopCloser",
"(",
"bytes",
".",
"NewReader",
"(",
"nil... | // Reader is a no-op implementation of the TranslateStore Reader method. | [
"Reader",
"is",
"a",
"no",
"-",
"op",
"implementation",
"of",
"the",
"TranslateStore",
"Reader",
"method",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1197-L1199 | train |
pilosa/pilosa | server/setup_logger.go | setupLogger | func (m *Command) setupLogger() error {
if m.Config.LogPath == "" {
m.logOutput = m.Stderr
} else {
f, err := os.OpenFile(m.Config.LogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
if err != nil {
return errors.Wrap(err, "opening file")
}
m.logOutput = f
err = syscall.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
if err != nil {
return errors.Wrap(err, "dup2ing stderr onto logfile")
}
}
if m.Config.Verbose {
m.logger = logger.NewVerboseLogger(m.logOutput)
} else {
m.logger = logger.NewStandardLogger(m.logOutput)
}
return nil
} | go | func (m *Command) setupLogger() error {
if m.Config.LogPath == "" {
m.logOutput = m.Stderr
} else {
f, err := os.OpenFile(m.Config.LogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
if err != nil {
return errors.Wrap(err, "opening file")
}
m.logOutput = f
err = syscall.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
if err != nil {
return errors.Wrap(err, "dup2ing stderr onto logfile")
}
}
if m.Config.Verbose {
m.logger = logger.NewVerboseLogger(m.logOutput)
} else {
m.logger = logger.NewStandardLogger(m.logOutput)
}
return nil
} | [
"func",
"(",
"m",
"*",
"Command",
")",
"setupLogger",
"(",
")",
"error",
"{",
"if",
"m",
".",
"Config",
".",
"LogPath",
"==",
"\"\"",
"{",
"m",
".",
"logOutput",
"=",
"m",
".",
"Stderr",
"\n",
"}",
"else",
"{",
"f",
",",
"err",
":=",
"os",
".",... | // setupLogger sets up the logger based on the configuration. | [
"setupLogger",
"sets",
"up",
"the",
"logger",
"based",
"on",
"the",
"configuration",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server/setup_logger.go#L28-L49 | train |
pilosa/pilosa | field.go | OptFieldTypeDefault | func OptFieldTypeDefault() FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeSet
fo.CacheType = DefaultCacheType
fo.CacheSize = DefaultCacheSize
return nil
}
} | go | func OptFieldTypeDefault() FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeSet
fo.CacheType = DefaultCacheType
fo.CacheSize = DefaultCacheSize
return nil
}
} | [
"func",
"OptFieldTypeDefault",
"(",
")",
"FieldOption",
"{",
"return",
"func",
"(",
"fo",
"*",
"FieldOptions",
")",
"error",
"{",
"if",
"fo",
".",
"Type",
"!=",
"\"\"",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"field type is already set to: %s\"",
",",
... | // OptFieldTypeDefault is a functional option on FieldOptions
// used to set the field type and cache setting to the default values. | [
"OptFieldTypeDefault",
"is",
"a",
"functional",
"option",
"on",
"FieldOptions",
"used",
"to",
"set",
"the",
"field",
"type",
"and",
"cache",
"setting",
"to",
"the",
"default",
"values",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L103-L113 | train |
pilosa/pilosa | field.go | OptFieldTypeSet | func OptFieldTypeSet(cacheType string, cacheSize uint32) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeSet
fo.CacheType = cacheType
fo.CacheSize = cacheSize
return nil
}
} | go | func OptFieldTypeSet(cacheType string, cacheSize uint32) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeSet
fo.CacheType = cacheType
fo.CacheSize = cacheSize
return nil
}
} | [
"func",
"OptFieldTypeSet",
"(",
"cacheType",
"string",
",",
"cacheSize",
"uint32",
")",
"FieldOption",
"{",
"return",
"func",
"(",
"fo",
"*",
"FieldOptions",
")",
"error",
"{",
"if",
"fo",
".",
"Type",
"!=",
"\"\"",
"{",
"return",
"errors",
".",
"Errorf",
... | // OptFieldTypeSet is a functional option on FieldOptions
// used to specify the field as being type `set` and to
// provide any respective configuration values. | [
"OptFieldTypeSet",
"is",
"a",
"functional",
"option",
"on",
"FieldOptions",
"used",
"to",
"specify",
"the",
"field",
"as",
"being",
"type",
"set",
"and",
"to",
"provide",
"any",
"respective",
"configuration",
"values",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L118-L128 | train |
pilosa/pilosa | field.go | OptFieldTypeInt | func OptFieldTypeInt(min, max int64) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
if min > max {
return ErrInvalidBSIGroupRange
}
fo.Type = FieldTypeInt
fo.Min = min
fo.Max = max
return nil
}
} | go | func OptFieldTypeInt(min, max int64) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
if min > max {
return ErrInvalidBSIGroupRange
}
fo.Type = FieldTypeInt
fo.Min = min
fo.Max = max
return nil
}
} | [
"func",
"OptFieldTypeInt",
"(",
"min",
",",
"max",
"int64",
")",
"FieldOption",
"{",
"return",
"func",
"(",
"fo",
"*",
"FieldOptions",
")",
"error",
"{",
"if",
"fo",
".",
"Type",
"!=",
"\"\"",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"field type is... | // OptFieldTypeInt is a functional option on FieldOptions
// used to specify the field as being type `int` and to
// provide any respective configuration values. | [
"OptFieldTypeInt",
"is",
"a",
"functional",
"option",
"on",
"FieldOptions",
"used",
"to",
"specify",
"the",
"field",
"as",
"being",
"type",
"int",
"and",
"to",
"provide",
"any",
"respective",
"configuration",
"values",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L133-L146 | train |
pilosa/pilosa | field.go | OptFieldTypeTime | func OptFieldTypeTime(timeQuantum TimeQuantum, opt ...bool) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
if !timeQuantum.Valid() {
return ErrInvalidTimeQuantum
}
fo.Type = FieldTypeTime
fo.TimeQuantum = timeQuantum
fo.NoStandardView = len(opt) >= 1 && opt[0]
return nil
}
} | go | func OptFieldTypeTime(timeQuantum TimeQuantum, opt ...bool) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
if !timeQuantum.Valid() {
return ErrInvalidTimeQuantum
}
fo.Type = FieldTypeTime
fo.TimeQuantum = timeQuantum
fo.NoStandardView = len(opt) >= 1 && opt[0]
return nil
}
} | [
"func",
"OptFieldTypeTime",
"(",
"timeQuantum",
"TimeQuantum",
",",
"opt",
"...",
"bool",
")",
"FieldOption",
"{",
"return",
"func",
"(",
"fo",
"*",
"FieldOptions",
")",
"error",
"{",
"if",
"fo",
".",
"Type",
"!=",
"\"\"",
"{",
"return",
"errors",
".",
"... | // OptFieldTypeTime is a functional option on FieldOptions
// used to specify the field as being type `time` and to
// provide any respective configuration values.
// Pass true to skip creation of the standard view. | [
"OptFieldTypeTime",
"is",
"a",
"functional",
"option",
"on",
"FieldOptions",
"used",
"to",
"specify",
"the",
"field",
"as",
"being",
"type",
"time",
"and",
"to",
"provide",
"any",
"respective",
"configuration",
"values",
".",
"Pass",
"true",
"to",
"skip",
"cre... | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L152-L165 | train |
pilosa/pilosa | field.go | OptFieldTypeMutex | func OptFieldTypeMutex(cacheType string, cacheSize uint32) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeMutex
fo.CacheType = cacheType
fo.CacheSize = cacheSize
return nil
}
} | go | func OptFieldTypeMutex(cacheType string, cacheSize uint32) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeMutex
fo.CacheType = cacheType
fo.CacheSize = cacheSize
return nil
}
} | [
"func",
"OptFieldTypeMutex",
"(",
"cacheType",
"string",
",",
"cacheSize",
"uint32",
")",
"FieldOption",
"{",
"return",
"func",
"(",
"fo",
"*",
"FieldOptions",
")",
"error",
"{",
"if",
"fo",
".",
"Type",
"!=",
"\"\"",
"{",
"return",
"errors",
".",
"Errorf"... | // OptFieldTypeMutex is a functional option on FieldOptions
// used to specify the field as being type `mutex` and to
// provide any respective configuration values. | [
"OptFieldTypeMutex",
"is",
"a",
"functional",
"option",
"on",
"FieldOptions",
"used",
"to",
"specify",
"the",
"field",
"as",
"being",
"type",
"mutex",
"and",
"to",
"provide",
"any",
"respective",
"configuration",
"values",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L170-L180 | train |
pilosa/pilosa | field.go | OptFieldTypeBool | func OptFieldTypeBool() FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeBool
return nil
}
} | go | func OptFieldTypeBool() FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeBool
return nil
}
} | [
"func",
"OptFieldTypeBool",
"(",
")",
"FieldOption",
"{",
"return",
"func",
"(",
"fo",
"*",
"FieldOptions",
")",
"error",
"{",
"if",
"fo",
".",
"Type",
"!=",
"\"\"",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"field type is already set to: %s\"",
",",
"f... | // OptFieldTypeBool is a functional option on FieldOptions
// used to specify the field as being type `bool` and to
// provide any respective configuration values. | [
"OptFieldTypeBool",
"is",
"a",
"functional",
"option",
"on",
"FieldOptions",
"used",
"to",
"specify",
"the",
"field",
"as",
"being",
"type",
"bool",
"and",
"to",
"provide",
"any",
"respective",
"configuration",
"values",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L185-L193 | train |
pilosa/pilosa | field.go | NewField | func NewField(path, index, name string, opts FieldOption) (*Field, error) {
err := validateName(name)
if err != nil {
return nil, errors.Wrap(err, "validating name")
}
return newField(path, index, name, opts)
} | go | func NewField(path, index, name string, opts FieldOption) (*Field, error) {
err := validateName(name)
if err != nil {
return nil, errors.Wrap(err, "validating name")
}
return newField(path, index, name, opts)
} | [
"func",
"NewField",
"(",
"path",
",",
"index",
",",
"name",
"string",
",",
"opts",
"FieldOption",
")",
"(",
"*",
"Field",
",",
"error",
")",
"{",
"err",
":=",
"validateName",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"... | // NewField returns a new instance of field. | [
"NewField",
"returns",
"a",
"new",
"instance",
"of",
"field",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L196-L203 | train |
pilosa/pilosa | field.go | AvailableShards | func (f *Field) AvailableShards() *roaring.Bitmap {
f.mu.RLock()
defer f.mu.RUnlock()
b := f.remoteAvailableShards.Clone()
for _, view := range f.viewMap {
b = b.Union(view.availableShards())
}
return b
} | go | func (f *Field) AvailableShards() *roaring.Bitmap {
f.mu.RLock()
defer f.mu.RUnlock()
b := f.remoteAvailableShards.Clone()
for _, view := range f.viewMap {
b = b.Union(view.availableShards())
}
return b
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"AvailableShards",
"(",
")",
"*",
"roaring",
".",
"Bitmap",
"{",
"f",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"b",
":=",
"f",
".",
"remoteAvailableShar... | // AvailableShards returns a bitmap of shards that contain data. | [
"AvailableShards",
"returns",
"a",
"bitmap",
"of",
"shards",
"that",
"contain",
"data",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L248-L257 | train |
pilosa/pilosa | field.go | AddRemoteAvailableShards | func (f *Field) AddRemoteAvailableShards(b *roaring.Bitmap) error {
f.mergeRemoteAvailableShards(b)
// Save the updated bitmap to the data store.
return f.saveAvailableShards()
} | go | func (f *Field) AddRemoteAvailableShards(b *roaring.Bitmap) error {
f.mergeRemoteAvailableShards(b)
// Save the updated bitmap to the data store.
return f.saveAvailableShards()
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"AddRemoteAvailableShards",
"(",
"b",
"*",
"roaring",
".",
"Bitmap",
")",
"error",
"{",
"f",
".",
"mergeRemoteAvailableShards",
"(",
"b",
")",
"\n",
"return",
"f",
".",
"saveAvailableShards",
"(",
")",
"\n",
"}"
] | // AddRemoteAvailableShards merges the set of available shards into the current known set
// and saves the set to a file. | [
"AddRemoteAvailableShards",
"merges",
"the",
"set",
"of",
"available",
"shards",
"into",
"the",
"current",
"known",
"set",
"and",
"saves",
"the",
"set",
"to",
"a",
"file",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L261-L265 | train |
pilosa/pilosa | field.go | mergeRemoteAvailableShards | func (f *Field) mergeRemoteAvailableShards(b *roaring.Bitmap) {
f.mu.Lock()
defer f.mu.Unlock()
f.remoteAvailableShards = f.remoteAvailableShards.Union(b)
} | go | func (f *Field) mergeRemoteAvailableShards(b *roaring.Bitmap) {
f.mu.Lock()
defer f.mu.Unlock()
f.remoteAvailableShards = f.remoteAvailableShards.Union(b)
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"mergeRemoteAvailableShards",
"(",
"b",
"*",
"roaring",
".",
"Bitmap",
")",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"f",
".",
"remoteAvailableSha... | // mergeRemoteAvailableShards merges the set of available shards into the current known set. | [
"mergeRemoteAvailableShards",
"merges",
"the",
"set",
"of",
"available",
"shards",
"into",
"the",
"current",
"known",
"set",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L268-L272 | train |
pilosa/pilosa | field.go | loadAvailableShards | func (f *Field) loadAvailableShards() error {
bm := roaring.NewBitmap()
// Read data from meta file.
path := filepath.Join(f.path, ".available.shards")
buf, err := ioutil.ReadFile(path)
if os.IsNotExist(err) {
return nil
} else if err != nil {
return errors.Wrap(err, "reading available shards")
} else {
if err := bm.UnmarshalBinary(buf); err != nil {
return errors.Wrap(err, "unmarshaling")
}
}
// Merge bitmap from file into field.
f.mergeRemoteAvailableShards(bm)
return nil
} | go | func (f *Field) loadAvailableShards() error {
bm := roaring.NewBitmap()
// Read data from meta file.
path := filepath.Join(f.path, ".available.shards")
buf, err := ioutil.ReadFile(path)
if os.IsNotExist(err) {
return nil
} else if err != nil {
return errors.Wrap(err, "reading available shards")
} else {
if err := bm.UnmarshalBinary(buf); err != nil {
return errors.Wrap(err, "unmarshaling")
}
}
// Merge bitmap from file into field.
f.mergeRemoteAvailableShards(bm)
return nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"loadAvailableShards",
"(",
")",
"error",
"{",
"bm",
":=",
"roaring",
".",
"NewBitmap",
"(",
")",
"\n",
"path",
":=",
"filepath",
".",
"Join",
"(",
"f",
".",
"path",
",",
"\".available.shards\"",
")",
"\n",
"buf",
... | // loadAvailableShards reads remoteAvailableShards data for the field, if any. | [
"loadAvailableShards",
"reads",
"remoteAvailableShards",
"data",
"for",
"the",
"field",
"if",
"any",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L275-L293 | train |
pilosa/pilosa | field.go | saveAvailableShards | func (f *Field) saveAvailableShards() error {
f.mu.Lock()
defer f.mu.Unlock()
return f.unprotectedSaveAvailableShards()
} | go | func (f *Field) saveAvailableShards() error {
f.mu.Lock()
defer f.mu.Unlock()
return f.unprotectedSaveAvailableShards()
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"saveAvailableShards",
"(",
")",
"error",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"f",
".",
"unprotectedSaveAvailableShards",
"(",
")",
... | // saveAvailableShards writes remoteAvailableShards data for the field. | [
"saveAvailableShards",
"writes",
"remoteAvailableShards",
"data",
"for",
"the",
"field",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L296-L300 | train |
pilosa/pilosa | field.go | Type | func (f *Field) Type() string {
f.mu.RLock()
defer f.mu.RUnlock()
return f.options.Type
} | go | func (f *Field) Type() string {
f.mu.RLock()
defer f.mu.RUnlock()
return f.options.Type
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Type",
"(",
")",
"string",
"{",
"f",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"f",
".",
"options",
".",
"Type",
"\n",
"}"
] | // Type returns the field type. | [
"Type",
"returns",
"the",
"field",
"type",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L339-L343 | train |
pilosa/pilosa | field.go | SetCacheSize | func (f *Field) SetCacheSize(v uint32) error {
f.mu.Lock()
defer f.mu.Unlock()
// Ignore if no change occurred.
if v == 0 || f.options.CacheSize == v {
return nil
}
// Persist meta data to disk on change.
f.options.CacheSize = v
if err := f.saveMeta(); err != nil {
return errors.Wrap(err, "saving")
}
return nil
} | go | func (f *Field) SetCacheSize(v uint32) error {
f.mu.Lock()
defer f.mu.Unlock()
// Ignore if no change occurred.
if v == 0 || f.options.CacheSize == v {
return nil
}
// Persist meta data to disk on change.
f.options.CacheSize = v
if err := f.saveMeta(); err != nil {
return errors.Wrap(err, "saving")
}
return nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"SetCacheSize",
"(",
"v",
"uint32",
")",
"error",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"v",
"==",
"0",
"||",
"f",
".",
"options",
... | // SetCacheSize sets the cache size for ranked fames. Persists to meta file on update.
// defaults to DefaultCacheSize 50000 | [
"SetCacheSize",
"sets",
"the",
"cache",
"size",
"for",
"ranked",
"fames",
".",
"Persists",
"to",
"meta",
"file",
"on",
"update",
".",
"defaults",
"to",
"DefaultCacheSize",
"50000"
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L347-L363 | train |
pilosa/pilosa | field.go | CacheSize | func (f *Field) CacheSize() uint32 {
f.mu.RLock()
v := f.options.CacheSize
f.mu.RUnlock()
return v
} | go | func (f *Field) CacheSize() uint32 {
f.mu.RLock()
v := f.options.CacheSize
f.mu.RUnlock()
return v
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"CacheSize",
"(",
")",
"uint32",
"{",
"f",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"v",
":=",
"f",
".",
"options",
".",
"CacheSize",
"\n",
"f",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"v",
"\... | // CacheSize returns the ranked field cache size. | [
"CacheSize",
"returns",
"the",
"ranked",
"field",
"cache",
"size",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L366-L371 | train |
pilosa/pilosa | field.go | Options | func (f *Field) Options() FieldOptions {
f.mu.RLock()
defer f.mu.RUnlock()
return f.options
} | go | func (f *Field) Options() FieldOptions {
f.mu.RLock()
defer f.mu.RUnlock()
return f.options
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Options",
"(",
")",
"FieldOptions",
"{",
"f",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"f",
".",
"options",
"\n",
"}"
] | // Options returns all options for this field. | [
"Options",
"returns",
"all",
"options",
"for",
"this",
"field",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L374-L378 | train |
pilosa/pilosa | field.go | Open | func (f *Field) Open() error {
if err := func() error {
// Ensure the field's path exists.
f.logger.Debugf("ensure field path exists: %s", f.path)
if err := os.MkdirAll(f.path, 0777); err != nil {
return errors.Wrap(err, "creating field dir")
}
f.logger.Debugf("load meta file for index/field: %s/%s", f.index, f.name)
if err := f.loadMeta(); err != nil {
return errors.Wrap(err, "loading meta")
}
f.logger.Debugf("load available shards for index/field: %s/%s", f.index, f.name)
if err := f.loadAvailableShards(); err != nil {
return errors.Wrap(err, "loading available shards")
}
// Apply the field options loaded from meta.
f.logger.Debugf("apply options for index/field: %s/%s", f.index, f.name)
if err := f.applyOptions(f.options); err != nil {
return errors.Wrap(err, "applying options")
}
f.logger.Debugf("open views for index/field: %s/%s", f.index, f.name)
if err := f.openViews(); err != nil {
return errors.Wrap(err, "opening views")
}
f.logger.Debugf("open row attribute store for index/field: %s/%s", f.index, f.name)
if err := f.rowAttrStore.Open(); err != nil {
return errors.Wrap(err, "opening attrstore")
}
return nil
}(); err != nil {
f.Close()
return err
}
f.logger.Debugf("successfully opened field index/field: %s/%s", f.index, f.name)
return nil
} | go | func (f *Field) Open() error {
if err := func() error {
// Ensure the field's path exists.
f.logger.Debugf("ensure field path exists: %s", f.path)
if err := os.MkdirAll(f.path, 0777); err != nil {
return errors.Wrap(err, "creating field dir")
}
f.logger.Debugf("load meta file for index/field: %s/%s", f.index, f.name)
if err := f.loadMeta(); err != nil {
return errors.Wrap(err, "loading meta")
}
f.logger.Debugf("load available shards for index/field: %s/%s", f.index, f.name)
if err := f.loadAvailableShards(); err != nil {
return errors.Wrap(err, "loading available shards")
}
// Apply the field options loaded from meta.
f.logger.Debugf("apply options for index/field: %s/%s", f.index, f.name)
if err := f.applyOptions(f.options); err != nil {
return errors.Wrap(err, "applying options")
}
f.logger.Debugf("open views for index/field: %s/%s", f.index, f.name)
if err := f.openViews(); err != nil {
return errors.Wrap(err, "opening views")
}
f.logger.Debugf("open row attribute store for index/field: %s/%s", f.index, f.name)
if err := f.rowAttrStore.Open(); err != nil {
return errors.Wrap(err, "opening attrstore")
}
return nil
}(); err != nil {
f.Close()
return err
}
f.logger.Debugf("successfully opened field index/field: %s/%s", f.index, f.name)
return nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Open",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"func",
"(",
")",
"error",
"{",
"f",
".",
"logger",
".",
"Debugf",
"(",
"\"ensure field path exists: %s\"",
",",
"f",
".",
"path",
")",
"\n",
"if",
"err",
":=",... | // Open opens and initializes the field. | [
"Open",
"opens",
"and",
"initializes",
"the",
"field",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L381-L423 | train |
pilosa/pilosa | field.go | openViews | func (f *Field) openViews() error {
file, err := os.Open(filepath.Join(f.path, "views"))
if os.IsNotExist(err) {
return nil
} else if err != nil {
return errors.Wrap(err, "opening view directory")
}
defer file.Close()
fis, err := file.Readdir(0)
if err != nil {
return errors.Wrap(err, "reading directory")
}
for _, fi := range fis {
if !fi.IsDir() {
continue
}
name := filepath.Base(fi.Name())
f.logger.Debugf("open index/field/view: %s/%s/%s", f.index, f.name, fi.Name())
view := f.newView(f.viewPath(name), name)
if err := view.open(); err != nil {
return fmt.Errorf("opening view: view=%s, err=%s", view.name, err)
}
view.rowAttrStore = f.rowAttrStore
f.logger.Debugf("add index/field/view to field.viewMap: %s/%s/%s", f.index, f.name, view.name)
f.viewMap[view.name] = view
}
return nil
} | go | func (f *Field) openViews() error {
file, err := os.Open(filepath.Join(f.path, "views"))
if os.IsNotExist(err) {
return nil
} else if err != nil {
return errors.Wrap(err, "opening view directory")
}
defer file.Close()
fis, err := file.Readdir(0)
if err != nil {
return errors.Wrap(err, "reading directory")
}
for _, fi := range fis {
if !fi.IsDir() {
continue
}
name := filepath.Base(fi.Name())
f.logger.Debugf("open index/field/view: %s/%s/%s", f.index, f.name, fi.Name())
view := f.newView(f.viewPath(name), name)
if err := view.open(); err != nil {
return fmt.Errorf("opening view: view=%s, err=%s", view.name, err)
}
view.rowAttrStore = f.rowAttrStore
f.logger.Debugf("add index/field/view to field.viewMap: %s/%s/%s", f.index, f.name, view.name)
f.viewMap[view.name] = view
}
return nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"openViews",
"(",
")",
"error",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filepath",
".",
"Join",
"(",
"f",
".",
"path",
",",
"\"views\"",
")",
")",
"\n",
"if",
"os",
".",
"IsNotExist",
"(",
"e... | // openViews opens and initializes the views inside the field. | [
"openViews",
"opens",
"and",
"initializes",
"the",
"views",
"inside",
"the",
"field",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L426-L457 | train |
pilosa/pilosa | field.go | loadMeta | func (f *Field) loadMeta() error {
var pb internal.FieldOptions
// Read data from meta file.
buf, err := ioutil.ReadFile(filepath.Join(f.path, ".meta"))
if os.IsNotExist(err) {
return nil
} else if err != nil {
return errors.Wrap(err, "reading meta")
} else {
if err := proto.Unmarshal(buf, &pb); err != nil {
return errors.Wrap(err, "unmarshaling")
}
}
// Copy metadata fields.
f.options.Type = pb.Type
f.options.CacheType = pb.CacheType
f.options.CacheSize = pb.CacheSize
f.options.Min = pb.Min
f.options.Max = pb.Max
f.options.TimeQuantum = TimeQuantum(pb.TimeQuantum)
f.options.Keys = pb.Keys
f.options.NoStandardView = pb.NoStandardView
return nil
} | go | func (f *Field) loadMeta() error {
var pb internal.FieldOptions
// Read data from meta file.
buf, err := ioutil.ReadFile(filepath.Join(f.path, ".meta"))
if os.IsNotExist(err) {
return nil
} else if err != nil {
return errors.Wrap(err, "reading meta")
} else {
if err := proto.Unmarshal(buf, &pb); err != nil {
return errors.Wrap(err, "unmarshaling")
}
}
// Copy metadata fields.
f.options.Type = pb.Type
f.options.CacheType = pb.CacheType
f.options.CacheSize = pb.CacheSize
f.options.Min = pb.Min
f.options.Max = pb.Max
f.options.TimeQuantum = TimeQuantum(pb.TimeQuantum)
f.options.Keys = pb.Keys
f.options.NoStandardView = pb.NoStandardView
return nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"loadMeta",
"(",
")",
"error",
"{",
"var",
"pb",
"internal",
".",
"FieldOptions",
"\n",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filepath",
".",
"Join",
"(",
"f",
".",
"path",
",",
"\".meta\"",
... | // loadMeta reads meta data for the field, if any. | [
"loadMeta",
"reads",
"meta",
"data",
"for",
"the",
"field",
"if",
"any",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L460-L486 | train |
pilosa/pilosa | field.go | saveMeta | func (f *Field) saveMeta() error {
// Marshal metadata.
fo := f.options
buf, err := proto.Marshal(fo.encode())
if err != nil {
return errors.Wrap(err, "marshaling")
}
// Write to meta file.
if err := ioutil.WriteFile(filepath.Join(f.path, ".meta"), buf, 0666); err != nil {
return errors.Wrap(err, "writing meta")
}
return nil
} | go | func (f *Field) saveMeta() error {
// Marshal metadata.
fo := f.options
buf, err := proto.Marshal(fo.encode())
if err != nil {
return errors.Wrap(err, "marshaling")
}
// Write to meta file.
if err := ioutil.WriteFile(filepath.Join(f.path, ".meta"), buf, 0666); err != nil {
return errors.Wrap(err, "writing meta")
}
return nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"saveMeta",
"(",
")",
"error",
"{",
"fo",
":=",
"f",
".",
"options",
"\n",
"buf",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"fo",
".",
"encode",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r... | // saveMeta writes meta data for the field. | [
"saveMeta",
"writes",
"meta",
"data",
"for",
"the",
"field",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L489-L503 | train |
pilosa/pilosa | field.go | applyOptions | func (f *Field) applyOptions(opt FieldOptions) error {
switch opt.Type {
case FieldTypeSet, FieldTypeMutex, "":
fldType := opt.Type
if fldType == "" {
fldType = FieldTypeSet
}
f.options.Type = fldType
if opt.CacheType != "" {
f.options.CacheType = opt.CacheType
}
if opt.CacheSize != 0 {
if opt.CacheType == CacheTypeNone {
f.options.CacheSize = 0
} else {
f.options.CacheSize = opt.CacheSize
}
}
f.options.Min = 0
f.options.Max = 0
f.options.TimeQuantum = ""
f.options.Keys = opt.Keys
case FieldTypeInt:
f.options.Type = opt.Type
f.options.CacheType = CacheTypeNone
f.options.CacheSize = 0
f.options.Min = opt.Min
f.options.Max = opt.Max
f.options.TimeQuantum = ""
f.options.Keys = opt.Keys
// Create new bsiGroup.
bsig := &bsiGroup{
Name: f.name,
Type: bsiGroupTypeInt,
Min: opt.Min,
Max: opt.Max,
}
// Validate bsiGroup.
if err := bsig.validate(); err != nil {
return err
}
if err := f.createBSIGroup(bsig); err != nil {
return errors.Wrap(err, "creating bsigroup")
}
case FieldTypeTime:
f.options.Type = opt.Type
f.options.CacheType = CacheTypeNone
f.options.CacheSize = 0
f.options.Min = 0
f.options.Max = 0
f.options.Keys = opt.Keys
f.options.NoStandardView = opt.NoStandardView
// Set the time quantum.
if err := f.setTimeQuantum(opt.TimeQuantum); err != nil {
f.Close()
return errors.Wrap(err, "setting time quantum")
}
case FieldTypeBool:
f.options.Type = FieldTypeBool
f.options.CacheType = CacheTypeNone
f.options.CacheSize = 0
f.options.Min = 0
f.options.Max = 0
f.options.TimeQuantum = ""
f.options.Keys = false
default:
return errors.New("invalid field type")
}
return nil
} | go | func (f *Field) applyOptions(opt FieldOptions) error {
switch opt.Type {
case FieldTypeSet, FieldTypeMutex, "":
fldType := opt.Type
if fldType == "" {
fldType = FieldTypeSet
}
f.options.Type = fldType
if opt.CacheType != "" {
f.options.CacheType = opt.CacheType
}
if opt.CacheSize != 0 {
if opt.CacheType == CacheTypeNone {
f.options.CacheSize = 0
} else {
f.options.CacheSize = opt.CacheSize
}
}
f.options.Min = 0
f.options.Max = 0
f.options.TimeQuantum = ""
f.options.Keys = opt.Keys
case FieldTypeInt:
f.options.Type = opt.Type
f.options.CacheType = CacheTypeNone
f.options.CacheSize = 0
f.options.Min = opt.Min
f.options.Max = opt.Max
f.options.TimeQuantum = ""
f.options.Keys = opt.Keys
// Create new bsiGroup.
bsig := &bsiGroup{
Name: f.name,
Type: bsiGroupTypeInt,
Min: opt.Min,
Max: opt.Max,
}
// Validate bsiGroup.
if err := bsig.validate(); err != nil {
return err
}
if err := f.createBSIGroup(bsig); err != nil {
return errors.Wrap(err, "creating bsigroup")
}
case FieldTypeTime:
f.options.Type = opt.Type
f.options.CacheType = CacheTypeNone
f.options.CacheSize = 0
f.options.Min = 0
f.options.Max = 0
f.options.Keys = opt.Keys
f.options.NoStandardView = opt.NoStandardView
// Set the time quantum.
if err := f.setTimeQuantum(opt.TimeQuantum); err != nil {
f.Close()
return errors.Wrap(err, "setting time quantum")
}
case FieldTypeBool:
f.options.Type = FieldTypeBool
f.options.CacheType = CacheTypeNone
f.options.CacheSize = 0
f.options.Min = 0
f.options.Max = 0
f.options.TimeQuantum = ""
f.options.Keys = false
default:
return errors.New("invalid field type")
}
return nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"applyOptions",
"(",
"opt",
"FieldOptions",
")",
"error",
"{",
"switch",
"opt",
".",
"Type",
"{",
"case",
"FieldTypeSet",
",",
"FieldTypeMutex",
",",
"\"\"",
":",
"fldType",
":=",
"opt",
".",
"Type",
"\n",
"if",
"fl... | // applyOptions configures the field based on opt. | [
"applyOptions",
"configures",
"the",
"field",
"based",
"on",
"opt",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L506-L577 | train |
pilosa/pilosa | field.go | Close | func (f *Field) Close() error {
f.mu.Lock()
defer f.mu.Unlock()
// Close the attribute store.
if f.rowAttrStore != nil {
_ = f.rowAttrStore.Close()
}
// Close all views.
for _, view := range f.viewMap {
if err := view.close(); err != nil {
return err
}
}
f.viewMap = make(map[string]*view)
return nil
} | go | func (f *Field) Close() error {
f.mu.Lock()
defer f.mu.Unlock()
// Close the attribute store.
if f.rowAttrStore != nil {
_ = f.rowAttrStore.Close()
}
// Close all views.
for _, view := range f.viewMap {
if err := view.close(); err != nil {
return err
}
}
f.viewMap = make(map[string]*view)
return nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Close",
"(",
")",
"error",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"f",
".",
"rowAttrStore",
"!=",
"nil",
"{",
"_",
"=",
"f",
".",... | // Close closes the field and its views. | [
"Close",
"closes",
"the",
"field",
"and",
"its",
"views",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L580-L598 | train |
pilosa/pilosa | field.go | keys | func (f *Field) keys() bool {
f.mu.RLock()
defer f.mu.RUnlock()
return f.options.Keys
} | go | func (f *Field) keys() bool {
f.mu.RLock()
defer f.mu.RUnlock()
return f.options.Keys
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"keys",
"(",
")",
"bool",
"{",
"f",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"f",
".",
"options",
".",
"Keys",
"\n",
"}"
] | // keys returns true if the field uses string keys. | [
"keys",
"returns",
"true",
"if",
"the",
"field",
"uses",
"string",
"keys",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L601-L605 | train |
pilosa/pilosa | field.go | bsiGroup | func (f *Field) bsiGroup(name string) *bsiGroup {
f.mu.RLock()
defer f.mu.RUnlock()
for _, bsig := range f.bsiGroups {
if bsig.Name == name {
return bsig
}
}
return nil
} | go | func (f *Field) bsiGroup(name string) *bsiGroup {
f.mu.RLock()
defer f.mu.RUnlock()
for _, bsig := range f.bsiGroups {
if bsig.Name == name {
return bsig
}
}
return nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"bsiGroup",
"(",
"name",
"string",
")",
"*",
"bsiGroup",
"{",
"f",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"for",
"_",
",",
"bsig",
":=",
"range",
... | // bsiGroup returns a bsiGroup by name. | [
"bsiGroup",
"returns",
"a",
"bsiGroup",
"by",
"name",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L608-L617 | train |
pilosa/pilosa | field.go | hasBSIGroup | func (f *Field) hasBSIGroup(name string) bool {
for _, bsig := range f.bsiGroups {
if bsig.Name == name {
return true
}
}
return false
} | go | func (f *Field) hasBSIGroup(name string) bool {
for _, bsig := range f.bsiGroups {
if bsig.Name == name {
return true
}
}
return false
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"hasBSIGroup",
"(",
"name",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"bsig",
":=",
"range",
"f",
".",
"bsiGroups",
"{",
"if",
"bsig",
".",
"Name",
"==",
"name",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",... | // hasBSIGroup returns true if a bsiGroup exists on the field. | [
"hasBSIGroup",
"returns",
"true",
"if",
"a",
"bsiGroup",
"exists",
"on",
"the",
"field",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L620-L627 | train |
pilosa/pilosa | field.go | createBSIGroup | func (f *Field) createBSIGroup(bsig *bsiGroup) error {
f.mu.Lock()
defer f.mu.Unlock()
// Append bsiGroup.
if err := f.addBSIGroup(bsig); err != nil {
return err
}
if err := f.saveMeta(); err != nil {
return errors.Wrap(err, "saving")
}
return nil
} | go | func (f *Field) createBSIGroup(bsig *bsiGroup) error {
f.mu.Lock()
defer f.mu.Unlock()
// Append bsiGroup.
if err := f.addBSIGroup(bsig); err != nil {
return err
}
if err := f.saveMeta(); err != nil {
return errors.Wrap(err, "saving")
}
return nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"createBSIGroup",
"(",
"bsig",
"*",
"bsiGroup",
")",
"error",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
":=",
"f",
".",
"addBSIGro... | // createBSIGroup creates a new bsiGroup on the field. | [
"createBSIGroup",
"creates",
"a",
"new",
"bsiGroup",
"on",
"the",
"field",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L630-L642 | train |
pilosa/pilosa | field.go | addBSIGroup | func (f *Field) addBSIGroup(bsig *bsiGroup) error {
if err := bsig.validate(); err != nil {
return errors.Wrap(err, "validating bsigroup")
} else if f.hasBSIGroup(bsig.Name) {
return ErrBSIGroupExists
}
// Add bsiGroup to list.
f.bsiGroups = append(f.bsiGroups, bsig)
// Sort bsiGroups by name.
sort.Slice(f.bsiGroups, func(i, j int) bool {
return f.bsiGroups[i].Name < f.bsiGroups[j].Name
})
return nil
} | go | func (f *Field) addBSIGroup(bsig *bsiGroup) error {
if err := bsig.validate(); err != nil {
return errors.Wrap(err, "validating bsigroup")
} else if f.hasBSIGroup(bsig.Name) {
return ErrBSIGroupExists
}
// Add bsiGroup to list.
f.bsiGroups = append(f.bsiGroups, bsig)
// Sort bsiGroups by name.
sort.Slice(f.bsiGroups, func(i, j int) bool {
return f.bsiGroups[i].Name < f.bsiGroups[j].Name
})
return nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"addBSIGroup",
"(",
"bsig",
"*",
"bsiGroup",
")",
"error",
"{",
"if",
"err",
":=",
"bsig",
".",
"validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"validating... | // addBSIGroup adds a single bsiGroup to bsiGroups. | [
"addBSIGroup",
"adds",
"a",
"single",
"bsiGroup",
"to",
"bsiGroups",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L645-L661 | train |
pilosa/pilosa | field.go | TimeQuantum | func (f *Field) TimeQuantum() TimeQuantum {
f.mu.Lock()
defer f.mu.Unlock()
return f.options.TimeQuantum
} | go | func (f *Field) TimeQuantum() TimeQuantum {
f.mu.Lock()
defer f.mu.Unlock()
return f.options.TimeQuantum
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"TimeQuantum",
"(",
")",
"TimeQuantum",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"f",
".",
"options",
".",
"TimeQuantum",
"\n",
"}"
] | // TimeQuantum returns the time quantum for the field. | [
"TimeQuantum",
"returns",
"the",
"time",
"quantum",
"for",
"the",
"field",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L664-L668 | train |
pilosa/pilosa | field.go | setTimeQuantum | func (f *Field) setTimeQuantum(q TimeQuantum) error {
f.mu.Lock()
defer f.mu.Unlock()
// Validate input.
if !q.Valid() {
return ErrInvalidTimeQuantum
}
// Update value on field.
f.options.TimeQuantum = q
// Persist meta data to disk.
if err := f.saveMeta(); err != nil {
return errors.Wrap(err, "saving meta")
}
return nil
} | go | func (f *Field) setTimeQuantum(q TimeQuantum) error {
f.mu.Lock()
defer f.mu.Unlock()
// Validate input.
if !q.Valid() {
return ErrInvalidTimeQuantum
}
// Update value on field.
f.options.TimeQuantum = q
// Persist meta data to disk.
if err := f.saveMeta(); err != nil {
return errors.Wrap(err, "saving meta")
}
return nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"setTimeQuantum",
"(",
"q",
"TimeQuantum",
")",
"error",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"q",
".",
"Valid",
"(",
")",
"{... | // setTimeQuantum sets the time quantum for the field. | [
"setTimeQuantum",
"sets",
"the",
"time",
"quantum",
"for",
"the",
"field",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L671-L689 | train |
pilosa/pilosa | field.go | RowTime | func (f *Field) RowTime(rowID uint64, time time.Time, quantum string) (*Row, error) {
if !TimeQuantum(quantum).Valid() {
return nil, ErrInvalidTimeQuantum
}
viewname := viewsByTime(viewStandard, time, TimeQuantum(quantum[len(quantum)-1:]))[0]
view := f.view(viewname)
if view == nil {
return nil, errors.Errorf("view with quantum %v not found.", quantum)
}
return view.row(rowID), nil
} | go | func (f *Field) RowTime(rowID uint64, time time.Time, quantum string) (*Row, error) {
if !TimeQuantum(quantum).Valid() {
return nil, ErrInvalidTimeQuantum
}
viewname := viewsByTime(viewStandard, time, TimeQuantum(quantum[len(quantum)-1:]))[0]
view := f.view(viewname)
if view == nil {
return nil, errors.Errorf("view with quantum %v not found.", quantum)
}
return view.row(rowID), nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"RowTime",
"(",
"rowID",
"uint64",
",",
"time",
"time",
".",
"Time",
",",
"quantum",
"string",
")",
"(",
"*",
"Row",
",",
"error",
")",
"{",
"if",
"!",
"TimeQuantum",
"(",
"quantum",
")",
".",
"Valid",
"(",
")... | // RowTime gets the row at the particular time with the granularity specified by
// the quantum. | [
"RowTime",
"gets",
"the",
"row",
"at",
"the",
"particular",
"time",
"with",
"the",
"granularity",
"specified",
"by",
"the",
"quantum",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L693-L703 | train |
pilosa/pilosa | field.go | viewPath | func (f *Field) viewPath(name string) string {
return filepath.Join(f.path, "views", name)
} | go | func (f *Field) viewPath(name string) string {
return filepath.Join(f.path, "views", name)
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"viewPath",
"(",
"name",
"string",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"f",
".",
"path",
",",
"\"views\"",
",",
"name",
")",
"\n",
"}"
] | // viewPath returns the path to a view in the field. | [
"viewPath",
"returns",
"the",
"path",
"to",
"a",
"view",
"in",
"the",
"field",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L706-L708 | train |
pilosa/pilosa | field.go | view | func (f *Field) view(name string) *view {
f.mu.RLock()
defer f.mu.RUnlock()
return f.unprotectedView(name)
} | go | func (f *Field) view(name string) *view {
f.mu.RLock()
defer f.mu.RUnlock()
return f.unprotectedView(name)
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"view",
"(",
"name",
"string",
")",
"*",
"view",
"{",
"f",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"f",
".",
"unprotectedView",
"(",
"name"... | // view returns a view in the field by name. | [
"view",
"returns",
"a",
"view",
"in",
"the",
"field",
"by",
"name",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L711-L715 | train |
pilosa/pilosa | field.go | views | func (f *Field) views() []*view {
f.mu.RLock()
defer f.mu.RUnlock()
other := make([]*view, 0, len(f.viewMap))
for _, view := range f.viewMap {
other = append(other, view)
}
return other
} | go | func (f *Field) views() []*view {
f.mu.RLock()
defer f.mu.RUnlock()
other := make([]*view, 0, len(f.viewMap))
for _, view := range f.viewMap {
other = append(other, view)
}
return other
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"views",
"(",
")",
"[",
"]",
"*",
"view",
"{",
"f",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"other",
":=",
"make",
"(",
"[",
"]",
"*",
"view",
... | // views returns a list of all views in the field. | [
"views",
"returns",
"a",
"list",
"of",
"all",
"views",
"in",
"the",
"field",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L720-L729 | train |
pilosa/pilosa | field.go | createViewIfNotExists | func (f *Field) createViewIfNotExists(name string) (*view, error) {
view, created, err := f.createViewIfNotExistsBase(name)
if err != nil {
return nil, err
}
if created {
// Broadcast view creation to the cluster.
err = f.broadcaster.SendSync(
&CreateViewMessage{
Index: f.index,
Field: f.name,
View: name,
})
if err != nil {
return nil, errors.Wrap(err, "sending CreateView message")
}
}
return view, nil
} | go | func (f *Field) createViewIfNotExists(name string) (*view, error) {
view, created, err := f.createViewIfNotExistsBase(name)
if err != nil {
return nil, err
}
if created {
// Broadcast view creation to the cluster.
err = f.broadcaster.SendSync(
&CreateViewMessage{
Index: f.index,
Field: f.name,
View: name,
})
if err != nil {
return nil, errors.Wrap(err, "sending CreateView message")
}
}
return view, nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"createViewIfNotExists",
"(",
"name",
"string",
")",
"(",
"*",
"view",
",",
"error",
")",
"{",
"view",
",",
"created",
",",
"err",
":=",
"f",
".",
"createViewIfNotExistsBase",
"(",
"name",
")",
"\n",
"if",
"err",
... | // createViewIfNotExists returns the named view, creating it if necessary.
// Additionally, a CreateViewMessage is sent to the cluster. | [
"createViewIfNotExists",
"returns",
"the",
"named",
"view",
"creating",
"it",
"if",
"necessary",
".",
"Additionally",
"a",
"CreateViewMessage",
"is",
"sent",
"to",
"the",
"cluster",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L740-L760 | train |
pilosa/pilosa | field.go | createViewIfNotExistsBase | func (f *Field) createViewIfNotExistsBase(name string) (*view, bool, error) {
f.mu.Lock()
defer f.mu.Unlock()
if view := f.viewMap[name]; view != nil {
return view, false, nil
}
view := f.newView(f.viewPath(name), name)
if err := view.open(); err != nil {
return nil, false, errors.Wrap(err, "opening view")
}
view.rowAttrStore = f.rowAttrStore
f.viewMap[view.name] = view
return view, true, nil
} | go | func (f *Field) createViewIfNotExistsBase(name string) (*view, bool, error) {
f.mu.Lock()
defer f.mu.Unlock()
if view := f.viewMap[name]; view != nil {
return view, false, nil
}
view := f.newView(f.viewPath(name), name)
if err := view.open(); err != nil {
return nil, false, errors.Wrap(err, "opening view")
}
view.rowAttrStore = f.rowAttrStore
f.viewMap[view.name] = view
return view, true, nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"createViewIfNotExistsBase",
"(",
"name",
"string",
")",
"(",
"*",
"view",
",",
"bool",
",",
"error",
")",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
... | // createViewIfNotExistsBase returns the named view, creating it if necessary.
// The returned bool indicates whether the view was created or not. | [
"createViewIfNotExistsBase",
"returns",
"the",
"named",
"view",
"creating",
"it",
"if",
"necessary",
".",
"The",
"returned",
"bool",
"indicates",
"whether",
"the",
"view",
"was",
"created",
"or",
"not",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L764-L780 | train |
pilosa/pilosa | field.go | deleteView | func (f *Field) deleteView(name string) error {
view := f.viewMap[name]
if view == nil {
return ErrInvalidView
}
// Close data files before deletion.
if err := view.close(); err != nil {
return errors.Wrap(err, "closing view")
}
// Delete view directory.
if err := os.RemoveAll(view.path); err != nil {
return errors.Wrap(err, "deleting directory")
}
delete(f.viewMap, name)
return nil
} | go | func (f *Field) deleteView(name string) error {
view := f.viewMap[name]
if view == nil {
return ErrInvalidView
}
// Close data files before deletion.
if err := view.close(); err != nil {
return errors.Wrap(err, "closing view")
}
// Delete view directory.
if err := os.RemoveAll(view.path); err != nil {
return errors.Wrap(err, "deleting directory")
}
delete(f.viewMap, name)
return nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"deleteView",
"(",
"name",
"string",
")",
"error",
"{",
"view",
":=",
"f",
".",
"viewMap",
"[",
"name",
"]",
"\n",
"if",
"view",
"==",
"nil",
"{",
"return",
"ErrInvalidView",
"\n",
"}",
"\n",
"if",
"err",
":=",
... | // deleteView removes the view from the field. | [
"deleteView",
"removes",
"the",
"view",
"from",
"the",
"field",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L792-L811 | train |
pilosa/pilosa | field.go | Row | func (f *Field) Row(rowID uint64) (*Row, error) {
if f.Type() != FieldTypeSet {
return nil, errors.Errorf("row method unsupported for field type: %s", f.Type())
}
view := f.view(viewStandard)
if view == nil {
return nil, ErrInvalidView
}
return view.row(rowID), nil
} | go | func (f *Field) Row(rowID uint64) (*Row, error) {
if f.Type() != FieldTypeSet {
return nil, errors.Errorf("row method unsupported for field type: %s", f.Type())
}
view := f.view(viewStandard)
if view == nil {
return nil, ErrInvalidView
}
return view.row(rowID), nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Row",
"(",
"rowID",
"uint64",
")",
"(",
"*",
"Row",
",",
"error",
")",
"{",
"if",
"f",
".",
"Type",
"(",
")",
"!=",
"FieldTypeSet",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"row method unsuppo... | // Row returns a row of the standard view.
// It seems this method is only being used by the test
// package, and the fact that it's only allowed on
// `set` fields is odd. This may be considered for
// deprecation in a future version. | [
"Row",
"returns",
"a",
"row",
"of",
"the",
"standard",
"view",
".",
"It",
"seems",
"this",
"method",
"is",
"only",
"being",
"used",
"by",
"the",
"test",
"package",
"and",
"the",
"fact",
"that",
"it",
"s",
"only",
"allowed",
"on",
"set",
"fields",
"is",... | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L818-L827 | train |
pilosa/pilosa | field.go | SetBit | func (f *Field) SetBit(rowID, colID uint64, t *time.Time) (changed bool, err error) {
viewName := viewStandard
if !f.options.NoStandardView {
// Retrieve view. Exit if it doesn't exist.
view, err := f.createViewIfNotExists(viewName)
if err != nil {
return changed, errors.Wrap(err, "creating view")
}
// Set non-time bit.
if v, err := view.setBit(rowID, colID); err != nil {
return changed, errors.Wrap(err, "setting on view")
} else if v {
changed = v
}
}
// Exit early if no timestamp is specified.
if t == nil {
return changed, nil
}
// If a timestamp is specified then set bits across all views for the quantum.
for _, subname := range viewsByTime(viewName, *t, f.TimeQuantum()) {
view, err := f.createViewIfNotExists(subname)
if err != nil {
return changed, errors.Wrapf(err, "creating view %s", subname)
}
if c, err := view.setBit(rowID, colID); err != nil {
return changed, errors.Wrapf(err, "setting on view %s", subname)
} else if c {
changed = true
}
}
return changed, nil
} | go | func (f *Field) SetBit(rowID, colID uint64, t *time.Time) (changed bool, err error) {
viewName := viewStandard
if !f.options.NoStandardView {
// Retrieve view. Exit if it doesn't exist.
view, err := f.createViewIfNotExists(viewName)
if err != nil {
return changed, errors.Wrap(err, "creating view")
}
// Set non-time bit.
if v, err := view.setBit(rowID, colID); err != nil {
return changed, errors.Wrap(err, "setting on view")
} else if v {
changed = v
}
}
// Exit early if no timestamp is specified.
if t == nil {
return changed, nil
}
// If a timestamp is specified then set bits across all views for the quantum.
for _, subname := range viewsByTime(viewName, *t, f.TimeQuantum()) {
view, err := f.createViewIfNotExists(subname)
if err != nil {
return changed, errors.Wrapf(err, "creating view %s", subname)
}
if c, err := view.setBit(rowID, colID); err != nil {
return changed, errors.Wrapf(err, "setting on view %s", subname)
} else if c {
changed = true
}
}
return changed, nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"SetBit",
"(",
"rowID",
",",
"colID",
"uint64",
",",
"t",
"*",
"time",
".",
"Time",
")",
"(",
"changed",
"bool",
",",
"err",
"error",
")",
"{",
"viewName",
":=",
"viewStandard",
"\n",
"if",
"!",
"f",
".",
"opt... | // SetBit sets a bit on a view within the field. | [
"SetBit",
"sets",
"a",
"bit",
"on",
"a",
"view",
"within",
"the",
"field",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L830-L867 | train |
pilosa/pilosa | field.go | ClearBit | func (f *Field) ClearBit(rowID, colID uint64) (changed bool, err error) {
viewName := viewStandard
// Retrieve view. Exit if it doesn't exist.
view, present := f.viewMap[viewName]
if !present {
return changed, errors.Wrap(err, "clearing missing view")
}
// Clear non-time bit.
if v, err := view.clearBit(rowID, colID); err != nil {
return changed, errors.Wrap(err, "clearing on view")
} else if v {
changed = v
}
if len(f.viewMap) == 1 { // assuming no time views
return changed, nil
}
lastViewNameSize := 0
level := 0
skipAbove := maxInt
for _, view := range f.allTimeViewsSortedByQuantum() {
if lastViewNameSize < len(view.name) {
level++
} else if lastViewNameSize > len(view.name) {
level--
}
if level < skipAbove {
if changed, err = view.clearBit(rowID, colID); err != nil {
return changed, errors.Wrapf(err, "clearing on view %s", view.name)
}
if !changed {
skipAbove = level + 1
} else {
skipAbove = maxInt
}
}
lastViewNameSize = len(view.name)
}
return changed, nil
} | go | func (f *Field) ClearBit(rowID, colID uint64) (changed bool, err error) {
viewName := viewStandard
// Retrieve view. Exit if it doesn't exist.
view, present := f.viewMap[viewName]
if !present {
return changed, errors.Wrap(err, "clearing missing view")
}
// Clear non-time bit.
if v, err := view.clearBit(rowID, colID); err != nil {
return changed, errors.Wrap(err, "clearing on view")
} else if v {
changed = v
}
if len(f.viewMap) == 1 { // assuming no time views
return changed, nil
}
lastViewNameSize := 0
level := 0
skipAbove := maxInt
for _, view := range f.allTimeViewsSortedByQuantum() {
if lastViewNameSize < len(view.name) {
level++
} else if lastViewNameSize > len(view.name) {
level--
}
if level < skipAbove {
if changed, err = view.clearBit(rowID, colID); err != nil {
return changed, errors.Wrapf(err, "clearing on view %s", view.name)
}
if !changed {
skipAbove = level + 1
} else {
skipAbove = maxInt
}
}
lastViewNameSize = len(view.name)
}
return changed, nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"ClearBit",
"(",
"rowID",
",",
"colID",
"uint64",
")",
"(",
"changed",
"bool",
",",
"err",
"error",
")",
"{",
"viewName",
":=",
"viewStandard",
"\n",
"view",
",",
"present",
":=",
"f",
".",
"viewMap",
"[",
"viewNa... | // ClearBit clears a bit within the field. | [
"ClearBit",
"clears",
"a",
"bit",
"within",
"the",
"field",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L870-L912 | train |
pilosa/pilosa | field.go | Value | func (f *Field) Value(columnID uint64) (value int64, exists bool, err error) {
bsig := f.bsiGroup(f.name)
if bsig == nil {
return 0, false, ErrBSIGroupNotFound
}
// Fetch target view.
view := f.view(viewBSIGroupPrefix + f.name)
if view == nil {
return 0, false, nil
}
v, exists, err := view.value(columnID, bsig.BitDepth())
if err != nil {
return 0, false, err
} else if !exists {
return 0, false, nil
}
return int64(v) + bsig.Min, true, nil
} | go | func (f *Field) Value(columnID uint64) (value int64, exists bool, err error) {
bsig := f.bsiGroup(f.name)
if bsig == nil {
return 0, false, ErrBSIGroupNotFound
}
// Fetch target view.
view := f.view(viewBSIGroupPrefix + f.name)
if view == nil {
return 0, false, nil
}
v, exists, err := view.value(columnID, bsig.BitDepth())
if err != nil {
return 0, false, err
} else if !exists {
return 0, false, nil
}
return int64(v) + bsig.Min, true, nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Value",
"(",
"columnID",
"uint64",
")",
"(",
"value",
"int64",
",",
"exists",
"bool",
",",
"err",
"error",
")",
"{",
"bsig",
":=",
"f",
".",
"bsiGroup",
"(",
"f",
".",
"name",
")",
"\n",
"if",
"bsig",
"==",
... | // Value reads a field value for a column. | [
"Value",
"reads",
"a",
"field",
"value",
"for",
"a",
"column",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L956-L975 | train |
pilosa/pilosa | field.go | SetValue | func (f *Field) SetValue(columnID uint64, value int64) (changed bool, err error) {
// Fetch bsiGroup and validate value.
bsig := f.bsiGroup(f.name)
if bsig == nil {
return false, ErrBSIGroupNotFound
} else if value < bsig.Min {
return false, ErrBSIGroupValueTooLow
} else if value > bsig.Max {
return false, ErrBSIGroupValueTooHigh
}
// Fetch target view.
view, err := f.createViewIfNotExists(viewBSIGroupPrefix + f.name)
if err != nil {
return false, errors.Wrap(err, "creating view")
}
// Determine base value to store.
baseValue := uint64(value - bsig.Min)
return view.setValue(columnID, bsig.BitDepth(), baseValue)
} | go | func (f *Field) SetValue(columnID uint64, value int64) (changed bool, err error) {
// Fetch bsiGroup and validate value.
bsig := f.bsiGroup(f.name)
if bsig == nil {
return false, ErrBSIGroupNotFound
} else if value < bsig.Min {
return false, ErrBSIGroupValueTooLow
} else if value > bsig.Max {
return false, ErrBSIGroupValueTooHigh
}
// Fetch target view.
view, err := f.createViewIfNotExists(viewBSIGroupPrefix + f.name)
if err != nil {
return false, errors.Wrap(err, "creating view")
}
// Determine base value to store.
baseValue := uint64(value - bsig.Min)
return view.setValue(columnID, bsig.BitDepth(), baseValue)
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"SetValue",
"(",
"columnID",
"uint64",
",",
"value",
"int64",
")",
"(",
"changed",
"bool",
",",
"err",
"error",
")",
"{",
"bsig",
":=",
"f",
".",
"bsiGroup",
"(",
"f",
".",
"name",
")",
"\n",
"if",
"bsig",
"==... | // SetValue sets a field value for a column. | [
"SetValue",
"sets",
"a",
"field",
"value",
"for",
"a",
"column",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L978-L999 | train |
pilosa/pilosa | field.go | Sum | func (f *Field) Sum(filter *Row, name string) (sum, count int64, err error) {
bsig := f.bsiGroup(name)
if bsig == nil {
return 0, 0, ErrBSIGroupNotFound
}
view := f.view(viewBSIGroupPrefix + name)
if view == nil {
return 0, 0, nil
}
vsum, vcount, err := view.sum(filter, bsig.BitDepth())
if err != nil {
return 0, 0, err
}
return int64(vsum) + (int64(vcount) * bsig.Min), int64(vcount), nil
} | go | func (f *Field) Sum(filter *Row, name string) (sum, count int64, err error) {
bsig := f.bsiGroup(name)
if bsig == nil {
return 0, 0, ErrBSIGroupNotFound
}
view := f.view(viewBSIGroupPrefix + name)
if view == nil {
return 0, 0, nil
}
vsum, vcount, err := view.sum(filter, bsig.BitDepth())
if err != nil {
return 0, 0, err
}
return int64(vsum) + (int64(vcount) * bsig.Min), int64(vcount), nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Sum",
"(",
"filter",
"*",
"Row",
",",
"name",
"string",
")",
"(",
"sum",
",",
"count",
"int64",
",",
"err",
"error",
")",
"{",
"bsig",
":=",
"f",
".",
"bsiGroup",
"(",
"name",
")",
"\n",
"if",
"bsig",
"==",... | // Sum returns the sum and count for a field.
// An optional filtering row can be provided. | [
"Sum",
"returns",
"the",
"sum",
"and",
"count",
"for",
"a",
"field",
".",
"An",
"optional",
"filtering",
"row",
"can",
"be",
"provided",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1003-L1019 | train |
pilosa/pilosa | field.go | Min | func (f *Field) Min(filter *Row, name string) (min, count int64, err error) {
bsig := f.bsiGroup(name)
if bsig == nil {
return 0, 0, ErrBSIGroupNotFound
}
view := f.view(viewBSIGroupPrefix + name)
if view == nil {
return 0, 0, nil
}
vmin, vcount, err := view.min(filter, bsig.BitDepth())
if err != nil {
return 0, 0, err
}
return int64(vmin) + bsig.Min, int64(vcount), nil
} | go | func (f *Field) Min(filter *Row, name string) (min, count int64, err error) {
bsig := f.bsiGroup(name)
if bsig == nil {
return 0, 0, ErrBSIGroupNotFound
}
view := f.view(viewBSIGroupPrefix + name)
if view == nil {
return 0, 0, nil
}
vmin, vcount, err := view.min(filter, bsig.BitDepth())
if err != nil {
return 0, 0, err
}
return int64(vmin) + bsig.Min, int64(vcount), nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Min",
"(",
"filter",
"*",
"Row",
",",
"name",
"string",
")",
"(",
"min",
",",
"count",
"int64",
",",
"err",
"error",
")",
"{",
"bsig",
":=",
"f",
".",
"bsiGroup",
"(",
"name",
")",
"\n",
"if",
"bsig",
"==",... | // Min returns the min for a field.
// An optional filtering row can be provided. | [
"Min",
"returns",
"the",
"min",
"for",
"a",
"field",
".",
"An",
"optional",
"filtering",
"row",
"can",
"be",
"provided",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1023-L1039 | train |
pilosa/pilosa | field.go | Max | func (f *Field) Max(filter *Row, name string) (max, count int64, err error) {
bsig := f.bsiGroup(name)
if bsig == nil {
return 0, 0, ErrBSIGroupNotFound
}
view := f.view(viewBSIGroupPrefix + name)
if view == nil {
return 0, 0, nil
}
vmax, vcount, err := view.max(filter, bsig.BitDepth())
if err != nil {
return 0, 0, err
}
return int64(vmax) + bsig.Min, int64(vcount), nil
} | go | func (f *Field) Max(filter *Row, name string) (max, count int64, err error) {
bsig := f.bsiGroup(name)
if bsig == nil {
return 0, 0, ErrBSIGroupNotFound
}
view := f.view(viewBSIGroupPrefix + name)
if view == nil {
return 0, 0, nil
}
vmax, vcount, err := view.max(filter, bsig.BitDepth())
if err != nil {
return 0, 0, err
}
return int64(vmax) + bsig.Min, int64(vcount), nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Max",
"(",
"filter",
"*",
"Row",
",",
"name",
"string",
")",
"(",
"max",
",",
"count",
"int64",
",",
"err",
"error",
")",
"{",
"bsig",
":=",
"f",
".",
"bsiGroup",
"(",
"name",
")",
"\n",
"if",
"bsig",
"==",... | // Max returns the max for a field.
// An optional filtering row can be provided. | [
"Max",
"returns",
"the",
"max",
"for",
"a",
"field",
".",
"An",
"optional",
"filtering",
"row",
"can",
"be",
"provided",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1043-L1059 | train |
pilosa/pilosa | field.go | Range | func (f *Field) Range(name string, op pql.Token, predicate int64) (*Row, error) {
// Retrieve and validate bsiGroup.
bsig := f.bsiGroup(name)
if bsig == nil {
return nil, ErrBSIGroupNotFound
} else if predicate < bsig.Min || predicate > bsig.Max {
return nil, nil
}
// Retrieve bsiGroup's view.
view := f.view(viewBSIGroupPrefix + name)
if view == nil {
return nil, nil
}
baseValue, outOfRange := bsig.baseValue(op, predicate)
if outOfRange {
return NewRow(), nil
}
return view.rangeOp(op, bsig.BitDepth(), baseValue)
} | go | func (f *Field) Range(name string, op pql.Token, predicate int64) (*Row, error) {
// Retrieve and validate bsiGroup.
bsig := f.bsiGroup(name)
if bsig == nil {
return nil, ErrBSIGroupNotFound
} else if predicate < bsig.Min || predicate > bsig.Max {
return nil, nil
}
// Retrieve bsiGroup's view.
view := f.view(viewBSIGroupPrefix + name)
if view == nil {
return nil, nil
}
baseValue, outOfRange := bsig.baseValue(op, predicate)
if outOfRange {
return NewRow(), nil
}
return view.rangeOp(op, bsig.BitDepth(), baseValue)
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Range",
"(",
"name",
"string",
",",
"op",
"pql",
".",
"Token",
",",
"predicate",
"int64",
")",
"(",
"*",
"Row",
",",
"error",
")",
"{",
"bsig",
":=",
"f",
".",
"bsiGroup",
"(",
"name",
")",
"\n",
"if",
"bsi... | // Range performs a conditional operation on Field. | [
"Range",
"performs",
"a",
"conditional",
"operation",
"on",
"Field",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1062-L1083 | train |
pilosa/pilosa | field.go | Import | func (f *Field) Import(rowIDs, columnIDs []uint64, timestamps []*time.Time, opts ...ImportOption) error {
// Set up import options.
options := &ImportOptions{}
for _, opt := range opts {
err := opt(options)
if err != nil {
return errors.Wrap(err, "applying option")
}
}
// Determine quantum if timestamps are set.
q := f.TimeQuantum()
if hasTime(timestamps) {
if q == "" {
return errors.New("time quantum not set in field")
} else if options.Clear {
return errors.New("import clear is not supported with timestamps")
}
}
fieldType := f.Type()
// Split import data by fragment.
dataByFragment := make(map[importKey]importData)
for i := range rowIDs {
rowID, columnID := rowIDs[i], columnIDs[i]
// Bool-specific data validation.
if fieldType == FieldTypeBool && rowID > 1 {
return errors.New("bool field imports only support values 0 and 1")
}
var timestamp *time.Time
if len(timestamps) > i {
timestamp = timestamps[i]
}
var standard []string
if timestamp == nil {
standard = []string{viewStandard}
} else {
standard = viewsByTime(viewStandard, *timestamp, q)
if !f.options.NoStandardView {
// In order to match the logic of `SetBit()`, we want bits
// with timestamps to write to both time and standard views.
standard = append(standard, viewStandard)
}
}
// Attach bit to each standard view.
for _, name := range standard {
key := importKey{View: name, Shard: columnID / ShardWidth}
data := dataByFragment[key]
data.RowIDs = append(data.RowIDs, rowID)
data.ColumnIDs = append(data.ColumnIDs, columnID)
dataByFragment[key] = data
}
}
// Import into each fragment.
for key, data := range dataByFragment {
view, err := f.createViewIfNotExists(key.View)
if err != nil {
return errors.Wrap(err, "creating view")
}
frag, err := view.CreateFragmentIfNotExists(key.Shard)
if err != nil {
return errors.Wrap(err, "creating fragment")
}
if err := frag.bulkImport(data.RowIDs, data.ColumnIDs, options); err != nil {
return err
}
}
return nil
} | go | func (f *Field) Import(rowIDs, columnIDs []uint64, timestamps []*time.Time, opts ...ImportOption) error {
// Set up import options.
options := &ImportOptions{}
for _, opt := range opts {
err := opt(options)
if err != nil {
return errors.Wrap(err, "applying option")
}
}
// Determine quantum if timestamps are set.
q := f.TimeQuantum()
if hasTime(timestamps) {
if q == "" {
return errors.New("time quantum not set in field")
} else if options.Clear {
return errors.New("import clear is not supported with timestamps")
}
}
fieldType := f.Type()
// Split import data by fragment.
dataByFragment := make(map[importKey]importData)
for i := range rowIDs {
rowID, columnID := rowIDs[i], columnIDs[i]
// Bool-specific data validation.
if fieldType == FieldTypeBool && rowID > 1 {
return errors.New("bool field imports only support values 0 and 1")
}
var timestamp *time.Time
if len(timestamps) > i {
timestamp = timestamps[i]
}
var standard []string
if timestamp == nil {
standard = []string{viewStandard}
} else {
standard = viewsByTime(viewStandard, *timestamp, q)
if !f.options.NoStandardView {
// In order to match the logic of `SetBit()`, we want bits
// with timestamps to write to both time and standard views.
standard = append(standard, viewStandard)
}
}
// Attach bit to each standard view.
for _, name := range standard {
key := importKey{View: name, Shard: columnID / ShardWidth}
data := dataByFragment[key]
data.RowIDs = append(data.RowIDs, rowID)
data.ColumnIDs = append(data.ColumnIDs, columnID)
dataByFragment[key] = data
}
}
// Import into each fragment.
for key, data := range dataByFragment {
view, err := f.createViewIfNotExists(key.View)
if err != nil {
return errors.Wrap(err, "creating view")
}
frag, err := view.CreateFragmentIfNotExists(key.Shard)
if err != nil {
return errors.Wrap(err, "creating fragment")
}
if err := frag.bulkImport(data.RowIDs, data.ColumnIDs, options); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Import",
"(",
"rowIDs",
",",
"columnIDs",
"[",
"]",
"uint64",
",",
"timestamps",
"[",
"]",
"*",
"time",
".",
"Time",
",",
"opts",
"...",
"ImportOption",
")",
"error",
"{",
"options",
":=",
"&",
"ImportOptions",
"... | // Import bulk imports data. | [
"Import",
"bulk",
"imports",
"data",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1086-L1164 | train |
pilosa/pilosa | field.go | importValue | func (f *Field) importValue(columnIDs []uint64, values []int64, options *ImportOptions) error {
viewName := viewBSIGroupPrefix + f.name
// Get the bsiGroup so we know bitDepth.
bsig := f.bsiGroup(f.name)
if bsig == nil {
return errors.Wrap(ErrBSIGroupNotFound, f.name)
}
// Split import data by fragment.
dataByFragment := make(map[importKey]importValueData)
for i := range columnIDs {
columnID, value := columnIDs[i], values[i]
if value > bsig.Max {
return fmt.Errorf("%v, columnID=%v, value=%v", ErrBSIGroupValueTooHigh, columnID, value)
} else if value < bsig.Min {
return fmt.Errorf("%v, columnID=%v, value=%v", ErrBSIGroupValueTooLow, columnID, value)
}
// Attach value to each bsiGroup view.
for _, name := range []string{viewName} {
key := importKey{View: name, Shard: columnID / ShardWidth}
data := dataByFragment[key]
data.ColumnIDs = append(data.ColumnIDs, columnID)
data.Values = append(data.Values, value)
dataByFragment[key] = data
}
}
// Import into each fragment.
for key, data := range dataByFragment {
// The view must already exist (i.e. we can't create it)
// because we need to know bitDepth (based on min/max value).
view, err := f.createViewIfNotExists(key.View)
if err != nil {
return errors.Wrap(err, "creating view")
}
frag, err := view.CreateFragmentIfNotExists(key.Shard)
if err != nil {
return errors.Wrap(err, "creating fragment")
}
baseValues := make([]uint64, len(data.Values))
for i, value := range data.Values {
baseValues[i] = uint64(value - bsig.Min)
}
if err := frag.importValue(data.ColumnIDs, baseValues, bsig.BitDepth(), options.Clear); err != nil {
return err
}
}
return nil
} | go | func (f *Field) importValue(columnIDs []uint64, values []int64, options *ImportOptions) error {
viewName := viewBSIGroupPrefix + f.name
// Get the bsiGroup so we know bitDepth.
bsig := f.bsiGroup(f.name)
if bsig == nil {
return errors.Wrap(ErrBSIGroupNotFound, f.name)
}
// Split import data by fragment.
dataByFragment := make(map[importKey]importValueData)
for i := range columnIDs {
columnID, value := columnIDs[i], values[i]
if value > bsig.Max {
return fmt.Errorf("%v, columnID=%v, value=%v", ErrBSIGroupValueTooHigh, columnID, value)
} else if value < bsig.Min {
return fmt.Errorf("%v, columnID=%v, value=%v", ErrBSIGroupValueTooLow, columnID, value)
}
// Attach value to each bsiGroup view.
for _, name := range []string{viewName} {
key := importKey{View: name, Shard: columnID / ShardWidth}
data := dataByFragment[key]
data.ColumnIDs = append(data.ColumnIDs, columnID)
data.Values = append(data.Values, value)
dataByFragment[key] = data
}
}
// Import into each fragment.
for key, data := range dataByFragment {
// The view must already exist (i.e. we can't create it)
// because we need to know bitDepth (based on min/max value).
view, err := f.createViewIfNotExists(key.View)
if err != nil {
return errors.Wrap(err, "creating view")
}
frag, err := view.CreateFragmentIfNotExists(key.Shard)
if err != nil {
return errors.Wrap(err, "creating fragment")
}
baseValues := make([]uint64, len(data.Values))
for i, value := range data.Values {
baseValues[i] = uint64(value - bsig.Min)
}
if err := frag.importValue(data.ColumnIDs, baseValues, bsig.BitDepth(), options.Clear); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"importValue",
"(",
"columnIDs",
"[",
"]",
"uint64",
",",
"values",
"[",
"]",
"int64",
",",
"options",
"*",
"ImportOptions",
")",
"error",
"{",
"viewName",
":=",
"viewBSIGroupPrefix",
"+",
"f",
".",
"name",
"\n",
"b... | // importValue bulk imports range-encoded value data. | [
"importValue",
"bulk",
"imports",
"range",
"-",
"encoded",
"value",
"data",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1167-L1221 | train |
pilosa/pilosa | field.go | applyDefaultOptions | func applyDefaultOptions(o FieldOptions) FieldOptions {
if o.Type == "" {
return FieldOptions{
Type: DefaultFieldType,
CacheType: DefaultCacheType,
CacheSize: DefaultCacheSize,
}
}
return o
} | go | func applyDefaultOptions(o FieldOptions) FieldOptions {
if o.Type == "" {
return FieldOptions{
Type: DefaultFieldType,
CacheType: DefaultCacheType,
CacheSize: DefaultCacheSize,
}
}
return o
} | [
"func",
"applyDefaultOptions",
"(",
"o",
"FieldOptions",
")",
"FieldOptions",
"{",
"if",
"o",
".",
"Type",
"==",
"\"\"",
"{",
"return",
"FieldOptions",
"{",
"Type",
":",
"DefaultFieldType",
",",
"CacheType",
":",
"DefaultCacheType",
",",
"CacheSize",
":",
"Def... | // applyDefaultOptions returns a new FieldOptions object
// with default values if o does not contain a valid type. | [
"applyDefaultOptions",
"returns",
"a",
"new",
"FieldOptions",
"object",
"with",
"default",
"values",
"if",
"o",
"does",
"not",
"contain",
"a",
"valid",
"type",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1281-L1290 | train |
pilosa/pilosa | field.go | MarshalJSON | func (o *FieldOptions) MarshalJSON() ([]byte, error) {
switch o.Type {
case FieldTypeSet:
return json.Marshal(struct {
Type string `json:"type"`
CacheType string `json:"cacheType"`
CacheSize uint32 `json:"cacheSize"`
Keys bool `json:"keys"`
}{
o.Type,
o.CacheType,
o.CacheSize,
o.Keys,
})
case FieldTypeInt:
return json.Marshal(struct {
Type string `json:"type"`
Min int64 `json:"min"`
Max int64 `json:"max"`
Keys bool `json:"keys"`
}{
o.Type,
o.Min,
o.Max,
o.Keys,
})
case FieldTypeTime:
return json.Marshal(struct {
Type string `json:"type"`
TimeQuantum TimeQuantum `json:"timeQuantum"`
Keys bool `json:"keys"`
NoStandardView bool `json:"noStandardView"`
}{
o.Type,
o.TimeQuantum,
o.Keys,
o.NoStandardView,
})
case FieldTypeMutex:
return json.Marshal(struct {
Type string `json:"type"`
CacheType string `json:"cacheType"`
CacheSize uint32 `json:"cacheSize"`
Keys bool `json:"keys"`
}{
o.Type,
o.CacheType,
o.CacheSize,
o.Keys,
})
case FieldTypeBool:
return json.Marshal(struct {
Type string `json:"type"`
}{
o.Type,
})
}
return nil, errors.New("invalid field type")
} | go | func (o *FieldOptions) MarshalJSON() ([]byte, error) {
switch o.Type {
case FieldTypeSet:
return json.Marshal(struct {
Type string `json:"type"`
CacheType string `json:"cacheType"`
CacheSize uint32 `json:"cacheSize"`
Keys bool `json:"keys"`
}{
o.Type,
o.CacheType,
o.CacheSize,
o.Keys,
})
case FieldTypeInt:
return json.Marshal(struct {
Type string `json:"type"`
Min int64 `json:"min"`
Max int64 `json:"max"`
Keys bool `json:"keys"`
}{
o.Type,
o.Min,
o.Max,
o.Keys,
})
case FieldTypeTime:
return json.Marshal(struct {
Type string `json:"type"`
TimeQuantum TimeQuantum `json:"timeQuantum"`
Keys bool `json:"keys"`
NoStandardView bool `json:"noStandardView"`
}{
o.Type,
o.TimeQuantum,
o.Keys,
o.NoStandardView,
})
case FieldTypeMutex:
return json.Marshal(struct {
Type string `json:"type"`
CacheType string `json:"cacheType"`
CacheSize uint32 `json:"cacheSize"`
Keys bool `json:"keys"`
}{
o.Type,
o.CacheType,
o.CacheSize,
o.Keys,
})
case FieldTypeBool:
return json.Marshal(struct {
Type string `json:"type"`
}{
o.Type,
})
}
return nil, errors.New("invalid field type")
} | [
"func",
"(",
"o",
"*",
"FieldOptions",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"switch",
"o",
".",
"Type",
"{",
"case",
"FieldTypeSet",
":",
"return",
"json",
".",
"Marshal",
"(",
"struct",
"{",
"Type",
"string",
... | // MarshalJSON marshals FieldOptions to JSON such that
// only those attributes associated to the field type
// are included. | [
"MarshalJSON",
"marshals",
"FieldOptions",
"to",
"JSON",
"such",
"that",
"only",
"those",
"attributes",
"associated",
"to",
"the",
"field",
"type",
"are",
"included",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1316-L1374 | train |
pilosa/pilosa | field.go | BitDepth | func (b *bsiGroup) BitDepth() uint {
for i := uint(0); i < 63; i++ {
if b.Max-b.Min < (1 << i) {
return i
}
}
return 63
} | go | func (b *bsiGroup) BitDepth() uint {
for i := uint(0); i < 63; i++ {
if b.Max-b.Min < (1 << i) {
return i
}
}
return 63
} | [
"func",
"(",
"b",
"*",
"bsiGroup",
")",
"BitDepth",
"(",
")",
"uint",
"{",
"for",
"i",
":=",
"uint",
"(",
"0",
")",
";",
"i",
"<",
"63",
";",
"i",
"++",
"{",
"if",
"b",
".",
"Max",
"-",
"b",
".",
"Min",
"<",
"(",
"1",
"<<",
"i",
")",
"{... | // BitDepth returns the number of bits required to store a value between min & max. | [
"BitDepth",
"returns",
"the",
"number",
"of",
"bits",
"required",
"to",
"store",
"a",
"value",
"between",
"min",
"&",
"max",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1399-L1406 | train |
pilosa/pilosa | field.go | isValidCacheType | func isValidCacheType(v string) bool {
switch v {
case CacheTypeLRU, CacheTypeRanked, CacheTypeNone:
return true
default:
return false
}
} | go | func isValidCacheType(v string) bool {
switch v {
case CacheTypeLRU, CacheTypeRanked, CacheTypeNone:
return true
default:
return false
}
} | [
"func",
"isValidCacheType",
"(",
"v",
"string",
")",
"bool",
"{",
"switch",
"v",
"{",
"case",
"CacheTypeLRU",
",",
"CacheTypeRanked",
",",
"CacheTypeNone",
":",
"return",
"true",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"}"
] | // isValidCacheType returns true if v is a valid cache type. | [
"isValidCacheType",
"returns",
"true",
"if",
"v",
"is",
"a",
"valid",
"cache",
"type",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1481-L1488 | train |
pilosa/pilosa | gopsutil/systeminfo.go | Uptime | func (s *systemInfo) Uptime() (uptime uint64, err error) {
hostInfo, err := host.Info()
if err != nil {
return 0, err
}
return hostInfo.Uptime, nil
} | go | func (s *systemInfo) Uptime() (uptime uint64, err error) {
hostInfo, err := host.Info()
if err != nil {
return 0, err
}
return hostInfo.Uptime, nil
} | [
"func",
"(",
"s",
"*",
"systemInfo",
")",
"Uptime",
"(",
")",
"(",
"uptime",
"uint64",
",",
"err",
"error",
")",
"{",
"hostInfo",
",",
"err",
":=",
"host",
".",
"Info",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"... | // Uptime returns the system uptime in seconds. | [
"Uptime",
"returns",
"the",
"system",
"uptime",
"in",
"seconds",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L41-L47 | train |
pilosa/pilosa | gopsutil/systeminfo.go | collectPlatformInfo | func (s *systemInfo) collectPlatformInfo() error {
var err error
if s.platform == "" {
s.platform, s.family, s.osVersion, err = host.PlatformInformation()
if err != nil {
return err
}
}
if s.cpuModel == "" {
infos, err := cpu.Info()
if err != nil || len(infos) == 0 {
s.cpuModel = "unknown"
// if err is nil, but we got no infos, we don't
// have a meaningful error to return.
return err
}
s.cpuModel = infos[0].ModelName
s.cpuMHz = computeMHz(s.cpuModel)
// gopsutil reports core and clock speed info inconsistently
// by OS
switch runtime.GOOS {
case "linux":
// Each reported "CPU" is a logical core. Some cores may
// have the same Core ID, which is a strictly numeric
// value which gopsutil returned as a string, which
// indicates that they're hyperthreading or similar things
// on the same physical core.
uniqueCores := make(map[string]struct{}, len(infos))
totalCores := 0
for _, info := range infos {
uniqueCores[info.CoreID] = struct{}{}
totalCores += int(info.Cores)
}
s.cpuPhysicalCores = len(uniqueCores)
s.cpuLogicalCores = totalCores
case "darwin":
fallthrough
default: // let's hope other systems give useful core info?
s.cpuPhysicalCores = int(infos[0].Cores)
// we have no way to know, let's try runtime
s.cpuLogicalCores = runtime.NumCPU()
}
return nil
}
return nil
} | go | func (s *systemInfo) collectPlatformInfo() error {
var err error
if s.platform == "" {
s.platform, s.family, s.osVersion, err = host.PlatformInformation()
if err != nil {
return err
}
}
if s.cpuModel == "" {
infos, err := cpu.Info()
if err != nil || len(infos) == 0 {
s.cpuModel = "unknown"
// if err is nil, but we got no infos, we don't
// have a meaningful error to return.
return err
}
s.cpuModel = infos[0].ModelName
s.cpuMHz = computeMHz(s.cpuModel)
// gopsutil reports core and clock speed info inconsistently
// by OS
switch runtime.GOOS {
case "linux":
// Each reported "CPU" is a logical core. Some cores may
// have the same Core ID, which is a strictly numeric
// value which gopsutil returned as a string, which
// indicates that they're hyperthreading or similar things
// on the same physical core.
uniqueCores := make(map[string]struct{}, len(infos))
totalCores := 0
for _, info := range infos {
uniqueCores[info.CoreID] = struct{}{}
totalCores += int(info.Cores)
}
s.cpuPhysicalCores = len(uniqueCores)
s.cpuLogicalCores = totalCores
case "darwin":
fallthrough
default: // let's hope other systems give useful core info?
s.cpuPhysicalCores = int(infos[0].Cores)
// we have no way to know, let's try runtime
s.cpuLogicalCores = runtime.NumCPU()
}
return nil
}
return nil
} | [
"func",
"(",
"s",
"*",
"systemInfo",
")",
"collectPlatformInfo",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"if",
"s",
".",
"platform",
"==",
"\"\"",
"{",
"s",
".",
"platform",
",",
"s",
".",
"family",
",",
"s",
".",
"osVersion",
",",
"er... | // collectPlatformInfo fetches and caches system platform information. | [
"collectPlatformInfo",
"fetches",
"and",
"caches",
"system",
"platform",
"information",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L99-L145 | train |
pilosa/pilosa | gopsutil/systeminfo.go | Platform | func (s *systemInfo) Platform() (string, error) {
err := s.collectPlatformInfo()
if err != nil {
return "", err
}
return s.platform, nil
} | go | func (s *systemInfo) Platform() (string, error) {
err := s.collectPlatformInfo()
if err != nil {
return "", err
}
return s.platform, nil
} | [
"func",
"(",
"s",
"*",
"systemInfo",
")",
"Platform",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"err",
":=",
"s",
".",
"collectPlatformInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"re... | // Platform returns the system platform. | [
"Platform",
"returns",
"the",
"system",
"platform",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L148-L154 | train |
pilosa/pilosa | gopsutil/systeminfo.go | Family | func (s *systemInfo) Family() (string, error) {
err := s.collectPlatformInfo()
if err != nil {
return "", err
}
return s.family, err
} | go | func (s *systemInfo) Family() (string, error) {
err := s.collectPlatformInfo()
if err != nil {
return "", err
}
return s.family, err
} | [
"func",
"(",
"s",
"*",
"systemInfo",
")",
"Family",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"err",
":=",
"s",
".",
"collectPlatformInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"retu... | // Family returns the system family. | [
"Family",
"returns",
"the",
"system",
"family",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L157-L163 | train |
pilosa/pilosa | gopsutil/systeminfo.go | OSVersion | func (s *systemInfo) OSVersion() (string, error) {
err := s.collectPlatformInfo()
if err != nil {
return "", err
}
return s.osVersion, err
} | go | func (s *systemInfo) OSVersion() (string, error) {
err := s.collectPlatformInfo()
if err != nil {
return "", err
}
return s.osVersion, err
} | [
"func",
"(",
"s",
"*",
"systemInfo",
")",
"OSVersion",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"err",
":=",
"s",
".",
"collectPlatformInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"r... | // OSVersion returns the OS Version. | [
"OSVersion",
"returns",
"the",
"OS",
"Version",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L166-L172 | train |
pilosa/pilosa | gopsutil/systeminfo.go | MemFree | func (s *systemInfo) MemFree() (uint64, error) {
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, err
}
return memInfo.Free, err
} | go | func (s *systemInfo) MemFree() (uint64, error) {
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, err
}
return memInfo.Free, err
} | [
"func",
"(",
"s",
"*",
"systemInfo",
")",
"MemFree",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"memInfo",
",",
"err",
":=",
"mem",
".",
"VirtualMemory",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
... | // MemFree returns the amount of free memory in bytes. | [
"MemFree",
"returns",
"the",
"amount",
"of",
"free",
"memory",
"in",
"bytes",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L175-L181 | train |
pilosa/pilosa | gopsutil/systeminfo.go | MemTotal | func (s *systemInfo) MemTotal() (uint64, error) {
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, err
}
return memInfo.Total, err
} | go | func (s *systemInfo) MemTotal() (uint64, error) {
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, err
}
return memInfo.Total, err
} | [
"func",
"(",
"s",
"*",
"systemInfo",
")",
"MemTotal",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"memInfo",
",",
"err",
":=",
"mem",
".",
"VirtualMemory",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
... | // MemTotal returns the amount of total memory in bytes. | [
"MemTotal",
"returns",
"the",
"amount",
"of",
"total",
"memory",
"in",
"bytes",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L184-L190 | train |
pilosa/pilosa | gopsutil/systeminfo.go | MemUsed | func (s *systemInfo) MemUsed() (uint64, error) {
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, err
}
return memInfo.Used, err
} | go | func (s *systemInfo) MemUsed() (uint64, error) {
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, err
}
return memInfo.Used, err
} | [
"func",
"(",
"s",
"*",
"systemInfo",
")",
"MemUsed",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"memInfo",
",",
"err",
":=",
"mem",
".",
"VirtualMemory",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
... | // MemUsed returns the amount of used memory in bytes. | [
"MemUsed",
"returns",
"the",
"amount",
"of",
"used",
"memory",
"in",
"bytes",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L193-L199 | train |
pilosa/pilosa | gopsutil/systeminfo.go | CPUModel | func (s *systemInfo) CPUModel() string {
err := s.collectPlatformInfo()
if err != nil {
return "unknown"
}
return s.cpuModel
} | go | func (s *systemInfo) CPUModel() string {
err := s.collectPlatformInfo()
if err != nil {
return "unknown"
}
return s.cpuModel
} | [
"func",
"(",
"s",
"*",
"systemInfo",
")",
"CPUModel",
"(",
")",
"string",
"{",
"err",
":=",
"s",
".",
"collectPlatformInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"unknown\"",
"\n",
"}",
"\n",
"return",
"s",
".",
"cpuModel",
"\n"... | // CPUModel returns the CPU model string | [
"CPUModel",
"returns",
"the",
"CPU",
"model",
"string"
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L212-L218 | train |
pilosa/pilosa | gopsutil/systeminfo.go | CPUMHz | func (s *systemInfo) CPUMHz() (int, error) {
err := s.collectPlatformInfo()
if err != nil {
return 0, err
}
return s.cpuMHz, nil
} | go | func (s *systemInfo) CPUMHz() (int, error) {
err := s.collectPlatformInfo()
if err != nil {
return 0, err
}
return s.cpuMHz, nil
} | [
"func",
"(",
"s",
"*",
"systemInfo",
")",
"CPUMHz",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"err",
":=",
"s",
".",
"collectPlatformInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
... | // CPUMhz returns the CPU clock speed | [
"CPUMhz",
"returns",
"the",
"CPU",
"clock",
"speed"
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L221-L227 | train |
pilosa/pilosa | iterator.go | Next | func (itr *bufIterator) Next() (rowID, columnID uint64, eof bool) {
if itr.buf.full {
itr.buf.full = false
return itr.buf.rowID, itr.buf.columnID, itr.buf.eof
}
// Read values onto buffer in case of unread.
itr.buf.rowID, itr.buf.columnID, itr.buf.eof = itr.itr.Next()
return itr.buf.rowID, itr.buf.columnID, itr.buf.eof
} | go | func (itr *bufIterator) Next() (rowID, columnID uint64, eof bool) {
if itr.buf.full {
itr.buf.full = false
return itr.buf.rowID, itr.buf.columnID, itr.buf.eof
}
// Read values onto buffer in case of unread.
itr.buf.rowID, itr.buf.columnID, itr.buf.eof = itr.itr.Next()
return itr.buf.rowID, itr.buf.columnID, itr.buf.eof
} | [
"func",
"(",
"itr",
"*",
"bufIterator",
")",
"Next",
"(",
")",
"(",
"rowID",
",",
"columnID",
"uint64",
",",
"eof",
"bool",
")",
"{",
"if",
"itr",
".",
"buf",
".",
"full",
"{",
"itr",
".",
"buf",
".",
"full",
"=",
"false",
"\n",
"return",
"itr",
... | // Next returns the next pair in the row.
// If a value has been buffered then it is returned and the buffer is cleared. | [
"Next",
"returns",
"the",
"next",
"pair",
"in",
"the",
"row",
".",
"If",
"a",
"value",
"has",
"been",
"buffered",
"then",
"it",
"is",
"returned",
"and",
"the",
"buffer",
"is",
"cleared",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/iterator.go#L53-L63 | train |
pilosa/pilosa | iterator.go | Peek | func (itr *bufIterator) Peek() (rowID, columnID uint64, eof bool) {
rowID, columnID, eof = itr.Next()
itr.Unread()
return
} | go | func (itr *bufIterator) Peek() (rowID, columnID uint64, eof bool) {
rowID, columnID, eof = itr.Next()
itr.Unread()
return
} | [
"func",
"(",
"itr",
"*",
"bufIterator",
")",
"Peek",
"(",
")",
"(",
"rowID",
",",
"columnID",
"uint64",
",",
"eof",
"bool",
")",
"{",
"rowID",
",",
"columnID",
",",
"eof",
"=",
"itr",
".",
"Next",
"(",
")",
"\n",
"itr",
".",
"Unread",
"(",
")",
... | // Peek reads the next value but leaves it on the buffer. | [
"Peek",
"reads",
"the",
"next",
"value",
"but",
"leaves",
"it",
"on",
"the",
"buffer",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/iterator.go#L66-L70 | train |
pilosa/pilosa | iterator.go | Unread | func (itr *bufIterator) Unread() {
if itr.buf.full {
panic("pilosa.BufIterator: buffer full")
}
itr.buf.full = true
} | go | func (itr *bufIterator) Unread() {
if itr.buf.full {
panic("pilosa.BufIterator: buffer full")
}
itr.buf.full = true
} | [
"func",
"(",
"itr",
"*",
"bufIterator",
")",
"Unread",
"(",
")",
"{",
"if",
"itr",
".",
"buf",
".",
"full",
"{",
"panic",
"(",
"\"pilosa.BufIterator: buffer full\"",
")",
"\n",
"}",
"\n",
"itr",
".",
"buf",
".",
"full",
"=",
"true",
"\n",
"}"
] | // Unread pushes previous pair on to the buffer.
// Panics if the buffer is already full. | [
"Unread",
"pushes",
"previous",
"pair",
"on",
"to",
"the",
"buffer",
".",
"Panics",
"if",
"the",
"buffer",
"is",
"already",
"full",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/iterator.go#L74-L79 | train |
pilosa/pilosa | iterator.go | newLimitIterator | func newLimitIterator(itr iterator, maxRowID, maxColumnID uint64) *limitIterator { // nolint: unparam
return &limitIterator{
itr: itr,
maxRowID: maxRowID,
maxColumnID: maxColumnID,
}
} | go | func newLimitIterator(itr iterator, maxRowID, maxColumnID uint64) *limitIterator { // nolint: unparam
return &limitIterator{
itr: itr,
maxRowID: maxRowID,
maxColumnID: maxColumnID,
}
} | [
"func",
"newLimitIterator",
"(",
"itr",
"iterator",
",",
"maxRowID",
",",
"maxColumnID",
"uint64",
")",
"*",
"limitIterator",
"{",
"return",
"&",
"limitIterator",
"{",
"itr",
":",
"itr",
",",
"maxRowID",
":",
"maxRowID",
",",
"maxColumnID",
":",
"maxColumnID",... | // newLimitIterator returns a new LimitIterator. | [
"newLimitIterator",
"returns",
"a",
"new",
"LimitIterator",
"."
] | 67d53f6b48a43f7fe090f48e35518ca8d024747c | https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/iterator.go#L91-L97 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.