Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
Signed-off-by: you06 <[email protected]>
  • Loading branch information
you06 committed Aug 27, 2024
1 parent 25acc3b commit 3ebca27
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
4 changes: 4 additions & 0 deletions internal/unionstore/art/art.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ func New() *ART {
}

func (t *ART) Get(key []byte) ([]byte, error) {
// 1. search the leaf node.
_, leaf := t.search(key)
if leaf == nil || leaf.vAddr.IsNull() {
return nil, tikverr.ErrNotExist
}
// 2. get the value from the vlog.
return t.allocator.vlogAllocator.GetValue(leaf.vAddr), nil
}

Expand Down Expand Up @@ -79,7 +81,9 @@ func (t *ART) Set(key artKey, value []byte, ops ...kv.FlagsOp) error {
if len(t.stages) == 0 {
t.dirty = true
}
// 1. create or search the exist leaf in the tree.
addr, leaf := t.recursiveInsert(key)
// 2. set the value and flags.
t.setValue(addr, leaf, value, ops)
if uint64(t.Size()) > t.bufferSizeLimit {
return &tikverr.ErrTxnTooLarge{Size: t.Size()}
Expand Down
1 change: 0 additions & 1 deletion internal/unionstore/art/art_arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//nolint:unused
package art

import (
Expand Down
35 changes: 13 additions & 22 deletions internal/unionstore/art/art_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ package art

import (
"bytes"
"github.com/tikv/client-go/v2/internal/unionstore/arena"
"github.com/tikv/client-go/v2/kv"
"math"
"math/bits"
"sort"
"unsafe"

"github.com/tikv/client-go/v2/internal/unionstore/arena"
"github.com/tikv/client-go/v2/kv"
)

type nodeKind uint16
Expand Down Expand Up @@ -55,22 +56,6 @@ const (

var nullArtNode = artNode{kind: typeInvalid, addr: arena.NullAddr}

var (
// nullNode48 is used to initialize the node48
nullNode48 = node48{}
// nullNode256 is used to initialize the node256
nullNode256 = node256{}
)

func init() {
for i := 0; i < node48cap; i++ {
nullNode48.children[i] = artNode{kind: typeInvalid, addr: arena.NullAddr}
}
for i := 0; i < node256cap; i++ {
nullNode256.children[i] = artNode{kind: typeInvalid, addr: arena.NullAddr}
}
}

type artKey []byte

type artNode struct {
Expand Down Expand Up @@ -161,7 +146,9 @@ func (an *artNode) node(a *artAllocator) *nodeBase {
}
}

// at returns the nth child of the node.
// at returns the nth child of the node, used for test.
//
//nolint:unused
func (an *artNode) at(a *artAllocator, idx int) artNode {
switch an.kind {
case typeNode4:
Expand All @@ -183,7 +170,6 @@ func (n48 *node48) init() {
n48.nodeBase.init()
// initialize node48
n48.present[0], n48.present[1], n48.present[2], n48.present[3] = 0, 0, 0, 0
copy(n48.children[:], nullNode48.children[:])
}

// nextPresentIdx returns the next present index starting from the given index.
Expand Down Expand Up @@ -222,7 +208,7 @@ func (n256 *node256) init() {
// initialize nodeBase
n256.nodeBase.init()
// initialize node256
copy(n256.children[:], nullNode256.children[:])
n256.present[0], n256.present[1], n256.present[2], n256.present[3] = 0, 0, 0, 0
}

func (n256 *node256) nextPresentIdx(start int) int {
Expand Down Expand Up @@ -302,6 +288,8 @@ const (
)

// markDelete marks the artLeaf as deleted
//
//nolint:unused
func (l *artLeaf) markDelete() {
l.flags = deleteFlag
}
Expand Down Expand Up @@ -470,7 +458,10 @@ func (an *artNode) findChild48(a *artAllocator, c byte) (int, artNode) {

func (an *artNode) findChild256(a *artAllocator, c byte) (int, artNode) {
n256 := an.node256(a)
return int(c), n256.children[c]
if n256.present[c>>n48s]&(1<<(c%n48m)) != 0 {
return int(c), n256.children[c]
}
return -2, nullArtNode
}

func (an *artNode) swapChild(a *artAllocator, c byte, child artNode) {
Expand Down
4 changes: 1 addition & 3 deletions internal/unionstore/art/art_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ func TestAllocNode(t *testing.T) {
require.Equal(t, [4]uint64{0, 0, 0, 0}, n.present)
case *node256:
base = &n.nodeBase
for i := 0; i < node256cap; i++ {
require.Equal(t, n.children[i], nullArtNode)
}
require.Equal(t, [4]uint64{0, 0, 0, 0}, n.present)
default:
require.Fail(t, "unknown node type")
}
Expand Down

0 comments on commit 3ebca27

Please sign in to comment.