-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5736: Expose atClusterTime parameter in snapshot sessions #1874
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
base: main
Are you sure you want to change the base?
Changes from 21 commits
e9d3178
d5e8b3d
a46c3a7
763f950
69e0baf
43ab914
0b40cce
7678002
02114e0
b504123
8556b21
c9c5041
edd0371
56c1b0b
5f63a93
5aa0a58
c22e569
8499e96
3e96140
f2f6f1e
c1e8f25
ecbae5a
7ee46b2
ce2c1c3
3ffea71
fe35bcb
9c9880c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,13 +13,35 @@ | |||||||||||||||||||||||||||||||||||
| * limitations under the License. | ||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| using System; | ||||||||||||||||||||||||||||||||||||
| using System.Threading; | ||||||||||||||||||||||||||||||||||||
| using System.Threading.Tasks; | ||||||||||||||||||||||||||||||||||||
| using MongoDB.Bson; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| namespace MongoDB.Driver | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||
| /// Extension methods for <see cref="IClientSession"/>. | ||||||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||||||
| public static class IClientSessionExtensions | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||
| /// Gets the snapshot time for a snapshot session. | ||||||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||||||
| /// <param name="session">The client session handle.</param> | ||||||||||||||||||||||||||||||||||||
| /// <returns>The snapshot time as a <see cref="BsonTimestamp"/>.</returns> | ||||||||||||||||||||||||||||||||||||
| /// <exception cref="InvalidOperationException">Thrown when the session is not a snapshot session.</exception> | ||||||||||||||||||||||||||||||||||||
| public static BsonTimestamp GetSnapshotTime(this IClientSession session) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| var clientSessionHandle = (ClientSessionHandle)session; | ||||||||||||||||||||||||||||||||||||
| return clientSessionHandle.WrappedCoreSession.IsSnapshot ? | ||||||||||||||||||||||||||||||||||||
| clientSessionHandle.SnapshotTime | ||||||||||||||||||||||||||||||||||||
papafe marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||
| : throw new InvalidOperationException("Cannot retrieve snapshot time from a non-snapshot session."); | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+34
to
+39
|
||||||||||||||||||||||||||||||||||||
| public static BsonTimestamp GetSnapshotTime(this IClientSession session) | |
| { | |
| var clientSessionHandle = (ClientSessionHandle)session; | |
| return clientSessionHandle.WrappedCoreSession.IsSnapshot ? | |
| clientSessionHandle.SnapshotTime | |
| : throw new InvalidOperationException("Cannot retrieve snapshot time from a non-snapshot session."); | |
| /// <exception cref="NotSupportedException">Thrown when the session is not a <see cref="ClientSessionHandle"/>.</exception> | |
| public static BsonTimestamp GetSnapshotTime(this IClientSession session) | |
| { | |
| if (session is ClientSessionHandle clientSessionHandle) | |
| { | |
| return clientSessionHandle.WrappedCoreSession.IsSnapshot | |
| ? clientSessionHandle.SnapshotTime | |
| : throw new InvalidOperationException("Cannot retrieve snapshot time from a non-snapshot session."); | |
| } | |
| throw new NotSupportedException("GetSnapshotTime is only supported for sessions of type ClientSessionHandle."); |
papafe marked this conversation as resolved.
Show resolved
Hide resolved
papafe marked this conversation as resolved.
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* Copyright 2010-present MongoDB Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using MongoDB.Bson; | ||
|
|
||
| namespace MongoDB.Driver.Tests.UnifiedTestOperations; | ||
|
|
||
| public class UnifiedGetSnapshotOperation : IUnifiedEntityTestOperation | ||
papafe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| private readonly IClientSessionHandle _session; | ||
|
|
||
| public UnifiedGetSnapshotOperation(IClientSessionHandle session) | ||
| { | ||
| _session = session; | ||
| } | ||
|
|
||
| public OperationResult Execute(CancellationToken cancellationToken) => GetSnapshotTime(); | ||
|
|
||
| public Task<OperationResult> ExecuteAsync(CancellationToken cancellationToken) => Task.FromResult(GetSnapshotTime()); | ||
|
|
||
| private OperationResult GetSnapshotTime() | ||
| { | ||
| try | ||
| { | ||
| return OperationResult.FromResult(_session.GetSnapshotTime()); | ||
| } | ||
| catch (Exception exception) | ||
| { | ||
| return OperationResult.FromException(exception); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public class UnifiedGetSnapshotOperationBuilder | ||
| { | ||
| private readonly UnifiedEntityMap _entityMap; | ||
|
|
||
| public UnifiedGetSnapshotOperationBuilder(UnifiedEntityMap entityMap) | ||
| { | ||
| _entityMap = entityMap; | ||
| } | ||
|
|
||
| public UnifiedGetSnapshotOperation Build(string targetSessionId, BsonDocument arguments) | ||
| { | ||
| if (arguments != null) | ||
| { | ||
| throw new FormatException("GetSnapshotTime is not expected to contain arguments."); | ||
| } | ||
|
|
||
| var session = _entityMap.Sessions[targetSessionId]; | ||
| return new UnifiedGetSnapshotOperation(session); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.