From 9d8972370aca0dffaf1cd4b78bc70986172e8e83 Mon Sep 17 00:00:00 2001 From: mtmk Date: Wed, 9 Oct 2024 13:47:00 +0100 Subject: [PATCH] Add placement configuration to key-value and object store (#650) * Add placement configuration to key-value store * Add placement configuration to object store --- src/NATS.Client.KeyValueStore/NatsKVConfig.cs | 5 +++++ src/NATS.Client.KeyValueStore/NatsKVContext.cs | 1 + src/NATS.Client.ObjectStore/NatsObjConfig.cs | 7 +++++++ src/NATS.Client.ObjectStore/NatsObjContext.cs | 2 +- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/NATS.Client.KeyValueStore/NatsKVConfig.cs b/src/NATS.Client.KeyValueStore/NatsKVConfig.cs index 3ff86e67d..ac4432819 100644 --- a/src/NATS.Client.KeyValueStore/NatsKVConfig.cs +++ b/src/NATS.Client.KeyValueStore/NatsKVConfig.cs @@ -58,6 +58,11 @@ public record NatsKVConfig /// public NatsKVRepublish? Republish { get; init; } + /// + /// Placement requirements for a key-value store stream. + /// + public Placement? Placement { get; init; } + /// /// Use compressed storage. /// diff --git a/src/NATS.Client.KeyValueStore/NatsKVContext.cs b/src/NATS.Client.KeyValueStore/NatsKVContext.cs index 501a261aa..9cbbdbc6b 100644 --- a/src/NATS.Client.KeyValueStore/NatsKVContext.cs +++ b/src/NATS.Client.KeyValueStore/NatsKVContext.cs @@ -223,6 +223,7 @@ private static StreamConfig CreateStreamConfig(NatsKVConfig config) Compression = config.Compression ? StreamConfigCompression.S2 : StreamConfigCompression.None, Storage = storage, Republish = republish!, + Placement = config.Placement, AllowRollupHdrs = true, DenyDelete = true, DenyPurge = false, diff --git a/src/NATS.Client.ObjectStore/NatsObjConfig.cs b/src/NATS.Client.ObjectStore/NatsObjConfig.cs index 9df981fbb..bef5d7d03 100644 --- a/src/NATS.Client.ObjectStore/NatsObjConfig.cs +++ b/src/NATS.Client.ObjectStore/NatsObjConfig.cs @@ -1,3 +1,5 @@ +using NATS.Client.JetStream.Models; + namespace NATS.Client.ObjectStore; /// @@ -40,6 +42,11 @@ public record NatsObjConfig(string Bucket) /// public int NumberOfReplicas { get; init; } = 1; + /// + /// Placement requirements for a object store stream. + /// + public Placement? Placement { get; init; } + /// /// Additional metadata for the bucket. /// diff --git a/src/NATS.Client.ObjectStore/NatsObjContext.cs b/src/NATS.Client.ObjectStore/NatsObjContext.cs index 969239e17..61c23a8f3 100644 --- a/src/NATS.Client.ObjectStore/NatsObjContext.cs +++ b/src/NATS.Client.ObjectStore/NatsObjContext.cs @@ -43,7 +43,7 @@ public async ValueTask CreateObjectStoreAsync(NatsObjConfig confi MaxBytes = config.MaxBytes ?? -1, Storage = storage, NumReplicas = config.NumberOfReplicas, - /* TODO: Placement = */ + Placement = config.Placement, Discard = StreamConfigDiscard.New, AllowRollupHdrs = true, AllowDirect = true,