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

state: remove duplicate tableCheck indexes #9796

Merged
merged 4 commits into from
Mar 10, 2021

Conversation

dnephin
Copy link
Contributor

@dnephin dnephin commented Feb 19, 2021

This PR uses a new pattern (see agent/consul/state/indexer.go) for defining memdb indexes in the state store.

By using this pattern we are able to remove one of the indexes on the check table. The generic index did not behave the way we wanted, which forced us to create a second index. Now we can use a single index because we add the blank string value as part of the index.

Since each section of the index is null terminated, there is no ambiguity. Node checks will have two sequential null bytes at the end, but that is ok.

This PR also makes the new function signature for indexFromObject match that of indexFromQuery by using errors as values. This will allow us to use the same function for both sets of operations (queries and insert/delete).

It also adds an indexBuilder which can be used instead of a bytes.Buffer to add null terminators, and makes the index building a little less verbose.

catalogChecksForNodeService was a duplicate of catalogListServiceChecks
By using a new pattern for more specific indexes. This allows us to use
the same index for both service checks and node checks. It removes the
abstraction around memdb.Txn operations, and isolates all of the
enterprise differences in a single place (the indexer).
These new functional indexers provide a few advantages:

1. enterprise differences can be isolated to a single function (the
   indexer function), making code easier to change
2. as a consequence of (1) we no longer need to wrap all the calls to
   Txn operations, making code easier to read.
3. by removing reflection we should increase the performance of all
   operations.

One important change is in making all the function signatures the same.

https://blog.golang.org/errors-are-values

An extra boolean return value for SingleIndexer.FromObject is superfluous.
The error value can indicate when the index value could not be created.
By removing this extra return value we can use the same signature for both
indexer functions.

This has the nice properly of a function being usable for both indexing operations.
@dnephin dnephin requested a review from a team February 19, 2021 22:18
@hashicorp-ci
Copy link
Contributor

🤔 Double check that this PR does not require a changelog entry in the .changelog directory. Reference

@dnephin dnephin added the pr/no-changelog PR does not need a corresponding .changelog entry label Feb 19, 2021
Copy link
Member

@banks banks left a comment

Choose a reason for hiding this comment

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

LGTM! I like this new pattern!

@dnephin dnephin merged commit 948d1a3 into master Mar 10, 2021
@dnephin dnephin deleted the dnephin/state-cleanup-catalog-index-oss branch March 10, 2021 17:20
@hashicorp-ci
Copy link
Contributor

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/335707.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/no-changelog PR does not need a corresponding .changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants