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
handle an empty namespace in FullScanIterator skip list - levedb #1360
Conversation
case s.isCurrentNamespaceSet && ns == s.currentNamespace: | ||
return compositeKey, dbVal, nil | ||
// new namespace begins | ||
case !s.toSkip(ns): | ||
s.isCurrentNamespaceSet = true | ||
s.currentNamespace = ns | ||
return compositeKey, dbVal, nil | ||
// skip the new namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, these two cases separately are not needed as such. This can simply be
switch {
case !s.toSkip(ns):
return compositeKey, dbVal, nil
default:
// default logic
}
I had added additional explicit check for string equality as an future optimization, where in if we could somehow reuse the same string till the namespace changes. But in the current form, as it's causing to add one more flag, IMO, let's keep the simpler version for now - wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch { case !s.toSkip(ns): return compositeKey, dbVal, nil default: // default logic }
Yes, I thought of doing this. There were two choices and both had a + and -.
Choice 1
If we go with the above flow, we would call the following function for every key-value pair in the database but it simplifies the code.
func isPvtdataNs(namespace string) bool {
return strings.Contains(namespace, nsJoiner+pvtDataPrefix)
}
Choice 2
if we go with the current one, it makes the code bit complex but reduces the number of calls to isPvtdataNs
switch {
case s.isCurrentNamespaceSet && ns == s.currentNamespace:
return compositeKey, dbVal, nil
case !s.toSkip(ns):
s.isCurrentNamespaceSet = true
s.currentNamespace = ns
return compositeKey, dbVal, nil
}
As you prefer choice 1, I will go with that as I don't have a strong preference here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Later, if needed (after the performance benchmarking), we can add a method toSkipNamespaces()
on the scanner and include a map to avoid calling isPvtdataNs()
for every entry in the database.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it makes the code bit complex but reduces the number of calls to isPvtdataNs
Just for a note, this does not make any difference until the string comparison in the other case is optimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Manish, for merging this. I quickly ran a benchmark.
BenchmarkIsPvtNs-8 140749465 8.43 ns/op
It took 1.18sec for more than 100 million calls. Hence, it isn't an issue.
An empty namespace is used for the config block. However, we would skip only the private data namespaces but not empty namespaces. However, we need to make the function generic. FAB-17946 Signed-off-by: senthil <cendhu@gmail.com>
Type of change
Description
An empty namespace is used for the config block. However, we would skip only the private data namespaces but not an empty namespace. However, we need to make the function generic.