diff --git a/cmd/migrate-lid/migrate_lid.go b/cmd/migrate-lid/migrate_lid.go index 50bb85fb7..cae401d80 100644 --- a/cmd/migrate-lid/migrate_lid.go +++ b/cmd/migrate-lid/migrate_lid.go @@ -122,6 +122,14 @@ var migrateYugabyteDBCmd = &cli.Command{ Usage: "yugabyte hosts to connect to over cassandra interface eg '127.0.0.1'", Required: true, }, + &cli.StringFlag{ + Name: "username", + Usage: "yugabyte username to connect to over cassandra interface eg 'cassandra'", + }, + &cli.StringFlag{ + Name: "password", + Usage: "yugabyte password to connect to over cassandra interface eg 'cassandra'", + }, &cli.StringFlag{ Name: "connect-string", Usage: "postgres connect string eg 'postgresql://postgres:postgres@localhost'", @@ -154,6 +162,8 @@ var migrateYugabyteDBCmd = &cli.Command{ // Create a connection to the yugabyte local index directory settings := yugabyte.DBSettings{ Hosts: cctx.StringSlice("hosts"), + Username: cctx.String("username"), + Password: cctx.String("password"), ConnectString: cctx.String("connect-string"), PayloadPiecesParallelism: cctx.Int("insert-parallelism"), CQLTimeout: cctx.Int("CQLTimeout"), @@ -646,6 +656,14 @@ var migrateReverseYugabyteCmd = &cli.Command{ Usage: "yugabyte hosts to connect to over cassandra interface eg '127.0.0.1'", Required: true, }, + &cli.StringFlag{ + Name: "username", + Usage: "yugabyte username to connect to over cassandra interface eg 'cassandra'", + }, + &cli.StringFlag{ + Name: "password", + Usage: "yugabyte password to connect to over cassandra interface eg 'cassandra'", + }, &cli.StringFlag{ Name: "connect-string", Usage: "postgres connect string eg 'postgresql://postgres:postgres@localhost'", @@ -691,6 +709,8 @@ func migrateReverse(cctx *cli.Context, dbType string) error { settings := yugabyte.DBSettings{ ConnectString: cctx.String("connect-string"), Hosts: cctx.StringSlice("hosts"), + Username: cctx.String("username"), + Password: cctx.String("password"), PayloadPiecesParallelism: cctx.Int("insert-parallelism"), } migrator := yugabyte.NewMigrator(settings, migrations.DisabledMinerAddr) diff --git a/extern/boostd-data/cmd/run.go b/extern/boostd-data/cmd/run.go index 6de80873e..1521f7d05 100644 --- a/extern/boostd-data/cmd/run.go +++ b/extern/boostd-data/cmd/run.go @@ -103,6 +103,14 @@ var yugabyteCmd = &cli.Command{ Usage: "yugabyte hosts to connect to over cassandra interface eg '127.0.0.1'", Required: true, }, + &cli.StringFlag{ + Name: "username", + Usage: "yugabyte username to connect to over cassandra interface eg 'cassandra'", + }, + &cli.StringFlag{ + Name: "password", + Usage: "yugabyte password to connect to over cassandra interface eg 'cassandra'", + }, &cli.StringFlag{ Name: "connect-string", Usage: "postgres connect string eg 'postgresql://postgres:postgres@localhost'", @@ -125,6 +133,8 @@ var yugabyteCmd = &cli.Command{ // Create a yugabyte data service settings := yugabyte.DBSettings{ Hosts: cctx.StringSlice("hosts"), + Username: cctx.String("username"), + Password: cctx.String("password"), ConnectString: cctx.String("connect-string"), CQLTimeout: cctx.Int("CQLTimeout"), InsertConcurrency: cctx.Int("insert-concurrency"), @@ -224,6 +234,14 @@ var yugabyteMigrateCmd = &cli.Command{ Usage: "yugabyte hosts to connect to over cassandra interface eg '127.0.0.1'", Required: true, }, + &cli.StringFlag{ + Name: "username", + Usage: "yugabyte username to connect to over cassandra interface eg 'cassandra'", + }, + &cli.StringFlag{ + Name: "password", + Usage: "yugabyte password to connect to over cassandra interface eg 'cassandra'", + }, &cli.StringFlag{ Name: "connect-string", Usage: "postgres connect string eg 'postgresql://postgres:postgres@localhost'", @@ -252,6 +270,8 @@ var yugabyteMigrateCmd = &cli.Command{ // Create a yugabyte data service settings := yugabyte.DBSettings{ Hosts: cctx.StringSlice("hosts"), + Username: cctx.String("username"), + Password: cctx.String("password"), ConnectString: cctx.String("connect-string"), CQLTimeout: cctx.Int("CQLTimeout"), InsertConcurrency: cctx.Int("insert-concurrency"), @@ -286,6 +306,14 @@ var yugabyteAddIndexCmd = &cli.Command{ Usage: "yugabyte hosts to connect to over cassandra interface eg '127.0.0.1'", Required: true, }, + &cli.StringFlag{ + Name: "username", + Usage: "yugabyte username to connect to over cassandra interface eg 'cassandra'", + }, + &cli.StringFlag{ + Name: "password", + Usage: "yugabyte password to connect to over cassandra interface eg 'cassandra'", + }, &cli.StringFlag{ Name: "connect-string", Usage: "postgres connect string eg 'postgresql://postgres:postgres@localhost'", @@ -314,6 +342,8 @@ var yugabyteAddIndexCmd = &cli.Command{ // Create a yugabyte data service settings := yugabyte.DBSettings{ Hosts: cctx.StringSlice("hosts"), + Username: cctx.String("username"), + Password: cctx.String("password"), ConnectString: cctx.String("connect-string"), CQLTimeout: cctx.Int("CQLTimeout"), InsertConcurrency: cctx.Int("insert-concurrency"), diff --git a/extern/boostd-data/yugabyte/migrator.go b/extern/boostd-data/yugabyte/migrator.go index c8ff1bb5f..e495414aa 100644 --- a/extern/boostd-data/yugabyte/migrator.go +++ b/extern/boostd-data/yugabyte/migrator.go @@ -5,13 +5,11 @@ import ( "database/sql" "fmt" "net/url" - "time" "github.com/filecoin-project/boost/extern/boostd-data/yugabyte/cassmigrate" "github.com/filecoin-project/boost/extern/boostd-data/yugabyte/migrations" "github.com/filecoin-project/go-address" _ "github.com/lib/pq" - "github.com/yugabyte/gocql" ) type Migrator struct { @@ -55,8 +53,7 @@ func (m *Migrator) Migrate(ctx context.Context) error { } // Create a cassandra connection to be used only for running migrations. - cluster := gocql.NewCluster(m.settings.Hosts...) - cluster.Timeout = time.Duration(m.settings.CQLTimeout) * time.Second + cluster := NewCluster(m.settings) cluster.Keyspace = m.CassandraKeyspace session, err := cluster.CreateSession() if err != nil { diff --git a/extern/boostd-data/yugabyte/service.go b/extern/boostd-data/yugabyte/service.go index 1ac40c8df..6d6d8894d 100644 --- a/extern/boostd-data/yugabyte/service.go +++ b/extern/boostd-data/yugabyte/service.go @@ -42,6 +42,10 @@ const InsertConcurrency = 4 type DBSettings struct { // The cassandra hosts to connect to Hosts []string + // The cassandra password to use + Username string + // The cassandra password to use + Password string // The postgres connect string ConnectString string // The number of threads to use when inserting into the PayloadToPieces index @@ -89,8 +93,7 @@ func NewStore(settings DBSettings, migrator *Migrator, opts ...StoreOpt) *Store settings.InsertConcurrency = InsertConcurrency } - cluster := gocql.NewCluster(settings.Hosts...) - cluster.Timeout = time.Duration(settings.CQLTimeout) * time.Second + cluster := NewCluster(settings) cluster.Keyspace = defaultKeyspace s := &Store{ settings: settings, diff --git a/extern/boostd-data/yugabyte/setup.go b/extern/boostd-data/yugabyte/setup.go index c1fbc24f5..684ec965b 100644 --- a/extern/boostd-data/yugabyte/setup.go +++ b/extern/boostd-data/yugabyte/setup.go @@ -20,8 +20,7 @@ func (s *Store) CreateKeyspace(ctx context.Context) error { // Create a new session using the default keyspace, then use that to create // the new keyspace log.Infow("creating cassandra keyspace " + s.cluster.Keyspace) - cluster := gocql.NewCluster(s.settings.Hosts...) - cluster.Timeout = time.Duration(s.settings.CQLTimeout) * time.Second + cluster := NewCluster(s.settings) session, err := cluster.CreateSession() if err != nil { return fmt.Errorf("creating yugabyte cluster: %w", err) @@ -90,3 +89,15 @@ func (s *Store) execSQL(ctx context.Context, query string) error { _, err := s.db.Exec(ctx, query) return err } + +func NewCluster(settings DBSettings) *gocql.ClusterConfig { + cluster := gocql.NewCluster(settings.Hosts...) + cluster.Timeout = time.Duration(settings.CQLTimeout) * time.Second + if settings.Username != "" { + cluster.Authenticator = gocql.PasswordAuthenticator{ + Username: settings.Username, + Password: settings.Password, + } + } + return cluster +} diff --git a/node/config/doc_gen.go b/node/config/doc_gen.go index 5e54c0e21..8b64d8022 100644 --- a/node/config/doc_gen.go +++ b/node/config/doc_gen.go @@ -698,6 +698,18 @@ as this task consumes considerable resources and time`, Comment: `The yugabyte cassandra hosts eg ["127.0.0.1"]`, }, + { + Name: "Username", + Type: "string", + + Comment: `The yugabyte cassandra username eg "cassandra"`, + }, + { + Name: "Password", + Type: "string", + + Comment: `The yugabyte cassandra password eg "cassandra"`, + }, }, "MonitoringConfig": []DocField{ { diff --git a/node/config/types.go b/node/config/types.go index 872f4f90f..06e17159a 100644 --- a/node/config/types.go +++ b/node/config/types.go @@ -265,6 +265,10 @@ type LocalIndexDirectoryYugabyteConfig struct { ConnectString string // The yugabyte cassandra hosts eg ["127.0.0.1"] Hosts []string + // The yugabyte cassandra username eg "cassandra" + Username string + // The yugabyte cassandra password eg "cassandra" + Password string } type LocalIndexDirectoryConfig struct { diff --git a/node/modules/piecedirectory.go b/node/modules/piecedirectory.go index 3bc30cfd9..3ab53d2a7 100644 --- a/node/modules/piecedirectory.go +++ b/node/modules/piecedirectory.go @@ -56,6 +56,8 @@ func NewPieceDirectoryStore(cfg *config.Boost) func(lc fx.Lifecycle, r lotus_rep // Set up a local index directory service that connects to the yugabyte db settings := yugabyte.DBSettings{ Hosts: cfg.LocalIndexDirectory.Yugabyte.Hosts, + Username: cfg.LocalIndexDirectory.Yugabyte.Username, + Password: cfg.LocalIndexDirectory.Yugabyte.Password, ConnectString: cfg.LocalIndexDirectory.Yugabyte.ConnectString, } migrator := yugabyte.NewMigrator(settings, address.Address(maddr))