mirror of
https://github.com/Alfresco/SearchServices.git
synced 2025-09-10 14:11:25 +00:00
SEARCH-1745 Better handling of NPE in MetadataTracker.
Add a meaningful message so that the log contains some information about why search isn't working if shard.key is not set correctly. Also update the .gitignore file.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -4,6 +4,9 @@ target
|
||||
.project
|
||||
.idea/
|
||||
*.iml
|
||||
.vscode
|
||||
overlays
|
||||
*.orig
|
||||
.metadata
|
||||
alf_data_dev
|
||||
alfresco.log*
|
||||
|
@@ -52,6 +52,7 @@ import org.alfresco.solr.client.SOLRAPIClient;
|
||||
import org.alfresco.solr.client.Transaction;
|
||||
import org.alfresco.solr.client.Transactions;
|
||||
import org.apache.commons.codec.EncoderException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.json.JSONException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -60,7 +61,7 @@ import static java.util.Optional.of;
|
||||
|
||||
/*
|
||||
* This tracks two things: transactions and metadata nodes
|
||||
* @author Ahmed Owianå
|
||||
* @author Ahmed Owian
|
||||
*/
|
||||
public class MetadataTracker extends AbstractTracker implements Tracker
|
||||
{
|
||||
@@ -68,6 +69,7 @@ public class MetadataTracker extends AbstractTracker implements Tracker
|
||||
protected final static Logger log = LoggerFactory.getLogger(MetadataTracker.class);
|
||||
private static final int DEFAULT_TRANSACTION_DOCS_BATCH_SIZE = 100;
|
||||
private static final int DEFAULT_NODE_BATCH_SIZE = 10;
|
||||
protected static final String SHARD_KEY = "shard.key";
|
||||
private int transactionDocsBatchSize = DEFAULT_TRANSACTION_DOCS_BATCH_SIZE;
|
||||
private int nodeBatchSize = DEFAULT_NODE_BATCH_SIZE;
|
||||
private ConcurrentLinkedQueue<Long> transactionsToReindex = new ConcurrentLinkedQueue<Long>();
|
||||
@@ -86,8 +88,9 @@ public class MetadataTracker extends AbstractTracker implements Tracker
|
||||
super(p, client, coreName, informationServer, Tracker.Type.MetaData);
|
||||
transactionDocsBatchSize = Integer.parseInt(p.getProperty("alfresco.transactionDocsBatchSize", "100"));
|
||||
shardMethod = p.getProperty("shard.method", SHARD_METHOD_DBID);
|
||||
String shardKey = p.getProperty("shard.key");
|
||||
if(shardKey != null) {
|
||||
String shardKey = p.getProperty(SHARD_KEY);
|
||||
if(shardKey != null)
|
||||
{
|
||||
shardProperty = getShardProperty(shardKey);
|
||||
}
|
||||
|
||||
@@ -1183,7 +1186,12 @@ public class MetadataTracker extends AbstractTracker implements Tracker
|
||||
this.queriesToReindex.offer(query);
|
||||
}
|
||||
|
||||
public static QName getShardProperty(String field) {
|
||||
public static QName getShardProperty(String field)
|
||||
{
|
||||
if (StringUtils.isBlank(field))
|
||||
{
|
||||
throw new IllegalArgumentException("Sharding property " + SHARD_KEY + " has not been set.");
|
||||
}
|
||||
AlfrescoSolrDataModel dataModel = AlfrescoSolrDataModel.getInstance();
|
||||
NamespaceDAO namespaceDAO = dataModel.getNamespaceDAO();
|
||||
DictionaryService dictionaryService = dataModel.getDictionaryService(CMISStrictDictionaryService.DEFAULT);
|
||||
@@ -1191,7 +1199,10 @@ public class MetadataTracker extends AbstractTracker implements Tracker
|
||||
namespaceDAO,
|
||||
dictionaryService,
|
||||
field);
|
||||
|
||||
if (propertyDef == null)
|
||||
{
|
||||
throw new IllegalStateException("Sharding property " + SHARD_KEY + " was set to " + field + ", but no such property was found.");
|
||||
}
|
||||
return propertyDef.getName();
|
||||
}
|
||||
}
|
||||
|
@@ -52,6 +52,7 @@ import static org.alfresco.solr.AlfrescoSolrUtils.getNodeMetaData;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.getTransaction;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.indexAclChangeSet;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.list;
|
||||
import static org.alfresco.solr.tracker.MetadataTracker.SHARD_KEY;
|
||||
|
||||
/**
|
||||
* Test Routes based on an explicit shard
|
||||
@@ -179,7 +180,7 @@ public class DistributedExplicitShardRoutingTrackerTest extends AbstractAlfresco
|
||||
prop.put("shard.method", ShardMethodEnum.EXPLICIT_ID.toString());
|
||||
//Normally this would be used by the Solr client which will automatically add the property to the node.shardPropertyValue
|
||||
//For testing this doesn't work like that so I setShardPropertyValue explicitly above.
|
||||
prop.put("shard.key", ContentModel.PROP_SKYPE.toString());
|
||||
prop.put(SHARD_KEY, ContentModel.PROP_SKYPE.toString());
|
||||
return prop;
|
||||
}
|
||||
}
|
||||
|
@@ -54,6 +54,7 @@ import static org.alfresco.solr.AlfrescoSolrUtils.getNodeMetaData;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.getTransaction;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.indexAclChangeSet;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.list;
|
||||
import static org.alfresco.solr.tracker.MetadataTracker.SHARD_KEY;
|
||||
|
||||
/**
|
||||
* Test Routes based on a text property field.
|
||||
@@ -178,7 +179,7 @@ public class DistributedPropertyBasedAlfrescoSolrTrackerTest extends AbstractAlf
|
||||
Properties prop = new Properties();
|
||||
prop.put("shard.method", ShardMethodEnum.PROPERTY.toString());
|
||||
prop.put("shard.regex", "^[A-Za-z0-9._%+-]+@([A-Za-z0-9.-]+\\.[A-Za-z]{2,6})$");
|
||||
prop.put("shard.key", ContentModel.PROP_EMAIL.toString());
|
||||
prop.put(SHARD_KEY, ContentModel.PROP_EMAIL.toString());
|
||||
return prop;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user