Delegate CoreCacheKey for all reader wrappers

This change removes obsolete forbidden API usage, cuts over
from an interface to an abstract class for IndexSearcherWrapper and
delegates all core cache keys to the wrapped reader.

Relates to elastic/elasticsearch#774

Original commit: elastic/x-pack-elasticsearch@3799bab0d9
This commit is contained in:
Simon Willnauer 2015-10-14 10:28:06 +02:00
parent 245614c9cb
commit baa06fb6fb
5 changed files with 16 additions and 15 deletions

View File

@ -65,6 +65,10 @@ public final class DocumentSubsetReader extends FilterLeafReader {
}
}
@Override
public Object getCoreCacheKey() {
return in.getCoreCacheKey();
}
}
private final BitSet roleQueryBits;

View File

@ -81,6 +81,11 @@ public final class FieldSubsetReader extends FilterLeafReader {
}
}
}
@Override
public Object getCoreCacheKey() {
return in.getCoreCacheKey();
}
}
/** List of filtered fields */
@ -215,11 +220,6 @@ public final class FieldSubsetReader extends FilterLeafReader {
// we share core cache keys (for e.g. fielddata)
@Override
public Object getCombinedCoreAndDeletesKey() {
return in.getCombinedCoreAndDeletesKey();
}
@Override
public Object getCoreCacheKey() {
return in.getCoreCacheKey();

View File

@ -14,6 +14,8 @@ import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.logging.support.LoggerMessageFormat;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.cache.bitset.BitsetFilterCache;
@ -49,18 +51,19 @@ import static org.apache.lucene.search.BooleanClause.Occur.FILTER;
* Document level security is enabled by wrapping the original {@link DirectoryReader} in a {@link DocumentSubsetReader}
* instance.
*/
public final class ShieldIndexSearcherWrapper extends AbstractComponent implements IndexSearcherWrapper {
public final class ShieldIndexSearcherWrapper extends IndexSearcherWrapper {
private final MapperService mapperService;
private final Set<String> allowedMetaFields;
private final IndexQueryParserService parserService;
private final BitsetFilterCache bitsetFilterCache;
private final ShieldLicenseState shieldLicenseState;
private final ESLogger logger;
@Inject
public ShieldIndexSearcherWrapper(@IndexSettings Settings indexSettings, IndexQueryParserService parserService,
MapperService mapperService, BitsetFilterCache bitsetFilterCache, ShieldLicenseState shieldLicenseState) {
super(indexSettings);
this.logger = Loggers.getLogger(getClass(), indexSettings);
this.mapperService = mapperService;
this.parserService = parserService;
this.bitsetFilterCache = bitsetFilterCache;
@ -76,7 +79,7 @@ public final class ShieldIndexSearcherWrapper extends AbstractComponent implemen
}
@Override
public DirectoryReader wrap(DirectoryReader reader) {
protected DirectoryReader wrap(DirectoryReader reader) {
if (shieldLicenseState.documentAndFieldLevelSecurityEnabled() == false) {
return reader;
}
@ -131,7 +134,7 @@ public final class ShieldIndexSearcherWrapper extends AbstractComponent implemen
}
@Override
public IndexSearcher wrap(EngineConfig engineConfig, IndexSearcher searcher) throws EngineException {
protected IndexSearcher wrap(EngineConfig engineConfig, IndexSearcher searcher) throws EngineException {
if (shieldLicenseState.documentAndFieldLevelSecurityEnabled() == false) {
return searcher;
}

View File

@ -196,9 +196,6 @@ public class DocumentSubsetReaderTests extends ESTestCase {
assertEquals(1, ir2.leaves().size());
assertSame(ir.leaves().get(0).reader().getCoreCacheKey(), ir2.leaves().get(0).reader().getCoreCacheKey());
// this is kind of stupid, but for now its here
assertNotSame(ir.leaves().get(0).reader().getCombinedCoreAndDeletesKey(), ir2.leaves().get(0).reader().getCombinedCoreAndDeletesKey());
TestUtil.checkReader(ir);
IOUtils.close(ir, ir2, iw, dir);
}

View File

@ -707,9 +707,6 @@ public class FieldSubsetReaderTests extends ESTestCase {
assertEquals(1, ir2.leaves().size());
assertSame(ir.leaves().get(0).reader().getCoreCacheKey(), ir2.leaves().get(0).reader().getCoreCacheKey());
// this is kind of stupid, but for now its here
assertNotSame(ir.leaves().get(0).reader().getCombinedCoreAndDeletesKey(), ir2.leaves().get(0).reader().getCombinedCoreAndDeletesKey());
TestUtil.checkReader(ir);
IOUtils.close(ir, ir2, iw, dir);
}