[Rename] ElasticsearchLeafReader class in server module (#177)

This commit refactors the ElasticsearchleafReader class located in the server
module to OpenSearchLeafReader. References and usages throughout the rest of the
codebase are fully refactored.

Signed-off-by: Nicholas Knize <nknize@amazon.com>
This commit is contained in:
Nick Knize 2021-03-03 19:30:07 -06:00
parent c42c2101a8
commit ce7864efdc
3 changed files with 16 additions and 19 deletions

View File

@ -29,7 +29,7 @@ import java.io.IOException;
/**
* A {@link org.apache.lucene.index.FilterDirectoryReader} that exposes
* Elasticsearch internal per shard / index information like the shard ID.
* OpenSearch internal per shard / index information like the shard ID.
*/
public final class OpenSearchDirectoryReader extends FilterDirectoryReader {
@ -63,7 +63,7 @@ public final class OpenSearchDirectoryReader extends FilterDirectoryReader {
/**
* Wraps the given reader in a {@link OpenSearchDirectoryReader} as
* well as all it's sub-readers in {@link ElasticsearchLeafReader} to
* well as all it's sub-readers in {@link OpenSearchLeafReader} to
* expose the given shard Id.
*
* @param reader the reader to wrap
@ -80,7 +80,7 @@ public final class OpenSearchDirectoryReader extends FilterDirectoryReader {
}
@Override
public LeafReader wrap(LeafReader reader) {
return new ElasticsearchLeafReader(reader, shardId);
return new OpenSearchLeafReader(reader, shardId);
}
}
@ -97,7 +97,7 @@ public final class OpenSearchDirectoryReader extends FilterDirectoryReader {
OpenSearchDirectoryReader openSearchDirectoryReader = getOpenSearchDirectoryReader(reader);
if (openSearchDirectoryReader == null) {
throw new IllegalArgumentException(
"Can't install close listener reader is not an OpenSearchDirectoryReader/ElasticsearchLeafReader");
"Can't install close listener reader is not an OpenSearchDirectoryReader/OpenSearchLeafReader");
}
IndexReader.CacheHelper cacheHelper = openSearchDirectoryReader.getReaderCacheHelper();
if (cacheHelper == null) {
@ -120,7 +120,7 @@ public final class OpenSearchDirectoryReader extends FilterDirectoryReader {
// We need to use FilterDirectoryReader#getDelegate and not FilterDirectoryReader#unwrap, because
// If there are multiple levels of filtered leaf readers then with the unwrap() method it immediately
// returns the most inner leaf reader and thus skipping of over any other filtered leaf reader that
// may be instance of ElasticsearchLeafReader. This can cause us to miss the shardId.
// may be instance of OpenSearchLeafReader. This can cause us to miss the shardId.
return getOpenSearchDirectoryReader(((FilterDirectoryReader) reader).getDelegate());
}
}

View File

@ -25,9 +25,9 @@ import org.elasticsearch.index.shard.ShardId;
/**
* A {@link org.apache.lucene.index.FilterLeafReader} that exposes
* Elasticsearch internal per shard / index information like the shard ID.
* OpenSearch internal per shard / index information like the shard ID.
*/
public final class ElasticsearchLeafReader extends SequentialStoredFieldsLeafReader {
public final class OpenSearchLeafReader extends SequentialStoredFieldsLeafReader {
private final ShardId shardId;
@ -37,7 +37,7 @@ public final class ElasticsearchLeafReader extends SequentialStoredFieldsLeafRea
*
* @param in specified base reader.
*/
public ElasticsearchLeafReader(LeafReader in, ShardId shardId) {
public OpenSearchLeafReader(LeafReader in, ShardId shardId) {
super(in);
this.shardId = shardId;
}
@ -59,16 +59,16 @@ public final class ElasticsearchLeafReader extends SequentialStoredFieldsLeafRea
return in.getReaderCacheHelper();
}
public static ElasticsearchLeafReader getElasticsearchLeafReader(LeafReader reader) {
public static OpenSearchLeafReader getOpenSearchLeafReader(LeafReader reader) {
if (reader instanceof FilterLeafReader) {
if (reader instanceof ElasticsearchLeafReader) {
return (ElasticsearchLeafReader) reader;
if (reader instanceof OpenSearchLeafReader) {
return (OpenSearchLeafReader) reader;
} else {
// We need to use FilterLeafReader#getDelegate and not FilterLeafReader#unwrap, because
// If there are multiple levels of filtered leaf readers then with the unwrap() method it immediately
// returns the most inner leaf reader and thus skipping of over any other filtered leaf reader that
// may be instance of ElasticsearchLeafReader. This can cause us to miss the shardId.
return getElasticsearchLeafReader(((FilterLeafReader) reader).getDelegate());
// may be instance of OpenSearchLeafReader. This can cause us to miss the shardId.
return getOpenSearchLeafReader(((FilterLeafReader) reader).getDelegate());
}
}
return null;

View File

@ -23,7 +23,7 @@ import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.LeafReader;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.lucene.index.OpenSearchDirectoryReader;
import org.elasticsearch.common.lucene.index.ElasticsearchLeafReader;
import org.elasticsearch.common.lucene.index.OpenSearchLeafReader;
public final class ShardUtils {
@ -35,9 +35,9 @@ public final class ShardUtils {
*/
@Nullable
public static ShardId extractShardId(LeafReader reader) {
final ElasticsearchLeafReader esReader = ElasticsearchLeafReader.getElasticsearchLeafReader(reader);
final OpenSearchLeafReader esReader = OpenSearchLeafReader.getOpenSearchLeafReader(reader);
if (esReader != null) {
assert reader.getRefCount() > 0 : "ElasticsearchLeafReader is already closed";
assert reader.getRefCount() > 0 : "OpenSearchLeafReader is already closed";
return esReader.shardId();
}
return null;
@ -55,7 +55,4 @@ public final class ShardUtils {
}
throw new IllegalArgumentException("can't extract shard ID, can't unwrap OpenSearchDirectoryReader");
}
}