Skip to content

Add new OBJ_GCRA type#14905

Merged
minchopaskal merged 22 commits into
redis:unstablefrom
minchopaskal:new-dt-for-gcra
Apr 15, 2026
Merged

Add new OBJ_GCRA type#14905
minchopaskal merged 22 commits into
redis:unstablefrom
minchopaskal:new-dt-for-gcra

Conversation

@minchopaskal

@minchopaskal minchopaskal commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator

PR introduced a new rate limiting command which stores its internal implementation-detail data into a string key.

Since this will prevent a client from detecting type errors or accidental overwrites or value invalidations, f.e via SET or INCR this PR introduces a new data type - OBJ_GCRA specifically created for that new command.

OBJ_GCRA name subject to change.


Note

High Risk
Adds a new core object type with new RDB encoding and AOF/replication rewrite behavior, which can impact persistence compatibility and data consistency if mishandled. Touches multiple critical subsystems (object lifecycle, copy/defrag, modules, keyspace notifications, command table).

Overview
Introduces a dedicated OBJ_GCRA value type for the GCRA rate-limiting command, replacing the previous string-backed storage so type errors/overwrites are detectable and handled consistently.

Adds full core support for the new type across persistence and runtime internals: RDB save/load via new RDB_TYPE_GCRA, AOF rewrite support, dataset copy/dup, memory sizing, defrag, and DEBUG DIGEST handling. Replication/AOF propagation for GCRA is changed to rewrite into a new internal command GCRASETVALUE, which also gets command-table/JSON docs, its own ACL category/group (rate_limit), and new keyspace notification class r (NOTIFY_RATE_LIMIT).

Updates tests to cover RDB reload, DUMP/RESTORE, AOF rewrite, digest stability, and replication behavior for GCRA keys.

Reviewed by Cursor Bugbot for commit 17b1f70. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread src/commands/gcrarecord.json Outdated
Comment thread src/commands/gcrasetvalue.json
@minchopaskal minchopaskal requested review from oranagra and sundb March 20, 2026 14:54
@minchopaskal

Copy link
Copy Markdown
Collaborator Author

@sundb we had talked with @oranagra about this and generally agreed that a new data type sounds reasonable, instead of abusing a string object. That said the amount of new code for that specific use case seems an overkill to me.

Another thing that came up while writing it - if we feel very strongly that a new type should be introduced - maybe it could be more generic one. GCRA stores a unix timestamp (in this case in microseconds). The new data type could be OBJ_TIMESTAMP or something like this. Not sure how useful would that be though.

WDYT?

@sundb

sundb commented Mar 21, 2026

Copy link
Copy Markdown
Collaborator

Another thing that came up while writing it - if we feel very strongly that a new type should be introduced - maybe it could be more generic one. GCRA stores a unix timestamp (in this case in microseconds). The new data type could be OBJ_TIMESTAMP or something like this. Not sure how useful would that be though.

I think long long * is sufficient. OBJ_TIMESTAMP is theoretically impossible to be used elsewhere in the future.
I didn't see you modify the GCRA command accordingly. Is it not done yet?

@oranagra oranagra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i skimmed over the file (except for gcra.c and gcra.tcl).
is is a lot of changes, and maybe we can find a way to make some of them in a way that the next time we add a simple type we'll have a little less (few of them may be more generic?).

anyway, despite being a lot of changes, if we do want WRONGTYPE error when people mix keys, then it is what it is.. there's no way around it.

Comment thread src/commands/gcrarecord.json Outdated
Comment thread src/object.c
Comment thread src/commands/gcrarecord.json Outdated
Comment thread src/rdb.h Outdated
@YaacovHazan

Copy link
Copy Markdown
Collaborator

@minchopaskal, as Oran wrote, let's try to see if we can make some of the changes more generic.
In any case, we should document all the required changes for adding a new data type in one place.

@minchopaskal

Copy link
Copy Markdown
Collaborator Author

Another thing that came up while writing it - if we feel very strongly that a new type should be introduced - maybe it could be more generic one. GCRA stores a unix timestamp (in this case in microseconds). The new data type could be OBJ_TIMESTAMP or something like this. Not sure how useful would that be though.

I think long long * is sufficient. OBJ_TIMESTAMP is theoretically impossible to be used elsewhere in the future. I didn't see you modify the GCRA command accordingly. Is it not done yet?

It is modified with the new type already.

Comment thread src/object.c
Comment thread src/object.c
Comment thread src/object.c Outdated
@minchopaskal minchopaskal marked this pull request as ready for review March 30, 2026 08:49
@augmentcode

augmentcode Bot commented Mar 30, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: Introduces a dedicated Redis object type (OBJ_GCRA) to store the GCRA rate-limiter’s internal TAT state, avoiding accidental overwrites and enabling proper type errors.

Changes:

  • Adds OBJ_GCRA plus a new encoding (OBJ_ENCODING_PTRINT) for 32-bit builds.
  • Updates the GCRA command to store/read the new object type and changes its keyspace notification event.
  • Adds an internal GCRASETTAT command used for replication/AOF rewrite to record TAT deterministically.
  • Implements persistence support: RDB save/load (RDB_TYPE_GCRA) and AOF rewrite serialization.
  • Extends core subsystems to understand the new type (copy, digest/debug, defrag, modules keytype, memory introspection).
  • Adds unit tests covering RDB reload, DUMP/RESTORE, AOF rewrite, replication behavior, and DEBUG DIGEST stability.

Technical notes: Uses pointer-int storage on 64-bit (OBJ_ENCODING_INT) and heap allocation on 32-bit (OBJ_ENCODING_PTRINT) to safely represent microsecond timestamps.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 5 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/server.h
Comment thread src/object.h Outdated
Comment thread src/rdb.c
Comment thread src/gcra.c
Comment thread src/object.c Outdated
Comment thread src/server.h
Comment thread src/rdb.c
Comment thread src/rdb.c Outdated
Comment thread src/debug.c Outdated
Comment thread src/object.h Outdated
Comment thread src/gcra.c

@oranagra oranagra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some random comments.

Comment thread src/commands/gcrasettat.json Outdated
Comment thread src/gcra.c Outdated
Comment thread src/gcra.c Outdated
Comment thread src/gcra.c
Comment thread src/gcra.c Outdated
Comment thread src/object.c
Comment thread src/object.c Outdated
Comment thread src/redismodule.h
Comment thread src/object.c
Comment thread src/debug.c Outdated
Comment thread src/debug.c Outdated
Comment thread src/debug.c Outdated
Comment thread src/defrag.c
Comment thread src/rdb.c Outdated
Comment thread src/redismodule.h
Comment thread src/notify.c
minchopaskal and others added 2 commits April 9, 2026 11:18
Co-authored-by: debing.sun <[email protected]>
Co-authored-by: debing.sun <[email protected]>
Comment thread src/object.c Outdated
Comment thread src/rdb.c Outdated
Comment thread src/debug.c Outdated
Comment thread src/debug.c
Comment thread src/gcra.c
Comment thread src/gcra.c Outdated
@sundb sundb added release-notes indication that this issue needs to be mentioned in the release notes state:needs-doc-pr requires a PR to redis-doc repository labels Apr 15, 2026
@sundb sundb added this to Redis 8.8 Apr 15, 2026
@sundb

sundb commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator

i don't see GCRASETVALUE was mentioned in the top comment, pls udpate the top comment, and check if anything missed.
like new notification type, new rdb type.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 17b1f70. Configure here.

Comment thread src/debug.c
Comment thread src/gcra.c
@minchopaskal minchopaskal merged commit 3bcfbbe into redis:unstable Apr 15, 2026
19 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Redis 8.8 Apr 15, 2026
@ShooterIT

Copy link
Copy Markdown
Member

#define NOTIFY_RATE_LIMIT (1<<18) /* r, notify rate limit event (Note: excluded from NOTIFY_ALL)*/

Hi @minchopaskal why do we exclude RATE_LIMIT from NOTIFY_ALL, it is related to normal data type OBJ_GCRA.

@minchopaskal

Copy link
Copy Markdown
Collaborator Author

@ShooterIT

#define NOTIFY_RATE_LIMIT (1<<18) /* r, notify rate limit event (Note: excluded from NOTIFY_ALL)*/

Hi @minchopaskal why do we exclude RATE_LIMIT from NOTIFY_ALL, it is related to normal data type OBJ_GCRA.

backwards compatibility? I rmbr I did the same for OVERWRITTEN/TYPE_CHANGED KSN, i.e if you upgrade redis you dont get some unexpected new notification type. But TBH I didn't give it much thought.
@sundb WDYT?

@sundb

sundb commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator

backwards compatibility? I rmbr I did the same for OVERWRITTEN/TYPE_CHANGED KSN, i.e if you upgrade redis you dont get some unexpected new notification type. But TBH I didn't give it much thought. @sundb WDYT?

I don't know the exact reason either, but I think you're right about that.

@oranagra

oranagra commented Apr 21, 2026

Copy link
Copy Markdown
Member

backwards compatibility? I rmbr I did the same for OVERWRITTEN/TYPE_CHANGED KSN, i.e if you upgrade redis you dont get some unexpected new notification type. But TBH I didn't give it much thought. @sundb WDYT?

i think that for KEYMISS, CHANGED, OVERWRITTEN it's a different story, because adding these notifications will affect users after upgrade even if they didn't change the app code.
but in case of CGRA, nothing will happen as long as it's unused.
so same as we added stream type in redis 5, we can add rate limit in 8.8

@minchopaskal

Copy link
Copy Markdown
Collaborator Author

Ok makes sense. I reasoned you may upgrade to newer redis version but still not expect the new KSN. @oranagra so we add GCRA to NOTIFY_ALL?

@oranagra

Copy link
Copy Markdown
Member

IMHO yes.
the new KSN won't be present for existing applications.

minchopaskal added a commit that referenced this pull request May 14, 2026
After introducing GCRA algorithm into redis
#14826 and subsequent introduction of
new RATE_LIMIT object type - #14905.
It was internally decided not to introduce GCRA into the new release.

As still no decision is made on whether it will be kept or not in the
future, this PR only makes the code related to GCRA dead - commands are
inaccessible and AOF/RDB load+save is disabled.

---------

Co-authored-by: debing.sun <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes indication that this issue needs to be mentioned in the release notes state:needs-doc-pr requires a PR to redis-doc repository

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants