具有乐观锁定的Solr更新语义

具有乐观锁定的Solr更新语义,solr,solrj,solr4,Solr,Solrj,Solr4,我在Solr4.6.1中遇到了一个奇怪的场景 我正在尝试多次更新文档。此的伪代码: id1 = obtain-the-ID-of-the-document() lock() // only one thread is updating document1 doc1 = read-document-from-Solr-with-realtime-GET(id1) modify-document(doc1) update-document-in-Solr(doc1) unlock()

我在Solr4.6.1中遇到了一个奇怪的场景

我正在尝试多次更新文档。此的伪代码:

id1 = obtain-the-ID-of-the-document()
lock() 
// only one thread is updating document1
  doc1 = read-document-from-Solr-with-realtime-GET(id1)
  modify-document(doc1)
  update-document-in-Solr(doc1)
unlock()

[...]

id1 = obtain-the-ID-of-the-document()
lock() 
// only one thread is updating document1
  doc1 = read-document-from-Solr-with-realtime-GET(id1)
  modify-document(doc1)
  update-document-in-Solr(doc1)
unlock()
现在,我也在使用Solr的乐观锁定机制,主要是为了确保我的更新逻辑是正确的。有时我仍然会从Solr那里得到“冲突”,状态代码是409

看起来更新操作是在写入事务日志之前返回的,因为RealTimeGetHandler找不到更新的版本(我知道这一点,因为返回的文档具有相同的版本号)。因此,第二次修改可能实际上在同一文档上执行,因为两个实时get查询都返回相同的文档;冲突的原因

我通过在更新方法中添加一个小延迟(50-100ms)来解决这个问题,并重新查询Solr,直到版本号不同;此时,我假设事务日志已正确更新,因此可以安全地解锁并返回以处理下一个文档


增加延迟真的很奇怪,是解决这个问题的更好方法吗?或者可能有一些配置告诉Solr仅在写入tlog后才从更新返回?

当更新处理程序响应时,更新将写入更新日志。是否将更新显式提交到索引?是。有一个单独的作业/线程每30秒执行一次(硬提交)。我在用电话。