Skip to content

Commit

Permalink
merge 2.22.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Oct 28, 2023
2 parents c81c2ec + 7524611 commit 8cbaa2b
Show file tree
Hide file tree
Showing 80 changed files with 2,113 additions and 451 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,6 @@ indent_size = 2
# Shell scripts
[*.sh]
end_of_line = lf
indent_size = 2
[*.{cmd, bat}]
end_of_line = crlf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ src/packages

# Nupkg artifacts
*.nupkg
*.snupkg

# NCrunch artifacts
*.ncrunch*
Expand Down
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
next-version: 2.20.1
next-version: 2.22.0
tag-prefix: '(v|V|eth-v)'
branches:
main:
Expand Down
18 changes: 18 additions & 0 deletions Release Notes/Release Notes v2.22.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# .NET Driver Version 2.22.0 Release Notes

This is the general availability release for the 2.22.0 version of the driver.

The main new features in 2.22.0 include:

* LINQ3 bug fixes and improvements
* Support for $set aggregation stage
* Added synonym support for Atlas Search
* Support for $vectorSearch aggregation stage
* Reduced memory allocations when using encryption
* Additional logging messages

An online version of these release notes is available [here](https://github.com/mongodb/mongo-csharp-driver/blob/master/Release%20Notes/Release%20Notes%20v2.22.0.md).

The full list of issues resolved in this release is available at [CSHARP JIRA project](https://jira.mongodb.org/issues/?jql=project%20%3D%20CSHARP%20AND%20fixVersion%20%3D%202.22.0%20ORDER%20BY%20key%20ASC).

Documentation on the .NET driver can be found [here](https://www.mongodb.com/docs/drivers/csharp/v2.22/).
19 changes: 14 additions & 5 deletions src/MongoDB.Bson/BsonExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ public static class BsonExtensionMethods
/// <param name="writerSettings">The writer settings.</param>
/// <param name="configurator">The serialization context configurator.</param>
/// <param name="args">The serialization args.</param>
/// <param name="estimatedBsonSize">The estimated size of the serialized object</param>
/// <returns>A BSON byte array.</returns>
public static byte[] ToBson<TNominalType>(
this TNominalType obj,
IBsonSerializer<TNominalType> serializer = null,
BsonBinaryWriterSettings writerSettings = null,
Action<BsonSerializationContext.Builder> configurator = null,
BsonSerializationArgs args = default(BsonSerializationArgs)
)
BsonSerializationArgs args = default(BsonSerializationArgs),
int estimatedBsonSize = 0)
{
args.SetOrValidateNominalType(typeof(TNominalType), "<TNominalType>");
return ToBson(obj, typeof(TNominalType), writerSettings, serializer, configurator, args);

return ToBson(obj, typeof(TNominalType), writerSettings, serializer, configurator, args, estimatedBsonSize);
}

/// <summary>
Expand All @@ -56,6 +58,7 @@ public static byte[] ToBson<TNominalType>(
/// <param name="serializer">The serializer.</param>
/// <param name="configurator">The serialization context configurator.</param>
/// <param name="args">The serialization args.</param>
/// <param name="estimatedBsonSize">The estimated size of the serialized object.</param>
/// <returns>A BSON byte array.</returns>
/// <exception cref="System.ArgumentNullException">nominalType</exception>
/// <exception cref="System.ArgumentException">serializer</exception>
Expand All @@ -65,8 +68,14 @@ public static byte[] ToBson(
BsonBinaryWriterSettings writerSettings = null,
IBsonSerializer serializer = null,
Action<BsonSerializationContext.Builder> configurator = null,
BsonSerializationArgs args = default(BsonSerializationArgs))
BsonSerializationArgs args = default(BsonSerializationArgs),
int estimatedBsonSize = 0)
{
if (estimatedBsonSize < 0)
{
throw new ArgumentException("Value cannot be negative.", nameof(estimatedBsonSize));
}

if (nominalType == null)
{
throw new ArgumentNullException("nominalType");
Expand All @@ -83,7 +92,7 @@ public static byte[] ToBson(
throw new ArgumentException(message, "serializer");
}

using (var memoryStream = new MemoryStream())
using (var memoryStream = new MemoryStream(estimatedBsonSize))
{
using (var bsonWriter = new BsonBinaryWriter(memoryStream, writerSettings ?? BsonBinaryWriterSettings.Defaults))
{
Expand Down
1 change: 1 addition & 0 deletions src/MongoDB.Bson/Etherna.MongoDB.Bson.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Description>Fork by Etherna of the official MongoDB supported BSON library. See https://www.mongodb.com/docs/drivers/csharp/ for more details.</Description>
<PackageDescription>Fork by Etherna of the MongoDB's Official Bson Library.</PackageDescription>
<PackageTags>$(PackageTags);bson</PackageTags>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
47 changes: 22 additions & 25 deletions src/MongoDB.Bson/IO/BsonWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,13 @@ public void PushSettings(Action<BsonWriterSettings> configurator)
/// Writes the end of a BSON array to the writer.
/// </summary>
public virtual void WriteEndArray()
{
_serializationDepth--;
}
=> ExitSerializationScope();

/// <summary>
/// Writes the end of a BSON document to the writer.
/// </summary>
public virtual void WriteEndDocument()
{
_serializationDepth--;

PopElementNameValidator();
}
=> ExitSerializationScope();

/// <summary>
/// Writes a BSON Int32 to the writer.
Expand Down Expand Up @@ -362,28 +356,13 @@ public virtual void WriteRawBsonDocument(IByteBuffer slice)
/// Writes the start of a BSON array to the writer.
/// </summary>
public virtual void WriteStartArray()
{
_serializationDepth++;
if (_serializationDepth > _settings.MaxSerializationDepth)
{
throw new BsonSerializationException("Maximum serialization depth exceeded (does the object being serialized have a circular reference?).");
}
}
=> EnterSerializationScope();

/// <summary>
/// Writes the start of a BSON document to the writer.
/// </summary>
public virtual void WriteStartDocument()
{
_serializationDepth++;
if (_serializationDepth > _settings.MaxSerializationDepth)
{
throw new BsonSerializationException("Maximum serialization depth exceeded (does the object being serialized have a circular reference?).");
}

var childValidator = _useChildValidator ? _elementNameValidator.GetValidatorForChildContent(_name) : _elementNameValidator;
PushElementNameValidator(childValidator);
}
=> EnterSerializationScope();

/// <summary>
/// Writes a BSON String to the writer.
Expand Down Expand Up @@ -470,5 +449,23 @@ protected void ThrowInvalidState(string methodName, params BsonWriterState[] val
methodName, validStatesString, _state);
throw new InvalidOperationException(message);
}

private void EnterSerializationScope()
{
_serializationDepth++;
if (_serializationDepth > _settings.MaxSerializationDepth)
{
throw new BsonSerializationException("Maximum serialization depth exceeded (does the object being serialized have a circular reference?).");
}

var childValidator = _useChildValidator ? _elementNameValidator.GetValidatorForChildContent(_name) : _elementNameValidator;
PushElementNameValidator(childValidator);
}

private void ExitSerializationScope()
{
_serializationDepth--;
PopElementNameValidator();
}
}
}
4 changes: 4 additions & 0 deletions src/MongoDB.Bson/ObjectModel/BsonBinarySubType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public enum BsonBinarySubType
/// </summary>
Column = 0x07,
/// <summary>
/// Sensitive data.
/// </summary>
Sensitive = 0x08,
/// <summary>
/// User defined binary data.
/// </summary>
UserDefined = 0x80
Expand Down
63 changes: 52 additions & 11 deletions src/MongoDB.Bson/Serialization/BsonSerializationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Etherna.MongoDB.Bson.IO;

namespace Etherna.MongoDB.Bson.Serialization
Expand All @@ -24,10 +26,26 @@ namespace Etherna.MongoDB.Bson.Serialization
/// </summary>
public class BsonSerializationInfo
{
#region static
/// <summary>
/// Creates a new instance of the BsonSerializationinfo class with an element path instead of an element name.
/// </summary>
/// <param name="elementPath">The element path.</param>
/// <param name="serializer">The serializer.</param>
/// <param name="nominalType">The nominal type.</param>
/// <returns>A BsonSerializationInfo.</returns>
public static BsonSerializationInfo CreateWithPath(IEnumerable<string> elementPath, IBsonSerializer serializer, Type nominalType)
{
return new BsonSerializationInfo(elementPath.ToList(), serializer, nominalType);
}
#endregion

// private fields
private string _elementName;
private IBsonSerializer _serializer;
private Type _nominalType;
// note: while _elementName could have been modeled with an _elementPath of length 1, treating this is a special case avoids some allocations
private readonly string _elementName;
private readonly IReadOnlyList<string> _elementPath;
private readonly IBsonSerializer _serializer;
private readonly Type _nominalType;

// constructors
/// <summary>
Expand All @@ -43,13 +61,35 @@ public BsonSerializationInfo(string elementName, IBsonSerializer serializer, Typ
_nominalType = nominalType;
}

private BsonSerializationInfo(IReadOnlyList<string> elementPath, IBsonSerializer serializer, Type nominalType)
{
_elementPath = elementPath;
_serializer = serializer;
_nominalType = nominalType;
}

// public properties
/// <summary>
/// Gets or sets the dotted element name.
/// Gets the element name.
/// </summary>
public string ElementName
{
get { return _elementName; }
get
{
if (_elementPath != null)
{
throw new InvalidOperationException("When ElementPath is not null you must use it instead.");
}
return _elementName;
}
}

/// <summary>
/// Gets element path.
/// </summary>
public IReadOnlyList<string> ElementPath
{
get { return _elementPath; }
}

/// <summary>
Expand Down Expand Up @@ -92,20 +132,21 @@ public object DeserializeValue(BsonValue value)
/// </summary>
/// <param name="newSerializationInfo">The new info.</param>
/// <returns>A new BsonSerializationInfo.</returns>
[Obsolete("This method is no longer relevant because field names are now allowed to contain dots.")]
public BsonSerializationInfo Merge(BsonSerializationInfo newSerializationInfo)
{
string elementName = null;
if (_elementName != null && newSerializationInfo._elementName != null)
if (ElementName != null && newSerializationInfo.ElementName != null)
{
elementName = _elementName + "." + newSerializationInfo._elementName;
elementName = ElementName + "." + newSerializationInfo.ElementName;
}
else if (_elementName != null)
else if (ElementName != null)
{
elementName = _elementName;
elementName = ElementName;
}
else if (newSerializationInfo._elementName != null)
else if (newSerializationInfo.ElementName != null)
{
elementName = newSerializationInfo._elementName;
elementName = newSerializationInfo.ElementName;
}

return new BsonSerializationInfo(
Expand Down
5 changes: 5 additions & 0 deletions src/MongoDB.Driver.Core/ChangeStreamDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ public TDocument FullDocumentBeforeChange
// if TDocument is BsonDocument avoid deserializing it again to prevent possible duplicate element name errors
if (typeof(TDocument) == typeof(BsonDocument) && BackingDocument.TryGetValue("fullDocumentBeforeChange", out var fullDocumentBeforeChange))
{
if (fullDocumentBeforeChange.IsBsonNull)
{
return default;
}

return (TDocument)(object)fullDocumentBeforeChange.AsBsonDocument;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void Authenticate(IConnection connection, ConnectionDescription descripti
if (!description.HelloResult.HasSaslSupportedMechs
&& Feature.ScramSha256Authentication.IsSupported(description.MaxWireVersion))
{
var command = CustomizeInitialHelloCommand(HelloHelper.CreateCommand(_serverApi));
var command = CustomizeInitialHelloCommand(HelloHelper.CreateCommand(_serverApi, loadBalanced: connection.Settings.LoadBalanced));
var helloProtocol = HelloHelper.CreateProtocol(command, _serverApi);
var helloResult = HelloHelper.GetResult(connection, helloProtocol, cancellationToken);
var mergedHelloResult = new HelloResult(description.HelloResult.Wrapped.Merge(helloResult.Wrapped));
Expand All @@ -111,7 +111,7 @@ public async Task AuthenticateAsync(IConnection connection, ConnectionDescriptio
if (!description.HelloResult.HasSaslSupportedMechs
&& Feature.ScramSha256Authentication.IsSupported(description.MaxWireVersion))
{
var command = CustomizeInitialHelloCommand(HelloHelper.CreateCommand(_serverApi));
var command = CustomizeInitialHelloCommand(HelloHelper.CreateCommand(_serverApi, loadBalanced: connection.Settings.LoadBalanced));
var helloProtocol = HelloHelper.CreateProtocol(command, _serverApi);
var helloResult = await HelloHelper.GetResultAsync(connection, helloProtocol, cancellationToken).ConfigureAwait(false);
var mergedHelloResult = new HelloResult(description.HelloResult.Wrapped.Merge(helloResult.Wrapped));
Expand Down
10 changes: 5 additions & 5 deletions src/MongoDB.Driver.Core/Core/Clusters/Cluster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected virtual void Dispose(bool disposing)
{
if (_state.TryChange(State.Disposed))
{
_clusterEventLogger.Logger?.LogDebug(_clusterId, "Disposing");
_clusterEventLogger.Logger?.LogTrace(_clusterId, "Cluster disposing");

#pragma warning disable CS0618 // Type or member is obsolete
var connectionModeSwitch = _description.ConnectionModeSwitch;
Expand All @@ -188,7 +188,7 @@ protected virtual void Dispose(bool disposing)
_rapidHeartbeatTimer.Dispose();
_cryptClient?.Dispose();

_clusterEventLogger.Logger?.LogDebug(_clusterId, "Disposed");
_clusterEventLogger.Logger?.LogTrace(_clusterId, "Cluster disposed");
}
}

Expand Down Expand Up @@ -231,14 +231,14 @@ public virtual void Initialize()
ThrowIfDisposed();
if (_state.TryChange(State.Initial, State.Open))
{
_clusterEventLogger.Logger?.LogDebug(_clusterId, "Initialized");
_clusterEventLogger.Logger?.LogTrace(_clusterId, "Cluster initialized");

if (_settings.CryptClientSettings != null)
{
_cryptClient = CryptClientCreator.CreateCryptClient(_settings.CryptClientSettings);

_clusterEventLogger.Logger?.LogDebug(
StructuredLogTemplateProviders.ClusterId_Message_SharedLibraryVersion,
_clusterEventLogger.Logger?.LogTrace(
StructuredLogTemplateProviders.TopologyId_Message_SharedLibraryVersion,
_clusterId,
"CryptClient created. Configured shared library version: ",
_cryptClient.CryptSharedLibraryVersion ?? "None");
Expand Down
7 changes: 3 additions & 4 deletions src/MongoDB.Driver.Core/Core/Clusters/MultiServerCluster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,9 @@ private void ServerDescriptionChangedHandler(object sender, ServerDescriptionCha
catch (Exception unexpectedException)
{
// if we catch an exception here it's because of a bug in the driver
_clusterEventLogger.LogAndPublish(new SdamInformationEvent(
"Unexpected exception in MultiServerCluster.ServerDescriptionChangedHandler: {0}",
unexpectedException),
unexpectedException);
_clusterEventLogger.LogAndPublish(
unexpectedException,
new SdamInformationEvent("Unexpected exception in MultiServerCluster.ServerDescriptionChangedHandler: {0}", unexpectedException));
}
// TODO: should we reset the cluster state in some way? (the state is undefined since an unexpected exception was thrown)
}
Expand Down
Loading

0 comments on commit 8cbaa2b

Please sign in to comment.