Commit 38f7fb5f authored by linj's avatar linj

增加 trade Upgrade

parent 11c2be11
...@@ -29,16 +29,21 @@ const ( ...@@ -29,16 +29,21 @@ const (
orderASTHK = "LODB-trade-order-asthk:" orderASTHK = "LODB-trade-order-asthk:"
) )
// Upgrade 实现升级接口
func (t *trade) Upgrade() error {
localDB := t.GetLocalDB()
return TradeUpdateLocalDBV2(localDB, 0)
}
// TradeUpdateLocalDBV2 trade 本地数据库升级 // TradeUpdateLocalDBV2 trade 本地数据库升级
// from 1 to 2 // from 1 to 2
func TradeUpdateLocalDBV2(localDB dbm.DB, total int) error { func TradeUpdateLocalDBV2(localDB dbm.KVDB, total int) error {
// 外部不指定, 强制分批执行 // 外部不指定, 强制分批执行
if total <= 0 { if total <= 0 {
total = 10000 total = 10000
} }
toVersion := 2 toVersion := 2
kvdb := dbm.NewKVDB(localDB) version, err := getVersion(localDB)
version, err := getVersion(kvdb)
if err != nil { if err != nil {
tradelog.Error("TradeUpdateLocalDBV2 get version", "err", err) tradelog.Error("TradeUpdateLocalDBV2 get version", "err", err)
return errors.Cause(err) return errors.Cause(err)
...@@ -47,15 +52,16 @@ func TradeUpdateLocalDBV2(localDB dbm.DB, total int) error { ...@@ -47,15 +52,16 @@ func TradeUpdateLocalDBV2(localDB dbm.DB, total int) error {
return nil return nil
} }
err = UpdateLocalDBPart2(kvdb, total) err = UpdateLocalDBPart2(localDB, total)
if err != nil { if err != nil {
return err return err
} }
err = UpdateLocalDBPart1(localDB, total) // TODO input DB to KVDB
err = UpdateLocalDBPart1(nil, total)
if err != nil { if err != nil {
return err return err
} }
return setVersion(kvdb, toVersion) return setVersion(localDB, toVersion)
} }
// UpdateLocalDBPart1 手动生成KV,需要在原有数据库中删除 // UpdateLocalDBPart1 手动生成KV,需要在原有数据库中删除
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment