diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/tracker/DocRouterFactory.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/tracker/DocRouterFactory.java index bf590b68e..6937a0b07 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/tracker/DocRouterFactory.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/tracker/DocRouterFactory.java @@ -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(); } } diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/tracker/PropertyRouter.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/tracker/PropertyRouter.java index e57b43694..668265067 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/tracker/PropertyRouter.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/tracker/PropertyRouter.java @@ -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: - * - * - * - * 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: - * - * * * @author Gethin James - * @see Search Services sharding methods */ 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); }