Repository navigation
fix(amber): store anonymous hub views with a NULL uid - #9226
tanishqgandhi1908 wants to merge 4 commits into
Conversation
… with 500 A logged-out viewer sends userId 0, which no user row has, so the user_action insert broke its foreign key after the view count was already incremented. postView now records the view with a NULL uid, and recordUserAction defaults to null instead of 0. Closes apache#9225
Backport auto-label reportThis
|
Automated Reviewer SuggestionsBased on the
|
|
| config | throughput | MB/s | latency | max Δ latest / 7d | |
|---|---|---|---|---|---|
| 🔴 | bs=10 sw=10 sl=64 | 364 | 0.222 | 26,403/42,824/42,824 us | 🔴 +21.8% / 🔴 +212.0% |
| 🔴 | bs=100 sw=10 sl=64 | 822 | 0.502 | 119,338/148,986/148,986 us | 🔴 +8.8% / 🔴 +68.3% |
| ⚪ | bs=1000 sw=10 sl=64 | 975 | 0.595 | 1,022,703/1,079,218/1,079,218 us | ⚪ within ±5% / 🔴 +30.6% |
Baseline details
Latest main b516b2c from same runner
| config | metric | PR | latest main | 7d avg | Δ latest | Δ 7d |
|---|---|---|---|---|---|---|
| bs=10 sw=10 sl=64 | throughput | 364 tuples/sec | 414 tuples/sec | 1,005 tuples/sec | -12.1% | -63.8% |
| bs=10 sw=10 sl=64 | MB/s | 0.222 MB/s | 0.253 MB/s | 0.614 MB/s | -12.3% | -63.8% |
| bs=10 sw=10 sl=64 | p50 | 26,403 us | 22,939 us | 10,325 us | +15.1% | +155.7% |
| bs=10 sw=10 sl=64 | p95 | 42,824 us | 35,168 us | 13,728 us | +21.8% | +212.0% |
| bs=10 sw=10 sl=64 | p99 | 42,824 us | 35,168 us | 16,323 us | +21.8% | +162.3% |
| bs=100 sw=10 sl=64 | throughput | 822 tuples/sec | 886 tuples/sec | 1,347 tuples/sec | -7.2% | -39.0% |
| bs=100 sw=10 sl=64 | MB/s | 0.502 MB/s | 0.541 MB/s | 0.822 MB/s | -7.2% | -39.0% |
| bs=100 sw=10 sl=64 | p50 | 119,338 us | 109,717 us | 80,846 us | +8.8% | +47.6% |
| bs=100 sw=10 sl=64 | p95 | 148,986 us | 141,445 us | 88,523 us | +5.3% | +68.3% |
| bs=100 sw=10 sl=64 | p99 | 148,986 us | 141,445 us | 112,010 us | +5.3% | +33.0% |
| bs=1000 sw=10 sl=64 | throughput | 975 tuples/sec | 988 tuples/sec | 1,394 tuples/sec | -1.3% | -30.0% |
| bs=1000 sw=10 sl=64 | MB/s | 0.595 MB/s | 0.603 MB/s | 0.851 MB/s | -1.3% | -30.0% |
| bs=1000 sw=10 sl=64 | p50 | 1,022,703 us | 1,017,181 us | 787,853 us | +0.5% | +29.8% |
| bs=1000 sw=10 sl=64 | p95 | 1,079,218 us | 1,061,575 us | 826,583 us | +1.7% | +30.6% |
| bs=1000 sw=10 sl=64 | p99 | 1,079,218 us | 1,061,575 us | 872,816 us | +1.7% | +23.6% |
Raw CSV
config_idx,batch_size,schema_width,string_len,num_batches,total_ms,total_tuples,total_bytes,tuples_per_sec,mb_per_sec,lat_p50_us,lat_p95_us,lat_p99_us
0,10,10,64,20,549.29,200,128000,364,0.222,26403.35,42823.78,42823.78
1,100,10,64,20,2433.53,2000,1280000,822,0.502,119338.14,148986.36,148986.36
2,1000,10,64,20,20509.65,20000,12800000,975,0.595,1022702.79,1079217.74,1079217.74
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9226 +/- ##
=========================================
Coverage 91.60% 91.61%
Complexity 5038 5038
=========================================
Files 1283 1283
Lines 57005 57014 +9
Branches 7419 7420 +1
=========================================
+ Hits 52222 52232 +10
+ Misses 2915 2913 -2
- Partials 1868 1869 +1
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Removing release/v1.2: the view count is still recorded. |
bobbai00
left a comment
There was a problem hiding this comment.
🟡 0 must-fix · 3 advisory · 0 polish: the fix is correct and stores anonymous views the way migration 13 does; three optional follow-ups.
Correctness (1)
HubResource.scala:423: count bump and audit insert still commit separately (advisory, see inline)
Simplifications (1)
HubResource.scala:422: null sentinel where anOptionwould do (advisory, see inline)
Conventions (1)
HubResourceSpec.scala:456: title length and scope (advisory, see inline)
Verification trace
Traced every userId the frontend sends to POST /hub/view: the uid decoded from the session token, or 0, from the four postView call sites. Null, 0 and negative values now become a NULL uid, which user_action.uid allows and sql/updates/13.sql already uses for old anonymous rows. Positive uids pass through unchanged. HubResourceSpec runs on MockTexeraDB, which loads sql/texera_ddl.sql, so the uid-0 case hits the real foreign key.
Takes the anonymous viewer as Option[Integer] instead of a null uid, and writes the view count and its user_action row together, so a view that cannot be recorded does not raise the count.
What changes were proposed in this PR?
A logged-out viewer's page sends
POST /api/hub/viewwithuserId: 0.postViewincremented the view count, then inserted auser_actionrow withuid = 0. That breaks the foreign key touser(uid), since no user has uid 0, so the request returned 500 and the view was never recorded, though the count had already gone up.postViewnow records the view with aNULLuid whenuserIdis0or missing.user_action.uidis nullable, and migration13.sqlalready stored the old anonymous views asNULL.recordUserActionnow takesuserId: Option[Integer] = Noneand sets the uid only when one is given, so the default can't hit the same foreign key.postViewbumps the count and inserts theuser_actionrow in one transaction, so a view that can't be recorded (for example, a uid whose account was deleted) no longer raises the count.Before and after, sending the logged-out request (
{"entityId":8,"userId":0,"entityType":"workflow"}) three times:Any related issues, documentation, discussions?
Closes #9225.
How was this PR tested?
New
HubResourceSpectests:userId: 0and one with nouserIdboth return the next count and are recorded with aNULLuid;Each fails without its part of the fix.
HubResourceSpecpasses (75/75), andscalafmtCheckAllandscalafixAll --checkare clean. The before/after table above came from running the requests against a local server.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 5.5)