Skip to content

Commit

Permalink
upgrade logger, log matches upgrade outcome
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc committed Nov 11, 2021
1 parent 7909ec7 commit e2b65e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions client/db/bolt/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"

dexdb "decred.org/dcrdex/client/db"
"decred.org/dcrdex/dex"
"decred.org/dcrdex/dex/encode"
"decred.org/dcrdex/dex/order"
"go.etcd.io/bbolt"
Expand Down Expand Up @@ -57,6 +58,8 @@ func setDBVersion(tx *bbolt.Tx, newVersion uint32) error {
return bucket.Put(versionKey, encode.Uint32Bytes(newVersion))
}

var upgradeLog = dex.Disabled

// upgradeDB checks whether any upgrades are necessary before the database is
// ready for application usage. If any are, they are performed.
func (db *BoltDB) upgradeDB() error {
Expand All @@ -77,6 +80,7 @@ func (db *BoltDB) upgradeDB() error {
}

db.log.Infof("Upgrading database from version %d to %d", version, DBVersion)
upgradeLog = db.log

// Backup the current version's DB file before processing the upgrades to
// DBVersion. Note that any intermediate versions are not stored.
Expand Down Expand Up @@ -307,6 +311,12 @@ func v6Upgrade(dbtx *bbolt.Tx) error {
return err
}

var nActive, nArchived int

defer func() {
upgradeLog.Infof("%d active matches moved, %d archived matches unmoved", nActive, nArchived)
}()

archivedMatchesBkt := dbtx.Bucket(oldMatchesBucket)
activeMatchesBkt := dbtx.Bucket(newActiveMatchesBucket)

Expand All @@ -333,9 +343,15 @@ func v6Upgrade(dbtx *bbolt.Tx) error {
}
// If match is active, move to activeMatchesBucket.
if !dexdb.MatchIsActive(match, proof) {
nArchived++
return nil
}

upgradeLog.Infof("Moving match %v (%v, revoked = %v, refunded = %v, sigs (init/redeem): %v, %v) to active bucket.",
match, match.Status, proof.IsRevoked(), len(proof.RefundCoin) > 0,
len(proof.Auth.InitSig) > 0, len(proof.Auth.RedeemSig) > 0)
nActive++

activeMBkt, err := activeMatchesBkt.CreateBucket(k)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions client/db/bolt/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var dbUpgradeTests = [...]struct {
}

func TestUpgrades(t *testing.T) {
upgradeLog = tLogger
t.Run("group", func(t *testing.T) {
for _, tc := range dbUpgradeTests {
tc := tc // capture range variable
Expand Down

0 comments on commit e2b65e7

Please sign in to comment.