MCPcopy
hub / github.com/etcd-io/bbolt / put

Method put

node.go:117–142  ·  view source on GitHub ↗

put inserts a key/value.

(oldKey, newKey, value []byte, pgId common.Pgid, flags uint32)

Source from the content-addressed store, hash-verified

115
116// put inserts a key/value.
117func (n *node) put(oldKey, newKey, value []byte, pgId common.Pgid, flags uint32) {
118 if pgId >= n.bucket.tx.meta.Pgid() {
119 panic(fmt.Sprintf("pgId (%d) above high water mark (%d)", pgId, n.bucket.tx.meta.Pgid()))
120 } else if len(oldKey) <= 0 {
121 panic("put: zero-length old key")
122 } else if len(newKey) <= 0 {
123 panic("put: zero-length new key")
124 }
125
126 // Find insertion index.
127 index := sort.Search(len(n.inodes), func(i int) bool { return bytes.Compare(n.inodes[i].Key(), oldKey) != -1 })
128
129 // Add capacity and shift nodes if we don't have an exact match and need to insert.
130 exact := len(n.inodes) > 0 && index < len(n.inodes) && bytes.Equal(n.inodes[index].Key(), oldKey)
131 if !exact {
132 n.inodes = append(n.inodes, common.Inode{})
133 copy(n.inodes[index+1:], n.inodes[index:])
134 }
135
136 inode := &n.inodes[index]
137 inode.SetFlags(flags)
138 inode.SetKey(newKey)
139 inode.SetValue(value)
140 inode.SetPgid(pgId)
141 common.Assert(len(inode.Key()) > 0, "put: zero-length inode key")
142}
143
144// del removes a key from the node.
145func (n *node) del(key []byte) {

Callers 11

TestNode_putFunction · 0.95
TestNode_write_LeafPageFunction · 0.95
TestNode_splitFunction · 0.95
TestNode_split_MinKeysFunction · 0.95
spillMethod · 0.80
CreateBucketMethod · 0.80
MoveBucketMethod · 0.80
PutMethod · 0.80
spillMethod · 0.80

Calls 7

AssertFunction · 0.92
SetKeyMethod · 0.80
SetValueMethod · 0.80
PgidMethod · 0.45
KeyMethod · 0.45
SetFlagsMethod · 0.45
SetPgidMethod · 0.45

Tested by 5

TestNode_putFunction · 0.76
TestNode_write_LeafPageFunction · 0.76
TestNode_splitFunction · 0.76
TestNode_split_MinKeysFunction · 0.76