Skip to content
This repository was archived by the owner on Jun 12, 2018. It is now read-only.

Commit 8377ab8

Browse files
author
Stefan Röhrbein
committed
Add DatabaseHostname to replica options
It is now possible to set a specific database hostname. The default database hostname is set to 'localhost'. Additionally removed the replica options in lrazureblobdriver.go and use replica options from lreplica_drivers/lrs3driver/lrs3driver.go, to have the same code base.
1 parent d5a4c11 commit 8377ab8

6 files changed

Lines changed: 22 additions & 20 deletions

File tree

strata/cmd/mongo/lreplica_drivers/lrazureblobdriver/lrazureblobdriver.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,20 @@ import (
77

88
"github.com/facebookgo/rocks-strata/strata"
99
"github.com/facebookgo/rocks-strata/strata/azureblobstorage"
10+
"github.com/facebookgo/rocks-strata/strata/cmd/mongo/lreplica_drivers/lrs3driver"
1011
"github.com/facebookgo/rocks-strata/strata/mongo/lreplica"
1112
)
1213

14+
// AzureBlobOptions define basic options of your azure blob storage
1315
type AzureBlobOptions struct {
1416
Container string `short:"C" long:"container" description:"Azure Blob Storage container name" required:"true"`
1517
BlobPrefix string `short:"p" long:"blob-prefix" description:"Prefix used when storing and retrieving files. Optional" optional:"true"`
1618
}
1719

18-
// ReplicaOptions are used for commands like backup and restore
19-
type ReplicaOptions struct {
20-
MaxBackgroundCopies int `long:"max-background-copies" default:"16" description:"Backup and restore actions will use up to this many goroutines to copy files"`
21-
Port int `long:"port" default:"27017" description:"Backup should look for a mongod instance that is listening on this port"`
22-
Username string `long:"username" description:"If auth is configured, specify the username with admin privileges here"`
23-
Password string `long:"password" description:"Password for the specified user."`
24-
}
25-
2620
// Options define the common options needed by this strata command
2721
type Options struct {
28-
AzureBlobOptions AzureBlobOptions `group:"Azure Blob Options"`
29-
Replica ReplicaOptions `group:"Replica Options"`
22+
AzureBlobOptions AzureBlobOptions `group:"Azure Blob Options"`
23+
Replica lrs3driver.ReplicaOptions `group:"Replica Options"`
3024
}
3125

3226
// DriverFactory implements strata.DriverFactory
@@ -60,6 +54,7 @@ func (factory DriverFactory) Driver() (*strata.Driver, error) {
6054

6155
replica, err := lreplica.NewLocalReplica(
6256
options.Replica.MaxBackgroundCopies,
57+
options.Replica.DatabaseHostname,
6358
strconv.Itoa(options.Replica.Port),
6459
options.Replica.Username,
6560
options.Replica.Password,

strata/cmd/mongo/lreplica_drivers/lrldriver/lrldriver.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ import (
1010

1111
"github.com/facebookgo/rocks-strata/strata"
1212
"github.com/facebookgo/rocks-strata/strata/cmd/mongo/lreplica_drivers/lrs3driver"
13-
"github.com/facebookgo/rocks-strata/strata/mongo/lreplica"
1413
"github.com/facebookgo/rocks-strata/strata/lstorage"
14+
"github.com/facebookgo/rocks-strata/strata/mongo/lreplica"
1515
)
1616

1717
// FsOptions are common to all commands
1818
type FsOptions struct {
19-
Mountpoint string `short:"m" long:"mpoint" description:"Mount point name, such as \"~/sbackup\"" default:"~/sbackup"`
19+
Mountpoint string `short:"m" long:"mpoint" description:"Mount point name, such as \"~/sbackup\"" default:"~/sbackup"`
2020
}
2121

2222
// Options define the common options needed by this strata command
2323
type Options struct {
24-
LocalStorage FsOptions `group:"Storage Options"`
25-
Replica lrs3driver.ReplicaOptions `group:"Replica Options"`
24+
LocalStorage FsOptions `group:"Storage Options"`
25+
Replica lrs3driver.ReplicaOptions `group:"Replica Options"`
2626
}
2727

2828
// DriverFactory implements strata.DriverFactory
@@ -46,6 +46,7 @@ func (factory DriverFactory) Driver() (*strata.Driver, error) {
4646

4747
replica, err := lreplica.NewLocalReplica(
4848
options.Replica.MaxBackgroundCopies,
49+
options.Replica.DatabaseHostname,
4950
strconv.Itoa(options.Replica.Port),
5051
options.Replica.Username,
5152
options.Replica.Password,

strata/cmd/mongo/lreplica_drivers/lrminiodriver/lrminiodriver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func (factory DriverFactory) Driver() (*strata.Driver, error) {
6969

7070
replica, err := lreplica.NewLocalReplica(
7171
options.Replica.MaxBackgroundCopies,
72+
options.Replica.DatabaseHostname,
7273
strconv.Itoa(options.Replica.Port),
7374
options.Replica.Username,
7475
options.Replica.Password,

strata/cmd/mongo/lreplica_drivers/lrs3driver/lrs3driver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type AWSOptions struct {
2727

2828
// ReplicaOptions are used for commands like backup and restore
2929
type ReplicaOptions struct {
30+
DatabaseHostname string `long:"database-hostname" default:"localhost" description:"Database hostname can be override with a specific hostname in most cases localhost is sufficient"`
3031
MaxBackgroundCopies int `long:"max-background-copies" default:"16" description:"Backup and restore actions will use up to this many goroutines to copy files"`
3132
Port int `long:"port" default:"27017" description:"Backup should look for a mongod instance that is listening on this port"`
3233
Username string `long:"username" description:"If auth is configured, specify the username with admin privileges here"`
@@ -70,6 +71,7 @@ func (factory DriverFactory) Driver() (*strata.Driver, error) {
7071
}
7172
replica, err := lreplica.NewLocalReplica(
7273
options.Replica.MaxBackgroundCopies,
74+
options.Replica.DatabaseHostname,
7375
strconv.Itoa(options.Replica.Port),
7476
options.Replica.Username,
7577
options.Replica.Password,

strata/mongo/lreplica/mock_replica.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type mockLocalSessionGetter struct {
2020
mongo *mgotest.Server
2121
}
2222

23-
func (mlsg *mockLocalSessionGetter) get(string, string, string) (*mgo.Session, error) {
23+
func (mlsg *mockLocalSessionGetter) get(string, string, string, string) (*mgo.Session, error) {
2424
return mlsg.mongo.Session(), nil
2525
}
2626

strata/mongo/lreplica/replica.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import (
2222
)
2323

2424
type sessionGetter interface {
25-
get(port, username, password string) (*mgo.Session, error)
25+
get(databaseHostname, port, username, password string) (*mgo.Session, error)
2626
}
2727

2828
type localSessionGetter struct{}
2929

3030
// port could be the empty string
31-
func (l *localSessionGetter) get(port, username, password string) (*mgo.Session, error) {
32-
addr := "localhost"
31+
func (l *localSessionGetter) get(databaseHostname, port, username, password string) (*mgo.Session, error) {
32+
addr := databaseHostname
3333
if port != "" {
3434
addr += ":" + port
3535
}
@@ -44,6 +44,7 @@ func (l *localSessionGetter) get(port, username, password string) (*mgo.Session,
4444
// LocalReplica is a replica where all methods that take a ReplicaID must be
4545
// run on the host corresponding to ReplicaID
4646
type LocalReplica struct {
47+
databaseHostname string
4748
port string
4849
username string
4950
password string
@@ -52,10 +53,11 @@ type LocalReplica struct {
5253
}
5354

5455
// NewLocalReplica constructs a LocalReplica
55-
func NewLocalReplica(maxBackgroundCopies int, port, username, password string) (*LocalReplica, error) {
56+
func NewLocalReplica(maxBackgroundCopies int, databaseHostname, port, username, password string) (*LocalReplica, error) {
5657
return &LocalReplica{
5758
sessionGetter: &localSessionGetter{},
5859
maxBackgroundCopies: maxBackgroundCopies,
60+
databaseHostname: databaseHostname,
5961
port: port,
6062
username: username,
6163
password: password,
@@ -170,7 +172,7 @@ func nestedBsonMapGet(m bson.M, arg string, moreArgs ...string) (interface{}, er
170172
// TODO(agf): Have a way to pass in tags
171173
func (r *LocalReplica) CreateSnapshot(replicaID, snapshotID string) (*strata.Snapshot, error) {
172174
strata.Log("Getting session for CreateSnapshot()")
173-
session, err := r.sessionGetter.get(r.port, r.username, r.password)
175+
session, err := r.sessionGetter.get(r.databaseHostname, r.port, r.username, r.password)
174176
if err != nil {
175177
return nil, err
176178
}
@@ -302,3 +304,4 @@ func partialChecksum(filename string) (string, error) {
302304
csum, err := strata.PartialChecksum(file, fileinfo.Size())
303305
return fmt.Sprintf("%x", csum), err
304306
}
307+

0 commit comments

Comments
 (0)