Authored by hugufei

fix复制分片计算方式

... ... @@ -158,15 +158,28 @@ public class YohoIndexServiceImpl implements IYohoIndexService, ApplicationEvent
}
// 获取配置的主分片数
int numberOfPrimary = MapUtils.getIntValue(indexSettings, "number_of_shards");//配置的主分片数
// 动态计算复制分片数【1个主分片就是机器数-1 , 4个主分片,4台机器就是 0,然后取1 】
int number_of_replicas = dataNodesCount/numberOfPrimary - 1;
return Math.max(1, number_of_replicas);
// 计算副本数
return getReplicasShardCount(dataNodesCount,numberOfPrimary);
} catch (Exception e) {
INDEX_REBUILD_LOG.error(e.getMessage(), e);
return 0;
}
}
public static int getReplicasShardCount(int dataNodesCount, int numberOfPrimary){
if(dataNodesCount==numberOfPrimary){
return 1;
}
int maxTotalIndexCount = dataNodesCount ;
int totalIndexCount = dataNodesCount * 2 / numberOfPrimary;
totalIndexCount = Math.min(totalIndexCount, maxTotalIndexCount);
return Math.max(2, totalIndexCount) -1;
}
public static void main(String[] args) {
System.out.println(getReplicasShardCount(4,1));
}
/**
* 创建索引,并返回真实索引名称
*
... ...