Skip to content

Commit

Permalink
Replace the complex DeleteExecutions method body by simpler DropPrefi…
Browse files Browse the repository at this point in the history
…x in Badger 2
  • Loading branch information
Victor Castell committed Jul 15, 2019
1 parent 4b0d4d0 commit e2c448d
Showing 1 changed file with 1 addition and 51 deletions.
52 changes: 1 addition & 51 deletions dkron/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,57 +611,7 @@ func (s *Store) SetExecution(execution *Execution) (string, error) {
// DeleteExecutions removes all executions of a job
func (s *Store) DeleteExecutions(jobName string) error {
prefix := []byte(jobName)

// transaction may conflict
ConflictRetry:
for i := 0; i < defaultUpdateMaxAttempts; i++ {

// always retry when TxnTooBig is signalled
TxnTooBigRetry:
for {
txn := s.db.NewTransaction(true)
opts := badger.DefaultIteratorOptions
opts.PrefetchValues = false

it := txn.NewIterator(opts)

for it.Seek(prefix); it.ValidForPrefix(prefix); it.Next() {
k := it.Item().KeyCopy(nil)

err := txn.Delete(k)
it.Close()
if err != badger.ErrTxnTooBig {
return err
}

err = txn.Commit()

// commit failed with conflict
if err == badger.ErrConflict {
continue ConflictRetry
}

if err != nil {
return err
}

// open new transaction and continue
continue TxnTooBigRetry
}

it.Close()
err := txn.Commit()

// commit failed with conflict
if err == badger.ErrConflict {
continue ConflictRetry
}

return err
}
}

return ErrTooManyUpdateConflicts
return s.db.DropPrefix(prefix)
}

// Shutdown close the KV store
Expand Down

0 comments on commit e2c448d

Please sign in to comment.