feat: upgrade JetStreamService to lifecycle orchestrator

Implements enableJetStream() semantics from golang/nats-server/server/jetstream.go:414-523.

- JetStreamService.StartAsync(): validates config, creates store directory
  (including nested paths via Directory.CreateDirectory), registers all
  $JS.API.> subjects, logs startup stats; idempotent on double-start
- JetStreamService.DisposeAsync(): clears registered subjects, marks not running
- New properties: RegisteredApiSubjects, MaxStreams, MaxConsumers, MaxMemory, MaxStore
- JetStreamOptions: adds MaxStreams and MaxConsumers limits (0 = unlimited)
- FileStoreConfig: removes duplicate StoreCipher/StoreCompression enum declarations
  now that AeadEncryptor.cs owns them; updates defaults to NoCipher/NoCompression
- FileStoreOptions/FileStore: align enum member names with AeadEncryptor.cs
  (NoCipher, NoCompression, S2Compression) to fix cross-task naming conflict
- 13 new tests in JetStreamServiceOrchestrationTests covering all lifecycle paths
This commit is contained in:
Joseph Doherty
2026-02-24 06:03:46 -05:00
parent 14019d4c58
commit 2c9683e7aa
9 changed files with 1660 additions and 72 deletions

View File

@@ -1,8 +1,37 @@
namespace NATS.Server.Configuration;
// Maps to Go's JetStreamConfig struct in server/opts.go and server/jetstream.go.
// Controls the lifecycle parameters for the JetStream subsystem.
public sealed class JetStreamOptions
{
/// <summary>
/// Directory where JetStream persists stream data.
/// Maps to Go's JetStreamConfig.StoreDir (jetstream.go:enableJetStream:430).
/// An empty string disables file-backed persistence (memory-only mode).
/// </summary>
public string StoreDir { get; set; } = string.Empty;
/// <summary>
/// Maximum bytes of memory storage across all streams. 0 means unlimited.
/// Maps to Go's JetStreamConfig.MaxMemory (jetstream.go:enableJetStream:471).
/// </summary>
public long MaxMemoryStore { get; set; }
/// <summary>
/// Maximum bytes of file storage across all streams. 0 means unlimited.
/// Maps to Go's JetStreamConfig.MaxStore (jetstream.go:enableJetStream:472).
/// </summary>
public long MaxFileStore { get; set; }
/// <summary>
/// Maximum number of streams allowed. 0 means unlimited.
/// Maps to Go's JetStreamAccountLimits.MaxStreams (jetstream.go).
/// </summary>
public int MaxStreams { get; set; }
/// <summary>
/// Maximum number of consumers allowed across all streams. 0 means unlimited.
/// Maps to Go's JetStreamAccountLimits.MaxConsumers (jetstream.go).
/// </summary>
public int MaxConsumers { get; set; }
}