You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defrag: give the module global defrag cursor a server-managed lifetime
The global defrag cursor was an unsigned long living in the module structure with no
lifetime of its own. The per-key cursor does not need one, because it is bracketed by a
single key and moduleLateDefrag() resets it when the callback reports completion. The
global callback has no such bracketing, so a position saved mid-pass could be handed back
after the state it described had been rebuilt.
Make it a core-owned object instead. moduleDefragCursor is allocated when the server first
visits a module in a cycle and freed when the pass completes, when the cycle terminates
abnormally, or when the module is unloaded. Freeing it is what makes a stale resume
impossible: a cursor of 0 now unambiguously means a fresh pass.
The module-visible API is unchanged. The defrag context points at the position inside the
cursor, so VM_DefragCursorSet()/VM_DefragCursorGet() work exactly as before and
valkeymodule.h is untouched - no new calls, no altered signatures, nothing for an existing
module to adapt to. Naming follows the internal convention (moduleType, moduleValue)
rather than the ValkeyModule* prefix reserved for API types.
Making it a type rather than a bare value is what allows further per-pass state to be added
later without changing any signature.
Adds a test for unloading a module while a pass is outstanding.
Signed-off-by: AkshaThakkar1812 <akshathakkar@gmail.com>
0 commit comments