xihaian251 opened a new pull request, #1046:
URL: https://github.com/apache/burr/pull/1046

   # PR Body (Release) — Partition-aware local tracking
   
   > Draft only. Not submitted.
   
   ## Title
   
   ```
   fix(tracking): isolate local tracking state by partition key
   ```
   
   `Fixes #319`
   
   Patch SHA-256: 
`d7265b644647564f71a40d0176c7a6b36c1dc27b45a251236ab964e8d024d9e5`  
   Scope: 5 files, +818/−58, based on 
`36e3ff3048c8cabd7aac6d5c373307934bf3c2df`.
   
   ---
   
   ## Summary
   
   `LocalTrackingClient` used `<project>/<app_id>` as its only storage key. 
`partition_key` was persisted in `metadata.json` but ignored by path 
construction and `load()`. Two apps with the same project and app id but 
different partitions shared one log, metadata and children file; `load()` could 
return the last writer's state while labelling it with the caller's partition, 
and `ApplicationBuilder.initialize_from()` then resumed the wrong partition.
   
   This change writes non-`None` partitions to 
`<project>/<app_id>/partitions/p-<sha256(partition_key)>/`, verifies metadata 
before every legacy or partitioned read, teaches `LocalBackend` to resolve and 
enumerate partition runs, and routes fork/spawn child pointers to the parent's 
partition directory. The key itself never becomes a path segment, so 
separators, control characters, Unicode, empty strings and long keys are safe. 
`partition_key=None` keeps the original layout.
   
   An empty partitioned log created during `Application.__init__` cannot shadow 
legacy data during upgrade resume; a completed nested log takes precedence once 
written.
   
   ## Compatibility
   
   - Patched reader → legacy data with confirming or absent partition metadata: 
supported.
   - Patched reader → legacy data with unknown or mismatched ownership: 
explicit error; no automatic migration, overwrite or deletion.
   - Old and new runs for the same app id coexist; a completed new run 
supersedes a legacy run for the same partition in reads and UI listing.
   - **Old readers only see the legacy layout.** If a storage directory 
contains only new partitioned writes, an old `LocalTrackingClient.load()` 
returns no state. If the directory still contains legacy files (for example 
after an upgrade resume), the old reader returns that legacy state S1 and its 
UI shows only legacy steps, even though newer state S2/S3 exists in the 
partition directory. This can silently restore stale state.
   - **Do not mix versions on one storage directory.** Verified with real API 
calls: after an old writer creates legacy state S1 and a patched reader resumes 
it and writes newer state S2/S3 into the partition directory, an old reader 
still loads S1 and its UI shows only the legacy steps. Upgrade all readers 
before adopting partitioned writes; do not roll a reader back while shared 
storage contains legacy files alongside partitioned data.
   - #946/#948 add shared identifier validation and path containment. This 
change imports `join_within` through an optional shim and adds no duplicate 
validator. Integration trees with each PR were tested. With #948, the test 
failure set is identical to the pure #948 baseline (13 pre-existing 
Windows-specific failures: `:` validation and symlink privileges).
   - **HTTP routes:** real FastAPI handlers accept single-segment partition 
keys such as `tenant-A` and map the existing `__none__` sentinel to `None`. An 
empty key cannot be represented as a path segment, and a key containing `/` is 
decoded before route matching; both return HTTP 404 through the UI route. 
Direct `LocalBackend`/`LocalTrackingClient` calls do support these values 
because the key is hashed before it becomes a directory name. This is a 
pre-existing single-segment routing limitation; `burr/tracking/server/run.py` 
is not changed here. See the follow-up issue draft below.
   - Backend error policy: **404** means no data exists for the requested 
identifiers; **400** means data exists but cannot be attributed to them 
(metadata mismatch, missing partition, ambiguity, invalid path).
   
   ## Error semantics
   
   | Condition | Status |
   |---|---|
   | App/partition does not exist | 404 |
   | Legacy metadata says another partition, or no partition | 400 |
   | Nested metadata does not confirm its partition | 400 |
   | `partition_key=None` when only partitioned data exists | 400 |
   | Path/identifier validation failure | 400 |
   
   ## Tests
   
   - 18 partition-isolation tests pass on Python 3.10.22, 3.11.18, 3.12.14, 
3.13.1.
   - `tests/tracking`: 37 passed, 1 skipped standalone; 90 passed, 1 skipped 
with #946; with #948, 90 passed with only the 13 baseline failures.
   - `tests/core/test_application.py`: 184 passed; tracking+persistence: 86 
passed, 1 skipped.
   - ASF headers: 15 passed. black / isort / flake8: clean.
   - Real upgrade flow verifies legacy S1 → patched S2 → patched S3, unchanged 
legacy log hash, isolated nested log, correct UI steps, explicit refusal for 
other partitions, and the stale-read behaviour of old readers.
   - Real HTTP `TestClient` checks distinguish direct backend support from 
single-segment route limitations.
   
   ## Follow-up issue draft (not part of this PR)
   
   **Title:** `UI routes cannot address empty or separator-containing partition 
keys`
   
   **Body:** `LocalTrackingClient` and `LocalBackend` accept any string as 
`partition_key` (hashed into a safe directory name), but the FastAPI routes in 
`burr/tracking/server/run.py` declare `partition_key` as a single path segment. 
An empty key produces no route match, and a key containing `/` is decoded 
before routing and fails to match. `tenant-A` and the existing `__none__` 
sentinel work. Proposed fix: add an optional query-parameter form (for example 
`?partition_key=`) to the app-detail and app-list endpoints, keeping the 
existing path routes for compatibility, then update the frontend caller. No 
storage-layout change is required.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

  • [PR] fix(tracking): isolate loca... xihaian251 (via GitHub) via notifications

Reply via email to