Skip to content

Conversation

@jimczi
Copy link
Contributor

@jimczi jimczi commented Jul 2, 2019

This commit changes the way we manage refreshes in the index engines.
Instead of relying on a SearcherManager, this change uses a ReaderManager that
creates ElasticsearchDirectoryReader when needed. Searchers are now created on-demand
(when acquireSearcher is called) from the current ElasticsearchDirectoryReader.
It also slightly changes the Engine.Searcher to extend IndexSearcher in order
to simplify the usage in the consumer.

This commit changes the way we manage refreshes in the index engines.
Instead of relying on a SearcherManager, this change uses a ReaderManager that
creates ElasticsearchDirectoryReader when needed. Searchers are now created on-demand
(when acquireSearcher is called) from the current ElasticsearchDirectoryReader.
It also slightly changes the Engine.Searcher to extend IndexSearcher in order
to simplify the usage in the consumer.
@jimczi jimczi added >enhancement :Search/Search Search-related issues that do not fall into other categories :Distributed Indexing/Engine Anything around managing Lucene and the Translog in an open shard. v8.0.0 v7.3.0 labels Jul 2, 2019
@jimczi jimczi requested review from jpountz and s1monw July 2, 2019 08:58
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

Copy link
Contributor

@s1monw s1monw left a comment

Choose a reason for hiding this comment

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

Looks good, left some minors

private final Closeable onClose;

public Searcher(String source, IndexSearcher searcher, Closeable onClose) {
public Searcher(String source, IndexReader reader,
Copy link
Contributor

Choose a reason for hiding this comment

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

any chance we can make this ElasticsearchDirectoryReader instead of IndexReader?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ElasticsearchDirectoryReader can be wrapped by plugins so we'd need to move/recreate one when we create the Searcher. I agree that it would be simpler to always force the ElasticsearchDirectoryReader at the top though so I'll give it a try.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot the TranslogLeafReader that is used for get requests so this would require a bigger change and more refactoring. Maybe better to do this in a follow up ?

Copy link
Contributor

Choose a reason for hiding this comment

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

sure ++ no rush I didn't anticipate this one either

return searcher.getIndexReader();
}

public DirectoryReader getDirectoryReader() {
Copy link
Contributor

Choose a reason for hiding this comment

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

if we can move to a concrete reader then we can make this a hard cast to ElasticsearchDirectoryReader

}
}

private void notifyListener(ElasticsearchDirectoryReader reader, ElasticsearchDirectoryReader previousReader) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we move the reference stealing into this method too?

Copy link
Contributor

Choose a reason for hiding this comment

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

then we can also do this return incrementAndNotify(acquire, referenceToRefresh)


private void notifyListener(ElasticsearchDirectoryReader reader, ElasticsearchDirectoryReader previousReader) throws IOException {
boolean success = false;
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

you can maybe do this:

reader.incRef(); // steal the reference
try (Closeable c = reader::decRef) {
  refreshListener.accept(reader, previousReader);
  reader.incRef(); // double inc-ref if we were successful
  return reader;
}

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

if (renewed) {
// refresh outside of the write lock
// we have to refresh internal searcher here to ensure we release unreferenced segments.
// we have to refresh internal readr here to ensure we release unreferenced segments.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/readr/reader

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ta

@jimczi
Copy link
Contributor Author

jimczi commented Jul 3, 2019

@s1monw , the Engine.Searcher is used in the realtime get case where we read from the translog so we cannot use an ElasticsearchDirectoryReader in all cases. I pushed a commit to address the other comments but the move to a concrete reader in all cases require more change.

@jpountz jpountz added v7.4.0 and removed v7.3.0 labels Jul 3, 2019
Copy link
Contributor

@s1monw s1monw left a comment

Choose a reason for hiding this comment

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

LGTM

@jimczi jimczi merged commit 399d53e into elastic:master Jul 4, 2019
@jimczi jimczi deleted the enhancements/reader_manager branch July 4, 2019 20:48
@jimczi
Copy link
Contributor Author

jimczi commented Jul 4, 2019

Thanks @s1monw

jimczi added a commit that referenced this pull request Jul 4, 2019
This commit changes the way we manage refreshes in the index engines.
Instead of relying on a SearcherManager, this change uses a ReaderManager that
creates ElasticsearchDirectoryReader when needed. Searchers are now created on-demand
(when acquireSearcher is called) from the current ElasticsearchDirectoryReader.
It also slightly changes the Engine.Searcher to extend IndexSearcher in order
to simplify the usage in the consumer.
@colings86 colings86 removed the :Search/Search Search-related issues that do not fall into other categories label Aug 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Distributed Indexing/Engine Anything around managing Lucene and the Translog in an open shard. >enhancement v7.4.0 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants