← Back to Pull requests

SOLR-18200: make TextProfileSignature stable across HashMap rehash #5339

Merged
iprithv merged 4 files (133 lines) on Dec 02, 2026 16:42 UTC
View on GitHub
iprithv iprithv commented on Nov 13, 2026 19:57 UTC
Author

https://issues.apache.org/jira/browse/SOLR-18200

TextProfileSignature sorted tokens by frequency only, so equal-frequency ties followed HashMap iteration order. that order changes when the map rehashes, so the same surviving profile could get a different MD5.

tie-break on the token string so the profile is a pure function of the input.

Diff: 133 lines (+129 / -4) across 4 files Reviewer: sigram Review duration: 27165m
All Vouch review confidence checks passed
Residual risk 0.05 = Change Risk (0.37) × (1 − Review Confidence (0.86)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 133 lines diff across 4 files
0.37
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.81 · 5 substantive comment(s)
0.81
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
86%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.293
Real PR Conversation Timeline
13 items
github-actions[bot] github-actions[bot] commented on Nov 13, 2026 19:57 UTC
Bot

Automated PR readiness judgements (LLM-generated; may be wrong; not updated on later pushes).

  • ✅ Jira issue in title: already present

  • ⚠️ Changelog — missing (suggest type: fixed): The change fixes a bug where the TextProfileSignature MD5 hash was non-deterministic due to HashMap iteration order, which is a user-visible symptom (inconsistent profiling results).​

  • ✅ Reference Guide update: not needed <!-- The change is an internal fix to ensure deterministic sorting&#59; it does not alter any documented request parameters&#44; configuration settings&#44; or user&#45;facing API behavior&#46;​ -->

  • ✅ Upgrade notes: not needed <!-- This is a bug fix that makes behavior more consistent and does not remove or rename any parameters&#44; APIs&#44; or configuration elements&#46;​ -->

  • ✅ Tests: included <!-- The change modifies the sorting logic in TokenComparator to ensure stability&#44; which is non&#45;trivial production logic that warrants a test to verify deterministic output&#46;​ -->
  • <!-- Assessed commit 5a70cedaceb89a3bfed90d60c9356a52fdfa6b80 -->

    nick-boss-tech nick-boss-tech commented on code on Nov 16, 2026 03:27 UTC
    Code Review
    solr/core/src/java/org/apache/solr/update/processor/TextProfileSignature.java:1
    @@ -151,7 +151,11 @@ public String toString() {
       private static class TokenComparator implements Comparator<Token> {
         @Override
         public int compare(Token t1, Token t2) {
    -      return t2.cnt - t1.cnt;
    +      int c = Integer.compare(t2.cnt, t1.cnt);
    +      if (c != 0) {
    +        return c;
    +      }
    +      return t1.val.compareTo(t2.val);

    🤖 AI text below 🤖 (reviewed by Nick Shanin)

    This can change the signature for profiles whose tied tokens previously had a different order. Existing documents keep their old signatures, so overwriteDupes may no longer match them. If the signature is the unique key, a later add can also get a different ID.

    Could the upgrade notes explain this effect for users of TextProfileSignature and when they may need to rebuild their index?

    nick-boss-tech nick-boss-tech commented on code on Nov 16, 2026 03:27 UTC
    Code Review
    solr/core/src/test/org/apache/solr/update/processor/TextProfileSignatureTest.java:1
    @@ -0,0 +1,90 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.solr.update.processor;
    +
    +import java.util.HexFormat;
    +import java.util.Locale;
    +import java.util.Map;
    +import org.apache.solr.SolrTestCase;
    +import org.apache.solr.common.params.MapSolrParams;
    +import org.junit.Test;
    +
    +public class TextProfileSignatureTest extends SolrTestCase {
    +
    +  private static TextProfileSignature newSignature() {
    +    TextProfileSignature sig = new TextProfileSignature();
    +    sig.init(new MapSolrParams(Map.of()));
    +    return sig;
    +  }
    +
    +  private static byte[] signatureOf(String content) {
    +    TextProfileSignature sig = newSignature();
    +    sig.add(content);
    +    return sig.getSignature();
    +  }
    +
    +  private static String hex(byte[] bytes) {
    +    return HexFormat.of().formatHex(bytes);
    +  }
    +
    +  @Test
    +  public void testIdenticalContentSameSignature() {
    +    String content = "the quick brown fox jumps over the lazy dog";
    +    assertArrayEquals(signatureOf(content), signatureOf(content));
    +  }
    +
    +  @Test
    +  public void testSignatureStableAcrossHashMapResize() {
    +    String[] head = {"alpha", "bravo", "charlie", "delta", "echo", "foxtrot"};
    +    StringBuilder base = new StringBuilder();
    +    for (String token : head) {
    +      for (int i = 0; i < 200; i++) {
    +        if (!base.isEmpty()) {
    +          base.append(' ');
    +        }
    +        base.append(token);
    +      }
    +    }
    +
    +    byte[] expected = signatureOf(base.toString());
    +    for (int n = 0; n < 80; n++) {
    +      StringBuilder text = new StringBuilder(base);
    +      for (int i = 0; i <= n; i++) {
    +        text.append(' ').append("xpad").append(String.format(Locale.ROOT, "%04d", i));
    +      }
    +      byte[] actual = signatureOf(text.toString());
    +      assertArrayEquals(

    🤖 AI text below 🤖 (reviewed by Nick Shanin)

    The resize test covers the reported failure. Could the tests also assert a known signature for a profile with different frequencies and a tie after quantization? That would check the intended frequency order and tie-break as well as stability.

    nick-boss-tech nick-boss-tech commented on code on Nov 16, 2026 03:27 UTC
    Code Review
    solr/core/src/java/org/apache/solr/update/processor/TextProfileSignature.java:1
    @@ -35,7 +35,7 @@
      *   <li>remove all characters except letters and digits, and bring all characters to lower case,
      *   <li>split the text into tokens (all consecutive non-whitespace characters),
      *   <li>discard tokens equal or shorter than MIN_TOKEN_LEN (default 2 characters),
    - *   <li>sort the list of tokens by decreasing frequency,
    + *   <li>sort the list of tokens by decreasing frequency (ties broken by token string),

    Could the Javadoc list the sorting step after quantization and filtering, to match the order in the implementation?

    iprithv iprithv commented on code on Nov 16, 2026 18:52 UTC
    Code Review
    solr/core/src/java/org/apache/solr/update/processor/TextProfileSignature.java:1
    @@ -151,7 +151,11 @@ public String toString() {
       private static class TokenComparator implements Comparator<Token> {
         @Override
         public int compare(Token t1, Token t2) {
    -      return t2.cnt - t1.cnt;
    +      int c = Integer.compare(t2.cnt, t1.cnt);
    +      if (c != 0) {
    +        return c;
    +      }
    +      return t1.val.compareTo(t2.val);

    added an upgrade note in major-changes-in-solr-11 covering the signature change for tied tokens, overwriteDupes mismatch, uniqueKey ID risk, and when to reindex.

    iprithv iprithv commented on code on Nov 16, 2026 18:53 UTC
    Code Review
    solr/core/src/test/org/apache/solr/update/processor/TextProfileSignatureTest.java:1
    @@ -0,0 +1,90 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.solr.update.processor;
    +
    +import java.util.HexFormat;
    +import java.util.Locale;
    +import java.util.Map;
    +import org.apache.solr.SolrTestCase;
    +import org.apache.solr.common.params.MapSolrParams;
    +import org.junit.Test;
    +
    +public class TextProfileSignatureTest extends SolrTestCase {
    +
    +  private static TextProfileSignature newSignature() {
    +    TextProfileSignature sig = new TextProfileSignature();
    +    sig.init(new MapSolrParams(Map.of()));
    +    return sig;
    +  }
    +
    +  private static byte[] signatureOf(String content) {
    +    TextProfileSignature sig = newSignature();
    +    sig.add(content);
    +    return sig.getSignature();
    +  }
    +
    +  private static String hex(byte[] bytes) {
    +    return HexFormat.of().formatHex(bytes);
    +  }
    +
    +  @Test
    +  public void testIdenticalContentSameSignature() {
    +    String content = "the quick brown fox jumps over the lazy dog";
    +    assertArrayEquals(signatureOf(content), signatureOf(content));
    +  }
    +
    +  @Test
    +  public void testSignatureStableAcrossHashMapResize() {
    +    String[] head = {"alpha", "bravo", "charlie", "delta", "echo", "foxtrot"};
    +    StringBuilder base = new StringBuilder();
    +    for (String token : head) {
    +      for (int i = 0; i < 200; i++) {
    +        if (!base.isEmpty()) {
    +          base.append(' ');
    +        }
    +        base.append(token);
    +      }
    +    }
    +
    +    byte[] expected = signatureOf(base.toString());
    +    for (int n = 0; n < 80; n++) {
    +      StringBuilder text = new StringBuilder(base);
    +      for (int i = 0; i <= n; i++) {
    +        text.append(' ').append("xpad").append(String.format(Locale.ROOT, "%04d", i));
    +      }
    +      byte[] actual = signatureOf(text.toString());
    +      assertArrayEquals(

    added testKnownSignatureFrequencyOrderAndQuantizationTie.. fixed hex for aaaa/bbbb/cccc with a post-quantization tie, plus shuffled input.

    iprithv iprithv commented on code on Nov 16, 2026 18:53 UTC
    Code Review
    solr/core/src/java/org/apache/solr/update/processor/TextProfileSignature.java:1
    @@ -35,7 +35,7 @@
      *   <li>remove all characters except letters and digits, and bring all characters to lower case,
      *   <li>split the text into tokens (all consecutive non-whitespace characters),
      *   <li>discard tokens equal or shorter than MIN_TOKEN_LEN (default 2 characters),
    - *   <li>sort the list of tokens by decreasing frequency,
    + *   <li>sort the list of tokens by decreasing frequency (ties broken by token string),

    yep, javadoc now lists sort after quantization/filtering to match the implementation.

    sigram sigram commented on Nov 17, 2026 18:18 UTC
    Contributor

    LGTM, +1.

    sigram sigram approved these changes on Nov 17, 2026 18:18 UTC
    Approved Reviewer

    Approved these changes.

    nick-boss-tech nick-boss-tech approved these changes on Nov 18, 2026 02:35 UTC
    Approved Reviewer

    Approved these changes.

    sigram sigram commented on Nov 23, 2026 10:20 UTC
    Contributor

    @iprithv you need to merge from main to get a non-Crave runner.

    iprithv iprithv commented on Nov 23, 2026 11:08 UTC
    Author

    ah okay. got it, thanks for the heads up. merged main!

    Reviewers
    Assignees
    iprithv iprithv
    Labels
    risk: low confidence: 86% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.7% (MEDIUM) · Higher = larger blast radius
    36.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 86% · Lower = rushed or shallow review
    86%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 5.1% · Safe to merge
    5.1%
    Repository