SOLR-9565: The name of TemplateUpdateRequestProcessorFactory' is changed to 'template' from 'Template' and the

name of 'AtomicUpdateProcessorFactory' is changed to 'atomic' from 'Atomic'
This commit is contained in:
Noble Paul 2017-06-16 16:09:27 +09:30
parent d953488e93
commit e1d4ec7987
8 changed files with 66 additions and 41 deletions

View File

@ -94,6 +94,9 @@ Upgrading from Solr 6.x
* TemplateUpdateRequestProcessorFactory uses {} instead of ${} for template
* SOLR-9565: The name of TemplateUpdateRequestProcessorFactory' is changed to 'template' from 'Template' and the
name of 'AtomicUpdateProcessorFactory' is changed to 'atomic' from 'Atomic'
New Features
----------------------
* SOLR-9857, SOLR-9858: Collect aggregated metrics from nodes and shard leaders in overseer. (ab)

View File

@ -61,7 +61,8 @@ public class AtomicUpdateProcessorFactory extends UpdateRequestProcessorFactory
private final static Set<String> VALID_OPS = new HashSet<>(Arrays.asList(ADD, INC, REMOVE, SET, REMOVEREGEX));
private final static String VERSION = "_version_";
private final static String ATOMIC_FIELD_PREFIX = "Atomic.";
public static final String NAME = "atomic";
public final static String ATOMIC_FIELD_PREFIX = "atomic.";
private final static int MAX_ATTEMPTS = 5;
private VersionInfo vinfo;

View File

@ -29,14 +29,12 @@ import org.apache.solr.update.AddUpdateCommand;
* This is deliberately made to support only the add operation
*/
public abstract class SimpleUpdateProcessorFactory extends UpdateRequestProcessorFactory {
protected final String myName; // if classname==XyzUpdateProcessorFactory myName=Xyz
private String myName; // if classname==XyzUpdateProcessorFactory myName=Xyz
protected NamedList initArgs = new NamedList();
private static ThreadLocal<SolrQueryRequest> REQ = new ThreadLocal<>();
protected SimpleUpdateProcessorFactory() {
String simpleName = this.getClass().getSimpleName();
int idx = simpleName.indexOf("UpdateProcessorFactory");
this.myName = idx == -1 ? simpleName : simpleName.substring(0, idx);
}
@Override
@ -80,7 +78,17 @@ public abstract class SimpleUpdateProcessorFactory extends UpdateRequestProcesso
}
private String _param(String name) {
return myName + "." + name;
return getMyName() + "." + name;
}
protected String getMyName() {
String myName = this.myName;
if (myName == null) {
String simpleName = this.getClass().getSimpleName();
int idx = simpleName.indexOf("UpdateProcessorFactory");
this.myName = myName = idx == -1 ? simpleName : simpleName.substring(0, idx);
}
return myName;
}

View File

@ -41,6 +41,7 @@ import org.apache.solr.util.ConcurrentLRUCache;
*/
public class TemplateUpdateProcessorFactory extends SimpleUpdateProcessorFactory {
private Cache<String, Resolved> templateCache = new ConcurrentLRUCache<>(1000, 800, 900, 10, false, false, null);
public static final String NAME = "template";
@Override
protected void process(AddUpdateCommand cmd, SolrQueryRequest req, SolrQueryResponse rsp) {
String[] vals = getParams("field");
@ -63,6 +64,10 @@ public class TemplateUpdateProcessorFactory extends SimpleUpdateProcessorFactory
}
@Override
protected String getMyName() {
return NAME;
}
public static Resolved getResolved(String template, Cache<String, Resolved> cache, Pattern pattern) {
Resolved r = cache == null ? null : cache.get(template);

View File

@ -21,8 +21,10 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import com.google.common.collect.ImmutableMap;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.params.SolrParams;
@ -271,12 +273,13 @@ public final class UpdateRequestProcessorChain implements PluginInfoInitialized
if (s.isEmpty()) continue;
UpdateRequestProcessorFactory p = core.getUpdateProcessors().get(s);
if (p == null) {
Class<UpdateRequestProcessorFactory> factoryClass = implicits.get(s);
if(factoryClass != null) {
PluginInfo pluginInfo = new PluginInfo("updateProcessor",
Utils.makeMap("name", s,
"class", s + "UpdateProcessorFactory",
"runtimeLib", "true"));
"class", factoryClass.getName()));
core.getUpdateProcessors().put(s, p = core.getUpdateProcessors().createPlugin(pluginInfo).get());
}
if (p == null)
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No such processor " + s);
}
@ -315,4 +318,9 @@ public final class UpdateRequestProcessorChain implements PluginInfoInitialized
}
}
public static final Map<String, Class> implicits = new ImmutableMap.Builder()
.put(TemplateUpdateProcessorFactory.NAME, TemplateUpdateProcessorFactory.class)
.put(AtomicUpdateProcessorFactory.NAME, AtomicUpdateProcessorFactory.class)
.build();
}

View File

@ -45,7 +45,7 @@ public class AtomicUpdateProcessorFactoryTest extends SolrTestCaseJ4 {
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(),
new ModifiableSolrParams()
.add("processor", "Atomic")
.add("Atomic.cat", "delete")
.add("atomic.cat", "delete")
.add("commit","true")
));
@ -63,8 +63,8 @@ public class AtomicUpdateProcessorFactoryTest extends SolrTestCaseJ4 {
public void testNoUniqueIdPassed() throws Exception { //TODO
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(),
new ModifiableSolrParams()
.add("processor", "Atomic")
.add("Atomic.cat", "add")
.add("processor", "atomic")
.add("atomic.cat", "add")
.add("commit","true")
));
@ -85,12 +85,12 @@ public class AtomicUpdateProcessorFactoryTest extends SolrTestCaseJ4 {
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(),
new ModifiableSolrParams()
.add("processor", "Atomic")
.add("Atomic.cat", "add")
.add("Atomic.title", "set")
.add("Atomic.count_i", "set")
.add("Atomic.name_s", "set")
.add("Atomic.multiDefault", "set")
.add("processor", "atomic")
.add("atomic.cat", "add")
.add("atomic.title", "set")
.add("atomic.count_i", "set")
.add("atomic.name_s", "set")
.add("atomic.multiDefault", "set")
.add("commit","true")
));
@ -136,12 +136,12 @@ public class AtomicUpdateProcessorFactoryTest extends SolrTestCaseJ4 {
cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(),
new ModifiableSolrParams()
.add("processor", "Atomic")
.add("Atomic.cat", "add")
.add("Atomic.title", "set")
.add("Atomic.count_i", "inc")
.add("Atomic.name_s", "remove")
.add("Atomic.multiDefault", "removeregex")
.add("processor", "atomic")
.add("atomic.cat", "add")
.add("atomic.title", "set")
.add("atomic.count_i", "inc")
.add("atomic.name_s", "remove")
.add("atomic.multiDefault", "removeregex")
.add("commit","true")
));
@ -216,9 +216,9 @@ public class AtomicUpdateProcessorFactoryTest extends SolrTestCaseJ4 {
public void run() {
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(),
new ModifiableSolrParams()
.add("processor", "Atomic")
.add("Atomic.cat", "add")
.add("Atomic.int_i", "inc")
.add("processor", "atomic")
.add("atomic.cat", "add")
.add("atomic.int_i", "inc")
.add("commit","true")
));

View File

@ -61,10 +61,10 @@ public class TemplateUpdateProcessorTest extends SolrCloudTestCase {
public void testSimple() throws Exception {
ModifiableSolrParams params = new ModifiableSolrParams()
.add("processor", "Template")
.add("Template.field", "id:{firstName}_{lastName}")
.add("Template.field", "another:{lastName}_{firstName}")
.add("Template.field", "missing:{lastName}_{unKnown}");
.add("processor", "template")
.add("template.field", "id:{firstName}_{lastName}")
.add("template.field", "another:{lastName}_{firstName}")
.add("template.field", "missing:{lastName}_{unKnown}");
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(null,
params
@ -82,9 +82,9 @@ public class TemplateUpdateProcessorTest extends SolrCloudTestCase {
solrDoc.addField("id", "1");
params = new ModifiableSolrParams()
.add("processor", "Template")
.add("processor", "template")
.add("commit", "true")
.add("Template.field", "x_s:key_{id}");
.add("template.field", "x_s:key_{id}");
params.add("commit", "true");
UpdateRequest add = new UpdateRequest().add(solrDoc);
add.setParams(params);

View File

@ -386,27 +386,27 @@ These Update processors do not need any configuration is your `solrconfig.xml` .
The `TemplateUpdateProcessorFactory` can be used to add new fields to documents based on a template pattern.
Use the parameter `processor=Template` to use it. The template parameter `Template.field` (multivalued) defines the field to add and the pattern. Templates may contain placeholders which refer to other fields in the document. You can have multiple `Template.field` parameters in a single request.
Use the parameter `processor=template` to use it. The template parameter `template.field` (multivalued) define the field to add and the pattern. Templates may contain placeholders which refer to other fields in the document. You can have multiple `Template.field` parameters in a single request.
For example:
[source,bash]
----
processor=Template&Template.field=fullName:Mr. {firstName} {lastName}
processor=template&template.field=fullName:Mr. {firstName} {lastName}
----
The above example would add a new field to the document called `fullName`. The fields `firstName` and `lastName` are supplied from the document fields. If either of them is missing, that part is replaced with an empty string. If those fields are multi-valued, only the first value is used.
The above example would add a new field to the document called `fullName`. The fields `firstName and` `lastName` are supplied from the document fields. If either of them is missing, that part is replaced with an empty string. If those fields are multi-valued, only the first value is used.
==== AtomicUpdateProcessorFactory
Use it to convert your normal `update` operations to atomic update operations. This is particularly useful when you use endpoints such as `/update/csv` or `/update/json/docs` which does not support syntax for atomic operations.
Name of the processor is `atomic` . Use it to convert your normal `update` operations to atomic update operations. This is particularly useful when you use endpoints such as `/update/csv` or `/update/json/docs` which does not support syntax for atomic operations.
example:
[source,bash]
----
processor=Atomic&Atomic.field1=add&Atomic.field2=set&Atomic.field3=inc&Atomic.field4=remove&Atomic.field4=remove
processor=atomic&atomic.field1=add&atomic.field2=set&atomic.field3=inc&atomic.field4=remove&atomic.field4=remove
----
The above parameters convert a normal `update` operation on