-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Internal] Change Feed: Adds change feed retention policy to containe…
…r configuration (#2020) Adding internal APIs for retention policy
- Loading branch information
Showing
7 changed files
with
244 additions
and
2 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
Microsoft.Azure.Cosmos/src/Fluent/Settings/ChangeFeedPolicyDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//------------------------------------------------------------ | ||
|
||
namespace Microsoft.Azure.Cosmos.Fluent | ||
{ | ||
using System; | ||
|
||
/// <summary> | ||
/// <see cref="ChangeFeedPolicy"/> fluent definition. | ||
/// </summary> | ||
internal class ChangeFeedPolicyDefinition | ||
{ | ||
private readonly ContainerBuilder parent; | ||
private readonly Action<ChangeFeedPolicy> attachCallback; | ||
private TimeSpan changeFeedPolicyRetention; | ||
|
||
internal ChangeFeedPolicyDefinition( | ||
ContainerBuilder parent, | ||
TimeSpan retention, | ||
Action<ChangeFeedPolicy> attachCallback) | ||
{ | ||
this.parent = parent ?? throw new ArgumentNullException(nameof(parent)); | ||
this.attachCallback = attachCallback ?? throw new ArgumentNullException(nameof(attachCallback)); | ||
this.changeFeedPolicyRetention = retention; | ||
} | ||
|
||
/// <summary> | ||
/// Applies the current definition to the parent. | ||
/// </summary> | ||
/// <returns>An instance of the parent.</returns> | ||
public ContainerBuilder Attach() | ||
{ | ||
ChangeFeedPolicy resolutionPolicy = new ChangeFeedPolicy | ||
{ | ||
FullFidelityRetention = this.changeFeedPolicyRetention | ||
}; | ||
|
||
this.attachCallback(resolutionPolicy); | ||
return this.parent; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
Microsoft.Azure.Cosmos/src/Resource/Settings/ChangeFeedPolicy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//------------------------------------------------------------ | ||
|
||
namespace Microsoft.Azure.Cosmos | ||
{ | ||
using System; | ||
using Microsoft.Azure.Documents; | ||
using Newtonsoft.Json; | ||
|
||
/// <summary> | ||
/// Represents the change feed policy configuration for a container in the Azure Cosmos DB service. | ||
/// </summary> | ||
/// <example> | ||
/// The example below creates a new container with a custom change feed policy. | ||
/// <code language="c#"> | ||
/// <![CDATA[ | ||
/// ContainerProperties containerProperties = new ContainerProperties("MyCollection", "/country"); | ||
/// containerProperties.ChangeFeedPolicy.RetentionDuration = TimeSpan.FromMinutes(5); | ||
/// | ||
/// CosmosContainerResponse containerCreateResponse = await client.GetDatabase("dbName").CreateContainerAsync(containerProperties, 5000); | ||
/// ContainerProperties createdContainerProperties = containerCreateResponse.Container; | ||
/// ]]> | ||
/// </code> | ||
/// </example> | ||
/// <seealso cref="ContainerProperties"/> | ||
internal sealed class ChangeFeedPolicy | ||
{ | ||
[JsonProperty(PropertyName = Constants.Properties.LogRetentionDuration)] | ||
private int retentionDurationInMinutes = 0; | ||
|
||
/// <summary> | ||
/// Gets or sets a value that indicates for how long operation logs have to be retained. | ||
/// </summary> | ||
/// <remarks> | ||
/// Minimum granularity supported is minutes. | ||
/// </remarks> | ||
/// <value> | ||
/// Value is in TimeSpan. | ||
/// </value> | ||
[JsonIgnore] | ||
public TimeSpan FullFidelityRetention | ||
{ | ||
get => TimeSpan.FromMinutes(this.retentionDurationInMinutes); | ||
set | ||
{ | ||
if (value.Seconds > 0 | ||
|| value.Milliseconds > 0) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(this.FullFidelityRetention), "Retention's granularity is minutes."); | ||
} | ||
|
||
if (value.TotalMilliseconds < 0) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(this.FullFidelityRetention), "Retention cannot be negative."); | ||
} | ||
|
||
this.retentionDurationInMinutes = (int)value.TotalMinutes; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Disables the retention log. | ||
/// </summary> | ||
public static TimeSpan FullFidelityNoRetention => TimeSpan.Zero; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters