From 7bcadfc10058b80018584a106344a45d752bf067 Mon Sep 17 00:00:00 2001 From: xuejiaming <326308290@qq.com> Date: Wed, 8 Dec 2021 23:12:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E7=AE=80=E5=8D=95=E7=9A=84=E5=A4=87=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Directory.Build.props | 4 +-- ...ParseCompileCacheVirtualDataSourceRoute.cs | 1 + ...RouteParseCompileCacheVirtualTableRoute.cs | 2 +- .../Abstractions/AbstractVirtualTableRoute.cs | 2 +- .../DIExtensions/ShardingCoreConfigBuilder.cs | 2 ++ src/ShardingCore/IShardingConfigOption.cs | 8 +++++ ...hardingEnumeratorAsyncStreamMergeEngine.cs | 2 +- ...hardingEnumeratorAsyncStreamMergeEngine.cs | 10 ++++++ .../AbstractionReadWriteConnector.cs | 36 ++++--------------- src/ShardingCore/ShardingConfigOption.cs | 2 ++ 10 files changed, 35 insertions(+), 34 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 8e84a139..00928da7 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -7,8 +7,8 @@ https://github.com/xuejmnet/sharding-core git xuejm - 8.0 - easy sharding for efcore 2.x 3.x 5.x lib. + 9.0 + high performance lightweight solution for efcore sharding table and sharding database support read-write-separation \ No newline at end of file diff --git a/src/ShardingCore/Core/VirtualRoutes/DataSourceRoutes/Abstractions/AbstractShardingRouteParseCompileCacheVirtualDataSourceRoute.cs b/src/ShardingCore/Core/VirtualRoutes/DataSourceRoutes/Abstractions/AbstractShardingRouteParseCompileCacheVirtualDataSourceRoute.cs index 9296deb9..5e9fbfff 100644 --- a/src/ShardingCore/Core/VirtualRoutes/DataSourceRoutes/Abstractions/AbstractShardingRouteParseCompileCacheVirtualDataSourceRoute.cs +++ b/src/ShardingCore/Core/VirtualRoutes/DataSourceRoutes/Abstractions/AbstractShardingRouteParseCompileCacheVirtualDataSourceRoute.cs @@ -31,6 +31,7 @@ namespace ShardingCore.Core.VirtualRoutes.DataSourceRoutes.Abstractions /// 是否启用路由解析编译缓存 /// public virtual bool EnableRouteParseCompileCache => false; + /// /// 对表达式进行缓存编译默认永久缓存单个参数表达式,且不包含orElse只包含单个AndAlso或者没有AndAlso的, /// 比如:或者x]]>,不会缓存id>x && o.id等一共大于、等于、小于、大于等于、小于等于(不等于编译成true]]>)缓存会存在的数量个数上限为 diff --git a/src/ShardingCore/Core/VirtualRoutes/TableRoutes/Abstractions/AbstractShardingRouteParseCompileCacheVirtualTableRoute.cs b/src/ShardingCore/Core/VirtualRoutes/TableRoutes/Abstractions/AbstractShardingRouteParseCompileCacheVirtualTableRoute.cs index 32504848..001d72ed 100644 --- a/src/ShardingCore/Core/VirtualRoutes/TableRoutes/Abstractions/AbstractShardingRouteParseCompileCacheVirtualTableRoute.cs +++ b/src/ShardingCore/Core/VirtualRoutes/TableRoutes/Abstractions/AbstractShardingRouteParseCompileCacheVirtualTableRoute.cs @@ -57,7 +57,7 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes.Abstractions /// 系统默认永久单表达式缓存 /// /// - /// 返回null会走这个方法如果还是null就会调用方法 + /// 返回null会走这个方法如果还是null就会调用方法 protected virtual Func DoCachingCompile(Expression> parseWhere) { var shouldCache = ShouldCache(parseWhere); diff --git a/src/ShardingCore/Core/VirtualRoutes/TableRoutes/Abstractions/AbstractVirtualTableRoute.cs b/src/ShardingCore/Core/VirtualRoutes/TableRoutes/Abstractions/AbstractVirtualTableRoute.cs index 6bfe1e0f..2958164c 100644 --- a/src/ShardingCore/Core/VirtualRoutes/TableRoutes/Abstractions/AbstractVirtualTableRoute.cs +++ b/src/ShardingCore/Core/VirtualRoutes/TableRoutes/Abstractions/AbstractVirtualTableRoute.cs @@ -22,7 +22,7 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes.Abstractions { private readonly DoOnlyOnce _doOnlyOnce = new DoOnlyOnce(); - public void Initialize(EntityMetadata entityMetadata) + public virtual void Initialize(EntityMetadata entityMetadata) { if (!_doOnlyOnce.IsUnDo()) throw new ShardingCoreInvalidOperationException("already init"); diff --git a/src/ShardingCore/DIExtensions/ShardingCoreConfigBuilder.cs b/src/ShardingCore/DIExtensions/ShardingCoreConfigBuilder.cs index cb6ed462..afb073d2 100644 --- a/src/ShardingCore/DIExtensions/ShardingCoreConfigBuilder.cs +++ b/src/ShardingCore/DIExtensions/ShardingCoreConfigBuilder.cs @@ -96,6 +96,8 @@ namespace ShardingCore.DIExtensions public bool? IgnoreCreateTableError { get; set; } = true; public int MaxQueryConnectionsLimit { get; set; } = Environment.ProcessorCount; public ConnectionModeEnum ConnectionMode { get; set; } = ConnectionModeEnum.SYSTEM_AUTO; + public bool? EnableTableRouteCompileCache { get; set; } + public bool? EnableDataSourceRouteCompileCache { get; set; } private readonly ISet _createTableEntities = new HashSet(); diff --git a/src/ShardingCore/IShardingConfigOption.cs b/src/ShardingCore/IShardingConfigOption.cs index d7a092d1..4799881c 100644 --- a/src/ShardingCore/IShardingConfigOption.cs +++ b/src/ShardingCore/IShardingConfigOption.cs @@ -78,6 +78,14 @@ namespace ShardingCore /// 连接数限制 /// public ConnectionModeEnum ConnectionMode { get; set; } + ///// + ///// 是否启用表路由编译缓存 + ///// + //public bool? EnableTableRouteCompileCache { get; set; } + ///// + ///// 是否启用分库路由编译缓存 + ///// + //public bool? EnableDataSourceRouteCompileCache { get; set; } } public interface IShardingConfigOption: IShardingConfigOption where TShardingDbContext : DbContext, IShardingDbContext diff --git a/src/ShardingCore/Sharding/MergeEngines/EnumeratorStreamMergeEngines/EnumeratorAsync/DefaultShardingEnumeratorAsyncStreamMergeEngine.cs b/src/ShardingCore/Sharding/MergeEngines/EnumeratorStreamMergeEngines/EnumeratorAsync/DefaultShardingEnumeratorAsyncStreamMergeEngine.cs index 0ad7a6ff..762a6322 100644 --- a/src/ShardingCore/Sharding/MergeEngines/EnumeratorStreamMergeEngines/EnumeratorAsync/DefaultShardingEnumeratorAsyncStreamMergeEngine.cs +++ b/src/ShardingCore/Sharding/MergeEngines/EnumeratorStreamMergeEngines/EnumeratorAsync/DefaultShardingEnumeratorAsyncStreamMergeEngine.cs @@ -70,7 +70,7 @@ namespace ShardingCore.Sharding.MergeEngines.EnumeratorStreamMergeEngines.Enumer IStreamMergeAsyncEnumerator[] streamsAsyncEnumerators) { if (StreamMergeContext.IsPaginationQuery()) - return new PaginationStreamMergeAsyncEnumerator(StreamMergeContext, streamsAsyncEnumerators,0, StreamMergeContext.GetPaginationReWriteTake()); + return new PaginationStreamMergeAsyncEnumerator(StreamMergeContext, streamsAsyncEnumerators,0, StreamMergeContext.GetPaginationReWriteTake());//ڴۺϷҳֱӻȡskipȡskip+takeĿ return base.CombineInMemoryStreamMergeAsyncEnumerator(streamsAsyncEnumerators); } } diff --git a/src/ShardingCore/Sharding/MergeEngines/EnumeratorStreamMergeEngines/EnumeratorAsync/ReverseShardingEnumeratorAsyncStreamMergeEngine.cs b/src/ShardingCore/Sharding/MergeEngines/EnumeratorStreamMergeEngines/EnumeratorAsync/ReverseShardingEnumeratorAsyncStreamMergeEngine.cs index 6d81745a..832a9630 100644 --- a/src/ShardingCore/Sharding/MergeEngines/EnumeratorStreamMergeEngines/EnumeratorAsync/ReverseShardingEnumeratorAsyncStreamMergeEngine.cs +++ b/src/ShardingCore/Sharding/MergeEngines/EnumeratorStreamMergeEngines/EnumeratorAsync/ReverseShardingEnumeratorAsyncStreamMergeEngine.cs @@ -82,6 +82,11 @@ namespace ShardingCore.Sharding.StreamMergeEngines.EnumeratorStreamMergeEngines. private IStreamMergeAsyncEnumerator DoGetStreamMergeAsyncEnumerator(IStreamMergeAsyncEnumerator[] streamsAsyncEnumerators) { + if (StreamMergeContext.IsPaginationQuery() && StreamMergeContext.HasGroupQuery()) + { + var multiAggregateOrderStreamMergeAsyncEnumerator = new MultiAggregateOrderStreamMergeAsyncEnumerator(StreamMergeContext, streamsAsyncEnumerators); + return new PaginationStreamMergeAsyncEnumerator(StreamMergeContext, new[] { multiAggregateOrderStreamMergeAsyncEnumerator }); + } if (StreamMergeContext.IsPaginationQuery()) return new PaginationStreamMergeAsyncEnumerator(StreamMergeContext, streamsAsyncEnumerators); if (StreamMergeContext.HasGroupQuery()) @@ -91,6 +96,11 @@ namespace ShardingCore.Sharding.StreamMergeEngines.EnumeratorStreamMergeEngines. public override IStreamMergeAsyncEnumerator CombineInMemoryStreamMergeAsyncEnumerator( IStreamMergeAsyncEnumerator[] streamsAsyncEnumerators) { + if (StreamMergeContext.IsPaginationQuery() && StreamMergeContext.HasGroupQuery()) + { + var multiAggregateOrderStreamMergeAsyncEnumerator = new MultiAggregateOrderStreamMergeAsyncEnumerator(StreamMergeContext, streamsAsyncEnumerators); + return new PaginationStreamMergeAsyncEnumerator(StreamMergeContext, new[] { multiAggregateOrderStreamMergeAsyncEnumerator }, 0, StreamMergeContext.GetPaginationReWriteTake()); + } if (StreamMergeContext.IsPaginationQuery()) return new PaginationStreamMergeAsyncEnumerator(StreamMergeContext, streamsAsyncEnumerators, 0, StreamMergeContext.GetPaginationReWriteTake()); return base.CombineInMemoryStreamMergeAsyncEnumerator(streamsAsyncEnumerators); diff --git a/src/ShardingCore/Sharding/ReadWriteConfigurations/Connectors/Abstractions/AbstractionReadWriteConnector.cs b/src/ShardingCore/Sharding/ReadWriteConfigurations/Connectors/Abstractions/AbstractionReadWriteConnector.cs index 4d068af7..a6fac62e 100644 --- a/src/ShardingCore/Sharding/ReadWriteConfigurations/Connectors/Abstractions/AbstractionReadWriteConnector.cs +++ b/src/ShardingCore/Sharding/ReadWriteConfigurations/Connectors/Abstractions/AbstractionReadWriteConnector.cs @@ -13,29 +13,21 @@ namespace ShardingCore.Sharding.ReadWriteConfigurations.Connectors.Abstractions { protected List ConnectionStrings { get;} protected int Length { get; private set; } - private readonly string _tempConnectionString; - private readonly OneByOneChecker _oneByOneChecker = new OneByOneChecker(); + //private readonly string _tempConnectionString; + //private readonly OneByOneChecker _oneByOneChecker = new OneByOneChecker(); public AbstractionReadWriteConnector(string dataSourceName,IEnumerable connectionStrings) { DataSourceName = dataSourceName; ConnectionStrings = connectionStrings.ToList(); Length = ConnectionStrings.Count; - _tempConnectionString = ConnectionStrings[0]; + //_tempConnectionString = ConnectionStrings[0]; } public string DataSourceName { get; } public string GetConnectionString() { - //没有必要用太过于复杂的锁简单的操作简单的锁最简单的了 - if (_oneByOneChecker.IsRunning()) - { - return _tempConnectionString; - } - else - { - return DoGetConnectionString(); - } + return DoGetConnectionString(); } public abstract string DoGetConnectionString(); @@ -47,23 +39,9 @@ namespace ShardingCore.Sharding.ReadWriteConfigurations.Connectors.Abstractions /// public bool AddConnectionString(string connectionString) { - if (_oneByOneChecker.Start()) - { - try - { - //是其他线程充分返回Connection并且感知到当前已在进行写入操作 - Thread.SpinWait(1); - ConnectionStrings.Add(connectionString); - Length = ConnectionStrings.Count; - return true; - } - finally - { - _oneByOneChecker.Stop(); - } - } - - return false; + ConnectionStrings.Add(connectionString); + Length = ConnectionStrings.Count; + return true; } } } diff --git a/src/ShardingCore/ShardingConfigOption.cs b/src/ShardingCore/ShardingConfigOption.cs index 3c4ee66a..47dd5ae9 100644 --- a/src/ShardingCore/ShardingConfigOption.cs +++ b/src/ShardingCore/ShardingConfigOption.cs @@ -234,5 +234,7 @@ namespace ShardingCore public string DefaultConnectionString { get; set; } public int MaxQueryConnectionsLimit { get; set; } = Environment.ProcessorCount; public ConnectionModeEnum ConnectionMode { get; set; } = ConnectionModeEnum.SYSTEM_AUTO; + //public bool? EnableTableRouteCompileCache { get; set; } + //public bool? EnableDataSourceRouteCompileCache { get; set; } } } \ No newline at end of file