From 9f6ed05abc1978c83e09c1bb3c1bc4378d303d39 Mon Sep 17 00:00:00 2001 From: Allan Clark Date: Tue, 17 Sep 2024 11:09:35 -0700 Subject: [PATCH] Add MongoDB Load Balancer support Add MongoDB Load Balancer support if specified in client uri connection string opts. --- db/mongodb/db.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/db/mongodb/db.go b/db/mongodb/db.go index 6e5c7476..aa4498e7 100644 --- a/db/mongodb/db.go +++ b/db/mongodb/db.go @@ -159,14 +159,32 @@ func (c mongodbCreator) Create(p *properties.Properties) (ycsb.DB, error) { } caCertPool := x509.NewCertPool() if ok := caCertPool.AppendCertsFromPEM(caCert); !ok { - log.Fatalf("certifacte %s could not be parsed", caFile) + log.Fatalf("certificate %s could not be parsed", caFile) } cliOpts.TLSConfig.RootCAs = caCertPool } } + + // Check if the loadBalanced option is explicitly set + if connString.LoadBalancedSet { + // If loadBalanced is set, use its value + if connString.LoadBalanced { + log.Println("Setting loadBalanced to true") + cliOpts.SetLoadBalanced(true) + } else { + log.Println("Setting loadBalanced to false") + cliOpts.SetLoadBalanced(false) + } + } else { + // Default to false if not set + log.Println("Setting loadBalanced to false") + cliOpts.SetLoadBalanced(false) + } + t := uint64(p.GetInt64(prop.ThreadCount, prop.ThreadCountDefault)) cliOpts.SetMaxPoolSize(t) + username, usrExist := p.Get(mongodbUsername) password, pwdExist := p.Get(mongodbPassword) if usrExist && pwdExist {