Skip to content

Commit

Permalink
review followup
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Oct 11, 2024
1 parent 71ce774 commit f654628
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type CoreConfig struct {

ExtensionModeFile string `long:"extension-mode-file" description:"path to a file that specifies options for running core as an extension."`

PruneArchive uint64 `long:"prunearchive" description:"prune that order archive to the specified number of most recent orders"`
PruneArchive uint64 `long:"prunearchive" description:"prune that order archive to the specified number of most recent orders. zero means no pruning."`
}

// WebConfig encapsulates the configuration needed for the web server.
Expand Down
18 changes: 12 additions & 6 deletions client/db/bolt/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ func (db *BoltDB) pruneArchivedOrders(prunedSize uint64) error {
return fmt.Errorf("failed to open %s bucket", string(archivedOrdersBucket))
}

nOrds := uint64(archivedOB.Stats().BucketN - 1 /* BucketN includes top bucket */)
if nOrds <= prunedSize {
return nil
}

// We won't delete any orders with active matches.
activeMatches := tx.Bucket(activeMatchesBucket)
if activeMatches == nil {
Expand All @@ -441,11 +446,6 @@ func (db *BoltDB) pruneArchivedOrders(prunedSize uint64) error {
return fmt.Errorf("error building active match order ID index: %w", err)
}

nOrds := uint64(archivedOB.Stats().BucketN - 1 /* BucketN includes top bucket */)
if nOrds <= prunedSize {
return nil
}

toClear := int(nOrds - prunedSize)

type orderStamp struct {
Expand All @@ -458,6 +458,7 @@ func (db *BoltDB) pruneArchivedOrders(prunedSize uint64) error {
return deletes[i].stamp < deletes[j].stamp
})
}
var sortedAtCapacity bool
if err := archivedOB.ForEach(func(oidB, v []byte) error {
var oid order.OrderID
copy(oid[:], oidB)
Expand All @@ -479,9 +480,14 @@ func (db *BoltDB) pruneArchivedOrders(prunedSize uint64) error {
stamp: stamp,
oid: oidB,
})
sortDeletes()
return nil
}
if !sortedAtCapacity {
// Make sure the last element is the newest one once we hit
// capacity.
sortDeletes()
sortedAtCapacity = true
}
if stamp > deletes[len(deletes)-1].stamp {
return nil
}
Expand Down

0 comments on commit f654628

Please sign in to comment.