Skip to content

Commit fa0ae4a

Browse files
devanbenzCopilot
andauthored
feat: Adds logging when there are no shards during backup and restore (#27035)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ef1dd6b commit fa0ae4a

3 files changed

Lines changed: 42 additions & 5 deletions

File tree

backup/backup.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,27 @@ import (
88
"github.com/influxdata/influxdb/v2"
99
"github.com/influxdata/influxdb/v2/tenant"
1010
"github.com/influxdata/influxdb/v2/v1/services/meta"
11+
"go.uber.org/zap"
1112
)
1213

1314
type BucketManifestWriter struct {
14-
ts *tenant.Service
15-
mc *meta.Client
15+
ts *tenant.Service
16+
mc *meta.Client
17+
logger *zap.Logger
1618
}
1719

1820
func NewBucketManifestWriter(ts *tenant.Service, mc *meta.Client) BucketManifestWriter {
1921
return BucketManifestWriter{
20-
ts: ts,
21-
mc: mc,
22+
ts: ts,
23+
mc: mc,
24+
logger: zap.NewNop(),
2225
}
2326
}
2427

28+
func (b *BucketManifestWriter) WithLogger(logger *zap.Logger) {
29+
b.logger = logger
30+
}
31+
2532
// WriteManifest writes a bucket manifest describing all of the buckets that exist in the database.
2633
// It is intended to be used to write to an HTTP response after appropriate measures have been taken
2734
// to ensure that the request is authorized.
@@ -40,11 +47,28 @@ func (b BucketManifestWriter) WriteManifest(ctx context.Context, w io.Writer) er
4047
}
4148

4249
dbInfo := b.mc.Database(bkt.ID.String())
50+
if dbInfo == nil {
51+
b.logger.Error("Backup: could not find database", zap.String("id", bkt.ID.String()))
52+
continue
53+
}
4354

4455
var description *string
4556
if bkt.Description != "" {
4657
description = &bkt.Description
4758
}
59+
rpManifests := retentionPolicyToManifest(dbInfo.RetentionPolicies)
60+
61+
for _, rpManifest := range rpManifests {
62+
for _, sg := range rpManifest.ShardGroups {
63+
if len(sg.Shards) <= 0 && sg.DeletedAt == nil {
64+
b.logger.Warn("Backup: ShardGroup has not been deleted and has no shards",
65+
zap.String("bucket", bkt.Name),
66+
zap.String("rp", rpManifest.Name),
67+
zap.Uint64("shard-group-id", sg.ID), zap.Time("start-time", sg.StartTime),
68+
zap.Time("end-time", sg.EndTime))
69+
}
70+
}
71+
}
4872

4973
l = append(l, influxdb.BucketMetadataManifest{
5074
OrganizationID: bkt.OrgID,
@@ -53,7 +77,7 @@ func (b BucketManifestWriter) WriteManifest(ctx context.Context, w io.Writer) er
5377
BucketName: bkt.Name,
5478
Description: description,
5579
DefaultRetentionPolicy: dbInfo.DefaultRetentionPolicy,
56-
RetentionPolicies: retentionPolicyToManifest(dbInfo.RetentionPolicies),
80+
RetentionPolicies: rpManifests,
5781
})
5882
}
5983

cmd/influxd/launcher/launcher.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ func (m *Launcher) run(ctx context.Context, opts *InfluxdOpts) (err error) {
634634
ts.BucketService = dbrp.NewBucketService(m.log, ts.BucketService, dbrpSvc)
635635

636636
bucketManifestWriter := backup.NewBucketManifestWriter(ts, metaClient)
637+
bucketManifestWriter.WithLogger(m.log.With(zap.String("service", "bucket-manifest-writer")))
637638

638639
onboardingLogger := m.log.With(zap.String("handler", "onboard"))
639640
onboardOpts := []tenant.OnboardServiceOptionFn{tenant.WithOnboardingLogger(onboardingLogger)}

http/restore_service.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,18 @@ func (h *RestoreHandler) handleRestoreBucketMetadata(w http.ResponseWriter, r *h
226226
return
227227
}
228228

229+
for _, rps := range b.RetentionPolicies {
230+
for _, sg := range rps.ShardGroups {
231+
if len(sg.Shards) <= 0 && sg.DeletedAt == nil {
232+
h.Logger.Warn("Restore: ShardGroup has not been deleted and has no shards",
233+
zap.String("bucket", b.BucketName),
234+
zap.String("rp", rps.Name),
235+
zap.Uint64("shard-group-id", sg.ID), zap.Time("start-time", sg.StartTime),
236+
zap.Time("end-time", sg.EndTime))
237+
}
238+
}
239+
}
240+
229241
// Create the bucket - This will fail if the bucket already exists.
230242
// TODO: Could we support restoring to an existing bucket?
231243
var description string

0 commit comments

Comments
 (0)