Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

membuffer: implement ART with basic get/set #1451

Merged
merged 7 commits into from
Sep 18, 2024

Conversation

you06
Copy link
Contributor

@you06 you06 commented Aug 27, 2024

ref pingcap/tidb#55287

This PR implements ART with basic get and set.

@ti-chi-bot ti-chi-bot bot added dco-signoff: yes Indicates the PR's author has signed the dco. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 27, 2024
@you06 you06 requested review from cfzjywxk and ekexium August 27, 2024 09:27
if uint64(t.Size()) > t.bufferSizeLimit {
return &tikverr.ErrTxnTooLarge{Size: t.Size()}
}
return nil
}

func (t *ART) search(key artKey) (arena.MemdbArenaAddr, *artLeaf) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can documents its return values. Specifically, what value does it return when the key is not found?

return bytes.Equal(l.getKeyDepth(depth), key[depth:])
}

func (l *artLeaf) setKeyFlags(flags kv.KeyFlags) arena.MemdbArenaAddr {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this return value? Seems it unused.

copy(oldVal, value)
return true
}
t.size -= len(oldVal)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this line should be put outside of this function?

internal/unionstore/art/art_node.go Outdated Show resolved Hide resolved
internal/unionstore/art/art.go Show resolved Hide resolved
}

depth := uint32(0)
prevDepth := 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason that prevDepth must be int? Can it be unit32 as well to avoid type conversions?

internal/unionstore/art/art.go Outdated Show resolved Hide resolved
internal/unionstore/art/art_node.go Outdated Show resolved Hide resolved
internal/unionstore/art/art_node.go Outdated Show resolved Hide resolved
internal/unionstore/art/art_node.go Outdated Show resolved Hide resolved
Signed-off-by: you06 <[email protected]>
Signed-off-by: you06 <[email protected]>
if leaf == nil {
return 0, tikverr.ErrNotExist
}
if leaf.vAddr.IsNull() && leaf.isDeleted() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the isDeleted used here but not in the above Get function? Or when should the isDeleted be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isDelete marks the leaf is removed from the tree, which is used for cleanup after staging.

The difference between Get and GetFlags is the flag-only key (created by UpdateFlags), whose value address is null, so Get will return not exist error, meanwhile GetFlags should read the updated flags.

The RBT will remove the cleanup nodes from the tree, but ART will not (by now). Removing the node can reduces the height of the tree but also introduces the memory fragmentation (#1375). ART's performance isn't affected by the number of nodes, so it's ok to just mark it's deleted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to add comments about it here.

lcp := longestCommonPrefix(l1Key, l2Key, depth)

// calculate the common prefix length of new node.
an, n4 := t.newNode4()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the naming convention, there are places where newArtNode, newN4 := t.newNode4() is used.

For example using newArtNode or prevArtNode for ArtNode types, and node4Ptr for *node4 types.

}
return newLeaf.addr, lf
}
if !valid && next.kind == typeLeaf {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the meaning of valid here? Does it mean there is a leaf node but it is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid means if the current depth within the length of key. If valid is false, the in-place leaf is what we look for. If the in-place leaf is empty, we create it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to add commments about it at the valid function define location.

internal/unionstore/art/art_node.go Outdated Show resolved Hide resolved
internal/unionstore/art/art_node_test.go Show resolved Hide resolved
Copy link
Contributor

@ekexium ekexium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest LGTM

internal/unionstore/art/art_node.go Show resolved Hide resolved
internal/unionstore/art/art_node.go Outdated Show resolved Hide resolved
internal/unionstore/art/art_node.go Outdated Show resolved Hide resolved
internal/unionstore/art/art_node.go Outdated Show resolved Hide resolved
internal/unionstore/art/art_node.go Outdated Show resolved Hide resolved
internal/unionstore/art/art_node.go Show resolved Hide resolved
internal/unionstore/art/art_node.go Show resolved Hide resolved
Signed-off-by: you06 <[email protected]>

address comment

Signed-off-by: you06 <[email protected]>
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Sep 18, 2024
Copy link
Contributor

@cfzjywxk cfzjywxk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move on the PR merge as there is still plenty of work

@ti-chi-bot ti-chi-bot bot added the lgtm label Sep 18, 2024
Copy link

ti-chi-bot bot commented Sep 18, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, ekexium

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Sep 18, 2024
Copy link

ti-chi-bot bot commented Sep 18, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-09-18 08:39:22.404670818 +0000 UTC m=+1036832.145094752: ☑️ agreed by ekexium.
  • 2024-09-18 09:21:47.03248637 +0000 UTC m=+1039376.772910308: ☑️ agreed by cfzjywxk.

@ti-chi-bot ti-chi-bot bot merged commit 6beede6 into tikv:master Sep 18, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants