Repository navigation
fix(store): replay deletes under the importing app's id, skip other scopes' policies, and forget cached rows a move wrote - #2227
Conversation
a4c08a5 to
57561a9
Compare
57561a9 to
3fdc202
Compare
kanat
left a comment
There was a problem hiding this comment.
Reviewed 3fdc202 merged onto main ce41c39. I used my own test database and Redis.
Rebase: your importRow resolution matches mine. The stale keys are added right after the insert, before RowsAffected and ErrAnotherCustomersRow. A refused import returns before ImportRow forgets anything, and in ApplyChanges it rolls the transaction back, so nothing is forgotten.
Tests: TestDataMoveSuite passes in full, with Redis, on the merged tree. CI is green except integration (api). Its three TestChannelsSuite failures also fail on main at ce41c39 (Integration run 45233683234), so this PR does not cause them.
Mutations: 21 checked, 1 survived (R1.2). Every new rule fails a test when broken except that one: the customer-column skip, the scope filter in SQL and after the limit, appPolicy, both forgets, the old and new keys, the policy and app-policies keys, the id and name keys per table, and UseNumber.
Checked and sound:
- A delete replayed under one app cannot reach another customer's row with the same key. I probed it with two customers holding the same task id and app policies, using a key that names the other customer: only the replaying app's rows go. No table has the customer column as its whole primary key.
- An old source's organization-policy change is skipped on replay.
- No other moved table has a cached read.
- No migration. Nothing changes for an old router.
[Nit] R1.3 The Tests list in the body names TestAConfigImportedWithANumericIDIsServedRightAfterTheImport. The test is TestAConfigImportedWithANumericNameIsServedRightAfterTheImport.
Verdict: request changes, for R1.1. It is a regression on the feed path this PR changes. R1.2 can land as a follow-up.
…copes' policies, and forget cached rows a move wrote
3fdc202 to
daf5e90
Compare
|
R1.1 and R1.2 are fixed in daf5e90 (replied on both threads). R1.3: the Tests list now names |
kanat
left a comment
There was a problem hiding this comment.
Reviewed daf5e90 merged onto main d575e6e, on my own test database and Redis. Verdict: GO (a COMMENT review, not an approval). One follow-up test is listed below.
Prior findings
- R1.1: fixed. A page that is not full now returns the highest seq of the customer's rows at or below the mark, read in the same transaction as the rows.
followtakespage.Cursorwhenever it is past its own, also on an empty page.- My probe from round 1 (your
TestACursorPastAnOrganizationsPolicyLeftOutIsNotExpiredByItsPruning) passes on the head and on main. It failed on 3fdc202. - Mutations, each killed: cursor block off,
< limitto<= limit(TestAFullPageOfChangesResumesAfterItsLastChange), mark bound dropped (four in-flight tests),COALESCEdefault 0,followmoving the cursor only with changes,follownever moving it (TestARunWhosePageCarriesNoChangeStillMovesItsCursor).
- My probe from round 1 (your
- R1.2: fixed. Both tests are in. Under the
was-only-for-configs mutant,TestASkillMovedByAReplayLeavesItsOldConfigandTestAVoiceRenamedByAReplayIsNoLongerServedByItsOldNamefail. The config rename test still passes, as it should. - R1.3: fixed, the PR body names the right test.
New
- [Should fix, follow-up] R2.1 The query that moves the cursor (datamove.go:1836) filters by
customer_id, and no test needs that. With the filter dropped, every PR test still passes, and a follower is handed another customer's global change numbers as its cursor. The head is correct, so this is a test gap and does not block. Test row, checked to fail under that mutant (expected: 43, actual: 44) and pass on the head, forDataMoveSuitenext toTestChangesStopAtTheCustomerAskingForThem:
func (s *DataMoveSuite) TestAPageCursorNeverPassesTheCustomersOwnLastChange() {
s.capture("acme")
s.capture("other")
s.seedAgentConfig(s.source, "acme", "greeter")
_, ownCursor, err := s.source.Changes(s.ctx, "acme", 0, 100)
s.Require().NoError(err)
s.seedAgentConfig(s.source, "other", "not-yours")
_, cursor, err := s.source.Changes(s.ctx, "acme", 0, 100)
s.Require().NoError(err)
s.Equal(ownCursor, cursor)
}- [Nit] R2.2 The PR body's Tests list does not name the five tests added in this push.
Checks
TestDataMoveSuiteand the replicate suites incmd/router: pass. go build, go vet with the integration tag, and gofmt are clean.- An old source answers an empty page with cursor = after, and an old follower ignores the cursor of an empty page, so a mixed pair behaves as before.
- CI on this head: all green when I read it.
kanat
left a comment
There was a problem hiding this comment.
Approving on the reviewer's GO in delta round 2. R1.1 to R1.3 are fixed. R2.1 is a follow-up: no test pins the customer filter in the cursor query, and a ready test row is in the review. R2.2 is a body Nit.
…nge (#2286) **Changes** - None to the product code: this adds a test for the cursor a page of changes returns. **Tests** - `TestAPageCursorNeverPassesTheCustomersOwnLastChange`: with two customers recording changes, a page for one customer returns the same cursor after the other customer's rows are written. It fails when the `customer_id` condition is dropped from the cursor query in `Changes` (cursor 4, want 3). Follow-up to #2227 (Kanat's R2.1) Part of AI-3495
Problem
deleteRowmatched a replayed delete on every primary key column, the customer column included, so forusers,scheduled_tasks,customer_activityand the app'spoliciesa delete replayed under another app id matched nothing. A policy change is recorded under its scope id whatever its scope, so the change feed listed an organization's policy sharing the app's id, and the replay wrote it as the app's.ImportRowandApplyChangesdropped no cached rows, so configs, skills, voices and policies they wrote were served stale until the cache TTL.Fix
deleteRowleaves the customer column out of the key conditions; the destination's customer condition still scopes the delete.Changeslists apolicieschange only when its key's scope isapp, filtered before the limit so a page stays full andcaught_upholds.applyChangesreplays only those too, for changes from a source without the filter.importRowanddeleteRowcollect the cache keys of the row as it reads after and before the write, so a rename drops the old name too. Only a delete from a cached table returns its row.ImportRowforgets the keys after its statement,ApplyChangesafter its transaction commits, using the existing key functions andforget.Changesis left for a separate change.importRow; either merge order needs only a small rebase.Tests
Each failed before its fix, except
TestAnAppsPolicyChangeIsReplayed, which guards the scope filter.TestADeletedTaskIsReplayedUnderTheIDTheAppMovedTo: a delete replayed under another app id removes that task and keeps its sibling.TestChangesCarryNoOrganizationsPolicyOfTheAppsID: the feed leaves the organization's policy out and still fills the page.TestAnOrganizationsPolicyIsNotReplayedOverTheAppsOfTheSameID: an organization's policy change leaves the app's as it was.TestAPolicyChangeNamingNoScopeIsNotReplayed: a change with no scope in its key is not replayed.TestAnAppsPolicyChangeIsReplayed: an app's own policy change still lands.TestAnImportedConfigIsServedRightAfterTheImport: a cached missing config is dropped by an import.TestAConfigImportedWithANumericNameIsServedRightAfterTheImport: the same for an id sent as a number.TestARouterConfigImportedIsServedRightAfterTheImport: the same for a router config.TestAVoiceImportedIsServedRightAfterTheImport: the same for a voice.TestAnImportedPolicyIsServedRightAfterTheImport: the same for an app policy.TestAnImportedPolicyDecidesTheAppsRequestsRightAfterTheImport: the app's merged policies are dropped too.TestAReplayedConfigChangeIsServedRightAfterIt: a replayed update is served at once.TestAReplayedRouterConfigChangeIsServedRightAfterIt: the same for a router config by id.TestAReplayedVoiceChangeIsServedRightAfterIt: the same for a voice by id.TestAReplayedSkillChangeIsServedRightAfterIt: the same for a skill.TestAConfigRenamedByAReplayIsNoLongerServedByItsOldName: a replayed rename drops the old name.TestAConfigDeletedByAReplayIsNoLongerServed: a replayed delete drops the config.TestAPolicyDeletedByAReplayIsNoLongerServed: a replayed delete drops the app's policy.TestACursorPastAnOrganizationsPolicyLeftOutIsNotExpiredByItsPruning: a page that leaves out an organization's policy still moves the cursor past it, so pruning that change does not expire the follower.TestAFullPageOfChangesResumesAfterItsLastChange: a full page ends at its last change and skips nothing.TestARunWhosePageCarriesNoChangeStillMovesItsCursor:followsaves the newer cursor from an empty page.TestASkillMovedByAReplayLeavesItsOldConfig: a skill moved to another config is no longer served from the old one.TestAVoiceRenamedByAReplayIsNoLongerServedByItsOldName: a replayed voice rename drops the old name.Part of AI-3495