[SEARCH-1643]

Added possibility to use explicitRouter with the two fallbacks (LRSI and DBID)
This commit is contained in:
eliaporciani
2019-05-30 14:37:08 +02:00
parent 491e20e00e
commit 1e05e4aee0
4 changed files with 21 additions and 71 deletions

View File

@@ -60,9 +60,15 @@ public class DocRouterFactory
case PROPERTY:
log.info("Sharding via PROPERTY");
return new PropertyRouter(properties.getProperty("shard.regex", ""));
case LAST_REGISTERED_INDEXING_SHARD:
log.info("Sharding via LAST_REGISTERED_INDEXING_SHARD");
return new LastRegisteredShardRouter();
case EXPLICIT_ID_FALLBACK_LRIS:
log.info("Sharding via EXPLICIT_ID_FALLBACK_LRIS");
return new ExplicitRouter(new LastRegisteredShardRouter());
case EXPLICIT_ID:
log.info("Sharding via EXPLICIT_ID");
return new ExplicitElasticRouter();
return new ExplicitRouter(new DBIDRouter());
default:
log.info("Sharding via DB_ID (default)");
return new DBIDRouter();

View File

@@ -1,56 +0,0 @@
package org.alfresco.solr.tracker;
import org.alfresco.solr.client.Acl;
import org.alfresco.solr.client.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Routes a document only if the shardInstance matches the provided shardId
*/
public class ExplicitElasticRouter implements DocRouter {
protected final static Logger log = LoggerFactory.getLogger(ExplicitRouter.class);
private final ElasticLastShardRouter fallback = new ElasticLastShardRouter();
public ExplicitElasticRouter() {
}
@Override
public boolean routeAcl(int shardCount, int shardInstance, Acl acl) {
//all acls go to all shards.
return true;
}
@Override
public boolean routeNode(int shardCount, int shardInstance, Node node) {
String shardBy = node.getShardPropertyValue();
if (shardBy != null && !shardBy.isEmpty())
{
try
{
int shardid = Integer.parseInt(shardBy);
return shardid == shardInstance;
}
catch (NumberFormatException e)
{
if (log.isDebugEnabled())
{
log.debug("Shard "+shardInstance+" EXPLICIT_ID routing specified but failed to parse a shard property value ("+shardBy+") for node "+node.getNodeRef());
}
}
}
else
{
if (log.isDebugEnabled())
{
log.debug("Shard "+shardInstance+" EXPLICIT_ID routing specified but no shard id property found for node "+node.getNodeRef());
}
}
return fallback.routeNode(shardCount, shardInstance, node);
}
}

View File

@@ -11,9 +11,10 @@ import org.slf4j.LoggerFactory;
public class ExplicitRouter implements DocRouter {
protected final static Logger log = LoggerFactory.getLogger(ExplicitRouter.class);
private final DBIDRouter fallback = new DBIDRouter();
private final DocRouter fallbackRouter;
public ExplicitRouter() {
public ExplicitRouter(DocRouter fallbackRouter) {
this.fallbackRouter = fallbackRouter;
}
@Override
@@ -25,11 +26,6 @@ public class ExplicitRouter implements DocRouter {
@Override
public boolean routeNode(int shardCount, int shardInstance, Node node) {
if(shardCount <= 1)
{
return true;
}
String shardBy = node.getShardPropertyValue();
if (shardBy != null && !shardBy.isEmpty())
@@ -59,6 +55,6 @@ public class ExplicitRouter implements DocRouter {
{
log.debug("Shard "+shardInstance+" falling back to DBID routing for node "+node.getNodeRef());
}
return fallback.routeNode(shardCount, shardInstance, node);
return fallbackRouter.routeNode(shardCount, shardInstance, node);
}
}

View File

@@ -6,14 +6,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Routes a document only if the shardInstance matches the provided shardId
* Routes a document only if the explicitShardId matches the provided shardId
*/
public class ElasticLastShardRouter implements DocRouter {
public class LastRegisteredShardRouter implements DocRouter {
protected final static Logger log = LoggerFactory.getLogger(ExplicitRouter.class);
private final DBIDRouter fallback = new DBIDRouter();
public ElasticLastShardRouter() {
public LastRegisteredShardRouter() {
}
@Override
@@ -25,9 +24,14 @@ public class ElasticLastShardRouter implements DocRouter {
@Override
public boolean routeNode(int shardCount, int shardInstance, Node node) {
Integer explicitShardId = node.getExplicitShardId();
int explicitShardId = node.getExplicitShardId();
return explicitShardId == shardInstance;
if (explicitShardId == null) {
log.error("explicitShardId is not set for node " + node.getNodeRef());
return false;
}
return explicitShardId.equals(shardInstance);
}
}