mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
try and extract store directory also if its wrapped in a compound dir
This commit is contained in:
parent
8c1073bb6e
commit
46d191c8d4
@ -22,6 +22,7 @@ package org.elasticsearch.index.shard;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.SegmentReader;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.index.store.DirectoryUtils;
|
||||
import org.elasticsearch.index.store.Store;
|
||||
|
||||
/**
|
||||
@ -38,8 +39,9 @@ public class ShardUtils {
|
||||
public static ShardId extractShardId(IndexReader reader) {
|
||||
if (reader instanceof SegmentReader) {
|
||||
SegmentReader sReader = (SegmentReader) reader;
|
||||
if (sReader.directory() instanceof Store.StoreDirectory) {
|
||||
return ((Store.StoreDirectory) sReader.directory()).shardId();
|
||||
Store.StoreDirectory storeDir = DirectoryUtils.getStoreDirectory(sReader.directory());
|
||||
if (storeDir != null) {
|
||||
return storeDir.shardId();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -19,11 +19,10 @@
|
||||
|
||||
package org.elasticsearch.index.store;
|
||||
|
||||
import org.apache.lucene.store.CompoundFileDirectory;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.FilterDirectory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
|
||||
/**
|
||||
* Utils for working with {@link Directory} classes.
|
||||
@ -32,6 +31,27 @@ public final class DirectoryUtils {
|
||||
|
||||
private DirectoryUtils() {} // no instance
|
||||
|
||||
/**
|
||||
* Try and extract a store directory out of a directory, tries to take into
|
||||
* account the fact that a directory is a filter directory, and/or a compound dir.
|
||||
*/
|
||||
@Nullable
|
||||
public static Store.StoreDirectory getStoreDirectory(Directory dir) {
|
||||
Directory current = dir;
|
||||
while (true) {
|
||||
if (current instanceof Store.StoreDirectory) {
|
||||
return (Store.StoreDirectory) current;
|
||||
}
|
||||
if (current instanceof FilterDirectory) {
|
||||
current = ((FilterDirectory) current).getDelegate();
|
||||
} else if (current instanceof CompoundFileDirectory) {
|
||||
current = ((CompoundFileDirectory) current).getDirectory();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final Directory getLeafDirectory(FilterDirectory dir) {
|
||||
Directory current = dir.getDelegate();
|
||||
while ((current instanceof FilterDirectory)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user