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

Added DuplicateWindow to NatsKVConfig #440

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 13 additions & 1 deletion src/NATS.Client.KeyValueStore/NatsKVContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ public async ValueTask<INatsKVStore> CreateStoreAsync(NatsKVConfig config, Cance

var replicas = config.NumberOfReplicas > 0 ? config.NumberOfReplicas : 1;

// MIMIC GO CLient
// When stream's MaxAge is not set, server uses 2 minutes as the default
// for the duplicate window. If MaxAge is set, and lower than 2 minutes,
// then the duplicate window will be set to that. If MaxAge is greater,
// we will cap the duplicate window to 2 minutes (to be consistent with
// previous behavior).
var duplicateWindow = TimeSpan.FromMinutes(2); // 120_000_000_000ns, from ADR-8
if (config.MaxAge > TimeSpan.Zero && config.MaxAge < duplicateWindow)
{
duplicateWindow = config.MaxAge;
}

var streamConfig = new StreamConfig
{
Name = BucketToStream(config.Bucket),
Expand All @@ -108,7 +120,7 @@ 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 = duplicateWindow,
};

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