移除useMemorySkip的参数系统采用自行处理并且发布x.3.1.71

This commit is contained in:
xuejiaming 2021-12-06 23:46:13 +08:00
parent f18872cc60
commit 646b01bcbb
16 changed files with 103 additions and 39 deletions

BIN
Logo/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -55,7 +55,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShardingCoreBenchmark", "benchmarks\ShardingCoreBenchmark\ShardingCoreBenchmark.csproj", "{8CE5E8AF-DDB7-4989-8AA4-1D47E4226846}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShardingCoreBenchmark5x", "benchmarks\ShardingCoreBenchmark5x\ShardingCoreBenchmark5x.csproj", "{ED191305-AB19-4863-A48A-7BA4C21F467B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShardingCoreBenchmark5x", "benchmarks\ShardingCoreBenchmark5x\ShardingCoreBenchmark5x.csproj", "{ED191305-AB19-4863-A48A-7BA4C21F467B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -1,9 +1,9 @@
:start
::定义版本
set EFCORE2=2.3.1.68
set EFCORE3=3.3.1.68
set EFCORE5=5.3.1.68
set EFCORE6=6.3.1.68
set EFCORE2=2.3.1.71
set EFCORE3=3.3.1.71
set EFCORE5=5.3.1.71
set EFCORE6=6.3.1.71
::删除所有bin与obj下的文件
@echo off

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Sample.SqlServer.Domain.Maps;
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
using ShardingCore.Sharding;
using ShardingCore.Sharding.Abstractions;
namespace Sample.SqlServer.DbContexts
{
public class DefaultShardingDbContext1:AbstractShardingDbContext, IShardingTableDbContext
{
public DefaultShardingDbContext1(DbContextOptions<DefaultShardingDbContext1> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
public IRouteTail RouteTail { get; set; }
}
}

View File

@ -43,7 +43,6 @@ namespace Sample.SqlServer.Shardings
public override void Configure(EntityMetadataTableBuilder<SysUserMod> builder)
{
}
}
}

View File

@ -10,6 +10,7 @@ using ShardingCore;
using ShardingCore.Sharding.ReadWriteConfigurations;
using System;
using System.Collections.Generic;
using ShardingCore.Core;
namespace Sample.SqlServer
{
@ -34,6 +35,8 @@ namespace Sample.SqlServer
o.CreateShardingTableOnStart = true;
o.EnsureCreatedWithOutShardingTable = true;
o.AutoTrackEntity = true;
o.MaxQueryConnectionsLimit = Environment.ProcessorCount;
o.ConnectionMode = ConnectionModeEnum.SYSTEM_AUTO;
//if SysTest entity not exists in db and db is exists
//o.AddEntityTryCreateTable<SysTest>(); // or `o.AddEntitiesTryCreateTable(typeof(SysTest));`
})
@ -48,6 +51,27 @@ namespace Sample.SqlServer
o.AddShardingTableRoute<SysUserSalaryVirtualTableRoute>();
o.AddShardingTableRoute<TestYearShardingVirtualTableRoute>();
}).End();
services.AddShardingDbContext<DefaultShardingDbContext1>(
(conn, o) =>
o.UseSqlServer(conn).UseLoggerFactory(efLogger)
).Begin(o =>
{
o.CreateShardingTableOnStart = true;
o.EnsureCreatedWithOutShardingTable = true;
o.AutoTrackEntity = true;
o.MaxQueryConnectionsLimit = Environment.ProcessorCount;
o.ConnectionMode = ConnectionModeEnum.SYSTEM_AUTO;
//if SysTest entity not exists in db and db is exists
//o.AddEntityTryCreateTable<SysTest>(); // or `o.AddEntitiesTryCreateTable(typeof(SysTest));`
})
//.AddShardingQuery((conStr, builder) => builder.UseSqlServer(conStr).UseLoggerFactory(efLogger))//无需添加.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) 并发查询系统会自动添加NoTracking
.AddShardingTransaction((connection, builder) =>
builder.UseSqlServer(connection).UseLoggerFactory(efLogger))
.AddDefaultDataSource("A",
"Data Source=localhost;Initial Catalog=ShardingCoreDBXA;Integrated Security=True;")
.AddShardingTableRoute(o =>
{
}).End();
services.AddHealthChecks().AddDbContextCheck<DefaultShardingDbContext>();
//services.AddShardingDbContext<DefaultShardingDbContext, DefaultTableDbContext>(

View File

@ -1,14 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.Extensions.Logging;
using ShardingCore.Core.EntityMetadatas;
using ShardingCore.Core.EntityShardingMetadatas;
using ShardingCore.Core.PhysicTables;
using ShardingCore.Core.TrackerManagers;
using ShardingCore.Core.VirtualDatabase.VirtualDataSources;
using ShardingCore.Core.VirtualDatabase.VirtualTables;
@ -20,10 +14,11 @@ using ShardingCore.Extensions;
using ShardingCore.Helpers;
using ShardingCore.Jobs;
using ShardingCore.Jobs.Abstaractions;
using ShardingCore.Jobs.Impls;
using ShardingCore.Sharding.Abstractions;
using ShardingCore.TableCreator;
using ShardingCore.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
/*
* @Author: xjm
@ -33,6 +28,11 @@ using ShardingCore.Utils;
*/
namespace ShardingCore.Bootstrapers
{
/// <summary>
/// 对象元数据初始化器
/// </summary>
/// <typeparam name="TShardingDbContext"></typeparam>
/// <typeparam name="TEntity"></typeparam>
public class EntityMetadataInitializer<TShardingDbContext,TEntity>: IEntityMetadataInitializer where TShardingDbContext:DbContext,IShardingDbContext where TEntity:class
{
private readonly IEntityType _entityType;
@ -42,26 +42,31 @@ namespace ShardingCore.Bootstrapers
private readonly IVirtualDataSource<TShardingDbContext> _virtualDataSource;
private readonly IVirtualTableManager<TShardingDbContext> _virtualTableManager;
private readonly IEntityMetadataManager<TShardingDbContext> _entityMetadataManager;
private readonly IShardingTableCreator<TShardingDbContext> _tableCreator;
private readonly ILogger<EntityMetadataInitializer<TShardingDbContext, TEntity>> _logger;
public EntityMetadataInitializer(EntityMetadataEnsureParams entityMetadataEnsureParams
, IShardingConfigOption shardingConfigOption,
, IEnumerable<IShardingConfigOption> shardingConfigOptions,
ITrackerManager<TShardingDbContext> trackerManager,IVirtualDataSource<TShardingDbContext> virtualDataSource,IVirtualTableManager<TShardingDbContext> virtualTableManager,
IEntityMetadataManager<TShardingDbContext> entityMetadataManager, IShardingTableCreator<TShardingDbContext> tableCreator,
IEntityMetadataManager<TShardingDbContext> entityMetadataManager,
ILogger<EntityMetadataInitializer<TShardingDbContext, TEntity>> logger
)
{
_entityType = entityMetadataEnsureParams.EntityType;
_virtualTableName = entityMetadataEnsureParams.VirtualTableName;
_shardingConfigOption = shardingConfigOption;
_shardingConfigOption = shardingConfigOptions.FirstOrDefault(o=>o.ShardingDbContextType==typeof(TShardingDbContext));
_trackerManager = trackerManager;
_virtualDataSource = virtualDataSource;
_virtualTableManager = virtualTableManager;
_entityMetadataManager = entityMetadataManager;
_tableCreator = tableCreator;
_logger = logger;
}
/// <summary>
/// 初始化
/// 针对对象在dbcontext中的主键获取
/// 并且针对分库下的特性加接口的支持,然后是分库路由的配置覆盖
/// 分表下的特性加接口的支持,然后是分表下的路由的配置覆盖
/// </summary>
/// <exception cref="ShardingCoreInvalidOperationException"></exception>
public void Initialize()
{
var shardingEntityType = _entityType.ClrType;

View File

@ -53,7 +53,7 @@ namespace ShardingCore
Action<IServiceProvider, DbContextOptionsBuilder> shardingOptionAction = (sp, option) =>
{
var virtualDataSource = sp.GetRequiredService<IVirtualDataSource<TShardingDbContext>> ();
var connectionString = virtualDataSource.GetDefaultDataSource().ConnectionString;
var connectionString = virtualDataSource.GetConnectionString(virtualDataSource.DefaultDataSourceName);
optionsAction?.Invoke(connectionString, option);
option.UseSharding<TShardingDbContext>();
};

View File

@ -45,7 +45,6 @@ namespace ShardingCore.DIExtensions
ShardingConfigOption.IgnoreCreateTableError = shardingCoreBeginOptions.IgnoreCreateTableError;
ShardingConfigOption.MaxQueryConnectionsLimit = shardingCoreBeginOptions.MaxQueryConnectionsLimit;
ShardingConfigOption.ConnectionMode = shardingCoreBeginOptions.ConnectionMode;
ShardingConfigOption.UseMemoryLimitWhileSkip = shardingCoreBeginOptions.UseMemoryLimitWhileSkip;
foreach (var entityType in shardingCoreBeginOptions.GetCreateTableEntities())
{
ShardingConfigOption.AddEntityTryCreateTable(entityType);
@ -97,7 +96,6 @@ 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 int UseMemoryLimitWhileSkip { get; set; } = 10000;
private readonly ISet<Type> _createTableEntities = new HashSet<Type>();

View File

@ -78,10 +78,6 @@ namespace ShardingCore
/// 连接数限制
/// </summary>
public ConnectionModeEnum ConnectionMode { get; set; }
/// <summary>
/// 当ConnectionMode == SYSTEM_AUTO时生效
/// </summary>
public int UseMemoryLimitWhileSkip { get; set; }
}
public interface IShardingConfigOption<TShardingDbContext>: IShardingConfigOption where TShardingDbContext : DbContext, IShardingDbContext

View File

@ -222,20 +222,12 @@ namespace ShardingCore.Sharding
case ConnectionModeEnum.CONNECTION_STRICTLY: return _shardingConfigOption.ConnectionMode;
default:
{
if (Skip.HasValue && Skip.Value > _shardingConfigOption.UseMemoryLimitWhileSkip)
{
return ConnectionModeEnum.MEMORY_STRICTLY;
}
return _shardingConfigOption.MaxQueryConnectionsLimit < sqlCount
? ConnectionModeEnum.CONNECTION_STRICTLY
: ConnectionModeEnum.MEMORY_STRICTLY; ;
}
}
}
public int GetUseMemoryLimitWhileSkip()
{
return _shardingConfigOption.UseMemoryLimitWhileSkip;
}
/// <summary>
/// 是否是跨资源查询
/// </summary>

View File

@ -234,6 +234,5 @@ namespace ShardingCore
public string DefaultConnectionString { get; set; }
public int MaxQueryConnectionsLimit { get; set; } = Environment.ProcessorCount;
public ConnectionModeEnum ConnectionMode { get; set; } = ConnectionModeEnum.SYSTEM_AUTO;
public int UseMemoryLimitWhileSkip { get; set; } = 10000;
}
}

View File

@ -6,6 +6,7 @@
<DefineConstants>TRACE;DEBUG;EFCORE6;</DefineConstants>
<LangVersion>9.0</LangVersion>
<RepositoryUrl>https://github.com/xuejmnet/sharding-core</RepositoryUrl>
<PackageIcon>logo.png</PackageIcon>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@ -15,6 +16,12 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\Logo\logo.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
@ -16,6 +16,12 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<DocumentationFile>bin\Release\ShardingCore.2x.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\Logo\logo.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup>

View File

@ -16,6 +16,12 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<DocumentationFile>bin\Release\ShardingCore.3x.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\Logo\logo.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup>

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
@ -15,6 +15,12 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<DocumentationFile>bin\Release\ShardingCore.5x.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\Logo\logo.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup>