mirror of
https://github.com/redis/redis.git
synced 2026-02-03 20:39:54 -05:00
This PR introduces a mechanism that allows a module to temporarily
disable trimming after an ASM migration operation so it can safely
finish ongoing asynchronous jobs that depend on keys in migrating (and
about to be trimmed) slots.
1. **ClusterDisableTrim/ClusterEnableTrim**
We introduce `ClusterDisableTrim/ClusterEnableTrim` Module APIs to allow
module to disable/enable slot migration
```
/* Disable automatic slot trimming. */
int RM_ClusterDisableTrim(RedisModuleCtx *ctx)
/* Enable automatic slot trimming */
int RM_ClusterEnableTrim(RedisModuleCtx *ctx)
```
**Please notice**: Redis will not start any subsequent import or migrate
ASM operations while slot trimming is disabled, so modules must
re-enable trimming immediately after completing their pending work.
The only valid and meaningful time for a module to disable trimming
appears to be after the MIGRATE_COMPLETED event.
2. **REDISMODULE_OPEN_KEY_ACCESS_TRIMMED**
Added REDISMODULE_OPEN_KEY_ACCESS_TRIMMED to RM_OpenKey() so that module
can operate with these keys in the unowned slots after trim is paused.
And now we don't delete the key if it is in trim job when we access it.
And `expireIfNeeded` returns `KEY_VALID` if
`EXPIRE_ALLOW_ACCESS_TRIMMED` is set, otherwise, returns `KEY_TRIMMED`
without deleting key.
3. **REDISMODULE_CTX_FLAGS_TRIM_IN_PROGRESS**
We also extend RM_GetContextFlags() to include a flag
REDISMODULE_CTX_FLAGS_TRIM_IN_PROGRESS indicating whether a trimming job
is pending (due to trim pause) or in progress. Modules could
periodically poll this flag to synchronize their internal state, e.g.,
if a trim job was delayed or if the module incorrectly assumed trimming
was still active.
Bugfix: RM_SetClusterFlags could not clear a flag after enabling it first.
---------
Co-authored-by: Ozan Tezcan <ozantezcan@gmail.com>
|
||
|---|---|---|
| .. | ||
| aclcheck.c | ||
| atomicslotmigration.c | ||
| auth.c | ||
| basics.c | ||
| blockedclient.c | ||
| blockonbackground.c | ||
| blockonkeys.c | ||
| cmdintrospection.c | ||
| commandfilter.c | ||
| configaccess.c | ||
| crash.c | ||
| datatype.c | ||
| datatype2.c | ||
| defragtest.c | ||
| eventloop.c | ||
| fork.c | ||
| getchannels.c | ||
| getkeys.c | ||
| hash.c | ||
| hooks.c | ||
| infotest.c | ||
| internalsecret.c | ||
| keyspace_events.c | ||
| keyspecs.c | ||
| list.c | ||
| Makefile | ||
| mallocsize.c | ||
| misc.c | ||
| moduleauthtwo.c | ||
| moduleconfigs.c | ||
| moduleconfigstwo.c | ||
| postnotifications.c | ||
| propagate.c | ||
| publish.c | ||
| rdbloadsave.c | ||
| reply.c | ||
| scan.c | ||
| stream.c | ||
| subcommands.c | ||
| test_lazyfree.c | ||
| testrdb.c | ||
| timer.c | ||
| usercall.c | ||
| zset.c | ||