Revert "Restore conflicts from merge."

This reverts commit 946f7133714f21a45a632cd5b7e8a61262720684.
This commit is contained in:
Tom Page
2019-07-26 16:25:09 +01:00
parent d60bed859a
commit 43b1639ce6
2 changed files with 25 additions and 49 deletions

View File

@@ -30,7 +30,7 @@ import java.util.Properties;
public class DocRouterFactory
{
private final static Logger LOGGER = LoggerFactory.getLogger(DocRouterFactory.class);
protected final static Logger log = LoggerFactory.getLogger(DocRouterFactory.class);
public static final String SHARD_KEY_KEY = "shard.key";
public static final String SHARD_RANGE_KEY = "shard.range";
@@ -41,45 +41,41 @@ public class DocRouterFactory
switch(method) {
case DB_ID:
LOGGER.info("Sharding via DB_ID");
log.info("Sharding via DB_ID");
return new DBIDRouter();
case DB_ID_RANGE:
//
if(properties.containsKey(SHARD_RANGE_KEY))
{
LOGGER.info("Sharding via DB_ID_RANGE");
log.info("Sharding via DB_ID_RANGE");
String[] pair =properties.getProperty(SHARD_RANGE_KEY).split("-");
long start = Long.parseLong(pair[0]);
long end = Long.parseLong(pair[1]);
return new DBIDRangeRouter(start, end);
}
case ACL_ID:
LOGGER.info("Sharding via ACL_ID");
log.info("Sharding via ACL_ID");
return new ACLIDMurmurRouter();
case MOD_ACL_ID:
LOGGER.info("Sharding via MOD_ACL_ID");
log.info("Sharding via MOD_ACL_ID");
return new ACLIDModRouter();
case DATE:
LOGGER.info("Sharding via DATE");
log.info("Sharding via DATE");
return new DateMonthRouter(properties.getProperty(SHARD_DATE_GROUPING_KEY, "1"));
case PROPERTY:
LOGGER.info("Sharding via PROPERTY");
log.info("Sharding via PROPERTY");
return new PropertyRouter(properties.getProperty(SHARD_REGEX_KEY, ""));
case LAST_REGISTERED_INDEXING_SHARD:
LOGGER.info("Sharding via LAST_REGISTERED_INDEXING_SHARD");
return new ExplicitShardIdWithStaticPropertyRouter();
log.info("Sharding via LAST_REGISTERED_INDEXING_SHARD");
return new LastRegisteredShardRouter();
case EXPLICIT_ID_FALLBACK_LRIS:
LOGGER.info("Sharding via EXPLICIT_ID_FALLBACK_LRIS");
return new DocRouterWithFallback(
new ExplicitShardIdWithDynamicPropertyRouter(false),
new ExplicitShardIdWithStaticPropertyRouter());
log.info("Sharding via EXPLICIT_ID_FALLBACK_LRIS");
return new ExplicitRouter(new LastRegisteredShardRouter());
case EXPLICIT_ID:
LOGGER.info("Sharding via EXPLICIT_ID");
return new DocRouterWithFallback(
new ExplicitShardIdWithDynamicPropertyRouter(false),
new DBIDRouter());
log.info("Sharding via EXPLICIT_ID");
return new ExplicitRouter(new DBIDRouter());
default:
LOGGER.warn("WARNING! Unknown/unsupported sharding method ({}). System will fallback to DB_ID", method);
log.info("Sharding via DB_ID (default)");
return new DBIDRouter();
}
}

View File

@@ -34,63 +34,43 @@ import java.util.stream.Stream;
/**
* Routes based on a text property field.
* In this method, the value of some property is hashed and this hash is used to assign the node to a random shard.
* All nodes with the same property value will be assigned to the same shard.
* Each shard will duplicate all the ACL information.
*
* To use this method, when creating a shard add the new configuration properties:
*
* <ul>
* <li>shard.key=cm:creator</li>
* <li>shard.method=PROPERTY</li>
* <li>shard.instance=&lt;shard.instance></li>
* <li>shard.count=&lt;shard.count></li>
* </ul>
*
* It is possible to extract a part of the property value to use for sharding using a regular expression,
* for example, a year at the start of a string:
*
* <ul>
* <li>shard.regex=^\d{4}</li>
* </ul>
*
* @author Gethin James
* @see <a href="https://docs.alfresco.com/search-enterprise/concepts/solr-shard-approaches.html">Search Services sharding methods</a>
*/
public class PropertyRouter implements DocRouter
{
private final static Logger LOGGER = LoggerFactory.getLogger(PropertyRouter.class);
protected final static Logger log = LoggerFactory.getLogger(PropertyRouter.class);
Pattern pattern;
String propertyRegEx;
Pattern pattern = null;
private String propertyRegEx;
//Fallback to DB_ID routing
DocRouter fallback = DocRouterFactory.getRouter(null, ShardMethodEnum.DB_ID);
private DocRouter fallback = DocRouterFactory.getRouter(null, ShardMethodEnum.DB_ID);
public PropertyRouter(String propertyRegEx)
{
if (propertyRegEx != null && propertyRegEx.trim().length() > 0)
if (propertyRegEx != null && !propertyRegEx.isEmpty())
{
this.propertyRegEx = propertyRegEx;
pattern = Pattern.compile(propertyRegEx.trim());
pattern = Pattern.compile(propertyRegEx);
}
}
@Override
public Boolean routeAcl(int shardCount, int shardInstance, Acl acl)
public boolean routeAcl(int shardCount, int shardInstance, Acl acl)
{
return true;
}
@Override
public Boolean routeNode(int shardCount, int shardInstance, Node node)
public boolean routeNode(int shardCount, int shardInstance, Node node)
{
if(shardCount <= 1)
{
return true;
}
String shardBy = node.getShardPropertyValue();
if (shardBy !=null && pattern != null)
{
try
@@ -108,14 +88,14 @@ public class PropertyRouter implements DocRouter
}
catch (IndexOutOfBoundsException | NullPointerException exc)
{
LOGGER.debug("Regex matched, but group 1 not found, so falling back to DBID sharding.");
log.debug("Regex matched, but group 1 not found, so falling back to DBID sharding.");
shardBy = null;
}
}
if (shardBy == null || shardBy.isEmpty())
{
LOGGER.debug("Property not found or regex not matched, so falling back to DBID sharding.");
log.debug("Property not found or regex not matched, so falling back to DBID sharding.");
return fallback.routeNode(shardCount,shardInstance,node);
}