summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Russell <gabriel.russell@mongodb.com>2016-03-03 14:29:57 -0500
committerGabriel Russell <gabriel.russell@mongodb.com>2016-03-03 14:29:57 -0500
commit07635e851d8cbd3beb834c8cd68460220a7eadc4 (patch)
tree90bcc4e1af9576b30d2743f5524c8f4701b4b9ca
parentae73e5be6cb541df2d03acd68099f872fa7e822d (diff)
downloadmongo-07635e851d8cbd3beb834c8cd68460220a7eadc4.tar.gz
Revert "TOOLS-1078 specify dial timeout on the command line"
This reverts commit ae73e5be6cb541df2d03acd68099f872fa7e822d.
-rw-r--r--common/db/connector.go4
-rw-r--r--common/db/connector_test.go14
-rw-r--r--common/db/db.go7
-rw-r--r--common/db/kerberos/gssapi.go3
-rw-r--r--common/db/openssl/openssl.go6
-rw-r--r--common/options/options.go30
6 files changed, 24 insertions, 40 deletions
diff --git a/common/db/connector.go b/common/db/connector.go
index 22b79c661c0..24f55286a9b 100644
--- a/common/db/connector.go
+++ b/common/db/connector.go
@@ -1,8 +1,6 @@
package db
import (
- "time"
-
"github.com/mongodb/mongo-tools/common/options"
"github.com/mongodb/mongo-tools/common/util"
"gopkg.in/mgo.v2"
@@ -32,7 +30,7 @@ func (self *VanillaDBConnector) Configure(opts options.ToolOptions) error {
// set up the dial info
self.dialInfo = &mgo.DialInfo{
Addrs: connectionAddrs,
- Timeout: time.Duration(opts.HiddenOptions.DialTimeoutSeconds) * time.Second,
+ Timeout: DefaultDialTimeout,
Direct: opts.Direct,
ReplicaSetName: opts.ReplicaSetName,
Username: opts.Auth.Username,
diff --git a/common/db/connector_test.go b/common/db/connector_test.go
index a8b4040abe0..8d5ff9a361b 100644
--- a/common/db/connector_test.go
+++ b/common/db/connector_test.go
@@ -26,15 +26,12 @@ func TestVanillaDBConnector(t *testing.T) {
Host: "host1,host2",
Port: "20000",
},
- HiddenOptions: &options.HiddenOptions{
- DialTimeoutSeconds: options.DefaultDialTimeoutSeconds,
- },
Auth: &options.Auth{},
}
So(connector.Configure(opts), ShouldBeNil)
So(connector.dialInfo.Addrs, ShouldResemble,
[]string{"host1:20000", "host2:20000"})
- So(connector.dialInfo.Timeout, ShouldResemble, options.DefaultDialTimeoutSeconds)
+ So(connector.dialInfo.Timeout, ShouldResemble, DefaultDialTimeout)
})
@@ -48,9 +45,6 @@ func TestVanillaDBConnector(t *testing.T) {
Host: "localhost",
Port: DefaultTestPort,
},
- HiddenOptions: &options.HiddenOptions{
- DialTimeoutSeconds: options.DefaultDialTimeoutSeconds,
- },
Auth: &options.Auth{},
}
So(connector.Configure(opts), ShouldBeNil)
@@ -95,9 +89,6 @@ func TestVanillaDBConnectorWithAuth(t *testing.T) {
Host: "localhost",
Port: DefaultTestPort,
},
- HiddenOptions: &options.HiddenOptions{
- DialTimeoutSeconds: options.DefaultDialTimeoutSeconds,
- },
Auth: &options.Auth{},
}
So(connector.Configure(opts), ShouldBeNil)
@@ -121,9 +112,6 @@ func TestVanillaDBConnectorWithAuth(t *testing.T) {
Host: "localhost",
Port: DefaultTestPort,
},
- HiddenOptions: &options.HiddenOptions{
- DialTimeoutSeconds: options.DefaultDialTimeoutSeconds,
- },
Auth: &options.Auth{
Username: "cAdmin",
Password: "password",
diff --git a/common/db/db.go b/common/db/db.go
index 8d617b8ff10..e100ef42de1 100644
--- a/common/db/db.go
+++ b/common/db/db.go
@@ -3,15 +3,15 @@
package db
import (
+ "fmt"
"github.com/mongodb/mongo-tools/common/options"
"github.com/mongodb/mongo-tools/common/password"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
-
- "fmt"
"io"
"strings"
"sync"
+ "time"
)
type (
@@ -51,7 +51,8 @@ const (
)
var (
- GetConnectorFuncs = []GetConnectorFunc{}
+ DefaultDialTimeout = time.Second * 3
+ GetConnectorFuncs = []GetConnectorFunc{}
)
// Used to manage database sessions
diff --git a/common/db/kerberos/gssapi.go b/common/db/kerberos/gssapi.go
index c97c34a7188..51f531fab1b 100644
--- a/common/db/kerberos/gssapi.go
+++ b/common/db/kerberos/gssapi.go
@@ -12,6 +12,7 @@ import (
)
const (
+ KERBEROS_DIAL_TIMEOUT = time.Second * 3
KERBEROS_AUTHENTICATION_MECHANISM = "GSSAPI"
)
@@ -29,7 +30,7 @@ func (self *KerberosDBConnector) Configure(opts options.ToolOptions) error {
// set up the dial info
self.dialInfo = &mgo.DialInfo{
Addrs: connectionAddrs,
- Timeout: time.Duration(opts.HiddenOptions.DialTimeoutSeconds) * time.Second,
+ Timeout: KERBEROS_DIAL_TIMEOUT,
Direct: opts.Direct,
ReplicaSetName: opts.ReplicaSetName,
diff --git a/common/db/openssl/openssl.go b/common/db/openssl/openssl.go
index 2fa725676bf..36a788de027 100644
--- a/common/db/openssl/openssl.go
+++ b/common/db/openssl/openssl.go
@@ -13,6 +13,10 @@ import (
"github.com/spacemonkeygo/openssl"
)
+var (
+ DefaultSSLDialTimeout = time.Second * 3
+)
+
// For connecting to the database over ssl
type SSLDBConnector struct {
dialInfo *mgo.DialInfo
@@ -49,7 +53,7 @@ func (self *SSLDBConnector) Configure(opts options.ToolOptions) error {
// set up the dial info
self.dialInfo = &mgo.DialInfo{
Addrs: connectionAddrs,
- Timeout: time.Duration(opts.HiddenOptions.DialTimeoutSeconds) * time.Second,
+ Timeout: DefaultSSLDialTimeout,
Direct: opts.Direct,
ReplicaSetName: opts.ReplicaSetName,
DialServer: dialer,
diff --git a/common/options/options.go b/common/options/options.go
index e79b86f1647..49ab99e354d 100644
--- a/common/options/options.go
+++ b/common/options/options.go
@@ -3,10 +3,9 @@
package options
import (
+ "fmt"
"github.com/jessevdk/go-flags"
"github.com/mongodb/mongo-tools/common/log"
-
- "fmt"
"os"
"regexp"
"runtime"
@@ -15,8 +14,7 @@ import (
)
const (
- VersionStr = "3.3.3-pre-"
- DefaultDialTimeoutSeconds = 3
+ VersionStr = "3.3.3-pre-"
)
// Gitspec that the tool was built with. Needs to be set using -ldflags
@@ -68,9 +66,8 @@ type HiddenOptions struct {
// Deprecated flag for csv writing in mongoexport
CSVOutputType bool
- TempUsersColl *string
- TempRolesColl *string
- DialTimeoutSeconds int
+ TempUsersColl *string
+ TempRolesColl *string
}
type Namespace struct {
@@ -154,8 +151,7 @@ func parseVal(val string) int {
// Ask for a new instance of tool options
func New(appName, usageStr string, enabled EnabledOptions) *ToolOptions {
hiddenOpts := &HiddenOptions{
- BulkBufferSize: 10000,
- DialTimeoutSeconds: DefaultDialTimeoutSeconds,
+ BulkBufferSize: 10000,
}
opts := &ToolOptions{
@@ -190,7 +186,9 @@ func New(appName, usageStr string, enabled EnabledOptions) *ToolOptions {
}
}
- opts.parser.UnknownOptionHandler = hiddenOpts.parseHiddenOption
+ opts.parser.UnknownOptionHandler = func(option string, arg flags.SplitArgument, args []string) ([]string, error) {
+ return parseHiddenOption(hiddenOpts, option, arg, args)
+ }
if _, err := opts.parser.AddGroup("general options", "", opts.General); err != nil {
panic(fmt.Errorf("couldn't register general options: %v", err))
@@ -296,10 +294,10 @@ func (o *ToolOptions) Parse() ([]string, error) {
return o.parser.Parse()
}
-func (opts *HiddenOptions) parseHiddenOption(option string, arg flags.SplitArgument, args []string) ([]string, error) {
+func parseHiddenOption(opts *HiddenOptions, option string, arg flags.SplitArgument, args []string) ([]string, error) {
if option == "dbpath" || option == "directoryperdb" || option == "journal" {
- return args, fmt.Errorf("--dbpath and related flags are not supported in 3.0 tools.\n" +
- "See http://dochub.mongodb.org/core/tools-dbpath-deprecated for more information")
+ return args, fmt.Errorf(`--dbpath and related flags are not supported in 3.0 tools.
+See http://dochub.mongodb.org/core/tools-dbpath-deprecated for more information`)
}
if option == "csv" {
@@ -340,12 +338,6 @@ func (opts *HiddenOptions) parseHiddenOption(option string, arg flags.SplitArgum
opts.BulkBufferSize = optionValue
case "numDecodingWorkers":
opts.NumDecodingWorkers = optionValue
- case "dialTimeout":
- if optionValue >= 0 {
- opts.DialTimeoutSeconds = optionValue
- } else {
- return args, fmt.Errorf("invalid negative value for --dialTimeout")
- }
default:
return args, fmt.Errorf(`unknown option "%v"`, option)
}