[
https://issues.apache.org/jira/browse/LUCENE-6808?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Hoss Man updated LUCENE-6808:
-----------------------------
Attachment: LUCENE-6808.patch
Here's a patch which includes:
* A new testcase {{TestFieldComparatorValues}} demonstrating the problem when
using {{TermOrdValComparator}} and {{TermValComparator}} and how the behavior
of these two are inconsistent with the other existing impls.
* the previously mentioned fix to the {{value(slot)}} methods
* some other misc test coverage additions of {{FieldComparator.values(slot)}}
and {{fieldComparator.compareValues(first,second)}} (These don't demonstrate
the problem at all -- there were test improvements i attempted before i fullyer
understood the problem but they seemed like useful additions ot leave in)
There are still a few nocommits in FieldComparator.java related to the one
other place where a BytesRef is "shared" with the caller:
{{setTopValue(value)}} ... it's not clear to me if this should make a defensive
copy or not. If i understand correctly, the theory is that this value is
either coming from a previous call to {{value(slot)}} from the same, or another
instance of the same type of, FieldComparator (ie: FieldDoc from searchAfter)
and so we're safe since we already have a defensive copy (introduced by this
patch); or it's coming from a more complex client that knows it's dealing with
BytesRef and that client should have passed setTopValue a "safe" copy to use
internally. ... but maybe i'm wrong, maybe {{setTopValue}} should make it's own
copy?
> Term(Ord)ValComparator.value return BytesRefs that are re-used internally
> -------------------------------------------------------------------------
>
> Key: LUCENE-6808
> URL: https://issues.apache.org/jira/browse/LUCENE-6808
> Project: Lucene - Core
> Issue Type: Bug
> Reporter: Hoss Man
> Attachments: LUCENE-6808.patch
>
>
> While working on SOLR-6168, which involves some non-trivial usage of
> {{FieldComparator}}, I discovered some weird bugs anytime I was using
> TermOrdValComparator. I ultimately tracked this down to the fact that the
> {{BytesRef}} instances returned by {{TermOrdValComparator.value(int slot)}}
> are backed by {{BytesRefBuilder}} instances that the Comparator hangs on to
> and re-uses -- so the values a caller gets back from
> {{FieldComparator.value(slot)}} might be changed out from under it before it
> has a chance to use that value in something like
> {{FieldComparator.compareValues(first,second)}}.
> The general approach when dealing with BytesRef instances (as i understand
> it) is that the caller is responsible for making a copy if it wants to hang
> on to it -- but in this case that would violate the generic API of
> FieldComparator -- callers would have to pay attention to when a
> {{FieldComparator}} is a
> {{FieldComparator<BytesRef>}} and do casting to copy the BytesRef.
> It seems like the right solution is for {{TermOrdValComparator.value(slot)}}
> (and {{TermValComparator.value(slot)}} which has a similar BytesRef usage) to
> return {{BytesRef.deepCopyOf(values\[slot\])}}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]