Solr4.8.0源码分析(27)之ImplicitDocRouter和CompositeIdRouter
同样在公司工作中发现了一个现象,
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的更多相关文章
- Solr4.8.0源码分析(25)之SolrCloud的Split流程
Solr4.8.0源码分析(25)之SolrCloud的Split流程(一) 题记:昨天有位网友问我SolrCloud的split的机制是如何的,这个还真不知道,所以今天抽空去看了Split的原理,大 ...
- Solr4.8.0源码分析(24)之SolrCloud的Recovery策略(五)
Solr4.8.0源码分析(24)之SolrCloud的Recovery策略(五) 题记:关于SolrCloud的Recovery策略已经写了四篇了,这篇应该是系统介绍Recovery策略的最后一篇了 ...
- Solr4.8.0源码分析(23)之SolrCloud的Recovery策略(四)
Solr4.8.0源码分析(23)之SolrCloud的Recovery策略(四) 题记:本来计划的SolrCloud的Recovery策略的文章是3篇的,但是没想到Recovery的内容蛮多的,前面 ...
- Solr4.8.0源码分析(22)之SolrCloud的Recovery策略(三)
Solr4.8.0源码分析(22)之SolrCloud的Recovery策略(三) 本文是SolrCloud的Recovery策略系列的第三篇文章,前面两篇主要介绍了Recovery的总体流程,以及P ...
- Solr4.8.0源码分析(21)之SolrCloud的Recovery策略(二)
Solr4.8.0源码分析(21)之SolrCloud的Recovery策略(二) 题记: 前文<Solr4.8.0源码分析(20)之SolrCloud的Recovery策略(一)>中提 ...
- Solr4.8.0源码分析(20)之SolrCloud的Recovery策略(一)
Solr4.8.0源码分析(20)之SolrCloud的Recovery策略(一) 题记: 我们在使用SolrCloud中会经常发现会有备份的shard出现状态Recoverying,这就表明Solr ...
- Solr4.8.0源码分析(14)之SolrCloud索引深入(1)
Solr4.8.0源码分析(14) 之 SolrCloud索引深入(1) 上一章节<Solr In Action 笔记(4) 之 SolrCloud分布式索引基础>简要学习了SolrClo ...
- Solr4.8.0源码分析(15) 之 SolrCloud索引深入(2)
Solr4.8.0源码分析(15) 之 SolrCloud索引深入(2) 上一节主要介绍了SolrCloud分布式索引的整体流程图以及索引链的实现,那么本节开始将分别介绍三个索引过程即LogUpdat ...
- Solr4.8.0源码分析(19)之缓存机制(二)
Solr4.8.0源码分析(19)之缓存机制(二) 前文<Solr4.8.0源码分析(18)之缓存机制(一)>介绍了Solr缓存的生命周期,重点介绍了Solr缓存的warn过程.本节将更深 ...
随机推荐
- Android记录6--ViewPage+Fragment的使用例子
Android记录6--ViewPage+Fragment的使用例子 2013年9月6日Fragment学习 Fragment这个东西,我到现在才接触到,之前没有用到过,关于Fragment这个东西在 ...
- TRUNCATE TABLE 与 DELETE table 区别
语法 TRUNCATE TABLE name;参数 TRUNCATE TABLE 在功能上与不带 WHERE 子句的 DELETE 语句相同:二者均删除表中的全部行. TRUNCATE TABLE ...
- c++ 数据持久层研究(一)
C++ORM框架自动生成代码数据库 用过Java的都知道SSH框架,特别对于数据库开发,Java领域有无数的ORM框架,供数据持久层调用,如Hibernate,iBatis(现在改名叫MyBatis ...
- Android开发的第一天
不管做什么开发都是有开始的,对于开发的话开始要的准备的就是开发工具了 安装开发工具配置开发工具好了不多说了现在我来说怎么样安装和配置安卓的开发工具吧 第一首先就是要下载一个JDK (Java SE ...
- INI文件的读写
public class INIoperation { string inipath = Utils.GetMapPath("/Integration/Sync/set.ini") ...
- DevExpres.XtraLayout控件运行时动态设置数据项
问题分析: 通常.我们使用XtraLayout控件,是需要做以下的几个步骤来实现的: 1. 在窗体上拖拉一个 LayoutControl控件,设置它的填充属性: 2. 拖拉一些常规编辑控件到Lay ...
- Android中使用ViewPager实现广告条
我们在使用电商或视频的手机客户端时,通常会看到广告条的效果.在网上搜索时才知道使用的是ViewPager,于是自己也做了一个Demo. 以下是效果图: 图中包括背景图片.文字描述以及白点. 其中Vie ...
- SQL Server调优系列进阶篇 - 查询优化器的运行方式
前言 前面我们的几篇文章介绍了一系列关于运算符的基础介绍,以及各个运算符的优化方式和技巧.其中涵盖:查看执行计划的方式.几种数据集常用的连接方式.联合运算符方式.并行运算符等一系列的我们常见的运算符. ...
- JavaScript高级程序设计(五): js的关键字instanceof和typeof使用
JavaScript中instanceof和typeof 常用来判断一个变量是否为空,或者是什么类型的.但它们之间还是有区别的: 一.typeof 1.含义:typeof返回一个表达式的数据类型的字符 ...
- JS中==和===的区别
1.对于string,number等基础类型,==和===是有区别的 1)不同类型间比较,==之比较“转化成同一类型后的值”看“值”是否相等,===如果类型不同,其结果就是不等 2)同类型比较,直接进 ...