Permalink
Browse files

TOOLS-1903 Clean up initial UUID support code

  • Loading branch information...
xdg committed Dec 8, 2017
1 parent e49f77f commit 49d61f9a366a073a3d5a48c69bd1523f0b24f4ee
Showing with 17 additions and 26 deletions.
  1. +13 −19 common/testutil/testutil.go
  2. +1 −0 mongodump/mongodump_test.go
  3. +2 −4 mongodump/prepare.go
  4. +1 −3 mongorestore/oplog.go
@@ -72,49 +72,43 @@ func GetBareSessionProvider() (*db.SessionProvider, *options.ToolOptions, error)
// or the empty string if it can't be found.
func GetFCV(s *mgo.Session) string {
coll := s.DB("admin").C("system.version")
iter := coll.Find(bson.M{"_id": "featureCompatibilityVersion"}).Iter()
defer iter.Close()
var result struct {
Version string
}
if !iter.Next(&result) {
return ""
}
_ = coll.Find(bson.M{"_id": "featureCompatibilityVersion"}).One(&result)
return result.Version
}
// CompareFCV compares two strings as dot-delimited tuples of integers
func CompareFCV(x, y string) (int, error) {
xs, err := dottedStringToSlice(x)
left, err := dottedStringToSlice(x)
if err != nil {
return 0, err
}
ys, err := dottedStringToSlice(y)
right, err := dottedStringToSlice(y)
if err != nil {
return 0, err
}
// Ensure xs is the shorter one, flip logic if necesary
// Ensure left is the shorter one, flip logic if necesary
inverter := 1
if len(ys) < len(xs) {
if len(right) < len(left) {
inverter = -1
xs, ys = ys, xs
left, right = right, left
}
for i := range xs {
for i := range left {
switch {
case xs[i] < ys[i]:
case left[i] < right[i]:
return -1 * inverter, nil
case xs[i] > ys[i]:
case left[i] > right[i]:
return 1 * inverter, nil
}
}
// compared equal to length of xs. If ys are longer, then xs is less
// than ys (-1) (modulo the inverter)
if len(xs) < len(ys) {
// compared equal to length of left. If right is longer, then left is less
// than right (-1) (modulo the inverter)
if len(left) < len(right) {
return -1 * inverter, nil
}
@@ -780,6 +780,7 @@ func TestMongoDumpOplog(t *testing.T) {
So(err, ShouldBeNil)
withUI := countOplogUI(iter)
So(iter.Err(), ShouldBeNil)
if cmp >= 0 {
// for FCV 3.6+, should have 'ui' field in oplog entries
View
@@ -292,10 +292,8 @@ func (dump *MongoDump) NewIntentFromOptions(dbName string, ci *db.CollectionInfo
Options: ci.Options,
}
// If UUID is available, populate the intent with it
if uuid := ci.GetUUID(); uuid != "" {
intent.UUID = uuid
}
// Populate the intent with the collection UUID or the empty string
intent.UUID = ci.GetUUID()
// Setup output location
if dump.OutputOptions.Out == "-" { // regular standard output
View
@@ -170,9 +170,7 @@ func ParseTimestampFlag(ts string) (bson.MongoTimestamp, error) {
// filterUUIDs removes 'ui' entries from ops, including nested applyOps ops.
func filterUUIDs(op db.Oplog) (db.Oplog, error) {
// Remove UUIDs from oplog entries
if op.UI != nil {
op.UI = nil
}
op.UI = nil
// Check for and filter nested applyOps ops
if op.Operation == "c" && isApplyOpsCmd(op.Object) {

0 comments on commit 49d61f9

Please sign in to comment.