repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
prometheus/tsdb | wal.go | truncate | func (w *SegmentWAL) truncate(err error, file int, lastOffset int64) error {
level.Error(w.logger).Log("msg", "WAL corruption detected; truncating",
"err", err, "file", w.files[file].Name(), "pos", lastOffset)
// Close and delete all files after the current one.
for _, f := range w.files[file+1:] {
if err := f.... | go | func (w *SegmentWAL) truncate(err error, file int, lastOffset int64) error {
level.Error(w.logger).Log("msg", "WAL corruption detected; truncating",
"err", err, "file", w.files[file].Name(), "pos", lastOffset)
// Close and delete all files after the current one.
for _, f := range w.files[file+1:] {
if err := f.... | [
"func",
"(",
"w",
"*",
"SegmentWAL",
")",
"truncate",
"(",
"err",
"error",
",",
"file",
"int",
",",
"lastOffset",
"int64",
")",
"error",
"{",
"level",
".",
"Error",
"(",
"w",
".",
"logger",
")",
".",
"Log",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
... | // truncate the WAL after the last valid entry. | [
"truncate",
"the",
"WAL",
"after",
"the",
"last",
"valid",
"entry",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal.go#L259-L280 | train |
prometheus/tsdb | wal.go | Reader | func (w *SegmentWAL) Reader() WALReader {
return &repairingWALReader{
wal: w,
r: newWALReader(w.files, w.logger),
}
} | go | func (w *SegmentWAL) Reader() WALReader {
return &repairingWALReader{
wal: w,
r: newWALReader(w.files, w.logger),
}
} | [
"func",
"(",
"w",
"*",
"SegmentWAL",
")",
"Reader",
"(",
")",
"WALReader",
"{",
"return",
"&",
"repairingWALReader",
"{",
"wal",
":",
"w",
",",
"r",
":",
"newWALReader",
"(",
"w",
".",
"files",
",",
"w",
".",
"logger",
")",
",",
"}",
"\n",
"}"
] | // Reader returns a new reader over the the write ahead log data.
// It must be completely consumed before writing to the WAL. | [
"Reader",
"returns",
"a",
"new",
"reader",
"over",
"the",
"the",
"write",
"ahead",
"log",
"data",
".",
"It",
"must",
"be",
"completely",
"consumed",
"before",
"writing",
"to",
"the",
"WAL",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal.go#L284-L289 | train |
prometheus/tsdb | wal.go | LogSeries | func (w *SegmentWAL) LogSeries(series []RefSeries) error {
buf := w.getBuffer()
flag := w.encodeSeries(buf, series)
w.mtx.Lock()
defer w.mtx.Unlock()
err := w.write(WALEntrySeries, flag, buf.Get())
w.putBuffer(buf)
if err != nil {
return errors.Wrap(err, "log series")
}
tf := w.head()
for _, s := ran... | go | func (w *SegmentWAL) LogSeries(series []RefSeries) error {
buf := w.getBuffer()
flag := w.encodeSeries(buf, series)
w.mtx.Lock()
defer w.mtx.Unlock()
err := w.write(WALEntrySeries, flag, buf.Get())
w.putBuffer(buf)
if err != nil {
return errors.Wrap(err, "log series")
}
tf := w.head()
for _, s := ran... | [
"func",
"(",
"w",
"*",
"SegmentWAL",
")",
"LogSeries",
"(",
"series",
"[",
"]",
"RefSeries",
")",
"error",
"{",
"buf",
":=",
"w",
".",
"getBuffer",
"(",
")",
"\n\n",
"flag",
":=",
"w",
".",
"encodeSeries",
"(",
"buf",
",",
"series",
")",
"\n\n",
"w... | // LogSeries writes a batch of new series labels to the log.
// The series have to be ordered. | [
"LogSeries",
"writes",
"a",
"batch",
"of",
"new",
"series",
"labels",
"to",
"the",
"log",
".",
"The",
"series",
"have",
"to",
"be",
"ordered",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal.go#L429-L453 | train |
prometheus/tsdb | wal.go | LogSamples | func (w *SegmentWAL) LogSamples(samples []RefSample) error {
buf := w.getBuffer()
flag := w.encodeSamples(buf, samples)
w.mtx.Lock()
defer w.mtx.Unlock()
err := w.write(WALEntrySamples, flag, buf.Get())
w.putBuffer(buf)
if err != nil {
return errors.Wrap(err, "log series")
}
tf := w.head()
for _, s :=... | go | func (w *SegmentWAL) LogSamples(samples []RefSample) error {
buf := w.getBuffer()
flag := w.encodeSamples(buf, samples)
w.mtx.Lock()
defer w.mtx.Unlock()
err := w.write(WALEntrySamples, flag, buf.Get())
w.putBuffer(buf)
if err != nil {
return errors.Wrap(err, "log series")
}
tf := w.head()
for _, s :=... | [
"func",
"(",
"w",
"*",
"SegmentWAL",
")",
"LogSamples",
"(",
"samples",
"[",
"]",
"RefSample",
")",
"error",
"{",
"buf",
":=",
"w",
".",
"getBuffer",
"(",
")",
"\n\n",
"flag",
":=",
"w",
".",
"encodeSamples",
"(",
"buf",
",",
"samples",
")",
"\n\n",
... | // LogSamples writes a batch of new samples to the log. | [
"LogSamples",
"writes",
"a",
"batch",
"of",
"new",
"samples",
"to",
"the",
"log",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal.go#L456-L479 | train |
prometheus/tsdb | wal.go | LogDeletes | func (w *SegmentWAL) LogDeletes(stones []Stone) error {
buf := w.getBuffer()
flag := w.encodeDeletes(buf, stones)
w.mtx.Lock()
defer w.mtx.Unlock()
err := w.write(WALEntryDeletes, flag, buf.Get())
w.putBuffer(buf)
if err != nil {
return errors.Wrap(err, "log series")
}
tf := w.head()
for _, s := range... | go | func (w *SegmentWAL) LogDeletes(stones []Stone) error {
buf := w.getBuffer()
flag := w.encodeDeletes(buf, stones)
w.mtx.Lock()
defer w.mtx.Unlock()
err := w.write(WALEntryDeletes, flag, buf.Get())
w.putBuffer(buf)
if err != nil {
return errors.Wrap(err, "log series")
}
tf := w.head()
for _, s := range... | [
"func",
"(",
"w",
"*",
"SegmentWAL",
")",
"LogDeletes",
"(",
"stones",
"[",
"]",
"Stone",
")",
"error",
"{",
"buf",
":=",
"w",
".",
"getBuffer",
"(",
")",
"\n\n",
"flag",
":=",
"w",
".",
"encodeDeletes",
"(",
"buf",
",",
"stones",
")",
"\n\n",
"w",... | // LogDeletes write a batch of new deletes to the log. | [
"LogDeletes",
"write",
"a",
"batch",
"of",
"new",
"deletes",
"to",
"the",
"log",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal.go#L482-L507 | train |
prometheus/tsdb | wal.go | openSegmentFile | func (w *SegmentWAL) openSegmentFile(name string) (*os.File, error) {
// We must open all files in read/write mode as we may have to truncate along
// the way and any file may become the head.
f, err := os.OpenFile(name, os.O_RDWR, 0666)
if err != nil {
return nil, err
}
metab := make([]byte, 8)
// If there i... | go | func (w *SegmentWAL) openSegmentFile(name string) (*os.File, error) {
// We must open all files in read/write mode as we may have to truncate along
// the way and any file may become the head.
f, err := os.OpenFile(name, os.O_RDWR, 0666)
if err != nil {
return nil, err
}
metab := make([]byte, 8)
// If there i... | [
"func",
"(",
"w",
"*",
"SegmentWAL",
")",
"openSegmentFile",
"(",
"name",
"string",
")",
"(",
"*",
"os",
".",
"File",
",",
"error",
")",
"{",
"// We must open all files in read/write mode as we may have to truncate along",
"// the way and any file may become the head.",
"... | // openSegmentFile opens the given segment file and consumes and validates header. | [
"openSegmentFile",
"opens",
"the",
"given",
"segment",
"file",
"and",
"consumes",
"and",
"validates",
"header",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal.go#L510-L542 | train |
prometheus/tsdb | wal.go | createSegmentFile | func (w *SegmentWAL) createSegmentFile(name string) (*os.File, error) {
f, err := os.Create(name)
if err != nil {
return nil, err
}
if err = fileutil.Preallocate(f, w.segmentSize, true); err != nil {
return nil, err
}
// Write header metadata for new file.
metab := make([]byte, 8)
binary.BigEndian.PutUint32... | go | func (w *SegmentWAL) createSegmentFile(name string) (*os.File, error) {
f, err := os.Create(name)
if err != nil {
return nil, err
}
if err = fileutil.Preallocate(f, w.segmentSize, true); err != nil {
return nil, err
}
// Write header metadata for new file.
metab := make([]byte, 8)
binary.BigEndian.PutUint32... | [
"func",
"(",
"w",
"*",
"SegmentWAL",
")",
"createSegmentFile",
"(",
"name",
"string",
")",
"(",
"*",
"os",
".",
"File",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"... | // createSegmentFile creates a new segment file with the given name. It preallocates
// the standard segment size if possible and writes the header. | [
"createSegmentFile",
"creates",
"a",
"new",
"segment",
"file",
"with",
"the",
"given",
"name",
".",
"It",
"preallocates",
"the",
"standard",
"segment",
"size",
"if",
"possible",
"and",
"writes",
"the",
"header",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal.go#L546-L563 | train |
prometheus/tsdb | wal.go | cut | func (w *SegmentWAL) cut() error {
// Sync current head to disk and close.
if hf := w.head(); hf != nil {
if err := w.flush(); err != nil {
return err
}
// Finish last segment asynchronously to not block the WAL moving along
// in the new segment.
go func() {
w.actorc <- func() error {
off, err :=... | go | func (w *SegmentWAL) cut() error {
// Sync current head to disk and close.
if hf := w.head(); hf != nil {
if err := w.flush(); err != nil {
return err
}
// Finish last segment asynchronously to not block the WAL moving along
// in the new segment.
go func() {
w.actorc <- func() error {
off, err :=... | [
"func",
"(",
"w",
"*",
"SegmentWAL",
")",
"cut",
"(",
")",
"error",
"{",
"// Sync current head to disk and close.",
"if",
"hf",
":=",
"w",
".",
"head",
"(",
")",
";",
"hf",
"!=",
"nil",
"{",
"if",
"err",
":=",
"w",
".",
"flush",
"(",
")",
";",
"err... | // cut finishes the currently active segments and opens the next one.
// The encoder is reset to point to the new segment. | [
"cut",
"finishes",
"the",
"currently",
"active",
"segments",
"and",
"opens",
"the",
"next",
"one",
".",
"The",
"encoder",
"is",
"reset",
"to",
"point",
"to",
"the",
"new",
"segment",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal.go#L567-L617 | train |
prometheus/tsdb | wal.go | Sync | func (w *SegmentWAL) Sync() error {
var head *segmentFile
var err error
// Flush the writer and retrieve the reference to the head segment under mutex lock.
func() {
w.mtx.Lock()
defer w.mtx.Unlock()
if err = w.flush(); err != nil {
return
}
head = w.head()
}()
if err != nil {
return errors.Wrap(e... | go | func (w *SegmentWAL) Sync() error {
var head *segmentFile
var err error
// Flush the writer and retrieve the reference to the head segment under mutex lock.
func() {
w.mtx.Lock()
defer w.mtx.Unlock()
if err = w.flush(); err != nil {
return
}
head = w.head()
}()
if err != nil {
return errors.Wrap(e... | [
"func",
"(",
"w",
"*",
"SegmentWAL",
")",
"Sync",
"(",
")",
"error",
"{",
"var",
"head",
"*",
"segmentFile",
"\n",
"var",
"err",
"error",
"\n\n",
"// Flush the writer and retrieve the reference to the head segment under mutex lock.",
"func",
"(",
")",
"{",
"w",
".... | // Sync flushes the changes to disk. | [
"Sync",
"flushes",
"the",
"changes",
"to",
"disk",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal.go#L627-L651 | train |
prometheus/tsdb | wal.go | Close | func (w *SegmentWAL) Close() error {
// Make sure you can call Close() multiple times.
select {
case <-w.stopc:
return nil // Already closed.
default:
}
close(w.stopc)
<-w.donec
w.mtx.Lock()
defer w.mtx.Unlock()
if err := w.sync(); err != nil {
return err
}
// On opening, a WAL must be fully consumed... | go | func (w *SegmentWAL) Close() error {
// Make sure you can call Close() multiple times.
select {
case <-w.stopc:
return nil // Already closed.
default:
}
close(w.stopc)
<-w.donec
w.mtx.Lock()
defer w.mtx.Unlock()
if err := w.sync(); err != nil {
return err
}
// On opening, a WAL must be fully consumed... | [
"func",
"(",
"w",
"*",
"SegmentWAL",
")",
"Close",
"(",
")",
"error",
"{",
"// Make sure you can call Close() multiple times.",
"select",
"{",
"case",
"<-",
"w",
".",
"stopc",
":",
"return",
"nil",
"// Already closed.",
"\n",
"default",
":",
"}",
"\n\n",
"clos... | // Close syncs all data and closes the underlying resources. | [
"Close",
"syncs",
"all",
"data",
"and",
"closes",
"the",
"underlying",
"resources",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal.go#L711-L737 | train |
prometheus/tsdb | wal.go | next | func (r *walReader) next() bool {
if r.cur >= len(r.files) {
return false
}
cf := r.files[r.cur]
// Remember the offset after the last correctly read entry. If the next one
// is corrupted, this is where we can safely truncate.
r.lastOffset, r.err = cf.Seek(0, io.SeekCurrent)
if r.err != nil {
return false
... | go | func (r *walReader) next() bool {
if r.cur >= len(r.files) {
return false
}
cf := r.files[r.cur]
// Remember the offset after the last correctly read entry. If the next one
// is corrupted, this is where we can safely truncate.
r.lastOffset, r.err = cf.Seek(0, io.SeekCurrent)
if r.err != nil {
return false
... | [
"func",
"(",
"r",
"*",
"walReader",
")",
"next",
"(",
")",
"bool",
"{",
"if",
"r",
".",
"cur",
">=",
"len",
"(",
"r",
".",
"files",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"cf",
":=",
"r",
".",
"files",
"[",
"r",
".",
"cur",
"]",
"\n\... | // next returns decodes the next entry pair and returns true
// if it was successful. | [
"next",
"returns",
"decodes",
"the",
"next",
"entry",
"pair",
"and",
"returns",
"true",
"if",
"it",
"was",
"successful",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal.go#L1013-L1051 | train |
prometheus/tsdb | wal.go | MigrateWAL | func MigrateWAL(logger log.Logger, dir string) (err error) {
if logger == nil {
logger = log.NewNopLogger()
}
if exists, err := deprecatedWALExists(logger, dir); err != nil || !exists {
return err
}
level.Info(logger).Log("msg", "migrating WAL format")
tmpdir := dir + ".tmp"
if err := os.RemoveAll(tmpdir); ... | go | func MigrateWAL(logger log.Logger, dir string) (err error) {
if logger == nil {
logger = log.NewNopLogger()
}
if exists, err := deprecatedWALExists(logger, dir); err != nil || !exists {
return err
}
level.Info(logger).Log("msg", "migrating WAL format")
tmpdir := dir + ".tmp"
if err := os.RemoveAll(tmpdir); ... | [
"func",
"MigrateWAL",
"(",
"logger",
"log",
".",
"Logger",
",",
"dir",
"string",
")",
"(",
"err",
"error",
")",
"{",
"if",
"logger",
"==",
"nil",
"{",
"logger",
"=",
"log",
".",
"NewNopLogger",
"(",
")",
"\n",
"}",
"\n",
"if",
"exists",
",",
"err",... | // MigrateWAL rewrites the deprecated write ahead log into the new format. | [
"MigrateWAL",
"rewrites",
"the",
"deprecated",
"write",
"ahead",
"log",
"into",
"the",
"new",
"format",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal.go#L1235-L1312 | train |
prometheus/tsdb | db.go | Appender | func (db *DB) Appender() Appender {
return dbAppender{db: db, Appender: db.head.Appender()}
} | go | func (db *DB) Appender() Appender {
return dbAppender{db: db, Appender: db.head.Appender()}
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Appender",
"(",
")",
"Appender",
"{",
"return",
"dbAppender",
"{",
"db",
":",
"db",
",",
"Appender",
":",
"db",
".",
"head",
".",
"Appender",
"(",
")",
"}",
"\n",
"}"
] | // Appender opens a new appender against the database. | [
"Appender",
"opens",
"a",
"new",
"appender",
"against",
"the",
"database",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/db.go#L379-L381 | train |
prometheus/tsdb | db.go | compact | func (db *DB) compact() (err error) {
db.cmtx.Lock()
defer db.cmtx.Unlock()
// Check whether we have pending head blocks that are ready to be persisted.
// They have the highest priority.
for {
select {
case <-db.stopc:
return nil
default:
}
if !db.head.compactable() {
break
}
mint := db.head.M... | go | func (db *DB) compact() (err error) {
db.cmtx.Lock()
defer db.cmtx.Unlock()
// Check whether we have pending head blocks that are ready to be persisted.
// They have the highest priority.
for {
select {
case <-db.stopc:
return nil
default:
}
if !db.head.compactable() {
break
}
mint := db.head.M... | [
"func",
"(",
"db",
"*",
"DB",
")",
"compact",
"(",
")",
"(",
"err",
"error",
")",
"{",
"db",
".",
"cmtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"cmtx",
".",
"Unlock",
"(",
")",
"\n",
"// Check whether we have pending head blocks that are ready... | // Compact data if possible. After successful compaction blocks are reloaded
// which will also trigger blocks to be deleted that fall out of the retention
// window.
// If no blocks are compacted, the retention window state doesn't change. Thus,
// this is sufficient to reliably delete old data.
// Old blocks are only... | [
"Compact",
"data",
"if",
"possible",
".",
"After",
"successful",
"compaction",
"blocks",
"are",
"reloaded",
"which",
"will",
"also",
"trigger",
"blocks",
"to",
"be",
"deleted",
"that",
"fall",
"out",
"of",
"the",
"retention",
"window",
".",
"If",
"no",
"bloc... | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/db.go#L411-L496 | train |
prometheus/tsdb | db.go | deletableBlocks | func (db *DB) deletableBlocks(blocks []*Block) map[ulid.ULID]*Block {
deletable := make(map[ulid.ULID]*Block)
// Sort the blocks by time - newest to oldest (largest to smallest timestamp).
// This ensures that the retentions will remove the oldest blocks.
sort.Slice(blocks, func(i, j int) bool {
return blocks[i... | go | func (db *DB) deletableBlocks(blocks []*Block) map[ulid.ULID]*Block {
deletable := make(map[ulid.ULID]*Block)
// Sort the blocks by time - newest to oldest (largest to smallest timestamp).
// This ensures that the retentions will remove the oldest blocks.
sort.Slice(blocks, func(i, j int) bool {
return blocks[i... | [
"func",
"(",
"db",
"*",
"DB",
")",
"deletableBlocks",
"(",
"blocks",
"[",
"]",
"*",
"Block",
")",
"map",
"[",
"ulid",
".",
"ULID",
"]",
"*",
"Block",
"{",
"deletable",
":=",
"make",
"(",
"map",
"[",
"ulid",
".",
"ULID",
"]",
"*",
"Block",
")",
... | // deletableBlocks returns all blocks past retention policy. | [
"deletableBlocks",
"returns",
"all",
"blocks",
"past",
"retention",
"policy",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/db.go#L634-L658 | train |
prometheus/tsdb | db.go | deleteBlocks | func (db *DB) deleteBlocks(blocks map[ulid.ULID]*Block) error {
for ulid, block := range blocks {
if block != nil {
if err := block.Close(); err != nil {
level.Warn(db.logger).Log("msg", "closing block failed", "err", err)
}
}
if err := os.RemoveAll(filepath.Join(db.dir, ulid.String())); err != nil {
... | go | func (db *DB) deleteBlocks(blocks map[ulid.ULID]*Block) error {
for ulid, block := range blocks {
if block != nil {
if err := block.Close(); err != nil {
level.Warn(db.logger).Log("msg", "closing block failed", "err", err)
}
}
if err := os.RemoveAll(filepath.Join(db.dir, ulid.String())); err != nil {
... | [
"func",
"(",
"db",
"*",
"DB",
")",
"deleteBlocks",
"(",
"blocks",
"map",
"[",
"ulid",
".",
"ULID",
"]",
"*",
"Block",
")",
"error",
"{",
"for",
"ulid",
",",
"block",
":=",
"range",
"blocks",
"{",
"if",
"block",
"!=",
"nil",
"{",
"if",
"err",
":="... | // deleteBlocks closes and deletes blocks from the disk.
// When the map contains a non nil block object it means it is loaded in memory
// so needs to be closed first as it might need to wait for pending readers to complete. | [
"deleteBlocks",
"closes",
"and",
"deletes",
"blocks",
"from",
"the",
"disk",
".",
"When",
"the",
"map",
"contains",
"a",
"non",
"nil",
"block",
"object",
"it",
"means",
"it",
"is",
"loaded",
"in",
"memory",
"so",
"needs",
"to",
"be",
"closed",
"first",
"... | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/db.go#L706-L718 | train |
prometheus/tsdb | db.go | validateBlockSequence | func validateBlockSequence(bs []*Block) error {
if len(bs) <= 1 {
return nil
}
var metas []BlockMeta
for _, b := range bs {
metas = append(metas, b.meta)
}
overlaps := OverlappingBlocks(metas)
if len(overlaps) > 0 {
return errors.Errorf("block time ranges overlap: %s", overlaps)
}
return nil
} | go | func validateBlockSequence(bs []*Block) error {
if len(bs) <= 1 {
return nil
}
var metas []BlockMeta
for _, b := range bs {
metas = append(metas, b.meta)
}
overlaps := OverlappingBlocks(metas)
if len(overlaps) > 0 {
return errors.Errorf("block time ranges overlap: %s", overlaps)
}
return nil
} | [
"func",
"validateBlockSequence",
"(",
"bs",
"[",
"]",
"*",
"Block",
")",
"error",
"{",
"if",
"len",
"(",
"bs",
")",
"<=",
"1",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"metas",
"[",
"]",
"BlockMeta",
"\n",
"for",
"_",
",",
"b",
":=",
"rang... | // validateBlockSequence returns error if given block meta files indicate that some blocks overlaps within sequence. | [
"validateBlockSequence",
"returns",
"error",
"if",
"given",
"block",
"meta",
"files",
"indicate",
"that",
"some",
"blocks",
"overlaps",
"within",
"sequence",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/db.go#L721-L737 | train |
prometheus/tsdb | db.go | String | func (o Overlaps) String() string {
var res []string
for r, overlaps := range o {
var groups []string
for _, m := range overlaps {
groups = append(groups, fmt.Sprintf(
"<ulid: %s, mint: %d, maxt: %d, range: %s>",
m.ULID.String(),
m.MinTime,
m.MaxTime,
(time.Duration((m.MaxTime-m.MinTime)/10... | go | func (o Overlaps) String() string {
var res []string
for r, overlaps := range o {
var groups []string
for _, m := range overlaps {
groups = append(groups, fmt.Sprintf(
"<ulid: %s, mint: %d, maxt: %d, range: %s>",
m.ULID.String(),
m.MinTime,
m.MaxTime,
(time.Duration((m.MaxTime-m.MinTime)/10... | [
"func",
"(",
"o",
"Overlaps",
")",
"String",
"(",
")",
"string",
"{",
"var",
"res",
"[",
"]",
"string",
"\n",
"for",
"r",
",",
"overlaps",
":=",
"range",
"o",
"{",
"var",
"groups",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
... | // String returns human readable string form of overlapped blocks. | [
"String",
"returns",
"human",
"readable",
"string",
"form",
"of",
"overlapped",
"blocks",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/db.go#L748-L770 | train |
prometheus/tsdb | db.go | OverlappingBlocks | func OverlappingBlocks(bm []BlockMeta) Overlaps {
if len(bm) <= 1 {
return nil
}
var (
overlaps [][]BlockMeta
// pending contains not ended blocks in regards to "current" timestamp.
pending = []BlockMeta{bm[0]}
// continuousPending helps to aggregate same overlaps to single group.
continuousPending = tr... | go | func OverlappingBlocks(bm []BlockMeta) Overlaps {
if len(bm) <= 1 {
return nil
}
var (
overlaps [][]BlockMeta
// pending contains not ended blocks in regards to "current" timestamp.
pending = []BlockMeta{bm[0]}
// continuousPending helps to aggregate same overlaps to single group.
continuousPending = tr... | [
"func",
"OverlappingBlocks",
"(",
"bm",
"[",
"]",
"BlockMeta",
")",
"Overlaps",
"{",
"if",
"len",
"(",
"bm",
")",
"<=",
"1",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"var",
"(",
"overlaps",
"[",
"]",
"[",
"]",
"BlockMeta",
"\n\n",
"// pending contains no... | // OverlappingBlocks returns all overlapping blocks from given meta files. | [
"OverlappingBlocks",
"returns",
"all",
"overlapping",
"blocks",
"from",
"given",
"meta",
"files",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/db.go#L773-L837 | train |
prometheus/tsdb | db.go | Blocks | func (db *DB) Blocks() []*Block {
db.mtx.RLock()
defer db.mtx.RUnlock()
return db.blocks
} | go | func (db *DB) Blocks() []*Block {
db.mtx.RLock()
defer db.mtx.RUnlock()
return db.blocks
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Blocks",
"(",
")",
"[",
"]",
"*",
"Block",
"{",
"db",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"db",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"db",
".",
"blocks",
"\n",
"}"
] | // Blocks returns the databases persisted blocks. | [
"Blocks",
"returns",
"the",
"databases",
"persisted",
"blocks",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/db.go#L844-L849 | train |
prometheus/tsdb | db.go | Close | func (db *DB) Close() error {
close(db.stopc)
db.compactCancel()
<-db.donec
db.mtx.Lock()
defer db.mtx.Unlock()
var g errgroup.Group
// blocks also contains all head blocks.
for _, pb := range db.blocks {
g.Go(pb.Close)
}
var merr tsdb_errors.MultiError
merr.Add(g.Wait())
if db.lockf != nil {
merr... | go | func (db *DB) Close() error {
close(db.stopc)
db.compactCancel()
<-db.donec
db.mtx.Lock()
defer db.mtx.Unlock()
var g errgroup.Group
// blocks also contains all head blocks.
for _, pb := range db.blocks {
g.Go(pb.Close)
}
var merr tsdb_errors.MultiError
merr.Add(g.Wait())
if db.lockf != nil {
merr... | [
"func",
"(",
"db",
"*",
"DB",
")",
"Close",
"(",
")",
"error",
"{",
"close",
"(",
"db",
".",
"stopc",
")",
"\n",
"db",
".",
"compactCancel",
"(",
")",
"\n",
"<-",
"db",
".",
"donec",
"\n\n",
"db",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"def... | // Close the partition. | [
"Close",
"the",
"partition",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/db.go#L857-L881 | train |
prometheus/tsdb | db.go | DisableCompactions | func (db *DB) DisableCompactions() {
db.autoCompactMtx.Lock()
defer db.autoCompactMtx.Unlock()
db.autoCompact = false
level.Info(db.logger).Log("msg", "compactions disabled")
} | go | func (db *DB) DisableCompactions() {
db.autoCompactMtx.Lock()
defer db.autoCompactMtx.Unlock()
db.autoCompact = false
level.Info(db.logger).Log("msg", "compactions disabled")
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"DisableCompactions",
"(",
")",
"{",
"db",
".",
"autoCompactMtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"autoCompactMtx",
".",
"Unlock",
"(",
")",
"\n\n",
"db",
".",
"autoCompact",
"=",
"false",
"\n",
"le... | // DisableCompactions disables auto compactions. | [
"DisableCompactions",
"disables",
"auto",
"compactions",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/db.go#L884-L890 | train |
prometheus/tsdb | db.go | EnableCompactions | func (db *DB) EnableCompactions() {
db.autoCompactMtx.Lock()
defer db.autoCompactMtx.Unlock()
db.autoCompact = true
level.Info(db.logger).Log("msg", "compactions enabled")
} | go | func (db *DB) EnableCompactions() {
db.autoCompactMtx.Lock()
defer db.autoCompactMtx.Unlock()
db.autoCompact = true
level.Info(db.logger).Log("msg", "compactions enabled")
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"EnableCompactions",
"(",
")",
"{",
"db",
".",
"autoCompactMtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"autoCompactMtx",
".",
"Unlock",
"(",
")",
"\n\n",
"db",
".",
"autoCompact",
"=",
"true",
"\n",
"leve... | // EnableCompactions enables auto compactions. | [
"EnableCompactions",
"enables",
"auto",
"compactions",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/db.go#L893-L899 | train |
prometheus/tsdb | db.go | Querier | func (db *DB) Querier(mint, maxt int64) (Querier, error) {
var blocks []BlockReader
var blockMetas []BlockMeta
db.mtx.RLock()
defer db.mtx.RUnlock()
for _, b := range db.blocks {
if b.OverlapsClosedInterval(mint, maxt) {
blocks = append(blocks, b)
blockMetas = append(blockMetas, b.Meta())
}
}
if maxt... | go | func (db *DB) Querier(mint, maxt int64) (Querier, error) {
var blocks []BlockReader
var blockMetas []BlockMeta
db.mtx.RLock()
defer db.mtx.RUnlock()
for _, b := range db.blocks {
if b.OverlapsClosedInterval(mint, maxt) {
blocks = append(blocks, b)
blockMetas = append(blockMetas, b.Meta())
}
}
if maxt... | [
"func",
"(",
"db",
"*",
"DB",
")",
"Querier",
"(",
"mint",
",",
"maxt",
"int64",
")",
"(",
"Querier",
",",
"error",
")",
"{",
"var",
"blocks",
"[",
"]",
"BlockReader",
"\n",
"var",
"blockMetas",
"[",
"]",
"BlockMeta",
"\n\n",
"db",
".",
"mtx",
".",... | // Querier returns a new querier over the data partition for the given time range.
// A goroutine must not handle more than one open Querier. | [
"Querier",
"returns",
"a",
"new",
"querier",
"over",
"the",
"data",
"partition",
"for",
"the",
"given",
"time",
"range",
".",
"A",
"goroutine",
"must",
"not",
"handle",
"more",
"than",
"one",
"open",
"Querier",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/db.go#L933-L979 | train |
prometheus/tsdb | db.go | Delete | func (db *DB) Delete(mint, maxt int64, ms ...labels.Matcher) error {
db.cmtx.Lock()
defer db.cmtx.Unlock()
var g errgroup.Group
db.mtx.RLock()
defer db.mtx.RUnlock()
for _, b := range db.blocks {
if b.OverlapsClosedInterval(mint, maxt) {
g.Go(func(b *Block) func() error {
return func() error { return ... | go | func (db *DB) Delete(mint, maxt int64, ms ...labels.Matcher) error {
db.cmtx.Lock()
defer db.cmtx.Unlock()
var g errgroup.Group
db.mtx.RLock()
defer db.mtx.RUnlock()
for _, b := range db.blocks {
if b.OverlapsClosedInterval(mint, maxt) {
g.Go(func(b *Block) func() error {
return func() error { return ... | [
"func",
"(",
"db",
"*",
"DB",
")",
"Delete",
"(",
"mint",
",",
"maxt",
"int64",
",",
"ms",
"...",
"labels",
".",
"Matcher",
")",
"error",
"{",
"db",
".",
"cmtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"cmtx",
".",
"Unlock",
"(",
")",
... | // Delete implements deletion of metrics. It only has atomicity guarantees on a per-block basis. | [
"Delete",
"implements",
"deletion",
"of",
"metrics",
".",
"It",
"only",
"has",
"atomicity",
"guarantees",
"on",
"a",
"per",
"-",
"block",
"basis",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/db.go#L986-L1006 | train |
prometheus/tsdb | db.go | CleanTombstones | func (db *DB) CleanTombstones() (err error) {
db.cmtx.Lock()
defer db.cmtx.Unlock()
start := time.Now()
defer db.metrics.tombCleanTimer.Observe(time.Since(start).Seconds())
newUIDs := []ulid.ULID{}
defer func() {
// If any error is caused, we need to delete all the new directory created.
if err != nil {
... | go | func (db *DB) CleanTombstones() (err error) {
db.cmtx.Lock()
defer db.cmtx.Unlock()
start := time.Now()
defer db.metrics.tombCleanTimer.Observe(time.Since(start).Seconds())
newUIDs := []ulid.ULID{}
defer func() {
// If any error is caused, we need to delete all the new directory created.
if err != nil {
... | [
"func",
"(",
"db",
"*",
"DB",
")",
"CleanTombstones",
"(",
")",
"(",
"err",
"error",
")",
"{",
"db",
".",
"cmtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"cmtx",
".",
"Unlock",
"(",
")",
"\n\n",
"start",
":=",
"time",
".",
"Now",
"(",
... | // CleanTombstones re-writes any blocks with tombstones. | [
"CleanTombstones",
"re",
"-",
"writes",
"any",
"blocks",
"with",
"tombstones",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/db.go#L1009-L1042 | train |
prometheus/tsdb | compact.go | ExponentialBlockRanges | func ExponentialBlockRanges(minSize int64, steps, stepSize int) []int64 {
ranges := make([]int64, 0, steps)
curRange := minSize
for i := 0; i < steps; i++ {
ranges = append(ranges, curRange)
curRange = curRange * int64(stepSize)
}
return ranges
} | go | func ExponentialBlockRanges(minSize int64, steps, stepSize int) []int64 {
ranges := make([]int64, 0, steps)
curRange := minSize
for i := 0; i < steps; i++ {
ranges = append(ranges, curRange)
curRange = curRange * int64(stepSize)
}
return ranges
} | [
"func",
"ExponentialBlockRanges",
"(",
"minSize",
"int64",
",",
"steps",
",",
"stepSize",
"int",
")",
"[",
"]",
"int64",
"{",
"ranges",
":=",
"make",
"(",
"[",
"]",
"int64",
",",
"0",
",",
"steps",
")",
"\n",
"curRange",
":=",
"minSize",
"\n",
"for",
... | // ExponentialBlockRanges returns the time ranges based on the stepSize. | [
"ExponentialBlockRanges",
"returns",
"the",
"time",
"ranges",
"based",
"on",
"the",
"stepSize",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/compact.go#L41-L50 | train |
prometheus/tsdb | compact.go | NewLeveledCompactor | func NewLeveledCompactor(ctx context.Context, r prometheus.Registerer, l log.Logger, ranges []int64, pool chunkenc.Pool) (*LeveledCompactor, error) {
if len(ranges) == 0 {
return nil, errors.Errorf("at least one range must be provided")
}
if pool == nil {
pool = chunkenc.NewPool()
}
if l == nil {
l = log.New... | go | func NewLeveledCompactor(ctx context.Context, r prometheus.Registerer, l log.Logger, ranges []int64, pool chunkenc.Pool) (*LeveledCompactor, error) {
if len(ranges) == 0 {
return nil, errors.Errorf("at least one range must be provided")
}
if pool == nil {
pool = chunkenc.NewPool()
}
if l == nil {
l = log.New... | [
"func",
"NewLeveledCompactor",
"(",
"ctx",
"context",
".",
"Context",
",",
"r",
"prometheus",
".",
"Registerer",
",",
"l",
"log",
".",
"Logger",
",",
"ranges",
"[",
"]",
"int64",
",",
"pool",
"chunkenc",
".",
"Pool",
")",
"(",
"*",
"LeveledCompactor",
",... | // NewLeveledCompactor returns a LeveledCompactor. | [
"NewLeveledCompactor",
"returns",
"a",
"LeveledCompactor",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/compact.go#L151-L168 | train |
prometheus/tsdb | compact.go | Plan | func (c *LeveledCompactor) Plan(dir string) ([]string, error) {
dirs, err := blockDirs(dir)
if err != nil {
return nil, err
}
if len(dirs) < 1 {
return nil, nil
}
var dms []dirMeta
for _, dir := range dirs {
meta, err := readMetaFile(dir)
if err != nil {
return nil, err
}
dms = append(dms, dirMet... | go | func (c *LeveledCompactor) Plan(dir string) ([]string, error) {
dirs, err := blockDirs(dir)
if err != nil {
return nil, err
}
if len(dirs) < 1 {
return nil, nil
}
var dms []dirMeta
for _, dir := range dirs {
meta, err := readMetaFile(dir)
if err != nil {
return nil, err
}
dms = append(dms, dirMet... | [
"func",
"(",
"c",
"*",
"LeveledCompactor",
")",
"Plan",
"(",
"dir",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"dirs",
",",
"err",
":=",
"blockDirs",
"(",
"dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",... | // Plan returns a list of compactable blocks in the provided directory. | [
"Plan",
"returns",
"a",
"list",
"of",
"compactable",
"blocks",
"in",
"the",
"provided",
"directory",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/compact.go#L176-L194 | train |
prometheus/tsdb | compact.go | selectDirs | func (c *LeveledCompactor) selectDirs(ds []dirMeta) []dirMeta {
if len(c.ranges) < 2 || len(ds) < 1 {
return nil
}
highTime := ds[len(ds)-1].meta.MinTime
for _, iv := range c.ranges[1:] {
parts := splitByRange(ds, iv)
if len(parts) == 0 {
continue
}
Outer:
for _, p := range parts {
// Do not sel... | go | func (c *LeveledCompactor) selectDirs(ds []dirMeta) []dirMeta {
if len(c.ranges) < 2 || len(ds) < 1 {
return nil
}
highTime := ds[len(ds)-1].meta.MinTime
for _, iv := range c.ranges[1:] {
parts := splitByRange(ds, iv)
if len(parts) == 0 {
continue
}
Outer:
for _, p := range parts {
// Do not sel... | [
"func",
"(",
"c",
"*",
"LeveledCompactor",
")",
"selectDirs",
"(",
"ds",
"[",
"]",
"dirMeta",
")",
"[",
"]",
"dirMeta",
"{",
"if",
"len",
"(",
"c",
".",
"ranges",
")",
"<",
"2",
"||",
"len",
"(",
"ds",
")",
"<",
"1",
"{",
"return",
"nil",
"\n",... | // selectDirs returns the dir metas that should be compacted into a single new block.
// If only a single block range is configured, the result is always nil. | [
"selectDirs",
"returns",
"the",
"dir",
"metas",
"that",
"should",
"be",
"compacted",
"into",
"a",
"single",
"new",
"block",
".",
"If",
"only",
"a",
"single",
"block",
"range",
"is",
"configured",
"the",
"result",
"is",
"always",
"nil",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/compact.go#L233-L268 | train |
prometheus/tsdb | compact.go | selectOverlappingDirs | func (c *LeveledCompactor) selectOverlappingDirs(ds []dirMeta) []string {
if len(ds) < 2 {
return nil
}
var overlappingDirs []string
globalMaxt := ds[0].meta.MaxTime
for i, d := range ds[1:] {
if d.meta.MinTime < globalMaxt {
if len(overlappingDirs) == 0 { // When it is the first overlap, need to add the la... | go | func (c *LeveledCompactor) selectOverlappingDirs(ds []dirMeta) []string {
if len(ds) < 2 {
return nil
}
var overlappingDirs []string
globalMaxt := ds[0].meta.MaxTime
for i, d := range ds[1:] {
if d.meta.MinTime < globalMaxt {
if len(overlappingDirs) == 0 { // When it is the first overlap, need to add the la... | [
"func",
"(",
"c",
"*",
"LeveledCompactor",
")",
"selectOverlappingDirs",
"(",
"ds",
"[",
"]",
"dirMeta",
")",
"[",
"]",
"string",
"{",
"if",
"len",
"(",
"ds",
")",
"<",
"2",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"var",
"overlappingDirs",
"[",
"]",
... | // selectOverlappingDirs returns all dirs with overlapping time ranges.
// It expects sorted input by mint and returns the overlapping dirs in the same order as received. | [
"selectOverlappingDirs",
"returns",
"all",
"dirs",
"with",
"overlapping",
"time",
"ranges",
".",
"It",
"expects",
"sorted",
"input",
"by",
"mint",
"and",
"returns",
"the",
"overlapping",
"dirs",
"in",
"the",
"same",
"order",
"as",
"received",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/compact.go#L272-L292 | train |
prometheus/tsdb | tombstones.go | addInterval | func (t *memTombstones) addInterval(ref uint64, itvs ...Interval) {
t.mtx.Lock()
defer t.mtx.Unlock()
for _, itv := range itvs {
t.intvlGroups[ref] = t.intvlGroups[ref].add(itv)
}
} | go | func (t *memTombstones) addInterval(ref uint64, itvs ...Interval) {
t.mtx.Lock()
defer t.mtx.Unlock()
for _, itv := range itvs {
t.intvlGroups[ref] = t.intvlGroups[ref].add(itv)
}
} | [
"func",
"(",
"t",
"*",
"memTombstones",
")",
"addInterval",
"(",
"ref",
"uint64",
",",
"itvs",
"...",
"Interval",
")",
"{",
"t",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
... | // addInterval to an existing memTombstones | [
"addInterval",
"to",
"an",
"existing",
"memTombstones"
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/tombstones.go#L225-L231 | train |
prometheus/tsdb | tombstones.go | add | func (itvs Intervals) add(n Interval) Intervals {
for i, r := range itvs {
// TODO(gouthamve): Make this codepath easier to digest.
if r.inBounds(n.Mint-1) || r.inBounds(n.Mint) {
if n.Maxt > r.Maxt {
itvs[i].Maxt = n.Maxt
}
j := 0
for _, r2 := range itvs[i+1:] {
if n.Maxt < r2.Mint {
bre... | go | func (itvs Intervals) add(n Interval) Intervals {
for i, r := range itvs {
// TODO(gouthamve): Make this codepath easier to digest.
if r.inBounds(n.Mint-1) || r.inBounds(n.Mint) {
if n.Maxt > r.Maxt {
itvs[i].Maxt = n.Maxt
}
j := 0
for _, r2 := range itvs[i+1:] {
if n.Maxt < r2.Mint {
bre... | [
"func",
"(",
"itvs",
"Intervals",
")",
"add",
"(",
"n",
"Interval",
")",
"Intervals",
"{",
"for",
"i",
",",
"r",
":=",
"range",
"itvs",
"{",
"// TODO(gouthamve): Make this codepath easier to digest.",
"if",
"r",
".",
"inBounds",
"(",
"n",
".",
"Mint",
"-",
... | // add the new time-range to the existing ones.
// The existing ones must be sorted. | [
"add",
"the",
"new",
"time",
"-",
"range",
"to",
"the",
"existing",
"ones",
".",
"The",
"existing",
"ones",
"must",
"be",
"sorted",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/tombstones.go#L271-L314 | train |
prometheus/tsdb | fileutil/fileutil.go | CopyDirs | func CopyDirs(src, dest string) error {
if err := os.MkdirAll(dest, 0777); err != nil {
return err
}
files, err := readDirs(src)
if err != nil {
return err
}
for _, f := range files {
dp := filepath.Join(dest, f)
sp := filepath.Join(src, f)
stat, err := os.Stat(sp)
if err != nil {
return err
}
... | go | func CopyDirs(src, dest string) error {
if err := os.MkdirAll(dest, 0777); err != nil {
return err
}
files, err := readDirs(src)
if err != nil {
return err
}
for _, f := range files {
dp := filepath.Join(dest, f)
sp := filepath.Join(src, f)
stat, err := os.Stat(sp)
if err != nil {
return err
}
... | [
"func",
"CopyDirs",
"(",
"src",
",",
"dest",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"dest",
",",
"0777",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"files",
",",
"err",
":=",
"readDir... | // CopyDirs copies all directories, subdirectories and files recursively including the empty folders.
// Source and destination must be full paths. | [
"CopyDirs",
"copies",
"all",
"directories",
"subdirectories",
"and",
"files",
"recursively",
"including",
"the",
"empty",
"folders",
".",
"Source",
"and",
"destination",
"must",
"be",
"full",
"paths",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/fileutil/fileutil.go#L30-L61 | train |
prometheus/tsdb | fileutil/fileutil.go | readDirs | func readDirs(src string) ([]string, error) {
var files []string
err := filepath.Walk(src, func(path string, f os.FileInfo, err error) error {
relativePath := strings.TrimPrefix(path, src)
if len(relativePath) > 0 {
files = append(files, relativePath)
}
return nil
})
if err != nil {
return nil, err
}... | go | func readDirs(src string) ([]string, error) {
var files []string
err := filepath.Walk(src, func(path string, f os.FileInfo, err error) error {
relativePath := strings.TrimPrefix(path, src)
if len(relativePath) > 0 {
files = append(files, relativePath)
}
return nil
})
if err != nil {
return nil, err
}... | [
"func",
"readDirs",
"(",
"src",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"files",
"[",
"]",
"string",
"\n\n",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"src",
",",
"func",
"(",
"path",
"string",
",",
"f",
"os",
".",... | // readDirs reads the source directory recursively and
// returns relative paths to all files and empty directories. | [
"readDirs",
"reads",
"the",
"source",
"directory",
"recursively",
"and",
"returns",
"relative",
"paths",
"to",
"all",
"files",
"and",
"empty",
"directories",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/fileutil/fileutil.go#L78-L92 | train |
prometheus/tsdb | fileutil/fileutil.go | Replace | func Replace(from, to string) error {
if err := os.RemoveAll(to); err != nil {
return err
}
if err := os.Rename(from, to); err != nil {
return err
}
// Directory was renamed; sync parent dir to persist rename.
pdir, err := OpenDir(filepath.Dir(to))
if err != nil {
return err
}
if err = pdir.Sync(); err... | go | func Replace(from, to string) error {
if err := os.RemoveAll(to); err != nil {
return err
}
if err := os.Rename(from, to); err != nil {
return err
}
// Directory was renamed; sync parent dir to persist rename.
pdir, err := OpenDir(filepath.Dir(to))
if err != nil {
return err
}
if err = pdir.Sync(); err... | [
"func",
"Replace",
"(",
"from",
",",
"to",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"os",
".",
"RemoveAll",
"(",
"to",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"os",
".",
"Rename",
"(",
"fro... | // Replace moves a file or directory to a new location and deletes any previous data.
// It is not atomic. | [
"Replace",
"moves",
"a",
"file",
"or",
"directory",
"to",
"a",
"new",
"location",
"and",
"deletes",
"any",
"previous",
"data",
".",
"It",
"is",
"not",
"atomic",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/fileutil/fileutil.go#L130-L149 | train |
prometheus/tsdb | checkpoint.go | LastCheckpoint | func LastCheckpoint(dir string) (string, int, error) {
files, err := ioutil.ReadDir(dir)
if err != nil {
return "", 0, err
}
// Traverse list backwards since there may be multiple checkpoints left.
for i := len(files) - 1; i >= 0; i-- {
fi := files[i]
if !strings.HasPrefix(fi.Name(), checkpointPrefix) {
... | go | func LastCheckpoint(dir string) (string, int, error) {
files, err := ioutil.ReadDir(dir)
if err != nil {
return "", 0, err
}
// Traverse list backwards since there may be multiple checkpoints left.
for i := len(files) - 1; i >= 0; i-- {
fi := files[i]
if !strings.HasPrefix(fi.Name(), checkpointPrefix) {
... | [
"func",
"LastCheckpoint",
"(",
"dir",
"string",
")",
"(",
"string",
",",
"int",
",",
"error",
")",
"{",
"files",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"0",
","... | // LastCheckpoint returns the directory name and index of the most recent checkpoint.
// If dir does not contain any checkpoints, ErrNotFound is returned. | [
"LastCheckpoint",
"returns",
"the",
"directory",
"name",
"and",
"index",
"of",
"the",
"most",
"recent",
"checkpoint",
".",
"If",
"dir",
"does",
"not",
"contain",
"any",
"checkpoints",
"ErrNotFound",
"is",
"returned",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/checkpoint.go#L45-L67 | train |
prometheus/tsdb | checkpoint.go | DeleteCheckpoints | func DeleteCheckpoints(dir string, maxIndex int) error {
var errs tsdb_errors.MultiError
files, err := ioutil.ReadDir(dir)
if err != nil {
return err
}
for _, fi := range files {
if !strings.HasPrefix(fi.Name(), checkpointPrefix) {
continue
}
index, err := strconv.Atoi(fi.Name()[len(checkpointPrefix):]... | go | func DeleteCheckpoints(dir string, maxIndex int) error {
var errs tsdb_errors.MultiError
files, err := ioutil.ReadDir(dir)
if err != nil {
return err
}
for _, fi := range files {
if !strings.HasPrefix(fi.Name(), checkpointPrefix) {
continue
}
index, err := strconv.Atoi(fi.Name()[len(checkpointPrefix):]... | [
"func",
"DeleteCheckpoints",
"(",
"dir",
"string",
",",
"maxIndex",
"int",
")",
"error",
"{",
"var",
"errs",
"tsdb_errors",
".",
"MultiError",
"\n\n",
"files",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // DeleteCheckpoints deletes all checkpoints in a directory below a given index. | [
"DeleteCheckpoints",
"deletes",
"all",
"checkpoints",
"in",
"a",
"directory",
"below",
"a",
"given",
"index",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/checkpoint.go#L70-L90 | train |
prometheus/tsdb | wal/live_reader.go | NewLiveReader | func NewLiveReader(logger log.Logger, r io.Reader) *LiveReader {
return &LiveReader{
logger: logger,
rdr: r,
// Until we understand how they come about, make readers permissive
// to records spanning pages.
permissive: true,
}
} | go | func NewLiveReader(logger log.Logger, r io.Reader) *LiveReader {
return &LiveReader{
logger: logger,
rdr: r,
// Until we understand how they come about, make readers permissive
// to records spanning pages.
permissive: true,
}
} | [
"func",
"NewLiveReader",
"(",
"logger",
"log",
".",
"Logger",
",",
"r",
"io",
".",
"Reader",
")",
"*",
"LiveReader",
"{",
"return",
"&",
"LiveReader",
"{",
"logger",
":",
"logger",
",",
"rdr",
":",
"r",
",",
"// Until we understand how they come about, make re... | // NewLiveReader returns a new live reader. | [
"NewLiveReader",
"returns",
"a",
"new",
"live",
"reader",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/live_reader.go#L38-L47 | train |
prometheus/tsdb | wal/live_reader.go | Err | func (r *LiveReader) Err() error {
if r.eofNonErr && r.err == io.EOF {
return nil
}
return r.err
} | go | func (r *LiveReader) Err() error {
if r.eofNonErr && r.err == io.EOF {
return nil
}
return r.err
} | [
"func",
"(",
"r",
"*",
"LiveReader",
")",
"Err",
"(",
")",
"error",
"{",
"if",
"r",
".",
"eofNonErr",
"&&",
"r",
".",
"err",
"==",
"io",
".",
"EOF",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"r",
".",
"err",
"\n",
"}"
] | // Err returns any errors encountered reading the WAL. io.EOFs are not terminal
// and Next can be tried again. Non-EOFs are terminal, and the reader should
// not be used again. It is up to the user to decide when to stop trying should
// io.EOF be returned. | [
"Err",
"returns",
"any",
"errors",
"encountered",
"reading",
"the",
"WAL",
".",
"io",
".",
"EOFs",
"are",
"not",
"terminal",
"and",
"Next",
"can",
"be",
"tried",
"again",
".",
"Non",
"-",
"EOFs",
"are",
"terminal",
"and",
"the",
"reader",
"should",
"not"... | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/live_reader.go#L77-L82 | train |
prometheus/tsdb | wal/live_reader.go | buildRecord | func (r *LiveReader) buildRecord() (bool, error) {
for {
// Check that we have data in the internal buffer to read.
if r.writeIndex <= r.readIndex {
return false, nil
}
// Attempt to read a record, partial or otherwise.
temp, n, err := r.readRecord()
if err != nil {
return false, err
}
r.readIn... | go | func (r *LiveReader) buildRecord() (bool, error) {
for {
// Check that we have data in the internal buffer to read.
if r.writeIndex <= r.readIndex {
return false, nil
}
// Attempt to read a record, partial or otherwise.
temp, n, err := r.readRecord()
if err != nil {
return false, err
}
r.readIn... | [
"func",
"(",
"r",
"*",
"LiveReader",
")",
"buildRecord",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"for",
"{",
"// Check that we have data in the internal buffer to read.",
"if",
"r",
".",
"writeIndex",
"<=",
"r",
".",
"readIndex",
"{",
"return",
"false",... | // Rebuild a full record from potentially partial records. Returns false
// if there was an error or if we weren't able to read a record for any reason.
// Returns true if we read a full record. Any record data is appended to
// LiveReader.rec | [
"Rebuild",
"a",
"full",
"record",
"from",
"potentially",
"partial",
"records",
".",
"Returns",
"false",
"if",
"there",
"was",
"an",
"error",
"or",
"if",
"we",
"weren",
"t",
"able",
"to",
"read",
"a",
"record",
"for",
"any",
"reason",
".",
"Returns",
"tru... | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/live_reader.go#L150-L187 | train |
prometheus/tsdb | errors/errors.go | Add | func (es *MultiError) Add(err error) {
if err == nil {
return
}
if merr, ok := err.(MultiError); ok {
*es = append(*es, merr...)
} else {
*es = append(*es, err)
}
} | go | func (es *MultiError) Add(err error) {
if err == nil {
return
}
if merr, ok := err.(MultiError); ok {
*es = append(*es, merr...)
} else {
*es = append(*es, err)
}
} | [
"func",
"(",
"es",
"*",
"MultiError",
")",
"Add",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"merr",
",",
"ok",
":=",
"err",
".",
"(",
"MultiError",
")",
";",
"ok",
"{",
"*",
"es",
"=",
"app... | // Add adds the error to the error list if it is not nil. | [
"Add",
"adds",
"the",
"error",
"to",
"the",
"error",
"list",
"if",
"it",
"is",
"not",
"nil",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/errors/errors.go#L45-L54 | train |
prometheus/tsdb | wal/wal.go | OpenWriteSegment | func OpenWriteSegment(logger log.Logger, dir string, k int) (*Segment, error) {
segName := SegmentName(dir, k)
f, err := os.OpenFile(segName, os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
return nil, err
}
stat, err := f.Stat()
if err != nil {
f.Close()
return nil, err
}
// If the last page is torn, fill... | go | func OpenWriteSegment(logger log.Logger, dir string, k int) (*Segment, error) {
segName := SegmentName(dir, k)
f, err := os.OpenFile(segName, os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
return nil, err
}
stat, err := f.Stat()
if err != nil {
f.Close()
return nil, err
}
// If the last page is torn, fill... | [
"func",
"OpenWriteSegment",
"(",
"logger",
"log",
".",
"Logger",
",",
"dir",
"string",
",",
"k",
"int",
")",
"(",
"*",
"Segment",
",",
"error",
")",
"{",
"segName",
":=",
"SegmentName",
"(",
"dir",
",",
"k",
")",
"\n",
"f",
",",
"err",
":=",
"os",
... | // OpenWriteSegment opens segment k in dir. The returned segment is ready for new appends. | [
"OpenWriteSegment",
"opens",
"segment",
"k",
"in",
"dir",
".",
"The",
"returned",
"segment",
"is",
"ready",
"for",
"new",
"appends",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/wal.go#L99-L123 | train |
prometheus/tsdb | wal/wal.go | CreateSegment | func CreateSegment(dir string, k int) (*Segment, error) {
f, err := os.OpenFile(SegmentName(dir, k), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
return nil, err
}
return &Segment{File: f, i: k, dir: dir}, nil
} | go | func CreateSegment(dir string, k int) (*Segment, error) {
f, err := os.OpenFile(SegmentName(dir, k), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
return nil, err
}
return &Segment{File: f, i: k, dir: dir}, nil
} | [
"func",
"CreateSegment",
"(",
"dir",
"string",
",",
"k",
"int",
")",
"(",
"*",
"Segment",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"SegmentName",
"(",
"dir",
",",
"k",
")",
",",
"os",
".",
"O_WRONLY",
"|",
"os",
... | // CreateSegment creates a new segment k in dir. | [
"CreateSegment",
"creates",
"a",
"new",
"segment",
"k",
"in",
"dir",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/wal.go#L126-L132 | train |
prometheus/tsdb | wal/wal.go | OpenReadSegment | func OpenReadSegment(fn string) (*Segment, error) {
k, err := strconv.Atoi(filepath.Base(fn))
if err != nil {
return nil, errors.New("not a valid filename")
}
f, err := os.Open(fn)
if err != nil {
return nil, err
}
return &Segment{File: f, i: k, dir: filepath.Dir(fn)}, nil
} | go | func OpenReadSegment(fn string) (*Segment, error) {
k, err := strconv.Atoi(filepath.Base(fn))
if err != nil {
return nil, errors.New("not a valid filename")
}
f, err := os.Open(fn)
if err != nil {
return nil, err
}
return &Segment{File: f, i: k, dir: filepath.Dir(fn)}, nil
} | [
"func",
"OpenReadSegment",
"(",
"fn",
"string",
")",
"(",
"*",
"Segment",
",",
"error",
")",
"{",
"k",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"filepath",
".",
"Base",
"(",
"fn",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ni... | // OpenReadSegment opens the segment with the given filename. | [
"OpenReadSegment",
"opens",
"the",
"segment",
"with",
"the",
"given",
"filename",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/wal.go#L135-L145 | train |
prometheus/tsdb | wal/wal.go | New | func New(logger log.Logger, reg prometheus.Registerer, dir string) (*WAL, error) {
return NewSize(logger, reg, dir, DefaultSegmentSize)
} | go | func New(logger log.Logger, reg prometheus.Registerer, dir string) (*WAL, error) {
return NewSize(logger, reg, dir, DefaultSegmentSize)
} | [
"func",
"New",
"(",
"logger",
"log",
".",
"Logger",
",",
"reg",
"prometheus",
".",
"Registerer",
",",
"dir",
"string",
")",
"(",
"*",
"WAL",
",",
"error",
")",
"{",
"return",
"NewSize",
"(",
"logger",
",",
"reg",
",",
"dir",
",",
"DefaultSegmentSize",
... | // New returns a new WAL over the given directory. | [
"New",
"returns",
"a",
"new",
"WAL",
"over",
"the",
"given",
"directory",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/wal.go#L177-L179 | train |
prometheus/tsdb | wal/wal.go | NewSize | func NewSize(logger log.Logger, reg prometheus.Registerer, dir string, segmentSize int) (*WAL, error) {
if segmentSize%pageSize != 0 {
return nil, errors.New("invalid segment size")
}
if err := os.MkdirAll(dir, 0777); err != nil {
return nil, errors.Wrap(err, "create dir")
}
if logger == nil {
logger = log.N... | go | func NewSize(logger log.Logger, reg prometheus.Registerer, dir string, segmentSize int) (*WAL, error) {
if segmentSize%pageSize != 0 {
return nil, errors.New("invalid segment size")
}
if err := os.MkdirAll(dir, 0777); err != nil {
return nil, errors.Wrap(err, "create dir")
}
if logger == nil {
logger = log.N... | [
"func",
"NewSize",
"(",
"logger",
"log",
".",
"Logger",
",",
"reg",
"prometheus",
".",
"Registerer",
",",
"dir",
"string",
",",
"segmentSize",
"int",
")",
"(",
"*",
"WAL",
",",
"error",
")",
"{",
"if",
"segmentSize",
"%",
"pageSize",
"!=",
"0",
"{",
... | // NewSize returns a new WAL over the given directory.
// New segments are created with the specified size. | [
"NewSize",
"returns",
"a",
"new",
"WAL",
"over",
"the",
"given",
"directory",
".",
"New",
"segments",
"are",
"created",
"with",
"the",
"specified",
"size",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/wal.go#L183-L252 | train |
prometheus/tsdb | wal/wal.go | Repair | func (w *WAL) Repair(origErr error) error {
// We could probably have a mode that only discards torn records right around
// the corruption to preserve as data much as possible.
// But that's not generally applicable if the records have any kind of causality.
// Maybe as an extra mode in the future if mid-WAL corru... | go | func (w *WAL) Repair(origErr error) error {
// We could probably have a mode that only discards torn records right around
// the corruption to preserve as data much as possible.
// But that's not generally applicable if the records have any kind of causality.
// Maybe as an extra mode in the future if mid-WAL corru... | [
"func",
"(",
"w",
"*",
"WAL",
")",
"Repair",
"(",
"origErr",
"error",
")",
"error",
"{",
"// We could probably have a mode that only discards torn records right around",
"// the corruption to preserve as data much as possible.",
"// But that's not generally applicable if the records ha... | // Repair attempts to repair the WAL based on the error.
// It discards all data after the corruption. | [
"Repair",
"attempts",
"to",
"repair",
"the",
"WAL",
"based",
"on",
"the",
"error",
".",
"It",
"discards",
"all",
"data",
"after",
"the",
"corruption",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/wal.go#L279-L371 | train |
prometheus/tsdb | wal/wal.go | SegmentName | func SegmentName(dir string, i int) string {
return filepath.Join(dir, fmt.Sprintf("%08d", i))
} | go | func SegmentName(dir string, i int) string {
return filepath.Join(dir, fmt.Sprintf("%08d", i))
} | [
"func",
"SegmentName",
"(",
"dir",
"string",
",",
"i",
"int",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"dir",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
")",
")",
"\n",
"}"
] | // SegmentName builds a segment name for the directory. | [
"SegmentName",
"builds",
"a",
"segment",
"name",
"for",
"the",
"directory",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/wal.go#L374-L376 | train |
prometheus/tsdb | wal/wal.go | nextSegment | func (w *WAL) nextSegment() error {
// Only flush the current page if it actually holds data.
if w.page.alloc > 0 {
if err := w.flushPage(true); err != nil {
return err
}
}
next, err := CreateSegment(w.dir, w.segment.Index()+1)
if err != nil {
return errors.Wrap(err, "create new segment file")
}
prev :=... | go | func (w *WAL) nextSegment() error {
// Only flush the current page if it actually holds data.
if w.page.alloc > 0 {
if err := w.flushPage(true); err != nil {
return err
}
}
next, err := CreateSegment(w.dir, w.segment.Index()+1)
if err != nil {
return errors.Wrap(err, "create new segment file")
}
prev :=... | [
"func",
"(",
"w",
"*",
"WAL",
")",
"nextSegment",
"(",
")",
"error",
"{",
"// Only flush the current page if it actually holds data.",
"if",
"w",
".",
"page",
".",
"alloc",
">",
"0",
"{",
"if",
"err",
":=",
"w",
".",
"flushPage",
"(",
"true",
")",
";",
"... | // nextSegment creates the next segment and closes the previous one. | [
"nextSegment",
"creates",
"the",
"next",
"segment",
"and",
"closes",
"the",
"previous",
"one",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/wal.go#L379-L405 | train |
prometheus/tsdb | wal/wal.go | flushPage | func (w *WAL) flushPage(clear bool) error {
w.pageFlushes.Inc()
p := w.page
clear = clear || p.full()
// No more data will fit into the page. Enqueue and clear it.
if clear {
p.alloc = pageSize // Write till end of page.
w.pageCompletions.Inc()
}
n, err := w.segment.Write(p.buf[p.flushed:p.alloc])
if err ... | go | func (w *WAL) flushPage(clear bool) error {
w.pageFlushes.Inc()
p := w.page
clear = clear || p.full()
// No more data will fit into the page. Enqueue and clear it.
if clear {
p.alloc = pageSize // Write till end of page.
w.pageCompletions.Inc()
}
n, err := w.segment.Write(p.buf[p.flushed:p.alloc])
if err ... | [
"func",
"(",
"w",
"*",
"WAL",
")",
"flushPage",
"(",
"clear",
"bool",
")",
"error",
"{",
"w",
".",
"pageFlushes",
".",
"Inc",
"(",
")",
"\n\n",
"p",
":=",
"w",
".",
"page",
"\n",
"clear",
"=",
"clear",
"||",
"p",
".",
"full",
"(",
")",
"\n\n",
... | // flushPage writes the new contents of the page to disk. If no more records will fit into
// the page, the remaining bytes will be set to zero and a new page will be started.
// If clear is true, this is enforced regardless of how many bytes are left in the page. | [
"flushPage",
"writes",
"the",
"new",
"contents",
"of",
"the",
"page",
"to",
"disk",
".",
"If",
"no",
"more",
"records",
"will",
"fit",
"into",
"the",
"page",
"the",
"remaining",
"bytes",
"will",
"be",
"set",
"to",
"zero",
"and",
"a",
"new",
"page",
"wi... | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/wal.go#L423-L450 | train |
prometheus/tsdb | wal/wal.go | Log | func (w *WAL) Log(recs ...[]byte) error {
w.mtx.Lock()
defer w.mtx.Unlock()
// Callers could just implement their own list record format but adding
// a bit of extra logic here frees them from that overhead.
for i, r := range recs {
if err := w.log(r, i == len(recs)-1); err != nil {
return err
}
}
return ... | go | func (w *WAL) Log(recs ...[]byte) error {
w.mtx.Lock()
defer w.mtx.Unlock()
// Callers could just implement their own list record format but adding
// a bit of extra logic here frees them from that overhead.
for i, r := range recs {
if err := w.log(r, i == len(recs)-1); err != nil {
return err
}
}
return ... | [
"func",
"(",
"w",
"*",
"WAL",
")",
"Log",
"(",
"recs",
"...",
"[",
"]",
"byte",
")",
"error",
"{",
"w",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"w",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"// Callers could just implement their own list ... | // Log writes the records into the log.
// Multiple records can be passed at once to reduce writes and increase throughput. | [
"Log",
"writes",
"the",
"records",
"into",
"the",
"log",
".",
"Multiple",
"records",
"can",
"be",
"passed",
"at",
"once",
"to",
"reduce",
"writes",
"and",
"increase",
"throughput",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/wal.go#L485-L496 | train |
prometheus/tsdb | wal/wal.go | log | func (w *WAL) log(rec []byte, final bool) error {
// If the record is too big to fit within the active page in the current
// segment, terminate the active segment and advance to the next one.
// This ensures that records do not cross segment boundaries.
left := w.page.remaining() - recordHeaderSize ... | go | func (w *WAL) log(rec []byte, final bool) error {
// If the record is too big to fit within the active page in the current
// segment, terminate the active segment and advance to the next one.
// This ensures that records do not cross segment boundaries.
left := w.page.remaining() - recordHeaderSize ... | [
"func",
"(",
"w",
"*",
"WAL",
")",
"log",
"(",
"rec",
"[",
"]",
"byte",
",",
"final",
"bool",
")",
"error",
"{",
"// If the record is too big to fit within the active page in the current",
"// segment, terminate the active segment and advance to the next one.",
"// This ensur... | // log writes rec to the log and forces a flush of the current page if its
// the final record of a batch, the record is bigger than the page size or
// the current page is full. | [
"log",
"writes",
"rec",
"to",
"the",
"log",
"and",
"forces",
"a",
"flush",
"of",
"the",
"current",
"page",
"if",
"its",
"the",
"final",
"record",
"of",
"a",
"batch",
"the",
"record",
"is",
"bigger",
"than",
"the",
"page",
"size",
"or",
"the",
"current"... | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/wal.go#L501-L558 | train |
prometheus/tsdb | wal/wal.go | Truncate | func (w *WAL) Truncate(i int) (err error) {
w.truncateTotal.Inc()
defer func() {
if err != nil {
w.truncateFail.Inc()
}
}()
refs, err := listSegments(w.dir)
if err != nil {
return err
}
for _, r := range refs {
if r.index >= i {
break
}
if err = os.Remove(filepath.Join(w.dir, r.name)); err != n... | go | func (w *WAL) Truncate(i int) (err error) {
w.truncateTotal.Inc()
defer func() {
if err != nil {
w.truncateFail.Inc()
}
}()
refs, err := listSegments(w.dir)
if err != nil {
return err
}
for _, r := range refs {
if r.index >= i {
break
}
if err = os.Remove(filepath.Join(w.dir, r.name)); err != n... | [
"func",
"(",
"w",
"*",
"WAL",
")",
"Truncate",
"(",
"i",
"int",
")",
"(",
"err",
"error",
")",
"{",
"w",
".",
"truncateTotal",
".",
"Inc",
"(",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"w",
".",
"truncateFail",
... | // Truncate drops all segments before i. | [
"Truncate",
"drops",
"all",
"segments",
"before",
"i",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/wal.go#L574-L594 | train |
prometheus/tsdb | wal/wal.go | Close | func (w *WAL) Close() (err error) {
w.mtx.Lock()
defer w.mtx.Unlock()
if w.closed {
return errors.New("wal already closed")
}
// Flush the last page and zero out all its remaining size.
// We must not flush an empty page as it would falsely signal
// the segment is done if we start writing to it again after ... | go | func (w *WAL) Close() (err error) {
w.mtx.Lock()
defer w.mtx.Unlock()
if w.closed {
return errors.New("wal already closed")
}
// Flush the last page and zero out all its remaining size.
// We must not flush an empty page as it would falsely signal
// the segment is done if we start writing to it again after ... | [
"func",
"(",
"w",
"*",
"WAL",
")",
"Close",
"(",
")",
"(",
"err",
"error",
")",
"{",
"w",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"w",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"w",
".",
"closed",
"{",
"return",
"errors",
... | // Close flushes all writes and closes active segment. | [
"Close",
"flushes",
"all",
"writes",
"and",
"closes",
"active",
"segment",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/wal.go#L604-L633 | train |
prometheus/tsdb | wal/wal.go | NewSegmentsRangeReader | func NewSegmentsRangeReader(sr ...SegmentRange) (io.ReadCloser, error) {
var segs []*Segment
for _, sgmRange := range sr {
refs, err := listSegments(sgmRange.Dir)
if err != nil {
return nil, errors.Wrapf(err, "list segment in dir:%v", sgmRange.Dir)
}
for _, r := range refs {
if sgmRange.First >= 0 && ... | go | func NewSegmentsRangeReader(sr ...SegmentRange) (io.ReadCloser, error) {
var segs []*Segment
for _, sgmRange := range sr {
refs, err := listSegments(sgmRange.Dir)
if err != nil {
return nil, errors.Wrapf(err, "list segment in dir:%v", sgmRange.Dir)
}
for _, r := range refs {
if sgmRange.First >= 0 && ... | [
"func",
"NewSegmentsRangeReader",
"(",
"sr",
"...",
"SegmentRange",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"var",
"segs",
"[",
"]",
"*",
"Segment",
"\n\n",
"for",
"_",
",",
"sgmRange",
":=",
"range",
"sr",
"{",
"refs",
",",
"err",
... | // NewSegmentsRangeReader returns a new reader over the given WAL segment ranges.
// If first or last are -1, the range is open on the respective end. | [
"NewSegmentsRangeReader",
"returns",
"a",
"new",
"reader",
"over",
"the",
"given",
"WAL",
"segment",
"ranges",
".",
"If",
"first",
"or",
"last",
"are",
"-",
"1",
"the",
"range",
"is",
"open",
"on",
"the",
"respective",
"end",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/wal/wal.go#L676-L700 | train |
prometheus/tsdb | index/index.go | NewTOCFromByteSlice | func NewTOCFromByteSlice(bs ByteSlice) (*TOC, error) {
if bs.Len() < indexTOCLen {
return nil, encoding.ErrInvalidSize
}
b := bs.Range(bs.Len()-indexTOCLen, bs.Len())
expCRC := binary.BigEndian.Uint32(b[len(b)-4:])
d := encoding.Decbuf{B: b[:len(b)-4]}
if d.Crc32(castagnoliTable) != expCRC {
return nil, err... | go | func NewTOCFromByteSlice(bs ByteSlice) (*TOC, error) {
if bs.Len() < indexTOCLen {
return nil, encoding.ErrInvalidSize
}
b := bs.Range(bs.Len()-indexTOCLen, bs.Len())
expCRC := binary.BigEndian.Uint32(b[len(b)-4:])
d := encoding.Decbuf{B: b[:len(b)-4]}
if d.Crc32(castagnoliTable) != expCRC {
return nil, err... | [
"func",
"NewTOCFromByteSlice",
"(",
"bs",
"ByteSlice",
")",
"(",
"*",
"TOC",
",",
"error",
")",
"{",
"if",
"bs",
".",
"Len",
"(",
")",
"<",
"indexTOCLen",
"{",
"return",
"nil",
",",
"encoding",
".",
"ErrInvalidSize",
"\n",
"}",
"\n",
"b",
":=",
"bs",... | // NewTOCFromByteSlice return parsed TOC from given index byte slice. | [
"NewTOCFromByteSlice",
"return",
"parsed",
"TOC",
"from",
"given",
"index",
"byte",
"slice",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L150-L175 | train |
prometheus/tsdb | index/index.go | NewWriter | func NewWriter(fn string) (*Writer, error) {
dir := filepath.Dir(fn)
df, err := fileutil.OpenDir(dir)
if err != nil {
return nil, err
}
defer df.Close() // Close for platform windows.
if err := os.RemoveAll(fn); err != nil {
return nil, errors.Wrap(err, "remove any existing index at path")
}
f, err := os... | go | func NewWriter(fn string) (*Writer, error) {
dir := filepath.Dir(fn)
df, err := fileutil.OpenDir(dir)
if err != nil {
return nil, err
}
defer df.Close() // Close for platform windows.
if err := os.RemoveAll(fn); err != nil {
return nil, errors.Wrap(err, "remove any existing index at path")
}
f, err := os... | [
"func",
"NewWriter",
"(",
"fn",
"string",
")",
"(",
"*",
"Writer",
",",
"error",
")",
"{",
"dir",
":=",
"filepath",
".",
"Dir",
"(",
"fn",
")",
"\n\n",
"df",
",",
"err",
":=",
"fileutil",
".",
"OpenDir",
"(",
"dir",
")",
"\n",
"if",
"err",
"!=",
... | // NewWriter returns a new Writer to the given filename. It serializes data in format version 2. | [
"NewWriter",
"returns",
"a",
"new",
"Writer",
"to",
"the",
"given",
"filename",
".",
"It",
"serializes",
"data",
"in",
"format",
"version",
"2",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L178-L219 | train |
prometheus/tsdb | index/index.go | addPadding | func (w *Writer) addPadding(size int) error {
p := w.pos % uint64(size)
if p == 0 {
return nil
}
p = uint64(size) - p
return errors.Wrap(w.write(make([]byte, p)), "add padding")
} | go | func (w *Writer) addPadding(size int) error {
p := w.pos % uint64(size)
if p == 0 {
return nil
}
p = uint64(size) - p
return errors.Wrap(w.write(make([]byte, p)), "add padding")
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"addPadding",
"(",
"size",
"int",
")",
"error",
"{",
"p",
":=",
"w",
".",
"pos",
"%",
"uint64",
"(",
"size",
")",
"\n",
"if",
"p",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"p",
"=",
"uint64",
"("... | // addPadding adds zero byte padding until the file size is a multiple size. | [
"addPadding",
"adds",
"zero",
"byte",
"padding",
"until",
"the",
"file",
"size",
"is",
"a",
"multiple",
"size",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L240-L247 | train |
prometheus/tsdb | index/index.go | ensureStage | func (w *Writer) ensureStage(s indexWriterStage) error {
if w.stage == s {
return nil
}
if w.stage > s {
return errors.Errorf("invalid stage %q, currently at %q", s, w.stage)
}
// Mark start of sections in table of contents.
switch s {
case idxStageSymbols:
w.toc.Symbols = w.pos
case idxStageSeries:
w.... | go | func (w *Writer) ensureStage(s indexWriterStage) error {
if w.stage == s {
return nil
}
if w.stage > s {
return errors.Errorf("invalid stage %q, currently at %q", s, w.stage)
}
// Mark start of sections in table of contents.
switch s {
case idxStageSymbols:
w.toc.Symbols = w.pos
case idxStageSeries:
w.... | [
"func",
"(",
"w",
"*",
"Writer",
")",
"ensureStage",
"(",
"s",
"indexWriterStage",
")",
"error",
"{",
"if",
"w",
".",
"stage",
"==",
"s",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"w",
".",
"stage",
">",
"s",
"{",
"return",
"errors",
".",
"Err... | // ensureStage handles transitions between write stages and ensures that IndexWriter
// methods are called in an order valid for the implementation. | [
"ensureStage",
"handles",
"transitions",
"between",
"write",
"stages",
"and",
"ensures",
"that",
"IndexWriter",
"methods",
"are",
"called",
"in",
"an",
"order",
"valid",
"for",
"the",
"implementation",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L251-L288 | train |
prometheus/tsdb | index/index.go | writeOffsetTable | func (w *Writer) writeOffsetTable(entries []hashEntry) error {
w.buf2.Reset()
w.buf2.PutBE32int(len(entries))
for _, e := range entries {
w.buf2.PutUvarint(len(e.keys))
for _, k := range e.keys {
w.buf2.PutUvarintStr(k)
}
w.buf2.PutUvarint64(e.offset)
}
w.buf1.Reset()
w.buf1.PutBE32int(w.buf2.Len())
... | go | func (w *Writer) writeOffsetTable(entries []hashEntry) error {
w.buf2.Reset()
w.buf2.PutBE32int(len(entries))
for _, e := range entries {
w.buf2.PutUvarint(len(e.keys))
for _, k := range e.keys {
w.buf2.PutUvarintStr(k)
}
w.buf2.PutUvarint64(e.offset)
}
w.buf1.Reset()
w.buf1.PutBE32int(w.buf2.Len())
... | [
"func",
"(",
"w",
"*",
"Writer",
")",
"writeOffsetTable",
"(",
"entries",
"[",
"]",
"hashEntry",
")",
"error",
"{",
"w",
".",
"buf2",
".",
"Reset",
"(",
")",
"\n",
"w",
".",
"buf2",
".",
"PutBE32int",
"(",
"len",
"(",
"entries",
")",
")",
"\n\n",
... | // writeOffsetTable writes a sequence of readable hash entries. | [
"writeOffsetTable",
"writes",
"a",
"sequence",
"of",
"readable",
"hash",
"entries",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L451-L468 | train |
prometheus/tsdb | index/index.go | NewReader | func NewReader(b ByteSlice) (*Reader, error) {
return newReader(b, ioutil.NopCloser(nil))
} | go | func NewReader(b ByteSlice) (*Reader, error) {
return newReader(b, ioutil.NopCloser(nil))
} | [
"func",
"NewReader",
"(",
"b",
"ByteSlice",
")",
"(",
"*",
"Reader",
",",
"error",
")",
"{",
"return",
"newReader",
"(",
"b",
",",
"ioutil",
".",
"NopCloser",
"(",
"nil",
")",
")",
"\n",
"}"
] | // NewReader returns a new index reader on the given byte slice. It automatically
// handles different format versions. | [
"NewReader",
"returns",
"a",
"new",
"index",
"reader",
"on",
"the",
"given",
"byte",
"slice",
".",
"It",
"automatically",
"handles",
"different",
"format",
"versions",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L618-L620 | train |
prometheus/tsdb | index/index.go | NewFileReader | func NewFileReader(path string) (*Reader, error) {
f, err := fileutil.OpenMmapFile(path)
if err != nil {
return nil, err
}
r, err := newReader(realByteSlice(f.Bytes()), f)
if err != nil {
var merr tsdb_errors.MultiError
merr.Add(err)
merr.Add(f.Close())
return nil, merr
}
return r, nil
} | go | func NewFileReader(path string) (*Reader, error) {
f, err := fileutil.OpenMmapFile(path)
if err != nil {
return nil, err
}
r, err := newReader(realByteSlice(f.Bytes()), f)
if err != nil {
var merr tsdb_errors.MultiError
merr.Add(err)
merr.Add(f.Close())
return nil, merr
}
return r, nil
} | [
"func",
"NewFileReader",
"(",
"path",
"string",
")",
"(",
"*",
"Reader",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"fileutil",
".",
"OpenMmapFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
... | // NewFileReader returns a new index reader against the given index file. | [
"NewFileReader",
"returns",
"a",
"new",
"index",
"reader",
"against",
"the",
"given",
"index",
"file",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L623-L637 | train |
prometheus/tsdb | index/index.go | PostingsRanges | func (r *Reader) PostingsRanges() (map[labels.Label]Range, error) {
m := map[labels.Label]Range{}
for k, e := range r.postings {
for v, start := range e {
d := encoding.NewDecbufAt(r.b, int(start), castagnoliTable)
if d.Err() != nil {
return nil, d.Err()
}
m[labels.Label{Name: k, Value: v}] = Range... | go | func (r *Reader) PostingsRanges() (map[labels.Label]Range, error) {
m := map[labels.Label]Range{}
for k, e := range r.postings {
for v, start := range e {
d := encoding.NewDecbufAt(r.b, int(start), castagnoliTable)
if d.Err() != nil {
return nil, d.Err()
}
m[labels.Label{Name: k, Value: v}] = Range... | [
"func",
"(",
"r",
"*",
"Reader",
")",
"PostingsRanges",
"(",
")",
"(",
"map",
"[",
"labels",
".",
"Label",
"]",
"Range",
",",
"error",
")",
"{",
"m",
":=",
"map",
"[",
"labels",
".",
"Label",
"]",
"Range",
"{",
"}",
"\n\n",
"for",
"k",
",",
"e"... | // PostingsRanges returns a new map of byte range in the underlying index file
// for all postings lists. | [
"PostingsRanges",
"returns",
"a",
"new",
"map",
"of",
"byte",
"range",
"in",
"the",
"underlying",
"index",
"file",
"for",
"all",
"postings",
"lists",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L725-L741 | train |
prometheus/tsdb | index/index.go | ReadSymbols | func ReadSymbols(bs ByteSlice, version int, off int) ([]string, map[uint32]string, error) {
if off == 0 {
return nil, nil, nil
}
d := encoding.NewDecbufAt(bs, off, castagnoliTable)
var (
origLen = d.Len()
cnt = d.Be32int()
basePos = uint32(off) + 4
nextPos = basePos + uint32(origLen-d... | go | func ReadSymbols(bs ByteSlice, version int, off int) ([]string, map[uint32]string, error) {
if off == 0 {
return nil, nil, nil
}
d := encoding.NewDecbufAt(bs, off, castagnoliTable)
var (
origLen = d.Len()
cnt = d.Be32int()
basePos = uint32(off) + 4
nextPos = basePos + uint32(origLen-d... | [
"func",
"ReadSymbols",
"(",
"bs",
"ByteSlice",
",",
"version",
"int",
",",
"off",
"int",
")",
"(",
"[",
"]",
"string",
",",
"map",
"[",
"uint32",
"]",
"string",
",",
"error",
")",
"{",
"if",
"off",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
","... | // ReadSymbols reads the symbol table fully into memory and allocates proper strings for them.
// Strings backed by the mmap'd memory would cause memory faults if applications keep using them
// after the reader is closed. | [
"ReadSymbols",
"reads",
"the",
"symbol",
"table",
"fully",
"into",
"memory",
"and",
"allocates",
"proper",
"strings",
"for",
"them",
".",
"Strings",
"backed",
"by",
"the",
"mmap",
"d",
"memory",
"would",
"cause",
"memory",
"faults",
"if",
"applications",
"keep... | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L746-L776 | train |
prometheus/tsdb | index/index.go | ReadOffsetTable | func ReadOffsetTable(bs ByteSlice, off uint64, f func([]string, uint64) error) error {
d := encoding.NewDecbufAt(bs, int(off), castagnoliTable)
cnt := d.Be32()
for d.Err() == nil && d.Len() > 0 && cnt > 0 {
keyCount := d.Uvarint()
keys := make([]string, 0, keyCount)
for i := 0; i < keyCount; i++ {
keys = ... | go | func ReadOffsetTable(bs ByteSlice, off uint64, f func([]string, uint64) error) error {
d := encoding.NewDecbufAt(bs, int(off), castagnoliTable)
cnt := d.Be32()
for d.Err() == nil && d.Len() > 0 && cnt > 0 {
keyCount := d.Uvarint()
keys := make([]string, 0, keyCount)
for i := 0; i < keyCount; i++ {
keys = ... | [
"func",
"ReadOffsetTable",
"(",
"bs",
"ByteSlice",
",",
"off",
"uint64",
",",
"f",
"func",
"(",
"[",
"]",
"string",
",",
"uint64",
")",
"error",
")",
"error",
"{",
"d",
":=",
"encoding",
".",
"NewDecbufAt",
"(",
"bs",
",",
"int",
"(",
"off",
")",
"... | // ReadOffsetTable reads an offset table and at the given position calls f for each
// found entry. If f returns an error it stops decoding and returns the received error. | [
"ReadOffsetTable",
"reads",
"an",
"offset",
"table",
"and",
"at",
"the",
"given",
"position",
"calls",
"f",
"for",
"each",
"found",
"entry",
".",
"If",
"f",
"returns",
"an",
"error",
"it",
"stops",
"decoding",
"and",
"returns",
"the",
"received",
"error",
... | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L780-L801 | train |
prometheus/tsdb | index/index.go | Symbols | func (r *Reader) Symbols() (map[string]struct{}, error) {
res := make(map[string]struct{}, len(r.symbolsV1)+len(r.symbolsV2))
for _, s := range r.symbolsV1 {
res[s] = struct{}{}
}
for _, s := range r.symbolsV2 {
res[s] = struct{}{}
}
return res, nil
} | go | func (r *Reader) Symbols() (map[string]struct{}, error) {
res := make(map[string]struct{}, len(r.symbolsV1)+len(r.symbolsV2))
for _, s := range r.symbolsV1 {
res[s] = struct{}{}
}
for _, s := range r.symbolsV2 {
res[s] = struct{}{}
}
return res, nil
} | [
"func",
"(",
"r",
"*",
"Reader",
")",
"Symbols",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
",",
"error",
")",
"{",
"res",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
",",
"len",
"(",
"r",
".",
"symbol... | // Symbols returns a set of symbols that exist within the index. | [
"Symbols",
"returns",
"a",
"set",
"of",
"symbols",
"that",
"exist",
"within",
"the",
"index",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L820-L830 | train |
prometheus/tsdb | index/index.go | LabelValues | func (r *Reader) LabelValues(names ...string) (StringTuples, error) {
key := strings.Join(names, labelNameSeperator)
off, ok := r.labels[key]
if !ok {
// XXX(fabxc): hot fix. Should return a partial data error and handle cases
// where the entire block has no data gracefully.
return emptyStringTuples{}, nil
... | go | func (r *Reader) LabelValues(names ...string) (StringTuples, error) {
key := strings.Join(names, labelNameSeperator)
off, ok := r.labels[key]
if !ok {
// XXX(fabxc): hot fix. Should return a partial data error and handle cases
// where the entire block has no data gracefully.
return emptyStringTuples{}, nil
... | [
"func",
"(",
"r",
"*",
"Reader",
")",
"LabelValues",
"(",
"names",
"...",
"string",
")",
"(",
"StringTuples",
",",
"error",
")",
"{",
"key",
":=",
"strings",
".",
"Join",
"(",
"names",
",",
"labelNameSeperator",
")",
"\n",
"off",
",",
"ok",
":=",
"r"... | // LabelValues returns value tuples that exist for the given label name tuples. | [
"LabelValues",
"returns",
"value",
"tuples",
"that",
"exist",
"for",
"the",
"given",
"label",
"name",
"tuples",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L838-L863 | train |
prometheus/tsdb | index/index.go | Series | func (r *Reader) Series(id uint64, lbls *labels.Labels, chks *[]chunks.Meta) error {
offset := id
// In version 2 series IDs are no longer exact references but series are 16-byte padded
// and the ID is the multiple of 16 of the actual position.
if r.version == FormatV2 {
offset = id * 16
}
d := encoding.NewDec... | go | func (r *Reader) Series(id uint64, lbls *labels.Labels, chks *[]chunks.Meta) error {
offset := id
// In version 2 series IDs are no longer exact references but series are 16-byte padded
// and the ID is the multiple of 16 of the actual position.
if r.version == FormatV2 {
offset = id * 16
}
d := encoding.NewDec... | [
"func",
"(",
"r",
"*",
"Reader",
")",
"Series",
"(",
"id",
"uint64",
",",
"lbls",
"*",
"labels",
".",
"Labels",
",",
"chks",
"*",
"[",
"]",
"chunks",
".",
"Meta",
")",
"error",
"{",
"offset",
":=",
"id",
"\n",
"// In version 2 series IDs are no longer ex... | // Series reads the series with the given ID and writes its labels and chunks into lbls and chks. | [
"Series",
"reads",
"the",
"series",
"with",
"the",
"given",
"ID",
"and",
"writes",
"its",
"labels",
"and",
"chunks",
"into",
"lbls",
"and",
"chks",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L881-L893 | train |
prometheus/tsdb | index/index.go | Postings | func (r *Reader) Postings(name, value string) (Postings, error) {
e, ok := r.postings[name]
if !ok {
return EmptyPostings(), nil
}
off, ok := e[value]
if !ok {
return EmptyPostings(), nil
}
d := encoding.NewDecbufAt(r.b, int(off), castagnoliTable)
if d.Err() != nil {
return nil, errors.Wrap(d.Err(), "get ... | go | func (r *Reader) Postings(name, value string) (Postings, error) {
e, ok := r.postings[name]
if !ok {
return EmptyPostings(), nil
}
off, ok := e[value]
if !ok {
return EmptyPostings(), nil
}
d := encoding.NewDecbufAt(r.b, int(off), castagnoliTable)
if d.Err() != nil {
return nil, errors.Wrap(d.Err(), "get ... | [
"func",
"(",
"r",
"*",
"Reader",
")",
"Postings",
"(",
"name",
",",
"value",
"string",
")",
"(",
"Postings",
",",
"error",
")",
"{",
"e",
",",
"ok",
":=",
"r",
".",
"postings",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"EmptyPosting... | // Postings returns a postings list for the given label pair. | [
"Postings",
"returns",
"a",
"postings",
"list",
"for",
"the",
"given",
"label",
"pair",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L896-L914 | train |
prometheus/tsdb | index/index.go | LabelNames | func (r *Reader) LabelNames() ([]string, error) {
labelNamesMap := make(map[string]struct{}, len(r.labels))
for key := range r.labels {
// 'key' contains the label names concatenated with the
// delimiter 'labelNameSeperator'.
names := strings.Split(key, labelNameSeperator)
for _, name := range names {
if ... | go | func (r *Reader) LabelNames() ([]string, error) {
labelNamesMap := make(map[string]struct{}, len(r.labels))
for key := range r.labels {
// 'key' contains the label names concatenated with the
// delimiter 'labelNameSeperator'.
names := strings.Split(key, labelNameSeperator)
for _, name := range names {
if ... | [
"func",
"(",
"r",
"*",
"Reader",
")",
"LabelNames",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"labelNamesMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
",",
"len",
"(",
"r",
".",
"labels",
")",
")",
"\n... | // LabelNames returns all the unique label names present in the index. | [
"LabelNames",
"returns",
"all",
"the",
"unique",
"label",
"names",
"present",
"in",
"the",
"index",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L928-L949 | train |
prometheus/tsdb | index/index.go | Postings | func (dec *Decoder) Postings(b []byte) (int, Postings, error) {
d := encoding.Decbuf{B: b}
n := d.Be32int()
l := d.Get()
return n, newBigEndianPostings(l), d.Err()
} | go | func (dec *Decoder) Postings(b []byte) (int, Postings, error) {
d := encoding.Decbuf{B: b}
n := d.Be32int()
l := d.Get()
return n, newBigEndianPostings(l), d.Err()
} | [
"func",
"(",
"dec",
"*",
"Decoder",
")",
"Postings",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"Postings",
",",
"error",
")",
"{",
"d",
":=",
"encoding",
".",
"Decbuf",
"{",
"B",
":",
"b",
"}",
"\n",
"n",
":=",
"d",
".",
"Be32int",
"(... | // Postings returns a postings list for b and its number of elements. | [
"Postings",
"returns",
"a",
"postings",
"list",
"for",
"b",
"and",
"its",
"number",
"of",
"elements",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L1028-L1033 | train |
prometheus/tsdb | index/index.go | Series | func (dec *Decoder) Series(b []byte, lbls *labels.Labels, chks *[]chunks.Meta) error {
*lbls = (*lbls)[:0]
*chks = (*chks)[:0]
d := encoding.Decbuf{B: b}
k := d.Uvarint()
for i := 0; i < k; i++ {
lno := uint32(d.Uvarint())
lvo := uint32(d.Uvarint())
if d.Err() != nil {
return errors.Wrap(d.Err(), "rea... | go | func (dec *Decoder) Series(b []byte, lbls *labels.Labels, chks *[]chunks.Meta) error {
*lbls = (*lbls)[:0]
*chks = (*chks)[:0]
d := encoding.Decbuf{B: b}
k := d.Uvarint()
for i := 0; i < k; i++ {
lno := uint32(d.Uvarint())
lvo := uint32(d.Uvarint())
if d.Err() != nil {
return errors.Wrap(d.Err(), "rea... | [
"func",
"(",
"dec",
"*",
"Decoder",
")",
"Series",
"(",
"b",
"[",
"]",
"byte",
",",
"lbls",
"*",
"labels",
".",
"Labels",
",",
"chks",
"*",
"[",
"]",
"chunks",
".",
"Meta",
")",
"error",
"{",
"*",
"lbls",
"=",
"(",
"*",
"lbls",
")",
"[",
":",... | // Series decodes a series entry from the given byte slice into lset and chks. | [
"Series",
"decodes",
"a",
"series",
"entry",
"from",
"the",
"given",
"byte",
"slice",
"into",
"lset",
"and",
"chks",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/index/index.go#L1036-L1100 | train |
prometheus/tsdb | labels/selector.go | Matches | func (s Selector) Matches(labels Labels) bool {
for _, m := range s {
if v := labels.Get(m.Name()); !m.Matches(v) {
return false
}
}
return true
} | go | func (s Selector) Matches(labels Labels) bool {
for _, m := range s {
if v := labels.Get(m.Name()); !m.Matches(v) {
return false
}
}
return true
} | [
"func",
"(",
"s",
"Selector",
")",
"Matches",
"(",
"labels",
"Labels",
")",
"bool",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"s",
"{",
"if",
"v",
":=",
"labels",
".",
"Get",
"(",
"m",
".",
"Name",
"(",
")",
")",
";",
"!",
"m",
".",
"Matches"... | // Matches returns whether the labels satisfy all matchers. | [
"Matches",
"returns",
"whether",
"the",
"labels",
"satisfy",
"all",
"matchers",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/labels/selector.go#L25-L32 | train |
prometheus/tsdb | labels/selector.go | NewEqualMatcher | func NewEqualMatcher(name, value string) Matcher {
return &EqualMatcher{name: name, value: value}
} | go | func NewEqualMatcher(name, value string) Matcher {
return &EqualMatcher{name: name, value: value}
} | [
"func",
"NewEqualMatcher",
"(",
"name",
",",
"value",
"string",
")",
"Matcher",
"{",
"return",
"&",
"EqualMatcher",
"{",
"name",
":",
"name",
",",
"value",
":",
"value",
"}",
"\n",
"}"
] | // NewEqualMatcher returns a new matcher matching an exact label value. | [
"NewEqualMatcher",
"returns",
"a",
"new",
"matcher",
"matching",
"an",
"exact",
"label",
"value",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/labels/selector.go#L62-L64 | train |
prometheus/tsdb | labels/selector.go | NewRegexpMatcher | func NewRegexpMatcher(name, pattern string) (Matcher, error) {
re, err := regexp.Compile(pattern)
if err != nil {
return nil, err
}
return ®expMatcher{name: name, re: re}, nil
} | go | func NewRegexpMatcher(name, pattern string) (Matcher, error) {
re, err := regexp.Compile(pattern)
if err != nil {
return nil, err
}
return ®expMatcher{name: name, re: re}, nil
} | [
"func",
"NewRegexpMatcher",
"(",
"name",
",",
"pattern",
"string",
")",
"(",
"Matcher",
",",
"error",
")",
"{",
"re",
",",
"err",
":=",
"regexp",
".",
"Compile",
"(",
"pattern",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
... | // NewRegexpMatcher returns a new matcher verifying that a value matches
// the regular expression pattern. | [
"NewRegexpMatcher",
"returns",
"a",
"new",
"matcher",
"verifying",
"that",
"a",
"value",
"matches",
"the",
"regular",
"expression",
"pattern",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/labels/selector.go#L77-L83 | train |
prometheus/tsdb | labels/selector.go | NewMustRegexpMatcher | func NewMustRegexpMatcher(name, pattern string) Matcher {
re, err := regexp.Compile(pattern)
if err != nil {
panic(err)
}
return ®expMatcher{name: name, re: re}
} | go | func NewMustRegexpMatcher(name, pattern string) Matcher {
re, err := regexp.Compile(pattern)
if err != nil {
panic(err)
}
return ®expMatcher{name: name, re: re}
} | [
"func",
"NewMustRegexpMatcher",
"(",
"name",
",",
"pattern",
"string",
")",
"Matcher",
"{",
"re",
",",
"err",
":=",
"regexp",
".",
"Compile",
"(",
"pattern",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return... | // NewMustRegexpMatcher returns a new matcher verifying that a value matches
// the regular expression pattern. Will panic if the pattern is not a valid
// regular expression. | [
"NewMustRegexpMatcher",
"returns",
"a",
"new",
"matcher",
"verifying",
"that",
"a",
"value",
"matches",
"the",
"regular",
"expression",
"pattern",
".",
"Will",
"panic",
"if",
"the",
"pattern",
"is",
"not",
"a",
"valid",
"regular",
"expression",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/labels/selector.go#L88-L95 | train |
prometheus/tsdb | chunks/chunks.go | writeHash | func (cm *Meta) writeHash(h hash.Hash) error {
if _, err := h.Write([]byte{byte(cm.Chunk.Encoding())}); err != nil {
return err
}
if _, err := h.Write(cm.Chunk.Bytes()); err != nil {
return err
}
return nil
} | go | func (cm *Meta) writeHash(h hash.Hash) error {
if _, err := h.Write([]byte{byte(cm.Chunk.Encoding())}); err != nil {
return err
}
if _, err := h.Write(cm.Chunk.Bytes()); err != nil {
return err
}
return nil
} | [
"func",
"(",
"cm",
"*",
"Meta",
")",
"writeHash",
"(",
"h",
"hash",
".",
"Hash",
")",
"error",
"{",
"if",
"_",
",",
"err",
":=",
"h",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"byte",
"(",
"cm",
".",
"Chunk",
".",
"Encoding",
"(",
")",
")",
... | // writeHash writes the chunk encoding and raw data into the provided hash. | [
"writeHash",
"writes",
"the",
"chunk",
"encoding",
"and",
"raw",
"data",
"into",
"the",
"provided",
"hash",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/chunks/chunks.go#L58-L66 | train |
prometheus/tsdb | chunks/chunks.go | NewWriter | func NewWriter(dir string) (*Writer, error) {
if err := os.MkdirAll(dir, 0777); err != nil {
return nil, err
}
dirFile, err := fileutil.OpenDir(dir)
if err != nil {
return nil, err
}
cw := &Writer{
dirFile: dirFile,
n: 0,
crc32: newCRC32(),
segmentSize: defaultChunkSegmentSize,
}
... | go | func NewWriter(dir string) (*Writer, error) {
if err := os.MkdirAll(dir, 0777); err != nil {
return nil, err
}
dirFile, err := fileutil.OpenDir(dir)
if err != nil {
return nil, err
}
cw := &Writer{
dirFile: dirFile,
n: 0,
crc32: newCRC32(),
segmentSize: defaultChunkSegmentSize,
}
... | [
"func",
"NewWriter",
"(",
"dir",
"string",
")",
"(",
"*",
"Writer",
",",
"error",
")",
"{",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"dir",
",",
"0777",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"dir... | // NewWriter returns a new writer against the given directory. | [
"NewWriter",
"returns",
"a",
"new",
"writer",
"against",
"the",
"given",
"directory",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/chunks/chunks.go#L107-L122 | train |
prometheus/tsdb | chunks/chunks.go | finalizeTail | func (w *Writer) finalizeTail() error {
tf := w.tail()
if tf == nil {
return nil
}
if err := w.wbuf.Flush(); err != nil {
return err
}
if err := tf.Sync(); err != nil {
return err
}
// As the file was pre-allocated, we truncate any superfluous zero bytes.
off, err := tf.Seek(0, io.SeekCurrent)
if err !... | go | func (w *Writer) finalizeTail() error {
tf := w.tail()
if tf == nil {
return nil
}
if err := w.wbuf.Flush(); err != nil {
return err
}
if err := tf.Sync(); err != nil {
return err
}
// As the file was pre-allocated, we truncate any superfluous zero bytes.
off, err := tf.Seek(0, io.SeekCurrent)
if err !... | [
"func",
"(",
"w",
"*",
"Writer",
")",
"finalizeTail",
"(",
")",
"error",
"{",
"tf",
":=",
"w",
".",
"tail",
"(",
")",
"\n",
"if",
"tf",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"w",
".",
"wbuf",
".",
"Flush",
"... | // finalizeTail writes all pending data to the current tail file,
// truncates its size, and closes it. | [
"finalizeTail",
"writes",
"all",
"pending",
"data",
"to",
"the",
"current",
"tail",
"file",
"truncates",
"its",
"size",
"and",
"closes",
"it",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/chunks/chunks.go#L133-L155 | train |
prometheus/tsdb | chunks/chunks.go | MergeChunks | func MergeChunks(a, b chunkenc.Chunk) (*chunkenc.XORChunk, error) {
newChunk := chunkenc.NewXORChunk()
app, err := newChunk.Appender()
if err != nil {
return nil, err
}
ait := a.Iterator()
bit := b.Iterator()
aok, bok := ait.Next(), bit.Next()
for aok && bok {
at, av := ait.At()
bt, bv := bit.At()
if at... | go | func MergeChunks(a, b chunkenc.Chunk) (*chunkenc.XORChunk, error) {
newChunk := chunkenc.NewXORChunk()
app, err := newChunk.Appender()
if err != nil {
return nil, err
}
ait := a.Iterator()
bit := b.Iterator()
aok, bok := ait.Next(), bit.Next()
for aok && bok {
at, av := ait.At()
bt, bv := bit.At()
if at... | [
"func",
"MergeChunks",
"(",
"a",
",",
"b",
"chunkenc",
".",
"Chunk",
")",
"(",
"*",
"chunkenc",
".",
"XORChunk",
",",
"error",
")",
"{",
"newChunk",
":=",
"chunkenc",
".",
"NewXORChunk",
"(",
")",
"\n",
"app",
",",
"err",
":=",
"newChunk",
".",
"Appe... | // MergeChunks vertically merges a and b, i.e., if there is any sample
// with same timestamp in both a and b, the sample in a is discarded. | [
"MergeChunks",
"vertically",
"merges",
"a",
"and",
"b",
"i",
".",
"e",
".",
"if",
"there",
"is",
"any",
"sample",
"with",
"same",
"timestamp",
"in",
"both",
"a",
"and",
"b",
"the",
"sample",
"in",
"a",
"is",
"discarded",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/chunks/chunks.go#L240-L281 | train |
prometheus/tsdb | chunks/chunks.go | NewDirReader | func NewDirReader(dir string, pool chunkenc.Pool) (*Reader, error) {
files, err := sequenceFiles(dir)
if err != nil {
return nil, err
}
if pool == nil {
pool = chunkenc.NewPool()
}
var (
bs []ByteSlice
cs []io.Closer
merr tsdb_errors.MultiError
)
for _, fn := range files {
f, err := fileutil.Op... | go | func NewDirReader(dir string, pool chunkenc.Pool) (*Reader, error) {
files, err := sequenceFiles(dir)
if err != nil {
return nil, err
}
if pool == nil {
pool = chunkenc.NewPool()
}
var (
bs []ByteSlice
cs []io.Closer
merr tsdb_errors.MultiError
)
for _, fn := range files {
f, err := fileutil.Op... | [
"func",
"NewDirReader",
"(",
"dir",
"string",
",",
"pool",
"chunkenc",
".",
"Pool",
")",
"(",
"*",
"Reader",
",",
"error",
")",
"{",
"files",
",",
"err",
":=",
"sequenceFiles",
"(",
"dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // NewDirReader returns a new Reader against sequentially numbered files in the
// given directory. | [
"NewDirReader",
"returns",
"a",
"new",
"Reader",
"against",
"sequentially",
"numbered",
"files",
"in",
"the",
"given",
"directory",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/chunks/chunks.go#L401-L433 | train |
prometheus/tsdb | chunks/chunks.go | Chunk | func (s *Reader) Chunk(ref uint64) (chunkenc.Chunk, error) {
var (
sgmSeq = int(ref >> 32)
sgmOffset = int((ref << 32) >> 32)
)
if sgmSeq >= len(s.bs) {
return nil, errors.Errorf("reference sequence %d out of range", sgmSeq)
}
chkS := s.bs[sgmSeq]
if sgmOffset >= chkS.Len() {
return nil, errors.Errorf... | go | func (s *Reader) Chunk(ref uint64) (chunkenc.Chunk, error) {
var (
sgmSeq = int(ref >> 32)
sgmOffset = int((ref << 32) >> 32)
)
if sgmSeq >= len(s.bs) {
return nil, errors.Errorf("reference sequence %d out of range", sgmSeq)
}
chkS := s.bs[sgmSeq]
if sgmOffset >= chkS.Len() {
return nil, errors.Errorf... | [
"func",
"(",
"s",
"*",
"Reader",
")",
"Chunk",
"(",
"ref",
"uint64",
")",
"(",
"chunkenc",
".",
"Chunk",
",",
"error",
")",
"{",
"var",
"(",
"sgmSeq",
"=",
"int",
"(",
"ref",
">>",
"32",
")",
"\n",
"sgmOffset",
"=",
"int",
"(",
"(",
"ref",
"<<"... | // Chunk returns a chunk from a given reference. | [
"Chunk",
"returns",
"a",
"chunk",
"from",
"a",
"given",
"reference",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/chunks/chunks.go#L445-L469 | train |
prometheus/tsdb | chunkenc/xor.go | NewXORChunk | func NewXORChunk() *XORChunk {
b := make([]byte, 2, 128)
return &XORChunk{b: bstream{stream: b, count: 0}}
} | go | func NewXORChunk() *XORChunk {
b := make([]byte, 2, 128)
return &XORChunk{b: bstream{stream: b, count: 0}}
} | [
"func",
"NewXORChunk",
"(",
")",
"*",
"XORChunk",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"2",
",",
"128",
")",
"\n",
"return",
"&",
"XORChunk",
"{",
"b",
":",
"bstream",
"{",
"stream",
":",
"b",
",",
"count",
":",
"0",
"}",
"}",
... | // NewXORChunk returns a new chunk with XOR encoding of the given size. | [
"NewXORChunk",
"returns",
"a",
"new",
"chunk",
"with",
"XOR",
"encoding",
"of",
"the",
"given",
"size",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/chunkenc/xor.go#L58-L61 | train |
prometheus/tsdb | chunkenc/xor.go | NumSamples | func (c *XORChunk) NumSamples() int {
return int(binary.BigEndian.Uint16(c.Bytes()))
} | go | func (c *XORChunk) NumSamples() int {
return int(binary.BigEndian.Uint16(c.Bytes()))
} | [
"func",
"(",
"c",
"*",
"XORChunk",
")",
"NumSamples",
"(",
")",
"int",
"{",
"return",
"int",
"(",
"binary",
".",
"BigEndian",
".",
"Uint16",
"(",
"c",
".",
"Bytes",
"(",
")",
")",
")",
"\n",
"}"
] | // NumSamples returns the number of samples in the chunk. | [
"NumSamples",
"returns",
"the",
"number",
"of",
"samples",
"in",
"the",
"chunk",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/chunkenc/xor.go#L74-L76 | train |
prometheus/tsdb | chunkenc/xor.go | Appender | func (c *XORChunk) Appender() (Appender, error) {
it := c.iterator()
// To get an appender we must know the state it would have if we had
// appended all existing data from scratch.
// We iterate through the end and populate via the iterator's state.
for it.Next() {
}
if err := it.Err(); err != nil {
return n... | go | func (c *XORChunk) Appender() (Appender, error) {
it := c.iterator()
// To get an appender we must know the state it would have if we had
// appended all existing data from scratch.
// We iterate through the end and populate via the iterator's state.
for it.Next() {
}
if err := it.Err(); err != nil {
return n... | [
"func",
"(",
"c",
"*",
"XORChunk",
")",
"Appender",
"(",
")",
"(",
"Appender",
",",
"error",
")",
"{",
"it",
":=",
"c",
".",
"iterator",
"(",
")",
"\n\n",
"// To get an appender we must know the state it would have if we had",
"// appended all existing data from scrat... | // Appender implements the Chunk interface. | [
"Appender",
"implements",
"the",
"Chunk",
"interface",
"."
] | 3ccab17f5dc60de1bea3e5cfc807cb63a287078f | https://github.com/prometheus/tsdb/blob/3ccab17f5dc60de1bea3e5cfc807cb63a287078f/chunkenc/xor.go#L79-L103 | train |
edgexfoundry/edgex-go | internal/pkg/db/mongo/export.go | DeleteRegistrationByName | func (mc MongoClient) DeleteRegistrationByName(name string) error {
return mc.deleteRegistration(bson.M{"name": name})
} | go | func (mc MongoClient) DeleteRegistrationByName(name string) error {
return mc.deleteRegistration(bson.M{"name": name})
} | [
"func",
"(",
"mc",
"MongoClient",
")",
"DeleteRegistrationByName",
"(",
"name",
"string",
")",
"error",
"{",
"return",
"mc",
".",
"deleteRegistration",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"name",
"}",
")",
"\n",
"}"
] | // Delete a registration by name
// UnexpectedError - problem getting in database
// NotFound - no registration with the ID was found | [
"Delete",
"a",
"registration",
"by",
"name",
"UnexpectedError",
"-",
"problem",
"getting",
"in",
"database",
"NotFound",
"-",
"no",
"registration",
"with",
"the",
"ID",
"was",
"found"
] | c67086fe10c4d34caeefffaee5379490103dd63f | https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/export.go#L120-L122 | train |
edgexfoundry/edgex-go | internal/pkg/db/mongo/export.go | getRegistrations | func (mc MongoClient) getRegistrations(q bson.M) ([]models.Registration, error) {
s := mc.getSessionCopy()
defer s.Close()
var regs []models.Registration
err := s.DB(mc.database.Name).C(db.ExportCollection).Find(q).All(®s)
if err != nil {
return []models.Registration{}, errorMap(err)
}
return regs, nil
} | go | func (mc MongoClient) getRegistrations(q bson.M) ([]models.Registration, error) {
s := mc.getSessionCopy()
defer s.Close()
var regs []models.Registration
err := s.DB(mc.database.Name).C(db.ExportCollection).Find(q).All(®s)
if err != nil {
return []models.Registration{}, errorMap(err)
}
return regs, nil
} | [
"func",
"(",
"mc",
"MongoClient",
")",
"getRegistrations",
"(",
"q",
"bson",
".",
"M",
")",
"(",
"[",
"]",
"models",
".",
"Registration",
",",
"error",
")",
"{",
"s",
":=",
"mc",
".",
"getSessionCopy",
"(",
")",
"\n",
"defer",
"s",
".",
"Close",
"(... | // Get registrations for the passed query | [
"Get",
"registrations",
"for",
"the",
"passed",
"query"
] | c67086fe10c4d34caeefffaee5379490103dd63f | https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/export.go#L134-L145 | train |
edgexfoundry/edgex-go | internal/pkg/db/mongo/export.go | getRegistration | func (mc MongoClient) getRegistration(q bson.M) (models.Registration, error) {
s := mc.getSessionCopy()
defer s.Close()
var reg models.Registration
err := s.DB(mc.database.Name).C(db.ExportCollection).Find(q).One(®)
if err != nil {
return models.Registration{}, errorMap(err)
}
return reg, nil
} | go | func (mc MongoClient) getRegistration(q bson.M) (models.Registration, error) {
s := mc.getSessionCopy()
defer s.Close()
var reg models.Registration
err := s.DB(mc.database.Name).C(db.ExportCollection).Find(q).One(®)
if err != nil {
return models.Registration{}, errorMap(err)
}
return reg, nil
} | [
"func",
"(",
"mc",
"MongoClient",
")",
"getRegistration",
"(",
"q",
"bson",
".",
"M",
")",
"(",
"models",
".",
"Registration",
",",
"error",
")",
"{",
"s",
":=",
"mc",
".",
"getSessionCopy",
"(",
")",
"\n",
"defer",
"s",
".",
"Close",
"(",
")",
"\n... | // Get a single registration for the passed query | [
"Get",
"a",
"single",
"registration",
"for",
"the",
"passed",
"query"
] | c67086fe10c4d34caeefffaee5379490103dd63f | https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/export.go#L148-L158 | train |
edgexfoundry/edgex-go | internal/core/data/init.go | newDBClient | func newDBClient(dbType string) (interfaces.DBClient, error) {
switch dbType {
case db.MongoDB:
dbConfig := db.Configuration{
Host: Configuration.Databases["Primary"].Host,
Port: Configuration.Databases["Primary"].Port,
Timeout: Configuration.Databases["Primary"].Timeout,
DatabaseNa... | go | func newDBClient(dbType string) (interfaces.DBClient, error) {
switch dbType {
case db.MongoDB:
dbConfig := db.Configuration{
Host: Configuration.Databases["Primary"].Host,
Port: Configuration.Databases["Primary"].Port,
Timeout: Configuration.Databases["Primary"].Timeout,
DatabaseNa... | [
"func",
"newDBClient",
"(",
"dbType",
"string",
")",
"(",
"interfaces",
".",
"DBClient",
",",
"error",
")",
"{",
"switch",
"dbType",
"{",
"case",
"db",
".",
"MongoDB",
":",
"dbConfig",
":=",
"db",
".",
"Configuration",
"{",
"Host",
":",
"Configuration",
... | // Return the dbClient interface | [
"Return",
"the",
"dbClient",
"interface"
] | c67086fe10c4d34caeefffaee5379490103dd63f | https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/data/init.go#L152-L173 | train |
edgexfoundry/edgex-go | internal/system/agent/utils.go | pingHandler | func pingHandler(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte("pong"))
} | go | func pingHandler(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte("pong"))
} | [
"func",
"pingHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"_",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
... | // Test if the service is working | [
"Test",
"if",
"the",
"service",
"is",
"working"
] | c67086fe10c4d34caeefffaee5379490103dd63f | https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/system/agent/utils.go#L25-L28 | train |
edgexfoundry/edgex-go | internal/pkg/db/mongo/data.go | EventsWithLimit | func (mc MongoClient) EventsWithLimit(limit int) ([]contract.Event, error) {
return mc.mapEvents(mc.getEventsLimit(bson.M{}, limit))
} | go | func (mc MongoClient) EventsWithLimit(limit int) ([]contract.Event, error) {
return mc.mapEvents(mc.getEventsLimit(bson.M{}, limit))
} | [
"func",
"(",
"mc",
"MongoClient",
")",
"EventsWithLimit",
"(",
"limit",
"int",
")",
"(",
"[",
"]",
"contract",
".",
"Event",
",",
"error",
")",
"{",
"return",
"mc",
".",
"mapEvents",
"(",
"mc",
".",
"getEventsLimit",
"(",
"bson",
".",
"M",
"{",
"}",
... | // Return events up to the max number specified
// UnexpectedError - failed to retrieve events from the database
// Sort the events in descending order by ID | [
"Return",
"events",
"up",
"to",
"the",
"max",
"number",
"specified",
"UnexpectedError",
"-",
"failed",
"to",
"retrieve",
"events",
"from",
"the",
"database",
"Sort",
"the",
"events",
"in",
"descending",
"order",
"by",
"ID"
] | c67086fe10c4d34caeefffaee5379490103dd63f | https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L42-L44 | train |
edgexfoundry/edgex-go | internal/pkg/db/mongo/data.go | EventCount | func (mc MongoClient) EventCount() (int, error) {
s := mc.getSessionCopy()
defer s.Close()
count, err := s.DB(mc.database.Name).C(db.EventsCollection).Find(nil).Count()
if err != nil {
return 0, errorMap(err)
}
return count, nil
} | go | func (mc MongoClient) EventCount() (int, error) {
s := mc.getSessionCopy()
defer s.Close()
count, err := s.DB(mc.database.Name).C(db.EventsCollection).Find(nil).Count()
if err != nil {
return 0, errorMap(err)
}
return count, nil
} | [
"func",
"(",
"mc",
"MongoClient",
")",
"EventCount",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"s",
":=",
"mc",
".",
"getSessionCopy",
"(",
")",
"\n",
"defer",
"s",
".",
"Close",
"(",
")",
"\n\n",
"count",
",",
"err",
":=",
"s",
".",
"DB",
... | // Get the number of events in Mongo | [
"Get",
"the",
"number",
"of",
"events",
"in",
"Mongo"
] | c67086fe10c4d34caeefffaee5379490103dd63f | https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L121-L130 | train |
edgexfoundry/edgex-go | internal/pkg/db/mongo/data.go | EventCountByDeviceId | func (mc MongoClient) EventCountByDeviceId(id string) (int, error) {
s := mc.getSessionCopy()
defer s.Close()
query := bson.M{"device": id}
count, err := s.DB(mc.database.Name).C(db.EventsCollection).Find(query).Count()
if err != nil {
return 0, errorMap(err)
}
return count, nil
} | go | func (mc MongoClient) EventCountByDeviceId(id string) (int, error) {
s := mc.getSessionCopy()
defer s.Close()
query := bson.M{"device": id}
count, err := s.DB(mc.database.Name).C(db.EventsCollection).Find(query).Count()
if err != nil {
return 0, errorMap(err)
}
return count, nil
} | [
"func",
"(",
"mc",
"MongoClient",
")",
"EventCountByDeviceId",
"(",
"id",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"s",
":=",
"mc",
".",
"getSessionCopy",
"(",
")",
"\n",
"defer",
"s",
".",
"Close",
"(",
")",
"\n\n",
"query",
":=",
"bson",
... | // Get the number of events in Mongo for the device | [
"Get",
"the",
"number",
"of",
"events",
"in",
"Mongo",
"for",
"the",
"device"
] | c67086fe10c4d34caeefffaee5379490103dd63f | https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L133-L143 | train |
edgexfoundry/edgex-go | internal/pkg/db/mongo/data.go | DeleteEventById | func (mc MongoClient) DeleteEventById(id string) error {
return mc.deleteById(db.EventsCollection, id)
} | go | func (mc MongoClient) DeleteEventById(id string) error {
return mc.deleteById(db.EventsCollection, id)
} | [
"func",
"(",
"mc",
"MongoClient",
")",
"DeleteEventById",
"(",
"id",
"string",
")",
"error",
"{",
"return",
"mc",
".",
"deleteById",
"(",
"db",
".",
"EventsCollection",
",",
"id",
")",
"\n",
"}"
] | // Delete an event by ID and all of its readings
// 404 - Event not found
// 503 - Unexpected problems | [
"Delete",
"an",
"event",
"by",
"ID",
"and",
"all",
"of",
"its",
"readings",
"404",
"-",
"Event",
"not",
"found",
"503",
"-",
"Unexpected",
"problems"
] | c67086fe10c4d34caeefffaee5379490103dd63f | https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L148-L150 | train |
edgexfoundry/edgex-go | internal/pkg/db/mongo/data.go | EventsForDeviceLimit | func (mc MongoClient) EventsForDeviceLimit(id string, limit int) ([]contract.Event, error) {
return mc.mapEvents(mc.getEventsLimit(bson.M{"device": id}, limit))
} | go | func (mc MongoClient) EventsForDeviceLimit(id string, limit int) ([]contract.Event, error) {
return mc.mapEvents(mc.getEventsLimit(bson.M{"device": id}, limit))
} | [
"func",
"(",
"mc",
"MongoClient",
")",
"EventsForDeviceLimit",
"(",
"id",
"string",
",",
"limit",
"int",
")",
"(",
"[",
"]",
"contract",
".",
"Event",
",",
"error",
")",
"{",
"return",
"mc",
".",
"mapEvents",
"(",
"mc",
".",
"getEventsLimit",
"(",
"bso... | // Get a list of events based on the device id and limit | [
"Get",
"a",
"list",
"of",
"events",
"based",
"on",
"the",
"device",
"id",
"and",
"limit"
] | c67086fe10c4d34caeefffaee5379490103dd63f | https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L153-L155 | train |
edgexfoundry/edgex-go | internal/pkg/db/mongo/data.go | EventsByCreationTime | func (mc MongoClient) EventsByCreationTime(startTime, endTime int64, limit int) ([]contract.Event, error) {
query := bson.M{"created": bson.M{
"$gte": startTime,
"$lte": endTime,
}}
return mc.mapEvents(mc.getEventsLimit(query, limit))
} | go | func (mc MongoClient) EventsByCreationTime(startTime, endTime int64, limit int) ([]contract.Event, error) {
query := bson.M{"created": bson.M{
"$gte": startTime,
"$lte": endTime,
}}
return mc.mapEvents(mc.getEventsLimit(query, limit))
} | [
"func",
"(",
"mc",
"MongoClient",
")",
"EventsByCreationTime",
"(",
"startTime",
",",
"endTime",
"int64",
",",
"limit",
"int",
")",
"(",
"[",
"]",
"contract",
".",
"Event",
",",
"error",
")",
"{",
"query",
":=",
"bson",
".",
"M",
"{",
"\"",
"\"",
":"... | // Return a list of events whose creation time is between startTime and endTime
// Limit the number of results by limit | [
"Return",
"a",
"list",
"of",
"events",
"whose",
"creation",
"time",
"is",
"between",
"startTime",
"and",
"endTime",
"Limit",
"the",
"number",
"of",
"results",
"by",
"limit"
] | c67086fe10c4d34caeefffaee5379490103dd63f | https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L164-L170 | train |
edgexfoundry/edgex-go | internal/pkg/db/mongo/data.go | EventsPushed | func (mc MongoClient) EventsPushed() ([]contract.Event, error) {
return mc.mapEvents(mc.getEvents(bson.M{"pushed": bson.M{"$gt": int64(0)}}))
} | go | func (mc MongoClient) EventsPushed() ([]contract.Event, error) {
return mc.mapEvents(mc.getEvents(bson.M{"pushed": bson.M{"$gt": int64(0)}}))
} | [
"func",
"(",
"mc",
"MongoClient",
")",
"EventsPushed",
"(",
")",
"(",
"[",
"]",
"contract",
".",
"Event",
",",
"error",
")",
"{",
"return",
"mc",
".",
"mapEvents",
"(",
"mc",
".",
"getEvents",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"bson",
... | // Get all of the events that have been pushed | [
"Get",
"all",
"of",
"the",
"events",
"that",
"have",
"been",
"pushed"
] | c67086fe10c4d34caeefffaee5379490103dd63f | https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L179-L181 | train |
edgexfoundry/edgex-go | internal/pkg/db/mongo/data.go | ScrubAllEvents | func (mc MongoClient) ScrubAllEvents() error {
s := mc.getSessionCopy()
defer s.Close()
_, err := s.DB(mc.database.Name).C(db.ReadingsCollection).RemoveAll(nil)
if err != nil {
return errorMap(err)
}
_, err = s.DB(mc.database.Name).C(db.EventsCollection).RemoveAll(nil)
if err != nil {
return errorMap(err)
... | go | func (mc MongoClient) ScrubAllEvents() error {
s := mc.getSessionCopy()
defer s.Close()
_, err := s.DB(mc.database.Name).C(db.ReadingsCollection).RemoveAll(nil)
if err != nil {
return errorMap(err)
}
_, err = s.DB(mc.database.Name).C(db.EventsCollection).RemoveAll(nil)
if err != nil {
return errorMap(err)
... | [
"func",
"(",
"mc",
"MongoClient",
")",
"ScrubAllEvents",
"(",
")",
"error",
"{",
"s",
":=",
"mc",
".",
"getSessionCopy",
"(",
")",
"\n",
"defer",
"s",
".",
"Close",
"(",
")",
"\n\n",
"_",
",",
"err",
":=",
"s",
".",
"DB",
"(",
"mc",
".",
"databas... | // Delete all of the readings and all of the events | [
"Delete",
"all",
"of",
"the",
"readings",
"and",
"all",
"of",
"the",
"events"
] | c67086fe10c4d34caeefffaee5379490103dd63f | https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L184-L199 | train |
edgexfoundry/edgex-go | internal/pkg/db/mongo/data.go | getEvents | func (mc MongoClient) getEvents(q bson.M) (me []models.Event, err error) {
s := mc.getSessionCopy()
defer s.Close()
err = s.DB(mc.database.Name).C(db.EventsCollection).Find(q).All(&me)
if err != nil {
return []models.Event{}, errorMap(err)
}
return
} | go | func (mc MongoClient) getEvents(q bson.M) (me []models.Event, err error) {
s := mc.getSessionCopy()
defer s.Close()
err = s.DB(mc.database.Name).C(db.EventsCollection).Find(q).All(&me)
if err != nil {
return []models.Event{}, errorMap(err)
}
return
} | [
"func",
"(",
"mc",
"MongoClient",
")",
"getEvents",
"(",
"q",
"bson",
".",
"M",
")",
"(",
"me",
"[",
"]",
"models",
".",
"Event",
",",
"err",
"error",
")",
"{",
"s",
":=",
"mc",
".",
"getSessionCopy",
"(",
")",
"\n",
"defer",
"s",
".",
"Close",
... | // Get events for the passed query | [
"Get",
"events",
"for",
"the",
"passed",
"query"
] | c67086fe10c4d34caeefffaee5379490103dd63f | https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L202-L211 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.