mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-10 08:29:32 +00:00
feat: use XORM EngineGroup instead of single Engine connection (#7212)
Resolves #7207 Add new configuration to make XORM work with a main and replicas database instances. The follow configuration parameters were added: - `HOST_PRIMARY` - `HOST_REPLICAS` - `LOAD_BALANCE_POLICY`. Options: - `"WeightRandom"` -> `xorm.WeightRandomPolicy` - `"WeightRoundRobin` -> `WeightRoundRobinPolicy` - `"LeastCon"` -> `LeastConnPolicy` - `"RoundRobin"` -> `xorm.RoundRobinPolicy()` - default: `xorm.RandomPolicy()` - `LOAD_BALANCE_WEIGHTS` Co-authored-by: pat-s <patrick.schratz@gmail.com@> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7212 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: pat-s <patrick.schratz@gmail.com> Co-committed-by: pat-s <patrick.schratz@gmail.com>
This commit is contained in:
parent
a23d0453a3
commit
63a80bf2b9
19 changed files with 463 additions and 129 deletions
|
@ -278,23 +278,36 @@ func doMigrationTest(t *testing.T, version string) {
|
|||
|
||||
setting.InitSQLLoggersForCli(log.INFO)
|
||||
|
||||
err := db.InitEngineWithMigration(t.Context(), wrappedMigrate)
|
||||
err := db.InitEngineWithMigration(t.Context(), func(e db.Engine) error {
|
||||
engine, err := db.GetMasterEngine(e)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
currentEngine = engine
|
||||
return wrappedMigrate(engine)
|
||||
})
|
||||
require.NoError(t, err)
|
||||
currentEngine.Close()
|
||||
|
||||
beans, _ := db.NamesToBean()
|
||||
|
||||
err = db.InitEngineWithMigration(t.Context(), func(x *xorm.Engine) error {
|
||||
currentEngine = x
|
||||
return migrate_base.RecreateTables(beans...)(x)
|
||||
err = db.InitEngineWithMigration(t.Context(), func(e db.Engine) error {
|
||||
currentEngine, err = db.GetMasterEngine(e)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return migrate_base.RecreateTables(beans...)(currentEngine)
|
||||
})
|
||||
require.NoError(t, err)
|
||||
currentEngine.Close()
|
||||
|
||||
// We do this a second time to ensure that there is not a problem with retained indices
|
||||
err = db.InitEngineWithMigration(t.Context(), func(x *xorm.Engine) error {
|
||||
currentEngine = x
|
||||
return migrate_base.RecreateTables(beans...)(x)
|
||||
err = db.InitEngineWithMigration(t.Context(), func(e db.Engine) error {
|
||||
currentEngine, err = db.GetMasterEngine(e)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return migrate_base.RecreateTables(beans...)(currentEngine)
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue