Skip to content

Commit

Permalink
[PBM-1179] Warn about unsupported MongoDB version (#876)
Browse files Browse the repository at this point in the history
  • Loading branch information
defbin authored Sep 19, 2023
1 parent c108a64 commit 2c5470b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ func (a *Agent) CanStart() error {
return errors.New("mongos is not supported")
}

ver, err := pbm.GetMongoVersion(context.Background(), a.pbm.Conn)
if err != nil {
return errors.WithMessage(err, "get mongo version")
}
if err := pbm.FeatureSupport(ver).PBMSupport(); err != nil {
a.log.Warning("", "", "", primitive.Timestamp{}, "WARNING: %v", err)
}

return nil
}

Expand Down
9 changes: 9 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
stdlog "log"
"os"
"strings"
"time"
Expand Down Expand Up @@ -352,6 +353,14 @@ func Main() {
exitErr(errors.Wrap(err, "connect to mongodb"), pbmOutF)
}
pbmClient.InitLogger("", "")

ver, err := pbm.GetMongoVersion(ctx, pbmClient.Conn)
if err != nil {
stdlog.Fatalf("get mongo version: %v", err)
}
if err := pbm.FeatureSupport(ver).PBMSupport(); err != nil {
fmt.Fprintf(os.Stderr, "WARNING: %v\n", err)
}
}

switch cmd {
Expand Down
14 changes: 14 additions & 0 deletions pbm/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ func GetMongoVersion(ctx context.Context, m *mongo.Client) (MongoVersion, error)

type FeatureSupport MongoVersion

func (f FeatureSupport) PBMSupport() error {
v := MongoVersion(f)

if v.Version[0] == 4 && v.Version[1] == 4 {
return nil
}

if (v.Version[0] == 5 || v.Version[0] == 6) && v.Version[1] == 0 {
return nil
}

return errors.New("Unsupported MongoDB version. PBM works with v4.4, v5.0, v6.0")
}

func (f FeatureSupport) FullPhysicalBackup() bool {
// PSMDB 4.2.15, 4.4.6
v := MongoVersion(f)
Expand Down

0 comments on commit 2c5470b

Please sign in to comment.