-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 Change Feed #11692
Merged
seanmcc-msft
merged 36 commits into
Azure:feature/storage/stg73base
from
seanmcc-msft:feature/storage/changeFeed
Jun 3, 2020
Merged
Added Change Feed #11692
Changes from 23 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
34ef0a6
Added Change Feed
seanmcc-msft 821c433
Added Chunk unit tests
seanmcc-msft e1e48b8
Added Shard tests
seanmcc-msft a838204
Added some Segment tests
seanmcc-msft 2e0c2c2
changed service version back to 12-12
seanmcc-msft 460887c
Added another Segment test
seanmcc-msft fb21295
Recorded tests
seanmcc-msft f728c6c
Merge branch 'feature/storage/stg73base' into feature/storage/changeFeed
seanmcc-msft f60dc32
Fixed build
seanmcc-msft 6825791
Merge branch 'feature/storage/stg73base' into feature/storage/changeFeed
seanmcc-msft c629fed
Added factories to Chunk
seanmcc-msft 60fc649
Added factories to Shard
seanmcc-msft 39f5bc2
Most the way through adding Factories to Segment
seanmcc-msft 52be7ed
Finished adding Factories to Segment
seanmcc-msft a1ec00f
Half way through adding Factories to Change Feed
seanmcc-msft 265c1e8
Finshed adding Factories to Change Feed
seanmcc-msft 4db0102
Moved Chunk initalization logic to ChunkFactory
seanmcc-msft 68d772f
Re-recorded tests
seanmcc-msft 4757ce3
Fixed CI
seanmcc-msft 34e837e
PR comments
seanmcc-msft 4e6cc08
Merge branch 'feature/storage/stg73base' into feature/storage/changeFeed
seanmcc-msft 442c07a
Filled out readme
seanmcc-msft d50a2b7
Added samples
seanmcc-msft 21bedda
PR comments
seanmcc-msft 743207f
Merge branch 'feature/storage/stg73base' into feature/storage/changeFeed
seanmcc-msft e8ef59b
Merge branch 'feature/storage/stg73base' into feature/storage/changeFeed
seanmcc-msft 85848d7
Merge branch 'feature/storage/stg73base' into feature/storage/changeFeed
seanmcc-msft 353b928
Updated readme to pass CI
seanmcc-msft 105c435
Fixed some edge cases and added tests
seanmcc-msft 20d364d
fixed ending the change feed
seanmcc-msft 669337b
PR comments
seanmcc-msft 1a07ef1
PR comments
seanmcc-msft c942c1f
Changed default page size
seanmcc-msft 83dba4d
PR comments
seanmcc-msft 04431b3
PR comments
seanmcc-msft 74e6e05
PR comments
seanmcc-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
6 changes: 6 additions & 0 deletions
6
sdk/storage/Azure.Storage.Blobs.ChangeFeed/BreakingChanges.txt
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,6 @@ | ||
Breaking Changes | ||
================ | ||
|
||
12.0.0-preview.1 | ||
-------------------------- | ||
- New Azure.Storage.Blobs.ChangeFeed client library. |
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,4 @@ | ||
# Release History | ||
|
||
## 12.0.0-preview.1 | ||
This preview is the first release supporting Azure Storage Blobs Change Feed. |
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,143 @@ | ||
# Azure Storage Blobs Change Feed client library for .NET | ||
|
||
> Server Version: 2019-12-12 | ||
|
||
The purpose of the change feed is to provide transaction logs of all the changes that occur to | ||
the blobs and the blob metadata in your storage account. The change feed provides ordered, | ||
guaranteed, durable, immutable, read-only log of these changes. Client applications can read these | ||
logs at any time. The change feed enables you to build efficient and scalable solutions that | ||
process change events that occur in your Blob Storage account at a low cost. | ||
|
||
[Source code][source] | [Product documentation][product_docs] | ||
|
||
## Getting started | ||
|
||
### Install the package | ||
- TODO after we have released. | ||
|
||
### Prerequisites | ||
|
||
You need an [Azure subscription][azure_sub] and a | ||
[Storage Account][storage_account_docs] to use this package. | ||
|
||
To create a new Storage Account, you can use the [Azure Portal][storage_account_create_portal], | ||
[Azure PowerShell][storage_account_create_ps], or the [Azure CLI][storage_account_create_cli]. | ||
Here's an example using the Azure CLI: | ||
|
||
```Powershell | ||
az storage account create --name MyStorageAccount --resource-group MyResourceGroup --location westus --sku Standard_LRS | ||
``` | ||
|
||
## Key concepts | ||
|
||
The change feed is stored as blobs in a special container in your storage account at standard blob | ||
pricing cost. You can control the retention period of these files based on your requirements | ||
(See the conditions of the current release). Change events are appended to the change feed as records | ||
in the Apache Avro format specification: a compact, fast, binary format that provides rich data structures | ||
with inline schema. This format is widely used in the Hadoop ecosystem, Stream Analytics, and Azure Data | ||
Factory. | ||
|
||
You can process these logs incrementally or in-full. Any number of client applications can independently | ||
read the change feed, in parallel, and at their own pace. Analytics applications such as Apache Drill or | ||
Apache Spark can consume logs directly as Avro files, which let you process them at a low-cost, with | ||
high-bandwidth, and without having to write a custom application. | ||
|
||
## Examples | ||
|
||
### Get all events in the Change Feed | ||
```C# Snippet:SampleSnippetsChangeFeed_GetAllEvents | ||
// Get all the events in the change feed. | ||
List<BlobChangeFeedEvent> changeFeedEvents = new List<BlobChangeFeedEvent>(); | ||
await foreach (BlobChangeFeedEvent changeFeedEvent in changeFeedClient.GetChangesAsync()) | ||
{ | ||
changeFeedEvents.Add(changeFeedEvent); | ||
} | ||
``` | ||
|
||
### Get events between a start and end time | ||
```C# Snippet:SampleSnippetsChangeFeed_GetEventsBetweenStartAndEndTime | ||
// Create the start and end time. The change feed client will round start time down to | ||
// the nearest hour, and round endTime up to the next hour if you provide DateTimeOffsets | ||
// with minutes and seconds. | ||
DateTimeOffset startTime = new DateTimeOffset(2017, 3, 2, 15, 0, 0, TimeSpan.Zero); | ||
DateTimeOffset endTime = new DateTimeOffset(2020, 10, 7, 2, 0, 0, TimeSpan.Zero); | ||
|
||
// You can also provide just a start or end time. | ||
await foreach (BlobChangeFeedEvent changeFeedEvent in changeFeedClient.GetChangesAsync( | ||
start: startTime, | ||
end: endTime)) | ||
{ | ||
changeFeedEvents.Add(changeFeedEvent); | ||
} | ||
``` | ||
|
||
### Resume with cursor | ||
```C# Snippet:SampleSnippetsChangeFeed_ResumeWithCursor | ||
IAsyncEnumerator<Page<BlobChangeFeedEvent>> enumerator = changeFeedClient | ||
.GetChangesAsync() | ||
.AsPages(pageSizeHint: 10) | ||
.GetAsyncEnumerator(); | ||
|
||
await enumerator.MoveNextAsync(); | ||
|
||
foreach (BlobChangeFeedEvent changeFeedEvent in enumerator.Current.Values) | ||
{ | ||
changeFeedEvents.Add(changeFeedEvent); | ||
} | ||
|
||
// get the change feed cursor. The cursor is not required to get each page of events, | ||
// it is intended to be saved and used to resume iterating at a later date. | ||
string cursor = enumerator.Current.ContinuationToken; | ||
|
||
// Resume iterating from the pervious position with the cursor. | ||
await foreach (BlobChangeFeedEvent changeFeedEvent in changeFeedClient.GetChangesAsync( | ||
continuation: cursor)) | ||
{ | ||
changeFeedEvents.Add(changeFeedEvent); | ||
} | ||
``` | ||
|
||
## Troubleshooting | ||
All Blob service operations will throw a | ||
[RequestFailedException][RequestFailedException] on failure with | ||
helpful [`ErrorCode`s][error_codes]. Many of these errors are recoverable. | ||
|
||
## Next steps | ||
|
||
Get started with our [Change Feed samples][samples]: | ||
|
||
1. [Hello World](samples/Sample01a_HelloWorld.cs): Get changes that have occured in your storage account (or [asynchronously](samples/Sample01b_HelloWorldAsync.cs)) | ||
2. [Auth](samples/Sample02_Auth.cs): Authenticate with connection strings, public access, shared keys, shared access signatures, and Azure Active Directory. | ||
|
||
|
||
## Contributing | ||
|
||
See the [Storage CONTRIBUTING.md][storage_contrib] for details on building, | ||
testing, and contributing to this library. | ||
|
||
This project welcomes contributions and suggestions. Most contributions require | ||
you to agree to a Contributor License Agreement (CLA) declaring that you have | ||
the right to, and actually do, grant us the rights to use your contribution. For | ||
details, visit [cla.microsoft.com][cla]. | ||
|
||
This project has adopted the [Microsoft Open Source Code of Conduct][coc]. | ||
For more information see the [Code of Conduct FAQ][coc_faq] | ||
or contact [[email protected]][coc_contact] with any | ||
additional questions or comments. | ||
|
||
<!-- LINKS --> | ||
[source]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/storage/Azure.Storage.Blobs/srcs | ||
ljian3377 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[product_docs]: https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-change-feed | ||
[azure_sub]: https://azure.microsoft.com/free/ | ||
[storage_account_docs]: https://docs.microsoft.com/azure/storage/common/storage-account-overview | ||
[storage_account_create_ps]: https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-powershell | ||
[storage_account_create_cli]: https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-cli | ||
[storage_account_create_portal]: https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-portal | ||
[RequestFailedException]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/core/Azure.Core/src/RequestFailedException.cs | ||
[error_codes]: https://docs.microsoft.com/rest/api/storageservices/blob-service-error-codes | ||
[samples]: samples/ | ||
[storage_contrib]: ../CONTRIBUTING.md | ||
[cla]: https://cla.microsoft.com | ||
[coc]: https://opensource.microsoft.com/codeofconduct/ | ||
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ | ||
[coc_contact]: mailto:[email protected] |
31 changes: 31 additions & 0 deletions
31
...zure.Storage.Blobs.ChangeFeed/samples/Azure.Storage.Blobs.ChangeFeed.Samples.Tests.csproj
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,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks> | ||
<AssemblyTitle>Microsoft Azure.Storage.Blobs.ChangeFeed client library samples</AssemblyTitle> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Azure.Identity" /> | ||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\src\Azure.Storage.Blobs.ChangeFeed.csproj" /> | ||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Azure.Storage.Common\src\Azure.Storage.Common.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildThisFileDirectory)..\..\Azure.Storage.Common\tests\Shared\**\*.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" /> | ||
<None Include="$(MSBuildThisFileDirectory)..\..\Azure.Storage.Common\tests\Shared\*.xml"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<!-- Required Shared Source for testing --> | ||
<Compile Include="$(AzureCoreSharedSources)ArrayBufferWriter.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" /> | ||
<Compile Include="$(AzureCoreSharedSources)NoBodyResponse{T}.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" /> | ||
<Compile Include="$(AzureCoreSharedSources)TaskExtensions.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" /> | ||
<Compile Include="$(AzureStorageSharedSources)Constants.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" /> | ||
<Compile Include="$(AzureStorageSharedSources)Errors.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" /> | ||
<Compile Include="$(AzureStorageSharedSources)StorageConnectionString.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" /> | ||
<Compile Include="$(AzureStorageSharedSources)SharedAccessSignatureCredentials.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" /> | ||
<Compile Include="$(AzureStorageSharedSources)UriExtensions.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" /> | ||
<Compile Include="$(AzureStorageSharedSources)UriQueryParamsCollection.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" /> | ||
<Compile Include="$(AzureStorageSharedSources)StorageExceptionExtensions.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" /> | ||
</ItemGroup> | ||
</Project> |
15 changes: 15 additions & 0 deletions
15
sdk/storage/Azure.Storage.Blobs.ChangeFeed/samples/README.md
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,15 @@ | ||
--- | ||
page_type: sample | ||
languages: | ||
- csharp | ||
products: | ||
- azure | ||
- azure-storage | ||
name: Azure.Storage.ChangeFeed samples for .NET | ||
description: Samples for the Azure.Storage.Blobs.ChangeFeed client library | ||
--- | ||
|
||
# Azure.Storage.ChangeFeed Samples | ||
|
||
- sample 0 | ||
- sample 1 |
115 changes: 115 additions & 0 deletions
115
sdk/storage/Azure.Storage.Blobs.ChangeFeed/samples/Sample01a_HelloWorld.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,115 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection.Metadata.Ecma335; | ||
using Azure.Storage.Blobs.ChangeFeed.Models; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.Storage.Blobs.ChangeFeed.Samples | ||
{ | ||
/// <summary> | ||
/// Basic Azure ChangeFeed Storage samples. | ||
/// </summary> | ||
public class Sample01a_HelloWorld : SampleTest | ||
{ | ||
/// <summary> | ||
/// Download every event in the change feed. | ||
/// </summary> | ||
[Test] | ||
public void ChangeFeed() | ||
{ | ||
// Get a connection string to our Azure Storage account. | ||
string connectionString = ConnectionString; | ||
|
||
// Get a new blob service client. | ||
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString); | ||
|
||
// Get a new change feed client. | ||
BlobChangeFeedClient changeFeedClient = blobServiceClient.GetChangeFeedClient(); | ||
|
||
// Get all the events in the change feed. | ||
List<BlobChangeFeedEvent> changeFeedEvents = new List<BlobChangeFeedEvent>(); | ||
foreach (BlobChangeFeedEvent changeFeedEvent in changeFeedClient.GetChanges()) | ||
{ | ||
changeFeedEvents.Add(changeFeedEvent); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Download change feed events between a start and end time. | ||
/// </summary> | ||
[Test] | ||
public void ChangeFeedBetweenDates() | ||
{ | ||
// Get a connection string to our Azure Storage account. | ||
string connectionString = ConnectionString; | ||
|
||
// Get a new blob service client. | ||
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString); | ||
|
||
// Get a new change feed client. | ||
BlobChangeFeedClient changeFeedClient = blobServiceClient.GetChangeFeedClient(); | ||
List<BlobChangeFeedEvent> changeFeedEvents = new List<BlobChangeFeedEvent>(); | ||
|
||
// Create the start and end time. The change feed client will round start time down to | ||
// the nearest hour, and round endTime up to the next hour if you provide DateTimeOffsets | ||
// with minutes and seconds. | ||
DateTimeOffset startTime = new DateTimeOffset(2017, 3, 2, 15, 0, 0, TimeSpan.Zero); | ||
DateTimeOffset endTime = new DateTimeOffset(2020, 10, 7, 2, 0, 0, TimeSpan.Zero); | ||
|
||
// You can also provide just a start or end time. | ||
foreach (BlobChangeFeedEvent changeFeedEvent in changeFeedClient.GetChanges( | ||
start: startTime, | ||
end: endTime)) | ||
{ | ||
changeFeedEvents.Add(changeFeedEvent); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// You can use the change feed cursor to resume iterating throw the change feed | ||
/// at a later time. | ||
/// </summary> | ||
[Test] | ||
public void ChangeFeedResumeWithCursor() | ||
{ | ||
// Get a connection string to our Azure Storage account. | ||
string connectionString = ConnectionString; | ||
|
||
// Get a new blob service client. | ||
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString); | ||
|
||
// Get a new change feed client. | ||
BlobChangeFeedClient changeFeedClient = blobServiceClient.GetChangeFeedClient(); | ||
List<BlobChangeFeedEvent> changeFeedEvents = new List<BlobChangeFeedEvent>(); | ||
|
||
IEnumerator<Page<BlobChangeFeedEvent>> enumerator = changeFeedClient | ||
.GetChanges() | ||
.AsPages(pageSizeHint: 10) | ||
.GetEnumerator(); | ||
; | ||
|
||
enumerator.MoveNext(); | ||
|
||
foreach (BlobChangeFeedEvent changeFeedEvent in enumerator.Current.Values) | ||
{ | ||
changeFeedEvents.Add(changeFeedEvent); | ||
} | ||
|
||
// get the change feed cursor. The cursor is not required to get each page of events, | ||
// it is intended to be saved and used to resume iterating at a later date. | ||
string cursor = enumerator.Current.ContinuationToken; | ||
|
||
// Resume iterating from the pervious position with the cursor. | ||
foreach (BlobChangeFeedEvent changeFeedEvent in changeFeedClient.GetChanges( | ||
continuation: cursor)) | ||
{ | ||
changeFeedEvents.Add(changeFeedEvent); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice readme. Thanks for writing it!