<commit_before>package transaction

import (
	"fmt"
	"log"
)

type RollbackTask struct {
	Name string
	Func func() error
}

type Transaction struct {
	stack []*RollbackTask
}

func Begin() *Transaction {
	t := &Transaction{}
	t.stack = make([]*RollbackTask, 0)

	return &Transaction{}
}

func (tx *Transaction) PushRollback(name string, f func() error) {
	tx.stack = append(tx.stack, &RollbackTask{
		Name: name,
		Func: f,
	})
}

func (tx *Transaction) PopRollback() *RollbackTask {
	l := len(tx.stack)
	if l == 0 {
		return nil
	}

	ret := tx.stack[l-1]
	tx.stack = tx.stack[:l-1]

	return ret
}

func (tx *Transaction) Rollback() error {
	errMes := ""

	for r := tx.PopRollback(); r != nil; r = tx.PopRollback() {
		if err := r.Func(); err != nil {<commit_msg>add exponentil backoff on rollback to increase the rollback success rate<commit_after>package transaction

import (
	"fmt"
	"log"

	"github.com/cenkalti/backoff"
)

type RollbackTask struct {
	Name string
	Func func() error
}

type Transaction struct {
	stack []*RollbackTask
}

func Begin() *Transaction {
	t := &Transaction{}
	t.stack = make([]*RollbackTask, 0)

	return &Transaction{}
}

func (tx *Transaction) PushRollback(name string, f func() error) {
	tx.stack = append(tx.stack, &RollbackTask{
		Name: name,
		Func: f,
	})
}

func (tx *Transaction) PopRollback() *RollbackTask {
	l := len(tx.stack)
	if l == 0 {
		return nil
	}

	ret := tx.stack[l-1]
	tx.stack = tx.stack[:l-1]

	return ret
}

func (tx *Transaction) Rollback() error {
	errMes := ""

	for r := tx.PopRollback(); r != nil; r = tx.PopRollback() {
		b := backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 5)
		err := backoff.Retry(r.Func, b)
		if err != nil {
{'fraction_non_alphanumeric': 0.15588235294117647, 'fraction_numerical': 0.005294117647058823, 'mean_word_length': 3.9020172910662825, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7379405', 'n_tokens_mistral': 658, 'n_tokens_neox': 632, 'n_words': 173}