Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent KeyValueStore error when MaxAge is set below the default DuplicateWindow value #362

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/NATS.Client.KeyValueStore/NatsKVContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,13 @@ public async ValueTask<INatsKVStore> CreateStoreAsync(NatsKVConfig config, Cance
// MirrorDirect =
// Mirror =
Retention = StreamConfigRetention.Limits, // from ADR-8
DuplicateWindow = TimeSpan.FromMinutes(2), // 120_000_000_000ns, from ADR-8
DuplicateWindow = config.MaxAge != default ? config.MaxAge : TimeSpan.FromMinutes(2), // 120_000_000_000ns, from ADR-8
rickdotnet marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

my fault didn't check setting duplicate-window to max-age here should've been removed

- DuplicateWindow = config.MaxAge != default ? config.MaxAge : TimeSpan.FromMinutes(2), // 120_000_000_000ns, from ADR-8
+ DuplicateWindow = TimeSpan.FromMinutes(2), // 120_000_000_000ns, from ADR-8

cc @scottf

Background: When setting max age default window is always set equals to max age. e.g. if we set max-age=30 minute default windows should still stay at 2 minutes.

};

// https://github.com/nats-io/nats.go/blob/98430acd80423b776149f29d625d158f490ac3c5/jetstream/kv.go#L334-L342
if (streamConfig.MaxAge > TimeSpan.Zero && streamConfig.MaxAge < streamConfig.DuplicateWindow)
streamConfig.DuplicateWindow = streamConfig.MaxAge;

var stream = await _context.CreateStreamAsync(streamConfig, cancellationToken);

return new NatsKVStore(config.Bucket, _context, stream);
Expand Down
Loading