Skip to content

[ISSUE #8223] Publish opt-in read-only base configuration - #8351

Open
hanzhe-one wants to merge 2 commits into
apache:masterfrom
hanzhe-one:feat/read-only-config-views
Open

hanzhe-one wants to merge 2 commits into
apache:masterfrom
hanzhe-one:feat/read-only-config-views

Conversation

@hanzhe-one

@hanzhe-one hanzhe-one commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Refs #8223.

Review scope and outstanding merge gate

This is the BaseDataCache matching-configuration first slice, with Divide as an actual adopter. It does not close #8223 or claim all gateway/Divide configuration is immutable. MetaDataCache, CommonHandleCache and parsed Divide handles remain explicitly documented legacy mutable paths.

Ready for review at the author's request; not a claim that the performance/merge gate has passed. Cloud-host validation now runs successfully, but performance parity remains inconclusive and the full update matrix encountered a baseline cache-hit publication-visibility assertion failure. Please review the implementation and the limitations below; the performance acceptance item remains unchecked. The earlier local Selector/loopback failure is not a blocker on the cloud host.

Problem and evidence

List.copyOf prevents changing the selector/rule container but does not detach its mutable DTO elements or nested conditions. A caller retaining the source ConditionData can alter another request's effective matching configuration.

An isolated probe compiled the production BaseDataCache from base 548bec1, published a selector with /original, modified its source condition to /polluted, and checked the returned value:

  • Baseline legacy contract: /polluted, assertion fails (exit 1).
  • This change's adopted readOnly() contract: /original, assertion passes (exit 0).

The same mutation is covered in PublishedConfigurationTest, including a legacy positive control showing that an immutable list alone is insufficient. This is a same-JVM trusted-code correctness boundary, not an HTTP mutation primitive or a sandbox against malicious extensions.

Changes

  • Add DtoSnapshots.freeze overloads for standard PluginData, SelectorData, RuleData and ConditionData. Freeze same-class copies at publication time, including both current/before condition lists and elements. Existing builders/source DTOs stay mutable, value equality/hash behavior is retained, and internal frozen state is not part of the JSON contract. All inherited/fluent setters reject writes on frozen instances; unknown concrete subclasses are explicitly rejected rather than incompletely frozen.
  • Add separate legacy and frozen publication storage with a narrow BaseDataCache.readOnly() contract. Reads return existing references and prebuilt unmodifiable map views. Normal publication/removal/refresh methods maintain both channels and reuse unchanged frozen elements; old backing-map mutation affects legacy state only. Writer-only synchronization orders paired publication calls, with no request-side lock or transactional revision protocol.
  • Add opt-in AbstractShenyuPlugin.useReadOnlyConfiguration(), default false, and enable it in Divide. Matching and execution receive frozen base DTOs; existing extension signatures and the legacy path remain. Request-owned default RuleData remains mutable. Negative sentinels are prebuilt/frozen; MatchDataCache isolates adopted entries, rejects mutable injection without copying, and receives all existing normal invalidation operations for both channels.
  • Retain intentionally mutable upstream health/counters/inflight/lag. Do not alter parsed handles or resource lifecycle.
  • Document migration, map-view generation semantics, legacy surfaces and costs. Extend the existing Divide HTTP benchmark with a separate config-view mode and runner; do not change the old run.ps1. The runner compiles nine base classes from 548bec1 as overrides, alternates baseline/change runs, covers 1/128 selectors with 1/128 rules each, matched/no-match/cache-hit and bounded update bursts, and records setup costs separately. It contains no fabricated measurements.

Compatibility and related work

Legacy mutable getter/map APIs remain, but direct writes to those maps are not publication to adopted plugins. Extensions must use the normal subscriber/publication APIs and standard DTOs before opting in. The compatibility period retains two representations and separate bounded derived-match caches, which adds update/storage cost that must be measured.

Frozen objects do not establish multi-object consistency or remove existing stale-match races. #8060 owns transactional revisions; #8061 owns resource leases. Existing match-cache generation/selector-scoping work in PR #7681 and PR #8103, and matching observation in PR #8291, is not duplicated here. The paired writer monitor exists to avoid introducing opposite legacy/frozen update orders; it is not a substitute for their request-visible contracts.

Validation

Targeted Maven-wrapper reactor command:

./mvnw -o -Dmaven.legacyLocalRepo=true -pl shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide -am test -Dtest=DtoSnapshotsTest,PluginDataTest,SelectorDataTest,RuleDataTest,ConditionDataTest,PublishedConfigurationTest,BaseDataCacheTest,MatchDataCacheTest,AbstractShenyuPluginTest,CommonPluginDataSubscriberTest,DividePluginTest,DividePublishedConfigurationTest -Dsurefire.failIfNoSpecifiedTests=false -Djacoco.skip=true -Dmaven.javadoc.skip=true

174 tests, 0 failures, 0 errors, 0 skipped:

Test class Count
DtoSnapshotsTest 12
Existing PluginData/SelectorData/RuleData/ConditionData tests 9
PublishedConfigurationTest 8
BaseDataCacheTest 25
MatchDataCacheTest 9
AbstractShenyuPluginTest 17
CommonPluginDataSubscriberTest 64
DividePluginTest 26
DividePublishedConfigurationTest 4

Coverage includes source/nested-condition detachment; reflective coverage of every public setter and DTO field; symmetric equality and Gson/Jackson round trips; map/list/entry mutation rejection; legacy-map isolation; refresh ordering and removal; rejection of invalid snapshots without partial channel updates; held-reader stability; read-only match injection rejection; actual Divide matching/forwarding, positive/negative invalidation and request-local default rules; live health/inflight mutation.

  • Checkstyle ran at validate for the target reactor: 0 violations.
  • ./mvnw -o -Dmaven.legacyLocalRepo=true -pl shenyu-common,shenyu-plugin/shenyu-plugin-base,shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide apache-rat:check: passed, 0 unapproved files in all three modules.
  • git diff --check and staged diff check: passed.
  • Extended HTTP harness javac --release 17: passed against changed and baseline APIs; the nine base override classes also compiled. PowerShell AST parsing: passed. These checks used available local/installed dependencies, not a completed benchmark deployment; the standard gateway-classpath.txt was absent. Only compilation/static validity is claimed.
  • Generic submission helper Ruff checks report existing unrelated Python lint/format issues. This PR changes no Python and includes no unrelated cleanup.

Cloud-host validation update (2026-11-08)

All project compilation, tests and benchmark execution reported here took place on the Simular Box cloud computer, not the phone. Tested PR head: 53ed8024e357780d1ce0ce543bccefcd43695e5f; benchmark baseline override: 548bec1f9. Ubuntu x86_64, Java 17.0.20.1, Maven Wrapper 3.6.3; system-visible 4 logical CPUs and approximately 7.7 GiB RAM. Benchmark JVMs used the runner's 512 MiB heap and ActiveProcessorCount=8; the latter is a runner setting, not a claim of 8 physical cores.

  • Re-ran the targeted reactor tests online: 174 tests, 0 failures, 0 errors, 0 skipped; BUILD SUCCESS, exit 0 (1m39s). Java/Maven initially failed with UnknownHostException because they did not automatically use the host's HTTP proxy; explicit proxy configuration resolved this environment issue.
  • Benchmark-profile reactor install and dependency classpath generation: passed, exit 0. This is not a full-repository clean install.
  • Compiled the harness and nine baseline override classes on Linux. Used uncommitted diagnostic runner copies adapting executable names, Windows-only WindowStyle, and classpath separators; the production implementation was unchanged.
  • 500 offered requests/s, 2,000 requests/sample, 3 repeats: a steady-state-only diagnostic matrix completed 36 samples / 72,000 load requests, 0 recorded request errors, exit 0, with JFR enabled.
  • 100 offered requests/s, 2,000 requests/sample, 3 repeats: the same steady-state-only matrix completed 36 samples / 72,000 load requests, 0 recorded request errors, exit 0, with JFR enabled.
  • Both steady matrices cover 1/128 selectors, 1/128 rules per selector, matched/no-match/cache-hit, and alternating baseline/change order. Expected no-match 404 responses are counted as expected responses, not successful upstream forwards. These diagnostic runs explicitly use updates=0 and do not replace the failed update matrix.

Observed latency (median of three sample p95 values, milliseconds)

Selectors Scenario 500 rps baseline 500 rps change 100 rps baseline 100 rps change
1 matched 32.52 112.64 67.09 71.90
1 no-match 20.70 7.40 40.07 39.54
1 cache-hit 165.70 71.27 349.93 163.36
128 matched 85.87 528.94 31.55 11.52
128 no-match 201.21 350.69 72.25 62.08
128 cache-hit 379.73 451.02 35.85 12.31

Interpretation: inconclusive, not a performance pass. Some 500-rps samples show substantial apparent regressions, while lower-rate comparisons change direction and remain noisy. Allocation per request was broadly similar, but latency/CPU variability prevents a defensible no-regression or capacity-parity claim. Fixed offered-rate runs do not establish saturation throughput. JFR was collected; a complete profiling/retained-memory and saturation analysis is still outstanding.

Failed update-matrix evidence (not waived)

The original full 500-rps matrix recorded 30 completed samples with 0 recorded load-request errors, then failed at baseline-1-cache-hit-b32-r500-0: IllegalStateException: first post-publication request must see v32. The load process subsequently remained alive until the runner's 180-second deadline. This is a correctness assertion failure despite zero errors in preceding completed samples. It occurred in the baseline variant; this alone does not establish that the change is unaffected or fixes it. Further baseline/change reproduction, cache invalidation/concurrent repopulation investigation, and harness failure-path cleanup are required. No claim of publication-convergence acceptance is made.

Raw CSV, per-process logs, configurations and JFR files are retained on the cloud host under /workspace/shenyu-pr8351/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/target/config-views-*:

  • Full matrix (failed): config-views-20261108-103438-33f0c05d.
  • 500-rps steady diagnostic: config-views-20261108-104707-832b7eaa.
  • 100-rps steady diagnostic: runner output and exit 0 recorded in /workspace/pr8351-steady100.log and .exit; its timestamped directory remains under the same target parent.

These paths are provenance on the test host, not publicly attached artifacts or independently downloadable evidence. Publishing a reproducible artifact bundle remains outstanding.

Not run / still required: full repository clean install; Docker/e2e; successful full update/correctness matrix; resolved performance variability and regression assessment; saturation/rate sweep; complete CPU/allocation/peak/retained-memory/JFR analysis; public raw artifacts and reproducible Linux runner. Earlier compile-only limitations above describe the original submission environment and are superseded only by the specific cloud-host checks listed here.

Checklist

  • Read the contribution guidelines.
  • Submit test cases supporting the scoped change.
  • Full local ./mvnw clean install -Dmaven.javadoc.skip=true passed (not run; targeted checks above).
  • Produce the issue-required repeated real-forwarding performance evidence and demonstrate no measurable ordinary-path regression before merge (still outstanding; readiness is for review, not acceptance).

@hanzhe-one

Copy link
Copy Markdown
Contributor Author

Keeping this as a Draft deliberately. Before I spend time producing the full performance matrix, I would like scope feedback — if the direction is wrong, adjusting now is cheaper than after the benchmark work.

What this slice does

  • Creates frozen same-class copies of PluginData / SelectorData / RuleData / ConditionData at publication time (DtoSnapshots.freeze), not per request.
  • Adds a narrow BaseDataCache.readOnly() contract. Legacy getters and backing maps keep their current mutable semantics.
  • Adds opt-in AbstractShenyuPlugin.useReadOnlyConfiguration(), default false. DividePlugin overrides it to true; matching and doExecute then receive frozen base DTOs.
  • Gives MatchDataCache an isolated channel that rejects mutable values instead of copying them on a cache hit. Existing invalidation calls clear both channels.

What it deliberately does not do

Validation so far

174 targeted tests pass, covering DTO snapshot/equality/JSON compatibility, publication isolation including nested conditions and map/list entry writes, rejection of invalid input without a partial channel update, invalidation, the legacy plugin path, and real Divide matching/forwarding with request-owned default rules. Checkstyle reports 0 violations; RAT is clean on the three affected modules. The comparison harness compiles against both the 548bec1f9 baseline APIs and this change.

The gate that is not met

The issue's real-forwarding performance acceptance gate is unmet. On this machine a standalone probe fails before any gateway code runs:

  • Selector.open() -> IOException: Unable to establish loopback connection
  • caused by java.net.SocketException: Invalid argument: connect (UnixDomainSockets)
  • identical failure with -Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.WindowsSelectorProvider

So throughput, p95/p99, CPU, allocation, update convergence and retained-memory numbers are missing, and I am not claiming the absence of a regression. docs/benchmarks/divide-gateway has a separate config-view mode ready for that run.

Questions

  1. Is BaseDataCache-only, with metadata and parsed handles left explicitly legacy, an acceptable first slice?
  2. Is freeze-on-publication with the legacy mutable API retained the direction you want, rather than an incompatible migration to immutable DTOs?
  3. For the gate, is the supplied config-view benchmark mode on a working host sufficient, or would you want the measurement done differently?

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stream Agent analysis

PR #8351 (head 53ed802) implements the first slice of opt-in read-only base configuration publishing, with Divide as an adopter. Changed files include new DtoSnapshots (freeze/read-only snapshots), BaseDataCache/ReadMatchDataCache PUBLISHED+READ_ONLY singletons, DividePlugin and AbstractShenyuPlugin wiring, plus docs and tests. The PR description itself states it is Draft and the real-forwarding performance acceptance gate is unmet.

Evidence

  • Frozen reference: ci.complete=true, ci.passed=false, ci.legacy_state=pending, 64 checks; PR description marks it Draft with unmet performance gate
  • resource_read BaseDataCache.java@head: INSTANCE/PUBLISHED/READ_ONLY singletons; published flag gates writes to PUBLISHED; cacheRuleData uses DtoSnapshots.freeze when published
  • resource_read MatchDataCache.java@head: PUBLISHED/READ_ONLY singletons and readOnly() accessor added; remove/cache methods propagate to PUBLISHED only from INSTANCE

Recommended next steps

  • Re-read the pinned diff via resource_diff from offset 161000 until has_more=false to cover the remaining ~4281 characters and all 18 files
  • Reconcile CI status: provided evidence shows complete=true but passed=false; obtain green CI before any PASS
  • Verify DividePlugin and AbstractShenyuPlugin integration against the read-only cache contract and the new tests

Scope: captured diff and GitHub check metadata only; no local tests were executed.

Task: 4af48a03-91a9-4f46-b92f-a36f5ed086fe · Commit: 53ed8024e357780d1ce0ce543bccefcd43695e5f

Review verdict: INCONCLUSIVE

Full diff coverage was not achieved (next_unread_offset 161000 of 165281; diff pages archived and not re-materialized in context) and the provided CI evidence reports passed=false, so PASS cannot be granted and no concrete blocking defect was confirmed in the partial read. Per protocol, incomplete coverage and non-passing CI yield INCONCLUSIVE with empty reviewed_head and no findings.

Publication: COMMENT (REVIEW_EVIDENCE_MISSING)

Review details

Review could not be completed to a PASS/NEEDS_CHANGES verdict. Per the frozen reference evidence, the diff was not fully read (next_unread_offset 161000 of total 165281 characters; full diff pages were archived and not re-materialized in this context), and CI is reported complete=true but passed=false with legacy_state=pending. Partial source reads of BaseDataCache, MatchDataCache and DtoSnapshots confirm the read-only snapshot design (PUBLISHED/READ_ONLY instances, freeze() gating), but full cross-file contract verification and all 18 changed files were not covered. Recommend re-running the review after retrieving the remaining diff pages and confirming green CI; the PR should remain Draft until the performance gate is satisfied.

@hanzhe-one

Copy link
Copy Markdown
Contributor Author

Could a maintainer please rerun only the failed build (shenyu-integrated-test-http) job on the current head, 53ed8024e357780d1ce0ce543bccefcd43695e5f?

I checked the full job log:

  • The build and integrated-test compilation steps passed.
  • The HTTP suite reported 103 tests, 0 assertion failures, 1 error, 5 skipped.
  • The error was SocketTimeoutException: timeout after 180 seconds, in CryptorResponsePluginTest.setup() at line 78, during initPlugin(...) (POST /shenyu/plugin/saveOrUpdate). The parameterized test body had not started.
  • The gateway recorded the corresponding cryptorResponse initialization around 11:28:05.801Z, near the end of that timeout window. Subsequent initialization requests and the remaining response-cryptor cases completed normally.

This is consistent with a transient request/connection delay, but the root cause is not established and I am not claiming it is unrelated to this PR. A rerun of the unchanged job would help distinguish a repeatable regression from a one-off timeout. If it repeats, I will investigate further rather than adding retries or weakening the test.

I tried gh run rerun 42367578643 --repo apache/shenyu --job 128388821983; the CLI returned job 128388821983 cannot be rerun, and my account has no write permission on the upstream repository. No code or empty commit was added to trigger another run.

The PR remains Draft: green CI would not replace the separately outstanding real-forwarding performance acceptance gate.

@hanzhe-one
hanzhe-one marked this pull request as ready for review November 8, 2026 11:27

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stream Agent analysis

Reviewed the full 18-file PR that adds opt-in frozen BaseDataCache configuration views (DtoSnapshots, dual legacy/published channels, readOnly contracts, DividePlugin opt-in) together with benchmark harness and tests. No concrete production defect was found, but CI is pending and the documented performance/publication-visibility gate is unmet, so the verdict is INCONCLUSIVE.

Evidence: ["Full VERSIONED_DIFF read to completion: all pages offset 0..165817, has_more=false, each sha256 6dcf797c24faad9ac03a0f3f04361ebb5d447dae8aa3775e85ab0441ddefd687 matching the pinned comparison; 18 files spanning DTOs, cache/matching classes, DividePlugin, benchmark docs and new tests.","CI evidence shows all 44 checks in_progress with null conclusions, passed=false, pending=true, diagnosis CI_PENDING; no passing CI is available on the reviewed head.","PR description states performance parity is inconclusive, the full update matrix failed 'IllegalStateException: first post-publication request must see v32' in the baseline variant, and the required real-forwarding acceptance gate/public artifacts remain outstanding. Verified at pinned head that DividePlugin.doExecute only reads selector/rule and that subscriber invalidations forward to the published channel; no concrete HIGH/CRITICAL defect identified."]

Next steps: ["Wait for the pending CI checks on head 98bdd5f (notably build and shenyu-integrated-test-http) to complete and confirm they pass.","Obtain the outstanding real-forwarding performance evidence, a successful full update/correctness matrix (the baseline 'first post-publication request must see v32' assertion failure), and reproducible public artifacts required by issue #8223.","Re-run the review once CI and validation evidence are complete to reach a PASS or a defect-anchored NEEDS_CHANGES conclusion."]

Verdict: INCONCLUSIVE; publication: COMMENT (DIFF_DELIVERY_INCOMPLETE)

Findings: []

Scope: captured GitHub evidence only; no local tests were executed.

Task: 20563cc3-010e-45fa-bbd4-6d0d6529b5f6 Commit: 98bdd5f22b5783ad0a27477feb491c7e575644d3

This branch has not been deployed

No deployments
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.

[Task][Plugin Base] Publish read-only cached configuration views without per-request copying

2 participants