Skip to content

Conversation

@beautifulentropy
Copy link
Member

Fixes #8305

@beautifulentropy beautifulentropy force-pushed the make-resets-take-transactions branch from c9297b0 to f4ec6cd Compare November 21, 2025 17:40
@beautifulentropy beautifulentropy changed the title ratelimits: Refactor Reset() to accept Transactions ratelimits: Refactor Reset() to accept a batch of Transactions Nov 21, 2025
@beautifulentropy beautifulentropy marked this pull request as ready for review November 21, 2025 17:47
@beautifulentropy beautifulentropy requested a review from a team as a code owner November 21, 2025 17:47
@beautifulentropy beautifulentropy marked this pull request as draft November 21, 2025 18:08
@beautifulentropy beautifulentropy marked this pull request as ready for review November 21, 2025 18:49
@beautifulentropy
Copy link
Member Author

I am satisfied that all keys will be deleted even if some are missing. Ring.Del(ctx, keys...) builds one DEL per shard, grouping keys by hash slot. Each shard runs a DEL with only its keys. Non-existent keys are ignored, per Redis docs.

@jprenken jprenken requested a review from aarongable November 21, 2025 22:58
func (r *RedisSource) Delete(ctx context.Context, bucketKey string) error {
// BatchDelete deletes the TATs at the specified bucketKeys ('name:id'). A nil
// return value does not indicate that the bucketKeys existed.
func (r *RedisSource) BatchDelete(ctx context.Context, bucketKeys []string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't BatchDelete and Delete just be a single function with variadic args?

func (r *RedisSource) Delete(ctx context.Context, bucketKeys ...string) error {

}, newTestTransactionBuilder(t), clk, randIP.String()
}

func mustReset(t *testing.T, l *Limiter, ctx context.Context, limit *Limit, bucketKey string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a nit, but: I think we tend to use must to mean "will panic if a precondition fails", rather than "will fail a test assertion". I don't think I see any other mustFoo functions in the codebase that take a testing.T as an argument; meanwhile we do have mustFoo test functions that use our must.Do helper.

Maybe this is totally fine? I think the meaning and usage is mostly clear. But it just blurs the line between this helper being a test function that readers need to care about, versus it being boilerplate that we're clearly stating can never fail.

// - allow-only: when neither check nor spend are true, the transaction will
// be considered "allowed" regardless of the bucket's capacity. This is
// useful for limits that are disabled.
// - reset: when reset is true, the bucket will be reset to full capacity.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: name this "reset-only", and put it above "allow-only".

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.

ratelimits: Make ratelimits.NewRegIdIdentValueBucketKey private

4 participants