本文原文:Solr TTL - Auto-Purging Solr Documents & Ranger Audits
背景
最近公司的使用的大数据项目中频繁出现以下的报错:
ERROR [org.apache.ranger.audit.queue.AuditBatchQueue0] o.a.s.c.solrj.impl.CloudSolrClient:924- Request to collection ranger_audits failed due to (400) org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://172.18.2.6:8886/solr/ranger_audits_shard1_replica1: Exception writing document id bc8d53c6-0878-450c-a9b0-1b8d34c55e1d to the index; possible analysis error: number of documents in the index cannot exceed 2147483519, retry? 0
搜索了一下原因,大致是说solr分片的索引量不能超过最大值(2的32次方)。由于线上solr是单机版本,所以数据量上已经超了,为了解决这个问题,我搜索到了下面这篇文章。
这篇文章将讲述如何在Solr文档上使用TTL(time to live)来自动清理过期文档。
这篇文章我们将关注如何自动地从Solr集合中删除文档,关于solr文档TTL的问题如下:
- 节点磁盘满
- 公司策略要求删除旧的审计日志(audit logs)
- 自动清理等
SOLR-5795介绍了一个新的UpdateProcesser叫做DocExpirationUpdateProcessorFactory
,它允许我们在solr文档上添加一个过期时间
,并且确保过期的文档能够自动的被清除。