Skip to content

Commit

Permalink
client/db/bolt: fix bug with archive summary
Browse files Browse the repository at this point in the history
The number of archived orders or matches returned by
DeleteInactiveOrders and DeleteInactiveMatches was incorrect
if there were more than 1000 (more than one batch).

This fixes it so the tests pass when not run with -short.
  • Loading branch information
chappjc committed Feb 22, 2023
1 parent 459fead commit facce62
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions client/db/bolt/db.go
Expand Up @@ -1914,7 +1914,7 @@ func (db *BoltDB) DeleteInactiveOrders(ctx context.Context, olderThan *time.Time
return err
}
start := time.Now()
nDeletedOrders = 0
nDeletedBatch := 0
err := db.Update(func(tx *bbolt.Tx) error {
// Run through the archived order bucket storing id's keys for
// returning the order data and deletion later.
Expand Down Expand Up @@ -1960,14 +1960,16 @@ func (db *BoltDB) DeleteInactiveOrders(ctx context.Context, olderThan *time.Time
return fmt.Errorf("problem performing batch function: %v", err)
}
}
nDeletedOrders++
nDeletedBatch++
}
db.log.Infof("Deleted %d orders from the database in %v.", nDeletedOrders, time.Since(start))
nDeletedOrders += nDeletedBatch
db.log.Infof("Deleted %d orders (%d total) from the database in %v.",
nDeletedBatch, nDeletedOrders, time.Since(start))
return nil
})
if err != nil {
if perOrderFn != nil && nDeletedOrders != 0 {
db.log.Warnf("%d orders reported as deleted have been rolled back due to error.", nDeletedOrders)
if perOrderFn != nil && nDeletedBatch != 0 {
db.log.Warnf("%d orders reported as deleted have been rolled back due to error.", nDeletedBatch)
}
return fmt.Errorf("unable to delete orders: %v", err)
}
Expand Down Expand Up @@ -2051,7 +2053,7 @@ func (db *BoltDB) DeleteInactiveMatches(ctx context.Context, olderThan *time.Tim
return err
}
start := time.Now()
nDeletedMatches = 0
nDeletedBatch := 0
if err := db.Update(func(tx *bbolt.Tx) error {
archivedMB := tx.Bucket(archivedMatchesBucket)
if archivedMB == nil {
Expand Down Expand Up @@ -2096,13 +2098,16 @@ func (db *BoltDB) DeleteInactiveMatches(ctx context.Context, olderThan *time.Tim
return fmt.Errorf("problem performing batch function: %v", err)
}
}
nDeletedMatches++
nDeletedBatch++
}
db.log.Infof("Deleted %d matches from the database in %v.", nDeletedMatches, time.Since(start))
nDeletedMatches += nDeletedBatch
db.log.Infof("Deleted %d matches (%d total) from the database in %v.",
nDeletedBatch, nDeletedMatches, time.Since(start))

return nil
}); err != nil {
if perMatchFn != nil && nDeletedMatches != 0 {
db.log.Warnf("%d matches reported as deleted have been rolled back due to error.", nDeletedMatches)
if perMatchFn != nil && nDeletedBatch != 0 {
db.log.Warnf("%d matches reported as deleted have been rolled back due to error.", nDeletedBatch)
}
return fmt.Errorf("unable to delete matches: %v", err)
}
Expand Down

0 comments on commit facce62

Please sign in to comment.