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

Question about the format comments in Add and Put methods of Memtable. #1201

Open
gukj-spel opened this issue Jul 26, 2024 · 2 comments
Open

Comments

@gukj-spel
Copy link

Hello, Recently I am learning leveldb by reading its source code. When I saw this function fallow:

void MemTable::Add(SequenceNumber s, ValueType type, const Slice& key,
                   const Slice& value) {
  // Format of an entry is concatenation of:
  //  key_size     : varint32 of internal_key.size()
  //  key bytes    : char[internal_key.size()]
  //  tag          : uint64((sequence << 8) | type)
  //  value_size   : varint32 of value.size()
  //  value bytes  : char[value.size()]

I have a question about this comments of key bytes format. Shouldn't it' s size be the user_key 's size which equal to internal_key.size() - 8? Why this comment say its size is the size of the internal_key?

@felipecrv
Copy link
Contributor

Because it would be more complicated to manipulate the full entries if one had to always add 8 to get the size of the key part.

@gukj-spel
Copy link
Author

Because it would be more complicated to manipulate the full entries if one had to always add 8 to get the size of the key part.

Oh, yeah. Thank you for the answer. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants