Skip to content

Commit

Permalink
Turn off the history compaction by default
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
  • Loading branch information
peterbroadhurst committed Jul 2, 2023
1 parent 581fe26 commit 4771ba8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion config.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
|batchTimeout|Duration to hold batch open for new transaction operations before flushing to the DB|[`time.Duration`](https://pkg.go.dev/time#Duration)|`10ms`
|cacheSlots|Number of transactions to hold cached metadata for to avoid DB read operations to calculate history|`int`|`1000`
|count|Number of transactions writing routines to start|`int`|`5`
|historyCompactionInterval|Duration between cleanup activities on the DB for a transaction with a large history|[`time.Duration`](https://pkg.go.dev/time#Duration)|`5m`
|historyCompactionInterval|Duration between cleanup activities on the DB for a transaction with a large history|[`time.Duration`](https://pkg.go.dev/time#Duration)|`0`
|historySummaryLimit|Maximum number of action entries to return embedded in the JSON response object when querying a transaction summary|`int`|`50`

## policyengine
Expand Down
2 changes: 1 addition & 1 deletion internal/persistence/postgres/sqlpersistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func InitConfig(conf config.Section) {

conf.AddKnownKey(ConfigTXWriterCacheSlots, 1000)
conf.AddKnownKey(ConfigTXWriterHistorySummaryLimit, 50) // returned on TX status
conf.AddKnownKey(ConfigTXWriterHistoryCompactionInterval, "5m")
conf.AddKnownKey(ConfigTXWriterHistoryCompactionInterval, "0" /* disabled by default */)
conf.AddKnownKey(ConfigTXWriterCount, 5)
conf.AddKnownKey(ConfigTXWriterBatchTimeout, "10ms")
conf.AddKnownKey(ConfigTXWriterBatchSize, 100)
Expand Down
5 changes: 4 additions & 1 deletion internal/persistence/postgres/sqlpersistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ import (
"github.com/stretchr/testify/assert"
)

func newMockSQLPersistence(t *testing.T) (context.Context, *sqlPersistence, sqlmock.Sqlmock, func()) {
func newMockSQLPersistence(t *testing.T, init ...func(dbconf config.Section)) (context.Context, *sqlPersistence, sqlmock.Sqlmock, func()) {

ctx, cancelCtx := context.WithCancel(context.Background())
db, dbm := dbsql.NewMockProvider().UTInit()

config.RootConfigReset()
dbconf := config.RootSection("utdb")
InitConfig(dbconf)
for _, fn := range init {
fn(dbconf)
}

p, err := newSQLPersistence(ctx, &db.Database, dbconf, 1*time.Hour)
assert.NoError(t, err)
Expand Down
10 changes: 6 additions & 4 deletions internal/persistence/postgres/transaction_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,12 @@ func (tw *transactionWriter) executeBatchOps(ctx context.Context, b *transaction
}
}
// Do the compression checks
for txID := range b.compressionChecks {
if err := tw.compressionCheck(ctx, txID); err != nil {
log.L(ctx).Errorf("Compression check for %s failed: %s", txID, err)
return err
if tw.compressionInterval > 0 {
for txID := range b.compressionChecks {
if err := tw.compressionCheck(ctx, txID); err != nil {
log.L(ctx).Errorf("Compression check for %s failed: %s", txID, err)
return err
}
}
}
// Do all the transaction deletes
Expand Down
13 changes: 10 additions & 3 deletions internal/persistence/postgres/txhistory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/DATA-DOG/go-sqlmock"
"github.com/hyperledger/firefly-common/pkg/config"
"github.com/hyperledger/firefly-common/pkg/fftypes"
"github.com/hyperledger/firefly-transaction-manager/internal/persistence"
"github.com/hyperledger/firefly-transaction-manager/pkg/apitypes"
Expand All @@ -35,7 +36,9 @@ func TestTXHistoryCompressionPSQL(t *testing.T) {
logrus.SetLevel(logrus.TraceLevel)

// Do a set of transaction operations through the writers, and confirm the results are correct
ctx, p, _, done := initTestPSQL(t)
ctx, p, _, done := initTestPSQL(t, func(conf config.Section) {
conf.Set(ConfigTXWriterHistoryCompactionInterval, "5m")
})
defer done()

// Write an initial transaction
Expand Down Expand Up @@ -182,7 +185,9 @@ func TestTXHistoryCompressionPSQL(t *testing.T) {
}

func TestCompactionFail(t *testing.T) {
ctx, p, mdb, done := newMockSQLPersistence(t)
ctx, p, mdb, done := newMockSQLPersistence(t, func(dbconf config.Section) {
dbconf.Set(ConfigTXWriterHistoryCompactionInterval, "5m")
})
defer done()

longAgo := time.Now().Add(-1000 * time.Hour)
Expand Down Expand Up @@ -238,7 +243,9 @@ func TestCompactionFail(t *testing.T) {
}

func TestCompactionOnCacheMiss(t *testing.T) {
ctx, p, mdb, done := newMockSQLPersistence(t)
ctx, p, mdb, done := newMockSQLPersistence(t, func(dbconf config.Section) {
dbconf.Set(ConfigTXWriterHistoryCompactionInterval, "5m")
})
defer done()

b := &transactionWriterBatch{
Expand Down

0 comments on commit 4771ba8

Please sign in to comment.