Skip to content

adapter: fix orphaned list items when DEL + recreate in same Lua script#385

Merged
bootjp merged 3 commits into
feature/reduce-lockfrom
copilot/sub-pr-384
Mar 21, 2026
Merged

adapter: fix orphaned list items when DEL + recreate in same Lua script#385
bootjp merged 3 commits into
feature/reduce-lockfrom
copilot/sub-pr-384

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 21, 2026

When a Lua script deleted a key and then recreated it as a list in the same transaction, the delta commit path (preserveExisting=true) skipped deleteLogicalKeyElems, leaving the original list items orphaned in storage.

Root cause: listCommitPlan always returned preserveExisting=true for non-materialized (delta) lists. But if the key was previously deleted in the same script, listState never loaded the persisted meta (because deleted[key]=true made keyType return redisTypeNone), so the delta path wrote only the new items while the old storage entries were never cleaned up.

-- before fix: [a, b, c] items from original list leaked in storage
redis.call("DEL", KEYS[1])
redis.call("RPUSH", KEYS[1], "d")
-- LRANGE returned ["d"] but [a,b,c] remained as orphaned storage entries

Changes

  • luaScriptContext: add everDeleted map[string]bool field, populated by deleteLogical and never reset (unlike deleted, which is cleared when commands recreate a key).
  • listCommitPlan: when everDeleted[key] is true, force the full-rewrite/materialized path (preserveExisting=false) so deleteLogicalKeyElems runs and cleans up stale storage before writing the new list.
  • TestRedis_LuaDelAndRecreateListNoOrphan: covers the DEL → RPUSH sequence to guard against regression.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Adapter: reduce Lua list lock contention adapter: fix orphaned list items when DEL + recreate in same Lua script Mar 21, 2026
Copilot AI requested a review from bootjp March 21, 2026 09:54
@bootjp bootjp marked this pull request as ready for review March 21, 2026 09:58
@bootjp
Copy link
Copy Markdown
Owner

bootjp commented Mar 21, 2026

@copilot fix golangci-lint

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 21, 2026

@copilot fix golangci-lint

Fixed in commit b4ab53e:

  • gci: fixed missing tab indentation in the test function body of TestRedis_LuaDelAndRecreateListNoOrphan in adapter/redis_lua_compat_test.go
  • mnd: replaced literal 2 in len(args) != 2 (SELECT arity checks) with a named constant selectArgCount = 2 defined in proxy/pubsub.go, used in both proxy/pubsub.go and proxy/proxy.go

Copilot AI requested a review from bootjp March 21, 2026 10:06
@bootjp bootjp merged commit 939e785 into feature/reduce-lock Mar 21, 2026
5 checks passed
@bootjp bootjp deleted the copilot/sub-pr-384 branch March 21, 2026 10:09
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.

2 participants