-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.优化原有的DBS配置,破坏性修改,原有的DBS配置在多库和读写分离无法兼容,配置写法不是合适,故此优化 2.新增数据库故障转移方案,例如主库挂了自动切换到备用库,备用库不会由程序维护,需要运维、dba去做数据库同步方案,比如Sqlserver事务日志传输等 故障转移方案兼容多种方式 1.数据库主从方案 在配置主从之后,需要将从库配置为备用链接就行了 一般就是:修改、写入、删除走主库,查询操作走从库,在主库挂了后则所有操作走从库 2.数据库主备方案 日常使用主数据库操作,备用库只是备份,只有主库挂了才会用备用库 从库和备库都属于slave库功能
- Loading branch information
1 parent
dfa067d
commit 0901de2
Showing
16 changed files
with
363 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Linq; | ||
using SqlSugar; | ||
|
||
namespace Blog.Core.Common.DB.Aop; | ||
|
||
public class SqlSugarReuse | ||
{ | ||
public static void AutoChangeAvailableConnect(SqlSugarClient db) | ||
{ | ||
if (db == null) return; | ||
if (db.Ado.IsValidConnection()) return; | ||
if (!BaseDBConfig.ReuseConfigs.Any()) return; | ||
|
||
foreach (var connectionConfig in BaseDBConfig.ReuseConfigs) | ||
{ | ||
var config = db.CurrentConnectionConfig.ConfigId; | ||
db.ChangeDatabase(connectionConfig.ConfigId); | ||
//移除旧的连接,只会在本次上下文移除,因为主库已经故障会导致多库事务无法使用 | ||
db.RemoveConnection(config); | ||
if (db.Ado.IsValidConnection()) return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Reflection; | ||
using SqlSugar; | ||
|
||
namespace Blog.Core.Common.DB.Extension; | ||
|
||
public static class DbEntityException | ||
{ | ||
public static object GetEntityTenant(this Type type) | ||
{ | ||
var tenant = type.GetCustomAttribute<TenantAttribute>(); | ||
return tenant?.configId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.