mirror of https://github.com/apache/lucene.git
added postOptimize hooks, analogous to postCommit hooks but only called after an optimize command. Useful for only distributing optimized indicies
git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@390501 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
38bd428893
commit
4202b65619
|
@ -47,15 +47,23 @@
|
|||
args - the arguments to pass to the program. default=nothing
|
||||
env - environment variables to set. default=nothing
|
||||
-->
|
||||
<!-- A postCommit event is fired after every commit
|
||||
<!-- A postCommit event is fired after every commit or optimize command
|
||||
<listener event="postCommit" class="solr.RunExecutableListener">
|
||||
<str name="exe">snapshooter</str>
|
||||
<str name="dir">bin</str>
|
||||
<str name="dir">solr/bin</str>
|
||||
<bool name="wait">true</bool>
|
||||
<arr name="args"> <str>arg1</str> <str>arg2</str> </arr>
|
||||
<arr name="env"> <str>MYVAR=val1</str> </arr>
|
||||
</listener>
|
||||
-->
|
||||
<!-- A postOptimize event is fired only after every optimize command, useful
|
||||
in conjunction with index distribution to only distribute optimized indicies
|
||||
<listener event="postOptimize" class="solr.RunExecutableListener">
|
||||
<str name="exe">snapshooter</str>
|
||||
<str name="dir">solr/bin</str>
|
||||
<bool name="wait">true</bool>
|
||||
</listener>
|
||||
-->
|
||||
|
||||
</updateHandler>
|
||||
|
||||
|
|
|
@ -238,6 +238,9 @@ public class DirectUpdateHandler extends UpdateHandler {
|
|||
closeWriter();
|
||||
|
||||
callPostCommitCallbacks();
|
||||
if (cmd.optimize) {
|
||||
callPostOptimizeCallbacks();
|
||||
}
|
||||
|
||||
core.getSearcher(true,false,waitSearcher);
|
||||
}
|
||||
|
|
|
@ -463,7 +463,9 @@ public class DirectUpdateHandler2 extends UpdateHandler {
|
|||
closeWriter();
|
||||
|
||||
callPostCommitCallbacks();
|
||||
|
||||
if (cmd.optimize) {
|
||||
callPostOptimizeCallbacks();
|
||||
}
|
||||
// open a new searcher in the sync block to avoid opening it
|
||||
// after a deleteByQuery changed the index, or in between deletes
|
||||
// and adds of another commit being done.
|
||||
|
|
|
@ -55,6 +55,7 @@ public abstract class UpdateHandler implements SolrInfoMBean {
|
|||
protected final FieldType idFieldType;
|
||||
|
||||
protected Vector<SolrEventListener> commitCallbacks = new Vector<SolrEventListener>();
|
||||
protected Vector<SolrEventListener> optimizeCallbacks = new Vector<SolrEventListener>();
|
||||
|
||||
private void parseEventListeners() {
|
||||
NodeList nodes = (NodeList) SolrConfig.config.evaluate("updateHandler/listener[@event=\"postCommit\"]", XPathConstants.NODESET);
|
||||
|
@ -73,6 +74,21 @@ public abstract class UpdateHandler implements SolrInfoMBean {
|
|||
}
|
||||
}
|
||||
}
|
||||
nodes = (NodeList)SolrConfig.config.evaluate("updateHandler/listener[@event=\"postOptimize\"]", XPathConstants.NODESET);
|
||||
if (nodes!=null) {
|
||||
for (int i=0; i<nodes.getLength(); i++) {
|
||||
Node node = nodes.item(i);
|
||||
try {
|
||||
String className = DOMUtil.getAttr(node,"class");
|
||||
SolrEventListener listener = (SolrEventListener)Config.newInstance(className);
|
||||
listener.init(DOMUtil.childNodesToNamedList(node));
|
||||
optimizeCallbacks.add(listener);
|
||||
log.info("added SolarEventListener for postOptimize: " + listener);
|
||||
} catch (Exception e) {
|
||||
throw new SolrException(1,"error parsing event listeners", e, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void callPostCommitCallbacks() {
|
||||
|
@ -81,6 +97,12 @@ public abstract class UpdateHandler implements SolrInfoMBean {
|
|||
}
|
||||
}
|
||||
|
||||
protected void callPostOptimizeCallbacks() {
|
||||
for (SolrEventListener listener : optimizeCallbacks) {
|
||||
listener.postCommit();
|
||||
}
|
||||
}
|
||||
|
||||
public UpdateHandler(SolrCore core) {
|
||||
this.core=core;
|
||||
schema = core.getSchema();
|
||||
|
|
Loading…
Reference in New Issue