fix(repository): reduce scheduler cache LastUsedAt write amplification#1735
Open
atoz03 wants to merge 2 commits intoWei-Shaw:mainfrom
Open
fix(repository): reduce scheduler cache LastUsedAt write amplification#1735atoz03 wants to merge 2 commits intoWei-Shaw:mainfrom
atoz03 wants to merge 2 commits intoWei-Shaw:mainfrom
Conversation
Split LastUsedAt into a dedicated Redis side key (sched:acc:last_used:<id>) to avoid rewriting full account JSON on every hot-path touch. What changed: - Update UpdateLastUsed to write only the side key instead of MGET/decode/re-marshal/full SET. - Merge side-key value back into accounts in GetAccount and GetSnapshot. - Keep side key in sync in SetAccount/SetSnapshot and remove it in DeleteAccount. - Add integration coverage proving account JSON payload remains unchanged while LastUsedAt updates still take effect.
Move ptrTime out of production scheduler cache code into integration test scope where it is actually used. This keeps issue-1723 behavior unchanged while eliminating the CI lint failure: func ptrTime is unused. Validation performed: - golangci-lint v2.9.0 run ./internal/repository/... -> 0 issues - go test ./internal/repository -count=1 -> ok
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联问题
背景
scheduler_cache.UpdateLastUsed在热路径会反序列化并重写整块账号 JSON(sched:acc:*和sched:meta:*),导致明显写放大。变更内容
LastUsedAt拆为独立 side key:sched:acc:last_used:<id>。UpdateLastUsed仅更新 side key,不再重写账号/元数据 JSON。GetAccount读取主账号后,用 side key 覆盖LastUsedAt。GetSnapshot读取 metadata 后,用 side key 覆盖LastUsedAt。SetAccount/SetSnapshot(经writeAccounts)同步 side key。DeleteAccount同时删除 side key。ptrTimehelper 下沉到idempotency_repo_integration_test.go,避免生产代码unused。验证
cd backend && go test ./internal/repository -count=1cd backend && golangci-lint run ./internal/repository/...cd backend && go test -tags=integration ./internal/repository -run "TestSchedulerCacheSnapshotUsesSlimMetadataButKeepsFullAccount|TestSchedulerCacheUpdateLastUsedUsesSideKeyAndKeepsAccountJSON" -count=1上述命令本地已通过。