Skip to content

Log warning when URI precedence exceeds maximum 127 - #721

Merged
ato merged 1 commit into
internetarchive:masterfrom
simons-hub:fix/warn-on-precedence-clipping
Apr 6, 2026
Merged

ato merged 1 commit into
internetarchive:masterfrom
simons-hub:fix/warn-on-precedence-clipping

Conversation

@simons-hub

Copy link
Copy Markdown
Contributor

Summary

BdbMultipleWorkQueues.calculateInsertKey() silently clips URI precedence values to 127 for queue ordering. Custom cost assignment policies that return values above 127 get their precedence silently truncated with no indication anything is wrong.

This change:

  • Logs a warning when precedence clipping occurs, so operators can identify and fix misconfigured policies
  • Fixes the misleading comment on CrawlURI.holderCost that said "should not exceed 255" β€” the actual limit is 127 (7-bit signed byte, not 8-bit unsigned)

Details

The precedence byte in the BDB insert key is packed as a signed byte, so the effective maximum is 127 (Math.min(curi.getPrecedence(), 127)). The original author noted this in the method javadoc: "Dangers here are: (1) priorities or precedences over 2^7 (signed byte comparison)" β€” but no runtime warning was emitted.

A user with a custom CostAssignmentPolicy returning values up to 10000 (as described in #502) would have all precedence values silently flattened to 127, making their policy ineffective with no feedback.

Changes

File Change
BdbMultipleWorkQueues.java Log WARNING when precedence > 127 before clipping
CrawlURI.java Fix comment: "8 bits" / "255" β†’ "7 bits" / "127"

Testing

Full test suite passes (96 tests, 0 failures). Specifically:

  • BdbMultipleWorkQueuesTest β€” 2/2 (directly exercises calculateInsertKey across all ordinal ranges)
  • All 6 precedence policy tests β€” pass
  • BdbFrontierTest β€” pass

Fixes #502

BdbMultipleWorkQueues.calculateInsertKey() silently clips precedence
values to 127 for queue ordering. This can cause unexpected behavior
for custom cost assignment policies that return values above 127.

Log a warning when clipping occurs and fix the misleading comment in
CrawlURI.holderCost that said "should not exceed 255" (the actual
limit is 127, not 255).

Fixes internetarchive#502
@simons-hub
simons-hub marked this pull request as ready for review April 1, 2026 06:02
@ato
ato merged commit 7490998 into internetarchive:master Apr 6, 2026
3 checks passed
@ato

ato commented Apr 6, 2026

Copy link
Copy Markdown
Collaborator

Thanks. Released in 3.14.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implicit max. value of URI cost and precedence (?) should raise warning if exceeded

2 participants