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

handle an empty namespace in FullScanIterator skip list - levedb #1360

Merged
merged 1 commit into from Jun 2, 2020

Conversation

cendhu
Copy link
Contributor

@cendhu cendhu commented Jun 1, 2020

Type of change

  • Improvement (improvement to code)

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.

Comment on lines 327 to 334
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
Copy link
Contributor

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?

Copy link
Contributor Author

@cendhu cendhu Jun 2, 2020

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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>
@manish-sethi manish-sethi merged commit 17f5c7f into hyperledger:master Jun 2, 2020
@cendhu cendhu deleted the fix-skip-ns branch June 10, 2020 15:27
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

Successfully merging this pull request may close these issues.

None yet

2 participants