mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-25 01:19:02 +00:00
Simplify plugin API and fix IndexService internal allocation
This commit is contained in:
parent
cf0179bf12
commit
94bed42213
@ -111,10 +111,11 @@ public final class IndexService extends AbstractIndexComponent implements IndexC
|
||||
this.nodeServicesProvider = nodeServicesProvider;
|
||||
this.indexStore = indexStore;
|
||||
indexFieldData.setListener(new FieldDataCacheListener(this));
|
||||
this.searcherWrapper = wrapperFactory.newWrapper(this);
|
||||
this.bitsetFilterCache = new BitsetFilterCache(indexSettings, nodeServicesProvider.getWarmer(), new BitsetCacheListener(this));
|
||||
this.indexCache = new IndexCache(indexSettings, queryCache, bitsetFilterCache);
|
||||
this.engineFactory = engineFactory;
|
||||
// initialize this last -- otherwise if the wrapper requires any other member to be non-null we fail with an NPE
|
||||
this.searcherWrapper = wrapperFactory.newWrapper(this);
|
||||
}
|
||||
|
||||
public int numberOfShards() {
|
||||
|
@ -70,11 +70,23 @@ public abstract class Plugin {
|
||||
return Settings.Builder.EMPTY_SETTINGS;
|
||||
}
|
||||
|
||||
public List<Closeable> indexService(IndexService indexService) {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
/**
|
||||
* Called once the given {@link IndexService} is fully constructed but not yet published.
|
||||
* This is used to initialize plugin services that require acess to index level resources
|
||||
*/
|
||||
public void onIndexService(IndexService indexService) {}
|
||||
|
||||
/**
|
||||
* Called before a new index is created on a node. The given module can be used to regsiter index-leve
|
||||
* extensions.
|
||||
*/
|
||||
public void onIndexModule(IndexModule indexModule) {}
|
||||
|
||||
/**
|
||||
* Old-style guice index level extension point.
|
||||
*
|
||||
* @deprecated use #onIndexModule instead
|
||||
*/
|
||||
@Deprecated
|
||||
public final void onModule(IndexModule indexModule) {}
|
||||
}
|
||||
|
@ -41,7 +41,6 @@ import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.IndexModule;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.shard.IndexEventListener;
|
||||
import org.elasticsearch.index.shard.IndexShard;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
@ -249,19 +248,12 @@ public class PluginsService extends AbstractComponent {
|
||||
plugin.v2().onIndexModule(indexModule);
|
||||
}
|
||||
indexModule.addIndexEventListener(new IndexEventListener() {
|
||||
final List<Closeable> closeables = new ArrayList<>();
|
||||
@Override
|
||||
public void afterIndexCreated(IndexService indexService) {
|
||||
for (Tuple<PluginInfo, Plugin> plugin : plugins) {
|
||||
List<Closeable> services = plugin.v2().indexService(indexService);
|
||||
closeables.addAll(services);
|
||||
plugin.v2().onIndexService(indexService);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeIndexClosed(IndexService indexService) {
|
||||
IOUtils.closeWhileHandlingException(closeables);
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
|
@ -43,12 +43,11 @@ public class ExternalMapperPlugin extends Plugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Closeable> indexService(IndexService indexService) {
|
||||
public void onIndexService(IndexService indexService) {
|
||||
final MapperService mapperService = indexService.mapperService();
|
||||
mapperService.documentMapperParser().putRootTypeParser(ExternalMetadataMapper.CONTENT_TYPE, new ExternalMetadataMapper.TypeParser());
|
||||
mapperService.documentMapperParser().putTypeParser(EXTERNAL, new ExternalMapper.TypeParser(EXTERNAL, "foo"));
|
||||
mapperService.documentMapperParser().putTypeParser(EXTERNAL_BIS, new ExternalMapper.TypeParser(EXTERNAL_BIS, "bar"));
|
||||
mapperService.documentMapperParser().putTypeParser(EXTERNAL_UPPER, new ExternalMapper.TypeParser(EXTERNAL_UPPER, "FOO BAR"));
|
||||
return super.indexService(indexService);
|
||||
}
|
||||
}
|
@ -19,15 +19,11 @@
|
||||
|
||||
package org.elasticsearch.plugin.mapper;
|
||||
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.mapper.murmur3.Murmur3FieldMapper;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class MapperMurmur3Plugin extends Plugin {
|
||||
@ -43,9 +39,8 @@ public class MapperMurmur3Plugin extends Plugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Closeable> indexService(IndexService indexService) {
|
||||
public void onIndexService(IndexService indexService) {
|
||||
indexService.mapperService().documentMapperParser().putTypeParser(Murmur3FieldMapper.CONTENT_TYPE, new Murmur3FieldMapper.TypeParser());
|
||||
return super.indexService(indexService);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,15 +19,11 @@
|
||||
|
||||
package org.elasticsearch.plugin.mapper;
|
||||
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.mapper.size.SizeFieldMapper;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class MapperSizePlugin extends Plugin {
|
||||
@ -43,9 +39,8 @@ public class MapperSizePlugin extends Plugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Closeable> indexService(IndexService indexService) {
|
||||
public void onIndexService(IndexService indexService) {
|
||||
indexService.mapperService().documentMapperParser().putRootTypeParser(SizeFieldMapper.NAME, new SizeFieldMapper.TypeParser());
|
||||
return super.indexService(indexService);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user