同样在公司工作中发现了一个现象,

1.我用/solr/admin/collections?action=CREATE&name=collection&numShards=3&replicationFactor=2创建collection

2. delete其中的一个shard

3. 使用以下命令增加shard,/admin/collections?action=CREATESHARD&shard=shardName&collection=name

如此就会报以下错误:shards can be added only to ‘implicit’ collections。

那么是什么原因呢?问题就出在Solr的两种ROUTER方式ImplicitDocRouter和CompositeIdRouter。在SolrCloud的开发文档中有这句话:

Shards can only created with this API for collections that use the ‘implicit’ router. Use SPLITSHARD for collections using the ‘compositeId’ router. A new shard with a name can be created for an existing ‘implicit’ collection.

也就是说在创建collections时候(如果指定参数numshards参数会自动切换到router=”compositeId”),如果采用compositeId方式,那么就不能动态增加shard。如果采用的是implicit方式,就可以动态的增加shard。进一步来讲:

  • ImplicitDocRouter就是和 uniqueKey无关,可以在请求参数或者SolrInputDocument中添加_route_(_shard_已废弃,或者指定field参数)参数获取slice ,(router=”implicit”) .
  • CompositeIdRouter就是根据uniqueKey的hash值获取slice,   (在指定numshards参数会自动切换到router=”compositeId”) .

综上所述,CompositeIdRouter在创建的时候由于指定了numshards参数即已经固定了hash区间,那么在update的时候,根据uniqueid的hash坐落在那个hash区间来决定这份document数据发送至哪个shard。而ImplicitDocRouter则是在创建的时候并不选定每个shard的hash区间,而是在需要update的document中增加_route_字段来存放需要发送的shard名字,以此shard的名字来决定发送至哪个shard。不难看出,相对来说ImplicitDocRouter更加灵活。

在http://stackoverflow.com/questions/15678142/how-to-add-shards-dynamically-to-collection-in-solr中很好的介绍了动态创建/删除shard的好处(ImplicitDocRouter)

 One solution to the problem is to use the “implicit router” when creating your Collection.

 Solr does supports the ability to add New Shards (or DELETE existing shards) to your index (whenever you want) via the “implicit router” configuration (CREATE COLLECTION API).

 Lets say – you have to index all “Audit Trail” data of your application into Solr. New Data gets added every day. You might most probably want to shard by year.

 You could do something like the below during the initial setup of your collection:

 admin/collections?
action=CREATE&
name=AuditTrailIndex&
router.name=implicit&
shards=2010,2011,2012,2013,2014&
router.field=year
The above command: a) Creates 5 shards – one each for the current and the last 4 years 2010,2011,2012,2013,2014 b) Routes data to the correct shard based on the value of the “year” field (specified as router.field) In December 2014, you might add a new shard in preparation for 2015 using the CREATESHARD API (part of the Collections API) – Do something like: /admin/collections?
action=CREATESHARD&
shard=2015&
collection=AuditTrailIndex
The above command creates a new shard on the same collection. When its 2015, all data will get automatically indexed into the “2015” shard assuming your data has the “year” field populated correctly to 2015. In 2015, if you think you don’t need the 2010 shard (based on your data retention requirements) – you could always use the DELETESHARD API to do so: /admin/collections?
action=DELETESHARD&
shard=2015&
collection=AuditTrailIndex

Solr4.8.0源码分析(27)之ImplicitDocRouter和CompositeIdRouter的更多相关文章

  1. Solr4.8.0源码分析(25)之SolrCloud的Split流程

    Solr4.8.0源码分析(25)之SolrCloud的Split流程(一) 题记:昨天有位网友问我SolrCloud的split的机制是如何的,这个还真不知道,所以今天抽空去看了Split的原理,大 ...

  2. Solr4.8.0源码分析(24)之SolrCloud的Recovery策略(五)

    Solr4.8.0源码分析(24)之SolrCloud的Recovery策略(五) 题记:关于SolrCloud的Recovery策略已经写了四篇了,这篇应该是系统介绍Recovery策略的最后一篇了 ...

  3. Solr4.8.0源码分析(23)之SolrCloud的Recovery策略(四)

    Solr4.8.0源码分析(23)之SolrCloud的Recovery策略(四) 题记:本来计划的SolrCloud的Recovery策略的文章是3篇的,但是没想到Recovery的内容蛮多的,前面 ...

  4. Solr4.8.0源码分析(22)之SolrCloud的Recovery策略(三)

    Solr4.8.0源码分析(22)之SolrCloud的Recovery策略(三) 本文是SolrCloud的Recovery策略系列的第三篇文章,前面两篇主要介绍了Recovery的总体流程,以及P ...

  5. Solr4.8.0源码分析(21)之SolrCloud的Recovery策略(二)

    Solr4.8.0源码分析(21)之SolrCloud的Recovery策略(二) 题记:  前文<Solr4.8.0源码分析(20)之SolrCloud的Recovery策略(一)>中提 ...

  6. Solr4.8.0源码分析(20)之SolrCloud的Recovery策略(一)

    Solr4.8.0源码分析(20)之SolrCloud的Recovery策略(一) 题记: 我们在使用SolrCloud中会经常发现会有备份的shard出现状态Recoverying,这就表明Solr ...

  7. Solr4.8.0源码分析(14)之SolrCloud索引深入(1)

    Solr4.8.0源码分析(14) 之 SolrCloud索引深入(1) 上一章节<Solr In Action 笔记(4) 之 SolrCloud分布式索引基础>简要学习了SolrClo ...

  8. Solr4.8.0源码分析(15) 之 SolrCloud索引深入(2)

    Solr4.8.0源码分析(15) 之 SolrCloud索引深入(2) 上一节主要介绍了SolrCloud分布式索引的整体流程图以及索引链的实现,那么本节开始将分别介绍三个索引过程即LogUpdat ...

  9. Solr4.8.0源码分析(19)之缓存机制(二)

    Solr4.8.0源码分析(19)之缓存机制(二) 前文<Solr4.8.0源码分析(18)之缓存机制(一)>介绍了Solr缓存的生命周期,重点介绍了Solr缓存的warn过程.本节将更深 ...

随机推荐

  1. PreferenceActivity 自动保存属性

    package com.example.preference; import android.content.Context; import android.os.Bundle; import and ...

  2. mysql导出部分(指定)数据库表字段

      需要导出某个表中的部分字段信息 之前导出数据库表一直使用mysqldump命令,例如: mysqldump -hIP -uroot -P3306 -p 库 表 > 名字.sql 但是如果导出 ...

  3. Java基础知识强化之IO流笔记61:输入流 和 输出流 使用总结

    1. 结构: 字节流:InputStream,OutputStream 字符流:Reader,Writer 2. 字符流 和 字节流: (1)Reader:读取字符流的抽象类 BufferedRead ...

  4. 虚拟机及ubuntu环境搭建问题

    1.现象: VMware中ubuntu ping通 宿主机windows VMware中ubuntu ping通 百度 宿主机windows ping不通 VMware中ubuntu 解决办法: 确保 ...

  5. 解决无法获取 GridView 隐藏列值问题

    今天遇到了一个要获取GridView隐藏列值的问题,试了好几种方法,要么获取不到,要么获取到了类列的值也隐藏了,但在样式中这一列会多出一块,,但最后找到了一个功能实现而且实现了列完美隐藏的方法和大家分 ...

  6. HDU-1052(贪心策略)

    Tian Ji -- The Horse Racing Problem Description Here is a famous story in Chinese history. "Tha ...

  7. Unity3D 之3D游戏角色控制器运动

    3D运动,绑定了人形控制器后的一个简单的运动方法. using UnityEngine; using System.Collections; public class PlayerMove : Mon ...

  8. 20160331javaweb之JSP include 指令&&九大隐式对象

    3.零散知识 (1)jsp映射 <servlet> <servlet-name>index</servlet-name> <jsp-file>/inde ...

  9. 【转】【JavaScript】禁用backspace键的后退功能,但是可以删除文本内容

    在JavaScript中添加以下代码,就可实现 禁用backspace键的后退功能,但是可以删除文本内容 // 禁用backspace键的后退功能,但是可以删除文本内容 document.onkeyd ...

  10. Oracle 数据库(oracle Database)Select 多表关联查询方式

    Oracle数据库中Select语句语法及介绍 SELECT [ ALL | DISTINCT ] <字段表达式1[,<字段表达式2[,…] FROM <表名1>,<表名 ...