repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
list | docstring
stringlengths 6
2.61k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
syndtr/goleveldb
|
leveldb/cache/cache.go
|
Delete
|
func (r *Cache) Delete(ns, key uint64, onDel func()) bool {
r.mu.RLock()
defer r.mu.RUnlock()
if r.closed {
return false
}
hash := murmur32(ns, key, 0xf00)
for {
h, b := r.getBucket(hash)
done, _, n := b.get(r, h, hash, ns, key, true)
if done {
if n != nil {
if onDel != nil {
n.mu.Lock()
n.onDel = append(n.onDel, onDel)
n.mu.Unlock()
}
if r.cacher != nil {
r.cacher.Ban(n)
}
n.unref()
return true
}
break
}
}
if onDel != nil {
onDel()
}
return false
}
|
go
|
func (r *Cache) Delete(ns, key uint64, onDel func()) bool {
r.mu.RLock()
defer r.mu.RUnlock()
if r.closed {
return false
}
hash := murmur32(ns, key, 0xf00)
for {
h, b := r.getBucket(hash)
done, _, n := b.get(r, h, hash, ns, key, true)
if done {
if n != nil {
if onDel != nil {
n.mu.Lock()
n.onDel = append(n.onDel, onDel)
n.mu.Unlock()
}
if r.cacher != nil {
r.cacher.Ban(n)
}
n.unref()
return true
}
break
}
}
if onDel != nil {
onDel()
}
return false
}
|
[
"func",
"(",
"r",
"*",
"Cache",
")",
"Delete",
"(",
"ns",
",",
"key",
"uint64",
",",
"onDel",
"func",
"(",
")",
")",
"bool",
"{",
"r",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"r",
".",
"closed",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"hash",
":=",
"murmur32",
"(",
"ns",
",",
"key",
",",
"0xf00",
")",
"\n",
"for",
"{",
"h",
",",
"b",
":=",
"r",
".",
"getBucket",
"(",
"hash",
")",
"\n",
"done",
",",
"_",
",",
"n",
":=",
"b",
".",
"get",
"(",
"r",
",",
"h",
",",
"hash",
",",
"ns",
",",
"key",
",",
"true",
")",
"\n",
"if",
"done",
"{",
"if",
"n",
"!=",
"nil",
"{",
"if",
"onDel",
"!=",
"nil",
"{",
"n",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"n",
".",
"onDel",
"=",
"append",
"(",
"n",
".",
"onDel",
",",
"onDel",
")",
"\n",
"n",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"if",
"r",
".",
"cacher",
"!=",
"nil",
"{",
"r",
".",
"cacher",
".",
"Ban",
"(",
"n",
")",
"\n",
"}",
"\n",
"n",
".",
"unref",
"(",
")",
"\n",
"return",
"true",
"\n",
"}",
"\n\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"onDel",
"!=",
"nil",
"{",
"onDel",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// Delete removes and ban 'cache node' with the given namespace and key.
// A banned 'cache node' will never inserted into the 'cache tree'. Ban
// only attributed to the particular 'cache node', so when a 'cache node'
// is recreated it will not be banned.
//
// If onDel is not nil, then it will be executed if such 'cache node'
// doesn't exist or once the 'cache node' is released.
//
// Delete return true is such 'cache node' exist.
|
[
"Delete",
"removes",
"and",
"ban",
"cache",
"node",
"with",
"the",
"given",
"namespace",
"and",
"key",
".",
"A",
"banned",
"cache",
"node",
"will",
"never",
"inserted",
"into",
"the",
"cache",
"tree",
".",
"Ban",
"only",
"attributed",
"to",
"the",
"particular",
"cache",
"node",
"so",
"when",
"a",
"cache",
"node",
"is",
"recreated",
"it",
"will",
"not",
"be",
"banned",
".",
"If",
"onDel",
"is",
"not",
"nil",
"then",
"it",
"will",
"be",
"executed",
"if",
"such",
"cache",
"node",
"doesn",
"t",
"exist",
"or",
"once",
"the",
"cache",
"node",
"is",
"released",
".",
"Delete",
"return",
"true",
"is",
"such",
"cache",
"node",
"exist",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/cache/cache.go#L419-L453
|
train
|
syndtr/goleveldb
|
leveldb/cache/cache.go
|
Evict
|
func (r *Cache) Evict(ns, key uint64) bool {
r.mu.RLock()
defer r.mu.RUnlock()
if r.closed {
return false
}
hash := murmur32(ns, key, 0xf00)
for {
h, b := r.getBucket(hash)
done, _, n := b.get(r, h, hash, ns, key, true)
if done {
if n != nil {
if r.cacher != nil {
r.cacher.Evict(n)
}
n.unref()
return true
}
break
}
}
return false
}
|
go
|
func (r *Cache) Evict(ns, key uint64) bool {
r.mu.RLock()
defer r.mu.RUnlock()
if r.closed {
return false
}
hash := murmur32(ns, key, 0xf00)
for {
h, b := r.getBucket(hash)
done, _, n := b.get(r, h, hash, ns, key, true)
if done {
if n != nil {
if r.cacher != nil {
r.cacher.Evict(n)
}
n.unref()
return true
}
break
}
}
return false
}
|
[
"func",
"(",
"r",
"*",
"Cache",
")",
"Evict",
"(",
"ns",
",",
"key",
"uint64",
")",
"bool",
"{",
"r",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"r",
".",
"closed",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"hash",
":=",
"murmur32",
"(",
"ns",
",",
"key",
",",
"0xf00",
")",
"\n",
"for",
"{",
"h",
",",
"b",
":=",
"r",
".",
"getBucket",
"(",
"hash",
")",
"\n",
"done",
",",
"_",
",",
"n",
":=",
"b",
".",
"get",
"(",
"r",
",",
"h",
",",
"hash",
",",
"ns",
",",
"key",
",",
"true",
")",
"\n",
"if",
"done",
"{",
"if",
"n",
"!=",
"nil",
"{",
"if",
"r",
".",
"cacher",
"!=",
"nil",
"{",
"r",
".",
"cacher",
".",
"Evict",
"(",
"n",
")",
"\n",
"}",
"\n",
"n",
".",
"unref",
"(",
")",
"\n",
"return",
"true",
"\n",
"}",
"\n\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// Evict evicts 'cache node' with the given namespace and key. This will
// simply call Cacher.Evict.
//
// Evict return true is such 'cache node' exist.
|
[
"Evict",
"evicts",
"cache",
"node",
"with",
"the",
"given",
"namespace",
"and",
"key",
".",
"This",
"will",
"simply",
"call",
"Cacher",
".",
"Evict",
".",
"Evict",
"return",
"true",
"is",
"such",
"cache",
"node",
"exist",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/cache/cache.go#L459-L484
|
train
|
syndtr/goleveldb
|
leveldb/cache/cache.go
|
EvictNS
|
func (r *Cache) EvictNS(ns uint64) {
r.mu.RLock()
defer r.mu.RUnlock()
if r.closed {
return
}
if r.cacher != nil {
r.cacher.EvictNS(ns)
}
}
|
go
|
func (r *Cache) EvictNS(ns uint64) {
r.mu.RLock()
defer r.mu.RUnlock()
if r.closed {
return
}
if r.cacher != nil {
r.cacher.EvictNS(ns)
}
}
|
[
"func",
"(",
"r",
"*",
"Cache",
")",
"EvictNS",
"(",
"ns",
"uint64",
")",
"{",
"r",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"r",
".",
"closed",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"cacher",
"!=",
"nil",
"{",
"r",
".",
"cacher",
".",
"EvictNS",
"(",
"ns",
")",
"\n",
"}",
"\n",
"}"
] |
// EvictNS evicts 'cache node' with the given namespace. This will
// simply call Cacher.EvictNS.
|
[
"EvictNS",
"evicts",
"cache",
"node",
"with",
"the",
"given",
"namespace",
".",
"This",
"will",
"simply",
"call",
"Cacher",
".",
"EvictNS",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/cache/cache.go#L488-L498
|
train
|
syndtr/goleveldb
|
leveldb/cache/cache.go
|
EvictAll
|
func (r *Cache) EvictAll() {
r.mu.RLock()
defer r.mu.RUnlock()
if r.closed {
return
}
if r.cacher != nil {
r.cacher.EvictAll()
}
}
|
go
|
func (r *Cache) EvictAll() {
r.mu.RLock()
defer r.mu.RUnlock()
if r.closed {
return
}
if r.cacher != nil {
r.cacher.EvictAll()
}
}
|
[
"func",
"(",
"r",
"*",
"Cache",
")",
"EvictAll",
"(",
")",
"{",
"r",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"r",
".",
"closed",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"cacher",
"!=",
"nil",
"{",
"r",
".",
"cacher",
".",
"EvictAll",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// EvictAll evicts all 'cache node'. This will simply call Cacher.EvictAll.
|
[
"EvictAll",
"evicts",
"all",
"cache",
"node",
".",
"This",
"will",
"simply",
"call",
"Cacher",
".",
"EvictAll",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/cache/cache.go#L501-L511
|
train
|
syndtr/goleveldb
|
leveldb/cache/cache.go
|
Close
|
func (r *Cache) Close() error {
r.mu.Lock()
if !r.closed {
r.closed = true
h := (*mNode)(r.mHead)
h.initBuckets()
for i := range h.buckets {
b := (*mBucket)(h.buckets[i])
for _, n := range b.node {
// Call releaser.
if n.value != nil {
if r, ok := n.value.(util.Releaser); ok {
r.Release()
}
n.value = nil
}
// Call OnDel.
for _, f := range n.onDel {
f()
}
n.onDel = nil
}
}
}
r.mu.Unlock()
// Avoid deadlock.
if r.cacher != nil {
if err := r.cacher.Close(); err != nil {
return err
}
}
return nil
}
|
go
|
func (r *Cache) Close() error {
r.mu.Lock()
if !r.closed {
r.closed = true
h := (*mNode)(r.mHead)
h.initBuckets()
for i := range h.buckets {
b := (*mBucket)(h.buckets[i])
for _, n := range b.node {
// Call releaser.
if n.value != nil {
if r, ok := n.value.(util.Releaser); ok {
r.Release()
}
n.value = nil
}
// Call OnDel.
for _, f := range n.onDel {
f()
}
n.onDel = nil
}
}
}
r.mu.Unlock()
// Avoid deadlock.
if r.cacher != nil {
if err := r.cacher.Close(); err != nil {
return err
}
}
return nil
}
|
[
"func",
"(",
"r",
"*",
"Cache",
")",
"Close",
"(",
")",
"error",
"{",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"!",
"r",
".",
"closed",
"{",
"r",
".",
"closed",
"=",
"true",
"\n\n",
"h",
":=",
"(",
"*",
"mNode",
")",
"(",
"r",
".",
"mHead",
")",
"\n",
"h",
".",
"initBuckets",
"(",
")",
"\n\n",
"for",
"i",
":=",
"range",
"h",
".",
"buckets",
"{",
"b",
":=",
"(",
"*",
"mBucket",
")",
"(",
"h",
".",
"buckets",
"[",
"i",
"]",
")",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"b",
".",
"node",
"{",
"// Call releaser.",
"if",
"n",
".",
"value",
"!=",
"nil",
"{",
"if",
"r",
",",
"ok",
":=",
"n",
".",
"value",
".",
"(",
"util",
".",
"Releaser",
")",
";",
"ok",
"{",
"r",
".",
"Release",
"(",
")",
"\n",
"}",
"\n",
"n",
".",
"value",
"=",
"nil",
"\n",
"}",
"\n\n",
"// Call OnDel.",
"for",
"_",
",",
"f",
":=",
"range",
"n",
".",
"onDel",
"{",
"f",
"(",
")",
"\n",
"}",
"\n",
"n",
".",
"onDel",
"=",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Avoid deadlock.",
"if",
"r",
".",
"cacher",
"!=",
"nil",
"{",
"if",
"err",
":=",
"r",
".",
"cacher",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Close closes the 'cache map' and forcefully releases all 'cache node'.
|
[
"Close",
"closes",
"the",
"cache",
"map",
"and",
"forcefully",
"releases",
"all",
"cache",
"node",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/cache/cache.go#L514-L550
|
train
|
syndtr/goleveldb
|
leveldb/cache/cache.go
|
CloseWeak
|
func (r *Cache) CloseWeak() error {
r.mu.Lock()
if !r.closed {
r.closed = true
}
r.mu.Unlock()
// Avoid deadlock.
if r.cacher != nil {
r.cacher.EvictAll()
if err := r.cacher.Close(); err != nil {
return err
}
}
return nil
}
|
go
|
func (r *Cache) CloseWeak() error {
r.mu.Lock()
if !r.closed {
r.closed = true
}
r.mu.Unlock()
// Avoid deadlock.
if r.cacher != nil {
r.cacher.EvictAll()
if err := r.cacher.Close(); err != nil {
return err
}
}
return nil
}
|
[
"func",
"(",
"r",
"*",
"Cache",
")",
"CloseWeak",
"(",
")",
"error",
"{",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"!",
"r",
".",
"closed",
"{",
"r",
".",
"closed",
"=",
"true",
"\n",
"}",
"\n",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Avoid deadlock.",
"if",
"r",
".",
"cacher",
"!=",
"nil",
"{",
"r",
".",
"cacher",
".",
"EvictAll",
"(",
")",
"\n",
"if",
"err",
":=",
"r",
".",
"cacher",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// CloseWeak closes the 'cache map' and evict all 'cache node' from cacher, but
// unlike Close it doesn't forcefully releases 'cache node'.
|
[
"CloseWeak",
"closes",
"the",
"cache",
"map",
"and",
"evict",
"all",
"cache",
"node",
"from",
"cacher",
"but",
"unlike",
"Close",
"it",
"doesn",
"t",
"forcefully",
"releases",
"cache",
"node",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/cache/cache.go#L554-L569
|
train
|
syndtr/goleveldb
|
leveldb/cache/cache.go
|
GetHandle
|
func (n *Node) GetHandle() *Handle {
if atomic.AddInt32(&n.ref, 1) <= 1 {
panic("BUG: Node.GetHandle on zero ref")
}
return &Handle{unsafe.Pointer(n)}
}
|
go
|
func (n *Node) GetHandle() *Handle {
if atomic.AddInt32(&n.ref, 1) <= 1 {
panic("BUG: Node.GetHandle on zero ref")
}
return &Handle{unsafe.Pointer(n)}
}
|
[
"func",
"(",
"n",
"*",
"Node",
")",
"GetHandle",
"(",
")",
"*",
"Handle",
"{",
"if",
"atomic",
".",
"AddInt32",
"(",
"&",
"n",
".",
"ref",
",",
"1",
")",
"<=",
"1",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"&",
"Handle",
"{",
"unsafe",
".",
"Pointer",
"(",
"n",
")",
"}",
"\n",
"}"
] |
// GetHandle returns an handle for this 'cache node'.
|
[
"GetHandle",
"returns",
"an",
"handle",
"for",
"this",
"cache",
"node",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/cache/cache.go#L614-L619
|
train
|
syndtr/goleveldb
|
leveldb/cache/cache.go
|
Value
|
func (h *Handle) Value() Value {
n := (*Node)(atomic.LoadPointer(&h.n))
if n != nil {
return n.value
}
return nil
}
|
go
|
func (h *Handle) Value() Value {
n := (*Node)(atomic.LoadPointer(&h.n))
if n != nil {
return n.value
}
return nil
}
|
[
"func",
"(",
"h",
"*",
"Handle",
")",
"Value",
"(",
")",
"Value",
"{",
"n",
":=",
"(",
"*",
"Node",
")",
"(",
"atomic",
".",
"LoadPointer",
"(",
"&",
"h",
".",
"n",
")",
")",
"\n",
"if",
"n",
"!=",
"nil",
"{",
"return",
"n",
".",
"value",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Value returns the value of the 'cache node'.
|
[
"Value",
"returns",
"the",
"value",
"of",
"the",
"cache",
"node",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/cache/cache.go#L643-L649
|
train
|
syndtr/goleveldb
|
leveldb/cache/cache.go
|
Release
|
func (h *Handle) Release() {
nPtr := atomic.LoadPointer(&h.n)
if nPtr != nil && atomic.CompareAndSwapPointer(&h.n, nPtr, nil) {
n := (*Node)(nPtr)
n.unrefLocked()
}
}
|
go
|
func (h *Handle) Release() {
nPtr := atomic.LoadPointer(&h.n)
if nPtr != nil && atomic.CompareAndSwapPointer(&h.n, nPtr, nil) {
n := (*Node)(nPtr)
n.unrefLocked()
}
}
|
[
"func",
"(",
"h",
"*",
"Handle",
")",
"Release",
"(",
")",
"{",
"nPtr",
":=",
"atomic",
".",
"LoadPointer",
"(",
"&",
"h",
".",
"n",
")",
"\n",
"if",
"nPtr",
"!=",
"nil",
"&&",
"atomic",
".",
"CompareAndSwapPointer",
"(",
"&",
"h",
".",
"n",
",",
"nPtr",
",",
"nil",
")",
"{",
"n",
":=",
"(",
"*",
"Node",
")",
"(",
"nPtr",
")",
"\n",
"n",
".",
"unrefLocked",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// Release releases this 'cache handle'.
// It is safe to call release multiple times.
|
[
"Release",
"releases",
"this",
"cache",
"handle",
".",
"It",
"is",
"safe",
"to",
"call",
"release",
"multiple",
"times",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/cache/cache.go#L653-L659
|
train
|
syndtr/goleveldb
|
leveldb/util/hash.go
|
Hash
|
func Hash(data []byte, seed uint32) uint32 {
// Similar to murmur hash
const (
m = uint32(0xc6a4a793)
r = uint32(24)
)
var (
h = seed ^ (uint32(len(data)) * m)
i int
)
for n := len(data) - len(data)%4; i < n; i += 4 {
h += binary.LittleEndian.Uint32(data[i:])
h *= m
h ^= (h >> 16)
}
switch len(data) - i {
default:
panic("not reached")
case 3:
h += uint32(data[i+2]) << 16
fallthrough
case 2:
h += uint32(data[i+1]) << 8
fallthrough
case 1:
h += uint32(data[i])
h *= m
h ^= (h >> r)
case 0:
}
return h
}
|
go
|
func Hash(data []byte, seed uint32) uint32 {
// Similar to murmur hash
const (
m = uint32(0xc6a4a793)
r = uint32(24)
)
var (
h = seed ^ (uint32(len(data)) * m)
i int
)
for n := len(data) - len(data)%4; i < n; i += 4 {
h += binary.LittleEndian.Uint32(data[i:])
h *= m
h ^= (h >> 16)
}
switch len(data) - i {
default:
panic("not reached")
case 3:
h += uint32(data[i+2]) << 16
fallthrough
case 2:
h += uint32(data[i+1]) << 8
fallthrough
case 1:
h += uint32(data[i])
h *= m
h ^= (h >> r)
case 0:
}
return h
}
|
[
"func",
"Hash",
"(",
"data",
"[",
"]",
"byte",
",",
"seed",
"uint32",
")",
"uint32",
"{",
"// Similar to murmur hash",
"const",
"(",
"m",
"=",
"uint32",
"(",
"0xc6a4a793",
")",
"\n",
"r",
"=",
"uint32",
"(",
"24",
")",
"\n",
")",
"\n",
"var",
"(",
"h",
"=",
"seed",
"^",
"(",
"uint32",
"(",
"len",
"(",
"data",
")",
")",
"*",
"m",
")",
"\n",
"i",
"int",
"\n",
")",
"\n\n",
"for",
"n",
":=",
"len",
"(",
"data",
")",
"-",
"len",
"(",
"data",
")",
"%",
"4",
";",
"i",
"<",
"n",
";",
"i",
"+=",
"4",
"{",
"h",
"+=",
"binary",
".",
"LittleEndian",
".",
"Uint32",
"(",
"data",
"[",
"i",
":",
"]",
")",
"\n",
"h",
"*=",
"m",
"\n",
"h",
"^=",
"(",
"h",
">>",
"16",
")",
"\n",
"}",
"\n\n",
"switch",
"len",
"(",
"data",
")",
"-",
"i",
"{",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"case",
"3",
":",
"h",
"+=",
"uint32",
"(",
"data",
"[",
"i",
"+",
"2",
"]",
")",
"<<",
"16",
"\n",
"fallthrough",
"\n",
"case",
"2",
":",
"h",
"+=",
"uint32",
"(",
"data",
"[",
"i",
"+",
"1",
"]",
")",
"<<",
"8",
"\n",
"fallthrough",
"\n",
"case",
"1",
":",
"h",
"+=",
"uint32",
"(",
"data",
"[",
"i",
"]",
")",
"\n",
"h",
"*=",
"m",
"\n",
"h",
"^=",
"(",
"h",
">>",
"r",
")",
"\n",
"case",
"0",
":",
"}",
"\n\n",
"return",
"h",
"\n",
"}"
] |
// Hash return hash of the given data.
|
[
"Hash",
"return",
"hash",
"of",
"the",
"given",
"data",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/util/hash.go#L14-L48
|
train
|
syndtr/goleveldb
|
leveldb/db_write.go
|
writeLocked
|
func (db *DB) writeLocked(batch, ourBatch *Batch, merge, sync bool) error {
// Try to flush memdb. This method would also trying to throttle writes
// if it is too fast and compaction cannot catch-up.
mdb, mdbFree, err := db.flush(batch.internalLen)
if err != nil {
db.unlockWrite(false, 0, err)
return err
}
defer mdb.decref()
var (
overflow bool
merged int
batches = []*Batch{batch}
)
if merge {
// Merge limit.
var mergeLimit int
if batch.internalLen > 128<<10 {
mergeLimit = (1 << 20) - batch.internalLen
} else {
mergeLimit = 128 << 10
}
mergeCap := mdbFree - batch.internalLen
if mergeLimit > mergeCap {
mergeLimit = mergeCap
}
merge:
for mergeLimit > 0 {
select {
case incoming := <-db.writeMergeC:
if incoming.batch != nil {
// Merge batch.
if incoming.batch.internalLen > mergeLimit {
overflow = true
break merge
}
batches = append(batches, incoming.batch)
mergeLimit -= incoming.batch.internalLen
} else {
// Merge put.
internalLen := len(incoming.key) + len(incoming.value) + 8
if internalLen > mergeLimit {
overflow = true
break merge
}
if ourBatch == nil {
ourBatch = db.batchPool.Get().(*Batch)
ourBatch.Reset()
batches = append(batches, ourBatch)
}
// We can use same batch since concurrent write doesn't
// guarantee write order.
ourBatch.appendRec(incoming.keyType, incoming.key, incoming.value)
mergeLimit -= internalLen
}
sync = sync || incoming.sync
merged++
db.writeMergedC <- true
default:
break merge
}
}
}
// Release ourBatch if any.
if ourBatch != nil {
defer db.batchPool.Put(ourBatch)
}
// Seq number.
seq := db.seq + 1
// Write journal.
if err := db.writeJournal(batches, seq, sync); err != nil {
db.unlockWrite(overflow, merged, err)
return err
}
// Put batches.
for _, batch := range batches {
if err := batch.putMem(seq, mdb.DB); err != nil {
panic(err)
}
seq += uint64(batch.Len())
}
// Incr seq number.
db.addSeq(uint64(batchesLen(batches)))
// Rotate memdb if it's reach the threshold.
if batch.internalLen >= mdbFree {
db.rotateMem(0, false)
}
db.unlockWrite(overflow, merged, nil)
return nil
}
|
go
|
func (db *DB) writeLocked(batch, ourBatch *Batch, merge, sync bool) error {
// Try to flush memdb. This method would also trying to throttle writes
// if it is too fast and compaction cannot catch-up.
mdb, mdbFree, err := db.flush(batch.internalLen)
if err != nil {
db.unlockWrite(false, 0, err)
return err
}
defer mdb.decref()
var (
overflow bool
merged int
batches = []*Batch{batch}
)
if merge {
// Merge limit.
var mergeLimit int
if batch.internalLen > 128<<10 {
mergeLimit = (1 << 20) - batch.internalLen
} else {
mergeLimit = 128 << 10
}
mergeCap := mdbFree - batch.internalLen
if mergeLimit > mergeCap {
mergeLimit = mergeCap
}
merge:
for mergeLimit > 0 {
select {
case incoming := <-db.writeMergeC:
if incoming.batch != nil {
// Merge batch.
if incoming.batch.internalLen > mergeLimit {
overflow = true
break merge
}
batches = append(batches, incoming.batch)
mergeLimit -= incoming.batch.internalLen
} else {
// Merge put.
internalLen := len(incoming.key) + len(incoming.value) + 8
if internalLen > mergeLimit {
overflow = true
break merge
}
if ourBatch == nil {
ourBatch = db.batchPool.Get().(*Batch)
ourBatch.Reset()
batches = append(batches, ourBatch)
}
// We can use same batch since concurrent write doesn't
// guarantee write order.
ourBatch.appendRec(incoming.keyType, incoming.key, incoming.value)
mergeLimit -= internalLen
}
sync = sync || incoming.sync
merged++
db.writeMergedC <- true
default:
break merge
}
}
}
// Release ourBatch if any.
if ourBatch != nil {
defer db.batchPool.Put(ourBatch)
}
// Seq number.
seq := db.seq + 1
// Write journal.
if err := db.writeJournal(batches, seq, sync); err != nil {
db.unlockWrite(overflow, merged, err)
return err
}
// Put batches.
for _, batch := range batches {
if err := batch.putMem(seq, mdb.DB); err != nil {
panic(err)
}
seq += uint64(batch.Len())
}
// Incr seq number.
db.addSeq(uint64(batchesLen(batches)))
// Rotate memdb if it's reach the threshold.
if batch.internalLen >= mdbFree {
db.rotateMem(0, false)
}
db.unlockWrite(overflow, merged, nil)
return nil
}
|
[
"func",
"(",
"db",
"*",
"DB",
")",
"writeLocked",
"(",
"batch",
",",
"ourBatch",
"*",
"Batch",
",",
"merge",
",",
"sync",
"bool",
")",
"error",
"{",
"// Try to flush memdb. This method would also trying to throttle writes",
"// if it is too fast and compaction cannot catch-up.",
"mdb",
",",
"mdbFree",
",",
"err",
":=",
"db",
".",
"flush",
"(",
"batch",
".",
"internalLen",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"db",
".",
"unlockWrite",
"(",
"false",
",",
"0",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"mdb",
".",
"decref",
"(",
")",
"\n\n",
"var",
"(",
"overflow",
"bool",
"\n",
"merged",
"int",
"\n",
"batches",
"=",
"[",
"]",
"*",
"Batch",
"{",
"batch",
"}",
"\n",
")",
"\n\n",
"if",
"merge",
"{",
"// Merge limit.",
"var",
"mergeLimit",
"int",
"\n",
"if",
"batch",
".",
"internalLen",
">",
"128",
"<<",
"10",
"{",
"mergeLimit",
"=",
"(",
"1",
"<<",
"20",
")",
"-",
"batch",
".",
"internalLen",
"\n",
"}",
"else",
"{",
"mergeLimit",
"=",
"128",
"<<",
"10",
"\n",
"}",
"\n",
"mergeCap",
":=",
"mdbFree",
"-",
"batch",
".",
"internalLen",
"\n",
"if",
"mergeLimit",
">",
"mergeCap",
"{",
"mergeLimit",
"=",
"mergeCap",
"\n",
"}",
"\n\n",
"merge",
":",
"for",
"mergeLimit",
">",
"0",
"{",
"select",
"{",
"case",
"incoming",
":=",
"<-",
"db",
".",
"writeMergeC",
":",
"if",
"incoming",
".",
"batch",
"!=",
"nil",
"{",
"// Merge batch.",
"if",
"incoming",
".",
"batch",
".",
"internalLen",
">",
"mergeLimit",
"{",
"overflow",
"=",
"true",
"\n",
"break",
"merge",
"\n",
"}",
"\n",
"batches",
"=",
"append",
"(",
"batches",
",",
"incoming",
".",
"batch",
")",
"\n",
"mergeLimit",
"-=",
"incoming",
".",
"batch",
".",
"internalLen",
"\n",
"}",
"else",
"{",
"// Merge put.",
"internalLen",
":=",
"len",
"(",
"incoming",
".",
"key",
")",
"+",
"len",
"(",
"incoming",
".",
"value",
")",
"+",
"8",
"\n",
"if",
"internalLen",
">",
"mergeLimit",
"{",
"overflow",
"=",
"true",
"\n",
"break",
"merge",
"\n",
"}",
"\n",
"if",
"ourBatch",
"==",
"nil",
"{",
"ourBatch",
"=",
"db",
".",
"batchPool",
".",
"Get",
"(",
")",
".",
"(",
"*",
"Batch",
")",
"\n",
"ourBatch",
".",
"Reset",
"(",
")",
"\n",
"batches",
"=",
"append",
"(",
"batches",
",",
"ourBatch",
")",
"\n",
"}",
"\n",
"// We can use same batch since concurrent write doesn't",
"// guarantee write order.",
"ourBatch",
".",
"appendRec",
"(",
"incoming",
".",
"keyType",
",",
"incoming",
".",
"key",
",",
"incoming",
".",
"value",
")",
"\n",
"mergeLimit",
"-=",
"internalLen",
"\n",
"}",
"\n",
"sync",
"=",
"sync",
"||",
"incoming",
".",
"sync",
"\n",
"merged",
"++",
"\n",
"db",
".",
"writeMergedC",
"<-",
"true",
"\n\n",
"default",
":",
"break",
"merge",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Release ourBatch if any.",
"if",
"ourBatch",
"!=",
"nil",
"{",
"defer",
"db",
".",
"batchPool",
".",
"Put",
"(",
"ourBatch",
")",
"\n",
"}",
"\n\n",
"// Seq number.",
"seq",
":=",
"db",
".",
"seq",
"+",
"1",
"\n\n",
"// Write journal.",
"if",
"err",
":=",
"db",
".",
"writeJournal",
"(",
"batches",
",",
"seq",
",",
"sync",
")",
";",
"err",
"!=",
"nil",
"{",
"db",
".",
"unlockWrite",
"(",
"overflow",
",",
"merged",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Put batches.",
"for",
"_",
",",
"batch",
":=",
"range",
"batches",
"{",
"if",
"err",
":=",
"batch",
".",
"putMem",
"(",
"seq",
",",
"mdb",
".",
"DB",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"seq",
"+=",
"uint64",
"(",
"batch",
".",
"Len",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// Incr seq number.",
"db",
".",
"addSeq",
"(",
"uint64",
"(",
"batchesLen",
"(",
"batches",
")",
")",
")",
"\n\n",
"// Rotate memdb if it's reach the threshold.",
"if",
"batch",
".",
"internalLen",
">=",
"mdbFree",
"{",
"db",
".",
"rotateMem",
"(",
"0",
",",
"false",
")",
"\n",
"}",
"\n\n",
"db",
".",
"unlockWrite",
"(",
"overflow",
",",
"merged",
",",
"nil",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// ourBatch is batch that we can modify.
|
[
"ourBatch",
"is",
"batch",
"that",
"we",
"can",
"modify",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/db_write.go#L154-L254
|
train
|
syndtr/goleveldb
|
leveldb/db_write.go
|
Write
|
func (db *DB) Write(batch *Batch, wo *opt.WriteOptions) error {
if err := db.ok(); err != nil || batch == nil || batch.Len() == 0 {
return err
}
// If the batch size is larger than write buffer, it may justified to write
// using transaction instead. Using transaction the batch will be written
// into tables directly, skipping the journaling.
if batch.internalLen > db.s.o.GetWriteBuffer() && !db.s.o.GetDisableLargeBatchTransaction() {
tr, err := db.OpenTransaction()
if err != nil {
return err
}
if err := tr.Write(batch, wo); err != nil {
tr.Discard()
return err
}
return tr.Commit()
}
merge := !wo.GetNoWriteMerge() && !db.s.o.GetNoWriteMerge()
sync := wo.GetSync() && !db.s.o.GetNoSync()
// Acquire write lock.
if merge {
select {
case db.writeMergeC <- writeMerge{sync: sync, batch: batch}:
if <-db.writeMergedC {
// Write is merged.
return <-db.writeAckC
}
// Write is not merged, the write lock is handed to us. Continue.
case db.writeLockC <- struct{}{}:
// Write lock acquired.
case err := <-db.compPerErrC:
// Compaction error.
return err
case <-db.closeC:
// Closed
return ErrClosed
}
} else {
select {
case db.writeLockC <- struct{}{}:
// Write lock acquired.
case err := <-db.compPerErrC:
// Compaction error.
return err
case <-db.closeC:
// Closed
return ErrClosed
}
}
return db.writeLocked(batch, nil, merge, sync)
}
|
go
|
func (db *DB) Write(batch *Batch, wo *opt.WriteOptions) error {
if err := db.ok(); err != nil || batch == nil || batch.Len() == 0 {
return err
}
// If the batch size is larger than write buffer, it may justified to write
// using transaction instead. Using transaction the batch will be written
// into tables directly, skipping the journaling.
if batch.internalLen > db.s.o.GetWriteBuffer() && !db.s.o.GetDisableLargeBatchTransaction() {
tr, err := db.OpenTransaction()
if err != nil {
return err
}
if err := tr.Write(batch, wo); err != nil {
tr.Discard()
return err
}
return tr.Commit()
}
merge := !wo.GetNoWriteMerge() && !db.s.o.GetNoWriteMerge()
sync := wo.GetSync() && !db.s.o.GetNoSync()
// Acquire write lock.
if merge {
select {
case db.writeMergeC <- writeMerge{sync: sync, batch: batch}:
if <-db.writeMergedC {
// Write is merged.
return <-db.writeAckC
}
// Write is not merged, the write lock is handed to us. Continue.
case db.writeLockC <- struct{}{}:
// Write lock acquired.
case err := <-db.compPerErrC:
// Compaction error.
return err
case <-db.closeC:
// Closed
return ErrClosed
}
} else {
select {
case db.writeLockC <- struct{}{}:
// Write lock acquired.
case err := <-db.compPerErrC:
// Compaction error.
return err
case <-db.closeC:
// Closed
return ErrClosed
}
}
return db.writeLocked(batch, nil, merge, sync)
}
|
[
"func",
"(",
"db",
"*",
"DB",
")",
"Write",
"(",
"batch",
"*",
"Batch",
",",
"wo",
"*",
"opt",
".",
"WriteOptions",
")",
"error",
"{",
"if",
"err",
":=",
"db",
".",
"ok",
"(",
")",
";",
"err",
"!=",
"nil",
"||",
"batch",
"==",
"nil",
"||",
"batch",
".",
"Len",
"(",
")",
"==",
"0",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// If the batch size is larger than write buffer, it may justified to write",
"// using transaction instead. Using transaction the batch will be written",
"// into tables directly, skipping the journaling.",
"if",
"batch",
".",
"internalLen",
">",
"db",
".",
"s",
".",
"o",
".",
"GetWriteBuffer",
"(",
")",
"&&",
"!",
"db",
".",
"s",
".",
"o",
".",
"GetDisableLargeBatchTransaction",
"(",
")",
"{",
"tr",
",",
"err",
":=",
"db",
".",
"OpenTransaction",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"tr",
".",
"Write",
"(",
"batch",
",",
"wo",
")",
";",
"err",
"!=",
"nil",
"{",
"tr",
".",
"Discard",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"return",
"tr",
".",
"Commit",
"(",
")",
"\n",
"}",
"\n\n",
"merge",
":=",
"!",
"wo",
".",
"GetNoWriteMerge",
"(",
")",
"&&",
"!",
"db",
".",
"s",
".",
"o",
".",
"GetNoWriteMerge",
"(",
")",
"\n",
"sync",
":=",
"wo",
".",
"GetSync",
"(",
")",
"&&",
"!",
"db",
".",
"s",
".",
"o",
".",
"GetNoSync",
"(",
")",
"\n\n",
"// Acquire write lock.",
"if",
"merge",
"{",
"select",
"{",
"case",
"db",
".",
"writeMergeC",
"<-",
"writeMerge",
"{",
"sync",
":",
"sync",
",",
"batch",
":",
"batch",
"}",
":",
"if",
"<-",
"db",
".",
"writeMergedC",
"{",
"// Write is merged.",
"return",
"<-",
"db",
".",
"writeAckC",
"\n",
"}",
"\n",
"// Write is not merged, the write lock is handed to us. Continue.",
"case",
"db",
".",
"writeLockC",
"<-",
"struct",
"{",
"}",
"{",
"}",
":",
"// Write lock acquired.",
"case",
"err",
":=",
"<-",
"db",
".",
"compPerErrC",
":",
"// Compaction error.",
"return",
"err",
"\n",
"case",
"<-",
"db",
".",
"closeC",
":",
"// Closed",
"return",
"ErrClosed",
"\n",
"}",
"\n",
"}",
"else",
"{",
"select",
"{",
"case",
"db",
".",
"writeLockC",
"<-",
"struct",
"{",
"}",
"{",
"}",
":",
"// Write lock acquired.",
"case",
"err",
":=",
"<-",
"db",
".",
"compPerErrC",
":",
"// Compaction error.",
"return",
"err",
"\n",
"case",
"<-",
"db",
".",
"closeC",
":",
"// Closed",
"return",
"ErrClosed",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"db",
".",
"writeLocked",
"(",
"batch",
",",
"nil",
",",
"merge",
",",
"sync",
")",
"\n",
"}"
] |
// Write apply the given batch to the DB. The batch records will be applied
// sequentially. Write might be used concurrently, when used concurrently and
// batch is small enough, write will try to merge the batches. Set NoWriteMerge
// option to true to disable write merge.
//
// It is safe to modify the contents of the arguments after Write returns but
// not before. Write will not modify content of the batch.
|
[
"Write",
"apply",
"the",
"given",
"batch",
"to",
"the",
"DB",
".",
"The",
"batch",
"records",
"will",
"be",
"applied",
"sequentially",
".",
"Write",
"might",
"be",
"used",
"concurrently",
"when",
"used",
"concurrently",
"and",
"batch",
"is",
"small",
"enough",
"write",
"will",
"try",
"to",
"merge",
"the",
"batches",
".",
"Set",
"NoWriteMerge",
"option",
"to",
"true",
"to",
"disable",
"write",
"merge",
".",
"It",
"is",
"safe",
"to",
"modify",
"the",
"contents",
"of",
"the",
"arguments",
"after",
"Write",
"returns",
"but",
"not",
"before",
".",
"Write",
"will",
"not",
"modify",
"content",
"of",
"the",
"batch",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/db_write.go#L263-L318
|
train
|
syndtr/goleveldb
|
leveldb/db_write.go
|
Put
|
func (db *DB) Put(key, value []byte, wo *opt.WriteOptions) error {
return db.putRec(keyTypeVal, key, value, wo)
}
|
go
|
func (db *DB) Put(key, value []byte, wo *opt.WriteOptions) error {
return db.putRec(keyTypeVal, key, value, wo)
}
|
[
"func",
"(",
"db",
"*",
"DB",
")",
"Put",
"(",
"key",
",",
"value",
"[",
"]",
"byte",
",",
"wo",
"*",
"opt",
".",
"WriteOptions",
")",
"error",
"{",
"return",
"db",
".",
"putRec",
"(",
"keyTypeVal",
",",
"key",
",",
"value",
",",
"wo",
")",
"\n",
"}"
] |
// Put sets the value for the given key. It overwrites any previous value
// for that key; a DB is not a multi-map. Write merge also applies for Put, see
// Write.
//
// It is safe to modify the contents of the arguments after Put returns but not
// before.
|
[
"Put",
"sets",
"the",
"value",
"for",
"the",
"given",
"key",
".",
"It",
"overwrites",
"any",
"previous",
"value",
"for",
"that",
"key",
";",
"a",
"DB",
"is",
"not",
"a",
"multi",
"-",
"map",
".",
"Write",
"merge",
"also",
"applies",
"for",
"Put",
"see",
"Write",
".",
"It",
"is",
"safe",
"to",
"modify",
"the",
"contents",
"of",
"the",
"arguments",
"after",
"Put",
"returns",
"but",
"not",
"before",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/db_write.go#L371-L373
|
train
|
syndtr/goleveldb
|
leveldb/db_write.go
|
Delete
|
func (db *DB) Delete(key []byte, wo *opt.WriteOptions) error {
return db.putRec(keyTypeDel, key, nil, wo)
}
|
go
|
func (db *DB) Delete(key []byte, wo *opt.WriteOptions) error {
return db.putRec(keyTypeDel, key, nil, wo)
}
|
[
"func",
"(",
"db",
"*",
"DB",
")",
"Delete",
"(",
"key",
"[",
"]",
"byte",
",",
"wo",
"*",
"opt",
".",
"WriteOptions",
")",
"error",
"{",
"return",
"db",
".",
"putRec",
"(",
"keyTypeDel",
",",
"key",
",",
"nil",
",",
"wo",
")",
"\n",
"}"
] |
// Delete deletes the value for the given key. Delete will not returns error if
// key doesn't exist. Write merge also applies for Delete, see Write.
//
// It is safe to modify the contents of the arguments after Delete returns but
// not before.
|
[
"Delete",
"deletes",
"the",
"value",
"for",
"the",
"given",
"key",
".",
"Delete",
"will",
"not",
"returns",
"error",
"if",
"key",
"doesn",
"t",
"exist",
".",
"Write",
"merge",
"also",
"applies",
"for",
"Delete",
"see",
"Write",
".",
"It",
"is",
"safe",
"to",
"modify",
"the",
"contents",
"of",
"the",
"arguments",
"after",
"Delete",
"returns",
"but",
"not",
"before",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/db_write.go#L380-L382
|
train
|
syndtr/goleveldb
|
leveldb/db_write.go
|
CompactRange
|
func (db *DB) CompactRange(r util.Range) error {
if err := db.ok(); err != nil {
return err
}
// Lock writer.
select {
case db.writeLockC <- struct{}{}:
case err := <-db.compPerErrC:
return err
case <-db.closeC:
return ErrClosed
}
// Check for overlaps in memdb.
mdb := db.getEffectiveMem()
if mdb == nil {
return ErrClosed
}
defer mdb.decref()
if isMemOverlaps(db.s.icmp, mdb.DB, r.Start, r.Limit) {
// Memdb compaction.
if _, err := db.rotateMem(0, false); err != nil {
<-db.writeLockC
return err
}
<-db.writeLockC
if err := db.compTriggerWait(db.mcompCmdC); err != nil {
return err
}
} else {
<-db.writeLockC
}
// Table compaction.
return db.compTriggerRange(db.tcompCmdC, -1, r.Start, r.Limit)
}
|
go
|
func (db *DB) CompactRange(r util.Range) error {
if err := db.ok(); err != nil {
return err
}
// Lock writer.
select {
case db.writeLockC <- struct{}{}:
case err := <-db.compPerErrC:
return err
case <-db.closeC:
return ErrClosed
}
// Check for overlaps in memdb.
mdb := db.getEffectiveMem()
if mdb == nil {
return ErrClosed
}
defer mdb.decref()
if isMemOverlaps(db.s.icmp, mdb.DB, r.Start, r.Limit) {
// Memdb compaction.
if _, err := db.rotateMem(0, false); err != nil {
<-db.writeLockC
return err
}
<-db.writeLockC
if err := db.compTriggerWait(db.mcompCmdC); err != nil {
return err
}
} else {
<-db.writeLockC
}
// Table compaction.
return db.compTriggerRange(db.tcompCmdC, -1, r.Start, r.Limit)
}
|
[
"func",
"(",
"db",
"*",
"DB",
")",
"CompactRange",
"(",
"r",
"util",
".",
"Range",
")",
"error",
"{",
"if",
"err",
":=",
"db",
".",
"ok",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Lock writer.",
"select",
"{",
"case",
"db",
".",
"writeLockC",
"<-",
"struct",
"{",
"}",
"{",
"}",
":",
"case",
"err",
":=",
"<-",
"db",
".",
"compPerErrC",
":",
"return",
"err",
"\n",
"case",
"<-",
"db",
".",
"closeC",
":",
"return",
"ErrClosed",
"\n",
"}",
"\n\n",
"// Check for overlaps in memdb.",
"mdb",
":=",
"db",
".",
"getEffectiveMem",
"(",
")",
"\n",
"if",
"mdb",
"==",
"nil",
"{",
"return",
"ErrClosed",
"\n",
"}",
"\n",
"defer",
"mdb",
".",
"decref",
"(",
")",
"\n",
"if",
"isMemOverlaps",
"(",
"db",
".",
"s",
".",
"icmp",
",",
"mdb",
".",
"DB",
",",
"r",
".",
"Start",
",",
"r",
".",
"Limit",
")",
"{",
"// Memdb compaction.",
"if",
"_",
",",
"err",
":=",
"db",
".",
"rotateMem",
"(",
"0",
",",
"false",
")",
";",
"err",
"!=",
"nil",
"{",
"<-",
"db",
".",
"writeLockC",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"<-",
"db",
".",
"writeLockC",
"\n",
"if",
"err",
":=",
"db",
".",
"compTriggerWait",
"(",
"db",
".",
"mcompCmdC",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"<-",
"db",
".",
"writeLockC",
"\n",
"}",
"\n\n",
"// Table compaction.",
"return",
"db",
".",
"compTriggerRange",
"(",
"db",
".",
"tcompCmdC",
",",
"-",
"1",
",",
"r",
".",
"Start",
",",
"r",
".",
"Limit",
")",
"\n",
"}"
] |
// CompactRange compacts the underlying DB for the given key range.
// In particular, deleted and overwritten versions are discarded,
// and the data is rearranged to reduce the cost of operations
// needed to access the data. This operation should typically only
// be invoked by users who understand the underlying implementation.
//
// A nil Range.Start is treated as a key before all keys in the DB.
// And a nil Range.Limit is treated as a key after all keys in the DB.
// Therefore if both is nil then it will compact entire DB.
|
[
"CompactRange",
"compacts",
"the",
"underlying",
"DB",
"for",
"the",
"given",
"key",
"range",
".",
"In",
"particular",
"deleted",
"and",
"overwritten",
"versions",
"are",
"discarded",
"and",
"the",
"data",
"is",
"rearranged",
"to",
"reduce",
"the",
"cost",
"of",
"operations",
"needed",
"to",
"access",
"the",
"data",
".",
"This",
"operation",
"should",
"typically",
"only",
"be",
"invoked",
"by",
"users",
"who",
"understand",
"the",
"underlying",
"implementation",
".",
"A",
"nil",
"Range",
".",
"Start",
"is",
"treated",
"as",
"a",
"key",
"before",
"all",
"keys",
"in",
"the",
"DB",
".",
"And",
"a",
"nil",
"Range",
".",
"Limit",
"is",
"treated",
"as",
"a",
"key",
"after",
"all",
"keys",
"in",
"the",
"DB",
".",
"Therefore",
"if",
"both",
"is",
"nil",
"then",
"it",
"will",
"compact",
"entire",
"DB",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/db_write.go#L400-L436
|
train
|
syndtr/goleveldb
|
leveldb/db_write.go
|
SetReadOnly
|
func (db *DB) SetReadOnly() error {
if err := db.ok(); err != nil {
return err
}
// Lock writer.
select {
case db.writeLockC <- struct{}{}:
db.compWriteLocking = true
case err := <-db.compPerErrC:
return err
case <-db.closeC:
return ErrClosed
}
// Set compaction read-only.
select {
case db.compErrSetC <- ErrReadOnly:
case perr := <-db.compPerErrC:
return perr
case <-db.closeC:
return ErrClosed
}
return nil
}
|
go
|
func (db *DB) SetReadOnly() error {
if err := db.ok(); err != nil {
return err
}
// Lock writer.
select {
case db.writeLockC <- struct{}{}:
db.compWriteLocking = true
case err := <-db.compPerErrC:
return err
case <-db.closeC:
return ErrClosed
}
// Set compaction read-only.
select {
case db.compErrSetC <- ErrReadOnly:
case perr := <-db.compPerErrC:
return perr
case <-db.closeC:
return ErrClosed
}
return nil
}
|
[
"func",
"(",
"db",
"*",
"DB",
")",
"SetReadOnly",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"db",
".",
"ok",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Lock writer.",
"select",
"{",
"case",
"db",
".",
"writeLockC",
"<-",
"struct",
"{",
"}",
"{",
"}",
":",
"db",
".",
"compWriteLocking",
"=",
"true",
"\n",
"case",
"err",
":=",
"<-",
"db",
".",
"compPerErrC",
":",
"return",
"err",
"\n",
"case",
"<-",
"db",
".",
"closeC",
":",
"return",
"ErrClosed",
"\n",
"}",
"\n\n",
"// Set compaction read-only.",
"select",
"{",
"case",
"db",
".",
"compErrSetC",
"<-",
"ErrReadOnly",
":",
"case",
"perr",
":=",
"<-",
"db",
".",
"compPerErrC",
":",
"return",
"perr",
"\n",
"case",
"<-",
"db",
".",
"closeC",
":",
"return",
"ErrClosed",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// SetReadOnly makes DB read-only. It will stay read-only until reopened.
|
[
"SetReadOnly",
"makes",
"DB",
"read",
"-",
"only",
".",
"It",
"will",
"stay",
"read",
"-",
"only",
"until",
"reopened",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/db_write.go#L439-L464
|
train
|
syndtr/goleveldb
|
leveldb/util/util.go
|
Release
|
func (r *BasicReleaser) Release() {
if !r.released {
if r.releaser != nil {
r.releaser.Release()
r.releaser = nil
}
r.released = true
}
}
|
go
|
func (r *BasicReleaser) Release() {
if !r.released {
if r.releaser != nil {
r.releaser.Release()
r.releaser = nil
}
r.released = true
}
}
|
[
"func",
"(",
"r",
"*",
"BasicReleaser",
")",
"Release",
"(",
")",
"{",
"if",
"!",
"r",
".",
"released",
"{",
"if",
"r",
".",
"releaser",
"!=",
"nil",
"{",
"r",
".",
"releaser",
".",
"Release",
"(",
")",
"\n",
"r",
".",
"releaser",
"=",
"nil",
"\n",
"}",
"\n",
"r",
".",
"released",
"=",
"true",
"\n",
"}",
"\n",
"}"
] |
// Release implements Releaser.Release.
|
[
"Release",
"implements",
"Releaser",
".",
"Release",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/util/util.go#L50-L58
|
train
|
syndtr/goleveldb
|
leveldb/util/util.go
|
SetReleaser
|
func (r *BasicReleaser) SetReleaser(releaser Releaser) {
if r.released {
panic(ErrReleased)
}
if r.releaser != nil && releaser != nil {
panic(ErrHasReleaser)
}
r.releaser = releaser
}
|
go
|
func (r *BasicReleaser) SetReleaser(releaser Releaser) {
if r.released {
panic(ErrReleased)
}
if r.releaser != nil && releaser != nil {
panic(ErrHasReleaser)
}
r.releaser = releaser
}
|
[
"func",
"(",
"r",
"*",
"BasicReleaser",
")",
"SetReleaser",
"(",
"releaser",
"Releaser",
")",
"{",
"if",
"r",
".",
"released",
"{",
"panic",
"(",
"ErrReleased",
")",
"\n",
"}",
"\n",
"if",
"r",
".",
"releaser",
"!=",
"nil",
"&&",
"releaser",
"!=",
"nil",
"{",
"panic",
"(",
"ErrHasReleaser",
")",
"\n",
"}",
"\n",
"r",
".",
"releaser",
"=",
"releaser",
"\n",
"}"
] |
// SetReleaser implements ReleaseSetter.SetReleaser.
|
[
"SetReleaser",
"implements",
"ReleaseSetter",
".",
"SetReleaser",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/util/util.go#L61-L69
|
train
|
syndtr/goleveldb
|
leveldb/errors/errors.go
|
NewErrCorrupted
|
func NewErrCorrupted(fd storage.FileDesc, err error) error {
return &ErrCorrupted{fd, err}
}
|
go
|
func NewErrCorrupted(fd storage.FileDesc, err error) error {
return &ErrCorrupted{fd, err}
}
|
[
"func",
"NewErrCorrupted",
"(",
"fd",
"storage",
".",
"FileDesc",
",",
"err",
"error",
")",
"error",
"{",
"return",
"&",
"ErrCorrupted",
"{",
"fd",
",",
"err",
"}",
"\n",
"}"
] |
// NewErrCorrupted creates new ErrCorrupted error.
|
[
"NewErrCorrupted",
"creates",
"new",
"ErrCorrupted",
"error",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/errors/errors.go#L45-L47
|
train
|
syndtr/goleveldb
|
leveldb/errors/errors.go
|
IsCorrupted
|
func IsCorrupted(err error) bool {
switch err.(type) {
case *ErrCorrupted:
return true
case *storage.ErrCorrupted:
return true
}
return false
}
|
go
|
func IsCorrupted(err error) bool {
switch err.(type) {
case *ErrCorrupted:
return true
case *storage.ErrCorrupted:
return true
}
return false
}
|
[
"func",
"IsCorrupted",
"(",
"err",
"error",
")",
"bool",
"{",
"switch",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ErrCorrupted",
":",
"return",
"true",
"\n",
"case",
"*",
"storage",
".",
"ErrCorrupted",
":",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// IsCorrupted returns a boolean indicating whether the error is indicating
// a corruption.
|
[
"IsCorrupted",
"returns",
"a",
"boolean",
"indicating",
"whether",
"the",
"error",
"is",
"indicating",
"a",
"corruption",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/errors/errors.go#L51-L59
|
train
|
syndtr/goleveldb
|
leveldb/errors/errors.go
|
SetFd
|
func SetFd(err error, fd storage.FileDesc) error {
switch x := err.(type) {
case *ErrCorrupted:
x.Fd = fd
return x
}
return err
}
|
go
|
func SetFd(err error, fd storage.FileDesc) error {
switch x := err.(type) {
case *ErrCorrupted:
x.Fd = fd
return x
}
return err
}
|
[
"func",
"SetFd",
"(",
"err",
"error",
",",
"fd",
"storage",
".",
"FileDesc",
")",
"error",
"{",
"switch",
"x",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ErrCorrupted",
":",
"x",
".",
"Fd",
"=",
"fd",
"\n",
"return",
"x",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// SetFd sets 'file info' of the given error with the given file.
// Currently only ErrCorrupted is supported, otherwise will do nothing.
|
[
"SetFd",
"sets",
"file",
"info",
"of",
"the",
"given",
"error",
"with",
"the",
"given",
"file",
".",
"Currently",
"only",
"ErrCorrupted",
"is",
"supported",
"otherwise",
"will",
"do",
"nothing",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/errors/errors.go#L71-L78
|
train
|
syndtr/goleveldb
|
leveldb/db_util.go
|
Sum
|
func (sizes Sizes) Sum() int64 {
var sum int64
for _, size := range sizes {
sum += size
}
return sum
}
|
go
|
func (sizes Sizes) Sum() int64 {
var sum int64
for _, size := range sizes {
sum += size
}
return sum
}
|
[
"func",
"(",
"sizes",
"Sizes",
")",
"Sum",
"(",
")",
"int64",
"{",
"var",
"sum",
"int64",
"\n",
"for",
"_",
",",
"size",
":=",
"range",
"sizes",
"{",
"sum",
"+=",
"size",
"\n",
"}",
"\n",
"return",
"sum",
"\n",
"}"
] |
// Sum returns sum of the sizes.
|
[
"Sum",
"returns",
"sum",
"of",
"the",
"sizes",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/db_util.go#L28-L34
|
train
|
syndtr/goleveldb
|
leveldb/db_util.go
|
checkAndCleanFiles
|
func (db *DB) checkAndCleanFiles() error {
v := db.s.version()
defer v.release()
tmap := make(map[int64]bool)
for _, tables := range v.levels {
for _, t := range tables {
tmap[t.fd.Num] = false
}
}
fds, err := db.s.stor.List(storage.TypeAll)
if err != nil {
return err
}
var nt int
var rem []storage.FileDesc
for _, fd := range fds {
keep := true
switch fd.Type {
case storage.TypeManifest:
keep = fd.Num >= db.s.manifestFd.Num
case storage.TypeJournal:
if !db.frozenJournalFd.Zero() {
keep = fd.Num >= db.frozenJournalFd.Num
} else {
keep = fd.Num >= db.journalFd.Num
}
case storage.TypeTable:
_, keep = tmap[fd.Num]
if keep {
tmap[fd.Num] = true
nt++
}
}
if !keep {
rem = append(rem, fd)
}
}
if nt != len(tmap) {
var mfds []storage.FileDesc
for num, present := range tmap {
if !present {
mfds = append(mfds, storage.FileDesc{Type: storage.TypeTable, Num: num})
db.logf("db@janitor table missing @%d", num)
}
}
return errors.NewErrCorrupted(storage.FileDesc{}, &errors.ErrMissingFiles{Fds: mfds})
}
db.logf("db@janitor F·%d G·%d", len(fds), len(rem))
for _, fd := range rem {
db.logf("db@janitor removing %s-%d", fd.Type, fd.Num)
if err := db.s.stor.Remove(fd); err != nil {
return err
}
}
return nil
}
|
go
|
func (db *DB) checkAndCleanFiles() error {
v := db.s.version()
defer v.release()
tmap := make(map[int64]bool)
for _, tables := range v.levels {
for _, t := range tables {
tmap[t.fd.Num] = false
}
}
fds, err := db.s.stor.List(storage.TypeAll)
if err != nil {
return err
}
var nt int
var rem []storage.FileDesc
for _, fd := range fds {
keep := true
switch fd.Type {
case storage.TypeManifest:
keep = fd.Num >= db.s.manifestFd.Num
case storage.TypeJournal:
if !db.frozenJournalFd.Zero() {
keep = fd.Num >= db.frozenJournalFd.Num
} else {
keep = fd.Num >= db.journalFd.Num
}
case storage.TypeTable:
_, keep = tmap[fd.Num]
if keep {
tmap[fd.Num] = true
nt++
}
}
if !keep {
rem = append(rem, fd)
}
}
if nt != len(tmap) {
var mfds []storage.FileDesc
for num, present := range tmap {
if !present {
mfds = append(mfds, storage.FileDesc{Type: storage.TypeTable, Num: num})
db.logf("db@janitor table missing @%d", num)
}
}
return errors.NewErrCorrupted(storage.FileDesc{}, &errors.ErrMissingFiles{Fds: mfds})
}
db.logf("db@janitor F·%d G·%d", len(fds), len(rem))
for _, fd := range rem {
db.logf("db@janitor removing %s-%d", fd.Type, fd.Num)
if err := db.s.stor.Remove(fd); err != nil {
return err
}
}
return nil
}
|
[
"func",
"(",
"db",
"*",
"DB",
")",
"checkAndCleanFiles",
"(",
")",
"error",
"{",
"v",
":=",
"db",
".",
"s",
".",
"version",
"(",
")",
"\n",
"defer",
"v",
".",
"release",
"(",
")",
"\n\n",
"tmap",
":=",
"make",
"(",
"map",
"[",
"int64",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"tables",
":=",
"range",
"v",
".",
"levels",
"{",
"for",
"_",
",",
"t",
":=",
"range",
"tables",
"{",
"tmap",
"[",
"t",
".",
"fd",
".",
"Num",
"]",
"=",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"fds",
",",
"err",
":=",
"db",
".",
"s",
".",
"stor",
".",
"List",
"(",
"storage",
".",
"TypeAll",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"var",
"nt",
"int",
"\n",
"var",
"rem",
"[",
"]",
"storage",
".",
"FileDesc",
"\n",
"for",
"_",
",",
"fd",
":=",
"range",
"fds",
"{",
"keep",
":=",
"true",
"\n",
"switch",
"fd",
".",
"Type",
"{",
"case",
"storage",
".",
"TypeManifest",
":",
"keep",
"=",
"fd",
".",
"Num",
">=",
"db",
".",
"s",
".",
"manifestFd",
".",
"Num",
"\n",
"case",
"storage",
".",
"TypeJournal",
":",
"if",
"!",
"db",
".",
"frozenJournalFd",
".",
"Zero",
"(",
")",
"{",
"keep",
"=",
"fd",
".",
"Num",
">=",
"db",
".",
"frozenJournalFd",
".",
"Num",
"\n",
"}",
"else",
"{",
"keep",
"=",
"fd",
".",
"Num",
">=",
"db",
".",
"journalFd",
".",
"Num",
"\n",
"}",
"\n",
"case",
"storage",
".",
"TypeTable",
":",
"_",
",",
"keep",
"=",
"tmap",
"[",
"fd",
".",
"Num",
"]",
"\n",
"if",
"keep",
"{",
"tmap",
"[",
"fd",
".",
"Num",
"]",
"=",
"true",
"\n",
"nt",
"++",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"keep",
"{",
"rem",
"=",
"append",
"(",
"rem",
",",
"fd",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"nt",
"!=",
"len",
"(",
"tmap",
")",
"{",
"var",
"mfds",
"[",
"]",
"storage",
".",
"FileDesc",
"\n",
"for",
"num",
",",
"present",
":=",
"range",
"tmap",
"{",
"if",
"!",
"present",
"{",
"mfds",
"=",
"append",
"(",
"mfds",
",",
"storage",
".",
"FileDesc",
"{",
"Type",
":",
"storage",
".",
"TypeTable",
",",
"Num",
":",
"num",
"}",
")",
"\n",
"db",
".",
"logf",
"(",
"\"",
"\"",
",",
"num",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"errors",
".",
"NewErrCorrupted",
"(",
"storage",
".",
"FileDesc",
"{",
"}",
",",
"&",
"errors",
".",
"ErrMissingFiles",
"{",
"Fds",
":",
"mfds",
"}",
")",
"\n",
"}",
"\n\n",
"db",
".",
"logf",
"(",
"\"",
" ",
"l",
"n(f",
"d",
"s),",
" ",
"l",
"n(r",
"e",
"m))",
"",
"",
"\n",
"for",
"_",
",",
"fd",
":=",
"range",
"rem",
"{",
"db",
".",
"logf",
"(",
"\"",
"\"",
",",
"fd",
".",
"Type",
",",
"fd",
".",
"Num",
")",
"\n",
"if",
"err",
":=",
"db",
".",
"s",
".",
"stor",
".",
"Remove",
"(",
"fd",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Check and clean files.
|
[
"Check",
"and",
"clean",
"files",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/db_util.go#L41-L102
|
train
|
syndtr/goleveldb
|
leveldb/batch.go
|
Delete
|
func (b *Batch) Delete(key []byte) {
b.appendRec(keyTypeDel, key, nil)
}
|
go
|
func (b *Batch) Delete(key []byte) {
b.appendRec(keyTypeDel, key, nil)
}
|
[
"func",
"(",
"b",
"*",
"Batch",
")",
"Delete",
"(",
"key",
"[",
"]",
"byte",
")",
"{",
"b",
".",
"appendRec",
"(",
"keyTypeDel",
",",
"key",
",",
"nil",
")",
"\n",
"}"
] |
// Delete appends 'delete operation' of the given key to the batch.
// It is safe to modify the contents of the argument after Delete returns but
// not before.
|
[
"Delete",
"appends",
"delete",
"operation",
"of",
"the",
"given",
"key",
"to",
"the",
"batch",
".",
"It",
"is",
"safe",
"to",
"modify",
"the",
"contents",
"of",
"the",
"argument",
"after",
"Delete",
"returns",
"but",
"not",
"before",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/batch.go#L124-L126
|
train
|
syndtr/goleveldb
|
leveldb/batch.go
|
Replay
|
func (b *Batch) Replay(r BatchReplay) error {
for _, index := range b.index {
switch index.keyType {
case keyTypeVal:
r.Put(index.k(b.data), index.v(b.data))
case keyTypeDel:
r.Delete(index.k(b.data))
}
}
return nil
}
|
go
|
func (b *Batch) Replay(r BatchReplay) error {
for _, index := range b.index {
switch index.keyType {
case keyTypeVal:
r.Put(index.k(b.data), index.v(b.data))
case keyTypeDel:
r.Delete(index.k(b.data))
}
}
return nil
}
|
[
"func",
"(",
"b",
"*",
"Batch",
")",
"Replay",
"(",
"r",
"BatchReplay",
")",
"error",
"{",
"for",
"_",
",",
"index",
":=",
"range",
"b",
".",
"index",
"{",
"switch",
"index",
".",
"keyType",
"{",
"case",
"keyTypeVal",
":",
"r",
".",
"Put",
"(",
"index",
".",
"k",
"(",
"b",
".",
"data",
")",
",",
"index",
".",
"v",
"(",
"b",
".",
"data",
")",
")",
"\n",
"case",
"keyTypeDel",
":",
"r",
".",
"Delete",
"(",
"index",
".",
"k",
"(",
"b",
".",
"data",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Replay replays batch contents.
|
[
"Replay",
"replays",
"batch",
"contents",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/batch.go#L145-L155
|
train
|
syndtr/goleveldb
|
leveldb/batch.go
|
Reset
|
func (b *Batch) Reset() {
b.data = b.data[:0]
b.index = b.index[:0]
b.internalLen = 0
}
|
go
|
func (b *Batch) Reset() {
b.data = b.data[:0]
b.index = b.index[:0]
b.internalLen = 0
}
|
[
"func",
"(",
"b",
"*",
"Batch",
")",
"Reset",
"(",
")",
"{",
"b",
".",
"data",
"=",
"b",
".",
"data",
"[",
":",
"0",
"]",
"\n",
"b",
".",
"index",
"=",
"b",
".",
"index",
"[",
":",
"0",
"]",
"\n",
"b",
".",
"internalLen",
"=",
"0",
"\n",
"}"
] |
// Reset resets the batch.
|
[
"Reset",
"resets",
"the",
"batch",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/batch.go#L163-L167
|
train
|
syndtr/goleveldb
|
leveldb/db.go
|
Open
|
func Open(stor storage.Storage, o *opt.Options) (db *DB, err error) {
s, err := newSession(stor, o)
if err != nil {
return
}
defer func() {
if err != nil {
s.close()
s.release()
}
}()
err = s.recover()
if err != nil {
if !os.IsNotExist(err) || s.o.GetErrorIfMissing() || s.o.GetReadOnly() {
return
}
err = s.create()
if err != nil {
return
}
} else if s.o.GetErrorIfExist() {
err = os.ErrExist
return
}
return openDB(s)
}
|
go
|
func Open(stor storage.Storage, o *opt.Options) (db *DB, err error) {
s, err := newSession(stor, o)
if err != nil {
return
}
defer func() {
if err != nil {
s.close()
s.release()
}
}()
err = s.recover()
if err != nil {
if !os.IsNotExist(err) || s.o.GetErrorIfMissing() || s.o.GetReadOnly() {
return
}
err = s.create()
if err != nil {
return
}
} else if s.o.GetErrorIfExist() {
err = os.ErrExist
return
}
return openDB(s)
}
|
[
"func",
"Open",
"(",
"stor",
"storage",
".",
"Storage",
",",
"o",
"*",
"opt",
".",
"Options",
")",
"(",
"db",
"*",
"DB",
",",
"err",
"error",
")",
"{",
"s",
",",
"err",
":=",
"newSession",
"(",
"stor",
",",
"o",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"s",
".",
"close",
"(",
")",
"\n",
"s",
".",
"release",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"err",
"=",
"s",
".",
"recover",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"!",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"||",
"s",
".",
"o",
".",
"GetErrorIfMissing",
"(",
")",
"||",
"s",
".",
"o",
".",
"GetReadOnly",
"(",
")",
"{",
"return",
"\n",
"}",
"\n",
"err",
"=",
"s",
".",
"create",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"else",
"if",
"s",
".",
"o",
".",
"GetErrorIfExist",
"(",
")",
"{",
"err",
"=",
"os",
".",
"ErrExist",
"\n",
"return",
"\n",
"}",
"\n\n",
"return",
"openDB",
"(",
"s",
")",
"\n",
"}"
] |
// Open opens or creates a DB for the given storage.
// The DB will be created if not exist, unless ErrorIfMissing is true.
// Also, if ErrorIfExist is true and the DB exist Open will returns
// os.ErrExist error.
//
// Open will return an error with type of ErrCorrupted if corruption
// detected in the DB. Use errors.IsCorrupted to test whether an error is
// due to corruption. Corrupted DB can be recovered with Recover function.
//
// The returned DB instance is safe for concurrent use.
// The DB must be closed after use, by calling Close method.
|
[
"Open",
"opens",
"or",
"creates",
"a",
"DB",
"for",
"the",
"given",
"storage",
".",
"The",
"DB",
"will",
"be",
"created",
"if",
"not",
"exist",
"unless",
"ErrorIfMissing",
"is",
"true",
".",
"Also",
"if",
"ErrorIfExist",
"is",
"true",
"and",
"the",
"DB",
"exist",
"Open",
"will",
"returns",
"os",
".",
"ErrExist",
"error",
".",
"Open",
"will",
"return",
"an",
"error",
"with",
"type",
"of",
"ErrCorrupted",
"if",
"corruption",
"detected",
"in",
"the",
"DB",
".",
"Use",
"errors",
".",
"IsCorrupted",
"to",
"test",
"whether",
"an",
"error",
"is",
"due",
"to",
"corruption",
".",
"Corrupted",
"DB",
"can",
"be",
"recovered",
"with",
"Recover",
"function",
".",
"The",
"returned",
"DB",
"instance",
"is",
"safe",
"for",
"concurrent",
"use",
".",
"The",
"DB",
"must",
"be",
"closed",
"after",
"use",
"by",
"calling",
"Close",
"method",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/db.go#L171-L198
|
train
|
syndtr/goleveldb
|
leveldb/db.go
|
Recover
|
func Recover(stor storage.Storage, o *opt.Options) (db *DB, err error) {
s, err := newSession(stor, o)
if err != nil {
return
}
defer func() {
if err != nil {
s.close()
s.release()
}
}()
err = recoverTable(s, o)
if err != nil {
return
}
return openDB(s)
}
|
go
|
func Recover(stor storage.Storage, o *opt.Options) (db *DB, err error) {
s, err := newSession(stor, o)
if err != nil {
return
}
defer func() {
if err != nil {
s.close()
s.release()
}
}()
err = recoverTable(s, o)
if err != nil {
return
}
return openDB(s)
}
|
[
"func",
"Recover",
"(",
"stor",
"storage",
".",
"Storage",
",",
"o",
"*",
"opt",
".",
"Options",
")",
"(",
"db",
"*",
"DB",
",",
"err",
"error",
")",
"{",
"s",
",",
"err",
":=",
"newSession",
"(",
"stor",
",",
"o",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"s",
".",
"close",
"(",
")",
"\n",
"s",
".",
"release",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"err",
"=",
"recoverTable",
"(",
"s",
",",
"o",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"return",
"openDB",
"(",
"s",
")",
"\n",
"}"
] |
// Recover recovers and opens a DB with missing or corrupted manifest files
// for the given storage. It will ignore any manifest files, valid or not.
// The DB must already exist or it will returns an error.
// Also, Recover will ignore ErrorIfMissing and ErrorIfExist options.
//
// The returned DB instance is safe for concurrent use.
// The DB must be closed after use, by calling Close method.
|
[
"Recover",
"recovers",
"and",
"opens",
"a",
"DB",
"with",
"missing",
"or",
"corrupted",
"manifest",
"files",
"for",
"the",
"given",
"storage",
".",
"It",
"will",
"ignore",
"any",
"manifest",
"files",
"valid",
"or",
"not",
".",
"The",
"DB",
"must",
"already",
"exist",
"or",
"it",
"will",
"returns",
"an",
"error",
".",
"Also",
"Recover",
"will",
"ignore",
"ErrorIfMissing",
"and",
"ErrorIfExist",
"options",
".",
"The",
"returned",
"DB",
"instance",
"is",
"safe",
"for",
"concurrent",
"use",
".",
"The",
"DB",
"must",
"be",
"closed",
"after",
"use",
"by",
"calling",
"Close",
"method",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/db.go#L235-L252
|
train
|
syndtr/goleveldb
|
leveldb/db.go
|
GetSnapshot
|
func (db *DB) GetSnapshot() (*Snapshot, error) {
if err := db.ok(); err != nil {
return nil, err
}
return db.newSnapshot(), nil
}
|
go
|
func (db *DB) GetSnapshot() (*Snapshot, error) {
if err := db.ok(); err != nil {
return nil, err
}
return db.newSnapshot(), nil
}
|
[
"func",
"(",
"db",
"*",
"DB",
")",
"GetSnapshot",
"(",
")",
"(",
"*",
"Snapshot",
",",
"error",
")",
"{",
"if",
"err",
":=",
"db",
".",
"ok",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"db",
".",
"newSnapshot",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// GetSnapshot returns a latest snapshot of the underlying DB. A snapshot
// is a frozen snapshot of a DB state at a particular point in time. The
// content of snapshot are guaranteed to be consistent.
//
// The snapshot must be released after use, by calling Release method.
|
[
"GetSnapshot",
"returns",
"a",
"latest",
"snapshot",
"of",
"the",
"underlying",
"DB",
".",
"A",
"snapshot",
"is",
"a",
"frozen",
"snapshot",
"of",
"a",
"DB",
"state",
"at",
"a",
"particular",
"point",
"in",
"time",
".",
"The",
"content",
"of",
"snapshot",
"are",
"guaranteed",
"to",
"be",
"consistent",
".",
"The",
"snapshot",
"must",
"be",
"released",
"after",
"use",
"by",
"calling",
"Release",
"method",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/db.go#L899-L905
|
train
|
syndtr/goleveldb
|
leveldb/db.go
|
Stats
|
func (db *DB) Stats(s *DBStats) error {
err := db.ok()
if err != nil {
return err
}
s.IORead = db.s.stor.reads()
s.IOWrite = db.s.stor.writes()
s.WriteDelayCount = atomic.LoadInt32(&db.cWriteDelayN)
s.WriteDelayDuration = time.Duration(atomic.LoadInt64(&db.cWriteDelay))
s.WritePaused = atomic.LoadInt32(&db.inWritePaused) == 1
s.OpenedTablesCount = db.s.tops.cache.Size()
if db.s.tops.bcache != nil {
s.BlockCacheSize = db.s.tops.bcache.Size()
} else {
s.BlockCacheSize = 0
}
s.AliveIterators = atomic.LoadInt32(&db.aliveIters)
s.AliveSnapshots = atomic.LoadInt32(&db.aliveSnaps)
s.LevelDurations = s.LevelDurations[:0]
s.LevelRead = s.LevelRead[:0]
s.LevelWrite = s.LevelWrite[:0]
s.LevelSizes = s.LevelSizes[:0]
s.LevelTablesCounts = s.LevelTablesCounts[:0]
v := db.s.version()
defer v.release()
for level, tables := range v.levels {
duration, read, write := db.compStats.getStat(level)
if len(tables) == 0 && duration == 0 {
continue
}
s.LevelDurations = append(s.LevelDurations, duration)
s.LevelRead = append(s.LevelRead, read)
s.LevelWrite = append(s.LevelWrite, write)
s.LevelSizes = append(s.LevelSizes, tables.size())
s.LevelTablesCounts = append(s.LevelTablesCounts, len(tables))
}
return nil
}
|
go
|
func (db *DB) Stats(s *DBStats) error {
err := db.ok()
if err != nil {
return err
}
s.IORead = db.s.stor.reads()
s.IOWrite = db.s.stor.writes()
s.WriteDelayCount = atomic.LoadInt32(&db.cWriteDelayN)
s.WriteDelayDuration = time.Duration(atomic.LoadInt64(&db.cWriteDelay))
s.WritePaused = atomic.LoadInt32(&db.inWritePaused) == 1
s.OpenedTablesCount = db.s.tops.cache.Size()
if db.s.tops.bcache != nil {
s.BlockCacheSize = db.s.tops.bcache.Size()
} else {
s.BlockCacheSize = 0
}
s.AliveIterators = atomic.LoadInt32(&db.aliveIters)
s.AliveSnapshots = atomic.LoadInt32(&db.aliveSnaps)
s.LevelDurations = s.LevelDurations[:0]
s.LevelRead = s.LevelRead[:0]
s.LevelWrite = s.LevelWrite[:0]
s.LevelSizes = s.LevelSizes[:0]
s.LevelTablesCounts = s.LevelTablesCounts[:0]
v := db.s.version()
defer v.release()
for level, tables := range v.levels {
duration, read, write := db.compStats.getStat(level)
if len(tables) == 0 && duration == 0 {
continue
}
s.LevelDurations = append(s.LevelDurations, duration)
s.LevelRead = append(s.LevelRead, read)
s.LevelWrite = append(s.LevelWrite, write)
s.LevelSizes = append(s.LevelSizes, tables.size())
s.LevelTablesCounts = append(s.LevelTablesCounts, len(tables))
}
return nil
}
|
[
"func",
"(",
"db",
"*",
"DB",
")",
"Stats",
"(",
"s",
"*",
"DBStats",
")",
"error",
"{",
"err",
":=",
"db",
".",
"ok",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"s",
".",
"IORead",
"=",
"db",
".",
"s",
".",
"stor",
".",
"reads",
"(",
")",
"\n",
"s",
".",
"IOWrite",
"=",
"db",
".",
"s",
".",
"stor",
".",
"writes",
"(",
")",
"\n",
"s",
".",
"WriteDelayCount",
"=",
"atomic",
".",
"LoadInt32",
"(",
"&",
"db",
".",
"cWriteDelayN",
")",
"\n",
"s",
".",
"WriteDelayDuration",
"=",
"time",
".",
"Duration",
"(",
"atomic",
".",
"LoadInt64",
"(",
"&",
"db",
".",
"cWriteDelay",
")",
")",
"\n",
"s",
".",
"WritePaused",
"=",
"atomic",
".",
"LoadInt32",
"(",
"&",
"db",
".",
"inWritePaused",
")",
"==",
"1",
"\n\n",
"s",
".",
"OpenedTablesCount",
"=",
"db",
".",
"s",
".",
"tops",
".",
"cache",
".",
"Size",
"(",
")",
"\n",
"if",
"db",
".",
"s",
".",
"tops",
".",
"bcache",
"!=",
"nil",
"{",
"s",
".",
"BlockCacheSize",
"=",
"db",
".",
"s",
".",
"tops",
".",
"bcache",
".",
"Size",
"(",
")",
"\n",
"}",
"else",
"{",
"s",
".",
"BlockCacheSize",
"=",
"0",
"\n",
"}",
"\n\n",
"s",
".",
"AliveIterators",
"=",
"atomic",
".",
"LoadInt32",
"(",
"&",
"db",
".",
"aliveIters",
")",
"\n",
"s",
".",
"AliveSnapshots",
"=",
"atomic",
".",
"LoadInt32",
"(",
"&",
"db",
".",
"aliveSnaps",
")",
"\n\n",
"s",
".",
"LevelDurations",
"=",
"s",
".",
"LevelDurations",
"[",
":",
"0",
"]",
"\n",
"s",
".",
"LevelRead",
"=",
"s",
".",
"LevelRead",
"[",
":",
"0",
"]",
"\n",
"s",
".",
"LevelWrite",
"=",
"s",
".",
"LevelWrite",
"[",
":",
"0",
"]",
"\n",
"s",
".",
"LevelSizes",
"=",
"s",
".",
"LevelSizes",
"[",
":",
"0",
"]",
"\n",
"s",
".",
"LevelTablesCounts",
"=",
"s",
".",
"LevelTablesCounts",
"[",
":",
"0",
"]",
"\n\n",
"v",
":=",
"db",
".",
"s",
".",
"version",
"(",
")",
"\n",
"defer",
"v",
".",
"release",
"(",
")",
"\n\n",
"for",
"level",
",",
"tables",
":=",
"range",
"v",
".",
"levels",
"{",
"duration",
",",
"read",
",",
"write",
":=",
"db",
".",
"compStats",
".",
"getStat",
"(",
"level",
")",
"\n",
"if",
"len",
"(",
"tables",
")",
"==",
"0",
"&&",
"duration",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"s",
".",
"LevelDurations",
"=",
"append",
"(",
"s",
".",
"LevelDurations",
",",
"duration",
")",
"\n",
"s",
".",
"LevelRead",
"=",
"append",
"(",
"s",
".",
"LevelRead",
",",
"read",
")",
"\n",
"s",
".",
"LevelWrite",
"=",
"append",
"(",
"s",
".",
"LevelWrite",
",",
"write",
")",
"\n",
"s",
".",
"LevelSizes",
"=",
"append",
"(",
"s",
".",
"LevelSizes",
",",
"tables",
".",
"size",
"(",
")",
")",
"\n",
"s",
".",
"LevelTablesCounts",
"=",
"append",
"(",
"s",
".",
"LevelTablesCounts",
",",
"len",
"(",
"tables",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Stats populates s with database statistics.
|
[
"Stats",
"populates",
"s",
"with",
"database",
"statistics",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/db.go#L1040-L1084
|
train
|
syndtr/goleveldb
|
leveldb/db.go
|
SizeOf
|
func (db *DB) SizeOf(ranges []util.Range) (Sizes, error) {
if err := db.ok(); err != nil {
return nil, err
}
v := db.s.version()
defer v.release()
sizes := make(Sizes, 0, len(ranges))
for _, r := range ranges {
imin := makeInternalKey(nil, r.Start, keyMaxSeq, keyTypeSeek)
imax := makeInternalKey(nil, r.Limit, keyMaxSeq, keyTypeSeek)
start, err := v.offsetOf(imin)
if err != nil {
return nil, err
}
limit, err := v.offsetOf(imax)
if err != nil {
return nil, err
}
var size int64
if limit >= start {
size = limit - start
}
sizes = append(sizes, size)
}
return sizes, nil
}
|
go
|
func (db *DB) SizeOf(ranges []util.Range) (Sizes, error) {
if err := db.ok(); err != nil {
return nil, err
}
v := db.s.version()
defer v.release()
sizes := make(Sizes, 0, len(ranges))
for _, r := range ranges {
imin := makeInternalKey(nil, r.Start, keyMaxSeq, keyTypeSeek)
imax := makeInternalKey(nil, r.Limit, keyMaxSeq, keyTypeSeek)
start, err := v.offsetOf(imin)
if err != nil {
return nil, err
}
limit, err := v.offsetOf(imax)
if err != nil {
return nil, err
}
var size int64
if limit >= start {
size = limit - start
}
sizes = append(sizes, size)
}
return sizes, nil
}
|
[
"func",
"(",
"db",
"*",
"DB",
")",
"SizeOf",
"(",
"ranges",
"[",
"]",
"util",
".",
"Range",
")",
"(",
"Sizes",
",",
"error",
")",
"{",
"if",
"err",
":=",
"db",
".",
"ok",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"v",
":=",
"db",
".",
"s",
".",
"version",
"(",
")",
"\n",
"defer",
"v",
".",
"release",
"(",
")",
"\n\n",
"sizes",
":=",
"make",
"(",
"Sizes",
",",
"0",
",",
"len",
"(",
"ranges",
")",
")",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"ranges",
"{",
"imin",
":=",
"makeInternalKey",
"(",
"nil",
",",
"r",
".",
"Start",
",",
"keyMaxSeq",
",",
"keyTypeSeek",
")",
"\n",
"imax",
":=",
"makeInternalKey",
"(",
"nil",
",",
"r",
".",
"Limit",
",",
"keyMaxSeq",
",",
"keyTypeSeek",
")",
"\n",
"start",
",",
"err",
":=",
"v",
".",
"offsetOf",
"(",
"imin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"limit",
",",
"err",
":=",
"v",
".",
"offsetOf",
"(",
"imax",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"size",
"int64",
"\n",
"if",
"limit",
">=",
"start",
"{",
"size",
"=",
"limit",
"-",
"start",
"\n",
"}",
"\n",
"sizes",
"=",
"append",
"(",
"sizes",
",",
"size",
")",
"\n",
"}",
"\n\n",
"return",
"sizes",
",",
"nil",
"\n",
"}"
] |
// SizeOf calculates approximate sizes of the given key ranges.
// The length of the returned sizes are equal with the length of the given
// ranges. The returned sizes measure storage space usage, so if the user
// data compresses by a factor of ten, the returned sizes will be one-tenth
// the size of the corresponding user data size.
// The results may not include the sizes of recently written data.
|
[
"SizeOf",
"calculates",
"approximate",
"sizes",
"of",
"the",
"given",
"key",
"ranges",
".",
"The",
"length",
"of",
"the",
"returned",
"sizes",
"are",
"equal",
"with",
"the",
"length",
"of",
"the",
"given",
"ranges",
".",
"The",
"returned",
"sizes",
"measure",
"storage",
"space",
"usage",
"so",
"if",
"the",
"user",
"data",
"compresses",
"by",
"a",
"factor",
"of",
"ten",
"the",
"returned",
"sizes",
"will",
"be",
"one",
"-",
"tenth",
"the",
"size",
"of",
"the",
"corresponding",
"user",
"data",
"size",
".",
"The",
"results",
"may",
"not",
"include",
"the",
"sizes",
"of",
"recently",
"written",
"data",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/db.go#L1092-L1120
|
train
|
syndtr/goleveldb
|
leveldb/db.go
|
Close
|
func (db *DB) Close() error {
if !db.setClosed() {
return ErrClosed
}
start := time.Now()
db.log("db@close closing")
// Clear the finalizer.
runtime.SetFinalizer(db, nil)
// Get compaction error.
var err error
select {
case err = <-db.compErrC:
if err == ErrReadOnly {
err = nil
}
default:
}
// Signal all goroutines.
close(db.closeC)
// Discard open transaction.
if db.tr != nil {
db.tr.Discard()
}
// Acquire writer lock.
db.writeLockC <- struct{}{}
// Wait for all gorotines to exit.
db.closeW.Wait()
// Closes journal.
if db.journal != nil {
db.journal.Close()
db.journalWriter.Close()
db.journal = nil
db.journalWriter = nil
}
if db.writeDelayN > 0 {
db.logf("db@write was delayed N·%d T·%v", db.writeDelayN, db.writeDelay)
}
// Close session.
db.s.close()
db.logf("db@close done T·%v", time.Since(start))
db.s.release()
if db.closer != nil {
if err1 := db.closer.Close(); err == nil {
err = err1
}
db.closer = nil
}
// Clear memdbs.
db.clearMems()
return err
}
|
go
|
func (db *DB) Close() error {
if !db.setClosed() {
return ErrClosed
}
start := time.Now()
db.log("db@close closing")
// Clear the finalizer.
runtime.SetFinalizer(db, nil)
// Get compaction error.
var err error
select {
case err = <-db.compErrC:
if err == ErrReadOnly {
err = nil
}
default:
}
// Signal all goroutines.
close(db.closeC)
// Discard open transaction.
if db.tr != nil {
db.tr.Discard()
}
// Acquire writer lock.
db.writeLockC <- struct{}{}
// Wait for all gorotines to exit.
db.closeW.Wait()
// Closes journal.
if db.journal != nil {
db.journal.Close()
db.journalWriter.Close()
db.journal = nil
db.journalWriter = nil
}
if db.writeDelayN > 0 {
db.logf("db@write was delayed N·%d T·%v", db.writeDelayN, db.writeDelay)
}
// Close session.
db.s.close()
db.logf("db@close done T·%v", time.Since(start))
db.s.release()
if db.closer != nil {
if err1 := db.closer.Close(); err == nil {
err = err1
}
db.closer = nil
}
// Clear memdbs.
db.clearMems()
return err
}
|
[
"func",
"(",
"db",
"*",
"DB",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"!",
"db",
".",
"setClosed",
"(",
")",
"{",
"return",
"ErrClosed",
"\n",
"}",
"\n\n",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"db",
".",
"log",
"(",
"\"",
"\"",
")",
"\n\n",
"// Clear the finalizer.",
"runtime",
".",
"SetFinalizer",
"(",
"db",
",",
"nil",
")",
"\n\n",
"// Get compaction error.",
"var",
"err",
"error",
"\n",
"select",
"{",
"case",
"err",
"=",
"<-",
"db",
".",
"compErrC",
":",
"if",
"err",
"==",
"ErrReadOnly",
"{",
"err",
"=",
"nil",
"\n",
"}",
"\n",
"default",
":",
"}",
"\n\n",
"// Signal all goroutines.",
"close",
"(",
"db",
".",
"closeC",
")",
"\n\n",
"// Discard open transaction.",
"if",
"db",
".",
"tr",
"!=",
"nil",
"{",
"db",
".",
"tr",
".",
"Discard",
"(",
")",
"\n",
"}",
"\n\n",
"// Acquire writer lock.",
"db",
".",
"writeLockC",
"<-",
"struct",
"{",
"}",
"{",
"}",
"\n\n",
"// Wait for all gorotines to exit.",
"db",
".",
"closeW",
".",
"Wait",
"(",
")",
"\n\n",
"// Closes journal.",
"if",
"db",
".",
"journal",
"!=",
"nil",
"{",
"db",
".",
"journal",
".",
"Close",
"(",
")",
"\n",
"db",
".",
"journalWriter",
".",
"Close",
"(",
")",
"\n",
"db",
".",
"journal",
"=",
"nil",
"\n",
"db",
".",
"journalWriter",
"=",
"nil",
"\n",
"}",
"\n\n",
"if",
"db",
".",
"writeDelayN",
">",
"0",
"{",
"db",
".",
"logf",
"(",
"\"",
" ",
"d",
".w",
"r",
"iteDelayN, ",
"d",
".w",
"r",
"iteDelay)",
"",
"\n",
"}",
"\n\n",
"// Close session.",
"db",
".",
"s",
".",
"close",
"(",
")",
"\n",
"db",
".",
"logf",
"(",
"\"",
",",
" ",
"ime.",
"S",
"ince(",
"s",
"tart)",
")",
"",
"\n",
"db",
".",
"s",
".",
"release",
"(",
")",
"\n\n",
"if",
"db",
".",
"closer",
"!=",
"nil",
"{",
"if",
"err1",
":=",
"db",
".",
"closer",
".",
"Close",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"err",
"=",
"err1",
"\n",
"}",
"\n",
"db",
".",
"closer",
"=",
"nil",
"\n",
"}",
"\n\n",
"// Clear memdbs.",
"db",
".",
"clearMems",
"(",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] |
// Close closes the DB. This will also releases any outstanding snapshot,
// abort any in-flight compaction and discard open transaction.
//
// It is not safe to close a DB until all outstanding iterators are released.
// It is valid to call Close multiple times. Other methods should not be
// called after the DB has been closed.
|
[
"Close",
"closes",
"the",
"DB",
".",
"This",
"will",
"also",
"releases",
"any",
"outstanding",
"snapshot",
"abort",
"any",
"in",
"-",
"flight",
"compaction",
"and",
"discard",
"open",
"transaction",
".",
"It",
"is",
"not",
"safe",
"to",
"close",
"a",
"DB",
"until",
"all",
"outstanding",
"iterators",
"are",
"released",
".",
"It",
"is",
"valid",
"to",
"call",
"Close",
"multiple",
"times",
".",
"Other",
"methods",
"should",
"not",
"be",
"called",
"after",
"the",
"DB",
"has",
"been",
"closed",
"."
] |
c3a204f8e96543bb0cc090385c001078f184fc46
|
https://github.com/syndtr/goleveldb/blob/c3a204f8e96543bb0cc090385c001078f184fc46/leveldb/db.go#L1128-L1191
|
train
|
olivere/elastic
|
search_queries_match_all.go
|
Source
|
func (q MatchAllQuery) Source() (interface{}, error) {
// {
// "match_all" : { ... }
// }
source := make(map[string]interface{})
params := make(map[string]interface{})
source["match_all"] = params
if q.boost != nil {
params["boost"] = *q.boost
}
if q.queryName != "" {
params["_name"] = q.queryName
}
return source, nil
}
|
go
|
func (q MatchAllQuery) Source() (interface{}, error) {
// {
// "match_all" : { ... }
// }
source := make(map[string]interface{})
params := make(map[string]interface{})
source["match_all"] = params
if q.boost != nil {
params["boost"] = *q.boost
}
if q.queryName != "" {
params["_name"] = q.queryName
}
return source, nil
}
|
[
"func",
"(",
"q",
"MatchAllQuery",
")",
"Source",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"// {",
"// \"match_all\" : { ... }",
"// }",
"source",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"params",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"source",
"[",
"\"",
"\"",
"]",
"=",
"params",
"\n",
"if",
"q",
".",
"boost",
"!=",
"nil",
"{",
"params",
"[",
"\"",
"\"",
"]",
"=",
"*",
"q",
".",
"boost",
"\n",
"}",
"\n",
"if",
"q",
".",
"queryName",
"!=",
"\"",
"\"",
"{",
"params",
"[",
"\"",
"\"",
"]",
"=",
"q",
".",
"queryName",
"\n",
"}",
"\n",
"return",
"source",
",",
"nil",
"\n",
"}"
] |
// Source returns JSON for the match all query.
|
[
"Source",
"returns",
"JSON",
"for",
"the",
"match",
"all",
"query",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_match_all.go#L37-L51
|
train
|
olivere/elastic
|
search_aggs.go
|
UnmarshalJSON
|
func (a *AggregationValueMetric) UnmarshalJSON(data []byte) error {
var aggs map[string]json.RawMessage
if err := json.Unmarshal(data, &aggs); err != nil {
return err
}
if v, ok := aggs["value"]; ok && v != nil {
json.Unmarshal(v, &a.Value)
}
if v, ok := aggs["meta"]; ok && v != nil {
json.Unmarshal(v, &a.Meta)
}
a.Aggregations = aggs
return nil
}
|
go
|
func (a *AggregationValueMetric) UnmarshalJSON(data []byte) error {
var aggs map[string]json.RawMessage
if err := json.Unmarshal(data, &aggs); err != nil {
return err
}
if v, ok := aggs["value"]; ok && v != nil {
json.Unmarshal(v, &a.Value)
}
if v, ok := aggs["meta"]; ok && v != nil {
json.Unmarshal(v, &a.Meta)
}
a.Aggregations = aggs
return nil
}
|
[
"func",
"(",
"a",
"*",
"AggregationValueMetric",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"aggs",
"map",
"[",
"string",
"]",
"json",
".",
"RawMessage",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"aggs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Value",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Meta",
")",
"\n",
"}",
"\n",
"a",
".",
"Aggregations",
"=",
"aggs",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON decodes JSON data and initializes an AggregationValueMetric structure.
|
[
"UnmarshalJSON",
"decodes",
"JSON",
"data",
"and",
"initializes",
"an",
"AggregationValueMetric",
"structure",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_aggs.go#L778-L791
|
train
|
olivere/elastic
|
search_aggs.go
|
UnmarshalJSON
|
func (a *AggregationStatsMetric) UnmarshalJSON(data []byte) error {
var aggs map[string]json.RawMessage
if err := json.Unmarshal(data, &aggs); err != nil {
return err
}
if v, ok := aggs["count"]; ok && v != nil {
json.Unmarshal(v, &a.Count)
}
if v, ok := aggs["min"]; ok && v != nil {
json.Unmarshal(v, &a.Min)
}
if v, ok := aggs["max"]; ok && v != nil {
json.Unmarshal(v, &a.Max)
}
if v, ok := aggs["avg"]; ok && v != nil {
json.Unmarshal(v, &a.Avg)
}
if v, ok := aggs["sum"]; ok && v != nil {
json.Unmarshal(v, &a.Sum)
}
if v, ok := aggs["meta"]; ok && v != nil {
json.Unmarshal(v, &a.Meta)
}
a.Aggregations = aggs
return nil
}
|
go
|
func (a *AggregationStatsMetric) UnmarshalJSON(data []byte) error {
var aggs map[string]json.RawMessage
if err := json.Unmarshal(data, &aggs); err != nil {
return err
}
if v, ok := aggs["count"]; ok && v != nil {
json.Unmarshal(v, &a.Count)
}
if v, ok := aggs["min"]; ok && v != nil {
json.Unmarshal(v, &a.Min)
}
if v, ok := aggs["max"]; ok && v != nil {
json.Unmarshal(v, &a.Max)
}
if v, ok := aggs["avg"]; ok && v != nil {
json.Unmarshal(v, &a.Avg)
}
if v, ok := aggs["sum"]; ok && v != nil {
json.Unmarshal(v, &a.Sum)
}
if v, ok := aggs["meta"]; ok && v != nil {
json.Unmarshal(v, &a.Meta)
}
a.Aggregations = aggs
return nil
}
|
[
"func",
"(",
"a",
"*",
"AggregationStatsMetric",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"aggs",
"map",
"[",
"string",
"]",
"json",
".",
"RawMessage",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"aggs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Count",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Min",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Max",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Avg",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Sum",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Meta",
")",
"\n",
"}",
"\n",
"a",
".",
"Aggregations",
"=",
"aggs",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON decodes JSON data and initializes an AggregationStatsMetric structure.
|
[
"UnmarshalJSON",
"decodes",
"JSON",
"data",
"and",
"initializes",
"an",
"AggregationStatsMetric",
"structure",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_aggs.go#L808-L833
|
train
|
olivere/elastic
|
search_aggs.go
|
UnmarshalJSON
|
func (a *AggregationGeoCentroidMetric) UnmarshalJSON(data []byte) error {
var aggs map[string]json.RawMessage
if err := json.Unmarshal(data, &aggs); err != nil {
return err
}
if v, ok := aggs["location"]; ok && v != nil {
json.Unmarshal(v, &a.Location)
}
if v, ok := aggs["meta"]; ok && v != nil {
json.Unmarshal(v, &a.Meta)
}
if v, ok := aggs["count"]; ok && v != nil {
json.Unmarshal(v, &a.Count)
}
a.Aggregations = aggs
return nil
}
|
go
|
func (a *AggregationGeoCentroidMetric) UnmarshalJSON(data []byte) error {
var aggs map[string]json.RawMessage
if err := json.Unmarshal(data, &aggs); err != nil {
return err
}
if v, ok := aggs["location"]; ok && v != nil {
json.Unmarshal(v, &a.Location)
}
if v, ok := aggs["meta"]; ok && v != nil {
json.Unmarshal(v, &a.Meta)
}
if v, ok := aggs["count"]; ok && v != nil {
json.Unmarshal(v, &a.Count)
}
a.Aggregations = aggs
return nil
}
|
[
"func",
"(",
"a",
"*",
"AggregationGeoCentroidMetric",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"aggs",
"map",
"[",
"string",
"]",
"json",
".",
"RawMessage",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"aggs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Location",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Meta",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Count",
")",
"\n",
"}",
"\n",
"a",
".",
"Aggregations",
"=",
"aggs",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON decodes JSON data and initializes an AggregationGeoCentroidMetric structure.
|
[
"UnmarshalJSON",
"decodes",
"JSON",
"data",
"and",
"initializes",
"an",
"AggregationGeoCentroidMetric",
"structure",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_aggs.go#L1033-L1049
|
train
|
olivere/elastic
|
search_aggs.go
|
UnmarshalJSON
|
func (a *AggregationBucketRangeItem) UnmarshalJSON(data []byte) error {
var aggs map[string]json.RawMessage
if err := json.Unmarshal(data, &aggs); err != nil {
return err
}
if v, ok := aggs["key"]; ok && v != nil {
json.Unmarshal(v, &a.Key)
}
if v, ok := aggs["doc_count"]; ok && v != nil {
json.Unmarshal(v, &a.DocCount)
}
if v, ok := aggs["from"]; ok && v != nil {
json.Unmarshal(v, &a.From)
}
if v, ok := aggs["from_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.FromAsString)
}
if v, ok := aggs["to"]; ok && v != nil {
json.Unmarshal(v, &a.To)
}
if v, ok := aggs["to_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.ToAsString)
}
a.Aggregations = aggs
return nil
}
|
go
|
func (a *AggregationBucketRangeItem) UnmarshalJSON(data []byte) error {
var aggs map[string]json.RawMessage
if err := json.Unmarshal(data, &aggs); err != nil {
return err
}
if v, ok := aggs["key"]; ok && v != nil {
json.Unmarshal(v, &a.Key)
}
if v, ok := aggs["doc_count"]; ok && v != nil {
json.Unmarshal(v, &a.DocCount)
}
if v, ok := aggs["from"]; ok && v != nil {
json.Unmarshal(v, &a.From)
}
if v, ok := aggs["from_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.FromAsString)
}
if v, ok := aggs["to"]; ok && v != nil {
json.Unmarshal(v, &a.To)
}
if v, ok := aggs["to_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.ToAsString)
}
a.Aggregations = aggs
return nil
}
|
[
"func",
"(",
"a",
"*",
"AggregationBucketRangeItem",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"aggs",
"map",
"[",
"string",
"]",
"json",
".",
"RawMessage",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"aggs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Key",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"DocCount",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"From",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"FromAsString",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"To",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"ToAsString",
")",
"\n",
"}",
"\n",
"a",
".",
"Aggregations",
"=",
"aggs",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON decodes JSON data and initializes an AggregationBucketRangeItem structure.
|
[
"UnmarshalJSON",
"decodes",
"JSON",
"data",
"and",
"initializes",
"an",
"AggregationBucketRangeItem",
"structure",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_aggs.go#L1158-L1183
|
train
|
olivere/elastic
|
search_aggs.go
|
UnmarshalJSON
|
func (a *AggregationBucketHistogramItem) UnmarshalJSON(data []byte) error {
var aggs map[string]json.RawMessage
if err := json.Unmarshal(data, &aggs); err != nil {
return err
}
if v, ok := aggs["key"]; ok && v != nil {
json.Unmarshal(v, &a.Key)
}
if v, ok := aggs["key_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.KeyAsString)
}
if v, ok := aggs["doc_count"]; ok && v != nil {
json.Unmarshal(v, &a.DocCount)
}
a.Aggregations = aggs
return nil
}
|
go
|
func (a *AggregationBucketHistogramItem) UnmarshalJSON(data []byte) error {
var aggs map[string]json.RawMessage
if err := json.Unmarshal(data, &aggs); err != nil {
return err
}
if v, ok := aggs["key"]; ok && v != nil {
json.Unmarshal(v, &a.Key)
}
if v, ok := aggs["key_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.KeyAsString)
}
if v, ok := aggs["doc_count"]; ok && v != nil {
json.Unmarshal(v, &a.DocCount)
}
a.Aggregations = aggs
return nil
}
|
[
"func",
"(",
"a",
"*",
"AggregationBucketHistogramItem",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"aggs",
"map",
"[",
"string",
"]",
"json",
".",
"RawMessage",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"aggs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Key",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"KeyAsString",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"DocCount",
")",
"\n",
"}",
"\n",
"a",
".",
"Aggregations",
"=",
"aggs",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON decodes JSON data and initializes an AggregationBucketHistogramItem structure.
|
[
"UnmarshalJSON",
"decodes",
"JSON",
"data",
"and",
"initializes",
"an",
"AggregationBucketHistogramItem",
"structure",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_aggs.go#L1433-L1449
|
train
|
olivere/elastic
|
search_aggs.go
|
UnmarshalJSON
|
func (a *AggregationPipelineDerivative) UnmarshalJSON(data []byte) error {
var aggs map[string]json.RawMessage
if err := json.Unmarshal(data, &aggs); err != nil {
return err
}
if v, ok := aggs["value"]; ok && v != nil {
json.Unmarshal(v, &a.Value)
}
if v, ok := aggs["value_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.ValueAsString)
}
if v, ok := aggs["normalized_value"]; ok && v != nil {
json.Unmarshal(v, &a.NormalizedValue)
}
if v, ok := aggs["normalized_value_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.NormalizedValueAsString)
}
if v, ok := aggs["meta"]; ok && v != nil {
json.Unmarshal(v, &a.Meta)
}
a.Aggregations = aggs
return nil
}
|
go
|
func (a *AggregationPipelineDerivative) UnmarshalJSON(data []byte) error {
var aggs map[string]json.RawMessage
if err := json.Unmarshal(data, &aggs); err != nil {
return err
}
if v, ok := aggs["value"]; ok && v != nil {
json.Unmarshal(v, &a.Value)
}
if v, ok := aggs["value_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.ValueAsString)
}
if v, ok := aggs["normalized_value"]; ok && v != nil {
json.Unmarshal(v, &a.NormalizedValue)
}
if v, ok := aggs["normalized_value_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.NormalizedValueAsString)
}
if v, ok := aggs["meta"]; ok && v != nil {
json.Unmarshal(v, &a.Meta)
}
a.Aggregations = aggs
return nil
}
|
[
"func",
"(",
"a",
"*",
"AggregationPipelineDerivative",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"aggs",
"map",
"[",
"string",
"]",
"json",
".",
"RawMessage",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"aggs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Value",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"ValueAsString",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"NormalizedValue",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"NormalizedValueAsString",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Meta",
")",
"\n",
"}",
"\n",
"a",
".",
"Aggregations",
"=",
"aggs",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON decodes JSON data and initializes an AggregationPipelineDerivative structure.
|
[
"UnmarshalJSON",
"decodes",
"JSON",
"data",
"and",
"initializes",
"an",
"AggregationPipelineDerivative",
"structure",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_aggs.go#L1532-L1554
|
train
|
olivere/elastic
|
search_aggs.go
|
UnmarshalJSON
|
func (a *AggregationPipelineStatsMetric) UnmarshalJSON(data []byte) error {
var aggs map[string]json.RawMessage
if err := json.Unmarshal(data, &aggs); err != nil {
return err
}
if v, ok := aggs["count"]; ok && v != nil {
json.Unmarshal(v, &a.Count)
}
if v, ok := aggs["count_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.CountAsString)
}
if v, ok := aggs["min"]; ok && v != nil {
json.Unmarshal(v, &a.Min)
}
if v, ok := aggs["min_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.MinAsString)
}
if v, ok := aggs["max"]; ok && v != nil {
json.Unmarshal(v, &a.Max)
}
if v, ok := aggs["max_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.MaxAsString)
}
if v, ok := aggs["avg"]; ok && v != nil {
json.Unmarshal(v, &a.Avg)
}
if v, ok := aggs["avg_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.AvgAsString)
}
if v, ok := aggs["sum"]; ok && v != nil {
json.Unmarshal(v, &a.Sum)
}
if v, ok := aggs["sum_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.SumAsString)
}
if v, ok := aggs["meta"]; ok && v != nil {
json.Unmarshal(v, &a.Meta)
}
a.Aggregations = aggs
return nil
}
|
go
|
func (a *AggregationPipelineStatsMetric) UnmarshalJSON(data []byte) error {
var aggs map[string]json.RawMessage
if err := json.Unmarshal(data, &aggs); err != nil {
return err
}
if v, ok := aggs["count"]; ok && v != nil {
json.Unmarshal(v, &a.Count)
}
if v, ok := aggs["count_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.CountAsString)
}
if v, ok := aggs["min"]; ok && v != nil {
json.Unmarshal(v, &a.Min)
}
if v, ok := aggs["min_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.MinAsString)
}
if v, ok := aggs["max"]; ok && v != nil {
json.Unmarshal(v, &a.Max)
}
if v, ok := aggs["max_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.MaxAsString)
}
if v, ok := aggs["avg"]; ok && v != nil {
json.Unmarshal(v, &a.Avg)
}
if v, ok := aggs["avg_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.AvgAsString)
}
if v, ok := aggs["sum"]; ok && v != nil {
json.Unmarshal(v, &a.Sum)
}
if v, ok := aggs["sum_as_string"]; ok && v != nil {
json.Unmarshal(v, &a.SumAsString)
}
if v, ok := aggs["meta"]; ok && v != nil {
json.Unmarshal(v, &a.Meta)
}
a.Aggregations = aggs
return nil
}
|
[
"func",
"(",
"a",
"*",
"AggregationPipelineStatsMetric",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"aggs",
"map",
"[",
"string",
"]",
"json",
".",
"RawMessage",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"aggs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Count",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"CountAsString",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Min",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"MinAsString",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Max",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"MaxAsString",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Avg",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"AvgAsString",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Sum",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"SumAsString",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"aggs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"v",
"!=",
"nil",
"{",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"a",
".",
"Meta",
")",
"\n",
"}",
"\n",
"a",
".",
"Aggregations",
"=",
"aggs",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON decodes JSON data and initializes an AggregationPipelineStatsMetric structure.
|
[
"UnmarshalJSON",
"decodes",
"JSON",
"data",
"and",
"initializes",
"an",
"AggregationPipelineStatsMetric",
"structure",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_aggs.go#L1578-L1618
|
train
|
olivere/elastic
|
ingest_get_pipeline.go
|
Id
|
func (s *IngestGetPipelineService) Id(id ...string) *IngestGetPipelineService {
s.id = append(s.id, id...)
return s
}
|
go
|
func (s *IngestGetPipelineService) Id(id ...string) *IngestGetPipelineService {
s.id = append(s.id, id...)
return s
}
|
[
"func",
"(",
"s",
"*",
"IngestGetPipelineService",
")",
"Id",
"(",
"id",
"...",
"string",
")",
"*",
"IngestGetPipelineService",
"{",
"s",
".",
"id",
"=",
"append",
"(",
"s",
".",
"id",
",",
"id",
"...",
")",
"\n",
"return",
"s",
"\n",
"}"
] |
// Id is a list of pipeline ids. Wildcards supported.
|
[
"Id",
"is",
"a",
"list",
"of",
"pipeline",
"ids",
".",
"Wildcards",
"supported",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/ingest_get_pipeline.go#L34-L37
|
train
|
olivere/elastic
|
search_aggs_pipeline_percentiles_bucket.go
|
Format
|
func (p *PercentilesBucketAggregation) Format(format string) *PercentilesBucketAggregation {
p.format = format
return p
}
|
go
|
func (p *PercentilesBucketAggregation) Format(format string) *PercentilesBucketAggregation {
p.format = format
return p
}
|
[
"func",
"(",
"p",
"*",
"PercentilesBucketAggregation",
")",
"Format",
"(",
"format",
"string",
")",
"*",
"PercentilesBucketAggregation",
"{",
"p",
".",
"format",
"=",
"format",
"\n",
"return",
"p",
"\n",
"}"
] |
// Format to apply the output value of this aggregation.
|
[
"Format",
"to",
"apply",
"the",
"output",
"value",
"of",
"this",
"aggregation",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_aggs_pipeline_percentiles_bucket.go#L29-L32
|
train
|
olivere/elastic
|
search_aggs_pipeline_percentiles_bucket.go
|
Percents
|
func (p *PercentilesBucketAggregation) Percents(percents ...float64) *PercentilesBucketAggregation {
p.percents = percents
return p
}
|
go
|
func (p *PercentilesBucketAggregation) Percents(percents ...float64) *PercentilesBucketAggregation {
p.percents = percents
return p
}
|
[
"func",
"(",
"p",
"*",
"PercentilesBucketAggregation",
")",
"Percents",
"(",
"percents",
"...",
"float64",
")",
"*",
"PercentilesBucketAggregation",
"{",
"p",
".",
"percents",
"=",
"percents",
"\n",
"return",
"p",
"\n",
"}"
] |
// Percents to calculate percentiles for in this aggregation.
|
[
"Percents",
"to",
"calculate",
"percentiles",
"for",
"in",
"this",
"aggregation",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_aggs_pipeline_percentiles_bucket.go#L35-L38
|
train
|
olivere/elastic
|
search_queries_ids.go
|
Ids
|
func (q *IdsQuery) Ids(ids ...string) *IdsQuery {
q.values = append(q.values, ids...)
return q
}
|
go
|
func (q *IdsQuery) Ids(ids ...string) *IdsQuery {
q.values = append(q.values, ids...)
return q
}
|
[
"func",
"(",
"q",
"*",
"IdsQuery",
")",
"Ids",
"(",
"ids",
"...",
"string",
")",
"*",
"IdsQuery",
"{",
"q",
".",
"values",
"=",
"append",
"(",
"q",
".",
"values",
",",
"ids",
"...",
")",
"\n",
"return",
"q",
"\n",
"}"
] |
// Ids adds ids to the filter.
|
[
"Ids",
"adds",
"ids",
"to",
"the",
"filter",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_ids.go#L30-L33
|
train
|
olivere/elastic
|
search_queries_ids.go
|
QueryName
|
func (q *IdsQuery) QueryName(queryName string) *IdsQuery {
q.queryName = queryName
return q
}
|
go
|
func (q *IdsQuery) QueryName(queryName string) *IdsQuery {
q.queryName = queryName
return q
}
|
[
"func",
"(",
"q",
"*",
"IdsQuery",
")",
"QueryName",
"(",
"queryName",
"string",
")",
"*",
"IdsQuery",
"{",
"q",
".",
"queryName",
"=",
"queryName",
"\n",
"return",
"q",
"\n",
"}"
] |
// QueryName sets the query name for the filter.
|
[
"QueryName",
"sets",
"the",
"query",
"name",
"for",
"the",
"filter",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_ids.go#L42-L45
|
train
|
olivere/elastic
|
snapshot_create_repository.go
|
Verify
|
func (s *SnapshotCreateRepositoryService) Verify(verify bool) *SnapshotCreateRepositoryService {
s.verify = &verify
return s
}
|
go
|
func (s *SnapshotCreateRepositoryService) Verify(verify bool) *SnapshotCreateRepositoryService {
s.verify = &verify
return s
}
|
[
"func",
"(",
"s",
"*",
"SnapshotCreateRepositoryService",
")",
"Verify",
"(",
"verify",
"bool",
")",
"*",
"SnapshotCreateRepositoryService",
"{",
"s",
".",
"verify",
"=",
"&",
"verify",
"\n",
"return",
"s",
"\n",
"}"
] |
// Verify indicates whether to verify the repository after creation.
|
[
"Verify",
"indicates",
"whether",
"to",
"verify",
"the",
"repository",
"after",
"creation",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/snapshot_create_repository.go#L58-L61
|
train
|
olivere/elastic
|
snapshot_create_repository.go
|
Settings
|
func (s *SnapshotCreateRepositoryService) Settings(settings map[string]interface{}) *SnapshotCreateRepositoryService {
s.settings = settings
return s
}
|
go
|
func (s *SnapshotCreateRepositoryService) Settings(settings map[string]interface{}) *SnapshotCreateRepositoryService {
s.settings = settings
return s
}
|
[
"func",
"(",
"s",
"*",
"SnapshotCreateRepositoryService",
")",
"Settings",
"(",
"settings",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"*",
"SnapshotCreateRepositoryService",
"{",
"s",
".",
"settings",
"=",
"settings",
"\n",
"return",
"s",
"\n",
"}"
] |
// Settings sets all settings of the snapshot repository.
|
[
"Settings",
"sets",
"all",
"settings",
"of",
"the",
"snapshot",
"repository",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/snapshot_create_repository.go#L76-L79
|
train
|
olivere/elastic
|
snapshot_create_repository.go
|
Setting
|
func (s *SnapshotCreateRepositoryService) Setting(name string, value interface{}) *SnapshotCreateRepositoryService {
if s.settings == nil {
s.settings = make(map[string]interface{})
}
s.settings[name] = value
return s
}
|
go
|
func (s *SnapshotCreateRepositoryService) Setting(name string, value interface{}) *SnapshotCreateRepositoryService {
if s.settings == nil {
s.settings = make(map[string]interface{})
}
s.settings[name] = value
return s
}
|
[
"func",
"(",
"s",
"*",
"SnapshotCreateRepositoryService",
")",
"Setting",
"(",
"name",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"*",
"SnapshotCreateRepositoryService",
"{",
"if",
"s",
".",
"settings",
"==",
"nil",
"{",
"s",
".",
"settings",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n",
"s",
".",
"settings",
"[",
"name",
"]",
"=",
"value",
"\n",
"return",
"s",
"\n",
"}"
] |
// Setting sets a single settings of the snapshot repository.
|
[
"Setting",
"sets",
"a",
"single",
"settings",
"of",
"the",
"snapshot",
"repository",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/snapshot_create_repository.go#L82-L88
|
train
|
olivere/elastic
|
snapshot_create_repository.go
|
buildBody
|
func (s *SnapshotCreateRepositoryService) buildBody() (interface{}, error) {
if s.bodyJson != nil {
return s.bodyJson, nil
}
if s.bodyString != "" {
return s.bodyString, nil
}
body := map[string]interface{}{
"type": s.typ,
}
if len(s.settings) > 0 {
body["settings"] = s.settings
}
return body, nil
}
|
go
|
func (s *SnapshotCreateRepositoryService) buildBody() (interface{}, error) {
if s.bodyJson != nil {
return s.bodyJson, nil
}
if s.bodyString != "" {
return s.bodyString, nil
}
body := map[string]interface{}{
"type": s.typ,
}
if len(s.settings) > 0 {
body["settings"] = s.settings
}
return body, nil
}
|
[
"func",
"(",
"s",
"*",
"SnapshotCreateRepositoryService",
")",
"buildBody",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"s",
".",
"bodyJson",
"!=",
"nil",
"{",
"return",
"s",
".",
"bodyJson",
",",
"nil",
"\n",
"}",
"\n",
"if",
"s",
".",
"bodyString",
"!=",
"\"",
"\"",
"{",
"return",
"s",
".",
"bodyString",
",",
"nil",
"\n",
"}",
"\n\n",
"body",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"s",
".",
"typ",
",",
"}",
"\n",
"if",
"len",
"(",
"s",
".",
"settings",
")",
">",
"0",
"{",
"body",
"[",
"\"",
"\"",
"]",
"=",
"s",
".",
"settings",
"\n",
"}",
"\n",
"return",
"body",
",",
"nil",
"\n",
"}"
] |
// buildBody builds the body for the operation.
|
[
"buildBody",
"builds",
"the",
"body",
"for",
"the",
"operation",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/snapshot_create_repository.go#L130-L145
|
train
|
olivere/elastic
|
indices_exists.go
|
NewIndicesExistsService
|
func NewIndicesExistsService(client *Client) *IndicesExistsService {
return &IndicesExistsService{
client: client,
index: make([]string, 0),
}
}
|
go
|
func NewIndicesExistsService(client *Client) *IndicesExistsService {
return &IndicesExistsService{
client: client,
index: make([]string, 0),
}
}
|
[
"func",
"NewIndicesExistsService",
"(",
"client",
"*",
"Client",
")",
"*",
"IndicesExistsService",
"{",
"return",
"&",
"IndicesExistsService",
"{",
"client",
":",
"client",
",",
"index",
":",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
",",
"}",
"\n",
"}"
] |
// NewIndicesExistsService creates and initializes a new IndicesExistsService.
|
[
"NewIndicesExistsService",
"creates",
"and",
"initializes",
"a",
"new",
"IndicesExistsService",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/indices_exists.go#L32-L37
|
train
|
olivere/elastic
|
indices_exists.go
|
Index
|
func (s *IndicesExistsService) Index(index []string) *IndicesExistsService {
s.index = index
return s
}
|
go
|
func (s *IndicesExistsService) Index(index []string) *IndicesExistsService {
s.index = index
return s
}
|
[
"func",
"(",
"s",
"*",
"IndicesExistsService",
")",
"Index",
"(",
"index",
"[",
"]",
"string",
")",
"*",
"IndicesExistsService",
"{",
"s",
".",
"index",
"=",
"index",
"\n",
"return",
"s",
"\n",
"}"
] |
// Index is a list of one or more indices to check.
|
[
"Index",
"is",
"a",
"list",
"of",
"one",
"or",
"more",
"indices",
"to",
"check",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/indices_exists.go#L40-L43
|
train
|
olivere/elastic
|
xpack_security_put_role.go
|
Name
|
func (s *XPackSecurityPutRoleService) Name(name string) *XPackSecurityPutRoleService {
s.name = name
return s
}
|
go
|
func (s *XPackSecurityPutRoleService) Name(name string) *XPackSecurityPutRoleService {
s.name = name
return s
}
|
[
"func",
"(",
"s",
"*",
"XPackSecurityPutRoleService",
")",
"Name",
"(",
"name",
"string",
")",
"*",
"XPackSecurityPutRoleService",
"{",
"s",
".",
"name",
"=",
"name",
"\n",
"return",
"s",
"\n",
"}"
] |
// Name is name of the role to create.
|
[
"Name",
"is",
"name",
"of",
"the",
"role",
"to",
"create",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/xpack_security_put_role.go#L33-L36
|
train
|
olivere/elastic
|
search_queries_range.go
|
Gt
|
func (q *RangeQuery) Gt(from interface{}) *RangeQuery {
q.from = from
q.includeLower = false
return q
}
|
go
|
func (q *RangeQuery) Gt(from interface{}) *RangeQuery {
q.from = from
q.includeLower = false
return q
}
|
[
"func",
"(",
"q",
"*",
"RangeQuery",
")",
"Gt",
"(",
"from",
"interface",
"{",
"}",
")",
"*",
"RangeQuery",
"{",
"q",
".",
"from",
"=",
"from",
"\n",
"q",
".",
"includeLower",
"=",
"false",
"\n",
"return",
"q",
"\n",
"}"
] |
// Gt indicates a greater-than value for the from part.
// Use nil to indicate an unbounded from part.
|
[
"Gt",
"indicates",
"a",
"greater",
"-",
"than",
"value",
"for",
"the",
"from",
"part",
".",
"Use",
"nil",
"to",
"indicate",
"an",
"unbounded",
"from",
"part",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_range.go#L38-L42
|
train
|
olivere/elastic
|
search_queries_range.go
|
Gte
|
func (q *RangeQuery) Gte(from interface{}) *RangeQuery {
q.from = from
q.includeLower = true
return q
}
|
go
|
func (q *RangeQuery) Gte(from interface{}) *RangeQuery {
q.from = from
q.includeLower = true
return q
}
|
[
"func",
"(",
"q",
"*",
"RangeQuery",
")",
"Gte",
"(",
"from",
"interface",
"{",
"}",
")",
"*",
"RangeQuery",
"{",
"q",
".",
"from",
"=",
"from",
"\n",
"q",
".",
"includeLower",
"=",
"true",
"\n",
"return",
"q",
"\n",
"}"
] |
// Gte indicates a greater-than-or-equal value for the from part.
// Use nil to indicate an unbounded from part.
|
[
"Gte",
"indicates",
"a",
"greater",
"-",
"than",
"-",
"or",
"-",
"equal",
"value",
"for",
"the",
"from",
"part",
".",
"Use",
"nil",
"to",
"indicate",
"an",
"unbounded",
"from",
"part",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_range.go#L46-L50
|
train
|
olivere/elastic
|
search_queries_range.go
|
Format
|
func (q *RangeQuery) Format(format string) *RangeQuery {
q.format = format
return q
}
|
go
|
func (q *RangeQuery) Format(format string) *RangeQuery {
q.format = format
return q
}
|
[
"func",
"(",
"q",
"*",
"RangeQuery",
")",
"Format",
"(",
"format",
"string",
")",
"*",
"RangeQuery",
"{",
"q",
".",
"format",
"=",
"format",
"\n",
"return",
"q",
"\n",
"}"
] |
// Format is used for date fields. In that case, we can set the format
// to be used instead of the mapper format.
|
[
"Format",
"is",
"used",
"for",
"date",
"fields",
".",
"In",
"that",
"case",
"we",
"can",
"set",
"the",
"format",
"to",
"be",
"used",
"instead",
"of",
"the",
"mapper",
"format",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_range.go#L111-L114
|
train
|
olivere/elastic
|
nodes_stats.go
|
Metric
|
func (s *NodesStatsService) Metric(metric ...string) *NodesStatsService {
s.metric = append(s.metric, metric...)
return s
}
|
go
|
func (s *NodesStatsService) Metric(metric ...string) *NodesStatsService {
s.metric = append(s.metric, metric...)
return s
}
|
[
"func",
"(",
"s",
"*",
"NodesStatsService",
")",
"Metric",
"(",
"metric",
"...",
"string",
")",
"*",
"NodesStatsService",
"{",
"s",
".",
"metric",
"=",
"append",
"(",
"s",
".",
"metric",
",",
"metric",
"...",
")",
"\n",
"return",
"s",
"\n",
"}"
] |
// Metric limits the information returned to the specified metrics.
|
[
"Metric",
"limits",
"the",
"information",
"returned",
"to",
"the",
"specified",
"metrics",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/nodes_stats.go#L44-L47
|
train
|
olivere/elastic
|
nodes_stats.go
|
Level
|
func (s *NodesStatsService) Level(level string) *NodesStatsService {
s.level = level
return s
}
|
go
|
func (s *NodesStatsService) Level(level string) *NodesStatsService {
s.level = level
return s
}
|
[
"func",
"(",
"s",
"*",
"NodesStatsService",
")",
"Level",
"(",
"level",
"string",
")",
"*",
"NodesStatsService",
"{",
"s",
".",
"level",
"=",
"level",
"\n",
"return",
"s",
"\n",
"}"
] |
// Level specifies whether to return indices stats aggregated at node, index or shard level.
|
[
"Level",
"specifies",
"whether",
"to",
"return",
"indices",
"stats",
"aggregated",
"at",
"node",
"index",
"or",
"shard",
"level",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/nodes_stats.go#L97-L100
|
train
|
olivere/elastic
|
nodes_stats.go
|
Types
|
func (s *NodesStatsService) Types(types ...string) *NodesStatsService {
s.types = append(s.types, types...)
return s
}
|
go
|
func (s *NodesStatsService) Types(types ...string) *NodesStatsService {
s.types = append(s.types, types...)
return s
}
|
[
"func",
"(",
"s",
"*",
"NodesStatsService",
")",
"Types",
"(",
"types",
"...",
"string",
")",
"*",
"NodesStatsService",
"{",
"s",
".",
"types",
"=",
"append",
"(",
"s",
".",
"types",
",",
"types",
"...",
")",
"\n",
"return",
"s",
"\n",
"}"
] |
// Types a list of document types for the `indexing` index metric.
|
[
"Types",
"a",
"list",
"of",
"document",
"types",
"for",
"the",
"indexing",
"index",
"metric",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/nodes_stats.go#L109-L112
|
train
|
olivere/elastic
|
search_queries_raw_string.go
|
Source
|
func (q RawStringQuery) Source() (interface{}, error) {
var f interface{}
err := json.Unmarshal([]byte(q), &f)
return f, err
}
|
go
|
func (q RawStringQuery) Source() (interface{}, error) {
var f interface{}
err := json.Unmarshal([]byte(q), &f)
return f, err
}
|
[
"func",
"(",
"q",
"RawStringQuery",
")",
"Source",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"var",
"f",
"interface",
"{",
"}",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"q",
")",
",",
"&",
"f",
")",
"\n",
"return",
"f",
",",
"err",
"\n",
"}"
] |
// Source returns the JSON encoded body
|
[
"Source",
"returns",
"the",
"JSON",
"encoded",
"body"
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_raw_string.go#L22-L26
|
train
|
olivere/elastic
|
search_queries_parent_id.go
|
NewParentIdQuery
|
func NewParentIdQuery(typ, id string) *ParentIdQuery {
return &ParentIdQuery{
typ: typ,
id: id,
}
}
|
go
|
func NewParentIdQuery(typ, id string) *ParentIdQuery {
return &ParentIdQuery{
typ: typ,
id: id,
}
}
|
[
"func",
"NewParentIdQuery",
"(",
"typ",
",",
"id",
"string",
")",
"*",
"ParentIdQuery",
"{",
"return",
"&",
"ParentIdQuery",
"{",
"typ",
":",
"typ",
",",
"id",
":",
"id",
",",
"}",
"\n",
"}"
] |
// NewParentIdQuery creates and initializes a new parent_id query.
|
[
"NewParentIdQuery",
"creates",
"and",
"initializes",
"a",
"new",
"parent_id",
"query",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_parent_id.go#L22-L27
|
train
|
olivere/elastic
|
search_queries_parent_id.go
|
Type
|
func (q *ParentIdQuery) Type(typ string) *ParentIdQuery {
q.typ = typ
return q
}
|
go
|
func (q *ParentIdQuery) Type(typ string) *ParentIdQuery {
q.typ = typ
return q
}
|
[
"func",
"(",
"q",
"*",
"ParentIdQuery",
")",
"Type",
"(",
"typ",
"string",
")",
"*",
"ParentIdQuery",
"{",
"q",
".",
"typ",
"=",
"typ",
"\n",
"return",
"q",
"\n",
"}"
] |
// Type sets the parent type.
|
[
"Type",
"sets",
"the",
"parent",
"type",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_parent_id.go#L30-L33
|
train
|
olivere/elastic
|
search_queries_parent_id.go
|
Id
|
func (q *ParentIdQuery) Id(id string) *ParentIdQuery {
q.id = id
return q
}
|
go
|
func (q *ParentIdQuery) Id(id string) *ParentIdQuery {
q.id = id
return q
}
|
[
"func",
"(",
"q",
"*",
"ParentIdQuery",
")",
"Id",
"(",
"id",
"string",
")",
"*",
"ParentIdQuery",
"{",
"q",
".",
"id",
"=",
"id",
"\n",
"return",
"q",
"\n",
"}"
] |
// Id sets the id.
|
[
"Id",
"sets",
"the",
"id",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_parent_id.go#L36-L39
|
train
|
olivere/elastic
|
search_queries_parent_id.go
|
QueryName
|
func (q *ParentIdQuery) QueryName(queryName string) *ParentIdQuery {
q.queryName = queryName
return q
}
|
go
|
func (q *ParentIdQuery) QueryName(queryName string) *ParentIdQuery {
q.queryName = queryName
return q
}
|
[
"func",
"(",
"q",
"*",
"ParentIdQuery",
")",
"QueryName",
"(",
"queryName",
"string",
")",
"*",
"ParentIdQuery",
"{",
"q",
".",
"queryName",
"=",
"queryName",
"\n",
"return",
"q",
"\n",
"}"
] |
// QueryName specifies the query name for the filter that can be used when
// searching for matched filters per hit.
|
[
"QueryName",
"specifies",
"the",
"query",
"name",
"for",
"the",
"filter",
"that",
"can",
"be",
"used",
"when",
"searching",
"for",
"matched",
"filters",
"per",
"hit",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_parent_id.go#L56-L59
|
train
|
olivere/elastic
|
search_queries_parent_id.go
|
InnerHit
|
func (q *ParentIdQuery) InnerHit(innerHit *InnerHit) *ParentIdQuery {
q.innerHit = innerHit
return q
}
|
go
|
func (q *ParentIdQuery) InnerHit(innerHit *InnerHit) *ParentIdQuery {
q.innerHit = innerHit
return q
}
|
[
"func",
"(",
"q",
"*",
"ParentIdQuery",
")",
"InnerHit",
"(",
"innerHit",
"*",
"InnerHit",
")",
"*",
"ParentIdQuery",
"{",
"q",
".",
"innerHit",
"=",
"innerHit",
"\n",
"return",
"q",
"\n",
"}"
] |
// InnerHit sets the inner hit definition in the scope of this query and
// reusing the defined type and query.
|
[
"InnerHit",
"sets",
"the",
"inner",
"hit",
"definition",
"in",
"the",
"scope",
"of",
"this",
"query",
"and",
"reusing",
"the",
"defined",
"type",
"and",
"query",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_parent_id.go#L63-L66
|
train
|
olivere/elastic
|
search_queries_parent_id.go
|
Source
|
func (q *ParentIdQuery) Source() (interface{}, error) {
// {
// "parent_id" : {
// "type" : "blog",
// "id" : "1"
// }
// }
source := make(map[string]interface{})
query := make(map[string]interface{})
source["parent_id"] = query
query["type"] = q.typ
query["id"] = q.id
if q.boost != nil {
query["boost"] = *q.boost
}
if q.ignoreUnmapped != nil {
query["ignore_unmapped"] = *q.ignoreUnmapped
}
if q.queryName != "" {
query["_name"] = q.queryName
}
if q.innerHit != nil {
src, err := q.innerHit.Source()
if err != nil {
return nil, err
}
query["inner_hits"] = src
}
return source, nil
}
|
go
|
func (q *ParentIdQuery) Source() (interface{}, error) {
// {
// "parent_id" : {
// "type" : "blog",
// "id" : "1"
// }
// }
source := make(map[string]interface{})
query := make(map[string]interface{})
source["parent_id"] = query
query["type"] = q.typ
query["id"] = q.id
if q.boost != nil {
query["boost"] = *q.boost
}
if q.ignoreUnmapped != nil {
query["ignore_unmapped"] = *q.ignoreUnmapped
}
if q.queryName != "" {
query["_name"] = q.queryName
}
if q.innerHit != nil {
src, err := q.innerHit.Source()
if err != nil {
return nil, err
}
query["inner_hits"] = src
}
return source, nil
}
|
[
"func",
"(",
"q",
"*",
"ParentIdQuery",
")",
"Source",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"// {",
"// \"parent_id\" : {",
"// \"type\" : \"blog\",",
"// \"id\" : \"1\"",
"// }",
"// }",
"source",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"query",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"source",
"[",
"\"",
"\"",
"]",
"=",
"query",
"\n\n",
"query",
"[",
"\"",
"\"",
"]",
"=",
"q",
".",
"typ",
"\n",
"query",
"[",
"\"",
"\"",
"]",
"=",
"q",
".",
"id",
"\n",
"if",
"q",
".",
"boost",
"!=",
"nil",
"{",
"query",
"[",
"\"",
"\"",
"]",
"=",
"*",
"q",
".",
"boost",
"\n",
"}",
"\n",
"if",
"q",
".",
"ignoreUnmapped",
"!=",
"nil",
"{",
"query",
"[",
"\"",
"\"",
"]",
"=",
"*",
"q",
".",
"ignoreUnmapped",
"\n",
"}",
"\n",
"if",
"q",
".",
"queryName",
"!=",
"\"",
"\"",
"{",
"query",
"[",
"\"",
"\"",
"]",
"=",
"q",
".",
"queryName",
"\n",
"}",
"\n",
"if",
"q",
".",
"innerHit",
"!=",
"nil",
"{",
"src",
",",
"err",
":=",
"q",
".",
"innerHit",
".",
"Source",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"query",
"[",
"\"",
"\"",
"]",
"=",
"src",
"\n",
"}",
"\n",
"return",
"source",
",",
"nil",
"\n",
"}"
] |
// Source returns JSON for the parent_id query.
|
[
"Source",
"returns",
"JSON",
"for",
"the",
"parent_id",
"query",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_parent_id.go#L69-L99
|
train
|
olivere/elastic
|
tasks_list.go
|
Actions
|
func (s *TasksListService) Actions(actions ...string) *TasksListService {
s.actions = append(s.actions, actions...)
return s
}
|
go
|
func (s *TasksListService) Actions(actions ...string) *TasksListService {
s.actions = append(s.actions, actions...)
return s
}
|
[
"func",
"(",
"s",
"*",
"TasksListService",
")",
"Actions",
"(",
"actions",
"...",
"string",
")",
"*",
"TasksListService",
"{",
"s",
".",
"actions",
"=",
"append",
"(",
"s",
".",
"actions",
",",
"actions",
"...",
")",
"\n",
"return",
"s",
"\n",
"}"
] |
// Actions is a list of actions that should be returned. Leave empty to return all.
|
[
"Actions",
"is",
"a",
"list",
"of",
"actions",
"that",
"should",
"be",
"returned",
".",
"Leave",
"empty",
"to",
"return",
"all",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/tasks_list.go#L52-L55
|
train
|
olivere/elastic
|
mget.go
|
Add
|
func (s *MgetService) Add(items ...*MultiGetItem) *MgetService {
s.items = append(s.items, items...)
return s
}
|
go
|
func (s *MgetService) Add(items ...*MultiGetItem) *MgetService {
s.items = append(s.items, items...)
return s
}
|
[
"func",
"(",
"s",
"*",
"MgetService",
")",
"Add",
"(",
"items",
"...",
"*",
"MultiGetItem",
")",
"*",
"MgetService",
"{",
"s",
".",
"items",
"=",
"append",
"(",
"s",
".",
"items",
",",
"items",
"...",
")",
"\n",
"return",
"s",
"\n",
"}"
] |
// Add an item to the request.
|
[
"Add",
"an",
"item",
"to",
"the",
"request",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/mget.go#L81-L84
|
train
|
olivere/elastic
|
mget.go
|
Source
|
func (s *MgetService) Source() (interface{}, error) {
source := make(map[string]interface{})
items := make([]interface{}, len(s.items))
for i, item := range s.items {
src, err := item.Source()
if err != nil {
return nil, err
}
items[i] = src
}
source["docs"] = items
return source, nil
}
|
go
|
func (s *MgetService) Source() (interface{}, error) {
source := make(map[string]interface{})
items := make([]interface{}, len(s.items))
for i, item := range s.items {
src, err := item.Source()
if err != nil {
return nil, err
}
items[i] = src
}
source["docs"] = items
return source, nil
}
|
[
"func",
"(",
"s",
"*",
"MgetService",
")",
"Source",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"source",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"items",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"s",
".",
"items",
")",
")",
"\n",
"for",
"i",
",",
"item",
":=",
"range",
"s",
".",
"items",
"{",
"src",
",",
"err",
":=",
"item",
".",
"Source",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"items",
"[",
"i",
"]",
"=",
"src",
"\n",
"}",
"\n",
"source",
"[",
"\"",
"\"",
"]",
"=",
"items",
"\n",
"return",
"source",
",",
"nil",
"\n",
"}"
] |
// Source returns the request body, which will be serialized into JSON.
|
[
"Source",
"returns",
"the",
"request",
"body",
"which",
"will",
"be",
"serialized",
"into",
"JSON",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/mget.go#L87-L99
|
train
|
olivere/elastic
|
mget.go
|
Do
|
func (s *MgetService) Do(ctx context.Context) (*MgetResponse, error) {
// Build url
path := "/_mget"
params := make(url.Values)
if s.realtime != nil {
params.Add("realtime", fmt.Sprintf("%v", *s.realtime))
}
if s.preference != "" {
params.Add("preference", s.preference)
}
if s.refresh != "" {
params.Add("refresh", s.refresh)
}
if s.routing != "" {
params.Set("routing", s.routing)
}
if len(s.storedFields) > 0 {
params.Set("stored_fields", strings.Join(s.storedFields, ","))
}
// Set body
body, err := s.Source()
if err != nil {
return nil, err
}
// Get response
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "GET",
Path: path,
Params: params,
Body: body,
})
if err != nil {
return nil, err
}
// Return result
ret := new(MgetResponse)
if err := s.client.decoder.Decode(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
|
go
|
func (s *MgetService) Do(ctx context.Context) (*MgetResponse, error) {
// Build url
path := "/_mget"
params := make(url.Values)
if s.realtime != nil {
params.Add("realtime", fmt.Sprintf("%v", *s.realtime))
}
if s.preference != "" {
params.Add("preference", s.preference)
}
if s.refresh != "" {
params.Add("refresh", s.refresh)
}
if s.routing != "" {
params.Set("routing", s.routing)
}
if len(s.storedFields) > 0 {
params.Set("stored_fields", strings.Join(s.storedFields, ","))
}
// Set body
body, err := s.Source()
if err != nil {
return nil, err
}
// Get response
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "GET",
Path: path,
Params: params,
Body: body,
})
if err != nil {
return nil, err
}
// Return result
ret := new(MgetResponse)
if err := s.client.decoder.Decode(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
|
[
"func",
"(",
"s",
"*",
"MgetService",
")",
"Do",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"MgetResponse",
",",
"error",
")",
"{",
"// Build url",
"path",
":=",
"\"",
"\"",
"\n\n",
"params",
":=",
"make",
"(",
"url",
".",
"Values",
")",
"\n",
"if",
"s",
".",
"realtime",
"!=",
"nil",
"{",
"params",
".",
"Add",
"(",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"*",
"s",
".",
"realtime",
")",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"preference",
"!=",
"\"",
"\"",
"{",
"params",
".",
"Add",
"(",
"\"",
"\"",
",",
"s",
".",
"preference",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"refresh",
"!=",
"\"",
"\"",
"{",
"params",
".",
"Add",
"(",
"\"",
"\"",
",",
"s",
".",
"refresh",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"routing",
"!=",
"\"",
"\"",
"{",
"params",
".",
"Set",
"(",
"\"",
"\"",
",",
"s",
".",
"routing",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"s",
".",
"storedFields",
")",
">",
"0",
"{",
"params",
".",
"Set",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"s",
".",
"storedFields",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"// Set body",
"body",
",",
"err",
":=",
"s",
".",
"Source",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Get response",
"res",
",",
"err",
":=",
"s",
".",
"client",
".",
"PerformRequest",
"(",
"ctx",
",",
"PerformRequestOptions",
"{",
"Method",
":",
"\"",
"\"",
",",
"Path",
":",
"path",
",",
"Params",
":",
"params",
",",
"Body",
":",
"body",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Return result",
"ret",
":=",
"new",
"(",
"MgetResponse",
")",
"\n",
"if",
"err",
":=",
"s",
".",
"client",
".",
"decoder",
".",
"Decode",
"(",
"res",
".",
"Body",
",",
"ret",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"ret",
",",
"nil",
"\n",
"}"
] |
// Do executes the request.
|
[
"Do",
"executes",
"the",
"request",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/mget.go#L102-L146
|
train
|
olivere/elastic
|
mget.go
|
Index
|
func (item *MultiGetItem) Index(index string) *MultiGetItem {
item.index = index
return item
}
|
go
|
func (item *MultiGetItem) Index(index string) *MultiGetItem {
item.index = index
return item
}
|
[
"func",
"(",
"item",
"*",
"MultiGetItem",
")",
"Index",
"(",
"index",
"string",
")",
"*",
"MultiGetItem",
"{",
"item",
".",
"index",
"=",
"index",
"\n",
"return",
"item",
"\n",
"}"
] |
// Index specifies the index name.
|
[
"Index",
"specifies",
"the",
"index",
"name",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/mget.go#L168-L171
|
train
|
olivere/elastic
|
mget.go
|
Type
|
func (item *MultiGetItem) Type(typ string) *MultiGetItem {
item.typ = typ
return item
}
|
go
|
func (item *MultiGetItem) Type(typ string) *MultiGetItem {
item.typ = typ
return item
}
|
[
"func",
"(",
"item",
"*",
"MultiGetItem",
")",
"Type",
"(",
"typ",
"string",
")",
"*",
"MultiGetItem",
"{",
"item",
".",
"typ",
"=",
"typ",
"\n",
"return",
"item",
"\n",
"}"
] |
// Type specifies the type name.
|
[
"Type",
"specifies",
"the",
"type",
"name",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/mget.go#L174-L177
|
train
|
olivere/elastic
|
mget.go
|
Id
|
func (item *MultiGetItem) Id(id string) *MultiGetItem {
item.id = id
return item
}
|
go
|
func (item *MultiGetItem) Id(id string) *MultiGetItem {
item.id = id
return item
}
|
[
"func",
"(",
"item",
"*",
"MultiGetItem",
")",
"Id",
"(",
"id",
"string",
")",
"*",
"MultiGetItem",
"{",
"item",
".",
"id",
"=",
"id",
"\n",
"return",
"item",
"\n",
"}"
] |
// Id specifies the identifier of the document.
|
[
"Id",
"specifies",
"the",
"identifier",
"of",
"the",
"document",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/mget.go#L180-L183
|
train
|
olivere/elastic
|
mget.go
|
VersionType
|
func (item *MultiGetItem) VersionType(versionType string) *MultiGetItem {
item.versionType = versionType
return item
}
|
go
|
func (item *MultiGetItem) VersionType(versionType string) *MultiGetItem {
item.versionType = versionType
return item
}
|
[
"func",
"(",
"item",
"*",
"MultiGetItem",
")",
"VersionType",
"(",
"versionType",
"string",
")",
"*",
"MultiGetItem",
"{",
"item",
".",
"versionType",
"=",
"versionType",
"\n",
"return",
"item",
"\n",
"}"
] |
// VersionType can be "internal", "external", "external_gt", or "external_gte".
// See org.elasticsearch.index.VersionType in Elasticsearch source.
// It is "internal" by default.
|
[
"VersionType",
"can",
"be",
"internal",
"external",
"external_gt",
"or",
"external_gte",
".",
"See",
"org",
".",
"elasticsearch",
".",
"index",
".",
"VersionType",
"in",
"Elasticsearch",
"source",
".",
"It",
"is",
"internal",
"by",
"default",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/mget.go#L208-L211
|
train
|
olivere/elastic
|
mget.go
|
FetchSource
|
func (item *MultiGetItem) FetchSource(fetchSourceContext *FetchSourceContext) *MultiGetItem {
item.fsc = fetchSourceContext
return item
}
|
go
|
func (item *MultiGetItem) FetchSource(fetchSourceContext *FetchSourceContext) *MultiGetItem {
item.fsc = fetchSourceContext
return item
}
|
[
"func",
"(",
"item",
"*",
"MultiGetItem",
")",
"FetchSource",
"(",
"fetchSourceContext",
"*",
"FetchSourceContext",
")",
"*",
"MultiGetItem",
"{",
"item",
".",
"fsc",
"=",
"fetchSourceContext",
"\n",
"return",
"item",
"\n",
"}"
] |
// FetchSource allows to specify source filtering.
|
[
"FetchSource",
"allows",
"to",
"specify",
"source",
"filtering",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/mget.go#L214-L217
|
train
|
olivere/elastic
|
docvalue_field.go
|
Source
|
func (d DocvalueField) Source() (interface{}, error) {
if d.Format == "" {
return d.Field, nil
}
return map[string]interface{}{
"field": d.Field,
"format": d.Format,
}, nil
}
|
go
|
func (d DocvalueField) Source() (interface{}, error) {
if d.Format == "" {
return d.Field, nil
}
return map[string]interface{}{
"field": d.Field,
"format": d.Format,
}, nil
}
|
[
"func",
"(",
"d",
"DocvalueField",
")",
"Source",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"d",
".",
"Format",
"==",
"\"",
"\"",
"{",
"return",
"d",
".",
"Field",
",",
"nil",
"\n",
"}",
"\n",
"return",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"d",
".",
"Field",
",",
"\"",
"\"",
":",
"d",
".",
"Format",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// Source serializes the DocvalueField into JSON.
|
[
"Source",
"serializes",
"the",
"DocvalueField",
"into",
"JSON",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/docvalue_field.go#L15-L23
|
train
|
olivere/elastic
|
docvalue_field.go
|
Source
|
func (d DocvalueFields) Source() (interface{}, error) {
if d == nil {
return nil, nil
}
v := make([]interface{}, 0)
for _, f := range d {
src, err := f.Source()
if err != nil {
return nil, err
}
v = append(v, src)
}
return v, nil
}
|
go
|
func (d DocvalueFields) Source() (interface{}, error) {
if d == nil {
return nil, nil
}
v := make([]interface{}, 0)
for _, f := range d {
src, err := f.Source()
if err != nil {
return nil, err
}
v = append(v, src)
}
return v, nil
}
|
[
"func",
"(",
"d",
"DocvalueFields",
")",
"Source",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"d",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"v",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"0",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"d",
"{",
"src",
",",
"err",
":=",
"f",
".",
"Source",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"v",
"=",
"append",
"(",
"v",
",",
"src",
")",
"\n",
"}",
"\n",
"return",
"v",
",",
"nil",
"\n",
"}"
] |
// Source serializes the DocvalueFields into JSON.
|
[
"Source",
"serializes",
"the",
"DocvalueFields",
"into",
"JSON",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/docvalue_field.go#L29-L42
|
train
|
olivere/elastic
|
indices_forcemerge.go
|
NewIndicesForcemergeService
|
func NewIndicesForcemergeService(client *Client) *IndicesForcemergeService {
return &IndicesForcemergeService{
client: client,
index: make([]string, 0),
}
}
|
go
|
func NewIndicesForcemergeService(client *Client) *IndicesForcemergeService {
return &IndicesForcemergeService{
client: client,
index: make([]string, 0),
}
}
|
[
"func",
"NewIndicesForcemergeService",
"(",
"client",
"*",
"Client",
")",
"*",
"IndicesForcemergeService",
"{",
"return",
"&",
"IndicesForcemergeService",
"{",
"client",
":",
"client",
",",
"index",
":",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
",",
"}",
"\n",
"}"
] |
// NewIndicesForcemergeService creates a new IndicesForcemergeService.
|
[
"NewIndicesForcemergeService",
"creates",
"a",
"new",
"IndicesForcemergeService",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/indices_forcemerge.go#L36-L41
|
train
|
olivere/elastic
|
indices_forcemerge.go
|
OnlyExpungeDeletes
|
func (s *IndicesForcemergeService) OnlyExpungeDeletes(onlyExpungeDeletes bool) *IndicesForcemergeService {
s.onlyExpungeDeletes = &onlyExpungeDeletes
return s
}
|
go
|
func (s *IndicesForcemergeService) OnlyExpungeDeletes(onlyExpungeDeletes bool) *IndicesForcemergeService {
s.onlyExpungeDeletes = &onlyExpungeDeletes
return s
}
|
[
"func",
"(",
"s",
"*",
"IndicesForcemergeService",
")",
"OnlyExpungeDeletes",
"(",
"onlyExpungeDeletes",
"bool",
")",
"*",
"IndicesForcemergeService",
"{",
"s",
".",
"onlyExpungeDeletes",
"=",
"&",
"onlyExpungeDeletes",
"\n",
"return",
"s",
"\n",
"}"
] |
// OnlyExpungeDeletes specifies whether the operation should only expunge
// deleted documents.
|
[
"OnlyExpungeDeletes",
"specifies",
"whether",
"the",
"operation",
"should",
"only",
"expunge",
"deleted",
"documents",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/indices_forcemerge.go#L91-L94
|
train
|
olivere/elastic
|
search_queries_wildcard.go
|
NewWildcardQuery
|
func NewWildcardQuery(name, wildcard string) *WildcardQuery {
return &WildcardQuery{
name: name,
wildcard: wildcard,
}
}
|
go
|
func NewWildcardQuery(name, wildcard string) *WildcardQuery {
return &WildcardQuery{
name: name,
wildcard: wildcard,
}
}
|
[
"func",
"NewWildcardQuery",
"(",
"name",
",",
"wildcard",
"string",
")",
"*",
"WildcardQuery",
"{",
"return",
"&",
"WildcardQuery",
"{",
"name",
":",
"name",
",",
"wildcard",
":",
"wildcard",
",",
"}",
"\n",
"}"
] |
// NewWildcardQuery creates and initializes a new WildcardQuery.
|
[
"NewWildcardQuery",
"creates",
"and",
"initializes",
"a",
"new",
"WildcardQuery",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_wildcard.go#L26-L31
|
train
|
olivere/elastic
|
tasks_cancel.go
|
Actions
|
func (s *TasksCancelService) Actions(actions ...string) *TasksCancelService {
s.actions = append(s.actions, actions...)
return s
}
|
go
|
func (s *TasksCancelService) Actions(actions ...string) *TasksCancelService {
s.actions = append(s.actions, actions...)
return s
}
|
[
"func",
"(",
"s",
"*",
"TasksCancelService",
")",
"Actions",
"(",
"actions",
"...",
"string",
")",
"*",
"TasksCancelService",
"{",
"s",
".",
"actions",
"=",
"append",
"(",
"s",
".",
"actions",
",",
"actions",
"...",
")",
"\n",
"return",
"s",
"\n",
"}"
] |
// Actions is a list of actions that should be cancelled. Leave empty to cancel all.
|
[
"Actions",
"is",
"a",
"list",
"of",
"actions",
"that",
"should",
"be",
"cancelled",
".",
"Leave",
"empty",
"to",
"cancel",
"all",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/tasks_cancel.go#L54-L57
|
train
|
olivere/elastic
|
tasks_cancel.go
|
ParentTaskIdFromNodeAndId
|
func (s *TasksCancelService) ParentTaskIdFromNodeAndId(nodeId string, id int64) *TasksCancelService {
if id != -1 {
s.parentTaskId = fmt.Sprintf("%s:%d", nodeId, id)
}
return s
}
|
go
|
func (s *TasksCancelService) ParentTaskIdFromNodeAndId(nodeId string, id int64) *TasksCancelService {
if id != -1 {
s.parentTaskId = fmt.Sprintf("%s:%d", nodeId, id)
}
return s
}
|
[
"func",
"(",
"s",
"*",
"TasksCancelService",
")",
"ParentTaskIdFromNodeAndId",
"(",
"nodeId",
"string",
",",
"id",
"int64",
")",
"*",
"TasksCancelService",
"{",
"if",
"id",
"!=",
"-",
"1",
"{",
"s",
".",
"parentTaskId",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"nodeId",
",",
"id",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] |
// ParentTaskIdFromNodeAndId specifies to cancel tasks with specified parent task id.
|
[
"ParentTaskIdFromNodeAndId",
"specifies",
"to",
"cancel",
"tasks",
"with",
"specified",
"parent",
"task",
"id",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/tasks_cancel.go#L76-L81
|
train
|
olivere/elastic
|
search_source.go
|
Query
|
func (s *SearchSource) Query(query Query) *SearchSource {
s.query = query
return s
}
|
go
|
func (s *SearchSource) Query(query Query) *SearchSource {
s.query = query
return s
}
|
[
"func",
"(",
"s",
"*",
"SearchSource",
")",
"Query",
"(",
"query",
"Query",
")",
"*",
"SearchSource",
"{",
"s",
".",
"query",
"=",
"query",
"\n",
"return",
"s",
"\n",
"}"
] |
// Query sets the query to use with this search source.
|
[
"Query",
"sets",
"the",
"query",
"to",
"use",
"with",
"this",
"search",
"source",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_source.go#L58-L61
|
train
|
olivere/elastic
|
search_source.go
|
TimeoutInMillis
|
func (s *SearchSource) TimeoutInMillis(timeoutInMillis int) *SearchSource {
s.timeout = fmt.Sprintf("%dms", timeoutInMillis)
return s
}
|
go
|
func (s *SearchSource) TimeoutInMillis(timeoutInMillis int) *SearchSource {
s.timeout = fmt.Sprintf("%dms", timeoutInMillis)
return s
}
|
[
"func",
"(",
"s",
"*",
"SearchSource",
")",
"TimeoutInMillis",
"(",
"timeoutInMillis",
"int",
")",
"*",
"SearchSource",
"{",
"s",
".",
"timeout",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"timeoutInMillis",
")",
"\n",
"return",
"s",
"\n",
"}"
] |
// TimeoutInMillis controls how many milliseconds a search is allowed
// to take before it is canceled.
|
[
"TimeoutInMillis",
"controls",
"how",
"many",
"milliseconds",
"a",
"search",
"is",
"allowed",
"to",
"take",
"before",
"it",
"is",
"canceled",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_source.go#L128-L131
|
train
|
olivere/elastic
|
search_source.go
|
DefaultRescoreWindowSize
|
func (s *SearchSource) DefaultRescoreWindowSize(defaultRescoreWindowSize int) *SearchSource {
s.defaultRescoreWindowSize = &defaultRescoreWindowSize
return s
}
|
go
|
func (s *SearchSource) DefaultRescoreWindowSize(defaultRescoreWindowSize int) *SearchSource {
s.defaultRescoreWindowSize = &defaultRescoreWindowSize
return s
}
|
[
"func",
"(",
"s",
"*",
"SearchSource",
")",
"DefaultRescoreWindowSize",
"(",
"defaultRescoreWindowSize",
"int",
")",
"*",
"SearchSource",
"{",
"s",
".",
"defaultRescoreWindowSize",
"=",
"&",
"defaultRescoreWindowSize",
"\n",
"return",
"s",
"\n",
"}"
] |
// DefaultRescoreWindowSize sets the rescore window size for rescores
// that don't specify their window.
|
[
"DefaultRescoreWindowSize",
"sets",
"the",
"rescore",
"window",
"size",
"for",
"rescores",
"that",
"don",
"t",
"specify",
"their",
"window",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_source.go#L196-L199
|
train
|
olivere/elastic
|
search_source.go
|
Highlighter
|
func (s *SearchSource) Highlighter() *Highlight {
if s.highlight == nil {
s.highlight = NewHighlight()
}
return s.highlight
}
|
go
|
func (s *SearchSource) Highlighter() *Highlight {
if s.highlight == nil {
s.highlight = NewHighlight()
}
return s.highlight
}
|
[
"func",
"(",
"s",
"*",
"SearchSource",
")",
"Highlighter",
"(",
")",
"*",
"Highlight",
"{",
"if",
"s",
".",
"highlight",
"==",
"nil",
"{",
"s",
".",
"highlight",
"=",
"NewHighlight",
"(",
")",
"\n",
"}",
"\n",
"return",
"s",
".",
"highlight",
"\n",
"}"
] |
// Highlighter returns the highlighter.
|
[
"Highlighter",
"returns",
"the",
"highlighter",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_source.go#L208-L213
|
train
|
olivere/elastic
|
search_source.go
|
DocvalueField
|
func (s *SearchSource) DocvalueField(fieldDataField string) *SearchSource {
s.docvalueFields = append(s.docvalueFields, DocvalueField{Field: fieldDataField})
return s
}
|
go
|
func (s *SearchSource) DocvalueField(fieldDataField string) *SearchSource {
s.docvalueFields = append(s.docvalueFields, DocvalueField{Field: fieldDataField})
return s
}
|
[
"func",
"(",
"s",
"*",
"SearchSource",
")",
"DocvalueField",
"(",
"fieldDataField",
"string",
")",
"*",
"SearchSource",
"{",
"s",
".",
"docvalueFields",
"=",
"append",
"(",
"s",
".",
"docvalueFields",
",",
"DocvalueField",
"{",
"Field",
":",
"fieldDataField",
"}",
")",
"\n",
"return",
"s",
"\n",
"}"
] |
// DocvalueField adds a single field to load from the field data cache
// and return as part of the search request.
|
[
"DocvalueField",
"adds",
"a",
"single",
"field",
"to",
"load",
"from",
"the",
"field",
"data",
"cache",
"and",
"return",
"as",
"part",
"of",
"the",
"search",
"request",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_source.go#L292-L295
|
train
|
olivere/elastic
|
search_source.go
|
DocvalueFieldWithFormat
|
func (s *SearchSource) DocvalueFieldWithFormat(fieldDataFieldWithFormat DocvalueField) *SearchSource {
s.docvalueFields = append(s.docvalueFields, fieldDataFieldWithFormat)
return s
}
|
go
|
func (s *SearchSource) DocvalueFieldWithFormat(fieldDataFieldWithFormat DocvalueField) *SearchSource {
s.docvalueFields = append(s.docvalueFields, fieldDataFieldWithFormat)
return s
}
|
[
"func",
"(",
"s",
"*",
"SearchSource",
")",
"DocvalueFieldWithFormat",
"(",
"fieldDataFieldWithFormat",
"DocvalueField",
")",
"*",
"SearchSource",
"{",
"s",
".",
"docvalueFields",
"=",
"append",
"(",
"s",
".",
"docvalueFields",
",",
"fieldDataFieldWithFormat",
")",
"\n",
"return",
"s",
"\n",
"}"
] |
// DocvalueField adds a single docvalue field to load from the field data cache
// and return as part of the search request.
|
[
"DocvalueField",
"adds",
"a",
"single",
"docvalue",
"field",
"to",
"load",
"from",
"the",
"field",
"data",
"cache",
"and",
"return",
"as",
"part",
"of",
"the",
"search",
"request",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_source.go#L299-L302
|
train
|
olivere/elastic
|
search_source.go
|
DocvalueFields
|
func (s *SearchSource) DocvalueFields(docvalueFields ...string) *SearchSource {
for _, f := range docvalueFields {
s.docvalueFields = append(s.docvalueFields, DocvalueField{Field: f})
}
return s
}
|
go
|
func (s *SearchSource) DocvalueFields(docvalueFields ...string) *SearchSource {
for _, f := range docvalueFields {
s.docvalueFields = append(s.docvalueFields, DocvalueField{Field: f})
}
return s
}
|
[
"func",
"(",
"s",
"*",
"SearchSource",
")",
"DocvalueFields",
"(",
"docvalueFields",
"...",
"string",
")",
"*",
"SearchSource",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"docvalueFields",
"{",
"s",
".",
"docvalueFields",
"=",
"append",
"(",
"s",
".",
"docvalueFields",
",",
"DocvalueField",
"{",
"Field",
":",
"f",
"}",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] |
// DocvalueFields adds one or more fields to load from the field data cache
// and return as part of the search request.
|
[
"DocvalueFields",
"adds",
"one",
"or",
"more",
"fields",
"to",
"load",
"from",
"the",
"field",
"data",
"cache",
"and",
"return",
"as",
"part",
"of",
"the",
"search",
"request",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_source.go#L306-L311
|
train
|
olivere/elastic
|
search_source.go
|
DocvalueFieldsWithFormat
|
func (s *SearchSource) DocvalueFieldsWithFormat(docvalueFields ...DocvalueField) *SearchSource {
s.docvalueFields = append(s.docvalueFields, docvalueFields...)
return s
}
|
go
|
func (s *SearchSource) DocvalueFieldsWithFormat(docvalueFields ...DocvalueField) *SearchSource {
s.docvalueFields = append(s.docvalueFields, docvalueFields...)
return s
}
|
[
"func",
"(",
"s",
"*",
"SearchSource",
")",
"DocvalueFieldsWithFormat",
"(",
"docvalueFields",
"...",
"DocvalueField",
")",
"*",
"SearchSource",
"{",
"s",
".",
"docvalueFields",
"=",
"append",
"(",
"s",
".",
"docvalueFields",
",",
"docvalueFields",
"...",
")",
"\n",
"return",
"s",
"\n",
"}"
] |
// DocvalueFields adds one or more docvalue fields to load from the field data cache
// and return as part of the search request.
|
[
"DocvalueFields",
"adds",
"one",
"or",
"more",
"docvalue",
"fields",
"to",
"load",
"from",
"the",
"field",
"data",
"cache",
"and",
"return",
"as",
"part",
"of",
"the",
"search",
"request",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_source.go#L315-L318
|
train
|
olivere/elastic
|
search_source.go
|
ScriptField
|
func (s *SearchSource) ScriptField(scriptField *ScriptField) *SearchSource {
s.scriptFields = append(s.scriptFields, scriptField)
return s
}
|
go
|
func (s *SearchSource) ScriptField(scriptField *ScriptField) *SearchSource {
s.scriptFields = append(s.scriptFields, scriptField)
return s
}
|
[
"func",
"(",
"s",
"*",
"SearchSource",
")",
"ScriptField",
"(",
"scriptField",
"*",
"ScriptField",
")",
"*",
"SearchSource",
"{",
"s",
".",
"scriptFields",
"=",
"append",
"(",
"s",
".",
"scriptFields",
",",
"scriptField",
")",
"\n",
"return",
"s",
"\n",
"}"
] |
// ScriptField adds a single script field with the provided script.
|
[
"ScriptField",
"adds",
"a",
"single",
"script",
"field",
"with",
"the",
"provided",
"script",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_source.go#L321-L324
|
train
|
olivere/elastic
|
search_source.go
|
ScriptFields
|
func (s *SearchSource) ScriptFields(scriptFields ...*ScriptField) *SearchSource {
s.scriptFields = append(s.scriptFields, scriptFields...)
return s
}
|
go
|
func (s *SearchSource) ScriptFields(scriptFields ...*ScriptField) *SearchSource {
s.scriptFields = append(s.scriptFields, scriptFields...)
return s
}
|
[
"func",
"(",
"s",
"*",
"SearchSource",
")",
"ScriptFields",
"(",
"scriptFields",
"...",
"*",
"ScriptField",
")",
"*",
"SearchSource",
"{",
"s",
".",
"scriptFields",
"=",
"append",
"(",
"s",
".",
"scriptFields",
",",
"scriptFields",
"...",
")",
"\n",
"return",
"s",
"\n",
"}"
] |
// ScriptFields adds one or more script fields with the provided scripts.
|
[
"ScriptFields",
"adds",
"one",
"or",
"more",
"script",
"fields",
"with",
"the",
"provided",
"scripts",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_source.go#L327-L330
|
train
|
olivere/elastic
|
search_source.go
|
IndexBoost
|
func (s *SearchSource) IndexBoost(index string, boost float64) *SearchSource {
s.indexBoosts[index] = boost
return s
}
|
go
|
func (s *SearchSource) IndexBoost(index string, boost float64) *SearchSource {
s.indexBoosts[index] = boost
return s
}
|
[
"func",
"(",
"s",
"*",
"SearchSource",
")",
"IndexBoost",
"(",
"index",
"string",
",",
"boost",
"float64",
")",
"*",
"SearchSource",
"{",
"s",
".",
"indexBoosts",
"[",
"index",
"]",
"=",
"boost",
"\n",
"return",
"s",
"\n",
"}"
] |
// IndexBoost sets the boost that a specific index will receive when the
// query is executed against it.
|
[
"IndexBoost",
"sets",
"the",
"boost",
"that",
"a",
"specific",
"index",
"will",
"receive",
"when",
"the",
"query",
"is",
"executed",
"against",
"it",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_source.go#L334-L337
|
train
|
olivere/elastic
|
search_source.go
|
Stats
|
func (s *SearchSource) Stats(statsGroup ...string) *SearchSource {
s.stats = append(s.stats, statsGroup...)
return s
}
|
go
|
func (s *SearchSource) Stats(statsGroup ...string) *SearchSource {
s.stats = append(s.stats, statsGroup...)
return s
}
|
[
"func",
"(",
"s",
"*",
"SearchSource",
")",
"Stats",
"(",
"statsGroup",
"...",
"string",
")",
"*",
"SearchSource",
"{",
"s",
".",
"stats",
"=",
"append",
"(",
"s",
".",
"stats",
",",
"statsGroup",
"...",
")",
"\n",
"return",
"s",
"\n",
"}"
] |
// Stats group this request will be aggregated under.
|
[
"Stats",
"group",
"this",
"request",
"will",
"be",
"aggregated",
"under",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_source.go#L340-L343
|
train
|
olivere/elastic
|
search_source.go
|
InnerHit
|
func (s *SearchSource) InnerHit(name string, innerHit *InnerHit) *SearchSource {
s.innerHits[name] = innerHit
return s
}
|
go
|
func (s *SearchSource) InnerHit(name string, innerHit *InnerHit) *SearchSource {
s.innerHits[name] = innerHit
return s
}
|
[
"func",
"(",
"s",
"*",
"SearchSource",
")",
"InnerHit",
"(",
"name",
"string",
",",
"innerHit",
"*",
"InnerHit",
")",
"*",
"SearchSource",
"{",
"s",
".",
"innerHits",
"[",
"name",
"]",
"=",
"innerHit",
"\n",
"return",
"s",
"\n",
"}"
] |
// InnerHit adds an inner hit to return with the result.
|
[
"InnerHit",
"adds",
"an",
"inner",
"hit",
"to",
"return",
"with",
"the",
"result",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_source.go#L346-L349
|
train
|
olivere/elastic
|
indices_analyze.go
|
NewIndicesAnalyzeService
|
func NewIndicesAnalyzeService(client *Client) *IndicesAnalyzeService {
return &IndicesAnalyzeService{
client: client,
request: new(IndicesAnalyzeRequest),
}
}
|
go
|
func NewIndicesAnalyzeService(client *Client) *IndicesAnalyzeService {
return &IndicesAnalyzeService{
client: client,
request: new(IndicesAnalyzeRequest),
}
}
|
[
"func",
"NewIndicesAnalyzeService",
"(",
"client",
"*",
"Client",
")",
"*",
"IndicesAnalyzeService",
"{",
"return",
"&",
"IndicesAnalyzeService",
"{",
"client",
":",
"client",
",",
"request",
":",
"new",
"(",
"IndicesAnalyzeRequest",
")",
",",
"}",
"\n",
"}"
] |
// NewIndicesAnalyzeService creates a new IndicesAnalyzeService.
|
[
"NewIndicesAnalyzeService",
"creates",
"a",
"new",
"IndicesAnalyzeService",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/indices_analyze.go#L32-L37
|
train
|
olivere/elastic
|
indices_analyze.go
|
Index
|
func (s *IndicesAnalyzeService) Index(index string) *IndicesAnalyzeService {
s.index = index
return s
}
|
go
|
func (s *IndicesAnalyzeService) Index(index string) *IndicesAnalyzeService {
s.index = index
return s
}
|
[
"func",
"(",
"s",
"*",
"IndicesAnalyzeService",
")",
"Index",
"(",
"index",
"string",
")",
"*",
"IndicesAnalyzeService",
"{",
"s",
".",
"index",
"=",
"index",
"\n",
"return",
"s",
"\n",
"}"
] |
// Index is the name of the index to scope the operation.
|
[
"Index",
"is",
"the",
"name",
"of",
"the",
"index",
"to",
"scope",
"the",
"operation",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/indices_analyze.go#L40-L43
|
train
|
olivere/elastic
|
indices_analyze.go
|
Format
|
func (s *IndicesAnalyzeService) Format(format string) *IndicesAnalyzeService {
s.format = format
return s
}
|
go
|
func (s *IndicesAnalyzeService) Format(format string) *IndicesAnalyzeService {
s.format = format
return s
}
|
[
"func",
"(",
"s",
"*",
"IndicesAnalyzeService",
")",
"Format",
"(",
"format",
"string",
")",
"*",
"IndicesAnalyzeService",
"{",
"s",
".",
"format",
"=",
"format",
"\n",
"return",
"s",
"\n",
"}"
] |
// Format of the output.
|
[
"Format",
"of",
"the",
"output",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/indices_analyze.go#L46-L49
|
train
|
olivere/elastic
|
indices_analyze.go
|
Request
|
func (s *IndicesAnalyzeService) Request(request *IndicesAnalyzeRequest) *IndicesAnalyzeService {
if request == nil {
s.request = new(IndicesAnalyzeRequest)
} else {
s.request = request
}
return s
}
|
go
|
func (s *IndicesAnalyzeService) Request(request *IndicesAnalyzeRequest) *IndicesAnalyzeService {
if request == nil {
s.request = new(IndicesAnalyzeRequest)
} else {
s.request = request
}
return s
}
|
[
"func",
"(",
"s",
"*",
"IndicesAnalyzeService",
")",
"Request",
"(",
"request",
"*",
"IndicesAnalyzeRequest",
")",
"*",
"IndicesAnalyzeService",
"{",
"if",
"request",
"==",
"nil",
"{",
"s",
".",
"request",
"=",
"new",
"(",
"IndicesAnalyzeRequest",
")",
"\n",
"}",
"else",
"{",
"s",
".",
"request",
"=",
"request",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] |
// Request passes the analyze request to use.
|
[
"Request",
"passes",
"the",
"analyze",
"request",
"to",
"use",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/indices_analyze.go#L59-L66
|
train
|
olivere/elastic
|
indices_analyze.go
|
Analyzer
|
func (s *IndicesAnalyzeService) Analyzer(analyzer string) *IndicesAnalyzeService {
s.request.Analyzer = analyzer
return s
}
|
go
|
func (s *IndicesAnalyzeService) Analyzer(analyzer string) *IndicesAnalyzeService {
s.request.Analyzer = analyzer
return s
}
|
[
"func",
"(",
"s",
"*",
"IndicesAnalyzeService",
")",
"Analyzer",
"(",
"analyzer",
"string",
")",
"*",
"IndicesAnalyzeService",
"{",
"s",
".",
"request",
".",
"Analyzer",
"=",
"analyzer",
"\n",
"return",
"s",
"\n",
"}"
] |
// Analyzer is the name of the analyzer to use.
|
[
"Analyzer",
"is",
"the",
"name",
"of",
"the",
"analyzer",
"to",
"use",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/indices_analyze.go#L69-L72
|
train
|
olivere/elastic
|
indices_analyze.go
|
Attributes
|
func (s *IndicesAnalyzeService) Attributes(attributes ...string) *IndicesAnalyzeService {
s.request.Attributes = attributes
return s
}
|
go
|
func (s *IndicesAnalyzeService) Attributes(attributes ...string) *IndicesAnalyzeService {
s.request.Attributes = attributes
return s
}
|
[
"func",
"(",
"s",
"*",
"IndicesAnalyzeService",
")",
"Attributes",
"(",
"attributes",
"...",
"string",
")",
"*",
"IndicesAnalyzeService",
"{",
"s",
".",
"request",
".",
"Attributes",
"=",
"attributes",
"\n",
"return",
"s",
"\n",
"}"
] |
// Attributes is a list of token attributes to output; this parameter works
// only with explain=true.
|
[
"Attributes",
"is",
"a",
"list",
"of",
"token",
"attributes",
"to",
"output",
";",
"this",
"parameter",
"works",
"only",
"with",
"explain",
"=",
"true",
"."
] |
0534a7b1bf47b1ccf57e905491a641709f8a623d
|
https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/indices_analyze.go#L76-L79
|
train
|
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.