mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Feature/search 1785 exception in explicit sharding policy (#115)
* SEARCH-1785 Add test cases and fix helper method so these fail. * SEARCH-1785 Throw exception when explicit sharding policy fails to create enough replicas. * SEARCH-1785 Update exception message to provide instructions to user.
This commit is contained in:
@@ -21,6 +21,8 @@ package org.alfresco.util.shard;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common ACL based index sharding behaviour for SOLR and the repository
|
* Common ACL based index sharding behaviour for SOLR and the repository
|
||||||
*
|
*
|
||||||
@@ -67,6 +69,13 @@ public class ExplicitShardingPolicy
|
|||||||
{
|
{
|
||||||
if (test % numNodes == nodeInstance - 1)
|
if (test % numNodes == nodeInstance - 1)
|
||||||
{
|
{
|
||||||
|
// This algorithm fails for some sets of parameters. (See SEARCH-1785)
|
||||||
|
if (shardIds.contains(shard % numShards))
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Sharding configuration not supported - unable to create shard list for node " + nodeInstance
|
||||||
|
+ " (shards:" + numShards + ", replication:" + replicationFactor + ", nodes:" + numNodes + ")."
|
||||||
|
+ " Please set up the shards manually or use a different sharding configuration.");
|
||||||
|
}
|
||||||
shardIds.add(shard % numShards);
|
shardIds.add(shard % numShards);
|
||||||
}
|
}
|
||||||
test++;
|
test++;
|
||||||
|
@@ -20,8 +20,11 @@ package org.alfresco.util.shard;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,6 +120,20 @@ public class ExplicitShardingPolicyTest
|
|||||||
buildAndTest(10, 2, 4);
|
buildAndTest(10, 2, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** ExplicitShardingPolicy algorithm fails for 2 shards, 3 replicas, 3 nodes. (See SEARCH-1785) */
|
||||||
|
@Test(expected = AlfrescoRuntimeException.class)
|
||||||
|
public void search1785_233()
|
||||||
|
{
|
||||||
|
buildAndTest(2, 3, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ExplicitShardingPolicy algorithm fails for 4 shards, 3 replicas, 6 nodes. (See SEARCH-1785) */
|
||||||
|
@Test (expected = AlfrescoRuntimeException.class)
|
||||||
|
public void search1785_436()
|
||||||
|
{
|
||||||
|
buildAndTest(4, 3, 6);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void check_10_2()
|
public void check_10_2()
|
||||||
{
|
{
|
||||||
@@ -163,7 +180,8 @@ public class ExplicitShardingPolicyTest
|
|||||||
int[] found = new int[numShards];
|
int[] found = new int[numShards];
|
||||||
for (int i = 0; i < numNodes; i++)
|
for (int i = 0; i < numNodes; i++)
|
||||||
{
|
{
|
||||||
List<Integer> shardIds = policy.getShardIdsForNode(i + 1);
|
// Convert to a set to remove any duplicates.
|
||||||
|
Set<Integer> shardIds = new HashSet<>(policy.getShardIdsForNode(i + 1));
|
||||||
assertEquals(numShards * replicationFactor / numNodes, shardIds.size());
|
assertEquals(numShards * replicationFactor / numNodes, shardIds.size());
|
||||||
for (Integer shardId : shardIds)
|
for (Integer shardId : shardIds)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user