Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PBM-1179] Warn about unsupported MongoDB version (percona#876)
Browse files Browse the repository at this point in the history
defbin authored and minottic committed Oct 26, 2023
1 parent 56f5f7e commit 99f1a4c
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
@@ -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
}

9 changes: 9 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
stdlog "log"
"os"
"strings"
"time"
@@ -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 {
14 changes: 14 additions & 0 deletions pbm/version.go
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 99f1a4c

Please sign in to comment.