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

Adds read locks to LuceneSearchProvider. #52

Merged
merged 1 commit into from
Sep 29, 2016

Conversation

archolewa
Copy link
Contributor

@archolewa archolewa commented Sep 27, 2016

The LuceneSearchProvider is missing read locks before reading the lucene database. As a result, Bad Things can happen if you attempt to read from Lucene (i.e. resolving dimension filters) while loading dimension indices.

@michael-mclawhorn
Copy link
Contributor

What would be great would be if we had some way of testing access to the indexer low levels so we could validate that all calls to them were only done in a readLocked context.

It looks pretty good. Needs a CHANGELOG.

Copy link
Collaborator

@cdeszaq cdeszaq left a comment

Choose a reason for hiding this comment

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

There's a lock that I think needs to be wider, and a Changelog entry is needed

@@ -547,17 +554,23 @@ private Query getFilterQuery(Set<ApiFilter> filters, int perPage) {
.map(document -> document.get(idKey))
.map(dimension::findDimensionRowByKeyValue)
.collect(Collectors.toCollection(TreeSet::new));

int documentCount;
lock.readLock().lock();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we need to get this lock much earlier in this method? We're getting indexSearcher up near the top of the method...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

@cdeszaq
Copy link
Collaborator

cdeszaq commented Sep 27, 2016

A few more thoughts:

  • Probably also need a write-lock in the reopenIndexSearcher method when we close/re-open it
  • clearDimension needs some help:
    -It currently will deadlock, since it holds a write-lock, and calls refreshCardinality from within it, which tries to grab a read-lock. I think moving the method calls torefreshCardinality and reopenIndexSearcher outside the try/catch/finally is all that's needed, but I didn't trace it too carefully

@archolewa archolewa force-pushed the lucene-index-missing-read-lock branch from 6776484 to 84db9a9 Compare September 27, 2016 21:18
@archolewa
Copy link
Contributor Author

@michael-mclawhorn You might be able to do something by taking a write lock in a separate thread and then inspecting the guts of the read-write lock. I did a little bit of digging, but it's not immediately clear to me how to do that.

Alternatively, you could take a write lock and then verify that the method doesn't finish, but that would significantly increase our testing time.

@archolewa archolewa force-pushed the lucene-index-missing-read-lock branch 2 times, most recently from acdfe4b to b7fc02b Compare September 27, 2016 21:35
Copy link
Collaborator

@cdeszaq cdeszaq left a comment

Choose a reason for hiding this comment

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

👍

lock.readLock().lock();
try {
numDocs = getIndexSearcher().getIndexReader().numDocs();
numDocs = indexSearcher.getIndexReader().numDocs();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we no longer going through the getter?

try {
IndexSearcher indexSearcher = getIndexSearcher();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this moving outside the try?

Copy link
Collaborator

Choose a reason for hiding this comment

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

And isn't the whole point of this lock so that the index searcher can get cycled while it's being held?

int documentCount;
initializeIndexSearcher();
try {
lock.readLock().lock();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move outside the try to match the other calls in this class?

Copy link

Choose a reason for hiding this comment

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

Correct. any lock must complete before the try

@cdeszaq
Copy link
Collaborator

cdeszaq commented Sep 29, 2016

👍

@wcekan
Copy link

wcekan commented Sep 29, 2016

👍

@archolewa archolewa deleted the lucene-index-missing-read-lock branch September 29, 2016 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants