Authored by wangnan9279

Merge branch '0920' into 0930

... ... @@ -4,6 +4,8 @@
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.CsRecallConfigCommon">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="config_page" property="configPage" jdbcType="INTEGER"/>
<result column="order_type" property="orderType" jdbcType="INTEGER"/>
<result column="ab_type" property="abType" jdbcType="INTEGER"/>
<result column="config_type" property="configType" jdbcType="VARCHAR"/>
<result column="description" property="description" jdbcType="VARCHAR"/>
<result column="size" property="size" jdbcType="INTEGER"/>
... ... @@ -11,37 +13,38 @@
<result column="interval" property="interval" jdbcType="INTEGER"/>
<result column="interval_limit" property="intervalLimit" jdbcType="VARCHAR"/>
<result column="insert_order" property="insertOrder" jdbcType="INTEGER"/>
<result column="ab_type" property="abType" jdbcType="INTEGER"/>
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, config_page, config_type, description, `size`, size_limit, `interval`, interval_limit, insert_order, ab_type, update_time
id, config_page, order_type, ab_type, config_type, description, `size`, size_limit, `interval`, interval_limit, insert_order , update_time
</sql>
<insert id="insert" parameterType="com.yoho.search.dal.model.CsRecallConfigCommon" timeout="20000">
insert ignore into cs_recall_config_common (
id,
config_page,
order_type,
ab_type,
config_type,
description,
`size`,
size_limit,
`interval`,
interval_limit,
insert_order,
ab_type )
insert_order)
values (
#{id,jdbcType=INTEGER},
#{configPage,jdbcType=INTEGER},
#{orderType,jdbcType=INTEGER},
#{abType,jdbcType=INTEGER},
#{configType,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR},
#{size,jdbcType=INTEGER},
#{sizeLimit,jdbcType=VARCHAR},
#{interval,jdbcType=INTEGER},
#{intervalLimit,jdbcType=VARCHAR},
#{insertOrder,jdbcType=INTEGER},
#{abType,jdbcType=INTEGER}
#{insertOrder,jdbcType=INTEGER}
)
</insert>
... ... @@ -51,6 +54,12 @@
<if test="configPage != null">
config_page = #{configPage,jdbcType=INTEGER},
</if>
<if test="orderType != null">
order_type = #{orderType,jdbcType=INTEGER},
</if>
<if test="abType != null">
ab_type = #{abType,jdbcType=INTEGER},
</if>
<if test="configType != null">
config_type = #{configType,jdbcType=VARCHAR},
</if>
... ... @@ -70,10 +79,7 @@
interval_limit = #{intervalLimit,jdbcType=VARCHAR},
</if>
<if test="insertOrder != null">
insert_order = #{insertOrder,jdbcType=VARCHAR},
</if>
<if test="abType != null">
ab_type = #{abType,jdbcType=VARCHAR},
insert_order = #{insertOrder,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
... ...
... ... @@ -146,16 +146,21 @@ public class YohoIndexServiceImpl implements IYohoIndexService, ApplicationEvent
*/
private int genNumberOfReplicas(IElasticsearchClient client, Map<String, String> indexSettings) {
try {
int numberOfDataNodes = client.getClusterHealthResponse().getNumberOfDataNodes();
if (numberOfDataNodes <= 1) {
//获取数据节点机器数
int dataNodesCount = client.getClusterHealthResponse().getNumberOfDataNodes();
if (dataNodesCount <= 1) {
return 0;
}
//获取配置的复制分片数
String numberOfReplicas = MapUtils.getString(indexSettings, "number_of_replicas");//配置的复制分片数
if (!"auto".equalsIgnoreCase(numberOfReplicas)) {
return Integer.valueOf(numberOfReplicas);
}
//获取索引配置的主分片数
return Math.max(1, numberOfDataNodes - 1);
// 获取配置的主分片数
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);
} catch (Exception e) {
INDEX_REBUILD_LOG.error(e.getMessage(), e);
return 0;
... ... @@ -206,7 +211,7 @@ public class YohoIndexServiceImpl implements IYohoIndexService, ApplicationEvent
indexSettings.put("merge.policy.expunge_deletes_allowed", 20d); // 删除了的文档数在一个segment里占的百分比,默认是10
indexSettings.put("merge.policy.floor_segment", "2mb"); // ES会避免产生很小size的segment,小于这个阈值的所有的非常小的segment都会做merge,默认是2MB.
indexSettings.put("merge.policy.max_merge_at_once", 10); // 一次最多只操作多少个segments,默认是10.
indexSettings.put("merge.policy.max_merged_segment", "2gb"); // 超过多大size的segment不会再做merge,默认是5g.
indexSettings.put("merge.policy.max_merged_segment", "500mb"); // 超过多大size的segment不会再做merge,默认是5g.
indexSettings.put("merge.policy.segments_per_tier", 10d); // 每个tier允许的segement 数,注意这个数要大于上面的at_once数,否则这个值会先于最大可操作数到达,就会立刻做merge,这样会造成频繁
client.createIndex(newRealIndexName, type, indexSettings, mappingContent);
... ...
... ... @@ -10,11 +10,17 @@
"id": {
"type": "integer"
},
"configPage": {
"type": "integer"
},
"orderType": {
"type": "integer"
},
"configType": {
"type": "keyword"
},
"configPage": {
"type": "integer"
"description": {
"type": "keyword"
},
"size": {
"type": "integer"
... ... @@ -28,15 +34,9 @@
"intervalLimit": {
"type": "keyword"
},
"description": {
"type": "keyword"
},
"insertOrder": {
"type": "integer"
},
"abType": {
"type": "integer"
},
"updateTime": {
"type": "date"
}
... ...
... ... @@ -80,7 +80,7 @@
<index>
<name>productindex</name>
<properties>
<property key="number_of_shards" value="2"/>
<property key="number_of_shards" value="4"/>
<property key="number_of_replicas" value="auto"/>
<property key="refresh_interval" value="10s"/>
<property key="translog.flush_threshold_size" value="100mb"/>
... ...
... ... @@ -80,7 +80,7 @@
<index>
<name>productindex</name>
<properties>
<property key="number_of_shards" value="2"/>
<property key="number_of_shards" value="4"/>
<property key="number_of_replicas" value="auto"/>
<property key="refresh_interval" value="${search.index.refresh_interval}"/>
<property key="translog.flush_threshold_size" value="${search.index.translog.flush_threshold_size}"/>
... ...