Skip to content

feature: add ngx.shared.DICT.flush_expired_tail for opportunistic cleanup - #2535

Open
AlinsRan wants to merge 2 commits into
openresty:masterfrom
AlinsRan:feat/shdict-flush-expired-tail
Open

AlinsRan wants to merge 2 commits into
openresty:masterfrom
AlinsRan:feat/shdict-flush-expired-tail

Conversation

@AlinsRan

@AlinsRan AlinsRan commented Oct 21, 2026 •

Copy link
Copy Markdown

flush_expired(max_count) can scan the entire shared dictionary while holding its mutex when expired entries are sparse. Its release limit does not limit the number of entries inspected.

Add ngx.shared.DICT:flush_expired_tail(max_count) for opportunistic cleanup starting at the least recently used end of the LRU queue. It skips entries without an expiration and stops at the first entry with an expiration time in the future, the required positive integer release limit, or the end of the queue. It reuses the existing reclamation code, including list-member cleanup, and leaves flush_expired() semantics unchanged.

The API does not guarantee eventual reclamation of expired entries behind an entry with an expiration time in the future. The limit bounds freed entries, not inspected entries or elapsed time: skipping non-expiring entries can still require a full scan, and freeing a list releases all its members under the dictionary lock. These limits and the need for a separate cleanup mechanism when eventual reclamation is required are documented.

Validation:

  • Built the modified module against nginx 1.29.2 from OpenResty 1.29.2.4 with debug assertions, using matching upstream lua-resty-core (873d072635fd408d81a0abd4187392f3f128ceb9).
  • Passed 473 assertions across t/195-shdict-flush-expired-tail.t, t/043-shdict.t, t/145-shdict-list.t, and t/144-shdict-incr-init.t.
  • New cases cover empty dictionaries, limits and continuation, skipping permanent entries, stopping at live expiring entries, LRU access order, renewal before cleanup, expired list reclamation, invalid limits, and compatibility with the existing flush API.
  • git diff --check passes. No production latency improvement is claimed from these functional tests.

I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.

@AlinsRan AlinsRan changed the title feature: add ngx.shared.DICT.flush_expired_tail for bounded tail cleanup feature: add ngx.shared.DICT.flush_expired_tail for opportunistic cleanup Oct 21, 2026
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.

1 participant