Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added --parallel-job-size=100 default when datastore backend used #5379

Merged
merged 5 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions services/horizon/cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
hlog "github.com/stellar/go/support/log"
)

var runDBReingestRangeFn = runDBReingestRange

var dbCmd = &cobra.Command{
Use: "db [command]",
Short: "commands to manage horizon's postgres db",
Expand Down Expand Up @@ -391,14 +393,19 @@ var dbReingestRangeCmd = &cobra.Command{
}
storageBackendConfig.BufferedStorageBackendFactory = ledgerbackend.NewBufferedStorageBackend
storageBackendConfig.DataStoreFactory = datastore.NewDataStore
// when using buffered storage, performance observations have noted optimal parallel batch size
// of 100, apply that as default if the flag was absent.
if !viper.IsSet("parallel-job-size") {
parallelJobSize = 100
}
options.NoCaptiveCore = true
}

err := horizon.ApplyFlags(globalConfig, globalFlags, options)
if err != nil {
return err
}
return runDBReingestRange(
return runDBReingestRangeFn(
[]history.LedgerRange{{StartSequence: argsUInt32[0], EndSequence: argsUInt32[1]}},
reingestForce,
parallelWorkers,
Expand Down Expand Up @@ -477,7 +484,7 @@ var dbFillGapsCmd = &cobra.Command{
hlog.Infof("found gaps %v", gaps)
}

return runDBReingestRange(gaps, reingestForce, parallelWorkers, *globalConfig, storageBackendConfig)
return runDBReingestRangeFn(gaps, reingestForce, parallelWorkers, *globalConfig, storageBackendConfig)
},
}

Expand Down
98 changes: 98 additions & 0 deletions services/horizon/cmd/db_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package cmd

import (
"testing"

horizon "github.com/stellar/go/services/horizon/internal"
"github.com/stellar/go/services/horizon/internal/db2/history"
"github.com/stellar/go/services/horizon/internal/ingest"
"github.com/stellar/go/support/db/dbtest"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)

func TestDBCommandsTestSuite(t *testing.T) {
dbCmdSuite := &DBCommandsTestSuite{}
suite.Run(t, dbCmdSuite)
}

type DBCommandsTestSuite struct {
suite.Suite
dsn string
}

func (s *DBCommandsTestSuite) SetupSuite() {
runDBReingestRangeFn = func([]history.LedgerRange, bool, uint,
horizon.Config, ingest.StorageBackendConfig) error {
return nil
}

newDB := dbtest.Postgres(s.T())
s.dsn = newDB.DSN

RootCmd.SetArgs([]string{
"db", "migrate", "up", "--db-url", s.dsn})
require.NoError(s.T(), RootCmd.Execute())
}

func (s *DBCommandsTestSuite) TestDefaultParallelJobSizeForBufferedBackend() {
RootCmd.SetArgs([]string{
"db", "reingest", "range",
"--db-url", s.dsn,
"--network", "testnet",
"--parallel-workers", "2",
"--ledgerbackend", "datastore",
"--datastore-config", "../config.storagebackend.toml",
"2",
"10"})

require.NoError(s.T(), dbReingestRangeCmd.Execute())
require.Equal(s.T(), parallelJobSize, uint32(100))
}

func (s *DBCommandsTestSuite) TestDefaultParallelJobSizeForCaptiveBackend() {
RootCmd.SetArgs([]string{
"db", "reingest", "range",
"--db-url", s.dsn,
"--network", "testnet",
"--stellar-core-binary-path", "/test/core/bin/path",
"--parallel-workers", "2",
"--ledgerbackend", "captive-core",
"2",
"10"})

require.NoError(s.T(), RootCmd.Execute())
require.Equal(s.T(), parallelJobSize, uint32(100_000))
}

func (s *DBCommandsTestSuite) TestUsesParallelJobSizeWhenSetForCaptive() {
RootCmd.SetArgs([]string{
"db", "reingest", "range",
"--db-url", s.dsn,
"--network", "testnet",
"--stellar-core-binary-path", "/test/core/bin/path",
"--parallel-workers", "2",
"--parallel-job-size", "5",
"--ledgerbackend", "captive-core",
"2",
"10"})

require.NoError(s.T(), RootCmd.Execute())
require.Equal(s.T(), parallelJobSize, uint32(5))
}

func (s *DBCommandsTestSuite) TestUsesParallelJobSizeWhenSetForBuffered() {
RootCmd.SetArgs([]string{
"db", "reingest", "range",
"--db-url", s.dsn,
"--network", "testnet",
"--parallel-workers", "2",
"--parallel-job-size", "5",
"--ledgerbackend", "datastore",
"--datastore-config", "../config.storagebackend.toml",
"2",
"10"})

require.NoError(s.T(), RootCmd.Execute())
require.Equal(s.T(), parallelJobSize, uint32(5))
}
3 changes: 1 addition & 2 deletions services/horizon/internal/integration/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ func TestEnvironmentPreserved(t *testing.T) {
// using NETWORK environment variables, history archive urls or network passphrase
// parameters are also set.
func TestInvalidNetworkParameters(t *testing.T) {
var captiveCoreConfigErrMsg = integration.HorizonInitErrStr + ": error generating captive " +
"core configuration: invalid config: %s parameter not allowed with the %s parameter"
var captiveCoreConfigErrMsg = integration.HorizonInitErrStr + ": invalid config: %s parameter not allowed with the %s parameter"
testCases := []struct {
name string
errMsg string
Expand Down
Loading