repo stringlengths 5 67 | path stringlengths 4 218 | func_name stringlengths 0 151 | original_string stringlengths 52 373k | language stringclasses 6
values | code stringlengths 52 373k | code_tokens listlengths 10 512 | docstring stringlengths 3 47.2k | docstring_tokens listlengths 3 234 | sha stringlengths 40 40 | url stringlengths 85 339 | partition stringclasses 3
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
dgraph-io/badger | txn.go | Get | func (txn *Txn) Get(key []byte) (item *Item, rerr error) {
if len(key) == 0 {
return nil, ErrEmptyKey
} else if txn.discarded {
return nil, ErrDiscardedTxn
}
item = new(Item)
if txn.update {
if e, has := txn.pendingWrites[string(key)]; has && bytes.Equal(key, e.Key) {
if isDeletedOrExpired(e.meta, e.Expi... | go | func (txn *Txn) Get(key []byte) (item *Item, rerr error) {
if len(key) == 0 {
return nil, ErrEmptyKey
} else if txn.discarded {
return nil, ErrDiscardedTxn
}
item = new(Item)
if txn.update {
if e, has := txn.pendingWrites[string(key)]; has && bytes.Equal(key, e.Key) {
if isDeletedOrExpired(e.meta, e.Expi... | [
"func",
"(",
"txn",
"*",
"Txn",
")",
"Get",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"item",
"*",
"Item",
",",
"rerr",
"error",
")",
"{",
"if",
"len",
"(",
"key",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"ErrEmptyKey",
"\n",
"}",
"else",
"if... | // Get looks for key and returns corresponding Item.
// If key is not found, ErrKeyNotFound is returned. | [
"Get",
"looks",
"for",
"key",
"and",
"returns",
"corresponding",
"Item",
".",
"If",
"key",
"is",
"not",
"found",
"ErrKeyNotFound",
"is",
"returned",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/txn.go#L429-L479 | test |
dgraph-io/badger | txn.go | CommitWith | func (txn *Txn) CommitWith(cb func(error)) {
txn.commitPrecheck() // Precheck before discarding txn.
defer txn.Discard()
if cb == nil {
panic("Nil callback provided to CommitWith")
}
if len(txn.writes) == 0 {
// Do not run these callbacks from here, because the CommitWith and the
// callback might be acqui... | go | func (txn *Txn) CommitWith(cb func(error)) {
txn.commitPrecheck() // Precheck before discarding txn.
defer txn.Discard()
if cb == nil {
panic("Nil callback provided to CommitWith")
}
if len(txn.writes) == 0 {
// Do not run these callbacks from here, because the CommitWith and the
// callback might be acqui... | [
"func",
"(",
"txn",
"*",
"Txn",
")",
"CommitWith",
"(",
"cb",
"func",
"(",
"error",
")",
")",
"{",
"txn",
".",
"commitPrecheck",
"(",
")",
"\n",
"defer",
"txn",
".",
"Discard",
"(",
")",
"\n",
"if",
"cb",
"==",
"nil",
"{",
"panic",
"(",
"\"Nil ca... | // CommitWith acts like Commit, but takes a callback, which gets run via a
// goroutine to avoid blocking this function. The callback is guaranteed to run,
// so it is safe to increment sync.WaitGroup before calling CommitWith, and
// decrementing it in the callback; to block until all callbacks are run. | [
"CommitWith",
"acts",
"like",
"Commit",
"but",
"takes",
"a",
"callback",
"which",
"gets",
"run",
"via",
"a",
"goroutine",
"to",
"avoid",
"blocking",
"this",
"function",
".",
"The",
"callback",
"is",
"guaranteed",
"to",
"run",
"so",
"it",
"is",
"safe",
"to"... | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/txn.go#L635-L658 | test |
dgraph-io/badger | txn.go | View | func (db *DB) View(fn func(txn *Txn) error) error {
var txn *Txn
if db.opt.managedTxns {
txn = db.NewTransactionAt(math.MaxUint64, false)
} else {
txn = db.NewTransaction(false)
}
defer txn.Discard()
return fn(txn)
} | go | func (db *DB) View(fn func(txn *Txn) error) error {
var txn *Txn
if db.opt.managedTxns {
txn = db.NewTransactionAt(math.MaxUint64, false)
} else {
txn = db.NewTransaction(false)
}
defer txn.Discard()
return fn(txn)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"View",
"(",
"fn",
"func",
"(",
"txn",
"*",
"Txn",
")",
"error",
")",
"error",
"{",
"var",
"txn",
"*",
"Txn",
"\n",
"if",
"db",
".",
"opt",
".",
"managedTxns",
"{",
"txn",
"=",
"db",
".",
"NewTransactionAt",
"... | // View executes a function creating and managing a read-only transaction for the user. Error
// returned by the function is relayed by the View method.
// If View is used with managed transactions, it would assume a read timestamp of MaxUint64. | [
"View",
"executes",
"a",
"function",
"creating",
"and",
"managing",
"a",
"read",
"-",
"only",
"transaction",
"for",
"the",
"user",
".",
"Error",
"returned",
"by",
"the",
"function",
"is",
"relayed",
"by",
"the",
"View",
"method",
".",
"If",
"View",
"is",
... | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/txn.go#L726-L736 | test |
dgraph-io/badger | txn.go | Update | func (db *DB) Update(fn func(txn *Txn) error) error {
if db.opt.managedTxns {
panic("Update can only be used with managedDB=false.")
}
txn := db.NewTransaction(true)
defer txn.Discard()
if err := fn(txn); err != nil {
return err
}
return txn.Commit()
} | go | func (db *DB) Update(fn func(txn *Txn) error) error {
if db.opt.managedTxns {
panic("Update can only be used with managedDB=false.")
}
txn := db.NewTransaction(true)
defer txn.Discard()
if err := fn(txn); err != nil {
return err
}
return txn.Commit()
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Update",
"(",
"fn",
"func",
"(",
"txn",
"*",
"Txn",
")",
"error",
")",
"error",
"{",
"if",
"db",
".",
"opt",
".",
"managedTxns",
"{",
"panic",
"(",
"\"Update can only be used with managedDB=false.\"",
")",
"\n",
"}",
... | // Update executes a function, creating and managing a read-write transaction
// for the user. Error returned by the function is relayed by the Update method.
// Update cannot be used with managed transactions. | [
"Update",
"executes",
"a",
"function",
"creating",
"and",
"managing",
"a",
"read",
"-",
"write",
"transaction",
"for",
"the",
"user",
".",
"Error",
"returned",
"by",
"the",
"function",
"is",
"relayed",
"by",
"the",
"Update",
"method",
".",
"Update",
"cannot"... | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/txn.go#L741-L753 | test |
dgraph-io/badger | table/iterator.go | Seek | func (itr *blockIterator) Seek(key []byte, whence int) {
itr.err = nil
switch whence {
case origin:
itr.Reset()
case current:
}
var done bool
for itr.Init(); itr.Valid(); itr.Next() {
k := itr.Key()
if y.CompareKeys(k, key) >= 0 {
// We are done as k is >= key.
done = true
break
}
}
if !done... | go | func (itr *blockIterator) Seek(key []byte, whence int) {
itr.err = nil
switch whence {
case origin:
itr.Reset()
case current:
}
var done bool
for itr.Init(); itr.Valid(); itr.Next() {
k := itr.Key()
if y.CompareKeys(k, key) >= 0 {
// We are done as k is >= key.
done = true
break
}
}
if !done... | [
"func",
"(",
"itr",
"*",
"blockIterator",
")",
"Seek",
"(",
"key",
"[",
"]",
"byte",
",",
"whence",
"int",
")",
"{",
"itr",
".",
"err",
"=",
"nil",
"\n",
"switch",
"whence",
"{",
"case",
"origin",
":",
"itr",
".",
"Reset",
"(",
")",
"\n",
"case",... | // Seek brings us to the first block element that is >= input key. | [
"Seek",
"brings",
"us",
"to",
"the",
"first",
"block",
"element",
"that",
"is",
">",
"=",
"input",
"key",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/iterator.go#L74-L95 | test |
dgraph-io/badger | table/iterator.go | SeekToLast | func (itr *blockIterator) SeekToLast() {
itr.err = nil
for itr.Init(); itr.Valid(); itr.Next() {
}
itr.Prev()
} | go | func (itr *blockIterator) SeekToLast() {
itr.err = nil
for itr.Init(); itr.Valid(); itr.Next() {
}
itr.Prev()
} | [
"func",
"(",
"itr",
"*",
"blockIterator",
")",
"SeekToLast",
"(",
")",
"{",
"itr",
".",
"err",
"=",
"nil",
"\n",
"for",
"itr",
".",
"Init",
"(",
")",
";",
"itr",
".",
"Valid",
"(",
")",
";",
"itr",
".",
"Next",
"(",
")",
"{",
"}",
"\n",
"itr"... | // SeekToLast brings us to the last element. Valid should return true. | [
"SeekToLast",
"brings",
"us",
"to",
"the",
"last",
"element",
".",
"Valid",
"should",
"return",
"true",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/iterator.go#L103-L108 | test |
dgraph-io/badger | table/iterator.go | parseKV | func (itr *blockIterator) parseKV(h header) {
if cap(itr.key) < int(h.plen+h.klen) {
sz := int(h.plen) + int(h.klen) // Convert to int before adding to avoid uint16 overflow.
itr.key = make([]byte, 2*sz)
}
itr.key = itr.key[:h.plen+h.klen]
copy(itr.key, itr.baseKey[:h.plen])
copy(itr.key[h.plen:], itr.data[itr... | go | func (itr *blockIterator) parseKV(h header) {
if cap(itr.key) < int(h.plen+h.klen) {
sz := int(h.plen) + int(h.klen) // Convert to int before adding to avoid uint16 overflow.
itr.key = make([]byte, 2*sz)
}
itr.key = itr.key[:h.plen+h.klen]
copy(itr.key, itr.baseKey[:h.plen])
copy(itr.key[h.plen:], itr.data[itr... | [
"func",
"(",
"itr",
"*",
"blockIterator",
")",
"parseKV",
"(",
"h",
"header",
")",
"{",
"if",
"cap",
"(",
"itr",
".",
"key",
")",
"<",
"int",
"(",
"h",
".",
"plen",
"+",
"h",
".",
"klen",
")",
"{",
"sz",
":=",
"int",
"(",
"h",
".",
"plen",
... | // parseKV would allocate a new byte slice for key and for value. | [
"parseKV",
"would",
"allocate",
"a",
"new",
"byte",
"slice",
"for",
"key",
"and",
"for",
"value",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/iterator.go#L111-L128 | test |
dgraph-io/badger | table/iterator.go | NewIterator | func (t *Table) NewIterator(reversed bool) *Iterator {
t.IncrRef() // Important.
ti := &Iterator{t: t, reversed: reversed}
ti.next()
return ti
} | go | func (t *Table) NewIterator(reversed bool) *Iterator {
t.IncrRef() // Important.
ti := &Iterator{t: t, reversed: reversed}
ti.next()
return ti
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"NewIterator",
"(",
"reversed",
"bool",
")",
"*",
"Iterator",
"{",
"t",
".",
"IncrRef",
"(",
")",
"\n",
"ti",
":=",
"&",
"Iterator",
"{",
"t",
":",
"t",
",",
"reversed",
":",
"reversed",
"}",
"\n",
"ti",
".",
... | // NewIterator returns a new iterator of the Table | [
"NewIterator",
"returns",
"a",
"new",
"iterator",
"of",
"the",
"Table"
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/iterator.go#L206-L211 | test |
dgraph-io/badger | table/iterator.go | seekFrom | func (itr *Iterator) seekFrom(key []byte, whence int) {
itr.err = nil
switch whence {
case origin:
itr.reset()
case current:
}
idx := sort.Search(len(itr.t.blockIndex), func(idx int) bool {
ko := itr.t.blockIndex[idx]
return y.CompareKeys(ko.key, key) > 0
})
if idx == 0 {
// The smallest key in our tab... | go | func (itr *Iterator) seekFrom(key []byte, whence int) {
itr.err = nil
switch whence {
case origin:
itr.reset()
case current:
}
idx := sort.Search(len(itr.t.blockIndex), func(idx int) bool {
ko := itr.t.blockIndex[idx]
return y.CompareKeys(ko.key, key) > 0
})
if idx == 0 {
// The smallest key in our tab... | [
"func",
"(",
"itr",
"*",
"Iterator",
")",
"seekFrom",
"(",
"key",
"[",
"]",
"byte",
",",
"whence",
"int",
")",
"{",
"itr",
".",
"err",
"=",
"nil",
"\n",
"switch",
"whence",
"{",
"case",
"origin",
":",
"itr",
".",
"reset",
"(",
")",
"\n",
"case",
... | // seekFrom brings us to a key that is >= input key. | [
"seekFrom",
"brings",
"us",
"to",
"a",
"key",
"that",
"is",
">",
"=",
"input",
"key",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/iterator.go#L275-L312 | test |
dgraph-io/badger | table/iterator.go | seekForPrev | func (itr *Iterator) seekForPrev(key []byte) {
// TODO: Optimize this. We shouldn't have to take a Prev step.
itr.seekFrom(key, origin)
if !bytes.Equal(itr.Key(), key) {
itr.prev()
}
} | go | func (itr *Iterator) seekForPrev(key []byte) {
// TODO: Optimize this. We shouldn't have to take a Prev step.
itr.seekFrom(key, origin)
if !bytes.Equal(itr.Key(), key) {
itr.prev()
}
} | [
"func",
"(",
"itr",
"*",
"Iterator",
")",
"seekForPrev",
"(",
"key",
"[",
"]",
"byte",
")",
"{",
"itr",
".",
"seekFrom",
"(",
"key",
",",
"origin",
")",
"\n",
"if",
"!",
"bytes",
".",
"Equal",
"(",
"itr",
".",
"Key",
"(",
")",
",",
"key",
")",
... | // seekForPrev will reset iterator and seek to <= key. | [
"seekForPrev",
"will",
"reset",
"iterator",
"and",
"seek",
"to",
"<",
"=",
"key",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/iterator.go#L320-L326 | test |
dgraph-io/badger | table/iterator.go | Value | func (itr *Iterator) Value() (ret y.ValueStruct) {
ret.Decode(itr.bi.Value())
return
} | go | func (itr *Iterator) Value() (ret y.ValueStruct) {
ret.Decode(itr.bi.Value())
return
} | [
"func",
"(",
"itr",
"*",
"Iterator",
")",
"Value",
"(",
")",
"(",
"ret",
"y",
".",
"ValueStruct",
")",
"{",
"ret",
".",
"Decode",
"(",
"itr",
".",
"bi",
".",
"Value",
"(",
")",
")",
"\n",
"return",
"\n",
"}"
] | // Value follows the y.Iterator interface | [
"Value",
"follows",
"the",
"y",
".",
"Iterator",
"interface"
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/iterator.go#L391-L394 | test |
dgraph-io/badger | table/iterator.go | Seek | func (itr *Iterator) Seek(key []byte) {
if !itr.reversed {
itr.seek(key)
} else {
itr.seekForPrev(key)
}
} | go | func (itr *Iterator) Seek(key []byte) {
if !itr.reversed {
itr.seek(key)
} else {
itr.seekForPrev(key)
}
} | [
"func",
"(",
"itr",
"*",
"Iterator",
")",
"Seek",
"(",
"key",
"[",
"]",
"byte",
")",
"{",
"if",
"!",
"itr",
".",
"reversed",
"{",
"itr",
".",
"seek",
"(",
"key",
")",
"\n",
"}",
"else",
"{",
"itr",
".",
"seekForPrev",
"(",
"key",
")",
"\n",
"... | // Seek follows the y.Iterator interface | [
"Seek",
"follows",
"the",
"y",
".",
"Iterator",
"interface"
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/iterator.go#L415-L421 | test |
dgraph-io/badger | table/iterator.go | NewConcatIterator | func NewConcatIterator(tbls []*Table, reversed bool) *ConcatIterator {
iters := make([]*Iterator, len(tbls))
for i := 0; i < len(tbls); i++ {
iters[i] = tbls[i].NewIterator(reversed)
}
return &ConcatIterator{
reversed: reversed,
iters: iters,
tables: tbls,
idx: -1, // Not really necessary becaus... | go | func NewConcatIterator(tbls []*Table, reversed bool) *ConcatIterator {
iters := make([]*Iterator, len(tbls))
for i := 0; i < len(tbls); i++ {
iters[i] = tbls[i].NewIterator(reversed)
}
return &ConcatIterator{
reversed: reversed,
iters: iters,
tables: tbls,
idx: -1, // Not really necessary becaus... | [
"func",
"NewConcatIterator",
"(",
"tbls",
"[",
"]",
"*",
"Table",
",",
"reversed",
"bool",
")",
"*",
"ConcatIterator",
"{",
"iters",
":=",
"make",
"(",
"[",
"]",
"*",
"Iterator",
",",
"len",
"(",
"tbls",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
... | // NewConcatIterator creates a new concatenated iterator | [
"NewConcatIterator",
"creates",
"a",
"new",
"concatenated",
"iterator"
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/iterator.go#L434-L445 | test |
dgraph-io/badger | table/iterator.go | Valid | func (s *ConcatIterator) Valid() bool {
return s.cur != nil && s.cur.Valid()
} | go | func (s *ConcatIterator) Valid() bool {
return s.cur != nil && s.cur.Valid()
} | [
"func",
"(",
"s",
"*",
"ConcatIterator",
")",
"Valid",
"(",
")",
"bool",
"{",
"return",
"s",
".",
"cur",
"!=",
"nil",
"&&",
"s",
".",
"cur",
".",
"Valid",
"(",
")",
"\n",
"}"
] | // Valid implements y.Interface | [
"Valid",
"implements",
"y",
".",
"Interface"
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/iterator.go#L470-L472 | test |
dgraph-io/badger | table/iterator.go | Next | func (s *ConcatIterator) Next() {
s.cur.Next()
if s.cur.Valid() {
// Nothing to do. Just stay with the current table.
return
}
for { // In case there are empty tables.
if !s.reversed {
s.setIdx(s.idx + 1)
} else {
s.setIdx(s.idx - 1)
}
if s.cur == nil {
// End of list. Valid will become false.
... | go | func (s *ConcatIterator) Next() {
s.cur.Next()
if s.cur.Valid() {
// Nothing to do. Just stay with the current table.
return
}
for { // In case there are empty tables.
if !s.reversed {
s.setIdx(s.idx + 1)
} else {
s.setIdx(s.idx - 1)
}
if s.cur == nil {
// End of list. Valid will become false.
... | [
"func",
"(",
"s",
"*",
"ConcatIterator",
")",
"Next",
"(",
")",
"{",
"s",
".",
"cur",
".",
"Next",
"(",
")",
"\n",
"if",
"s",
".",
"cur",
".",
"Valid",
"(",
")",
"{",
"return",
"\n",
"}",
"\n",
"for",
"{",
"if",
"!",
"s",
".",
"reversed",
"... | // Next advances our concat iterator. | [
"Next",
"advances",
"our",
"concat",
"iterator",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/iterator.go#L508-L529 | test |
dgraph-io/badger | table/iterator.go | Close | func (s *ConcatIterator) Close() error {
for _, it := range s.iters {
if err := it.Close(); err != nil {
return errors.Wrap(err, "ConcatIterator")
}
}
return nil
} | go | func (s *ConcatIterator) Close() error {
for _, it := range s.iters {
if err := it.Close(); err != nil {
return errors.Wrap(err, "ConcatIterator")
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"ConcatIterator",
")",
"Close",
"(",
")",
"error",
"{",
"for",
"_",
",",
"it",
":=",
"range",
"s",
".",
"iters",
"{",
"if",
"err",
":=",
"it",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",... | // Close implements y.Interface. | [
"Close",
"implements",
"y",
".",
"Interface",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/iterator.go#L532-L539 | test |
dgraph-io/badger | y/y.go | OpenExistingFile | func OpenExistingFile(filename string, flags uint32) (*os.File, error) {
openFlags := os.O_RDWR
if flags&ReadOnly != 0 {
openFlags = os.O_RDONLY
}
if flags&Sync != 0 {
openFlags |= datasyncFileFlag
}
return os.OpenFile(filename, openFlags, 0)
} | go | func OpenExistingFile(filename string, flags uint32) (*os.File, error) {
openFlags := os.O_RDWR
if flags&ReadOnly != 0 {
openFlags = os.O_RDONLY
}
if flags&Sync != 0 {
openFlags |= datasyncFileFlag
}
return os.OpenFile(filename, openFlags, 0)
} | [
"func",
"OpenExistingFile",
"(",
"filename",
"string",
",",
"flags",
"uint32",
")",
"(",
"*",
"os",
".",
"File",
",",
"error",
")",
"{",
"openFlags",
":=",
"os",
".",
"O_RDWR",
"\n",
"if",
"flags",
"&",
"ReadOnly",
"!=",
"0",
"{",
"openFlags",
"=",
"... | // OpenExistingFile opens an existing file, errors if it doesn't exist. | [
"OpenExistingFile",
"opens",
"an",
"existing",
"file",
"errors",
"if",
"it",
"doesn",
"t",
"exist",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/y.go#L57-L67 | test |
dgraph-io/badger | y/y.go | Copy | func Copy(a []byte) []byte {
b := make([]byte, len(a))
copy(b, a)
return b
} | go | func Copy(a []byte) []byte {
b := make([]byte, len(a))
copy(b, a)
return b
} | [
"func",
"Copy",
"(",
"a",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"a",
")",
")",
"\n",
"copy",
"(",
"b",
",",
"a",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Copy copies a byte slice and returns the copied slice. | [
"Copy",
"copies",
"a",
"byte",
"slice",
"and",
"returns",
"the",
"copied",
"slice",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/y.go#L102-L106 | test |
dgraph-io/badger | y/y.go | KeyWithTs | func KeyWithTs(key []byte, ts uint64) []byte {
out := make([]byte, len(key)+8)
copy(out, key)
binary.BigEndian.PutUint64(out[len(key):], math.MaxUint64-ts)
return out
} | go | func KeyWithTs(key []byte, ts uint64) []byte {
out := make([]byte, len(key)+8)
copy(out, key)
binary.BigEndian.PutUint64(out[len(key):], math.MaxUint64-ts)
return out
} | [
"func",
"KeyWithTs",
"(",
"key",
"[",
"]",
"byte",
",",
"ts",
"uint64",
")",
"[",
"]",
"byte",
"{",
"out",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"key",
")",
"+",
"8",
")",
"\n",
"copy",
"(",
"out",
",",
"key",
")",
"\n",
"bi... | // KeyWithTs generates a new key by appending ts to key. | [
"KeyWithTs",
"generates",
"a",
"new",
"key",
"by",
"appending",
"ts",
"to",
"key",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/y.go#L109-L114 | test |
dgraph-io/badger | y/y.go | ParseTs | func ParseTs(key []byte) uint64 {
if len(key) <= 8 {
return 0
}
return math.MaxUint64 - binary.BigEndian.Uint64(key[len(key)-8:])
} | go | func ParseTs(key []byte) uint64 {
if len(key) <= 8 {
return 0
}
return math.MaxUint64 - binary.BigEndian.Uint64(key[len(key)-8:])
} | [
"func",
"ParseTs",
"(",
"key",
"[",
"]",
"byte",
")",
"uint64",
"{",
"if",
"len",
"(",
"key",
")",
"<=",
"8",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"math",
".",
"MaxUint64",
"-",
"binary",
".",
"BigEndian",
".",
"Uint64",
"(",
"key",
"["... | // ParseTs parses the timestamp from the key bytes. | [
"ParseTs",
"parses",
"the",
"timestamp",
"from",
"the",
"key",
"bytes",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/y.go#L117-L122 | test |
dgraph-io/badger | y/y.go | ParseKey | func ParseKey(key []byte) []byte {
if key == nil {
return nil
}
AssertTrue(len(key) > 8)
return key[:len(key)-8]
} | go | func ParseKey(key []byte) []byte {
if key == nil {
return nil
}
AssertTrue(len(key) > 8)
return key[:len(key)-8]
} | [
"func",
"ParseKey",
"(",
"key",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"if",
"key",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"AssertTrue",
"(",
"len",
"(",
"key",
")",
">",
"8",
")",
"\n",
"return",
"key",
"[",
":",
"len",
"... | // ParseKey parses the actual key from the key bytes. | [
"ParseKey",
"parses",
"the",
"actual",
"key",
"from",
"the",
"key",
"bytes",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/y.go#L137-L144 | test |
dgraph-io/badger | y/y.go | SameKey | func SameKey(src, dst []byte) bool {
if len(src) != len(dst) {
return false
}
return bytes.Equal(ParseKey(src), ParseKey(dst))
} | go | func SameKey(src, dst []byte) bool {
if len(src) != len(dst) {
return false
}
return bytes.Equal(ParseKey(src), ParseKey(dst))
} | [
"func",
"SameKey",
"(",
"src",
",",
"dst",
"[",
"]",
"byte",
")",
"bool",
"{",
"if",
"len",
"(",
"src",
")",
"!=",
"len",
"(",
"dst",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"bytes",
".",
"Equal",
"(",
"ParseKey",
"(",
"src",
")... | // SameKey checks for key equality ignoring the version timestamp suffix. | [
"SameKey",
"checks",
"for",
"key",
"equality",
"ignoring",
"the",
"version",
"timestamp",
"suffix",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/y.go#L147-L152 | test |
dgraph-io/badger | y/y.go | FixedDuration | func FixedDuration(d time.Duration) string {
str := fmt.Sprintf("%02ds", int(d.Seconds())%60)
if d >= time.Minute {
str = fmt.Sprintf("%02dm", int(d.Minutes())%60) + str
}
if d >= time.Hour {
str = fmt.Sprintf("%02dh", int(d.Hours())) + str
}
return str
} | go | func FixedDuration(d time.Duration) string {
str := fmt.Sprintf("%02ds", int(d.Seconds())%60)
if d >= time.Minute {
str = fmt.Sprintf("%02dm", int(d.Minutes())%60) + str
}
if d >= time.Hour {
str = fmt.Sprintf("%02dh", int(d.Hours())) + str
}
return str
} | [
"func",
"FixedDuration",
"(",
"d",
"time",
".",
"Duration",
")",
"string",
"{",
"str",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"%02ds\"",
",",
"int",
"(",
"d",
".",
"Seconds",
"(",
")",
")",
"%",
"60",
")",
"\n",
"if",
"d",
">=",
"time",
".",
"Minute... | // FixedDuration returns a string representation of the given duration with the
// hours, minutes, and seconds. | [
"FixedDuration",
"returns",
"a",
"string",
"representation",
"of",
"the",
"given",
"duration",
"with",
"the",
"hours",
"minutes",
"and",
"seconds",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/y.go#L171-L180 | test |
dgraph-io/badger | y/y.go | NewCloser | func NewCloser(initial int) *Closer {
ret := &Closer{closed: make(chan struct{})}
ret.waiting.Add(initial)
return ret
} | go | func NewCloser(initial int) *Closer {
ret := &Closer{closed: make(chan struct{})}
ret.waiting.Add(initial)
return ret
} | [
"func",
"NewCloser",
"(",
"initial",
"int",
")",
"*",
"Closer",
"{",
"ret",
":=",
"&",
"Closer",
"{",
"closed",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"}",
"\n",
"ret",
".",
"waiting",
".",
"Add",
"(",
"initial",
")",
"\n",
"return",
... | // NewCloser constructs a new Closer, with an initial count on the WaitGroup. | [
"NewCloser",
"constructs",
"a",
"new",
"Closer",
"with",
"an",
"initial",
"count",
"on",
"the",
"WaitGroup",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/y.go#L191-L195 | test |
dgraph-io/badger | y/y.go | NewThrottle | func NewThrottle(max int) *Throttle {
return &Throttle{
ch: make(chan struct{}, max),
errCh: make(chan error, max),
}
} | go | func NewThrottle(max int) *Throttle {
return &Throttle{
ch: make(chan struct{}, max),
errCh: make(chan error, max),
}
} | [
"func",
"NewThrottle",
"(",
"max",
"int",
")",
"*",
"Throttle",
"{",
"return",
"&",
"Throttle",
"{",
"ch",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
",",
"max",
")",
",",
"errCh",
":",
"make",
"(",
"chan",
"error",
",",
"max",
")",
",",
"}",
... | // NewThrottle creates a new throttle with a max number of workers. | [
"NewThrottle",
"creates",
"a",
"new",
"throttle",
"with",
"a",
"max",
"number",
"of",
"workers",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/y.go#L245-L250 | test |
dgraph-io/badger | y/y.go | Do | func (t *Throttle) Do() error {
for {
select {
case t.ch <- struct{}{}:
t.wg.Add(1)
return nil
case err := <-t.errCh:
if err != nil {
return err
}
}
}
} | go | func (t *Throttle) Do() error {
for {
select {
case t.ch <- struct{}{}:
t.wg.Add(1)
return nil
case err := <-t.errCh:
if err != nil {
return err
}
}
}
} | [
"func",
"(",
"t",
"*",
"Throttle",
")",
"Do",
"(",
")",
"error",
"{",
"for",
"{",
"select",
"{",
"case",
"t",
".",
"ch",
"<-",
"struct",
"{",
"}",
"{",
"}",
":",
"t",
".",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"return",
"nil",
"\n",
"case"... | // Do should be called by workers before they start working. It blocks if there
// are already maximum number of workers working. If it detects an error from
// previously Done workers, it would return it. | [
"Do",
"should",
"be",
"called",
"by",
"workers",
"before",
"they",
"start",
"working",
".",
"It",
"blocks",
"if",
"there",
"are",
"already",
"maximum",
"number",
"of",
"workers",
"working",
".",
"If",
"it",
"detects",
"an",
"error",
"from",
"previously",
"... | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/y.go#L255-L267 | test |
dgraph-io/badger | y/y.go | Done | func (t *Throttle) Done(err error) {
if err != nil {
t.errCh <- err
}
select {
case <-t.ch:
default:
panic("Throttle Do Done mismatch")
}
t.wg.Done()
} | go | func (t *Throttle) Done(err error) {
if err != nil {
t.errCh <- err
}
select {
case <-t.ch:
default:
panic("Throttle Do Done mismatch")
}
t.wg.Done()
} | [
"func",
"(",
"t",
"*",
"Throttle",
")",
"Done",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"t",
".",
"errCh",
"<-",
"err",
"\n",
"}",
"\n",
"select",
"{",
"case",
"<-",
"t",
".",
"ch",
":",
"default",
":",
"panic",
"(",
"\"... | // Done should be called by workers when they finish working. They can also
// pass the error status of work done. | [
"Done",
"should",
"be",
"called",
"by",
"workers",
"when",
"they",
"finish",
"working",
".",
"They",
"can",
"also",
"pass",
"the",
"error",
"status",
"of",
"work",
"done",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/y.go#L271-L281 | test |
dgraph-io/badger | y/y.go | Finish | func (t *Throttle) Finish() error {
t.wg.Wait()
close(t.ch)
close(t.errCh)
for err := range t.errCh {
if err != nil {
return err
}
}
return nil
} | go | func (t *Throttle) Finish() error {
t.wg.Wait()
close(t.ch)
close(t.errCh)
for err := range t.errCh {
if err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"t",
"*",
"Throttle",
")",
"Finish",
"(",
")",
"error",
"{",
"t",
".",
"wg",
".",
"Wait",
"(",
")",
"\n",
"close",
"(",
"t",
".",
"ch",
")",
"\n",
"close",
"(",
"t",
".",
"errCh",
")",
"\n",
"for",
"err",
":=",
"range",
"t",
".... | // Finish waits until all workers have finished working. It would return any
// error passed by Done. | [
"Finish",
"waits",
"until",
"all",
"workers",
"have",
"finished",
"working",
".",
"It",
"would",
"return",
"any",
"error",
"passed",
"by",
"Done",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/y.go#L285-L295 | test |
dgraph-io/badger | managed_db.go | SetDiscardTs | func (db *DB) SetDiscardTs(ts uint64) {
if !db.opt.managedTxns {
panic("Cannot use SetDiscardTs with managedDB=false.")
}
db.orc.setDiscardTs(ts)
} | go | func (db *DB) SetDiscardTs(ts uint64) {
if !db.opt.managedTxns {
panic("Cannot use SetDiscardTs with managedDB=false.")
}
db.orc.setDiscardTs(ts)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"SetDiscardTs",
"(",
"ts",
"uint64",
")",
"{",
"if",
"!",
"db",
".",
"opt",
".",
"managedTxns",
"{",
"panic",
"(",
"\"Cannot use SetDiscardTs with managedDB=false.\"",
")",
"\n",
"}",
"\n",
"db",
".",
"orc",
".",
"setDi... | // SetDiscardTs sets a timestamp at or below which, any invalid or deleted
// versions can be discarded from the LSM tree, and thence from the value log to
// reclaim disk space. Can only be used with managed transactions. | [
"SetDiscardTs",
"sets",
"a",
"timestamp",
"at",
"or",
"below",
"which",
"any",
"invalid",
"or",
"deleted",
"versions",
"can",
"be",
"discarded",
"from",
"the",
"LSM",
"tree",
"and",
"thence",
"from",
"the",
"value",
"log",
"to",
"reclaim",
"disk",
"space",
... | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/managed_db.go#L63-L68 | test |
dgraph-io/badger | value.go | openReadOnly | func (lf *logFile) openReadOnly() error {
var err error
lf.fd, err = os.OpenFile(lf.path, os.O_RDONLY, 0666)
if err != nil {
return errors.Wrapf(err, "Unable to open %q as RDONLY.", lf.path)
}
fi, err := lf.fd.Stat()
if err != nil {
return errors.Wrapf(err, "Unable to check stat for %q", lf.path)
}
y.Asser... | go | func (lf *logFile) openReadOnly() error {
var err error
lf.fd, err = os.OpenFile(lf.path, os.O_RDONLY, 0666)
if err != nil {
return errors.Wrapf(err, "Unable to open %q as RDONLY.", lf.path)
}
fi, err := lf.fd.Stat()
if err != nil {
return errors.Wrapf(err, "Unable to check stat for %q", lf.path)
}
y.Asser... | [
"func",
"(",
"lf",
"*",
"logFile",
")",
"openReadOnly",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"lf",
".",
"fd",
",",
"err",
"=",
"os",
".",
"OpenFile",
"(",
"lf",
".",
"path",
",",
"os",
".",
"O_RDONLY",
",",
"0666",
")",
"\n",
"i... | // openReadOnly assumes that we have a write lock on logFile. | [
"openReadOnly",
"assumes",
"that",
"we",
"have",
"a",
"write",
"lock",
"on",
"logFile",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/value.go#L74-L94 | test |
dgraph-io/badger | value.go | iterate | func (vlog *valueLog) iterate(lf *logFile, offset uint32, fn logEntry) (uint32, error) {
fi, err := lf.fd.Stat()
if err != nil {
return 0, err
}
if int64(offset) == fi.Size() {
// We're at the end of the file already. No need to do anything.
return offset, nil
}
if vlog.opt.ReadOnly {
// We're not at the ... | go | func (vlog *valueLog) iterate(lf *logFile, offset uint32, fn logEntry) (uint32, error) {
fi, err := lf.fd.Stat()
if err != nil {
return 0, err
}
if int64(offset) == fi.Size() {
// We're at the end of the file already. No need to do anything.
return offset, nil
}
if vlog.opt.ReadOnly {
// We're not at the ... | [
"func",
"(",
"vlog",
"*",
"valueLog",
")",
"iterate",
"(",
"lf",
"*",
"logFile",
",",
"offset",
"uint32",
",",
"fn",
"logEntry",
")",
"(",
"uint32",
",",
"error",
")",
"{",
"fi",
",",
"err",
":=",
"lf",
".",
"fd",
".",
"Stat",
"(",
")",
"\n",
"... | // iterate iterates over log file. It doesn't not allocate new memory for every kv pair.
// Therefore, the kv pair is only valid for the duration of fn call. | [
"iterate",
"iterates",
"over",
"log",
"file",
".",
"It",
"doesn",
"t",
"not",
"allocate",
"new",
"memory",
"for",
"every",
"kv",
"pair",
".",
"Therefore",
"the",
"kv",
"pair",
"is",
"only",
"valid",
"for",
"the",
"duration",
"of",
"fn",
"call",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/value.go#L253-L336 | test |
dgraph-io/badger | value.go | sortedFids | func (vlog *valueLog) sortedFids() []uint32 {
toBeDeleted := make(map[uint32]struct{})
for _, fid := range vlog.filesToBeDeleted {
toBeDeleted[fid] = struct{}{}
}
ret := make([]uint32, 0, len(vlog.filesMap))
for fid := range vlog.filesMap {
if _, ok := toBeDeleted[fid]; !ok {
ret = append(ret, fid)
}
}
... | go | func (vlog *valueLog) sortedFids() []uint32 {
toBeDeleted := make(map[uint32]struct{})
for _, fid := range vlog.filesToBeDeleted {
toBeDeleted[fid] = struct{}{}
}
ret := make([]uint32, 0, len(vlog.filesMap))
for fid := range vlog.filesMap {
if _, ok := toBeDeleted[fid]; !ok {
ret = append(ret, fid)
}
}
... | [
"func",
"(",
"vlog",
"*",
"valueLog",
")",
"sortedFids",
"(",
")",
"[",
"]",
"uint32",
"{",
"toBeDeleted",
":=",
"make",
"(",
"map",
"[",
"uint32",
"]",
"struct",
"{",
"}",
")",
"\n",
"for",
"_",
",",
"fid",
":=",
"range",
"vlog",
".",
"filesToBeDe... | // sortedFids returns the file id's not pending deletion, sorted. Assumes we have shared access to
// filesMap. | [
"sortedFids",
"returns",
"the",
"file",
"id",
"s",
"not",
"pending",
"deletion",
"sorted",
".",
"Assumes",
"we",
"have",
"shared",
"access",
"to",
"filesMap",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/value.go#L863-L878 | test |
dgraph-io/badger | value.go | write | func (vlog *valueLog) write(reqs []*request) error {
vlog.filesLock.RLock()
maxFid := atomic.LoadUint32(&vlog.maxFid)
curlf := vlog.filesMap[maxFid]
vlog.filesLock.RUnlock()
var buf bytes.Buffer
toDisk := func() error {
if buf.Len() == 0 {
return nil
}
vlog.elog.Printf("Flushing %d blocks of total size:... | go | func (vlog *valueLog) write(reqs []*request) error {
vlog.filesLock.RLock()
maxFid := atomic.LoadUint32(&vlog.maxFid)
curlf := vlog.filesMap[maxFid]
vlog.filesLock.RUnlock()
var buf bytes.Buffer
toDisk := func() error {
if buf.Len() == 0 {
return nil
}
vlog.elog.Printf("Flushing %d blocks of total size:... | [
"func",
"(",
"vlog",
"*",
"valueLog",
")",
"write",
"(",
"reqs",
"[",
"]",
"*",
"request",
")",
"error",
"{",
"vlog",
".",
"filesLock",
".",
"RLock",
"(",
")",
"\n",
"maxFid",
":=",
"atomic",
".",
"LoadUint32",
"(",
"&",
"vlog",
".",
"maxFid",
")",... | // write is thread-unsafe by design and should not be called concurrently. | [
"write",
"is",
"thread",
"-",
"unsafe",
"by",
"design",
"and",
"should",
"not",
"be",
"called",
"concurrently",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/value.go#L936-L1006 | test |
dgraph-io/badger | value.go | populateDiscardStats | func (vlog *valueLog) populateDiscardStats() error {
discardStatsKey := y.KeyWithTs(lfDiscardStatsKey, math.MaxUint64)
vs, err := vlog.db.get(discardStatsKey)
if err != nil {
return err
}
// check if value is Empty
if vs.Value == nil || len(vs.Value) == 0 {
vlog.lfDiscardStats = &lfDiscardStats{m: make(map[u... | go | func (vlog *valueLog) populateDiscardStats() error {
discardStatsKey := y.KeyWithTs(lfDiscardStatsKey, math.MaxUint64)
vs, err := vlog.db.get(discardStatsKey)
if err != nil {
return err
}
// check if value is Empty
if vs.Value == nil || len(vs.Value) == 0 {
vlog.lfDiscardStats = &lfDiscardStats{m: make(map[u... | [
"func",
"(",
"vlog",
"*",
"valueLog",
")",
"populateDiscardStats",
"(",
")",
"error",
"{",
"discardStatsKey",
":=",
"y",
".",
"KeyWithTs",
"(",
"lfDiscardStatsKey",
",",
"math",
".",
"MaxUint64",
")",
"\n",
"vs",
",",
"err",
":=",
"vlog",
".",
"db",
".",... | // populateDiscardStats populates vlog.lfDiscardStats
// This function will be called while initializing valueLog | [
"populateDiscardStats",
"populates",
"vlog",
".",
"lfDiscardStats",
"This",
"function",
"will",
"be",
"called",
"while",
"initializing",
"valueLog"
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/value.go#L1343-L1363 | test |
dgraph-io/badger | backup.go | Backup | func (db *DB) Backup(w io.Writer, since uint64) (uint64, error) {
stream := db.NewStream()
stream.LogPrefix = "DB.Backup"
return stream.Backup(w, since)
} | go | func (db *DB) Backup(w io.Writer, since uint64) (uint64, error) {
stream := db.NewStream()
stream.LogPrefix = "DB.Backup"
return stream.Backup(w, since)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Backup",
"(",
"w",
"io",
".",
"Writer",
",",
"since",
"uint64",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"stream",
":=",
"db",
".",
"NewStream",
"(",
")",
"\n",
"stream",
".",
"LogPrefix",
"=",
"\"DB.Backup\""... | // Backup is a wrapper function over Stream.Backup to generate full and incremental backups of the
// DB. For more control over how many goroutines are used to generate the backup, or if you wish to
// backup only a certain range of keys, use Stream.Backup directly. | [
"Backup",
"is",
"a",
"wrapper",
"function",
"over",
"Stream",
".",
"Backup",
"to",
"generate",
"full",
"and",
"incremental",
"backups",
"of",
"the",
"DB",
".",
"For",
"more",
"control",
"over",
"how",
"many",
"goroutines",
"are",
"used",
"to",
"generate",
... | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/backup.go#L34-L38 | test |
dgraph-io/badger | stream.go | ToList | func (st *Stream) ToList(key []byte, itr *Iterator) (*pb.KVList, error) {
list := &pb.KVList{}
for ; itr.Valid(); itr.Next() {
item := itr.Item()
if item.IsDeletedOrExpired() {
break
}
if !bytes.Equal(key, item.Key()) {
// Break out on the first encounter with another key.
break
}
valCopy, err :... | go | func (st *Stream) ToList(key []byte, itr *Iterator) (*pb.KVList, error) {
list := &pb.KVList{}
for ; itr.Valid(); itr.Next() {
item := itr.Item()
if item.IsDeletedOrExpired() {
break
}
if !bytes.Equal(key, item.Key()) {
// Break out on the first encounter with another key.
break
}
valCopy, err :... | [
"func",
"(",
"st",
"*",
"Stream",
")",
"ToList",
"(",
"key",
"[",
"]",
"byte",
",",
"itr",
"*",
"Iterator",
")",
"(",
"*",
"pb",
".",
"KVList",
",",
"error",
")",
"{",
"list",
":=",
"&",
"pb",
".",
"KVList",
"{",
"}",
"\n",
"for",
";",
"itr",... | // ToList is a default implementation of KeyToList. It picks up all valid versions of the key,
// skipping over deleted or expired keys. | [
"ToList",
"is",
"a",
"default",
"implementation",
"of",
"KeyToList",
".",
"It",
"picks",
"up",
"all",
"valid",
"versions",
"of",
"the",
"key",
"skipping",
"over",
"deleted",
"or",
"expired",
"keys",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/stream.go#L77-L110 | test |
dgraph-io/badger | stream.go | produceRanges | func (st *Stream) produceRanges(ctx context.Context) {
splits := st.db.KeySplits(st.Prefix)
start := y.SafeCopy(nil, st.Prefix)
for _, key := range splits {
st.rangeCh <- keyRange{left: start, right: y.SafeCopy(nil, []byte(key))}
start = y.SafeCopy(nil, []byte(key))
}
// Edge case: prefix is empty and no split... | go | func (st *Stream) produceRanges(ctx context.Context) {
splits := st.db.KeySplits(st.Prefix)
start := y.SafeCopy(nil, st.Prefix)
for _, key := range splits {
st.rangeCh <- keyRange{left: start, right: y.SafeCopy(nil, []byte(key))}
start = y.SafeCopy(nil, []byte(key))
}
// Edge case: prefix is empty and no split... | [
"func",
"(",
"st",
"*",
"Stream",
")",
"produceRanges",
"(",
"ctx",
"context",
".",
"Context",
")",
"{",
"splits",
":=",
"st",
".",
"db",
".",
"KeySplits",
"(",
"st",
".",
"Prefix",
")",
"\n",
"start",
":=",
"y",
".",
"SafeCopy",
"(",
"nil",
",",
... | // keyRange is [start, end), including start, excluding end. Do ensure that the start,
// end byte slices are owned by keyRange struct. | [
"keyRange",
"is",
"[",
"start",
"end",
")",
"including",
"start",
"excluding",
"end",
".",
"Do",
"ensure",
"that",
"the",
"start",
"end",
"byte",
"slices",
"are",
"owned",
"by",
"keyRange",
"struct",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/stream.go#L114-L125 | test |
dgraph-io/badger | stream.go | produceKVs | func (st *Stream) produceKVs(ctx context.Context) error {
var size int
var txn *Txn
if st.readTs > 0 {
txn = st.db.NewTransactionAt(st.readTs, false)
} else {
txn = st.db.NewTransaction(false)
}
defer txn.Discard()
iterate := func(kr keyRange) error {
iterOpts := DefaultIteratorOptions
iterOpts.AllVersi... | go | func (st *Stream) produceKVs(ctx context.Context) error {
var size int
var txn *Txn
if st.readTs > 0 {
txn = st.db.NewTransactionAt(st.readTs, false)
} else {
txn = st.db.NewTransaction(false)
}
defer txn.Discard()
iterate := func(kr keyRange) error {
iterOpts := DefaultIteratorOptions
iterOpts.AllVersi... | [
"func",
"(",
"st",
"*",
"Stream",
")",
"produceKVs",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"var",
"size",
"int",
"\n",
"var",
"txn",
"*",
"Txn",
"\n",
"if",
"st",
".",
"readTs",
">",
"0",
"{",
"txn",
"=",
"st",
".",
"db",
".... | // produceKVs picks up ranges from rangeCh, generates KV lists and sends them to kvChan. | [
"produceKVs",
"picks",
"up",
"ranges",
"from",
"rangeCh",
"generates",
"KV",
"lists",
"and",
"sends",
"them",
"to",
"kvChan",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/stream.go#L128-L202 | test |
dgraph-io/badger | stream.go | Orchestrate | func (st *Stream) Orchestrate(ctx context.Context) error {
st.rangeCh = make(chan keyRange, 3) // Contains keys for posting lists.
// kvChan should only have a small capacity to ensure that we don't buffer up too much data if
// sending is slow. Page size is set to 4MB, which is used to lazily cap the size of each
... | go | func (st *Stream) Orchestrate(ctx context.Context) error {
st.rangeCh = make(chan keyRange, 3) // Contains keys for posting lists.
// kvChan should only have a small capacity to ensure that we don't buffer up too much data if
// sending is slow. Page size is set to 4MB, which is used to lazily cap the size of each
... | [
"func",
"(",
"st",
"*",
"Stream",
")",
"Orchestrate",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"st",
".",
"rangeCh",
"=",
"make",
"(",
"chan",
"keyRange",
",",
"3",
")",
"\n",
"st",
".",
"kvChan",
"=",
"make",
"(",
"chan",
"*",
"... | // Orchestrate runs Stream. It picks up ranges from the SSTables, then runs NumGo number of
// goroutines to iterate over these ranges and batch up KVs in lists. It concurrently runs a single
// goroutine to pick these lists, batch them up further and send to Output.Send. Orchestrate also
// spits logs out to Infof, us... | [
"Orchestrate",
"runs",
"Stream",
".",
"It",
"picks",
"up",
"ranges",
"from",
"the",
"SSTables",
"then",
"runs",
"NumGo",
"number",
"of",
"goroutines",
"to",
"iterate",
"over",
"these",
"ranges",
"and",
"batch",
"up",
"KVs",
"in",
"lists",
".",
"It",
"concu... | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/stream.go#L276-L325 | test |
dgraph-io/badger | stream.go | NewStream | func (db *DB) NewStream() *Stream {
if db.opt.managedTxns {
panic("This API can not be called in managed mode.")
}
return db.newStream()
} | go | func (db *DB) NewStream() *Stream {
if db.opt.managedTxns {
panic("This API can not be called in managed mode.")
}
return db.newStream()
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"NewStream",
"(",
")",
"*",
"Stream",
"{",
"if",
"db",
".",
"opt",
".",
"managedTxns",
"{",
"panic",
"(",
"\"This API can not be called in managed mode.\"",
")",
"\n",
"}",
"\n",
"return",
"db",
".",
"newStream",
"(",
"... | // NewStream creates a new Stream. | [
"NewStream",
"creates",
"a",
"new",
"Stream",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/stream.go#L332-L337 | test |
dgraph-io/badger | stream.go | NewStreamAt | func (db *DB) NewStreamAt(readTs uint64) *Stream {
if !db.opt.managedTxns {
panic("This API can only be called in managed mode.")
}
stream := db.newStream()
stream.readTs = readTs
return stream
} | go | func (db *DB) NewStreamAt(readTs uint64) *Stream {
if !db.opt.managedTxns {
panic("This API can only be called in managed mode.")
}
stream := db.newStream()
stream.readTs = readTs
return stream
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"NewStreamAt",
"(",
"readTs",
"uint64",
")",
"*",
"Stream",
"{",
"if",
"!",
"db",
".",
"opt",
".",
"managedTxns",
"{",
"panic",
"(",
"\"This API can only be called in managed mode.\"",
")",
"\n",
"}",
"\n",
"stream",
":="... | // NewStreamAt creates a new Stream at a particular timestamp. Should only be used with managed DB. | [
"NewStreamAt",
"creates",
"a",
"new",
"Stream",
"at",
"a",
"particular",
"timestamp",
".",
"Should",
"only",
"be",
"used",
"with",
"managed",
"DB",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/stream.go#L340-L347 | test |
dgraph-io/badger | table/table.go | DecrRef | func (t *Table) DecrRef() error {
newRef := atomic.AddInt32(&t.ref, -1)
if newRef == 0 {
// We can safely delete this file, because for all the current files, we always have
// at least one reference pointing to them.
// It's necessary to delete windows files
if t.loadingMode == options.MemoryMap {
y.Munm... | go | func (t *Table) DecrRef() error {
newRef := atomic.AddInt32(&t.ref, -1)
if newRef == 0 {
// We can safely delete this file, because for all the current files, we always have
// at least one reference pointing to them.
// It's necessary to delete windows files
if t.loadingMode == options.MemoryMap {
y.Munm... | [
"func",
"(",
"t",
"*",
"Table",
")",
"DecrRef",
"(",
")",
"error",
"{",
"newRef",
":=",
"atomic",
".",
"AddInt32",
"(",
"&",
"t",
".",
"ref",
",",
"-",
"1",
")",
"\n",
"if",
"newRef",
"==",
"0",
"{",
"if",
"t",
".",
"loadingMode",
"==",
"option... | // DecrRef decrements the refcount and possibly deletes the table | [
"DecrRef",
"decrements",
"the",
"refcount",
"and",
"possibly",
"deletes",
"the",
"table"
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/table.go#L82-L105 | test |
dgraph-io/badger | table/table.go | ParseFileID | func ParseFileID(name string) (uint64, bool) {
name = path.Base(name)
if !strings.HasSuffix(name, fileSuffix) {
return 0, false
}
// suffix := name[len(fileSuffix):]
name = strings.TrimSuffix(name, fileSuffix)
id, err := strconv.Atoi(name)
if err != nil {
return 0, false
}
y.AssertTrue(id >= 0)
return uin... | go | func ParseFileID(name string) (uint64, bool) {
name = path.Base(name)
if !strings.HasSuffix(name, fileSuffix) {
return 0, false
}
// suffix := name[len(fileSuffix):]
name = strings.TrimSuffix(name, fileSuffix)
id, err := strconv.Atoi(name)
if err != nil {
return 0, false
}
y.AssertTrue(id >= 0)
return uin... | [
"func",
"ParseFileID",
"(",
"name",
"string",
")",
"(",
"uint64",
",",
"bool",
")",
"{",
"name",
"=",
"path",
".",
"Base",
"(",
"name",
")",
"\n",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"name",
",",
"fileSuffix",
")",
"{",
"return",
"0",
",",... | // ParseFileID reads the file id out of a filename. | [
"ParseFileID",
"reads",
"the",
"file",
"id",
"out",
"of",
"a",
"filename",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/table.go#L315-L328 | test |
dgraph-io/badger | histogram.go | PrintHistogram | func (db *DB) PrintHistogram(keyPrefix []byte) {
if db == nil {
fmt.Println("\nCannot build histogram: DB is nil.")
return
}
histogram := db.buildHistogram(keyPrefix)
fmt.Printf("Histogram of key sizes (in bytes)\n")
histogram.keySizeHistogram.printHistogram()
fmt.Printf("Histogram of value sizes (in bytes)\n... | go | func (db *DB) PrintHistogram(keyPrefix []byte) {
if db == nil {
fmt.Println("\nCannot build histogram: DB is nil.")
return
}
histogram := db.buildHistogram(keyPrefix)
fmt.Printf("Histogram of key sizes (in bytes)\n")
histogram.keySizeHistogram.printHistogram()
fmt.Printf("Histogram of value sizes (in bytes)\n... | [
"func",
"(",
"db",
"*",
"DB",
")",
"PrintHistogram",
"(",
"keyPrefix",
"[",
"]",
"byte",
")",
"{",
"if",
"db",
"==",
"nil",
"{",
"fmt",
".",
"Println",
"(",
"\"\\nCannot build histogram: DB is nil.\"",
")",
"\n",
"\\n",
"\n",
"}",
"\n",
"return",
"\n",
... | // PrintHistogram builds and displays the key-value size histogram.
// When keyPrefix is set, only the keys that have prefix "keyPrefix" are
// considered for creating the histogram | [
"PrintHistogram",
"builds",
"and",
"displays",
"the",
"key",
"-",
"value",
"size",
"histogram",
".",
"When",
"keyPrefix",
"is",
"set",
"only",
"the",
"keys",
"that",
"have",
"prefix",
"keyPrefix",
"are",
"considered",
"for",
"creating",
"the",
"histogram"
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/histogram.go#L27-L37 | test |
dgraph-io/badger | histogram.go | newSizeHistogram | func newSizeHistogram() *sizeHistogram {
// TODO(ibrahim): find appropriate bin size.
keyBins := createHistogramBins(1, 16)
valueBins := createHistogramBins(1, 30)
return &sizeHistogram{
keySizeHistogram: histogramData{
bins: keyBins,
countPerBin: make([]int64, len(keyBins)+1),
max: math.M... | go | func newSizeHistogram() *sizeHistogram {
// TODO(ibrahim): find appropriate bin size.
keyBins := createHistogramBins(1, 16)
valueBins := createHistogramBins(1, 30)
return &sizeHistogram{
keySizeHistogram: histogramData{
bins: keyBins,
countPerBin: make([]int64, len(keyBins)+1),
max: math.M... | [
"func",
"newSizeHistogram",
"(",
")",
"*",
"sizeHistogram",
"{",
"keyBins",
":=",
"createHistogramBins",
"(",
"1",
",",
"16",
")",
"\n",
"valueBins",
":=",
"createHistogramBins",
"(",
"1",
",",
"30",
")",
"\n",
"return",
"&",
"sizeHistogram",
"{",
"keySizeHi... | // newSizeHistogram returns a new instance of keyValueSizeHistogram with
// properly initialized fields. | [
"newSizeHistogram",
"returns",
"a",
"new",
"instance",
"of",
"keyValueSizeHistogram",
"with",
"properly",
"initialized",
"fields",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/histogram.go#L56-L76 | test |
dgraph-io/badger | histogram.go | buildHistogram | func (db *DB) buildHistogram(keyPrefix []byte) *sizeHistogram {
txn := db.NewTransaction(false)
defer txn.Discard()
itr := txn.NewIterator(DefaultIteratorOptions)
defer itr.Close()
badgerHistogram := newSizeHistogram()
// Collect key and value sizes.
for itr.Seek(keyPrefix); itr.ValidForPrefix(keyPrefix); itr... | go | func (db *DB) buildHistogram(keyPrefix []byte) *sizeHistogram {
txn := db.NewTransaction(false)
defer txn.Discard()
itr := txn.NewIterator(DefaultIteratorOptions)
defer itr.Close()
badgerHistogram := newSizeHistogram()
// Collect key and value sizes.
for itr.Seek(keyPrefix); itr.ValidForPrefix(keyPrefix); itr... | [
"func",
"(",
"db",
"*",
"DB",
")",
"buildHistogram",
"(",
"keyPrefix",
"[",
"]",
"byte",
")",
"*",
"sizeHistogram",
"{",
"txn",
":=",
"db",
".",
"NewTransaction",
"(",
"false",
")",
"\n",
"defer",
"txn",
".",
"Discard",
"(",
")",
"\n",
"itr",
":=",
... | // buildHistogram builds the key-value size histogram.
// When keyPrefix is set, only the keys that have prefix "keyPrefix" are
// considered for creating the histogram | [
"buildHistogram",
"builds",
"the",
"key",
"-",
"value",
"size",
"histogram",
".",
"When",
"keyPrefix",
"is",
"set",
"only",
"the",
"keys",
"that",
"have",
"prefix",
"keyPrefix",
"are",
"considered",
"for",
"creating",
"the",
"histogram"
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/histogram.go#L119-L135 | test |
dgraph-io/badger | histogram.go | printHistogram | func (histogram histogramData) printHistogram() {
fmt.Printf("Total count: %d\n", histogram.totalCount)
fmt.Printf("Min value: %d\n", histogram.min)
fmt.Printf("Max value: %d\n", histogram.max)
fmt.Printf("Mean: %.2f\n", float64(histogram.sum)/float64(histogram.totalCount))
fmt.Printf("%24s %9s\n", "Range", "Count... | go | func (histogram histogramData) printHistogram() {
fmt.Printf("Total count: %d\n", histogram.totalCount)
fmt.Printf("Min value: %d\n", histogram.min)
fmt.Printf("Max value: %d\n", histogram.max)
fmt.Printf("Mean: %.2f\n", float64(histogram.sum)/float64(histogram.totalCount))
fmt.Printf("%24s %9s\n", "Range", "Count... | [
"func",
"(",
"histogram",
"histogramData",
")",
"printHistogram",
"(",
")",
"{",
"fmt",
".",
"Printf",
"(",
"\"Total count: %d\\n\"",
",",
"\\n",
")",
"\n",
"histogram",
".",
"totalCount",
"\n",
"fmt",
".",
"Printf",
"(",
"\"Min value: %d\\n\"",
",",
"\\n",
... | // printHistogram prints the histogram data in a human-readable format. | [
"printHistogram",
"prints",
"the",
"histogram",
"data",
"in",
"a",
"human",
"-",
"readable",
"format",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/histogram.go#L138-L169 | test |
dgraph-io/badger | y/watermark.go | Init | func (w *WaterMark) Init(closer *Closer) {
w.markCh = make(chan mark, 100)
w.elog = trace.NewEventLog("Watermark", w.Name)
go w.process(closer)
} | go | func (w *WaterMark) Init(closer *Closer) {
w.markCh = make(chan mark, 100)
w.elog = trace.NewEventLog("Watermark", w.Name)
go w.process(closer)
} | [
"func",
"(",
"w",
"*",
"WaterMark",
")",
"Init",
"(",
"closer",
"*",
"Closer",
")",
"{",
"w",
".",
"markCh",
"=",
"make",
"(",
"chan",
"mark",
",",
"100",
")",
"\n",
"w",
".",
"elog",
"=",
"trace",
".",
"NewEventLog",
"(",
"\"Watermark\"",
",",
"... | // Init initializes a WaterMark struct. MUST be called before using it. | [
"Init",
"initializes",
"a",
"WaterMark",
"struct",
".",
"MUST",
"be",
"called",
"before",
"using",
"it",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/watermark.go#L71-L75 | test |
dgraph-io/badger | y/watermark.go | Begin | func (w *WaterMark) Begin(index uint64) {
atomic.StoreUint64(&w.lastIndex, index)
w.markCh <- mark{index: index, done: false}
} | go | func (w *WaterMark) Begin(index uint64) {
atomic.StoreUint64(&w.lastIndex, index)
w.markCh <- mark{index: index, done: false}
} | [
"func",
"(",
"w",
"*",
"WaterMark",
")",
"Begin",
"(",
"index",
"uint64",
")",
"{",
"atomic",
".",
"StoreUint64",
"(",
"&",
"w",
".",
"lastIndex",
",",
"index",
")",
"\n",
"w",
".",
"markCh",
"<-",
"mark",
"{",
"index",
":",
"index",
",",
"done",
... | // Begin sets the last index to the given value. | [
"Begin",
"sets",
"the",
"last",
"index",
"to",
"the",
"given",
"value",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/watermark.go#L78-L81 | test |
dgraph-io/badger | y/watermark.go | BeginMany | func (w *WaterMark) BeginMany(indices []uint64) {
atomic.StoreUint64(&w.lastIndex, indices[len(indices)-1])
w.markCh <- mark{index: 0, indices: indices, done: false}
} | go | func (w *WaterMark) BeginMany(indices []uint64) {
atomic.StoreUint64(&w.lastIndex, indices[len(indices)-1])
w.markCh <- mark{index: 0, indices: indices, done: false}
} | [
"func",
"(",
"w",
"*",
"WaterMark",
")",
"BeginMany",
"(",
"indices",
"[",
"]",
"uint64",
")",
"{",
"atomic",
".",
"StoreUint64",
"(",
"&",
"w",
".",
"lastIndex",
",",
"indices",
"[",
"len",
"(",
"indices",
")",
"-",
"1",
"]",
")",
"\n",
"w",
"."... | // BeginMany works like Begin but accepts multiple indices. | [
"BeginMany",
"works",
"like",
"Begin",
"but",
"accepts",
"multiple",
"indices",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/watermark.go#L84-L87 | test |
dgraph-io/badger | y/watermark.go | Done | func (w *WaterMark) Done(index uint64) {
w.markCh <- mark{index: index, done: true}
} | go | func (w *WaterMark) Done(index uint64) {
w.markCh <- mark{index: index, done: true}
} | [
"func",
"(",
"w",
"*",
"WaterMark",
")",
"Done",
"(",
"index",
"uint64",
")",
"{",
"w",
".",
"markCh",
"<-",
"mark",
"{",
"index",
":",
"index",
",",
"done",
":",
"true",
"}",
"\n",
"}"
] | // Done sets a single index as done. | [
"Done",
"sets",
"a",
"single",
"index",
"as",
"done",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/watermark.go#L90-L92 | test |
dgraph-io/badger | y/watermark.go | DoneMany | func (w *WaterMark) DoneMany(indices []uint64) {
w.markCh <- mark{index: 0, indices: indices, done: true}
} | go | func (w *WaterMark) DoneMany(indices []uint64) {
w.markCh <- mark{index: 0, indices: indices, done: true}
} | [
"func",
"(",
"w",
"*",
"WaterMark",
")",
"DoneMany",
"(",
"indices",
"[",
"]",
"uint64",
")",
"{",
"w",
".",
"markCh",
"<-",
"mark",
"{",
"index",
":",
"0",
",",
"indices",
":",
"indices",
",",
"done",
":",
"true",
"}",
"\n",
"}"
] | // DoneMany works like Done but accepts multiple indices. | [
"DoneMany",
"works",
"like",
"Done",
"but",
"accepts",
"multiple",
"indices",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/watermark.go#L95-L97 | test |
dgraph-io/badger | y/watermark.go | SetDoneUntil | func (w *WaterMark) SetDoneUntil(val uint64) {
atomic.StoreUint64(&w.doneUntil, val)
} | go | func (w *WaterMark) SetDoneUntil(val uint64) {
atomic.StoreUint64(&w.doneUntil, val)
} | [
"func",
"(",
"w",
"*",
"WaterMark",
")",
"SetDoneUntil",
"(",
"val",
"uint64",
")",
"{",
"atomic",
".",
"StoreUint64",
"(",
"&",
"w",
".",
"doneUntil",
",",
"val",
")",
"\n",
"}"
] | // SetDoneUntil sets the maximum index that has the property that all indices
// less than or equal to it are done. | [
"SetDoneUntil",
"sets",
"the",
"maximum",
"index",
"that",
"has",
"the",
"property",
"that",
"all",
"indices",
"less",
"than",
"or",
"equal",
"to",
"it",
"are",
"done",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/watermark.go#L107-L109 | test |
dgraph-io/badger | y/watermark.go | WaitForMark | func (w *WaterMark) WaitForMark(ctx context.Context, index uint64) error {
if w.DoneUntil() >= index {
return nil
}
waitCh := make(chan struct{})
w.markCh <- mark{index: index, waiter: waitCh}
select {
case <-ctx.Done():
return ctx.Err()
case <-waitCh:
return nil
}
} | go | func (w *WaterMark) WaitForMark(ctx context.Context, index uint64) error {
if w.DoneUntil() >= index {
return nil
}
waitCh := make(chan struct{})
w.markCh <- mark{index: index, waiter: waitCh}
select {
case <-ctx.Done():
return ctx.Err()
case <-waitCh:
return nil
}
} | [
"func",
"(",
"w",
"*",
"WaterMark",
")",
"WaitForMark",
"(",
"ctx",
"context",
".",
"Context",
",",
"index",
"uint64",
")",
"error",
"{",
"if",
"w",
".",
"DoneUntil",
"(",
")",
">=",
"index",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"waitCh",
":=",
"... | // WaitForMark waits until the given index is marked as done. | [
"WaitForMark",
"waits",
"until",
"the",
"given",
"index",
"is",
"marked",
"as",
"done",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/watermark.go#L117-L130 | test |
dgraph-io/badger | table/builder.go | Encode | func (h header) Encode(b []byte) {
binary.BigEndian.PutUint16(b[0:2], h.plen)
binary.BigEndian.PutUint16(b[2:4], h.klen)
binary.BigEndian.PutUint16(b[4:6], h.vlen)
binary.BigEndian.PutUint32(b[6:10], h.prev)
} | go | func (h header) Encode(b []byte) {
binary.BigEndian.PutUint16(b[0:2], h.plen)
binary.BigEndian.PutUint16(b[2:4], h.klen)
binary.BigEndian.PutUint16(b[4:6], h.vlen)
binary.BigEndian.PutUint32(b[6:10], h.prev)
} | [
"func",
"(",
"h",
"header",
")",
"Encode",
"(",
"b",
"[",
"]",
"byte",
")",
"{",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"b",
"[",
"0",
":",
"2",
"]",
",",
"h",
".",
"plen",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(... | // Encode encodes the header. | [
"Encode",
"encodes",
"the",
"header",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/builder.go#L47-L52 | test |
dgraph-io/badger | table/builder.go | Decode | func (h *header) Decode(buf []byte) int {
h.plen = binary.BigEndian.Uint16(buf[0:2])
h.klen = binary.BigEndian.Uint16(buf[2:4])
h.vlen = binary.BigEndian.Uint16(buf[4:6])
h.prev = binary.BigEndian.Uint32(buf[6:10])
return h.Size()
} | go | func (h *header) Decode(buf []byte) int {
h.plen = binary.BigEndian.Uint16(buf[0:2])
h.klen = binary.BigEndian.Uint16(buf[2:4])
h.vlen = binary.BigEndian.Uint16(buf[4:6])
h.prev = binary.BigEndian.Uint32(buf[6:10])
return h.Size()
} | [
"func",
"(",
"h",
"*",
"header",
")",
"Decode",
"(",
"buf",
"[",
"]",
"byte",
")",
"int",
"{",
"h",
".",
"plen",
"=",
"binary",
".",
"BigEndian",
".",
"Uint16",
"(",
"buf",
"[",
"0",
":",
"2",
"]",
")",
"\n",
"h",
".",
"klen",
"=",
"binary",
... | // Decode decodes the header. | [
"Decode",
"decodes",
"the",
"header",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/builder.go#L55-L61 | test |
dgraph-io/badger | table/builder.go | NewTableBuilder | func NewTableBuilder() *Builder {
return &Builder{
keyBuf: newBuffer(1 << 20),
buf: newBuffer(1 << 20),
prevOffset: math.MaxUint32, // Used for the first element!
}
} | go | func NewTableBuilder() *Builder {
return &Builder{
keyBuf: newBuffer(1 << 20),
buf: newBuffer(1 << 20),
prevOffset: math.MaxUint32, // Used for the first element!
}
} | [
"func",
"NewTableBuilder",
"(",
")",
"*",
"Builder",
"{",
"return",
"&",
"Builder",
"{",
"keyBuf",
":",
"newBuffer",
"(",
"1",
"<<",
"20",
")",
",",
"buf",
":",
"newBuffer",
"(",
"1",
"<<",
"20",
")",
",",
"prevOffset",
":",
"math",
".",
"MaxUint32",... | // NewTableBuilder makes a new TableBuilder. | [
"NewTableBuilder",
"makes",
"a",
"new",
"TableBuilder",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/builder.go#L86-L92 | test |
dgraph-io/badger | table/builder.go | keyDiff | func (b Builder) keyDiff(newKey []byte) []byte {
var i int
for i = 0; i < len(newKey) && i < len(b.baseKey); i++ {
if newKey[i] != b.baseKey[i] {
break
}
}
return newKey[i:]
} | go | func (b Builder) keyDiff(newKey []byte) []byte {
var i int
for i = 0; i < len(newKey) && i < len(b.baseKey); i++ {
if newKey[i] != b.baseKey[i] {
break
}
}
return newKey[i:]
} | [
"func",
"(",
"b",
"Builder",
")",
"keyDiff",
"(",
"newKey",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"var",
"i",
"int",
"\n",
"for",
"i",
"=",
"0",
";",
"i",
"<",
"len",
"(",
"newKey",
")",
"&&",
"i",
"<",
"len",
"(",
"b",
".",
"baseKe... | // keyDiff returns a suffix of newKey that is different from b.baseKey. | [
"keyDiff",
"returns",
"a",
"suffix",
"of",
"newKey",
"that",
"is",
"different",
"from",
"b",
".",
"baseKey",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/builder.go#L101-L109 | test |
dgraph-io/badger | table/builder.go | Add | func (b *Builder) Add(key []byte, value y.ValueStruct) error {
if b.counter >= restartInterval {
b.finishBlock()
// Start a new block. Initialize the block.
b.restarts = append(b.restarts, uint32(b.buf.Len()))
b.counter = 0
b.baseKey = []byte{}
b.baseOffset = uint32(b.buf.Len())
b.prevOffset = math.MaxUi... | go | func (b *Builder) Add(key []byte, value y.ValueStruct) error {
if b.counter >= restartInterval {
b.finishBlock()
// Start a new block. Initialize the block.
b.restarts = append(b.restarts, uint32(b.buf.Len()))
b.counter = 0
b.baseKey = []byte{}
b.baseOffset = uint32(b.buf.Len())
b.prevOffset = math.MaxUi... | [
"func",
"(",
"b",
"*",
"Builder",
")",
"Add",
"(",
"key",
"[",
"]",
"byte",
",",
"value",
"y",
".",
"ValueStruct",
")",
"error",
"{",
"if",
"b",
".",
"counter",
">=",
"restartInterval",
"{",
"b",
".",
"finishBlock",
"(",
")",
"\n",
"b",
".",
"res... | // Add adds a key-value pair to the block.
// If doNotRestart is true, we will not restart even if b.counter >= restartInterval. | [
"Add",
"adds",
"a",
"key",
"-",
"value",
"pair",
"to",
"the",
"block",
".",
"If",
"doNotRestart",
"is",
"true",
"we",
"will",
"not",
"restart",
"even",
"if",
"b",
".",
"counter",
">",
"=",
"restartInterval",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/builder.go#L159-L171 | test |
dgraph-io/badger | table/builder.go | blockIndex | func (b *Builder) blockIndex() []byte {
// Store the end offset, so we know the length of the final block.
b.restarts = append(b.restarts, uint32(b.buf.Len()))
// Add 4 because we want to write out number of restarts at the end.
sz := 4*len(b.restarts) + 4
out := make([]byte, sz)
buf := out
for _, r := range b.... | go | func (b *Builder) blockIndex() []byte {
// Store the end offset, so we know the length of the final block.
b.restarts = append(b.restarts, uint32(b.buf.Len()))
// Add 4 because we want to write out number of restarts at the end.
sz := 4*len(b.restarts) + 4
out := make([]byte, sz)
buf := out
for _, r := range b.... | [
"func",
"(",
"b",
"*",
"Builder",
")",
"blockIndex",
"(",
")",
"[",
"]",
"byte",
"{",
"b",
".",
"restarts",
"=",
"append",
"(",
"b",
".",
"restarts",
",",
"uint32",
"(",
"b",
".",
"buf",
".",
"Len",
"(",
")",
")",
")",
"\n",
"sz",
":=",
"4",
... | // blockIndex generates the block index for the table.
// It is mainly a list of all the block base offsets. | [
"blockIndex",
"generates",
"the",
"block",
"index",
"for",
"the",
"table",
".",
"It",
"is",
"mainly",
"a",
"list",
"of",
"all",
"the",
"block",
"base",
"offsets",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/builder.go#L186-L200 | test |
dgraph-io/badger | table/builder.go | Finish | func (b *Builder) Finish() []byte {
bf := bbloom.New(float64(b.keyCount), 0.01)
var klen [2]byte
key := make([]byte, 1024)
for {
if _, err := b.keyBuf.Read(klen[:]); err == io.EOF {
break
} else if err != nil {
y.Check(err)
}
kl := int(binary.BigEndian.Uint16(klen[:]))
if cap(key) < kl {
key = ma... | go | func (b *Builder) Finish() []byte {
bf := bbloom.New(float64(b.keyCount), 0.01)
var klen [2]byte
key := make([]byte, 1024)
for {
if _, err := b.keyBuf.Read(klen[:]); err == io.EOF {
break
} else if err != nil {
y.Check(err)
}
kl := int(binary.BigEndian.Uint16(klen[:]))
if cap(key) < kl {
key = ma... | [
"func",
"(",
"b",
"*",
"Builder",
")",
"Finish",
"(",
")",
"[",
"]",
"byte",
"{",
"bf",
":=",
"bbloom",
".",
"New",
"(",
"float64",
"(",
"b",
".",
"keyCount",
")",
",",
"0.01",
")",
"\n",
"var",
"klen",
"[",
"2",
"]",
"byte",
"\n",
"key",
":=... | // Finish finishes the table by appending the index. | [
"Finish",
"finishes",
"the",
"table",
"by",
"appending",
"the",
"index",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/table/builder.go#L203-L235 | test |
dgraph-io/badger | logger.go | Errorf | func (opt *Options) Errorf(format string, v ...interface{}) {
if opt.Logger == nil {
return
}
opt.Logger.Errorf(format, v...)
} | go | func (opt *Options) Errorf(format string, v ...interface{}) {
if opt.Logger == nil {
return
}
opt.Logger.Errorf(format, v...)
} | [
"func",
"(",
"opt",
"*",
"Options",
")",
"Errorf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"opt",
".",
"Logger",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"opt",
".",
"Logger",
".",
"Errorf",
"(",
"form... | // Errorf logs an ERROR log message to the logger specified in opts or to the
// global logger if no logger is specified in opts. | [
"Errorf",
"logs",
"an",
"ERROR",
"log",
"message",
"to",
"the",
"logger",
"specified",
"in",
"opts",
"or",
"to",
"the",
"global",
"logger",
"if",
"no",
"logger",
"is",
"specified",
"in",
"opts",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/logger.go#L34-L39 | test |
dgraph-io/badger | logger.go | Infof | func (opt *Options) Infof(format string, v ...interface{}) {
if opt.Logger == nil {
return
}
opt.Logger.Infof(format, v...)
} | go | func (opt *Options) Infof(format string, v ...interface{}) {
if opt.Logger == nil {
return
}
opt.Logger.Infof(format, v...)
} | [
"func",
"(",
"opt",
"*",
"Options",
")",
"Infof",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"opt",
".",
"Logger",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"opt",
".",
"Logger",
".",
"Infof",
"(",
"format... | // Infof logs an INFO message to the logger specified in opts. | [
"Infof",
"logs",
"an",
"INFO",
"message",
"to",
"the",
"logger",
"specified",
"in",
"opts",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/logger.go#L42-L47 | test |
dgraph-io/badger | skl/skl.go | DecrRef | func (s *Skiplist) DecrRef() {
newRef := atomic.AddInt32(&s.ref, -1)
if newRef > 0 {
return
}
s.arena.reset()
// Indicate we are closed. Good for testing. Also, lets GC reclaim memory. Race condition
// here would suggest we are accessing skiplist when we are supposed to have no reference!
s.arena = nil
} | go | func (s *Skiplist) DecrRef() {
newRef := atomic.AddInt32(&s.ref, -1)
if newRef > 0 {
return
}
s.arena.reset()
// Indicate we are closed. Good for testing. Also, lets GC reclaim memory. Race condition
// here would suggest we are accessing skiplist when we are supposed to have no reference!
s.arena = nil
} | [
"func",
"(",
"s",
"*",
"Skiplist",
")",
"DecrRef",
"(",
")",
"{",
"newRef",
":=",
"atomic",
".",
"AddInt32",
"(",
"&",
"s",
".",
"ref",
",",
"-",
"1",
")",
"\n",
"if",
"newRef",
">",
"0",
"{",
"return",
"\n",
"}",
"\n",
"s",
".",
"arena",
"."... | // DecrRef decrements the refcount, deallocating the Skiplist when done using it | [
"DecrRef",
"decrements",
"the",
"refcount",
"deallocating",
"the",
"Skiplist",
"when",
"done",
"using",
"it"
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/skl.go#L90-L100 | test |
dgraph-io/badger | skl/skl.go | NewSkiplist | func NewSkiplist(arenaSize int64) *Skiplist {
arena := newArena(arenaSize)
head := newNode(arena, nil, y.ValueStruct{}, maxHeight)
return &Skiplist{
height: 1,
head: head,
arena: arena,
ref: 1,
}
} | go | func NewSkiplist(arenaSize int64) *Skiplist {
arena := newArena(arenaSize)
head := newNode(arena, nil, y.ValueStruct{}, maxHeight)
return &Skiplist{
height: 1,
head: head,
arena: arena,
ref: 1,
}
} | [
"func",
"NewSkiplist",
"(",
"arenaSize",
"int64",
")",
"*",
"Skiplist",
"{",
"arena",
":=",
"newArena",
"(",
"arenaSize",
")",
"\n",
"head",
":=",
"newNode",
"(",
"arena",
",",
"nil",
",",
"y",
".",
"ValueStruct",
"{",
"}",
",",
"maxHeight",
")",
"\n",... | // NewSkiplist makes a new empty skiplist, with a given arena size | [
"NewSkiplist",
"makes",
"a",
"new",
"empty",
"skiplist",
"with",
"a",
"given",
"arena",
"size"
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/skl.go#L126-L135 | test |
dgraph-io/badger | skl/skl.go | Put | func (s *Skiplist) Put(key []byte, v y.ValueStruct) {
// Since we allow overwrite, we may not need to create a new node. We might not even need to
// increase the height. Let's defer these actions.
listHeight := s.getHeight()
var prev [maxHeight + 1]*node
var next [maxHeight + 1]*node
prev[listHeight] = s.head
... | go | func (s *Skiplist) Put(key []byte, v y.ValueStruct) {
// Since we allow overwrite, we may not need to create a new node. We might not even need to
// increase the height. Let's defer these actions.
listHeight := s.getHeight()
var prev [maxHeight + 1]*node
var next [maxHeight + 1]*node
prev[listHeight] = s.head
... | [
"func",
"(",
"s",
"*",
"Skiplist",
")",
"Put",
"(",
"key",
"[",
"]",
"byte",
",",
"v",
"y",
".",
"ValueStruct",
")",
"{",
"listHeight",
":=",
"s",
".",
"getHeight",
"(",
")",
"\n",
"var",
"prev",
"[",
"maxHeight",
"+",
"1",
"]",
"*",
"node",
"\... | // Put inserts the key-value pair. | [
"Put",
"inserts",
"the",
"key",
"-",
"value",
"pair",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/skl.go#L283-L345 | test |
dgraph-io/badger | skl/skl.go | Get | func (s *Skiplist) Get(key []byte) y.ValueStruct {
n, _ := s.findNear(key, false, true) // findGreaterOrEqual.
if n == nil {
return y.ValueStruct{}
}
nextKey := s.arena.getKey(n.keyOffset, n.keySize)
if !y.SameKey(key, nextKey) {
return y.ValueStruct{}
}
valOffset, valSize := n.getValueOffset()
vs := s.ar... | go | func (s *Skiplist) Get(key []byte) y.ValueStruct {
n, _ := s.findNear(key, false, true) // findGreaterOrEqual.
if n == nil {
return y.ValueStruct{}
}
nextKey := s.arena.getKey(n.keyOffset, n.keySize)
if !y.SameKey(key, nextKey) {
return y.ValueStruct{}
}
valOffset, valSize := n.getValueOffset()
vs := s.ar... | [
"func",
"(",
"s",
"*",
"Skiplist",
")",
"Get",
"(",
"key",
"[",
"]",
"byte",
")",
"y",
".",
"ValueStruct",
"{",
"n",
",",
"_",
":=",
"s",
".",
"findNear",
"(",
"key",
",",
"false",
",",
"true",
")",
"\n",
"if",
"n",
"==",
"nil",
"{",
"return"... | // Get gets the value associated with the key. It returns a valid value if it finds equal or earlier
// version of the same key. | [
"Get",
"gets",
"the",
"value",
"associated",
"with",
"the",
"key",
".",
"It",
"returns",
"a",
"valid",
"value",
"if",
"it",
"finds",
"equal",
"or",
"earlier",
"version",
"of",
"the",
"same",
"key",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/skl.go#L375-L390 | test |
dgraph-io/badger | skl/skl.go | Key | func (s *Iterator) Key() []byte {
return s.list.arena.getKey(s.n.keyOffset, s.n.keySize)
} | go | func (s *Iterator) Key() []byte {
return s.list.arena.getKey(s.n.keyOffset, s.n.keySize)
} | [
"func",
"(",
"s",
"*",
"Iterator",
")",
"Key",
"(",
")",
"[",
"]",
"byte",
"{",
"return",
"s",
".",
"list",
".",
"arena",
".",
"getKey",
"(",
"s",
".",
"n",
".",
"keyOffset",
",",
"s",
".",
"n",
".",
"keySize",
")",
"\n",
"}"
] | // Key returns the key at the current position. | [
"Key",
"returns",
"the",
"key",
"at",
"the",
"current",
"position",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/skl.go#L419-L421 | test |
dgraph-io/badger | skl/skl.go | Value | func (s *Iterator) Value() y.ValueStruct {
valOffset, valSize := s.n.getValueOffset()
return s.list.arena.getVal(valOffset, valSize)
} | go | func (s *Iterator) Value() y.ValueStruct {
valOffset, valSize := s.n.getValueOffset()
return s.list.arena.getVal(valOffset, valSize)
} | [
"func",
"(",
"s",
"*",
"Iterator",
")",
"Value",
"(",
")",
"y",
".",
"ValueStruct",
"{",
"valOffset",
",",
"valSize",
":=",
"s",
".",
"n",
".",
"getValueOffset",
"(",
")",
"\n",
"return",
"s",
".",
"list",
".",
"arena",
".",
"getVal",
"(",
"valOffs... | // Value returns value. | [
"Value",
"returns",
"value",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/skl.go#L424-L427 | test |
dgraph-io/badger | skl/skl.go | Next | func (s *Iterator) Next() {
y.AssertTrue(s.Valid())
s.n = s.list.getNext(s.n, 0)
} | go | func (s *Iterator) Next() {
y.AssertTrue(s.Valid())
s.n = s.list.getNext(s.n, 0)
} | [
"func",
"(",
"s",
"*",
"Iterator",
")",
"Next",
"(",
")",
"{",
"y",
".",
"AssertTrue",
"(",
"s",
".",
"Valid",
"(",
")",
")",
"\n",
"s",
".",
"n",
"=",
"s",
".",
"list",
".",
"getNext",
"(",
"s",
".",
"n",
",",
"0",
")",
"\n",
"}"
] | // Next advances to the next position. | [
"Next",
"advances",
"to",
"the",
"next",
"position",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/skl.go#L430-L433 | test |
dgraph-io/badger | skl/skl.go | Prev | func (s *Iterator) Prev() {
y.AssertTrue(s.Valid())
s.n, _ = s.list.findNear(s.Key(), true, false) // find <. No equality allowed.
} | go | func (s *Iterator) Prev() {
y.AssertTrue(s.Valid())
s.n, _ = s.list.findNear(s.Key(), true, false) // find <. No equality allowed.
} | [
"func",
"(",
"s",
"*",
"Iterator",
")",
"Prev",
"(",
")",
"{",
"y",
".",
"AssertTrue",
"(",
"s",
".",
"Valid",
"(",
")",
")",
"\n",
"s",
".",
"n",
",",
"_",
"=",
"s",
".",
"list",
".",
"findNear",
"(",
"s",
".",
"Key",
"(",
")",
",",
"tru... | // Prev advances to the previous position. | [
"Prev",
"advances",
"to",
"the",
"previous",
"position",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/skl.go#L436-L439 | test |
dgraph-io/badger | skl/skl.go | Seek | func (s *Iterator) Seek(target []byte) {
s.n, _ = s.list.findNear(target, false, true) // find >=.
} | go | func (s *Iterator) Seek(target []byte) {
s.n, _ = s.list.findNear(target, false, true) // find >=.
} | [
"func",
"(",
"s",
"*",
"Iterator",
")",
"Seek",
"(",
"target",
"[",
"]",
"byte",
")",
"{",
"s",
".",
"n",
",",
"_",
"=",
"s",
".",
"list",
".",
"findNear",
"(",
"target",
",",
"false",
",",
"true",
")",
"\n",
"}"
] | // Seek advances to the first entry with a key >= target. | [
"Seek",
"advances",
"to",
"the",
"first",
"entry",
"with",
"a",
"key",
">",
"=",
"target",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/skl.go#L442-L444 | test |
dgraph-io/badger | skl/skl.go | SeekForPrev | func (s *Iterator) SeekForPrev(target []byte) {
s.n, _ = s.list.findNear(target, true, true) // find <=.
} | go | func (s *Iterator) SeekForPrev(target []byte) {
s.n, _ = s.list.findNear(target, true, true) // find <=.
} | [
"func",
"(",
"s",
"*",
"Iterator",
")",
"SeekForPrev",
"(",
"target",
"[",
"]",
"byte",
")",
"{",
"s",
".",
"n",
",",
"_",
"=",
"s",
".",
"list",
".",
"findNear",
"(",
"target",
",",
"true",
",",
"true",
")",
"\n",
"}"
] | // SeekForPrev finds an entry with key <= target. | [
"SeekForPrev",
"finds",
"an",
"entry",
"with",
"key",
"<",
"=",
"target",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/skl.go#L447-L449 | test |
dgraph-io/badger | skl/skl.go | NewUniIterator | func (s *Skiplist) NewUniIterator(reversed bool) *UniIterator {
return &UniIterator{
iter: s.NewIterator(),
reversed: reversed,
}
} | go | func (s *Skiplist) NewUniIterator(reversed bool) *UniIterator {
return &UniIterator{
iter: s.NewIterator(),
reversed: reversed,
}
} | [
"func",
"(",
"s",
"*",
"Skiplist",
")",
"NewUniIterator",
"(",
"reversed",
"bool",
")",
"*",
"UniIterator",
"{",
"return",
"&",
"UniIterator",
"{",
"iter",
":",
"s",
".",
"NewIterator",
"(",
")",
",",
"reversed",
":",
"reversed",
",",
"}",
"\n",
"}"
] | // NewUniIterator returns a UniIterator. | [
"NewUniIterator",
"returns",
"a",
"UniIterator",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/skl.go#L472-L477 | test |
dgraph-io/badger | skl/skl.go | Next | func (s *UniIterator) Next() {
if !s.reversed {
s.iter.Next()
} else {
s.iter.Prev()
}
} | go | func (s *UniIterator) Next() {
if !s.reversed {
s.iter.Next()
} else {
s.iter.Prev()
}
} | [
"func",
"(",
"s",
"*",
"UniIterator",
")",
"Next",
"(",
")",
"{",
"if",
"!",
"s",
".",
"reversed",
"{",
"s",
".",
"iter",
".",
"Next",
"(",
")",
"\n",
"}",
"else",
"{",
"s",
".",
"iter",
".",
"Prev",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Next implements y.Interface | [
"Next",
"implements",
"y",
".",
"Interface"
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/skl.go#L480-L486 | test |
dgraph-io/badger | skl/skl.go | Seek | func (s *UniIterator) Seek(key []byte) {
if !s.reversed {
s.iter.Seek(key)
} else {
s.iter.SeekForPrev(key)
}
} | go | func (s *UniIterator) Seek(key []byte) {
if !s.reversed {
s.iter.Seek(key)
} else {
s.iter.SeekForPrev(key)
}
} | [
"func",
"(",
"s",
"*",
"UniIterator",
")",
"Seek",
"(",
"key",
"[",
"]",
"byte",
")",
"{",
"if",
"!",
"s",
".",
"reversed",
"{",
"s",
".",
"iter",
".",
"Seek",
"(",
"key",
")",
"\n",
"}",
"else",
"{",
"s",
".",
"iter",
".",
"SeekForPrev",
"("... | // Seek implements y.Interface | [
"Seek",
"implements",
"y",
".",
"Interface"
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/skl.go#L498-L504 | test |
dgraph-io/badger | manifest.go | asChanges | func (m *Manifest) asChanges() []*pb.ManifestChange {
changes := make([]*pb.ManifestChange, 0, len(m.Tables))
for id, tm := range m.Tables {
changes = append(changes, newCreateChange(id, int(tm.Level), tm.Checksum))
}
return changes
} | go | func (m *Manifest) asChanges() []*pb.ManifestChange {
changes := make([]*pb.ManifestChange, 0, len(m.Tables))
for id, tm := range m.Tables {
changes = append(changes, newCreateChange(id, int(tm.Level), tm.Checksum))
}
return changes
} | [
"func",
"(",
"m",
"*",
"Manifest",
")",
"asChanges",
"(",
")",
"[",
"]",
"*",
"pb",
".",
"ManifestChange",
"{",
"changes",
":=",
"make",
"(",
"[",
"]",
"*",
"pb",
".",
"ManifestChange",
",",
"0",
",",
"len",
"(",
"m",
".",
"Tables",
")",
")",
"... | // asChanges returns a sequence of changes that could be used to recreate the Manifest in its
// present state. | [
"asChanges",
"returns",
"a",
"sequence",
"of",
"changes",
"that",
"could",
"be",
"used",
"to",
"recreate",
"the",
"Manifest",
"in",
"its",
"present",
"state",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/manifest.go#L99-L105 | test |
dgraph-io/badger | manifest.go | rewrite | func (mf *manifestFile) rewrite() error {
// In Windows the files should be closed before doing a Rename.
if err := mf.fp.Close(); err != nil {
return err
}
fp, netCreations, err := helpRewrite(mf.directory, &mf.manifest)
if err != nil {
return err
}
mf.fp = fp
mf.manifest.Creations = netCreations
mf.manif... | go | func (mf *manifestFile) rewrite() error {
// In Windows the files should be closed before doing a Rename.
if err := mf.fp.Close(); err != nil {
return err
}
fp, netCreations, err := helpRewrite(mf.directory, &mf.manifest)
if err != nil {
return err
}
mf.fp = fp
mf.manifest.Creations = netCreations
mf.manif... | [
"func",
"(",
"mf",
"*",
"manifestFile",
")",
"rewrite",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"mf",
".",
"fp",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"fp",
",",
"netCreations",
",",
"err",
"... | // Must be called while appendLock is held. | [
"Must",
"be",
"called",
"while",
"appendLock",
"is",
"held",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/manifest.go#L285-L299 | test |
dgraph-io/badger | util.go | validate | func (s *levelHandler) validate() error {
if s.level == 0 {
return nil
}
s.RLock()
defer s.RUnlock()
numTables := len(s.tables)
for j := 1; j < numTables; j++ {
if j >= len(s.tables) {
return errors.Errorf("Level %d, j=%d numTables=%d", s.level, j, numTables)
}
if y.CompareKeys(s.tables[j-1].Biggest(... | go | func (s *levelHandler) validate() error {
if s.level == 0 {
return nil
}
s.RLock()
defer s.RUnlock()
numTables := len(s.tables)
for j := 1; j < numTables; j++ {
if j >= len(s.tables) {
return errors.Errorf("Level %d, j=%d numTables=%d", s.level, j, numTables)
}
if y.CompareKeys(s.tables[j-1].Biggest(... | [
"func",
"(",
"s",
"*",
"levelHandler",
")",
"validate",
"(",
")",
"error",
"{",
"if",
"s",
".",
"level",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"s",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"RUnlock",
"(",
")",
"\n",
"numTabl... | // Check does some sanity check on one level of data or in-memory index. | [
"Check",
"does",
"some",
"sanity",
"check",
"on",
"one",
"level",
"of",
"data",
"or",
"in",
"-",
"memory",
"index",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/util.go#L66-L93 | test |
dgraph-io/badger | dir_windows.go | acquireDirectoryLock | func acquireDirectoryLock(dirPath string, pidFileName string, readOnly bool) (*directoryLockGuard, error) {
if readOnly {
return nil, ErrWindowsNotSupported
}
// Convert to absolute path so that Release still works even if we do an unbalanced
// chdir in the meantime.
absLockFilePath, err := filepath.Abs(filepa... | go | func acquireDirectoryLock(dirPath string, pidFileName string, readOnly bool) (*directoryLockGuard, error) {
if readOnly {
return nil, ErrWindowsNotSupported
}
// Convert to absolute path so that Release still works even if we do an unbalanced
// chdir in the meantime.
absLockFilePath, err := filepath.Abs(filepa... | [
"func",
"acquireDirectoryLock",
"(",
"dirPath",
"string",
",",
"pidFileName",
"string",
",",
"readOnly",
"bool",
")",
"(",
"*",
"directoryLockGuard",
",",
"error",
")",
"{",
"if",
"readOnly",
"{",
"return",
"nil",
",",
"ErrWindowsNotSupported",
"\n",
"}",
"\n"... | // AcquireDirectoryLock acquires exclusive access to a directory. | [
"AcquireDirectoryLock",
"acquires",
"exclusive",
"access",
"to",
"a",
"directory",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/dir_windows.go#L70-L100 | test |
dgraph-io/badger | dir_windows.go | release | func (g *directoryLockGuard) release() error {
g.path = ""
return syscall.CloseHandle(g.h)
} | go | func (g *directoryLockGuard) release() error {
g.path = ""
return syscall.CloseHandle(g.h)
} | [
"func",
"(",
"g",
"*",
"directoryLockGuard",
")",
"release",
"(",
")",
"error",
"{",
"g",
".",
"path",
"=",
"\"\"",
"\n",
"return",
"syscall",
".",
"CloseHandle",
"(",
"g",
".",
"h",
")",
"\n",
"}"
] | // Release removes the directory lock. | [
"Release",
"removes",
"the",
"directory",
"lock",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/dir_windows.go#L103-L106 | test |
dgraph-io/badger | y/error.go | AssertTruef | func AssertTruef(b bool, format string, args ...interface{}) {
if !b {
log.Fatalf("%+v", errors.Errorf(format, args...))
}
} | go | func AssertTruef(b bool, format string, args ...interface{}) {
if !b {
log.Fatalf("%+v", errors.Errorf(format, args...))
}
} | [
"func",
"AssertTruef",
"(",
"b",
"bool",
",",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"!",
"b",
"{",
"log",
".",
"Fatalf",
"(",
"\"%+v\"",
",",
"errors",
".",
"Errorf",
"(",
"format",
",",
"args",
"...",
")",
... | // AssertTruef is AssertTrue with extra info. | [
"AssertTruef",
"is",
"AssertTrue",
"with",
"extra",
"info",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/error.go#L60-L64 | test |
dgraph-io/badger | y/error.go | Wrapf | func Wrapf(err error, format string, args ...interface{}) error {
if !debugMode {
if err == nil {
return nil
}
return fmt.Errorf(format+" error: %+v", append(args, err)...)
}
return errors.Wrapf(err, format, args...)
} | go | func Wrapf(err error, format string, args ...interface{}) error {
if !debugMode {
if err == nil {
return nil
}
return fmt.Errorf(format+" error: %+v", append(args, err)...)
}
return errors.Wrapf(err, format, args...)
} | [
"func",
"Wrapf",
"(",
"err",
"error",
",",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"!",
"debugMode",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf... | // Wrapf is Wrap with extra info. | [
"Wrapf",
"is",
"Wrap",
"with",
"extra",
"info",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/error.go#L75-L83 | test |
dgraph-io/badger | level_handler.go | initTables | func (s *levelHandler) initTables(tables []*table.Table) {
s.Lock()
defer s.Unlock()
s.tables = tables
s.totalSize = 0
for _, t := range tables {
s.totalSize += t.Size()
}
if s.level == 0 {
// Key range will overlap. Just sort by fileID in ascending order
// because newer tables are at the end of level 0... | go | func (s *levelHandler) initTables(tables []*table.Table) {
s.Lock()
defer s.Unlock()
s.tables = tables
s.totalSize = 0
for _, t := range tables {
s.totalSize += t.Size()
}
if s.level == 0 {
// Key range will overlap. Just sort by fileID in ascending order
// because newer tables are at the end of level 0... | [
"func",
"(",
"s",
"*",
"levelHandler",
")",
"initTables",
"(",
"tables",
"[",
"]",
"*",
"table",
".",
"Table",
")",
"{",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\n",
"s",
".",
"tables",
"=",
"tables",
"\n",
"s"... | // initTables replaces s.tables with given tables. This is done during loading. | [
"initTables",
"replaces",
"s",
".",
"tables",
"with",
"given",
"tables",
".",
"This",
"is",
"done",
"during",
"loading",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/level_handler.go#L53-L75 | test |
dgraph-io/badger | level_handler.go | deleteTables | func (s *levelHandler) deleteTables(toDel []*table.Table) error {
s.Lock() // s.Unlock() below
toDelMap := make(map[uint64]struct{})
for _, t := range toDel {
toDelMap[t.ID()] = struct{}{}
}
// Make a copy as iterators might be keeping a slice of tables.
var newTables []*table.Table
for _, t := range s.table... | go | func (s *levelHandler) deleteTables(toDel []*table.Table) error {
s.Lock() // s.Unlock() below
toDelMap := make(map[uint64]struct{})
for _, t := range toDel {
toDelMap[t.ID()] = struct{}{}
}
// Make a copy as iterators might be keeping a slice of tables.
var newTables []*table.Table
for _, t := range s.table... | [
"func",
"(",
"s",
"*",
"levelHandler",
")",
"deleteTables",
"(",
"toDel",
"[",
"]",
"*",
"table",
".",
"Table",
")",
"error",
"{",
"s",
".",
"Lock",
"(",
")",
"\n",
"toDelMap",
":=",
"make",
"(",
"map",
"[",
"uint64",
"]",
"struct",
"{",
"}",
")"... | // deleteTables remove tables idx0, ..., idx1-1. | [
"deleteTables",
"remove",
"tables",
"idx0",
"...",
"idx1",
"-",
"1",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/level_handler.go#L78-L101 | test |
dgraph-io/badger | level_handler.go | tryAddLevel0Table | func (s *levelHandler) tryAddLevel0Table(t *table.Table) bool {
y.AssertTrue(s.level == 0)
// Need lock as we may be deleting the first table during a level 0 compaction.
s.Lock()
defer s.Unlock()
if len(s.tables) >= s.db.opt.NumLevelZeroTablesStall {
return false
}
s.tables = append(s.tables, t)
t.IncrRef()... | go | func (s *levelHandler) tryAddLevel0Table(t *table.Table) bool {
y.AssertTrue(s.level == 0)
// Need lock as we may be deleting the first table during a level 0 compaction.
s.Lock()
defer s.Unlock()
if len(s.tables) >= s.db.opt.NumLevelZeroTablesStall {
return false
}
s.tables = append(s.tables, t)
t.IncrRef()... | [
"func",
"(",
"s",
"*",
"levelHandler",
")",
"tryAddLevel0Table",
"(",
"t",
"*",
"table",
".",
"Table",
")",
"bool",
"{",
"y",
".",
"AssertTrue",
"(",
"s",
".",
"level",
"==",
"0",
")",
"\n",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
... | // tryAddLevel0Table returns true if ok and no stalling. | [
"tryAddLevel0Table",
"returns",
"true",
"if",
"ok",
"and",
"no",
"stalling",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/level_handler.go#L159-L173 | test |
dgraph-io/badger | level_handler.go | getTableForKey | func (s *levelHandler) getTableForKey(key []byte) ([]*table.Table, func() error) {
s.RLock()
defer s.RUnlock()
if s.level == 0 {
// For level 0, we need to check every table. Remember to make a copy as s.tables may change
// once we exit this function, and we don't want to lock s.tables while seeking in tables.... | go | func (s *levelHandler) getTableForKey(key []byte) ([]*table.Table, func() error) {
s.RLock()
defer s.RUnlock()
if s.level == 0 {
// For level 0, we need to check every table. Remember to make a copy as s.tables may change
// once we exit this function, and we don't want to lock s.tables while seeking in tables.... | [
"func",
"(",
"s",
"*",
"levelHandler",
")",
"getTableForKey",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"*",
"table",
".",
"Table",
",",
"func",
"(",
")",
"error",
")",
"{",
"s",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"RUnlock... | // getTableForKey acquires a read-lock to access s.tables. It returns a list of tableHandlers. | [
"getTableForKey",
"acquires",
"a",
"read",
"-",
"lock",
"to",
"access",
"s",
".",
"tables",
".",
"It",
"returns",
"a",
"list",
"of",
"tableHandlers",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/level_handler.go#L194-L227 | test |
dgraph-io/badger | level_handler.go | get | func (s *levelHandler) get(key []byte) (y.ValueStruct, error) {
tables, decr := s.getTableForKey(key)
keyNoTs := y.ParseKey(key)
var maxVs y.ValueStruct
for _, th := range tables {
if th.DoesNotHave(keyNoTs) {
y.NumLSMBloomHits.Add(s.strLevel, 1)
continue
}
it := th.NewIterator(false)
defer it.Close... | go | func (s *levelHandler) get(key []byte) (y.ValueStruct, error) {
tables, decr := s.getTableForKey(key)
keyNoTs := y.ParseKey(key)
var maxVs y.ValueStruct
for _, th := range tables {
if th.DoesNotHave(keyNoTs) {
y.NumLSMBloomHits.Add(s.strLevel, 1)
continue
}
it := th.NewIterator(false)
defer it.Close... | [
"func",
"(",
"s",
"*",
"levelHandler",
")",
"get",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"y",
".",
"ValueStruct",
",",
"error",
")",
"{",
"tables",
",",
"decr",
":=",
"s",
".",
"getTableForKey",
"(",
"key",
")",
"\n",
"keyNoTs",
":=",
"y",
".",... | // get returns value for a given key or the key after that. If not found, return nil. | [
"get",
"returns",
"value",
"for",
"a",
"given",
"key",
"or",
"the",
"key",
"after",
"that",
".",
"If",
"not",
"found",
"return",
"nil",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/level_handler.go#L230-L257 | test |
dgraph-io/badger | level_handler.go | overlappingTables | func (s *levelHandler) overlappingTables(_ levelHandlerRLocked, kr keyRange) (int, int) {
if len(kr.left) == 0 || len(kr.right) == 0 {
return 0, 0
}
left := sort.Search(len(s.tables), func(i int) bool {
return y.CompareKeys(kr.left, s.tables[i].Biggest()) <= 0
})
right := sort.Search(len(s.tables), func(i int)... | go | func (s *levelHandler) overlappingTables(_ levelHandlerRLocked, kr keyRange) (int, int) {
if len(kr.left) == 0 || len(kr.right) == 0 {
return 0, 0
}
left := sort.Search(len(s.tables), func(i int) bool {
return y.CompareKeys(kr.left, s.tables[i].Biggest()) <= 0
})
right := sort.Search(len(s.tables), func(i int)... | [
"func",
"(",
"s",
"*",
"levelHandler",
")",
"overlappingTables",
"(",
"_",
"levelHandlerRLocked",
",",
"kr",
"keyRange",
")",
"(",
"int",
",",
"int",
")",
"{",
"if",
"len",
"(",
"kr",
".",
"left",
")",
"==",
"0",
"||",
"len",
"(",
"kr",
".",
"right... | // overlappingTables returns the tables that intersect with key range. Returns a half-interval.
// This function should already have acquired a read lock, and this is so important the caller must
// pass an empty parameter declaring such. | [
"overlappingTables",
"returns",
"the",
"tables",
"that",
"intersect",
"with",
"key",
"range",
".",
"Returns",
"a",
"half",
"-",
"interval",
".",
"This",
"function",
"should",
"already",
"have",
"acquired",
"a",
"read",
"lock",
"and",
"this",
"is",
"so",
"imp... | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/level_handler.go#L288-L299 | test |
dgraph-io/badger | iterator.go | String | func (item *Item) String() string {
return fmt.Sprintf("key=%q, version=%d, meta=%x", item.Key(), item.Version(), item.meta)
} | go | func (item *Item) String() string {
return fmt.Sprintf("key=%q, version=%d, meta=%x", item.Key(), item.Version(), item.meta)
} | [
"func",
"(",
"item",
"*",
"Item",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"key=%q, version=%d, meta=%x\"",
",",
"item",
".",
"Key",
"(",
")",
",",
"item",
".",
"Version",
"(",
")",
",",
"item",
".",
"meta",
")"... | // String returns a string representation of Item | [
"String",
"returns",
"a",
"string",
"representation",
"of",
"Item"
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/iterator.go#L59-L61 | test |
dgraph-io/badger | iterator.go | KeyCopy | func (item *Item) KeyCopy(dst []byte) []byte {
return y.SafeCopy(dst, item.key)
} | go | func (item *Item) KeyCopy(dst []byte) []byte {
return y.SafeCopy(dst, item.key)
} | [
"func",
"(",
"item",
"*",
"Item",
")",
"KeyCopy",
"(",
"dst",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"return",
"y",
".",
"SafeCopy",
"(",
"dst",
",",
"item",
".",
"key",
")",
"\n",
"}"
] | // KeyCopy returns a copy of the key of the item, writing it to dst slice.
// If nil is passed, or capacity of dst isn't sufficient, a new slice would be allocated and
// returned. | [
"KeyCopy",
"returns",
"a",
"copy",
"of",
"the",
"key",
"of",
"the",
"item",
"writing",
"it",
"to",
"dst",
"slice",
".",
"If",
"nil",
"is",
"passed",
"or",
"capacity",
"of",
"dst",
"isn",
"t",
"sufficient",
"a",
"new",
"slice",
"would",
"be",
"allocated... | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/iterator.go#L74-L76 | test |
dgraph-io/badger | iterator.go | ValueSize | func (item *Item) ValueSize() int64 {
if !item.hasValue() {
return 0
}
if (item.meta & bitValuePointer) == 0 {
return int64(len(item.vptr))
}
var vp valuePointer
vp.Decode(item.vptr)
klen := int64(len(item.key) + 8) // 8 bytes for timestamp.
return int64(vp.Len) - klen - headerBufSize - crc32.Size
} | go | func (item *Item) ValueSize() int64 {
if !item.hasValue() {
return 0
}
if (item.meta & bitValuePointer) == 0 {
return int64(len(item.vptr))
}
var vp valuePointer
vp.Decode(item.vptr)
klen := int64(len(item.key) + 8) // 8 bytes for timestamp.
return int64(vp.Len) - klen - headerBufSize - crc32.Size
} | [
"func",
"(",
"item",
"*",
"Item",
")",
"ValueSize",
"(",
")",
"int64",
"{",
"if",
"!",
"item",
".",
"hasValue",
"(",
")",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"(",
"item",
".",
"meta",
"&",
"bitValuePointer",
")",
"==",
"0",
"{",
"return",
... | // ValueSize returns the exact size of the value.
//
// This can be called to quickly estimate the size of a value without fetching
// it. | [
"ValueSize",
"returns",
"the",
"exact",
"size",
"of",
"the",
"value",
".",
"This",
"can",
"be",
"called",
"to",
"quickly",
"estimate",
"the",
"size",
"of",
"a",
"value",
"without",
"fetching",
"it",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/iterator.go#L259-L271 | test |
dgraph-io/badger | iterator.go | NewKeyIterator | func (txn *Txn) NewKeyIterator(key []byte, opt IteratorOptions) *Iterator {
if len(opt.Prefix) > 0 {
panic("opt.Prefix should be nil for NewKeyIterator.")
}
opt.Prefix = key // This key must be without the timestamp.
opt.prefixIsKey = true
return txn.NewIterator(opt)
} | go | func (txn *Txn) NewKeyIterator(key []byte, opt IteratorOptions) *Iterator {
if len(opt.Prefix) > 0 {
panic("opt.Prefix should be nil for NewKeyIterator.")
}
opt.Prefix = key // This key must be without the timestamp.
opt.prefixIsKey = true
return txn.NewIterator(opt)
} | [
"func",
"(",
"txn",
"*",
"Txn",
")",
"NewKeyIterator",
"(",
"key",
"[",
"]",
"byte",
",",
"opt",
"IteratorOptions",
")",
"*",
"Iterator",
"{",
"if",
"len",
"(",
"opt",
".",
"Prefix",
")",
">",
"0",
"{",
"panic",
"(",
"\"opt.Prefix should be nil for NewKe... | // NewKeyIterator is just like NewIterator, but allows the user to iterate over all versions of a
// single key. Internally, it sets the Prefix option in provided opt, and uses that prefix to
// additionally run bloom filter lookups before picking tables from the LSM tree. | [
"NewKeyIterator",
"is",
"just",
"like",
"NewIterator",
"but",
"allows",
"the",
"user",
"to",
"iterate",
"over",
"all",
"versions",
"of",
"a",
"single",
"key",
".",
"Internally",
"it",
"sets",
"the",
"Prefix",
"option",
"in",
"provided",
"opt",
"and",
"uses",... | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/iterator.go#L430-L437 | test |
dgraph-io/badger | iterator.go | Valid | func (it *Iterator) Valid() bool {
if it.item == nil {
return false
}
return bytes.HasPrefix(it.item.key, it.opt.Prefix)
} | go | func (it *Iterator) Valid() bool {
if it.item == nil {
return false
}
return bytes.HasPrefix(it.item.key, it.opt.Prefix)
} | [
"func",
"(",
"it",
"*",
"Iterator",
")",
"Valid",
"(",
")",
"bool",
"{",
"if",
"it",
".",
"item",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"bytes",
".",
"HasPrefix",
"(",
"it",
".",
"item",
".",
"key",
",",
"it",
".",
"op... | // Valid returns false when iteration is done. | [
"Valid",
"returns",
"false",
"when",
"iteration",
"is",
"done",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/iterator.go#L456-L461 | test |
dgraph-io/badger | iterator.go | ValidForPrefix | func (it *Iterator) ValidForPrefix(prefix []byte) bool {
return it.Valid() && bytes.HasPrefix(it.item.key, prefix)
} | go | func (it *Iterator) ValidForPrefix(prefix []byte) bool {
return it.Valid() && bytes.HasPrefix(it.item.key, prefix)
} | [
"func",
"(",
"it",
"*",
"Iterator",
")",
"ValidForPrefix",
"(",
"prefix",
"[",
"]",
"byte",
")",
"bool",
"{",
"return",
"it",
".",
"Valid",
"(",
")",
"&&",
"bytes",
".",
"HasPrefix",
"(",
"it",
".",
"item",
".",
"key",
",",
"prefix",
")",
"\n",
"... | // ValidForPrefix returns false when iteration is done
// or when the current key is not prefixed by the specified prefix. | [
"ValidForPrefix",
"returns",
"false",
"when",
"iteration",
"is",
"done",
"or",
"when",
"the",
"current",
"key",
"is",
"not",
"prefixed",
"by",
"the",
"specified",
"prefix",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/iterator.go#L465-L467 | test |
dgraph-io/badger | iterator.go | Close | func (it *Iterator) Close() {
if it.closed {
return
}
it.closed = true
it.iitr.Close()
// It is important to wait for the fill goroutines to finish. Otherwise, we might leave zombie
// goroutines behind, which are waiting to acquire file read locks after DB has been closed.
waitFor := func(l list) {
item :=... | go | func (it *Iterator) Close() {
if it.closed {
return
}
it.closed = true
it.iitr.Close()
// It is important to wait for the fill goroutines to finish. Otherwise, we might leave zombie
// goroutines behind, which are waiting to acquire file read locks after DB has been closed.
waitFor := func(l list) {
item :=... | [
"func",
"(",
"it",
"*",
"Iterator",
")",
"Close",
"(",
")",
"{",
"if",
"it",
".",
"closed",
"{",
"return",
"\n",
"}",
"\n",
"it",
".",
"closed",
"=",
"true",
"\n",
"it",
".",
"iitr",
".",
"Close",
"(",
")",
"\n",
"waitFor",
":=",
"func",
"(",
... | // Close would close the iterator. It is important to call this when you're done with iteration. | [
"Close",
"would",
"close",
"the",
"iterator",
".",
"It",
"is",
"important",
"to",
"call",
"this",
"when",
"you",
"re",
"done",
"with",
"iteration",
"."
] | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/iterator.go#L470-L492 | test |
dgraph-io/badger | iterator.go | parseItem | func (it *Iterator) parseItem() bool {
mi := it.iitr
key := mi.Key()
setItem := func(item *Item) {
if it.item == nil {
it.item = item
} else {
it.data.push(item)
}
}
// Skip badger keys.
if !it.opt.internalAccess && bytes.HasPrefix(key, badgerPrefix) {
mi.Next()
return false
}
// Skip any ver... | go | func (it *Iterator) parseItem() bool {
mi := it.iitr
key := mi.Key()
setItem := func(item *Item) {
if it.item == nil {
it.item = item
} else {
it.data.push(item)
}
}
// Skip badger keys.
if !it.opt.internalAccess && bytes.HasPrefix(key, badgerPrefix) {
mi.Next()
return false
}
// Skip any ver... | [
"func",
"(",
"it",
"*",
"Iterator",
")",
"parseItem",
"(",
")",
"bool",
"{",
"mi",
":=",
"it",
".",
"iitr",
"\n",
"key",
":=",
"mi",
".",
"Key",
"(",
")",
"\n",
"setItem",
":=",
"func",
"(",
"item",
"*",
"Item",
")",
"{",
"if",
"it",
".",
"it... | // parseItem is a complex function because it needs to handle both forward and reverse iteration
// implementation. We store keys such that their versions are sorted in descending order. This makes
// forward iteration efficient, but revese iteration complicated. This tradeoff is better because
// forward iteration is ... | [
"parseItem",
"is",
"a",
"complex",
"function",
"because",
"it",
"needs",
"to",
"handle",
"both",
"forward",
"and",
"reverse",
"iteration",
"implementation",
".",
"We",
"store",
"keys",
"such",
"that",
"their",
"versions",
"are",
"sorted",
"in",
"descending",
"... | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/iterator.go#L529-L608 | test |
dgraph-io/badger | iterator.go | Seek | func (it *Iterator) Seek(key []byte) {
for i := it.data.pop(); i != nil; i = it.data.pop() {
i.wg.Wait()
it.waste.push(i)
}
it.lastKey = it.lastKey[:0]
if len(key) == 0 {
key = it.opt.Prefix
}
if len(key) == 0 {
it.iitr.Rewind()
it.prefetch()
return
}
if !it.opt.Reverse {
key = y.KeyWithTs(key, ... | go | func (it *Iterator) Seek(key []byte) {
for i := it.data.pop(); i != nil; i = it.data.pop() {
i.wg.Wait()
it.waste.push(i)
}
it.lastKey = it.lastKey[:0]
if len(key) == 0 {
key = it.opt.Prefix
}
if len(key) == 0 {
it.iitr.Rewind()
it.prefetch()
return
}
if !it.opt.Reverse {
key = y.KeyWithTs(key, ... | [
"func",
"(",
"it",
"*",
"Iterator",
")",
"Seek",
"(",
"key",
"[",
"]",
"byte",
")",
"{",
"for",
"i",
":=",
"it",
".",
"data",
".",
"pop",
"(",
")",
";",
"i",
"!=",
"nil",
";",
"i",
"=",
"it",
".",
"data",
".",
"pop",
"(",
")",
"{",
"i",
... | // Seek would seek to the provided key if present. If absent, it would seek to the next smallest key
// greater than the provided key if iterating in the forward direction. Behavior would be reversed if
// iterating backwards. | [
"Seek",
"would",
"seek",
"to",
"the",
"provided",
"key",
"if",
"present",
".",
"If",
"absent",
"it",
"would",
"seek",
"to",
"the",
"next",
"smallest",
"key",
"greater",
"than",
"the",
"provided",
"key",
"if",
"iterating",
"in",
"the",
"forward",
"direction... | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/iterator.go#L654-L677 | test |
dgraph-io/badger | merge.go | GetMergeOperator | func (db *DB) GetMergeOperator(key []byte,
f MergeFunc, dur time.Duration) *MergeOperator {
op := &MergeOperator{
f: f,
db: db,
key: key,
closer: y.NewCloser(1),
}
go op.runCompactions(dur)
return op
} | go | func (db *DB) GetMergeOperator(key []byte,
f MergeFunc, dur time.Duration) *MergeOperator {
op := &MergeOperator{
f: f,
db: db,
key: key,
closer: y.NewCloser(1),
}
go op.runCompactions(dur)
return op
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"GetMergeOperator",
"(",
"key",
"[",
"]",
"byte",
",",
"f",
"MergeFunc",
",",
"dur",
"time",
".",
"Duration",
")",
"*",
"MergeOperator",
"{",
"op",
":=",
"&",
"MergeOperator",
"{",
"f",
":",
"f",
",",
"db",
":",
... | // GetMergeOperator creates a new MergeOperator for a given key and returns a
// pointer to it. It also fires off a goroutine that performs a compaction using
// the merge function that runs periodically, as specified by dur. | [
"GetMergeOperator",
"creates",
"a",
"new",
"MergeOperator",
"for",
"a",
"given",
"key",
"and",
"returns",
"a",
"pointer",
"to",
"it",
".",
"It",
"also",
"fires",
"off",
"a",
"goroutine",
"that",
"performs",
"a",
"compaction",
"using",
"the",
"merge",
"functi... | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/merge.go#L48-L59 | test |
dgraph-io/badger | merge.go | Get | func (op *MergeOperator) Get() ([]byte, error) {
op.RLock()
defer op.RUnlock()
var existing []byte
err := op.db.View(func(txn *Txn) (err error) {
existing, err = op.iterateAndMerge(txn)
return err
})
if err == errNoMerge {
return existing, nil
}
return existing, err
} | go | func (op *MergeOperator) Get() ([]byte, error) {
op.RLock()
defer op.RUnlock()
var existing []byte
err := op.db.View(func(txn *Txn) (err error) {
existing, err = op.iterateAndMerge(txn)
return err
})
if err == errNoMerge {
return existing, nil
}
return existing, err
} | [
"func",
"(",
"op",
"*",
"MergeOperator",
")",
"Get",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"op",
".",
"RLock",
"(",
")",
"\n",
"defer",
"op",
".",
"RUnlock",
"(",
")",
"\n",
"var",
"existing",
"[",
"]",
"byte",
"\n",
"err",
... | // Get returns the latest value for the merge operator, which is derived by
// applying the merge function to all the values added so far.
//
// If Add has not been called even once, Get will return ErrKeyNotFound. | [
"Get",
"returns",
"the",
"latest",
"value",
"for",
"the",
"merge",
"operator",
"which",
"is",
"derived",
"by",
"applying",
"the",
"merge",
"function",
"to",
"all",
"the",
"values",
"added",
"so",
"far",
".",
"If",
"Add",
"has",
"not",
"been",
"called",
"... | 6b796b3ebec3ff006fcb1b425836cd784651e9fd | https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/merge.go#L155-L167 | test |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.