Skip to content

Commit 2d84290

Browse files
committed
Merge branch 'master' of github.com:Azure/azure-documentdb-dotnet
2 parents 7de1260 + 88f7ec8 commit 2d84290

File tree

29 files changed

+219
-106
lines changed

29 files changed

+219
-106
lines changed
Binary file not shown.

samples/ChangeFeedMigrationTool/ChangeFeedMigrationSample.csproj

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@
5454
<StartupObject>ChangeFeedMigrationSample.Program</StartupObject>
5555
</PropertyGroup>
5656
<ItemGroup>
57-
<Reference Include="Microsoft.Azure.Documents.ChangeFeedProcessor, Version=1.14.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
58-
<HintPath>..\packages\Microsoft.Azure.DocumentDB.ChangeFeedProcessor.1.0.0\lib\net45\Microsoft.Azure.Documents.ChangeFeedProcessor.dll</HintPath>
57+
<Reference Include="Microsoft.Azure.Documents.ChangeFeedProcessor">
58+
<HintPath>..\packages\Microsoft.Azure.DocumentDB.ChangeFeedProcessor.1.1.0\lib\net45\Microsoft.Azure.Documents.ChangeFeedProcessor.dll</HintPath>
5959
<Private>True</Private>
6060
</Reference>
61-
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.14.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
62-
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.14.1\lib\net45\Microsoft.Azure.Documents.Client.dll</HintPath>
61+
<Reference Include="Microsoft.Azure.Documents.Client">
62+
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.17.0\lib\net45\Microsoft.Azure.Documents.Client.dll</HintPath>
6363
<Private>True</Private>
6464
</Reference>
6565
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
@@ -81,28 +81,13 @@
8181
</None>
8282
<None Include="packages.config" />
8383
</ItemGroup>
84-
<ItemGroup>
85-
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2">
86-
<Visible>False</Visible>
87-
<ProductName>Microsoft .NET Framework 4.5.2 %28x86 and x64%29</ProductName>
88-
<Install>true</Install>
89-
</BootstrapperPackage>
90-
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
91-
<Visible>False</Visible>
92-
<ProductName>.NET Framework 3.5 SP1</ProductName>
93-
<Install>false</Install>
94-
</BootstrapperPackage>
95-
</ItemGroup>
96-
<ItemGroup>
97-
<WCFMetadata Include="Service References\" />
98-
</ItemGroup>
9984
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
100-
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.14.1\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.14.1\build\Microsoft.Azure.DocumentDB.targets')" />
85+
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.17.0\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.17.0\build\Microsoft.Azure.DocumentDB.targets')" />
10186
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
10287
<PropertyGroup>
10388
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
10489
</PropertyGroup>
105-
<Error Condition="!Exists('..\packages\Microsoft.Azure.DocumentDB.1.14.1\build\Microsoft.Azure.DocumentDB.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.DocumentDB.1.14.1\build\Microsoft.Azure.DocumentDB.targets'))" />
90+
<Error Condition="!Exists('..\packages\Microsoft.Azure.DocumentDB.1.17.0\build\Microsoft.Azure.DocumentDB.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.DocumentDB.1.17.0\build\Microsoft.Azure.DocumentDB.targets'))" />
10691
</Target>
10792
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
10893
Other similar extension points exist, see Microsoft.Common.targets.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Azure.DocumentDB" version="1.14.1" targetFramework="net47" />
4-
<package id="Microsoft.Azure.DocumentDB.ChangeFeedProcessor" version="1.0.0" targetFramework="net47" />
3+
<package id="Microsoft.Azure.DocumentDB" version="1.17.0" targetFramework="net47" />
4+
<package id="Microsoft.Azure.DocumentDB.ChangeFeedProcessor" version="1.1.0" targetFramework="net47" />
55
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net47" />
66
</packages>

samples/ChangeFeedProcessor/DocumentDB.ChangeFeedProcessor/ChangeFeedEventHost.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public class ChangeFeedEventHost : IPartitionObserver<DocumentServiceLease>
8383
{
8484
const string DefaultUserAgentSuffix = "changefeed-0.2";
8585
const string LeaseContainerName = "docdb-changefeed";
86+
const string LSNPropertyName = "_lsn";
87+
8688
readonly DocumentCollectionInfo collectionLocation;
8789

8890
string leasePrefix;
@@ -170,6 +172,60 @@ public async Task RegisterObserverFactoryAsync(IChangeFeedObserverFactory factor
170172
await this.StartAsync();
171173
}
172174

175+
/// <summary>
176+
/// Asynchronously checks the current existing leases and calculates an estimate of remaining work per leased partitions.
177+
/// </summary>
178+
/// <returns>An estimate amount of remaining documents to be processed</returns>
179+
public async Task<long> GetEstimatedRemainingWork()
180+
{
181+
await this.InitializeAsync();
182+
183+
long remaining = 0;
184+
ChangeFeedOptions options = new ChangeFeedOptions
185+
{
186+
MaxItemCount = 1
187+
};
188+
189+
foreach (DocumentServiceLease existingLease in await this.leaseManager.ListLeases())
190+
{
191+
options.PartitionKeyRangeId = existingLease.PartitionId;
192+
options.RequestContinuation = existingLease.ContinuationToken;
193+
IDocumentQuery<Document> query = this.documentClient.CreateDocumentChangeFeedQuery(this.collectionSelfLink, options);
194+
FeedResponse<Document> response = null;
195+
196+
try
197+
{
198+
response = await query.ExecuteNextAsync<Document>();
199+
long parsedLSNFromSessionToken = TryConvertToNumber(ParseAmountFromSessionToken(response.SessionToken));
200+
long lastSequenceNumber = response.Count > 0 ? TryConvertToNumber(response.First().GetPropertyValue<string>(LSNPropertyName)) : parsedLSNFromSessionToken;
201+
long partitionRemaining = parsedLSNFromSessionToken - lastSequenceNumber;
202+
remaining += partitionRemaining < 0 ? 0 : partitionRemaining;
203+
}
204+
catch (DocumentClientException ex)
205+
{
206+
ExceptionDispatchInfo exceptionDispatchInfo = ExceptionDispatchInfo.Capture(ex);
207+
DocumentClientException dcex = (DocumentClientException)exceptionDispatchInfo.SourceException;
208+
if ((StatusCode.NotFound == (StatusCode)dcex.StatusCode && SubStatusCode.ReadSessionNotAvailable != (SubStatusCode)GetSubStatusCode(dcex))
209+
|| StatusCode.Gone == (StatusCode)dcex.StatusCode)
210+
{
211+
// We are not explicitly handling Splits here to avoid any collision with an Observer that might have picked this up and managing the split
212+
TraceLog.Error(string.Format("GetEstimateWork > Partition {0}: resource gone (subStatus={1}).", existingLease.PartitionId, GetSubStatusCode(dcex)));
213+
}
214+
else if (StatusCode.TooManyRequests == (StatusCode)dcex.StatusCode ||
215+
StatusCode.ServiceUnavailable == (StatusCode)dcex.StatusCode)
216+
{
217+
TraceLog.Warning(string.Format("GetEstimateWork > Partition {0}: retriable exception : {1}", existingLease.PartitionId, dcex.Message));
218+
}
219+
else
220+
{
221+
TraceLog.Error(string.Format("GetEstimateWork > Partition {0}: Unhandled exception", ex.Error.Message));
222+
}
223+
}
224+
}
225+
226+
return remaining;
227+
}
228+
173229
/// <summary>Asynchronously shuts down the host instance. This method maintains the leases on all partitions currently held, and enables each
174230
/// host instance to shut down cleanly by invoking the method with object.</summary>
175231
/// <returns>A task that indicates the host instance has stopped.</returns>
@@ -759,6 +815,34 @@ private bool IsCheckpointNeeded(DocumentServiceLease lease, CheckpointStats chec
759815
return isCheckpointNeeded;
760816
}
761817

818+
private static long TryConvertToNumber(string number)
819+
{
820+
if (string.IsNullOrEmpty(number))
821+
{
822+
return 0;
823+
}
824+
825+
long parsed = 0;
826+
if (!long.TryParse(number, NumberStyles.Any, CultureInfo.InvariantCulture, out parsed))
827+
{
828+
TraceLog.Warning(string.Format(CultureInfo.InvariantCulture, "Cannot parse number '{0}'.", number));
829+
return 0;
830+
}
831+
832+
return parsed;
833+
}
834+
835+
private static string ParseAmountFromSessionToken(string sessionToken)
836+
{
837+
if (string.IsNullOrEmpty(sessionToken))
838+
{
839+
return string.Empty;
840+
}
841+
842+
int separatorIndex = sessionToken.IndexOf(':');
843+
return sessionToken.Substring(separatorIndex + 1);
844+
}
845+
762846
private static int GetDocumentCount(ResourceResponse<DocumentCollection> response)
763847
{
764848
Debug.Assert(response != null);

samples/ChangeFeedProcessor/DocumentDB.ChangeFeedProcessor/DocumentDB.ChangeFeedProcessor.csproj

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@
3838
<StartupObject />
3939
</PropertyGroup>
4040
<ItemGroup>
41-
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.13.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
42-
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.13.1\lib\net45\Microsoft.Azure.Documents.Client.dll</HintPath>
43-
<Private>True</Private>
41+
<Reference Include="Microsoft.Azure.Documents.Client">
42+
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.17.0\lib\net45\Microsoft.Azure.Documents.Client.dll</HintPath>
4443
</Reference>
4544
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
46-
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
47-
<Private>True</Private>
45+
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
4846
</Reference>
4947
<Reference Include="System" />
5048
<Reference Include="System.Core" />
@@ -81,14 +79,13 @@
8179
<None Include="packages.config" />
8280
</ItemGroup>
8381
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
84-
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.12.0\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.12.0\build\Microsoft.Azure.DocumentDB.targets')" />
82+
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.17.0\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.17.0\build\Microsoft.Azure.DocumentDB.targets')" />
8583
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
8684
<PropertyGroup>
8785
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
8886
</PropertyGroup>
89-
<Error Condition="!Exists('..\packages\Microsoft.Azure.DocumentDB.1.13.1\build\Microsoft.Azure.DocumentDB.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.DocumentDB.1.13.1\build\Microsoft.Azure.DocumentDB.targets'))" />
87+
<Error Condition="!Exists('..\packages\Microsoft.Azure.DocumentDB.1.17.0\build\Microsoft.Azure.DocumentDB.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.DocumentDB.1.17.0\build\Microsoft.Azure.DocumentDB.targets'))" />
9088
</Target>
91-
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.13.1\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.13.1\build\Microsoft.Azure.DocumentDB.targets')" />
9289
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
9390
Other similar extension points exist, see Microsoft.Common.targets.
9491
<Target Name="BeforeBuild">

samples/ChangeFeedProcessor/DocumentDB.ChangeFeedProcessor/packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Azure.DocumentDB" version="1.13.1" targetFramework="net452" />
4-
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net452" />
3+
<package id="Microsoft.Azure.DocumentDB" version="1.17.0" targetFramework="net452" />
4+
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
55
<package id="NuGet.Build" version="2.12.0" targetFramework="net45" />
66
<package id="NuGet.CommandLine" version="1.0.11220.26" targetFramework="net45" />
77
<package id="NuGetPowerTools" version="0.29" targetFramework="net45" />

samples/Spatial/NearestNeighbor/Spatial/Spatial.csproj

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<AssemblyName>Spatial</AssemblyName>
1212
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14+
<NuGetPackageImportStamp>
15+
</NuGetPackageImportStamp>
1416
</PropertyGroup>
1517
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1618
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -35,13 +37,11 @@
3537
<StartupObject />
3638
</PropertyGroup>
3739
<ItemGroup>
38-
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
39-
<SpecificVersion>False</SpecificVersion>
40-
<HintPath>..\..\..\..\..\..\..\..\NuGetPackages\Microsoft.Azure.DocumentDB.1.4.1\lib\net40\Microsoft.Azure.Documents.Client.dll</HintPath>
40+
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.17.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
41+
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.17.0\lib\net45\Microsoft.Azure.Documents.Client.dll</HintPath>
4142
</Reference>
4243
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
43-
<SpecificVersion>False</SpecificVersion>
44-
<HintPath>..\..\..\..\..\..\..\..\NuGetPackages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
44+
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
4545
</Reference>
4646
<Reference Include="System" />
4747
<Reference Include="System.Core" />
@@ -60,6 +60,13 @@
6060
<None Include="packages.config" />
6161
</ItemGroup>
6262
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
63+
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.17.0\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.17.0\build\Microsoft.Azure.DocumentDB.targets')" />
64+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
65+
<PropertyGroup>
66+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
67+
</PropertyGroup>
68+
<Error Condition="!Exists('..\packages\Microsoft.Azure.DocumentDB.1.17.0\build\Microsoft.Azure.DocumentDB.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.DocumentDB.1.17.0\build\Microsoft.Azure.DocumentDB.targets'))" />
69+
</Target>
6370
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
6471
Other similar extension points exist, see Microsoft.Common.targets.
6572
<Target Name="BeforeBuild">
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Azure.DocumentDB" version="1.4.1" targetFramework="net45" />
4-
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net45" />
3+
<package id="Microsoft.Azure.DocumentDB" version="1.17.0" targetFramework="net45" />
4+
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
55
</packages>

samples/Spatial/NearestNeighbor/Test/Test.csproj

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<AssemblyName>Test</AssemblyName>
1212
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14+
<NuGetPackageImportStamp>
15+
</NuGetPackageImportStamp>
1416
</PropertyGroup>
1517
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1618
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -32,13 +34,11 @@
3234
<WarningLevel>4</WarningLevel>
3335
</PropertyGroup>
3436
<ItemGroup>
35-
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
36-
<SpecificVersion>False</SpecificVersion>
37-
<HintPath>..\..\..\..\..\..\..\..\NuGetPackages\Microsoft.Azure.DocumentDB.1.4.1\lib\net40\Microsoft.Azure.Documents.Client.dll</HintPath>
37+
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.17.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
38+
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.17.0\lib\net45\Microsoft.Azure.Documents.Client.dll</HintPath>
3839
</Reference>
3940
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
40-
<SpecificVersion>False</SpecificVersion>
41-
<HintPath>..\..\..\..\..\..\..\..\NuGetPackages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll</HintPath>
41+
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
4242
</Reference>
4343
<Reference Include="System" />
4444
<Reference Include="System.Configuration" />
@@ -66,6 +66,13 @@
6666
</ProjectReference>
6767
</ItemGroup>
6868
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
69+
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.17.0\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.17.0\build\Microsoft.Azure.DocumentDB.targets')" />
70+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
71+
<PropertyGroup>
72+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
73+
</PropertyGroup>
74+
<Error Condition="!Exists('..\packages\Microsoft.Azure.DocumentDB.1.17.0\build\Microsoft.Azure.DocumentDB.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.DocumentDB.1.17.0\build\Microsoft.Azure.DocumentDB.targets'))" />
75+
</Target>
6976
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
7077
Other similar extension points exist, see Microsoft.Common.targets.
7178
<Target Name="BeforeBuild">
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Azure.DocumentDB" version="1.4.1" targetFramework="net45" />
4-
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net45" />
3+
<package id="Microsoft.Azure.DocumentDB" version="1.17.0" targetFramework="net45" />
4+
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
55
</packages>

0 commit comments

Comments
 (0)