Alex,
Didn't get a chance to trace the code for that stacktrace, but can you try
passing _version_=1 as a parameter in the URL instead of a field in the
document and see if you observe anything different? Also double check that
the id is *indeed* a valid one.

Eg: http://localhost:8983/solr/techproducts/update?_version_=1

Rahul

On Fri, May 14, 2021 at 7:51 AM alex noname <mrfun.ch...@gmail.com> wrote:

> Thanks Rahul,
>
> Yes that's exactly what I want. The optimistic concurrency part looks
> complicated so I didn't check them.
>
> ============
>
> I just had a try, with _version_:1 and id:1, there's an error telling me
> the record with id = 1 not exists so the update rejected. This is perfect.
>
> *But it also failed to update with a valid id:*
>
> {
>     "id":"6bdc3c1d-d21a-43e3-aa84-baeeda601bb3",
>     "_version_":1,
>     "month":{"set":14}
> }
>
> this code fragment is generated from scanning database so we get month
> value for every record (the record may no longer exist in solr) and update
> them in solr.
>
>
> The solr server reports an unsupported operation error:
>
> Status:
> {"data":{"responseHeader":{"rf":1,"status":500,"QTime":1},"error":{"trace":"java.lang.UnsupportedOperationException\n\tat
>
> org.apache.lucene.queries.function.FunctionValues.longVal(FunctionValues.java:49)\n\tat
>
> org.apache.solr.update.VersionInfo.getVersionFromIndex(VersionInfo.java:225)\n\tat
> org.apache.solr.update.UpdateLog.lookupVersion(UpdateLog.java:1058)\n\tat
>
> org.apache.solr.update.VersionInfo.lookupVersion(VersionInfo.java:204)\n\tat
>
> org.apache.solr.update.processor.DistributedUpdateProcessor.doVersionAdd(DistributedUpdateProcessor.java:387)\n\tat
>
> org.apache.solr.update.processor.DistributedUpdateProcessor.lambda$versionAdd$0(DistributedUpdateProcessor.java:339)\n\tat
>
> org.apache.solr.update.VersionBucket.runWithLock(VersionBucket.java:50)\n\tat
>
> org.apache.solr.update.processor.DistributedUpdateProcessor.versionAdd(DistributedUpdateProcessor.java:339)\n\tat
>
> org.apache.solr.update.processor.DistributedUpdateProcessor.processAdd(DistributedUpdateProcessor.java:225)\n\tat
>
> org.apache.solr.update.processor.DistributedZkUpdateProcessor.processAdd(DistributedZkUpdateProcessor.java:245)\n\tat
>
> org.apache.solr.update.processor.LogUpdateProcessorFactory$LogUpdateProcessor.processAdd(LogUpdateProcessorFactory.java:103)\n\tat
>
> org.apache.solr.handler.loader.JsonLoader$SingleThreadedJsonLoader.handleAdds(JsonLoader.java:507)\n\tat
>
> org.apache.solr.handler.loader.JsonLoader$SingleThreadedJsonLoader.processUpdate(JsonLoader.java:145)\n\tat
>
> org.apache.solr.handler.loader.JsonLoader$SingleThreadedJsonLoader.load(JsonLoader.java:121)\n\tat
> org.apache.solr.handler.loader.JsonLoader.load(JsonLoader.java:84)\n\tat
>
> org.apache.solr.handler.UpdateRequestHandler$1.load(UpdateRequestHandler.java:97)\n\tat
>
> org.apache.solr.handler.ContentStreamHandlerBase.handleRequestBody(ContentStreamHandlerBase.java:68)\n\tat
>
> org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:211)\n\tat
> org.apache.solr.core.SolrCore.execute(SolrCore.java:2596)\n\tat
> org.apache.solr.servlet.HttpSolrCall.execute(HttpSolrCall.java:802)\n\tat
> org.apache.solr.servlet.HttpSolrCall.call(HttpSolrCall.java:579)\n\tat
>
> org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:420)\n\tat
>
> org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:352)\n\tat
>
> org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1596)\n\tat
>
> org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:545)\n\tat
>
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)\n\tat
>
> org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:590)\n\tat
>
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)\n\tat
>
> org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)\n\tat
>
> org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1607)\n\tat
>
> org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)\n\tat
>
> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1297)\n\tat
>
> org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)\n\tat
>
> org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485)\n\tat
>
> org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1577)\n\tat
>
> org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)\n\tat
>
> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1212)\n\tat
>
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\n\tat
>
> org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221)\n\tat
>
> org.eclipse.jetty.server.handler.InetAccessHandler.handle(InetAccessHandler.java:177)\n\tat
>
> org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)\n\tat
>
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)\n\tat
>
> org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:322)\n\tat
>
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)\n\tat
> org.eclipse.jetty.server.Server.handle(Server.java:500)\n\tat
>
> org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)\n\tat
> org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547)\n\tat
> org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)\n\tat
>
> org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:270)\n\tat
> org.eclipse.jetty.io
> .AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)\n\tat
> org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)\n\tat
> org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)\n\tat
>
> org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)\n\tat
>
> org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)\n\tat
>
> org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)\n\tat
>
> org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)\n\tat
>
> org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:388)\n\tat
>
> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)\n\tat
>
> org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)\n\tat
> java.base/java.lang.Thread.run(Unknown
>
> Source)\n","code":500}},"status":500,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","headers":{"Content-type":"application/json","Accept":"application/json,
> text/plain,
>
> */*","X-Requested-With":"XMLHttpRequest"},"data":"[{\n\"id\":\"6bdc3c1d-d21a-43e3-aa84-baeeda601bb3\",\n\"_version_\":1,\n\"month\":{\"set\":14}\n}]","url":"biocache/update","params":{"wt":"json","_":1620991739159,"commitWithin":1000,"overwrite":true},"timeout":10000},"statusText":"Server
>
> Error","xhrStatus":"complete","resource":{"0":"[","1":"{","2":"\n","3":"\"","4":"i","5":"d","6":"\"","7":":","8":"\"","9":"6","10":"b","11":"d","12":"c","13":"3","14":"c","15":"1","16":"d","17":"-","18":"d","19":"2","20":"1","21":"a","22":"-","23":"4","24":"3","25":"e","26":"3","27":"-","28":"a","29":"a","30":"8","31":"4","32":"-","33":"b","34":"a","35":"e","36":"e","37":"d","38":"a","39":"6","40":"0","41":"1","42":"b","43":"b","44":"3","45":"\"","46":",","47":"\n","48":"\"","49":"_","50":"v","51":"e","52":"r","53":"s","54":"i","55":"o","56":"n","57":"_","58":"\"","59":":","60":"1","61":",","62":"\n","63":"\"","64":"m","65":"o","66":"n","67":"t","68":"h","69":"\"","70":":","71":"{","72":"\"","73":"s","74":"e","75":"t","76":"\"","77":":","78":"1","79":"4","80":"}","81":"\n","82":"}","83":"]"}}
> Response:
>
> {
>   "responseHeader": {
>     "rf": 1,
>     "status": 0,
>     "QTime": 11
>   }
> }
> Do you have any idea what' the problem ?
>
> Thanks
>
>
> Rahul Goswami <rahul196...@gmail.com> 于2021年5月14日周五 下午12:55写道:
>
> > If I understand your concern correctly, you want to perform an atomic
> > update only if the document already exists, else just want the update to
> be
> > rejected (as in don't want a new document to be added)? . If that's
> > correct, add "_version_" field with value 1 in your document as below :
> >
> > {
> > "id":"1",
> > "_version_":1,
> > "month":{"set":1}
> > }
> >
> > Check out optimistic concurrency : Updating Parts of Documents | Apache
> > Solr Reference Guide 8.5
> > <
> >
> https://solr.apache.org/guide/8_5/updating-parts-of-documents.html#optimistic-concurrency
> > >
> >
> > "If the content in the _version_ field is equal to '1', then the document
> > must simply exist. In this case, no version matching occurs, but if the
> > document does not exist, the updates will be rejected."
> >
> > - Rahul
> >
> > On Thu, May 13, 2021 at 9:55 PM alex noname <mrfun.ch...@gmail.com>
> wrote:
> >
> > > Hi everyone,
> > >
> > > I'm doing some solr update coding and the solr version I'm using is
> 8.5.1
> > >
> > > So far I can successfully do a partial update by sending
> > >
> > > {
> > >     "id":"1",
> > >     "month":{"set":1}
> > > }
> > >
> > > to the /update handler. This way I can update the month filed to be 1
> for
> > > record with id 1.
> > >
> > >
> > > *But the thing is, if there's no existing record with id 1, a new
> record
> > > will be created with provided id and month info.*
> > >
> > > One workaround is, before issuing an update, I do a solr query for
> id:1,
> > > only when the result is not empty then I do the update.
> > >
> > > Just want to know, if there's a better way to do this?
> > >
> > >
> > >
> > > Thanks
> > >
> >
>

Reply via email to