Skip to content

Commit

Permalink
fix: make ledger creations atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Feb 26, 2025
1 parent 3d27fa0 commit 4ec427b
Show file tree
Hide file tree
Showing 26 changed files with 435 additions and 557 deletions.
5 changes: 2 additions & 3 deletions cmd/buckets_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/formancehq/ledger/internal/storage/bucket"
"github.com/formancehq/ledger/internal/storage/driver"
"github.com/formancehq/ledger/internal/storage/ledger"
systemstore "github.com/formancehq/ledger/internal/storage/system"
"github.com/spf13/cobra"
"github.com/uptrace/bun"
)
Expand Down Expand Up @@ -56,9 +55,9 @@ func getDriver(cmd *cobra.Command) (*driver.Driver, *bun.DB, error) {
}

driver := driver.New(
db,
ledger.NewFactory(db),
systemstore.New(db),
bucket.NewDefaultFactory(db),
bucket.NewDefaultFactory(),
)
if err := driver.Initialize(cmd.Context()); err != nil {
return nil, nil, err
Expand Down
7 changes: 1 addition & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/formancehq/ledger/internal/storage/bucket"
"github.com/formancehq/ledger/internal/storage/driver"
"github.com/formancehq/ledger/internal/storage/ledger"
systemstore "github.com/formancehq/ledger/internal/storage/system"
"github.com/uptrace/bun"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -43,11 +42,7 @@ func NewRootCommand() *cobra.Command {
logger := logging.NewDefaultLogger(cmd.OutOrStdout(), service.IsDebug(cmd), false, false)
cmd.SetContext(logging.ContextWithLogger(cmd.Context(), logger))

driver := driver.New(
ledger.NewFactory(db),
systemstore.New(db),
bucket.NewDefaultFactory(db),
)
driver := driver.New(db, ledger.NewFactory(db), bucket.NewDefaultFactory())
if err := driver.Initialize(cmd.Context()); err != nil {
return err
}
Expand Down
48 changes: 24 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10
github.com/bluele/gcache v0.0.2
github.com/dop251/goja v0.0.0-20241009100908-5f46f2705ca3
github.com/formancehq/go-libs/v2 v2.0.1-0.20250217160145-75857677eef9
github.com/formancehq/go-libs/v2 v2.0.1-0.20250225100718-5e1dfe022817
github.com/formancehq/ledger/pkg/client v0.0.0-00010101000000-000000000000
github.com/go-chi/chi/v5 v5.2.1
github.com/go-chi/cors v1.2.1
Expand All @@ -24,14 +24,14 @@ require (
github.com/jackc/pgx/v5 v5.7.2
github.com/jamiealquiza/tachymeter v2.0.0+incompatible
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/nats-io/nats.go v1.38.0
github.com/nats-io/nats.go v1.39.1
github.com/onsi/ginkgo/v2 v2.22.1
github.com/onsi/gomega v1.36.2
github.com/ory/dockertest/v3 v3.11.0
github.com/pborman/uuid v1.2.1
github.com/pkg/errors v0.9.1
github.com/shomali11/xsql v0.0.0-20190608141458-bf76292144df
github.com/spf13/cobra v1.8.1
github.com/spf13/cobra v1.9.1
github.com/spf13/pflag v1.0.6
github.com/stoewer/go-strcase v1.3.0
github.com/stretchr/testify v1.10.0
Expand All @@ -47,7 +47,7 @@ require (
go.uber.org/fx v1.23.0
go.uber.org/mock v0.5.0
golang.org/x/oauth2 v0.24.0
golang.org/x/sync v0.10.0
golang.org/x/sync v0.11.0
)

require gopkg.in/yaml.v3 v3.0.1 // indirect
Expand All @@ -71,19 +71,19 @@ require (
github.com/ajg/form v1.5.1 // indirect
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
github.com/aws/aws-msk-iam-sasl-signer-go v1.0.1 // indirect
github.com/aws/aws-sdk-go-v2 v1.36.1 // indirect
github.com/aws/aws-sdk-go-v2/config v1.29.6 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.59 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.28 // indirect
github.com/aws/aws-sdk-go-v2/feature/rds/auth v1.5.9 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.32 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.32 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.13 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.24.15 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.14 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.33.14 // indirect
github.com/aws/aws-sdk-go-v2 v1.36.2 // indirect
github.com/aws/aws-sdk-go-v2/config v1.29.7 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.60 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.29 // indirect
github.com/aws/aws-sdk-go-v2/feature/rds/auth v1.5.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.33 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.33 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.14 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.24.16 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.15 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.33.15 // indirect
github.com/aws/smithy-go v1.22.2 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
Expand All @@ -93,7 +93,7 @@ require (
github.com/dlclark/regexp2 v1.11.4 // indirect
github.com/dnwe/otelsarama v0.0.0-20240308230250-9388d9d40bc0 // indirect
github.com/docker/cli v27.3.1+incompatible // indirect
github.com/docker/docker v27.4.1+incompatible // indirect
github.com/docker/docker v27.5.1+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/eapache/go-resiliency v1.7.0 // indirect
Expand All @@ -103,14 +103,14 @@ require (
github.com/ericlagergren/decimal v0.0.0-20240411145413-00de7ca16731 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/formancehq/numscript v0.0.10
github.com/formancehq/numscript v0.0.11
github.com/go-chi/chi v4.1.2+incompatible // indirect
github.com/go-chi/render v1.0.3 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/go-sql-driver/mysql v1.9.0 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
Expand Down Expand Up @@ -199,11 +199,11 @@ require (
go.uber.org/dig v1.18.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/crypto v0.33.0 // indirect
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/time v0.9.0 // indirect
golang.org/x/tools v0.28.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f // indirect
Expand Down
Loading

0 comments on commit 4ec427b

Please sign in to comment.