Skip to content

Commit 950eaab

Browse files
Max segment size (#110)
* add MaxSegmentSizeBytes configuration when creating a stream. * add MaxSegmentSizeBytes and MaxLengthBytes in stream creation test. * add documentation max segment size
1 parent 9800fc9 commit 950eaab

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ await system.CreateStream(new StreamSpec(stream)
197197

198198
Set a policy is highly recommended.
199199

200+
RabbitMQ does not store the whole stream in a single file, but splits it in segment files.
201+
This is also used for truncate the stream: when a stream reaches his maximum size, an entire segment file is deleted. For this reason `MaxLengthBytes` (the max dimension of the entire stream) is usually significantly higher than `MaxSegmentSizeBytes` (the max dimension of a single segment file).
202+
RabbitMQ enforces the retention policy when the current segment has reached its maximum size and is closed in favor of a new one.
203+
204+
```csharp
205+
await system.CreateStream(new StreamSpec(stream)
206+
{
207+
MaxLengthBytes = 20_000,
208+
MaxSegmentSizeBytes = 1000
209+
});
210+
```
211+
200212
### Producer
201213

202214
A Producer instance is created from the `System`.

RabbitMQ.Stream.Client/StreamSpec.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public LeaderLocator LeaderLocator
2828
{
2929
set => Args["queue-leader-locator"] = $"{value.ToString()}";
3030
}
31+
public int MaxSegmentSizeBytes
32+
{
33+
set => Args["stream-max-segment-size-bytes"] = $"{value}";
34+
}
3135

3236
public IDictionary<string, string> Args => args;
3337
}

Tests/ApiApproval.Approve.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ namespace RabbitMQ.Stream.Client
861861
public RabbitMQ.Stream.Client.LeaderLocator LeaderLocator { set; }
862862
public System.TimeSpan MaxAge { set; }
863863
public int MaxLengthBytes { set; }
864+
public int MaxSegmentSizeBytes { set; }
864865
public string Name { get; set; }
865866
public virtual RabbitMQ.Stream.Client.StreamSpec <Clone>$() { }
866867
public void Deconstruct(out string Name) { }

Tests/SystemTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,17 @@ public async void Create_Delete_Stream()
8080
var stream = Guid.NewGuid().ToString();
8181
var config = new StreamSystemConfig();
8282
var system = await StreamSystem.Create(config);
83-
var spec = new StreamSpec(stream) { MaxAge = TimeSpan.FromHours(8), LeaderLocator = LeaderLocator.Random };
83+
var spec = new StreamSpec(stream)
84+
{
85+
MaxAge = TimeSpan.FromHours(8),
86+
LeaderLocator = LeaderLocator.Random,
87+
MaxLengthBytes = 20_000,
88+
MaxSegmentSizeBytes = 1000
89+
};
8490
Assert.Equal("28800s", spec.Args["max-age"]);
8591
Assert.Equal("random", spec.Args["queue-leader-locator"]);
92+
Assert.Equal("1000", spec.Args["stream-max-segment-size-bytes"]);
93+
Assert.Equal("20000", spec.Args["max-length-bytes"]);
8694
await system.CreateStream(spec);
8795
await system.DeleteStream(stream);
8896
await system.Close();

0 commit comments

Comments
 (0)