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 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_KEY_KEY = "shard.key";
public static final String SHARD_RANGE_KEY = "shard.range"; public static final String SHARD_RANGE_KEY = "shard.range";
@@ -41,45 +41,41 @@ public class DocRouterFactory
switch(method) { switch(method) {
case DB_ID: case DB_ID:
LOGGER.info("Sharding via DB_ID"); log.info("Sharding via DB_ID");
return new DBIDRouter(); return new DBIDRouter();
case DB_ID_RANGE: case DB_ID_RANGE:
// //
if(properties.containsKey(SHARD_RANGE_KEY)) 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("-"); String[] pair =properties.getProperty(SHARD_RANGE_KEY).split("-");
long start = Long.parseLong(pair[0]); long start = Long.parseLong(pair[0]);
long end = Long.parseLong(pair[1]); long end = Long.parseLong(pair[1]);
return new DBIDRangeRouter(start, end); return new DBIDRangeRouter(start, end);
} }
case ACL_ID: case ACL_ID:
LOGGER.info("Sharding via ACL_ID"); log.info("Sharding via ACL_ID");
return new ACLIDMurmurRouter(); return new ACLIDMurmurRouter();
case MOD_ACL_ID: case MOD_ACL_ID:
LOGGER.info("Sharding via MOD_ACL_ID"); log.info("Sharding via MOD_ACL_ID");
return new ACLIDModRouter(); return new ACLIDModRouter();
case DATE: case DATE:
LOGGER.info("Sharding via DATE"); log.info("Sharding via DATE");
return new DateMonthRouter(properties.getProperty(SHARD_DATE_GROUPING_KEY, "1")); return new DateMonthRouter(properties.getProperty(SHARD_DATE_GROUPING_KEY, "1"));
case PROPERTY: case PROPERTY:
LOGGER.info("Sharding via PROPERTY"); log.info("Sharding via PROPERTY");
return new PropertyRouter(properties.getProperty(SHARD_REGEX_KEY, "")); return new PropertyRouter(properties.getProperty(SHARD_REGEX_KEY, ""));
case LAST_REGISTERED_INDEXING_SHARD: case LAST_REGISTERED_INDEXING_SHARD:
LOGGER.info("Sharding via LAST_REGISTERED_INDEXING_SHARD"); log.info("Sharding via LAST_REGISTERED_INDEXING_SHARD");
return new ExplicitShardIdWithStaticPropertyRouter(); return new LastRegisteredShardRouter();
case EXPLICIT_ID_FALLBACK_LRIS: case EXPLICIT_ID_FALLBACK_LRIS:
LOGGER.info("Sharding via EXPLICIT_ID_FALLBACK_LRIS"); log.info("Sharding via EXPLICIT_ID_FALLBACK_LRIS");
return new DocRouterWithFallback( return new ExplicitRouter(new LastRegisteredShardRouter());
new ExplicitShardIdWithDynamicPropertyRouter(false),
new ExplicitShardIdWithStaticPropertyRouter());
case EXPLICIT_ID: case EXPLICIT_ID:
LOGGER.info("Sharding via EXPLICIT_ID"); log.info("Sharding via EXPLICIT_ID");
return new DocRouterWithFallback( return new ExplicitRouter(new DBIDRouter());
new ExplicitShardIdWithDynamicPropertyRouter(false),
new DBIDRouter());
default: 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(); return new DBIDRouter();
} }
} }

View File

@@ -34,63 +34,43 @@ import java.util.stream.Stream;
/** /**
* Routes based on a text property field. * 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 * @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 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; Pattern pattern = null;
String propertyRegEx; private String propertyRegEx;
//Fallback to DB_ID routing //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) public PropertyRouter(String propertyRegEx)
{ {
if (propertyRegEx != null && propertyRegEx.trim().length() > 0) if (propertyRegEx != null && !propertyRegEx.isEmpty())
{ {
this.propertyRegEx = propertyRegEx; this.propertyRegEx = propertyRegEx;
pattern = Pattern.compile(propertyRegEx.trim()); pattern = Pattern.compile(propertyRegEx);
} }
} }
@Override @Override
public Boolean routeAcl(int shardCount, int shardInstance, Acl acl) public boolean routeAcl(int shardCount, int shardInstance, Acl acl)
{ {
return true; return true;
} }
@Override @Override
public Boolean routeNode(int shardCount, int shardInstance, Node node) public boolean routeNode(int shardCount, int shardInstance, Node node)
{ {
if(shardCount <= 1) if(shardCount <= 1)
{ {
return true; return true;
} }
String shardBy = node.getShardPropertyValue(); String shardBy = node.getShardPropertyValue();
if (shardBy !=null && pattern != null) if (shardBy !=null && pattern != null)
{ {
try try
@@ -108,14 +88,14 @@ public class PropertyRouter implements DocRouter
} }
catch (IndexOutOfBoundsException | NullPointerException exc) 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; shardBy = null;
} }
} }
if (shardBy == null || shardBy.isEmpty()) 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); return fallback.routeNode(shardCount,shardInstance,node);
} }