Skip to content

Commit

Permalink
feat: remove MOVES_HISTORY_POST_COMMIT_VOLUMES
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 16, 2024
1 parent cd1cd2b commit ccc85bf
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.
20 changes: 10 additions & 10 deletions internal/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ package ledger

import (
"fmt"
"regexp"

"github.com/formancehq/go-libs/metadata"
"github.com/formancehq/go-libs/time"
"regexp"
"slices"
)

const (
FeatureMovesHistory = "MOVES_HISTORY"
// todo: depends on FeatureMovesHistory
// todo: it should not be required as we have the information when updating volumes
FeatureMovesHistoryPostCommitVolumes = "MOVES_HISTORY_POST_COMMIT_VOLUMES"
// todo: depends on FeatureMovesHistory
// todo: depends on FeatureMovesHistory (dependency should be checked)
FeatureMovesHistoryPostCommitEffectiveVolumes = "MOVES_HISTORY_POST_COMMIT_EFFECTIVE_VOLUMES"
FeatureHashLogs = "HASH_LOGS"
FeatureAccountMetadataHistory = "ACCOUNT_METADATA_HISTORY"
Expand All @@ -30,7 +27,6 @@ const (
var (
DefaultFeatures = FeatureSet{
FeatureMovesHistory: "ON",
FeatureMovesHistoryPostCommitVolumes: "SYNC",
FeatureMovesHistoryPostCommitEffectiveVolumes: "SYNC",
FeatureHashLogs: "SYNC",
FeatureAccountMetadataHistory: "SYNC",
Expand All @@ -40,7 +36,6 @@ var (
}
MinimalFeatureSet = FeatureSet{
FeatureMovesHistory: "OFF",
FeatureMovesHistoryPostCommitVolumes: "DISABLED",
FeatureMovesHistoryPostCommitEffectiveVolumes: "DISABLED",
FeatureHashLogs: "DISABLED",
FeatureAccountMetadataHistory: "DISABLED",
Expand All @@ -50,7 +45,6 @@ var (
}
FeatureConfigurations = map[string][]string{
FeatureMovesHistory: {"ON", "OFF"},
FeatureMovesHistoryPostCommitVolumes: {"SYNC", "DISABLED"},
FeatureMovesHistoryPostCommitEffectiveVolumes: {"SYNC", "DISABLED"},
FeatureHashLogs: {"SYNC", "DISABLED"},
FeatureAccountMetadataHistory: {"SYNC", "DISABLED"},
Expand Down Expand Up @@ -113,7 +107,13 @@ type Ledger struct {
}

func (l Ledger) HasFeature(feature, value string) bool {
// todo: to avoid development error we could check if the value is possible
possibleConfigurations, ok := FeatureConfigurations[feature]
if !ok {
panic(fmt.Sprintf("feature %q not exists", feature))
}
if !slices.Contains(possibleConfigurations, value) {
panic(fmt.Sprintf("configuration %s it not possible for feature %s", value, feature))
}
return l.Features[feature] == value
}

Expand Down
6 changes: 1 addition & 5 deletions internal/storage/ledger/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ func (s *Store) selectAccounts(date *time.Time, expandVolumes, expandEffectiveVo
}
}

if needPCV && !s.ledger.HasFeature(ledger.FeatureMovesHistoryPostCommitVolumes, "SYNC") {
return ret.Err(ledgercontroller.NewErrMissingFeature(ledger.FeatureMovesHistoryPostCommitVolumes))
}

// build the query
ret = ret.
ModelTableExpr(s.GetPrefixedRelationName("accounts")).
Expand All @@ -188,7 +184,7 @@ func (s *Store) selectAccounts(date *time.Time, expandVolumes, expandEffectiveVo

// todo: should join on histories only if pit is specified
// otherwise the accounts_volumes table is enough
if s.ledger.HasFeature(ledger.FeatureMovesHistoryPostCommitVolumes, "SYNC") && needPCV {
if s.ledger.HasFeature(ledger.FeatureMovesHistory, "ON") && needPCV {
ret = ret.
Join(
`left join (?) pcv on pcv.accounts_seq = accounts.seq`,
Expand Down
4 changes: 2 additions & 2 deletions internal/storage/ledger/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func (s *Store) selectAccountWithVolumes(date *time.Time, useInsertionDate bool,
var selectAccountsWithVolumes *bun.SelectQuery
if date != nil && !date.IsZero() {
if useInsertionDate {
if !s.ledger.HasFeature(ledger.FeatureMovesHistoryPostCommitVolumes, "SYNC") {
return ret.Err(ledgercontroller.NewErrMissingFeature(ledger.FeatureMovesHistoryPostCommitVolumes))
if !s.ledger.HasFeature(ledger.FeatureMovesHistory, "ON") {
return ret.Err(ledgercontroller.NewErrMissingFeature(ledger.FeatureMovesHistory))
}
selectAccountsWithVolumes = s.db.NewSelect().
TableExpr("(?) moves", s.SelectDistinctMovesBySeq(date)).
Expand Down
4 changes: 2 additions & 2 deletions internal/storage/ledger/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func (s *Store) selectTransactions(date *time.Time, expandVolumes, expandEffecti

ret := s.db.NewSelect()
// todo: no need this feature to grab pcv since those are included in transaction table
if expandVolumes && !s.ledger.HasFeature(ledger.FeatureMovesHistoryPostCommitVolumes, "SYNC") {
return ret.Err(ledgercontroller.NewErrMissingFeature(ledger.FeatureMovesHistoryPostCommitVolumes))
if expandVolumes && !s.ledger.HasFeature(ledger.FeatureMovesHistory, "ON") {
return ret.Err(ledgercontroller.NewErrMissingFeature(ledger.FeatureMovesHistory))
}

if expandEffectiveVolumes && !s.ledger.HasFeature(ledger.FeatureMovesHistoryPostCommitEffectiveVolumes, "SYNC") {
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ var _ = Context("Ledger stress tests", func() {
Bucket: &bucketName,
Features: ledger.MinimalFeatureSet.
// todo: as we are interested only by aggregated volumes at current date, these features should not be required
With(ledger.FeatureMovesHistory, "ON").
With(ledger.FeatureMovesHistoryPostCommitVolumes, "SYNC"),
With(ledger.FeatureMovesHistory, "ON"),
},
})
Expect(err).ShouldNot(HaveOccurred())
Expand Down

0 comments on commit ccc85bf

Please sign in to comment.