Skip to content

Commit e67c983

Browse files
committed
PBM-1389: warn about sel backup/restore with ConfigShard
1 parent 1503385 commit e67c983

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

cmd/pbm-agent/agent.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (a *Agent) showIncompatibilityWarning(ctx context.Context) {
118118
Warning("", "", "", primitive.Timestamp{}, "WARNING: %v", err)
119119
}
120120

121-
if a.brief.Version.IsShardedTimeseriesSupported() {
121+
if a.brief.Sharded && a.brief.Version.IsShardedTimeseriesSupported() {
122122
tss, err := topo.ListShardedTimeseries(ctx, a.leadConn)
123123
if err != nil {
124124
log.FromContext(ctx).
@@ -131,6 +131,19 @@ func (a *Agent) showIncompatibilityWarning(ctx context.Context) {
131131
strings.Join(tss, ", "))
132132
}
133133
}
134+
135+
if a.brief.Sharded && a.brief.Version.IsConfigShardSupported() {
136+
hasConfigShard, err := topo.HasConfigShard(ctx, a.leadConn)
137+
if err != nil {
138+
log.FromContext(ctx).
139+
Error("", "", "", primitive.Timestamp{},
140+
"failed to check for Config Shard: %v", err)
141+
} else if hasConfigShard {
142+
log.FromContext(ctx).
143+
Warning("", "", "", primitive.Timestamp{},
144+
"WARNING: selective backup and restore is not supported with Config Shard")
145+
}
146+
}
134147
}
135148

136149
// Start starts listening the commands stream.

pbm/topo/cluster.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,21 @@ func getShardMapImpl(ctx context.Context, m *mongo.Client) (map[ReplsetName]Shar
171171
return shards, nil
172172
}
173173

174+
// HasConfigShard return true if configsvr is listened in shards list
175+
func HasConfigShard(ctx context.Context, conn connect.Client) (bool, error) {
176+
err := conn.MongoClient().Database("config").Collection("shards").
177+
FindOne(ctx, bson.D{{"_id", "config"}}).
178+
Err()
179+
if err == nil {
180+
return true, nil // OK: config shard is found
181+
}
182+
if errors.Is(err, mongo.ErrNoDocuments) {
183+
return false, nil // OK: config shard is not found
184+
}
185+
186+
return false, errors.Wrap(err, "query")
187+
}
188+
174189
type BalancerMode string
175190

176191
const (

pbm/version/version.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ func (v MongoVersion) IsShardedTimeseriesSupported() bool {
193193
return v.Version[0] >= 6 // sharded timeseries introduced in 5.1
194194
}
195195

196+
func (v MongoVersion) IsConfigShardSupported() bool {
197+
return v.Version[0] >= 8
198+
}
199+
196200
func GetMongoVersion(ctx context.Context, m *mongo.Client) (MongoVersion, error) {
197201
res := m.Database("admin").RunCommand(ctx, bson.D{{"buildInfo", 1}})
198202
if err := res.Err(); err != nil {

0 commit comments

Comments
 (0)